Skip to main content

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

Answered

Comments

2 comments

  • Official comment
    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 try Gurobot, our chatbot interface offering instant, expert-level support.
  • Jaromił Najman
    • 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

Post is closed for comments.