Description
The following model has a globally unique solution even though it is nonlinear. Not all solvers will recognize that the solution is globally unique. Equation e1 can be solved uniquely w.r.t. x1. Equation e2 can then be solved uniquely w.r.t. x2 even though it is nonlinear in x1 since x1 has a unique value. Equation e3 and e4 are now linear, given the values of x1 and x2, and they can be solved uniquely.
Small Model of Type : CNS
Category : GAMS Test library
Main file : cns05.gms
$title CNS model with globally unique solution (cns05,SEQ=95)
$onText
The following model has a globally unique solution even though it
is nonlinear.
Not all solvers will recognize that the solution is globally unique.
Equation e1 can be solved uniquely w.r.t. x1.
Equation e2 can then be solved uniquely w.r.t. x2 even though it
is nonlinear in x1 since x1 has a unique value.
Equation e3 and e4 are now linear, given the values of x1 and x2,
and they can be solved uniquely.
$offText
$if not set TESTTOL $set TESTTOL 1e-6
scalar tol / %TESTTOL% /;
$if not set SLOWOK $set SLOWOK 0
scalar slowOK 'slow solves are OK: just abort.noerror in this case' / %SLOWOK% /;
variable x1, x2, x3, x4;
equation e1, e2, e3, e4;
e1 .. x1 =e= 3;
e2 .. x2 =e= sqr(x1);
e3 .. x1*x3 + x4 =e= 5;
e4 .. x3 - x2*x4 =e= 11;
model cns05 / all /;
option limrow = 0, limcol = 0;
solve cns05 using cns;
abort.noError$[slowOK and %solveStat.resourceInterrupt% = cns05.solvestat] 'Solve too slow';
abort$(cns05.solvestat <> %solveStat.normalCompletion%
or (cns05.modelstat <> %modelStat.solvedUnique%) and (cns05.modelstat <> %modelStat.solved%))
'bad return codes', cns05.solvestat, cns05.modelstat;
abort$(abs(x1.l- 3) > tol) 'bad x1.l';
abort$(abs(x2.l- 9) > tol) 'bad x2.l';
abort$(abs(x3.l- 2) > tol) 'bad x3.l';
abort$(abs(x4.l+ 1) > tol) 'bad x4.l';
abort$(abs(e1.l- 3) > tol) 'bad e1.l';
abort$(abs(e2.l- 0) > tol) 'bad e2.l';
abort$(abs(e3.l- 5) > tol) 'bad e3.l';
abort$(abs(e4.l-11) > tol) 'bad e4.l';