1 comment

• Gurobi Staff

Hi,

I am not sure what you are trying to achieve. A rather standard way of summing over all values of a multidimensional list would be the use of $$\texttt{for}$$-loops

res = 0for i in x1:  for j in i:    for k in j:      res += kprint(res)

However, this will not work when $$\texttt{x1}$$ is an optimization variable.

You can introduce $$\texttt{x1,x2}$$ as a 3 dimensional optimization variable via the addVars function

x1 = model.addVars(2,3,4)x2 = model.addVars(4,5,6)

and then sum over all variable using the quicksum function

model.addConstr(gp.quicksum(x1[i,j,k] for i in range(2) for j in range(3) for k in range(4)             >= gp.quicksum(x2[i,j,k] for i in range(4) for j in range(5) for k in range(6))