Skip to main content

How can I get or print the LHS constraint values?

Answered

Comments

4 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff 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 Gurobi Staff

    Hi Marcela,

    Do you mean you want to extract the values of the LHS of those constraints at the optimal solution? If so, you can do this as follows:

    1. Construct a LinExpr object for each of the LHS expressions
    2. After optimizing, evaluate each LHS expression with the LinExpr.getValue() method

    In your case:

    LHS = {proc : quicksum(RestrProc2[proc][vr]*Vrbl[vr] for vr in vrs) for proc in procs}
    pp3.addConstrs(LHS[proc] <= MCapcity[proc] for proc in procs)

    pp3.optimize()

    for proc in procs:
        print(LHS[proc].getValue())

    I hope this helps!

    Eli

    1
  • Marcela Villa Marulanda
    • Gurobi-versary
    • First Question
    • First Comment

    Hi Eli, it worked! Thank you very much.  

    0
  • Wenbo Ma
    • Gurobi-versary
    • Curious
    • First Comment

    Just add a note to Eli's answer:

    If you don't want to create a new object LHS, below can give you the values too.

    for proc in procs:
    quicksum(RestrProc2[proc][vr]*Vrbl[vr] for vr in vrs).getValue()
    0

Post is closed for comments.