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

Trouble with using a transforming function on a variable

回答済み

コメント

3件のコメント

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

    You could introduce the transform value as an integer valued optimization variable and model the ceil function. However note that you will have to introduce a tolerance because modeling strict inequalities is not possible in Gurobi. The stackexchange post Modeling floor function exactly might be helpful. You can then introduce nonconvex binary products of optimization variables \(\text{transform} \cdot x\).

    Best regards,
    Jaromił

    0
  • Lukas Meier
    • Gurobi-versary
    • First Comment
    • First Question

    Thank you so much for your answer Jaromil, I think I' ve got the gist of it.

    In case somebody finds this with the same problem you can define the transformation function through constraints. In the case of my example above the function would be y=10-x so you define y as a variable and add the constraint y+x=10. If you're working with a scaling factor of say 0.5 (meaning y=x^0.5) you have to add another variable that defines x^0.5 by adding a constraint for (x^0,5) * x(0,5) - x = 0.

    GRBQuadExpr constr1 = new GRBQuadExpr();
    constr1.addTerm(1, root2, root2);
    constr1.addTerm(-1, x);
    model.addQConstr(constr1, GRB.EQUAL, 0.0, "constr1");

    Thanks again and best regards,

    Lukas

    0

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