MLinExpr and LinExpr incompatibilities, how to avoid that?
AnsweredHi, I am working with MVars and MLinExpr and I know that those environments are currently not compatible with LinExpr and Vars. However, Gurobi automatically switches the type of one of my variables from MVar to Var. Specifically, in Python,
These are three of my variables:
import gurobipy as grb
zeta = model.addMVar(
shape=1,
lb=-grb.GRB.INFINITY,
ub=grb.GRB.INFINITY,
name="zeta",
vtype=grb.GRB.CONTINUOUS
)
Z = model.addMVar(
shape=100,
vtype=grb.GRB.CONTINUOUS,
name="Z"
)
Y = model.addMVar(
shape=(50,100),
vtype=grb.GRB.CONTINUOUS,
name='Y'
)
model.addConstrs(
Z[s] >= a @ X - b @ Y[:, s] - zeta
for s in range(100)
)
And it raises the error:
GurobiError: Unsupported type (<class 'gurobipy.MLinExpr'>) for LinExpr addition argument
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support. -
Hi Daniele,
We currently have a few issues with interactions between Var/LinExpr and MVar/MLinExpr. There were some fixes added to the most recent release (version 9.5.1) which should address your case. Could you please upgrade to version 9.5.1 and additionally rewrite your constraints as below?
model.addConstrs(
a @ X - b @ Y[:, s] - zeta - Z[s] <= 0
for s in range(100)
)Note - I'm assuming here that X is a 1D MVar (similar to Z) and a and b are 1D numpy arrays with compatible shapes for multiplying with X and Y[:, s].
Best regards,
Simon1 -
Thank you Simon, now it works!
0
Post is closed for comments.
Comments
3 comments