Extracting duals from optimizer() output

72 views
Skip to first unread message

Danylo Malyuta

unread,
May 3, 2016, 10:06:34 AM5/3/16
to YALMIP
I would like to extract the duals from an optimization for which I have to use optimizer() function. Suppose I have the following constraints:

>> constraints
+++++++++++++++++++++++++++++++++++++++++++++++++++++
|    ID|                                  Constraint|
+++++++++++++++++++++++++++++++++++++++++++++++++++++
|    #1|                   Equality constraint 127x1|
|    #2|                   Equality constraint 127x1|
|    #3|                     Equality constraint 1x1|
|    #4|   Element-wise inequality (quadratic) 128x1|
|    #5|               Element-wise inequality 128x1|
|    #6|               Element-wise inequality 128x1|
|    #7|                     Equality constraint 1x1|
|    #8|                 Element-wise inequality 1x1|
|    #9|               Element-wise inequality 128x1|
|   #10|               Element-wise inequality 128x1|
|   #11|               Element-wise inequality 127x1|
|   #12|               Element-wise inequality 127x1|
|   #13|               Element-wise inequality 127x1|
|   #14|               Element-wise inequality 127x1|
|   #15|               Element-wise inequality 127x1|
|   #16|               Element-wise inequality 127x1|
|   #17|    Vectorized second-order cone constraints|
|   #18|    Element-wise inequality (bilinear) 127x1|
|   #19|        Equality constraint (bilinear) 127x1|
|   #20|   Element-wise inequality (quadratic) 127x1|
|   #21|        Equality constraint (bilinear) 127x1|
|   #22|        Equality constraint (bilinear) 128x1|
|   #23|   Element-wise inequality (quadratic) 127x1|
|   #24|   Element-wise inequality (quadratic) 128x1|
|   #25|          Second order cone constraint 128x1|
|   #26|          Second order cone constraint 129x1|
+++++++++++++++++++++++++++++++++++++++++++++++++++++

From what I understand, optimizer has the following call syntax:

[out1,out2,out3,out4] = optimizer(constraints,cost,options,inputs,outputs)

out1 contains the outputs, out2 contains the exit flag, out3 contains the solver message and out4 contains the duals. However, calling out4 for me gives:

out4 = 

    [4466x1 double]

So it's just a cell array made of one cell which is a very long vector. Please tell me, how do I relate the elements of this vector to the duals of my constraints? Thank you!

Johan Löfberg

unread,
May 3, 2016, 2:59:02 PM5/3/16
to YALMIP
You're not really supposed to try to use this, but the first are the equality duals, and the remaining are the duals for elementwise constraints.

To count the number of equalities, you can do

i = find(is(constraints('equalities')));
p = constraints(i);
neq = length(sdpvar(p))

As I said, if you really need duals, optimizer is not easy to use

To connect a value to a specific constraints, you'll have to do a lot of indexing, counting etc etc. This is the price for not using a high-level approach


Danylo Malyuta

unread,
May 3, 2016, 4:15:43 PM5/3/16
to YALMIP
Dear Johan,

I found though through testing a simpler optimization problem that optimizer() duals output is very consistent in outputting the duals of the constraints in the same order as the one in which they were written, but rearranged such that equalities come first, inequalities come second and cone constraints come third. Is this not the case?


Johan Löfberg

unread,
May 3, 2016, 4:23:29 PM5/3/16
to YALMIP
correct

Danylo Malyuta

unread,
May 3, 2016, 6:11:50 PM5/3/16
to YALMIP
What is correct? Do you mean this is the case and optimizer() does consistently output the duals arranged in this way? Thanks!

Johan Löfberg

unread,
May 4, 2016, 3:08:23 AM5/4/16
to YALMIP
You are correct (but the interface does not promise anything. equalities/lp inequalities/socps are always in that order, but the order in every group vs the order in the constraint object I cannot guarantee. additionally, the optimizer object might make various presolves and remove constraints etc)
Reply all
Reply to author
Forward
0 new messages