Please help, how I can solve it?



1 comment

  • Jaromił Najman

    Hi Konstantin,

    In the following, I omit \(c_2\) and \(y\), because both variables are not defined in your code snippet.

    The expression you try to construct is

    \[(b-A \cdot u)^T \cdot \lambda = \sum_{i=1}^4 \left( \lambda_i \cdot \left(b_i - \sum_{j=1}^3 ( A_{i,j}\cdot u_j ) \right) \right) \]

    which not a matrix object. The Python Matrix API is not meant to perform matrix operations but to construct matrix expression. For more information, see Gurobi Python Interface and Python Matrix Example.

    Note that the above expression is a quadratic one, so it might be advantageous to split it into a linear and a quadratic part

    import gurobipy as gp
    from gurobipy import GRB
    import numpy as np

    b = np.array([50,40,33,44]).reshape((4,))
    A = np.array([

    u = m.addVars(3,name='leader_strat')
    lmbd = m.addVars(4,name='lambda')

    lExpr = gp.LinExpr(0)
    qExpr = gp.QuadExpr(0)
    for i in range(4):
    for j in range(3):
    qExpr.add(lmbd[i] * u[j], A[i][j])

    finalExpr = lExpr - qExpr

    # Set objective
    m.setObjective(finalExpr, GRB.MINIMIZE)

    Note that your model is a non-convex quadratic one, so you have to set the NonConvex parameter to 2.


    Best regards,

    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk