メインコンテンツへスキップ

Please help, how I can solve it?

回答済み

コメント

2件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff Gurobi Staff
    This post is more than three 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 why not try our AI Gurobot?.
  • Jaromił Najman
    • Gurobi Staff Gurobi Staff

    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([
    [1.1,1.5,0.8],
    [3,2.5,0.7],
    [2,1,1.3],
    [0,0,0]])

    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):
    lExpr.add(lmbd[i],b[i])
    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.

    m.setParam("NonConvex",2)

    Best regards,
    Jaromił

    0

投稿コメントは受け付けていません。