0

I am new to gurobipy and I am trying to model this linear program the objective value and constraints are seen in this picture:

the objective value and constraints are seen in this picture

This is the code I have written for the objective function and constraints

#objective function

obj_fn = - quicksum(quicksum(R[k,r] * C[k,r] for k in ns) for r in nr) + quicksum(V[j] for j in np) * quicksum(W[k,j] for k in ns)

#constraints

c1 = model.addConstrs(quicksum(W[k,j] for j in np) <= quicksum(R[k,r] for r in nr) for k in ns)
c2 = model.addConstrs((R[k,r] <= P[k,r] for k in ns for r in nr))
c3 = model.addConstrs(quicksum(R[k,r] for k in ns) <= R[r] for r in nr)
c4 = model.addConstrs((quicksum(R[k,r] * X[i,k] for k in ns) <= R[r] * Z[i,r] for i in nc for r in nr))
c5 = model.addConstrs(LQ[j] <= quicksum(W[k,j] for k in ns) <= UQ[j] for j in np)
c6 = model.addConstrs((LY[i,j] <= quicksum(W[k,j] * X[i,k] for k in ns)/(quicksum(W[k,j] for k in ns)) <= UY[i,j] for i in nc for j in np))
c7 = model.addConstrs((LX[i,k] <= X[i,k] <= UX[i,k] for i in nc for k in ns))
c8 = model.addConstrs((quicksum(H[i,j,k] * X[i,k] for i in nc) == D[j,k] for j in E for k in ns))

But I am having trouble with implementing the decision variables so that I can solve the problem. I know the dimensions of each decision variable. For example, R will have different values corresponding with the kth and rth elements it possesses. Do I assign R as a matrix decision variable or just as a continuous decision variable?

Any help would be greatly appreciated.

Timus
  • 10,974
  • 5
  • 14
  • 28
imsorry
  • 1
  • 2

1 Answers1

0

When writing down the formulation of a math programming model, it is usually a good idea to start with defining the variables.

From the screenshot of the mathematical formulation, it is not clear what the variables are and what the coefficients of the objective and the constraints are. I suppose X are variables, but what about R, C, V, and W? I suppose that R also represents a variable set because the third constraint only containing R would not make any sense otherwise. But then your problem is not linear anymore because you are multiplying R and X in the fourth constraint.

In any case, you might want to think about decision variables not in a matrix fashion but rather as having a multi-dimensional index. You can easily pass multiple such index sets to the addVars() method in Gurobi (see documentation) without having to explicitly work with matrix vars (see addMVar()).

mattmilten
  • 6,242
  • 3
  • 35
  • 65