Multiply scalar array with two-dimensional Mvar? (GurobiError: Variable is not a 1D MVar object)
AnsweredHi. I am trying to improve my runtime by using Mvar instead of scalar variabes. I have a descision variable with a second dimension (time), but constraint coefficients which are time-independent, so my constraint looks like:
model = gp.Model()
A = np.random.rand(len(N)) #(N coefficients)
b = np.random.rand(len(T)) #(T timesteps)
X = model.addMVar((len(N),len(T)))
model.addConstr(A@X == b)
However, I do get an error: GurobiError: Variable is not a 1D MVar object.
The product A@X works when X is a parameter but not a variable,
so it seems like gurobi does not support this multiplication for variables? Is there another way perhaps?
0
-
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 Olaf,
I think the Knowledge Base article How do I multiply an array and a 2-D MVar object using the matrix-friendly Python API? should answer your question.
Best regards,
Jaromił0
Post is closed for comments.
Comments
2 comments