Combining Different Types if Variables in Matrix Constraints
OngoingIf I have the constraint of the form x_i <= z_i , (i = 1,2, ..., n), where x_i are continuous and belong to interval [0,1], and z_i's are binary. Both z_i's and x_i's are also present separately in various other constraints.
Then, how do I add variables x_i and z_i separately to my model and use both in a single Constraint in matrix form (e.x. A @ x , where x = [x_i z_i], a combination of both variables).
One way is to construct matrix constraints using all the variables as x but, then I won't be able to use different types of vars.
-
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 why not try our AI Gurobot?. -
Hi Mr. Satender,
You could create a one-dimensional binary matrix variable including both variable sets x and z, and then change the type of the x variables to CONTINUOUS afterwards, as demonstrated below on a small example:
A = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
Best regards,
b = np.array([1, 2, 3])
m = gp.Model("model")
x = m.addMVar(3, vtype=GRB.BINARY, name="x")
x[0].VType = GRB.CONTINUOUS
m.addConstr(A @ x <= b, name="matrix")
Mario1
Post is closed for comments.
Comments
2 comments