Skip to main content

Update from Gurobi 7.5.2 to 9.1.0 - GurobiError: "Constraint has no bool value"

Answered

Comments

3 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 why not try our AI Gurobot?.
  • Eli Towle
    • Gurobi Staff

    Building an expression with

    quicksum(x[i,j,0] for (i,j) in d if x[i,j,0] == 0)

    should not have worked in previous versions of Gurobi. So it's a good thing you see an error in newer versions of Gurobi. If Gurobi 7.5.2 optimized the model properly when you used this syntax, then you were lucky. The coefficients for variables in the objective function and constraints must be deterministically set prior to solving the model, and therefore cannot change based on the values assumed by those variables.

    There are almost always modeling tricks you can use to implement this kind of logic in your model. You might find the Model.addGenConstrIndicator() method (or its overloaded form) helpful. This method allows you to model certain logical implications using binary variables. E.g., given a binary variable \( x \) and another variable \( y \), you could add a constraint like

    $$x = 0 \implies y = 2.$$

    That said, what is your objective function trying to do? If you only sum over the \( x \) variables that are equal to \( 0 \), you always end up with \( 0 \).

    1
  • Loukas Katikas
    • Gurobi-versary
    • First Comment
    • First Question

    Hi Eli,

    Thanks for your immediate response! Finally, it worked without using the Model.addGenConstrIndicator(), I just customized my linear constraints (actually the quicksum of the x[i,j,k] for k in range(...)).

    I think the case is that with the current Gurobi version, the "GurobiError: Constraint has no bool value" error occurs with an "if" statement inside the objective function as you highlighted.

    Thanks for your help 

    Best regards,

    Loukas

    0

Post is closed for comments.