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

Constraints in Gurobi

回答済み

コメント

5件のコメント

  • Riley Clement
    Gurobi Staff 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 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 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

サインインしてコメントを残してください。