Skip to main content

How to use the optimal solution (Gurobi output) to calculate another equation

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?.
  • Silke Horn
    • Gurobi Staff Gurobi Staff

    You can get the value of a variable in the final solution via the variable's X attribute, e.g.:

    x[(0,0,1)].X

    In order to get the value of a linear expression at the current solution, you can use the LinExpr.getValue method.

    You can either save the LHS of your constraints to LinExpr objects first and then use them in constraints or use the Model.getRow method to retrieve the expression from the model. E.g.:

    # assume c points to the constraint object whose LHS you want to evaluate
    expr = m.getRow(c)
    expr.getValue()

    You can also define other linear expressions as linear combinations of your variables that are not constraints and then evaluate them at the current solution. E.g.:

    expr = quicksum(x[(i,j,k)] for i in N for j in N for k in B)
    expr.getValue()

     

    0
  • Azi
    • Gurobi-versary
    • First Comment
    • First Question

    Thank you so much. This was a big help. 

    0
  • Will Smith
    • Gurobi-versary
    • First Comment

    This is very useful information, Thanks for Sharing.

    0

Post is closed for comments.