Incorrect calculation of the sum of squares of the product of matrix and value(Cannot multiply with an MLinExpr from the left)

Answered

Comments

2 comments

  • Eli Towle

    It's not currently possible to multiply two MLinExpr objects together like this. As a workaround, you can create auxiliary variable \( y \in \mathbb{R}^{10} \) such that \( y_i \) equals \( \texttt{np.sum(it) - c[i]} \), then set the objective function equal to \( y^\top y \):

    y = model.addMVar(10, lb=-GRB.INFINITY)
    for i in range(10):
        model.addConstr(y[i] == sum(N[i,j] * B @ x[:,j] for j in range(2)) - c[i])
    model.setObjective(y @ y, sense=GRB.MINIMIZE)

    For more information, see the article How do I multiply two MLinExpr objects together with the matrix-friendly Python API?.

    0
    Comment actions Permalink
  • chen yan

    Dear Eli,

    Thank you very much for helping me solve the problem, thank you very much!

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk