gurobi python zero arrays with some entries variables
Answeredis it possible in gurobi to have a variable that is zero matrix with some entries being scalar gurobi expressions? eg, the code
Q = np.diag([1, 2, 3])
A = np.array([ [1, 2, 3], [1, 1, 0] ])
b = np.array([4, 1])
model = gp.Model()
x = model.addVar(ub=1.0, name='x') # Create three variables in [0,1]
y = model.addVar(ub=1.0, name='y')
vec = np.zeros((3, 1), dtype=object)
vec[0,0] = x
vec[1,0] = y
model.setObjective(vec.T @ Q @ vec)
model.addConstr(A@vec >= b)
model.optimize()
gives me the following error
gives me the following error
GurobiError: Unable to convert argument to an expression
0
-
Official comment
This post is more than two 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 Tetiana,
If I understood you correctly, instead of having a 3-dimensional variable vector, you want to replace the third variable with a scalar, right? What exactly do you want to achieve?
If you have a large variable vector where just a few entries are already fixed, you could set the lower and upper bounds of the corresponding fixed variables to the desired scalar. Then, Gurobi will remove the variable in presolving.Best regards,
Mario0
Post is closed for comments.
Comments
2 comments