Home > Mobile >  How to combine multiple terms in Gurobi addMConstr?
How to combine multiple terms in Gurobi addMConstr?

Time:10-23

I am trying to create a matrix constraint with the following terms:

sp1 = gp.Model('subproblem1')
I6 = np.identity(6)
y = sp1.addMVar(4,vtype=gp.GRB.CONTINUOUS,name='y') 
vp = sp1.addMVar(6,vtype=gp.GRB.CONTINUOUS,name='vp')
vm = sp1.addMVar(6,vtype=gp.GRB.CONTINUOUS,name='vm')
W = a 6x4 np array
rhs = a 6x1 np array
sp1.addConstr(W@y   I6@vp   I6@vm == rhs)

I get the following error: GurobiError: Incompatible vector dimensions

What is the issue? Best I can tell all terms should equal a [6x1] array.

CodePudding user response:

Since rhs has shape (6,1) Gurobi thinks it's a matrix, not a vector. You should make sure it has shape (6,):

sp1.addConstr(W@y   I6@vp   I6@vm == rhs.flatten())
  • Related