Skip to main content

What kind of functions can be accepted into Model.setObjective method?

Answered

Comments

1 comment

  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    Hi Vadim,

    1) Is the 'if statement' the issue in the function? The answer to the optimization should be x = 0.

    Yes, the if statement is causing the issue. Note that \(x\) is a Var object which does not have any value. You can access the variable solution point value via its X attribute after a solution point is available. In your case, you would have to run optimize first in order to make \(x\) have a solution point value available.

    In Mathemtical Programming, you can model \(\texttt{if}\)-statements via additional binary variables and constraints, cf. How do I model conditional statements in Gurobi? In your case, it is much easier. You can just set the objective function to \(x^2\) via

    model.setObjective(x*x, GRB.MINIMIZE)

    2) What kinds of functions can Model.setObjective() method accept as an argument?

    According to the documentation of the setObjective method, it accepts linear and quadratic expressions.

    Best regards, 
    Jaromił

    0

Please sign in to leave a comment.