Skip to main content

Dual value Pi and QCPi for specified constraint - python

Answered

Comments

6 comments

  • Official comment
    Simranjit Kaur
    • 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 try Gurobot, our chatbot interface offering instant, expert-level support.
  • Patricio Burdiles
    • Gurobi-versary
    • First Comment
    • First Question

    I have also tried the following without succes:

     

    fixed = model.fixed()
    fixed.Params.QCPDual = 1
    fixed.optimize()

    constrs = fixed.getConstrs()

    shadow_price = fixed.getAttr(GRB.Attr.QCPi)  #this works but there is no information about associated constraints to QCPi values.

    sh_pr = np.zeros((len(shadow_price),2))
    sh_p_i = 0
    for ci in range(0,len(constrs)+1):
        try:
            sh_pr[sh_p_i,0] = constrs[ci].getAttr(GRB.Attr.QCPi) #this does not work
            sh_pr[sh_p_i,1] = constrs[ci].index
           sh_p_i = sh_p_i + 1
        except Exception:
            pass


    thanks

    0
  • Eli Towle
    • Gurobi Staff

    Model.getConstrs() returns a list of all linear constraints in the model. Model.getQConstrs() returns a list of all quadratic constraints in the model.

    The code

    model.getAttr(GRB.Attr.QCPi)

    is equivalent to

    model.getAttr(GRB.Attr.QCPi, model.getQConstrs())
    0
  • Patricio Burdiles
    • Gurobi-versary
    • First Comment
    • First Question

    Thanks Eli for the clarification. Now it works.

    0
  • Panagiotis Vasilopoulos
    • Gurobi-versary
    • First Comment
    • First Question

    Hello, 

     

    as I'm writing the above after my initial model , (model=ConcreteModel(name=".......")), has been solved/optimized i get the below message:

    'ConcreteModel' object has no attribute 'fixed' . 

     

    Could you please advise why I'm getting this? Should i put the code before solving the initial quadtratic MILP model? 

    0
  • Eli Towle
    • Gurobi Staff

    The code included in previous posts applies to models built using \(\texttt{gurobipy}\), Gurobi's native Python interface. Specifically, \(\texttt{model}\) is a Model object, and the user calls the Model.fixed() method.

    In contrast, you are building your model using Pyomo. This is a separate, third-party modeling framework. As far as I can tell, the ConcreteModel class has no analogous method to fix every non-continuous variable. However, the Pyomo documentation suggests using the following code snippet to fix all non-continuous variables to their current values:

    import pyomo.environ as pyo

    for var in instance.component_data_objects(pyo.Var, active=True): if not var.is_continuous(): var.fixed = True

    The Fixing Variables and Re-solving section of the Pyomo documentation might also be useful.

    0

Post is closed for comments.