emp30.gms : Test JAMS/EMP on implicit variables appearing in constraints

Description

Test the case where there are constraints on implicit variables.

Contributors: Youngdae Kim & Steve Dirkse, Feb 2018


Small Model of Type : GAMS


Category : GAMS Test library


Main file : emp30.gms

$title 'Test JAMS/EMP on implicit variables appearing in constraints' (EMP30,SEQ=744)

$onText
Test the case where there are constraints on implicit variables.

Contributors: Youngdae Kim & Steve Dirkse, Feb 2018

$offText
$if not set TESTTOL $set TESTTOL 1e-3
scalars tol / %TESTTOL% /;
file opt  / 'jams.opt' /;
file info / '%emp.info%' /;

variable obj, z;
positive variable t;

equation defobj, cons, defz;

defobj..
    obj =E= z + 2*t + 1;

cons..
    z + 2*t + 1 =G= 4;

defz..
    z =E= sqr(t);

model m / defobj, cons, defz /;

put info 'equilibrium';
put / 'implicit z defz';
put / 'min', obj, z, t, defobj, cons;
putclose;

* Test with substitution.

putclose opt
   'Dict         implDict.txt' /
   'FileName     impl.gms'     /
   'ImplVarModel substitution'
   ;


m.optfile = 1;
solve m using emp;

abort$[ m.solvestat <> %solveStat.normalCompletion% ]
     'wrong m.solvestat', m.solvestat;
abort$[ m.modelstat <> %modelStat.locallyOptimal% ]
     'wrong m.modelstat', m.modelstat;
abort$[ abs(obj.l - 4) > tol ] 'bad obj.l', obj.l;
abort$[ abs(t.l   - 1) > tol ] 'bad t.l', t.l;
abort$[ abs(z.l   - 1) > tol ] 'bad z.l', z.l;

obj.l = 0;
t.l = 0;
z.l = 0;
defobj.m = 0;
cons.m = 0;
defz.m = 0;

$onEchoV > impl_gms
***********************************************
* written by GAMS/JAMS at 11/16/17 11:06:44
* for more information use JAMS option "Dict"
***********************************************

Variables  x2,x3,u2;

Positive Variables  x3;

Positive Variables  u2;

Equations  e2,e3,dL_dx3;


e2..    x2 + 2*x3 =G= 3;

e3.. -sqr(x3) + x2 =E= 0;

dL_dx3.. 2 + (1)*((-2*x3)/(-1)) - 2*u2 - ((1)*((-2*x3)/(-1)))*u2 =G= 0;

Model m / e2.u2,e3.x2,dL_dx3.x3 /;

File implvarfile / '%gams.scrdir%implvar.dat' /;
Put implvarfile;

$onPutV
x2
$offPut

m.limrow=0; m.limcol=0;

Solve m using MCP;
$offEcho

execute 'grep -v " written by GAMS" impl_gms > impl.gms.want'
execute 'grep -v " written by GAMS" impl.gms > impl.gms.got'
execute '=diff -I reslim -bw impl.gms.want impl.gms.got'
abort$errorlevel 'Files impl.gms.want and impl.gms.got differ';

$onEcho > impl_dict
* written by GAMS/JAMS at 11/16/17 11:16:28

********************************************************************************
 Contents
 1 Content of EMP Information File
 2 Processed EMP Information
 3 Dictionary
  3.1 Constraints
  3.2 Variables
********************************************************************************


 1 Content of EMP Information File
 ---------------------------------

     1:equilibrium
     2:implicit z defz
     3:min obj z t defobj cons


 2 Processed EMP Information
 ---------------------------


 3 Dictionary
 ------------
  3.1 Constraints
  ---------------

      {reformulated}  defobj
                  e2  cons
                  e3  defz
              dL_dx3  {new}


  3.2 Variables
 --------------

      {reformulated}  obj
                  x2  z
                  x3  t
                  u2  {new}
$offEcho

execute 'grep -v " written by GAMS" impl_dict > impldict.txt.want'
execute 'grep -v " written by GAMS" implDict.txt > impldict.txt.got'
execute '=diff -bw impldict.txt.want impldict.txt.got'
abort$errorlevel 'Files impldict.txt.want and impldict.txt.got differ';

* Test with switching.

putclose opt
   'Dict         implSwitchingDict.txt' /
   'FileName     implSwitching.gms'     /
   'ImplVarModel switching'
   ;

m.optfile = 1;
solve m using emp;

abort$[ m.solvestat <> %solveStat.normalCompletion% ]
     'wrong m.solvestat', m.solvestat;
abort$[ m.modelstat <> %modelStat.locallyOptimal% ]
     'wrong m.modelstat', m.modelstat;
abort$[ abs(obj.l - 4) > tol ] 'bad obj.l', obj.l;
abort$[ abs(t.l   - 1) > tol ] 'bad t.l', t.l;
abort$[ abs(z.l   - 1) > tol ] 'bad z.l', z.l;

obj.l = 0;
t.l = 0;
z.l = 0;
defobj.m = 0;
cons.m = 0;
defz.m = 0;

$onEchoV > implSwitching_gms
***********************************************
* written by GAMS/JAMS at 11/16/17 11:21:47
* for more information use JAMS option "Dict"
***********************************************

Variables  x2,x3,u2,u3_4;

Positive Variables  x3;

Positive Variables  u2;

Equations  e2,e3,dL_dx2_4,dL_dx3;


e2..    x2 + 2*x3 =G= 3;

e3.. -sqr(x3) + x2 =E= 0;

