sdp01.gms : Test of correct solving a simple conic program

Description

Test of correctness of solving a simple conic program (PSD and SOC cones)
by using the semidefinite programming example sdo1 from the Mosek manual.

http://docs.mosek.com/7.0/capi/Semidefinite_optimization.html

The problem is
min   2*(barX(0,0) + barX(1,0) + barX(1,1) + barX(2,1) + barX(2,2)) + x0
s.t.  barX(0,0) + barX(1,1) + barX(2,2) + x0 = 1
      barX(0,0) + barX(1,1) + barX(2,2) + 2*(barX(1,0) + barX(2,0) + barX(2,1)) + x1 + x2 = 0.5
      x0 >= sqrt(x1^2 + x2^2)
      barX symmetric and positive semidefinite


Small Model of Type : QCP


Category : GAMS Test library


Main file : sdp01.gms

$Title Test of correct solving a simple conic program (PSD and SOC cones). (SDP01,SEQ=630)

$ontext
Test of correctness of solving a simple conic program (PSD and SOC cones)
by using the semidefinite programming example sdo1 from the Mosek manual.

http://docs.mosek.com/7.0/capi/Semidefinite_optimization.html

The problem is
min   2*(barX(0,0) + barX(1,0) + barX(1,1) + barX(2,1) + barX(2,2)) + x0
s.t.  barX(0,0) + barX(1,1) + barX(2,2) + x0 = 1
      barX(0,0) + barX(1,1) + barX(2,2) + 2*(barX(1,0) + barX(2,0) + barX(2,1)) + x1 + x2 = 0.5
      x0 >= sqrt(x1^2 + x2^2)
      barX symmetric and positive semidefinite
$offtext

$if not set TESTTOL $set TESTTOL 1e-6

Set i / 0 * 2 /;
alias(i, ip);

Variables barX(i,i) PSDMATRIX
          x(i)      scalar variables
          z         objective variable
;
x.lo('0') = 0;

Parameters barAobj(i,i)  coefficients of barX in objective
           barAe1(i,i)   coefficients of barX in e1
           barAe2(i,i)   coefficients of barX in e2
;

Table barAobj(i,i)
   0    1    2
0  2.0  1.0  0.0
1  1.0  2.0  1.0
2  0.0  1.0  2.0
;

* identity matrix
barAe1(i,i) = 1.0;

* all-one matrix
barAe2(i,ip) = 1.0;

Equations obj, e1, e2, e3;

obj.. z   =e= sum((i,ip), barAobj(i,ip) * barX(i,ip)) + x('0');
e1..  1   =e= sum((i,ip), barAe1(i,ip)  * barX(i,ip)) + x('0');
e2..  0.5 =e= sum((i,ip), barAe2(i,ip)  * barX(i,ip)) + x('1') + x('2');
e3..  - sqr(x('0')) + sqr(x('1')) + sqr(x('2')) =l= 0;

Model m / all /;

option qcp = mosek;
m.dictfile = 1;
m.optfile = 1;

$echo SDPSOLUFILE sdpsol.gdx > mosek.opt

Solve m minimizing z using QCP;

display barX.l;

parameter zobj optimal value / 7.0571048621e-01 /;

abort$(m.modelstat <> %modelstat.optimal%) 'Not solved to optimality';
abort$(abs(z.l - zobj) > %TESTTOL%) 'Optimal value wrong';

Parameters A(i,i) 'an i x i matrix as parameter'
           ev(i)  'eigenvalues of a i x i matrix'
;

* check whether barX.l from GAMS solution is psd
* (should work in this example as all PSD matrix entries appear in constraints)
A(i,ip) = barX.l(i,ip);
execute_unload 'sdpsolpar.gdx' i, A;
execute 'eigenvalue sdpsolpar.gdx i A sdp_ev.gdx ev > %system.nullfile%'
execute_load 'sdp_ev.gdx' ev;
display ev;
abort$(smin(i, ev(i)) < -%TESTTOL%) 'barX.l not PSD'


* check whether barX.l and barX.m from GDX solution file are psd
execute_loadpoint 'sdpsol.gdx';

display barX.l;
A(i,ip) = barX.l(i,ip);
execute_unload 'sdpsolpar.gdx' i, A;
execute 'eigenvalue sdpsolpar.gdx i A sdp_ev.gdx ev > %system.nullfile%'
execute_load 'sdp_ev.gdx' ev;
display ev;
abort$(smin(i, ev(i)) < -%TESTTOL%) 'barX.l from GDX solution file not PSD'


display barX.m;
A(i,ip) = barX.m(i,ip);
execute_unload 'sdpsolpar.gdx' i, A;
execute 'eigenvalue sdpsolpar.gdx i A sdp_ev.gdx ev > %system.nullfile%'
execute_load 'sdp_ev.gdx' ev;
display ev;
abort$(smin(i, ev(i)) < -%TESTTOL%) 'barX.m from GDX solution file not PSD'