Skip to main content

Two Phase method

Answered

Comments

5 comments

  • Simranjit Kaur
    Gurobi Staff Gurobi Staff

    Hi Shahrzad,

    It seems like you forgot to call model.optimize() to solve the model before checking if model.status is GRB.OPTIMAL.

    Best regards,
    Simran

     

    0
  • Shahrzad Valizadeh
    Gurobi-versary
    Investigator
    Conversationalist

    Dear Simranjit, thank you for your response. You're right, it was a mistake.

    Overall, is this approach correct for writing the Two-Phase method?

    0
  • Simranjit Kaur
    Gurobi Staff Gurobi Staff

    Overall it looks correct. Just two points:

    1. The call model.setObjective(0, GRB.MINIMIZE) in the Phase 2 is not required. The following two lines are enough to set the original objective of the model

    obj = -1 * x[0] + 2 * x[1] -3 * x[2]
    model.setObjective(obj, GRB.MINIMIZE)

    2. In Phase two, instead of removing the constraints and re-adding them again, you can simply change the coefficients of the artificial variables to zero using model.chgCoeff method, for example, if you have 

    c1 = model.addConstr(x[0] + x[1] + x[2] + R[0] == 6, "First_Constraint")

    then to change the coefficient of R[0] to zero in Phase 2, you can call

    model.chgCoeff(c1, R[0], 0)
    0
  • Shahrzad Valizadeh
    Gurobi-versary
    Investigator
    Conversationalist

    Thank you so much for your guidance.

    0
  • Shahrzad Valizadeh
    Gurobi-versary
    Investigator
    Conversationalist

    Thank you for your valuable responses. 

    0

Please sign in to leave a comment.