'Creating variables using multiple lists

so I have three lists: customer,time and amount. Based on these three lists, I want to create a demand variable: demand of customer c in time t.

So let's say I have the following lists:

customer = ["c1","c1","c1","c2","c2","c2","c3","c3","c3"]
time = [1,2,3, 1,2,3, 1,2,3]
value = [4, 8, 9, 2, 3, 4, 5, 7, 9]

This should be read as:

so demand of customer "c1" at time 1 equals 4. Demand of customer "C3" at time 3 equals 9

Using addVars, how can I add demand as variables? Currently, I have the following:

time = [1,2,3, 1,2,3, 1,2,3]
value = [4, 8, 9, 2, 3, 4, 5, 7, 9]

indices = list(zip(customer, time))

demand = model.addVars(indices, obj = value, name = "demand")

But if I use the following:

for x in demand.values():
    print(x)

Output is as follows:

<gurobi.Var demand[c1,1]>
<gurobi.Var demand[c1,2]>
<gurobi.Var demand[c1,3]>
<gurobi.Var demand[c2,1]>
<gurobi.Var demand[c2,2]>
<gurobi.Var demand[c2,3]>
<gurobi.Var demand[c3,1]>
<gurobi.Var demand[c3,2]>
<gurobi.Var demand[c3,3]>

I would expect that I would get the values of the list value. How should I add demand as a variable?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source