Skip to main content

problem during trying to solve a bilinear problem




  • Simon Bowly
    Gurobi Staff Gurobi Staff

    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.

  • Richard Liu
    First Comment
    First Question

    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

  • Simon Bowly
    Gurobi Staff Gurobi Staff

    This deprecation warning comes from newer versions of numpy, please see 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].X

    MVars 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.


Please sign in to leave a comment.