Matrix assembly as equality constraint
AnsweredHi all,
I would like to define a matrix equality constraint (i.e. matrix assembly) in python.
The equality constraint defines the assembly of a matrix. The constraint is defined as in the code below, but this doesn't work. Can anyone suggest a correction?
Thank you very much for your attention and help!
x = mod.addVars(N, vtype=gp.GRB.CONTINUOUS, lb=0., ub=1., name="x")
A = mod.addMVar(shape=(n,n), vtype=gp.GRB.CONTINUOUS, lb=0, ub=gp.GRB.INFINITY, name="A")
AMat = mod.addConstrs( ( A == sum( xMax * np.ones((n,n)) * x[i] for i in range(N) ) ), name='A matrix')
0
-
the error that i get is: Variable is not a 1D MVar object
0 -
Hi Nicolo,
Currently, the Python Matrix API is not compatible with advanced matrix equations and operation such as a matrix assembly. I think it is best to model your equality constraints via the normal Var objects, i.e., define matrix \(A\) via the addVars method. You would then have to construct your constraints row by row.
Best regards,
Jaromił0
Please sign in to leave a comment.
Comments
2 comments