0

I have following code cutouts:

        a = range(0, 30)
        b = range (0, 88)
         Power_consumption =  LpVariable.dicts('Power_consumption', (a,b), lowBound=0, upBound=5, cat='Continuous')
    ...

result= [[]]
    for i in a:
        for j in b:
            print("i:",3, "j:",3, " = ", Power_consumption[i][j].varValue)
            result[i][j] = Power_consumption[i][j].varValue

After getting the optmimal solution of the Linear Programming Model, I would like to sum up the "Power_consumption" on the index i ( i = timestep, j = device) so that I have for every timestep "i" the power consumption of all devices. But when trying I get all the time "IndexError: list assignment index out of range". So I am wondering what I did wrong and whats the best way of doing so ?

Mada
  • 1
  • 1

1 Answers1

0

I don’t think you are constructing your variable correctly with respect to a and b. Be more explicit there…

a = list(range(30))
b = list(range(88))
ab = [(i, j) for i in a for j in b]
Power = LpVariable.dicts(‘power’, ab, . . . )
AirSquid
  • 10,214
  • 2
  • 7
  • 31