expcone1.gms : test conic problem using exponential cone

Description

Test of correctness of the levels and marginals returned.
Although this test should work for all NLP solvers,
it is designed specifically to test a conic solvers, e.g., Mosek.
It also tests whether slight variations in the algebraic formulation
of the exponential cone work.


Small Model of Type : NLP


Category : GAMS Test library


Main file : expcone1.gms

$title Test of correct handling of exponential cone in NLP (EXPCONE1,SEQ=800)

$ontext
Test of correctness of the levels and marginals returned.
Although this test should work for all NLP solvers,
it is designed specifically to test a conic solvers, e.g., Mosek.
It also tests whether slight variations in the algebraic formulation
of the exponential cone work.


The model is taken from (6.9) in
  https://docs.mosek.com/9.0/capi/tutorial-ceo-shared.html

Contributor: Stefan
$offtext

$if not set TESTTOL $set TESTTOL 1e-5
$if not set MCHECKS $set MCHECKS 1

Nonnegative Variables x0, x1;
Variable x2, z;
Equations e1, e2a, e2b, e2c, e2d, objdef;

objdef.. x0 + x1 =E= z;
e1.. x0 + x1 + x2 =E= 1;
e2a.. x0 =G= x1 * exp(x2/x1);
e2b.. x0 + exp(x2/x1) * (-x1) =G= 0;
e2c.. -x0 =L= -x1 * exp(x2/x1);
e2d.. x0 * (-1) + x1 * exp(1/x1*x2) =L= 0;

Model ma / objdef, e1, e2a /;
Model mb / objdef, e1, e2b /;
Model mc / objdef, e1, e2c /;
Model md / objdef, e1, e2d /;

option bratio = 1;

Scalar modelnr;
Scalar solvestat, modelstat, e2l;
for( modelnr = 1 to 4,
  x1.l = 1;

  if( modelnr = 1, Solve ma min z using NLP; solvestat = ma.solvestat; modelstat = ma.modelstat; e2l = e2a.l )
  if( modelnr = 2, Solve mb min z using NLP; solvestat = mb.solvestat; modelstat = mb.modelstat; e2l = e2b.l )
  if( modelnr = 3, Solve mc min z using NLP; solvestat = mc.solvestat; modelstat = mc.modelstat; e2l = e2c.l )
  if( modelnr = 4, Solve md min z using NLP; solvestat = md.solvestat; modelstat = md.modelstat; e2l = e2d.l )

  abort$(solvestat <> %solvestat.NormalCompletion%) "wrong solver status, expected normal completion", solvestat ;
  abort$(modelstat > %modelstat.LocallyOptimal% and modelstat <> %modelstat.FeasibleSolution%) "wrong model status, expected at least feasibility", modelstat ;

  abort$(abs(x0.l - 0.61181852) > %TESTTOL%) "wrong x0.l, expected 0.61181852", x0.l ;
  abort$(abs(x1.l - 0.17036977) > %TESTTOL%) "wrong x1.l, expected 0.17036977", x1.l ;
  abort$(abs(x2.l - 0.21781170) > %TESTTOL%) "wrong x2.l, expected 0.21781170", x2.l ;
  abort$(abs(e1.l - 1) > %TESTTOL%) "wrong e1.l, expected 1", e1.l ;
  abort$(abs(e2l) > %TESTTOL%) "wrong e2?.l, expected zero", e2l ;
  abort$(abs(z.l  - 0.78218829) > %TESTTOL%) "wrong z.l, expected 0.78218829", z.l ;

  if( %MCHECKS% <> 0,
    abort$(abs(x0.m) > %TESTTOL%) "wrong x0.m, expected zero", x0.m ;
    abort$(abs(x1.m) > %TESTTOL%) "wrong x1.m, expected zero", x1.m ;
    abort$(abs(x2.m) > %TESTTOL%) "wrong x2.m, expected zero", x2.m ;
    abort$(abs(e1.m - 0.78218829) > %TESTTOL%) "wrong e1.m, expected 0.78218829", e1.m ;
    abort$(modelnr = 1 and abs(e2a.m - 0.21781171) > %TESTTOL%) "wrong e2a.m, expected 0.21781171", e2a.m ;
    abort$(modelnr = 2 and abs(e2b.m - 0.21781171) > %TESTTOL%) "wrong e2b.m, expected 0.21781171", e2b.m ;
    abort$(modelnr = 3 and abs(e2c.m + 0.21781171) > %TESTTOL%) "wrong e2c.m, expected -0.21781171", e2c.m ;
  )
)