Set constraint using calculations from single values of MVar
ユーザーの入力を待っています。Hi
I have a selection variable as MVar:
selection = model.addMVar(n, vtype=gp.GRB.BINARY)
A = np.zeros((m, m))
for i in range(n):
j, k = indices[i]
A[j][k] = selection[i]
model.addConstr(gp.max_(A@A@A) <= 5)
-
Hi,
I am not fully sure what the mathematical constraint is that you want to model.
Could you please specify it in mathematical notation?Best regards,
Mario0 -
Sure.
The exact context is a bit hard to describe, but essentially I am trying to modify the adjacency matrix A of a graph. And the constraint in this modification is that the modified graph does not have a connected component of size greater than 5.
The adjacency matrix is quite large, hence I could not model the entire A as MVar, and therefore decided to select a subset of cells in A as decision variables. I hope this make sense.
0 -
You created a 1-dimensional MVar containing n variables. If you want to model the edges in your graph by variables, then it has to be a nxn matrix of variables. But since I guess your graph is very sparse, I would recommend to not create variables for the full matrix but only for the relevant edges.
Also, you assign a variable to some cells in a numpy matrix, while in the other cells there is value 0. This is not possible with Gurobi.
Additionally, if A would be an MVar, A@A@A would create a cubic formulation, which is also not possible with Gurobi. You might need a different approach to model connected components.
0
サインインしてコメントを残してください。
コメント
3件のコメント