Constraint with very large sparse matrices
回答済みHello,
I am struggling to add a constraint to my model with very large sparse matrices.
The constraint is in this linear form :
constraint = model.addConstr((A @ B @ C @ (b - 0.5)) == alpha*S)
Here b, and alpha are my MVars of respective size (768432,) and (32768,)
The matrix A is sparse of shape (32768, 262144). The matrix B is sparse of shape (262144, 262144). The matrix C is also sparse of shape (262144, 786432). I use scipy.sparse to declare them. The vector S is of shape (32768,).
When I try adding this constraint to my model, my python process gets killed. I have access to 400Gb of memory.
Is this problem simply too big or is there a more clever way to add this constraint ?
Edit :
Ideally, I would like Gurobi to do the matrix vector multiplication first, without ever doing the matrix matrix multiplications, is something like this possible ?
-
Hi Nicolas,
The solver must transform your expression to obtain a single coefficient for each variable before the solution process starts. So, the matrix-matrix multiplications need to be done first.
You might need to use some Python methods specialized for sparse matrices to do the matrix-matrix multiplications efficiently before defining the constraint.
The number of variables is quite high, but we have seen larger models. It, of course, depends on the structure and numerics of the problem if this model can be solved in a reasonable time.Best regards,
Mario0
サインインしてコメントを残してください。
コメント
1件のコメント