$TITLE 'Test JAMS/EMP on implicit variable handling' (EMP23,SEQ=705) $ontext Test JAMS behavior on a small equilibrium model with implicit variables. Contributors: Youngdae Kim & Steve Dirkse, Dec 2016 $offtext $if not set TESTTOL $set TESTTOL 1e-3 scalars tol / %TESTTOL% /; file opt / 'jams.opt' /; file info / '%emp.info%' /; sets i agents / 1*2 /; * The scalar files generated depend on the variable declaration order, * so do not change the declarations lightly * The objective variable is a shared variable among agents. * We set the objective variable as an implicit variable to implement shared * objective variable. variable objExp(i) obj x ; positive variable p; equation defobjExp(i) defobj defxlo defxup ; defobjExp(i).. objExp(i) =E= sqr(p) - p - sqr(x) - x; defxlo.. x =G= -p; defxup.. x =L= p; model me 'explicit formulation' / defobjExp, defxlo, defxup /; put info 'equilibrium'; put / 'min', objExp('1'), p, defobjExp('1'); put / 'max', objExp('2'), x, defobjExp('2'), defxlo, defxup; putclose; putclose opt 'Dict explDict.txt' / 'FileName expl.gms' ; me.optfile = 1; solve me using emp; abort$[me.solvestat <> %solvestat.NormalCompletion%] 'wrong me.solvestat', me.solvestat; abort$[me.modelstat > %modelstat.LocallyOptimal%] 'wrong me.modelstat', me.modelstat; abort$[ abs(objExp.l('1')-0) > tol ] 'bad objExp.l("1")', objExp.l; abort$[ abs(objExp.l('2')-0) > tol ] 'bad objExp.l("2")', objExp.l; abort$[ abs(x.l+.5) > tol ] 'bad x.l', x.l; abort$[ abs(p.l-.5) > tol ] 'bad p.l', p.l; x.l = 0; p.l = 0; defxlo.m = 0; defxup.m = 0; $onecho > expl_gms *********************************************** * written by GAMS/JAMS at 12/04/16 16:32:21 * for more information use JAMS option "Dict" *********************************************** Variables x3,x4,u3,u4; Negative Variables u3; Positive Variables x4; Positive Variables u4; Equations e3,e4,dL_dx3,dL_dx4; e3.. 0 =L= x3 + x4; e4.. 0 =G= x3 - x4; dL_dx3.. (-(-1 - 2*x3))/(1) + u3 + u4 =E= 0; dL_dx4.. (-(-1 + 2*x4))/(-1) =G= 0; Model m / e3.u3,e4.u4,dL_dx3.x3,dL_dx4.x4 /; m.limrow=0; m.limcol=0; Solve m using MCP; $offecho execute 'grep -v " written by GAMS" expl_gms > expl.gms.want' execute 'grep -v " written by GAMS" expl.gms > expl.gms.got' execute '=diff -I reslim -bw expl.gms.want expl.gms.got' abort$errorlevel 'Files expl.gms.want and expl.gms.got differ'; $onecho > expl_dict * written by GAMS/JAMS at 12/04/16 16:32:21 ******************************************************************************** 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:min objExp('1') p defobjExp('1') 3:max objExp('2') x defobjExp('2') defxlo defxup 2 Processed EMP Information --------------------------- 3 Dictionary ------------ 3.1 Constraints --------------- {reformulated} defobjExp(1) {reformulated} defobjExp(2) e3 defxlo e4 defxup dL_dx3 {new} dL_dx4 {new} 3.2 Variables -------------- {reformulated} objExp(1) {reformulated} objExp(2) x3 x x4 p u3 {new} u4 {new} $offecho execute 'grep -v " written by GAMS" expl_dict > expldict.txt.want' execute 'grep -v " written by GAMS" explDict.txt > expldict.txt.got' execute '=diff -bw expldict.txt.want expldict.txt.got' abort$errorlevel 'Files expldict.txt.want and expldict.txt.got differ'; defobj.. obj =E= sqr(p) - p - sqr(x) - x; model mi 'implicit formulation' / defobj, defxlo, defxup /; put info 'equilibrium'; put / 'implicit obj defobj'; put / 'min', obj, p; put / 'max', obj, x, defxlo, defxup; putclose; * testing with implicit putclose opt 'Dict implDict.txt' / 'FileName impl.gms' / 'ImplVarModel substitution' ; mi.optfile = 1; solve mi using emp; abort$[mi.solvestat <> %solvestat.NormalCompletion%] 'wrong mi.solvestat', mi.solvestat; abort$[mi.modelstat > %modelstat.LocallyOptimal%] 'wrong mi.modelstat', mi.modelstat; abort$[ abs(obj.l-0) > tol ] 'bad obj.l', obj.l; abort$[ abs(x.l+.5) > tol ] 'bad x.l', x.l; abort$[ abs(p.l-.5) > tol ] 'bad p.l', p.l; obj.l = 0; x.l = 0; p.l = 0; defobj.m = 0; defxlo.m = 0; defxup.m = 0; $onechoV > impl_gms *********************************************** * written by GAMS/JAMS at 11/15/17 22:32:04 * for more information use JAMS option "Dict" *********************************************** Variables x2,x3,u2,u3; Negative Variables u2; Positive Variables x3; Positive Variables u3; Equations e2,e3,dL_dx2,dL_dx3; e2.. 0 =L= x2 + x3; e3.. 0 =G= x2 - x3; dL_dx2.. (-(-1 - 2*x2))/(1) + u2 + u3 =E= 0; dL_dx3.. (-(-1 + 2*x3))/(-1) =G= 0; Model m / e2.u2,e3.u3,dL_dx2.x2,dL_dx3.x3 /; File implvarfile / '%gams.scrdir%implvar.dat' /; Put implvarfile; $onPutV $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 12/04/16 16:33:55 ******************************************************************************** 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 obj defobj 3:min obj p 4:max obj x defxlo defxup 2 Processed EMP Information --------------------------- 3 Dictionary ------------ 3.1 Constraints --------------- {reformulated} defobj e2 defxlo e3 defxup dL_dx2 {new} dL_dx3 {new} 3.2 Variables -------------- {reformulated} obj x2 x x3 p u2 {new} u3 {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'; * testing with replication putclose opt 'Dict implRepDict.txt' / 'FileName implRep.gms' / 'ImplVarModel replication' ; solve mi using emp; abort$[mi.solvestat <> %solvestat.NormalCompletion%] 'wrong mi.solvestat', mi.solvestat; abort$[mi.modelstat > %modelstat.LocallyOptimal%] 'wrong mi.modelstat', mi.modelstat; abort$[ abs(obj.l-0) > tol ] 'bad obj.l', obj.l; abort$[ abs(x.l+.5) > tol ] 'bad x.l', x.l; abort$[ abs(p.l-.5) > tol ] 'bad p.l', p.l; obj.l = 0; x.l = 0; p.l = 0; defobj.m = 0; defxlo.m = 0; defxup.m = 0; $onechoV > implRep_gms *********************************************** * written by GAMS/JAMS at 11/17/17 15:31:35 * for more information use JAMS option "Dict" *********************************************** Variables x2,x3,u2,u3; Negative Variables u2; Positive Variables x3; Positive Variables u3; Equations e2,e3,dL_dx2,dL_dx3; e2.. 0 =L= x2 + x3; e3.. 0 =G= x2 - x3; dL_dx2.. (-(-1 - 2*x2))/(1) + u2 + u3 =E= 0; dL_dx3.. (-(-1 + 2*x3))/(-1) =G= 0; Model m / e2.u2,e3.u3,dL_dx2.x2,dL_dx3.x3 /; File implvarfile / '%gams.scrdir%implvar.dat' /; Put implvarfile; $onPutV $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:32:09 ******************************************************************************** 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 obj defobj 3:min obj p 4:max obj x defxlo defxup 2 Processed EMP Information --------------------------- 3 Dictionary ------------ 3.1 Constraints --------------- {reformulated} defobj e2 defxlo e3 defxup {reformulated} defobj dL_dx2 {new} dL_dx3 {new} 3.2 Variables -------------- {reformulated} obj x2 x x3 p u2 {new} u3 {new} {reformulated} obj $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';