dL_dx2_4.. 1 - u3_4 + eps*x2 =E= 0;

dL_dx3.. 2 - 2*u2 - (-2*x3)*u3_4 =G= 0;

Model m / e2.u2,e3.x2,dL_dx2_4.u3_4,dL_dx3.x3 /;

File implvarfile / '%gams.scrdir%implvar.dat' /;
Put implvarfile;

$onPutV
x2
u3_4
$offPut

m.limrow=0; m.limcol=0;

Solve m using MCP;
$offEcho

execute 'grep -v " written by GAMS" implSwitching_gms > implSwitching.gms.want'
execute 'grep -v " written by GAMS" implSwitching.gms > implSwitching.gms.got'
execute '=diff -I reslim -bw implSwitching.gms.want implSwitching.gms.got'
abort$errorlevel 'Files implSwitching.gms.want and implSwitching.gms.got differ';

$onEcho > implSwitching_dict
* written by GAMS/JAMS at 11/16/17 11:21:47

********************************************************************************
 Contents
 1 Content of EMP Information File
 2 Processed EMP Information
 3 Dictionary
  3.1 Constraints
  3.2 Variables
********************************************************************************


 1 Content of EMP Information File
 ---------------------------------

     1:equilibrium
     2:implicit z defz
     3:min obj z t defobj cons


 2 Processed EMP Information
 ---------------------------


 3 Dictionary
 ------------
  3.1 Constraints
  ---------------

      {reformulated}  defobj
                  e2  cons
                  e3  defz
            dL_dx2_4  {new}
              dL_dx3  {new}


  3.2 Variables
 --------------

      {reformulated}  obj
                  x2  z
                  x3  t
                  u2  {new}
                u3_4  {new}
$offEcho

execute 'grep -v " written by GAMS" implSwitching_dict > implSwitchingDict.txt.want'
execute 'grep -v " written by GAMS" implSwitchingDict.txt > implSwitchingDict.txt.got'
execute '=diff -bw implSwitchingDict.txt.want implSwitchingDict.txt.got'
abort$errorlevel 'Files implSwitchingDict.txt.want and implSwitchingDict.txt.got differ';

* Test with replication.

putclose opt
  'Dict         implRepDict.txt' /
  'FileName     implRep.gms'     /
  'ImplVarModel replication'     ;

solve m using emp;

abort$[ m.solvestat <> %solveStat.normalCompletion% ]
     'wrong m.solvestat', m.solvestat;
abort$[ m.modelstat <> %modelStat.locallyOptimal% ]
     'wrong m.modelstat', m.modelstat;
abort$[ abs(obj.l - 4) > tol ] 'bad obj.l', obj.l;
abort$[ abs(t.l   - 1) > tol ] 'bad t.l', t.l;
abort$[ abs(z.l   - 1) > tol ] 'bad z.l', z.l;

obj.l = 0;
t.l = 0;
z.l = 0;
defobj.m = 0;
cons.m = 0;
defz.m = 0;

$onEchoV > implRep_gms
***********************************************
* written by GAMS/JAMS at 11/17/17 15:33:49
* for more information use JAMS option "Dict"
***********************************************

Variables  x2_4,x3,u2,u3_4;

Positive Variables  x3;

Positive Variables  u2;

Equations  e2,e3_4,dL_dx2_4,dL_dx3;


e2..    x2_4 + 2*x3 =G= 3;

e3_4.. -sqr(x3) + x2_4 =E= 0;

dL_dx2_4.. 1 - u3_4 + eps*x2_4 =E= 0;

dL_dx3.. 2 - 2*u2 - (-2*x3)*u3_4 =G= 0;

Model m / e2.u2,e3_4.u3_4,dL_dx2_4.x2_4,dL_dx3.x3 /;

File implvarfile / '%gams.scrdir%implvar.dat' /;
Put implvarfile;

$onPutV
x2_4
u3_4
$offPut

m.limrow=0; m.limcol=0;

Solve m using MCP;
$offEcho

execute 'grep -v " written by GAMS" implRep_gms > implRep.gms.want'
execute 'grep -v " written by GAMS" implRep.gms > implRep.gms.got'
execute '=diff -I reslim -bw implRep.gms.want implRep.gms.got'
abort$errorlevel 'Files implRep.gms.want and implRep.gms.got differ';

$onEcho > implRep_dict
* written by GAMS/JAMS at 11/17/17 15:34:26

********************************************************************************
 Contents
 1 Content of EMP Information File
 2 Processed EMP Information
 3 Dictionary
  3.1 Constraints
  3.2 Variables
********************************************************************************


 1 Content of EMP Information File
 ---------------------------------

     1:equilibrium
     2:implicit z defz
     3:min obj z t defobj cons


 2 Processed EMP Information
 ---------------------------


 3 Dictionary
 ------------
  3.1 Constraints
  ---------------

      {reformulated}  defobj
                  e2  cons
                e3_4  defz
            dL_dx2_4  {new}
              dL_dx3  {new}


  3.2 Variables
 --------------

      {reformulated}  obj
                x2_4  z
                  x3  t
                  u2  {new}
                u3_4  {new}
$offEcho

execute 'grep -v " written by GAMS" implRep_dict > implRepDict.txt.want'
execute 'grep -v " written by GAMS" implRepDict.txt > implRepDict.txt.got'
execute '=diff -bw implRepDict.txt.want implRepDict.txt.got'
abort$errorlevel 'Files implRepDict.txt.want and implRepDict.txt.got differ';