Different Optimal Solutions using YALMIP and CVX When Solving a LP

31 views
Skip to first unread message

Zhe Yu

unread,
Sep 17, 2018, 11:24:06 PM9/17/18
to YALMIP
Hello guys,

I tried to solve a simple LP (both primal and dual problems) using YALMIP and verify the duality gap is 0. I am pretty sure the dual formulation is correct. However, YALMIP could not give the same objective value for primal and dual problems. So I tried to solve exactly the same problem by using CVX and the duality gap was 0. By checking the results from CVX, I could tell YALMIP did not give the optimal solution and it was really confusing.

I have attached the codes for YALMIP and CVX.

Thank you very much for your time if you could shed some light!


CVX_TEST.m
YALMIP_TEST.m

Johan Löfberg

unread,
Sep 18, 2018, 1:10:46 AM9/18/18
to YALMIP
I suspect you want lambda = sdpvar(N,J,T,'full') etc, as N=J and thus these square matrices are symmetric as that is default

Johan Löfberg

unread,
Sep 18, 2018, 1:16:38 AM9/18/18
to YALMIP
btw, I note your two model looks different, so note that you can reuse your work much more easily and simply had written 

constraints_p = [lambda(1,1,1) + lambda(2,1,1) == 90;
    lambda(1,2,1) + lambda(2,2,1) == 100;
    a(1,1) >= (lambda(1,1,1) + lambda(1,2,1))/10;
    a(2,1) >= (lambda(2,1,1) + lambda(2,2,1))/10;
    q_l(1,1) + q_r(1,1) >= 1.2*(a(1,1)*0.15 + (lambda(1,1,1) + lambda(1,2,1))/300);
    q_l(2,1) + q_r(2,1) >= 1.2*(a(2,1)*0.15 + (lambda(2,1,1) + lambda(2,2,1))/300);
    a(1,1) >= 0; a(2,1) >= 0; q_r(1,1) >= 0; q_r(2,1) >= 0;
    lambda(1,1,1) >= 0; lambda(1,2,1) >= 0; lambda(2,1,1) >= 0; lambda(2,2,1) >= 0]

Zhe Yu

unread,
Sep 18, 2018, 10:51:31 AM9/18/18
to YALMIP
Hello professor Löfberg, thank you very much for your quick help. This makes more sense to me. I have been having trouble when setting N and J to be equal. However, the duality gap is zero no matter how you change the parameters when N is not equal to J.

Johan Löfberg

unread,
Sep 18, 2018, 10:56:56 AM9/18/18
to YALMIP
I get zero gap

dual_gap =

  -7.3767e-10

Zhe Yu

unread,
Sep 18, 2018, 10:59:38 AM9/18/18
to YALMIP
Hello professor Löfberg, thank you very much for your quick help. Writing in this way makes it more concise.

Zhe Yu

unread,
Sep 18, 2018, 11:10:33 AM9/18/18
to YALMIP
It worked when I use 'full' as an argument. Thanks again!
Reply all
Reply to author
Forward
0 new messages