Problem when asking for dual variable in QCP

755 views
Skip to first unread message

msie...@gatech.edu

unread,
Apr 12, 2017, 3:01:31 AM4/12/17
to Gurobi Optimization
Hello,

I'm running several times a QCP in pyhton, adding in each iteration new constraints to the model. If the problem is optimal I ask for the dual of a given linear constraint, and some times I get the following error:

 beta = Const1.getAttr("Pi")
 File "constr.pxi", line 125, in gurobipy.Constr.getAttr (../../src/python/gurobipy.c:20278)
gurobipy.GurobiError: Unable to retrieve attribute 'Pi'

At first I thought that maybe it was because the problem is unbounded, but I checked and the objective function is finite. Also, I only call for the dual if the problem is optimal, and therefore feasible using the statement "if m.status == GRB.Status.OPTIMAL"

I hope someone can help me with this.

Matias Siebert

David Nehme

unread,
Apr 12, 2017, 12:22:07 PM4/12/17
to Gurobi Optimization
Matias,

    Duals are not computed for quadratically constrained problems unless the QCPDual parameter is set to 1.  This is true even for the linear constraints of a QCP.  You can use m.setParam('QCPDual'1) before calling optimize.

- David Nehme


In [1]: import gurobipy as grb
In [2]: m = grb.Model(name='qc_dual_demo')
In [3]: x = m.addVar(obj=-1, name='x')
In [4]: qc = m.addConstr(x*x <= 10)
In [5]: lc = m.addConstr(x >= 3)
In [6]: m.optimize()
Optimize a model with 1 rows, 1 columns and 1 nonzeros
Model has 1 quadratic constraint
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  QMatrix range    [1e+00, 1e+00]
  Objective range  [1e+00, 1e+00]
  Bounds range     [0e+00, 0e+00]
  RHS range        [3e+00, 3e+00]
Presolve removed 1 rows and 1 columns
Presolve time: 0.00s
Presolve: All rows and columns removed

Barrier solved model in 0 iterations and 0.00 seconds
Optimal objective -3.16227766e+00

In [7]: lc.Pi  # not available with default parameters
Warning: to get QCP duals, please set parameter QCPDual to 1

---------------------------------------------------------------------------
GurobiError                               Traceback (most recent call last)
<ipython-input-7-78718cc9d728> in <module>()
----> 1 lc.Pi  # not available with default parameters

constr.pxi in gurobipy.Constr.__getattr__ (../../src/python/gurobipy.c:19467)()

constr.pxi in gurobipy.Constr.getAttr (../../src/python/gurobipy.c:20278)()


GurobiError: Unable to retrieve attribute 'Pi'

In [8]: m.setParam('QCPDual', 1)
Changed value of parameter QCPDual to 1
   Prev: 0  Min: 0  Max: 1  Default: 0
In [9]: m.optimize()
Optimize a model with 1 rows, 1 columns and 1 nonzeros
Model has 1 quadratic constraint
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  QMatrix range    [1e+00, 1e+00]
  Objective range  [1e+00, 1e+00]
  Bounds range     [0e+00, 0e+00]
  RHS range        [3e+00, 3e+00]
Presolve removed 1 rows and 1 columns
Presolve time: 0.00s
Presolve: All rows and columns removed

Barrier solved model in 0 iterations and 0.00 seconds
Optimal objective -3.16227766e+00
Solving KKT system to obtain QCP duals...

In [10]: lc.Pi # duals on linear constraints now available
Out[10]: 0.0
In [11]: qc.QCPi  # duals also available for quadratic constraints

Out[11]: -0.15811388300841897

msie...@gatech.edu

unread,
Apr 12, 2017, 12:44:43 PM4/12/17
to Gurobi Optimization
Thank you for your answer David, but this is not the problem because I've already set the parameter QCPDual to 1.

Matias
Reply all
Reply to author
Forward
0 new messages