Dual multipliers in optimizer

154 views
Skip to first unread message

Adriana Kiszka

unread,
Mar 11, 2021, 8:14:17 AM3/11/21
to YALMIP
Dear Johan,

I would like to ask, if it is possible to return dual multipliers in optimizer?

Thank you,
Adriana

Johan Löfberg

unread,
Mar 11, 2021, 8:19:07 AM3/11/21
to YALMIP

undocumented fourth output. It is up to you to figure out how that vector of duals relates to the original problem though...

Adriana

unread,
Mar 12, 2021, 4:26:57 AM3/12/21
to YALMIP
I tried it and got the following error:

Check for missing argument or incorrect argument data type in call to function 'is'.

Error in optimizer (line 105)
        if is(u{i},'complex')

Error in model_decomposition_random_nopar_v2 (line 208)
        SolveIterForward = optimizer([cons,theta_cons,
        sol_cons],-h,options,{parPd,parQd,parSol},{A,sigma,h,dual(theta_cons),dual(sol_cons)});

When I solve the problem without optimizer, there is no problem with taking dual of respective constraints.

Johan Löfberg

unread,
Mar 12, 2021, 4:38:17 AM3/12/21
to YALMIP
With 4th argument I mean the duals are turned as the 4th output argument

Adriana

unread,
Mar 12, 2021, 5:03:18 AM3/12/21
to YALMIP
I tried to return only dual of constraint as below, but then I also get error.

rep = 10;
n=2;
m=2;
T=4;
P_min=[0.0800; 0.0800];
P_max=[0.2; 0.2];
Pd = [1.0800    1.0800    1.0800    1.0800;
    0.9700    0.9700    0.9700    0.9700];
Qd = [0.2200    0.2200    0.2200    0.2200;
    0.2000    0.2000    0.2000    0.2000];

lambda_l = sdpvar(m,1);
lambda_u = sdpvar(m,1);

lambda = sdpvar(n,1);

h_bas = sum(lambda_l.*P_min.*(~isinf(P_min))-lambda_u.*P_max.*(~isinf(P_max)));

cons_bas = [lambda_l-lambda_u-lambda ==0,lambda_l>=0,lambda_u>=0];

for t=1:T
    parPd = sdpvar(n,1);
    h = h_bas + sum(lambda.*parPd);
    options = sdpsettings('solver','mosek','verbose',0);
    Solver = optimizer(cons_bas,-h,options, parPd, dual(cons_bas(1)));
    
    result = zeros(rep,1);
    for k=1:rep
        result(k,1) = Solver(Pd(:,t));
    end  
end
    
Error: 
Check for missing argument or incorrect argument data type in call to function 'is'.

Error in optimizer (line 204)
if isempty(u) || (is(u,'linear') & all(sum(base | base,2) == 1) & all(sum(base,2)==1) & all(base(:,1)==0))

Error in test_parfor (line 25)
    Solver = optimizer(cons_bas,-h,options, parPd, dual(cons_bas(1)));

Johan Löfberg

unread,
Mar 12, 2021, 6:11:18 AM3/12/21
to YALMIP
4th OUTPUT argument from the call to the optimizer object when you solve an instance

Adriana

unread,
Mar 12, 2021, 6:45:55 AM3/12/21
to YALMIP
I tried different solutions and none of them is working. Could you please provide any example of it?

Johan Löfberg

unread,
Mar 12, 2021, 7:24:12 AM3/12/21
to YALMIP
[mysolution,diagnostics,dontrememberwhatthisis,duals] = Solver(solveithere)

Adriana

unread,
Mar 15, 2021, 7:25:03 AM3/15/21
to YALMIP
Thank you Johan.

Is it possible to find a description how those duals are calculated? I am asking, because it seems that this returns different result than solving the problem without optimizer and using standard 'dual' function in my example. 

Johan Löfberg

unread,
Mar 15, 2021, 7:58:36 AM3/15/21
to YALMIP
No, it just throws out the duals from the solver. The model has been massaged a great deal and there is no guaranteed definition of what is sent to the solver, it can even differ for different calls as other reductions and presolves can happen depending on the value of the argument

Hence, if they don't make sense from simply looking at them and comparing with what you would get with optimize, you will have to use optimize if you need the duals

潘聪聪

unread,
Jul 6, 2021, 7:41:09 AM7/6/21
to YALMIP
Dear Johan: 


I would like to ask, if it is possible to return dual multipliers in optimizer?
Again, but more specificly, if yalmip will support to return lagrange multiplier by the "optimizer". I am trying to acquire the dual  multiplier without solving each problem by " lamdak1=dual(cst('special1'));  " , as the code "dual(cst) " is very very time consuming if there are quite a lot problems need to be solved. 

Here comes the details:
  1. sol=optimizer(cst, obj, ops, [x], [y]);
  2. tmpsol=sol{[x_unit]};
by the codes above, yalmip reaches a much faster solving as the yalmip time is saved. 
Further, what should I do if  I want to gain the dual multiplier for different [x] ?

I have tried: 
1)  [mysolution,diagnostics,dontrememberwhatthisis,duals] = Solver(cst,obj,ops,[x],[y]); % error

2) sol=optimizer(cst, obj, ops, [x], [y; dual(cst('special1')]); % error

3) parfor for problems to save time;   %erro, as there are other problems……

I'll appreciate it very much if you answer this queation. 

Johan Löfberg

unread,
Jul 6, 2021, 7:57:07 AM7/6/21
to YALMIP
You already know it as you show it in the code, fourth output from optimizer call. It is your task then to figure out how it realtes to the original constraints, which may or may not be a mess
Reply all
Reply to author
Forward
0 new messages