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

Adding SOCP contraints

回答済み

コメント

2件のコメント

  • 正式なコメント
    Simranjit Kaur
    • 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

    Hi Samuel,

    Providing the constraint in the second form would be the way to go here.

    You could introduce a auxiliary variables for the \(\frac{a\pm b}{2}\) terms and then add the SOC constraint explicitly. Your code could look something like

    GRBVar a  = model.addVar(0.0, GRB_INFINITY, 0.0, GRB_CONTINUOUS, "a");
    GRBVar b  = model.addVar(0.0, GRB_INFINITY, 0.0, GRB_CONTINUOUS, "b");
    GRBVar c  = model.addVar(0.0, GRB_INFINITY, 0.0, GRB_CONTINUOUS, "c");
    GRBVar z1 = model.addVar(0.0, GRB_INFINITY, 0.0, GRB_CONTINUOUS, "z1");
    GRBVar z2 = model.addVar(-GRB.INFINITY, GRB_INFINITY, 0.0, GRB_CONTINUOUS, "z2");

    model.addConstr(0.5*a + 0.5*b - z1 == 0, "aux1");
    model.addConstr(0.5*a - 0.5*b - z2 == 0, "aux2");
    model.addQConstr(z1*z1 - c*c - z2*z2 >= 0, "socc")

    You will probably want to construct bigger constraints. In this case, you should use a GRBQuadExpr. When doing so you should avoid using a loop to compute

    expr = expr + x*x

    as described in the documentation of GRBQuadExpr. Using the addTerm in a loop or the addTerms method is the way to go here.

    Best regards, 
    Jaromił

    0

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