Skip to main content

Constraints in Gurobi

Answered

Comments

6 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    This post is more than two 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.
  • Riley Clement
    • Gurobi Staff

    Hi Shahrzad,

    attached constraint

    It looks like we are missing this.

    - Riley

    0
  • Shahrzad Valizadeh
    • Gurobi-versary
    • Investigator
    • Conversationalist

    0
  • Riley Clement
    • Gurobi Staff

    Hi Shahrzad,

    This looks correct, however this line creates an empty linear expression:

    state_OPM_term = gp.LinExpr()

    The next line is overwriting it, not adding to it, so the first line is unnecessary.

    Just a note on the terminology, the above is not a constraint until there is a relation introduced: "<=", ">=", "==", at the moment it is just a linear expression.

    - Riley

    0
  • Shahrzad Valizadeh
    • Gurobi-versary
    • Investigator
    • Conversationalist

    Thank you so much Riley for your comment. As I'm using: 

        state_OPM_term = gp.quicksum((b1["O+", "1", m, t] - (0.1 * gp.quicksum(b2["O+", "1", m, demand, t] for demand in D))* weights["O+", "1", m]) for m in M) 
    

    as a linear expression in my objective function, would it be correct to have the following:

        state_OPM_term = gp.quicksum((b1["O+", "1", m, t] - (0.1 * gp.quicksum(b2["O+", "1", m, demand, t] for demand in D))* weights["O+", "1", m]) for m in M) 
    
    obj = state_OPM_term + (the rest linear expressions)
    0
  • Riley Clement
    • Gurobi Staff

    That should work without any problems.  If you did something like this and found there was an error you should verify that state_OPM_term is a LinExpr (or some other type of expression like QuadExpr) by inspecting the value of type(state_OPM_term).

    - Riley

    0

Post is closed for comments.