problem during trying to solve a bilinear problem
Answeredi want gurobi to solve a optimization problem with a bilinear term.In the highlighted row of code,u and w are both variables,u is 24*1 vector,w is 168*1 vector.But gurobi says 'MLinExpr' object has no attribute 'transpose',how do i cope with this?

-
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 Richard,
Currently, transpose is only implemented for MVars, not the corresponding expression objects (MLinExpr and MQuadExpr). You can work around it in this case by expanding out the transpose, i.e.
(p - J @ u).transpose()
is equivalent to:
(p.T - u.T @ J.T)
Note that T is a shorthand for transpose() which is supported both by numpy matrices and MVars.
0 -
thanks,the problem has been fixed.another problem emerged:GurobiError:problem adding constraints.gurobi says" DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation." whats wrong with that
0 -
This deprecation warning comes from newer versions of numpy, please see https://support.gurobi.com/hc/en-us/articles/16534198159889 for further information. Your code in the screenshot looks correct so I don't think you need to make any changes. The warning should go away with the upcoming 10.0.3 release of Gurobi.
By the way, you do not need to extract your solution element-wise. This code is actually quite inefficient:
res_u = np.zeros(24)
for i in range(24):
res_u[i] = u[i].XMVars have vectorized access to all Gurobi attributes (including the solution attribute, X), so you can extract your result without the for loop as follows:
res_u = u.X
This gives the same result and is much more efficient.
0
Post is closed for comments.
Comments
4 comments