Extracting Dual Variables

804 views
Skip to first unread message

J Domke

unread,
Apr 3, 2013, 8:29:00 AM4/3/13
to yal...@googlegroups.com
Hello,

Thanks for YALMIP-- it is extremely useful.  I have a simple example where I'd like to extract the dual variables. but am struggling to do so.  A simple toy version would be:

xlen = 20;
ylen = 5;
B    = rand(ylen,xlen);

theta = randn(xlen,1);
phi   = randn(ylen,1);

x = sdpvar(length(theta),1);
y = sdpvar(length(phi)  ,1);

obj = theta'*x + phi'*y + x'*x + y'*y + 2*y'*y;
con = [B*x==y; x>=0; y>=0];

solvesdp(con,obj);

A      = double(obj);
lambda = dual(con(1))


In which case YALMIP (I think) converts to a quadratic program, and all is groovy.  However, if I make a general nonlinear program, for example as follows:

xlen = 20;
ylen = 5;
B    = rand(ylen,xlen);

theta = randn(xlen,1);
phi   = randn(ylen,1);

x = sdpvar(length(theta),1);
y = sdpvar(length(phi)  ,1);

obj = theta'*x + phi'*y + x'*x + y'*y - 2*entropy(y);
con = [B*x==y; x>=0; y>=0];

solvesdp(con,obj);

A      = double(obj);
lambda = dual(con(1))


YALMIP still solves the problem just fine (using fmincon), but the dual variables are all set to NaN.  Is there anything I can do to get them?  Thank you again!

Johan Löfberg

unread,
Apr 3, 2013, 8:34:54 AM4/3/13
to yal...@googlegroups.com
Nope, no support for dual in a nonlinear program at the moment.

You can catch the dual data though, but you will have to figure out which constraint they relate to
sol = solvesdp(con,obj,sdpsettings('savesolveroutput',1))
sol.solveroutput.lambda.eqlin


J Domke

unread,
Apr 3, 2013, 8:48:37 AM4/3/13
to yal...@googlegroups.com
Great-- thanks for the easy workaround!

Omid

unread,
May 20, 2014, 6:35:15 AM5/20/14
to yal...@googlegroups.com
Dear Johan,

For a NLP, as you said, we can get the dual variables using "sdpsettings('savesolveroutput',1)".

In the case of FMINCON, this code "sol.solveroutput.lambda" gives all of dual variables.
But in the case of IPOPT, if I run this code "sol.solveroutput" I get empty Dual. (See following example)

K>> sol.solveroutput

ans = 

              x: [16x1 double]
           info: [1x1 struct]
         Primal: [50x1 double]
           Dual: []
          Slack: []
        problem: 0
        infostr: 'Successfully solved (IPOPT)'
    solverinput: []

Is there any way to get the dual variables in the case of IPOPT ?

Thank you in advance.
Omid

Johan Löfberg

unread,
May 20, 2014, 6:44:46 AM5/20/14
to yal...@googlegroups.com
ipopt returns the dual variable in the output called info

sdpvar x
sol
= solvesdp([x^3 <= 1],-x,sdpsettings('solver','ipopt','savesolveroutput',1));
sol
.solveroutput.info.lambda

(the struct solveroutput is a bit confusing since there is a bug in the code that generates it, so there is data repeated from the general structure YALMIP creates to communicate internally)
Message has been deleted

Ye Wang

unread,
Sep 4, 2017, 11:46:59 AM9/4/17
to YALMIP
Hi,
After extracting the dual variables from ipopt using sol.solveroutput.info.lambda,
how can I identify the dual variables of equality constraints?

Johan Löfberg

unread,
Sep 4, 2017, 12:02:51 PM9/4/17
to YALMIP
that's basically for you to find out. you will have to look at examples and then reverse engineer the structure, and study the ipopt manual in opti toolbox of course. no fun. 

Reply all
Reply to author
Forward
0 new messages