Skip to main content

Dual Variable for Facility Loaction Problem

Comments

2 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.
  • Alison Cozad
    • Gurobi Staff
     

    Your subproblem is a Linear Program (LP), which is advantageous because dual values (pi values) can be retrieved for convex, continuous models. This capability applies to both equality and inequality constraints. This is true whether or not the model is written in standard or cononical form.

    To retrieve the dual values, the model must be optimized and have a feasible solution. In your code, it's important to ensure that the sub.optimize() method is called after setting the objective function in your subproblem.

    To retrieve pi values

    1. Define your model
    2. Optimize it using the Model.optimize() method
    3. Retrieve the dual values using the Constraint.getAttr("Pi") method.

    Example with afiro.mps

    Here is an example using the afiro.mps model, which comes prepackaged with Gurobi:

    import gurobipy as gp
    from gurobipy import GRB

    # Read/build model
    # Here I am using the example LP model afiro that comes prepackaged with Gurobi
    m = gp.read('afiro.mps')

    # Optimize model
    m.optimize()

    # Print all dual values
    for c in m.getConstrs():
        print(f"Constraint '{c.ConstrName}' has a pi value of {c.getAttr('Pi')}")

    For more details on the pi attribute, see Pi - Gurobi Optimization.

    0

Post is closed for comments.