GAMS [ Home | Downloads | Documentation | Solvers | APIs | Tools | Model Libraries | Resources | Sales | Support | Contact Us | Search ]

emp24.gms : Test JAMS/EMP on implicit variable handling

Description

Test JAMS behavior on a small equilibrium model with implicit variables.

Contributors: Youngdae Kim & Steve Dirkse, Dec 2016

Small Model of Type : GAMS


Category : GAMS Test library


Main file : emp24.gms

$TITLE 'Test JAMS/EMP on implicit variable handling' (EMP24,SEQ=706)

$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
$set P 120
scalars tol / %TESTTOL% /;
file opt  / 'jams.opt' /;
file info / '%emp.info%' /;

sets i    all agents   / 0*5 /
     j(i) generators   / 1*5 /
     k        plants   /  1  /
     ;
alias(j,jj);

parameters
    U0
    U(j,k)
    M(j,k)
    b(j,k)
    d
    a
    price
    total_sum
    ;

U0 = 5;
U(j,k) = uniform(0,10);
M(j,k) = uniform(0.4,0.8);
b(j,k) = uniform(30,60);
d = 0.8 * sum((j,k), U(j,k));
a = -%P% / (1.5 * d)**2;

* The scalar files generated depend on the variable declaration order,
* so do not change the declarations lightly
variable
    isoobj               ISO objective variable
    agentobj(j)          Agent objective variable
    zExp(i)              Replica of the z variable
    z                    Implicit version
    ;

positive variable q0, q(j,k);

equation
    defisoobjExp         ISO objective equation that uses zExp in it
    defisoobj            ISO objective equation that uses z
    defagentobjExp(j)    Agent objective equation that uses zExp in it
    defagentobj(j)       Agent objective equation that uses z
    defdemandExp(i)      Demand constraint that is copied for each agent
    defdemand            Demand shared constraint
    defzExp(i)           Explicit equation for zExp variables
    defz                 Implicit variable equation
    ;

q0.up = U0;
q.up(j,k) = U(j,k);

defisoobjExp..
    isoobj =E= %P%*q0 + sum(j, 0.5*sum(k, M(j,k)*q(j,k)*q(j,k)) + sum(k, b(j,k)*q(j,k))) - (a*sqr(zExp('0')) + %P%)*(zExp('0'));

defagentobjExp(j)..
    agentobj(j) =E= 0.5*sum(k, M(j,k)*q(j,k)*q(j,k)) + sum(k, b(j,k)*q(j,k)) - (a*sqr(zExp(j)) + %P%)*sum(k, q(j,k));

defdemandExp(i)..
    q0 + sum((j,k), q(j,k)) =E= d;

defzExp(i)..
    zExp(i) =E= sum((j,k), q(j,k));

model me 'explicit formulation'
      / defisoobjExp, defagentobjExp, defdemandExp, defzExp /;
put info 'equilibrium';
put / 'min', isoobj, q0;
put / defisoobjExp, defdemandExp('0');
loop(j,
    put / 'min', agentobj(j);
    loop(k, put / q(j,k););
    put / zExp(j);
    put / defagentobjExp(j), defdemandExp(j), defzExp(j);
);
put / 'vi', defzExp('0'), zExp('0');
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(isoobj.l+267.374) > tol ]        'bad isoobj.l', isoobj.l;
abort$[ abs(agentobj.l('1')+ 10.825) > tol ] 'bad agentobj.l("1")', agentobj.l;
abort$[ abs(agentobj.l('2')+102.696) > tol ] 'bad agentobj.l("2")', agentobj.l;
abort$[ abs(agentobj.l('3')+ 21.109) > tol ] 'bad agentobj.l("3")', agentobj.l;
abort$[ abs(agentobj.l('4')+ 39.619) > tol ] 'bad agentobj.l("4")', agentobj.l;
abort$[ abs(agentobj.l('5')+ 93.125) > tol ] 'bad agentobj.l("5")', agentobj.l;
abort$[ abs(q0.l-0) > tol ]                  'bad q0.l', q0.l;
abort$[ abs(q.l('1','1')-1.717) > tol ]      'bad q.l("1","1")', q.l;
abort$[ abs(q.l('2','1')-5.788) > tol ]      'bad q.l("2","1")', q.l;
abort$[ abs(q.l('3','1')-3.831) > tol ]      'bad q.l("3","1")', q.l;
abort$[ abs(q.l('4','1')-3.011) > tol ]      'bad q.l("4","1")', q.l;
abort$[ abs(q.l('5','1')-2.922) > tol ]      'bad q.l("5","1")', q.l;
abort$[ smax{i, abs(zExp.l(i)-17.269)} > tol ] 'bad zExp.l(i)', zExp.l;
abort$[ smax{i, abs(defdemandExp.m(i)-19.571)} > tol ]
     'bad defdemandExp.m(i)', defdemandExp.m;

isoobj.l = 0;
agentobj.l(j) = 0;
q0.l = 0;
q.l(j,k) = 0;
defdemandExp.m(i) = 0;

$onecho > expl_gms
***********************************************
* written by GAMS/JAMS at 12/04/16 23:32:07
* for more information use JAMS option "Dict"
***********************************************

Variables  x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18,u7,u8,u9,u10,u11,u12
          ,u14,u15,u16,u17,u18;

Positive Variables  x13,x14,x15,x16,x17,x18;

Equations  e7,e8,e9,e10,e11,e12,e13,e14,e15,e16,e17,e18,dL_dx8,dL_dx9,dL_dx10
          ,dL_dx11,dL_dx12,dL_dx13,dL_dx14,dL_dx15,dL_dx16,dL_dx17,dL_dx18;


e7..    x13 + x14 + x15 + x16 + x17 + x18 =E= 17.269913736;

e8..    x13 + x14 + x15 + x16 + x17 + x18 =E= 17.269913736;

e9..    x13 + x14 + x15 + x16 + x17 + x18 =E= 17.269913736;

e10..    x13 + x14 + x15 + x16 + x17 + x18 =E= 17.269913736;

e11..    x13 + x14 + x15 + x16 + x17 + x18 =E= 17.269913736;

e12..    x13 + x14 + x15 + x16 + x17 + x18 =E= 17.269913736;

e13..    x7 - x14 - x15 - x16 - x17 - x18 =E= 0;

e14..    x8 - x14 - x15 - x16 - x17 - x18 =E= 0;

e15..    x9 - x14 - x15 - x16 - x17 - x18 =E= 0;

e16..    x10 - x14 - x15 - x16 - x17 - x18 =E= 0;

e17..    x11 - x14 - x15 - x16 - x17 - x18 =E= 0;

e18..    x12 - x14 - x15 - x16 - x17 - x18 =E= 0;

dL_dx8.. (-0.357641894777802*x8*x14)/(-1) - u14 =E= 0;

dL_dx9.. (-0.357641894777802*x9*x15)/(-1) - u15 =E= 0;

dL_dx10.. (-0.357641894777802*x10*x16)/(-1) - u16 =E= 0;

dL_dx11.. (-0.357641894777802*x11*x17)/(-1) - u17 =E= 0;

dL_dx12.. (-0.357641894777802*x12*x18)/(-1) - u18 =E= 0;

dL_dx13.. 120 - u7 + eps*x13 =N= 0;

dL_dx14.. (-(59.94352881 + 0.5*(0.4896211468*x14 + 0.4896211468*x14) - (120 - 
          0.178820947388901*sqr(x8))))/(-1) - u8 + u14 =N= 0;

dL_dx15.. (-(47.36200134 + 0.5*(0.5399322016*x15 + 0.5399322016*x15) - (120 - 
          0.178820947388901*sqr(x9))))/(-1) - u9 + u15 =N= 0;

dL_dx16.. (-(59.73399117 + 0.5*(0.7425081388*x16 + 0.7425081388*x16) - (120 - 
          0.178820947388901*sqr(x10))))/(-1) - u10 + u16 =N= 0;

dL_dx17.. (-(52.86751401 + 0.5*(0.4268454892*x17 + 0.4268454892*x17) - (120 - 
          0.178820947388901*sqr(x11))))/(-1) - u11 + u17 =N= 0;

dL_dx18.. (-(33.92077449 + 0.5*(0.6000842676*x18 + 0.6000842676*x18) - (120 - 
          0.178820947388901*sqr(x12))))/(-1) - u12 + u18 =N= 0;

* set non-default bounds
x13.up = 5;
x14.up = 1.71747132;
x15.up = 8.43266708;
x16.up = 5.50375356;
x17.up = 3.01137904;
x18.up = 2.92212117;

Model m / e7.u7,e8.u8,e9.u9,e10.u10,e11.u11,e12.u12,e13.x7,e14.u14,e15.u15
         ,e16.u16,e17.u17,e18.u18,dL_dx8.x8,dL_dx9.x9,dL_dx10.x10
         ,dL_dx11.x11,dL_dx12.x12,dL_dx13.x13,dL_dx14.x14,dL_dx15.x15
         ,dL_dx16.x16,dL_dx17.x17,dL_dx18.x18 /;

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 -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 23:32:07

********************************************************************************
 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 isoobj q0
     3:defisoobjExp defdemandExp('0')
     4:min agentobj('1')
     5:q('1','1')
     6:zExp('1')
     7:defagentobjExp('1') defdemandExp('1') defzExp('1')
     8:min agentobj('2')
     9:q('2','1')
    10:zExp('2')
    11:defagentobjExp('2') defdemandExp('2') defzExp('2')
    12:min agentobj('3')
    13:q('3','1')
    14:zExp('3')
    15:defagentobjExp('3') defdemandExp('3') defzExp('3')
    16:min agentobj('4')
    17:q('4','1')
    18:zExp('4')
    19:defagentobjExp('4') defdemandExp('4') defzExp('4')
    20:min agentobj('5')
    21:q('5','1')
    22:zExp('5')
    23:defagentobjExp('5') defdemandExp('5') defzExp('5')
    24:vi defzExp('0') zExp('0')


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

   Number of VI functions specified = 1
   * e13 is VI Func and perpendicular to x7


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

      {reformulated}  defisoobjExp
      {reformulated}  defagentobjExp(1)
      {reformulated}  defagentobjExp(2)
      {reformulated}  defagentobjExp(3)
      {reformulated}  defagentobjExp(4)
      {reformulated}  defagentobjExp(5)
                  e7  defdemandExp(0)
                  e8  defdemandExp(1)
                  e9  defdemandExp(2)
                 e10  defdemandExp(3)
                 e11  defdemandExp(4)
                 e12  defdemandExp(5)
                 e13  defzExp(0)
                 e14  defzExp(1)
                 e15  defzExp(2)
                 e16  defzExp(3)
                 e17  defzExp(4)
                 e18  defzExp(5)
              dL_dx8  {new}
              dL_dx9  {new}
             dL_dx10  {new}
             dL_dx11  {new}
             dL_dx12  {new}
             dL_dx13  {new}
             dL_dx14  {new}
             dL_dx15  {new}
             dL_dx16  {new}
             dL_dx17  {new}
             dL_dx18  {new}


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

      {reformulated}  isoobj
      {reformulated}  agentobj(1)
      {reformulated}  agentobj(2)
      {reformulated}  agentobj(3)
      {reformulated}  agentobj(4)
      {reformulated}  agentobj(5)
                  x7  zExp(0)
                  x8  zExp(1)
                  x9  zExp(2)
                 x10  zExp(3)
                 x11  zExp(4)
                 x12  zExp(5)
                 x13  q0
                 x14  q(1,1)
                 x15  q(2,1)
                 x16  q(3,1)
                 x17  q(4,1)
                 x18  q(5,1)
                  u7  {new}
                  u8  {new}
                  u9  {new}
                 u10  {new}
                 u11  {new}
                 u12  {new}
                 u14  {new}
                 u15  {new}
                 u16  {new}
                 u17  {new}
                 u18  {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';

defisoobj..
    isoobj =E= %P%*q0 + sum(j, 0.5*sum(k, M(j,k)*q(j,k)*q(j,k)) + sum(k, b(j,k)*q(j,k))) - (a*sqr(z) + %P%)*(z);

defagentobj(j)..
    agentobj(j) =E= 0.5*sum(k, M(j,k)*q(j,k)*q(j,k)) + sum(k, b(j,k)*q(j,k)) - (a*sqr(z) + %P%)*sum(k, q(j,k));

defz..
    z =E= sum((j,k), q(j,k));

model mi 'implicit formulation'
      / defisoobj, defagentobj, defdemandExp, defz /;

put info 'equilibrium';
put / 'implicit', z, defz;
put / 'min', isoobj, q0;
put / defisoobj, defdemandExp('0');
loop(j,
    put / 'min', agentobj(j);
    loop(k, put / q(j,k););
    put / z;
    put / defagentobj(j), defdemandExp(j);
);
putclose;

* testing with implicit
putclose opt
  'Dict     implDict.txt' /
  'FileName impl.gms' ;

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(isoobj.l+267.374) > tol ]        'bad isoobj.l', isoobj.l;
abort$[ abs(agentobj.l('1')+ 10.825) > tol ] 'bad agentobj.l("1")', agentobj.l;
abort$[ abs(agentobj.l('2')+102.696) > tol ] 'bad agentobj.l("2")', agentobj.l;
abort$[ abs(agentobj.l('3')+ 21.109) > tol ] 'bad agentobj.l("3")', agentobj.l;
abort$[ abs(agentobj.l('4')+ 39.619) > tol ] 'bad agentobj.l("4")', agentobj.l;
abort$[ abs(agentobj.l('5')+ 93.125) > tol ] 'bad agentobj.l("5")', agentobj.l;
abort$[ abs(q0.l-0) > tol ]                  'bad q0.l', q0.l;
abort$[ abs(q.l('1','1')-1.717) > tol ]      'bad q.l("1","1")', q.l;
abort$[ abs(q.l('2','1')-5.788) > tol ]      'bad q.l("2","1")', q.l;
abort$[ abs(q.l('3','1')-3.831) > tol ]      'bad q.l("3","1")', q.l;
abort$[ abs(q.l('4','1')-3.011) > tol ]      'bad q.l("4","1")', q.l;
abort$[ abs(q.l('5','1')-2.922) > tol ]      'bad q.l("5","1")', q.l;
abort$[ abs(z.l-17.269) > tol ]              'bad z.l', z.l;
abort$[ smax{i, abs(defdemandExp.m(i)-19.571)} > tol ]
     'bad defdemandExp.m(i)', defdemandExp.m;

isoobj.l = 0;
agentobj.l(j) = 0;
q0.l = 0;
q.l(j,k) = 0;
z.l = 0;
defisoobj.m = 0;
defagentobj.m(j) = 0;
defdemandExp.m(i) = 0;
defz.m = 0;

$onecho > impl_gms
***********************************************
* written by GAMS/JAMS at 12/04/16 23:37:58
* for more information use JAMS option "Dict"
***********************************************

Variables  x7,x8,x9,x10,x11,x12,x13,u7,u8,u9,u10,u11,u12;

Positive Variables  x8,x9,x10,x11,x12,x13;

Equations  e7,e8,e9,e10,e11,e12,e13,dL_dx8,dL_dx9,dL_dx10,dL_dx11,dL_dx12
          ,dL_dx13;


e7..    x8 + x9 + x10 + x11 + x12 + x13 =E= 17.269913736;

e8..    x8 + x9 + x10 + x11 + x12 + x13 =E= 17.269913736;

e9..    x8 + x9 + x10 + x11 + x12 + x13 =E= 17.269913736;

e10..    x8 + x9 + x10 + x11 + x12 + x13 =E= 17.269913736;

e11..    x8 + x9 + x10 + x11 + x12 + x13 =E= 17.269913736;

e12..    x8 + x9 + x10 + x11 + x12 + x13 =E= 17.269913736;

e13..    x7 - x9 - x10 - x11 - x12 - x13 =E= 0;

dL_dx8.. 120 - u7 + eps*x8 =N= 0;

dL_dx9.. (-(59.94352881 + 0.5*(0.4896211468*x9 + 0.4896211468*x9) - (120 - 
         0.178820947388901*sqr(x7))))/(-1) + ((-0.357641894777802*x7*x9)/(-1)
         )*(1) - u8 =N= 0;

dL_dx10.. (-(47.36200134 + 0.5*(0.5399322016*x10 + 0.5399322016*x10) - (120 - 
          0.178820947388901*sqr(x7))))/(-1) + ((-0.357641894777802*x7*x10)/(-1)
          )*(1) - u9 =N= 0;

dL_dx11.. (-(59.73399117 + 0.5*(0.7425081388*x11 + 0.7425081388*x11) - (120 - 
          0.178820947388901*sqr(x7))))/(-1) + ((-0.357641894777802*x7*x11)/(-1)
          )*(1) - u10 =N= 0;

dL_dx12.. (-(52.86751401 + 0.5*(0.4268454892*x12 + 0.4268454892*x12) - (120 - 
          0.178820947388901*sqr(x7))))/(-1) + ((-0.357641894777802*x7*x12)/(-1)
          )*(1) - u11 =N= 0;

dL_dx13.. (-(33.92077449 + 0.5*(0.6000842676*x13 + 0.6000842676*x13) - (120 - 
          0.178820947388901*sqr(x7))))/(-1) + ((-0.357641894777802*x7*x13)/(-1)
          )*(1) - u12 =N= 0;

* set non-default bounds
x8.up = 5;
x9.up = 1.71747132;
x10.up = 8.43266708;
x11.up = 5.50375356;
x12.up = 3.01137904;
x13.up = 2.92212117;

Model m / e7.u7,e8.u8,e9.u9,e10.u10,e11.u11,e12.u12,e13.x7,dL_dx8.x8
         ,dL_dx9.x9,dL_dx10.x10,dL_dx11.x11,dL_dx12.x12,dL_dx13.x13 /;

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 -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 23:37:58

********************************************************************************
 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 isoobj q0
     4:defisoobj defdemandExp('0')
     5:min agentobj('1')
     6:q('1','1')
     7:z
     8:defagentobj('1') defdemandExp('1')
     9:min agentobj('2')
    10:q('2','1')
    11:z
    12:defagentobj('2') defdemandExp('2')
    13:min agentobj('3')
    14:q('3','1')
    15:z
    16:defagentobj('3') defdemandExp('3')
    17:min agentobj('4')
    18:q('4','1')
    19:z
    20:defagentobj('4') defdemandExp('4')
    21:min agentobj('5')
    22:q('5','1')
    23:z
    24:defagentobj('5') defdemandExp('5')


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


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

      {reformulated}  defisoobj
      {reformulated}  defagentobj(1)
      {reformulated}  defagentobj(2)
      {reformulated}  defagentobj(3)
      {reformulated}  defagentobj(4)
      {reformulated}  defagentobj(5)
                  e7  defdemandExp(0)
                  e8  defdemandExp(1)
                  e9  defdemandExp(2)
                 e10  defdemandExp(3)
                 e11  defdemandExp(4)
                 e12  defdemandExp(5)
                 e13  defz
              dL_dx8  {new}
              dL_dx9  {new}
             dL_dx10  {new}
             dL_dx11  {new}
             dL_dx12  {new}
             dL_dx13  {new}


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

      {reformulated}  isoobj
      {reformulated}  agentobj(1)
      {reformulated}  agentobj(2)
      {reformulated}  agentobj(3)
      {reformulated}  agentobj(4)
      {reformulated}  agentobj(5)
                  x7  z
                  x8  q0
                  x9  q(1,1)
                 x10  q(2,1)
                 x11  q(3,1)
                 x12  q(4,1)
                 x13  q(5,1)
                  u7  {new}
                  u8  {new}
                  u9  {new}
                 u10  {new}
                 u11  {new}
                 u12  {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 adjoint

putclose opt
  'Dict     implAdjointDict.txt' /
  'FileName implAdjoint.gms' /
  'Adjoint' / ;

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(isoobj.l+267.374) > tol ]        'bad isoobj.l', isoobj.l;
abort$[ abs(agentobj.l('1')+ 10.825) > tol ] 'bad agentobj.l("1")', agentobj.l;
abort$[ abs(agentobj.l('2')+102.696) > tol ] 'bad agentobj.l("2")', agentobj.l;
abort$[ abs(agentobj.l('3')+ 21.109) > tol ] 'bad agentobj.l("3")', agentobj.l;
abort$[ abs(agentobj.l('4')+ 39.619) > tol ] 'bad agentobj.l("4")', agentobj.l;
abort$[ abs(agentobj.l('5')+ 93.125) > tol ] 'bad agentobj.l("5")', agentobj.l;
abort$[ abs(q0.l-0) > tol ]                  'bad q0.l', q0.l;
abort$[ abs(q.l('1','1')-1.717) > tol ]      'bad q.l("1","1")', q.l;
abort$[ abs(q.l('2','1')-5.788) > tol ]      'bad q.l("2","1")', q.l;
abort$[ abs(q.l('3','1')-3.831) > tol ]      'bad q.l("3","1")', q.l;
abort$[ abs(q.l('4','1')-3.011) > tol ]      'bad q.l("4","1")', q.l;
abort$[ abs(q.l('5','1')-2.922) > tol ]      'bad q.l("5","1")', q.l;
abort$[ abs(z.l-17.269) > tol ]              'bad z.l', z.l;
abort$[ smax{i, abs(defdemandExp.m(i)-19.571)} > tol ]
     'bad defdemandExp.m(i)', defdemandExp.m;

isoobj.l = 0;
agentobj.l(j) = 0;
q0.l = 0;
q.l(j,k) = 0;
z.l = 0;
defisoobj.m = 0;
defagentobj.m(j) = 0;
defdemandExp.m(i) = 0;
defz.m = 0;

$onecho > implAdjoint_gms
***********************************************
* written by GAMS/JAMS at 12/05/16 14:40:39
* for more information use JAMS option "Dict"
***********************************************

Variables  x7,x8,x9,x10,x11,x12,x13,u7,u8,u9,u10,u11,u12,IMPL1_a5_x1
          ,IMPL1_a6_x1,IMPL1_a7_x1,IMPL1_a8_x1,IMPL1_a9_x1;

Positive Variables  x8,x9,x10,x11,x12,x13;

Equations  e7,e8,e9,e10,e11,e12,e13,IMPL1_a5_e1,IMPL1_a6_e1,IMPL1_a7_e1
          ,IMPL1_a8_e1,IMPL1_a9_e1,dL_dx8,dL_dx9,dL_dx10,dL_dx11,dL_dx12
          ,dL_dx13;


e7..    x8 + x9 + x10 + x11 + x12 + x13 =E= 17.269913736;

e8..    x8 + x9 + x10 + x11 + x12 + x13 =E= 17.269913736;

e9..    x8 + x9 + x10 + x11 + x12 + x13 =E= 17.269913736;

e10..    x8 + x9 + x10 + x11 + x12 + x13 =E= 17.269913736;

e11..    x8 + x9 + x10 + x11 + x12 + x13 =E= 17.269913736;

e12..    x8 + x9 + x10 + x11 + x12 + x13 =E= 17.269913736;

e13..    x7 - x9 - x10 - x11 - x12 - x13 =E= 0;

IMPL1_a5_e1.. (1)*(IMPL1_a5_x1) + (-0.357641894777802*x7*x9)/(-1) =E= 0;

IMPL1_a6_e1.. (1)*(IMPL1_a6_x1) + (-0.357641894777802*x7*x10)/(-1) =E= 0;

IMPL1_a7_e1.. (1)*(IMPL1_a7_x1) + (-0.357641894777802*x7*x11)/(-1) =E= 0;

IMPL1_a8_e1.. (1)*(IMPL1_a8_x1) + (-0.357641894777802*x7*x12)/(-1) =E= 0;

IMPL1_a9_e1.. (1)*(IMPL1_a9_x1) + (-0.357641894777802*x7*x13)/(-1) =E= 0;

dL_dx8.. 120 - u7 + eps*x8 =N= 0;

dL_dx9.. (-(59.94352881 + 0.5*(0.4896211468*x9 + 0.4896211468*x9) - (120 - 
         0.178820947388901*sqr(x7))))/(-1) + (-1)*(IMPL1_a5_x1) - u8 =N= 0;

dL_dx10.. (-(47.36200134 + 0.5*(0.5399322016*x10 + 0.5399322016*x10) - (120 - 
          0.178820947388901*sqr(x7))))/(-1) + (-1)*(IMPL1_a6_x1) - u9 =N= 0;

dL_dx11.. (-(59.73399117 + 0.5*(0.7425081388*x11 + 0.7425081388*x11) - (120 - 
          0.178820947388901*sqr(x7))))/(-1) + (-1)*(IMPL1_a7_x1) - u10 =N= 0;

dL_dx12.. (-(52.86751401 + 0.5*(0.4268454892*x12 + 0.4268454892*x12) - (120 - 
          0.178820947388901*sqr(x7))))/(-1) + (-1)*(IMPL1_a8_x1) - u11 =N= 0;

dL_dx13.. (-(33.92077449 + 0.5*(0.6000842676*x13 + 0.6000842676*x13) - (120 - 
          0.178820947388901*sqr(x7))))/(-1) + (-1)*(IMPL1_a9_x1) - u12 =N= 0;

* set non-default bounds
x8.up = 5;
x9.up = 1.71747132;
x10.up = 8.43266708;
x11.up = 5.50375356;
x12.up = 3.01137904;
x13.up = 2.92212117;

Model m / e7.u7,e8.u8,e9.u9,e10.u10,e11.u11,e12.u12,e13.x7
         ,IMPL1_a5_e1.IMPL1_a5_x1,IMPL1_a6_e1.IMPL1_a6_x1
         ,IMPL1_a7_e1.IMPL1_a7_x1,IMPL1_a8_e1.IMPL1_a8_x1
         ,IMPL1_a9_e1.IMPL1_a9_x1,dL_dx8.x8,dL_dx9.x9,dL_dx10.x10
         ,dL_dx11.x11,dL_dx12.x12,dL_dx13.x13 /;

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

Solve m using MCP;
$offecho

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

$onecho > implAdjoint_dict
* written by GAMS/JAMS at 12/05/16 14:40:39

********************************************************************************
 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 isoobj q0
     4:defisoobj defdemandExp('0')
     5:min agentobj('1')
     6:q('1','1')
     7:z
     8:defagentobj('1') defdemandExp('1')
     9:min agentobj('2')
    10:q('2','1')
    11:z
    12:defagentobj('2') defdemandExp('2')
    13:min agentobj('3')
    14:q('3','1')
    15:z
    16:defagentobj('3') defdemandExp('3')
    17:min agentobj('4')
    18:q('4','1')
    19:z
    20:defagentobj('4') defdemandExp('4')
    21:min agentobj('5')
    22:q('5','1')
    23:z
    24:defagentobj('5') defdemandExp('5')


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


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

      {reformulated}  defisoobj
      {reformulated}  defagentobj(1)
      {reformulated}  defagentobj(2)
      {reformulated}  defagentobj(3)
      {reformulated}  defagentobj(4)
      {reformulated}  defagentobj(5)
                  e7  defdemandExp(0)
                  e8  defdemandExp(1)
                  e9  defdemandExp(2)
                 e10  defdemandExp(3)
                 e11  defdemandExp(4)
                 e12  defdemandExp(5)
                 e13  defz
         IMPL1_a5_e1  {new}
         IMPL1_a6_e1  {new}
         IMPL1_a7_e1  {new}
         IMPL1_a8_e1  {new}
         IMPL1_a9_e1  {new}
              dL_dx8  {new}
              dL_dx9  {new}
             dL_dx10  {new}
             dL_dx11  {new}
             dL_dx12  {new}
             dL_dx13  {new}


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

      {reformulated}  isoobj
      {reformulated}  agentobj(1)
      {reformulated}  agentobj(2)
      {reformulated}  agentobj(3)
      {reformulated}  agentobj(4)
      {reformulated}  agentobj(5)
                  x7  z
                  x8  q0
                  x9  q(1,1)
                 x10  q(2,1)
                 x11  q(3,1)
                 x12  q(4,1)
                 x13  q(5,1)
                  u7  {new}
                  u8  {new}
                  u9  {new}
                 u10  {new}
                 u11  {new}
                 u12  {new}
         IMPL1_a5_x1  {new}
         IMPL1_a6_x1  {new}
         IMPL1_a7_x1  {new}
         IMPL1_a8_x1  {new}
         IMPL1_a9_x1  {new}
$offecho

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

* testing with replication
putclose opt
  'Dict     implRepDict.txt' /
  'FileName implRep.gms' /
  'CopyImplVar' ;

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(isoobj.l+267.374) > tol ]        'bad isoobj.l', isoobj.l;
abort$[ abs(agentobj.l('1')+ 10.825) > tol ] 'bad agentobj.l("1")', agentobj.l;
abort$[ abs(agentobj.l('2')+102.696) > tol ] 'bad agentobj.l("2")', agentobj.l;
abort$[ abs(agentobj.l('3')+ 21.109) > tol ] 'bad agentobj.l("3")', agentobj.l;
abort$[ abs(agentobj.l('4')+ 39.619) > tol ] 'bad agentobj.l("4")', agentobj.l;
abort$[ abs(agentobj.l('5')+ 93.125) > tol ] 'bad agentobj.l("5")', agentobj.l;
abort$[ abs(q0.l-0) > tol ]                  'bad q0.l', q0.l;
abort$[ abs(q.l('1','1')-1.717) > tol ]      'bad q.l("1","1")', q.l;
abort$[ abs(q.l('2','1')-5.788) > tol ]      'bad q.l("2","1")', q.l;
abort$[ abs(q.l('3','1')-3.831) > tol ]      'bad q.l("3","1")', q.l;
abort$[ abs(q.l('4','1')-3.011) > tol ]      'bad q.l("4","1")', q.l;
abort$[ abs(q.l('5','1')-2.922) > tol ]      'bad q.l("5","1")', q.l;
abort$[ abs(z.l-17.269) > tol ]              'bad z.l', z.l;
abort$[ smax{i, abs(defdemandExp.m(i)-19.571)} > tol ]
     'bad defdemandExp.m(i)', defdemandExp.m;

isoobj.l = 0;
agentobj.l(j) = 0;
q0.l = 0;
q.l(j,k) = 0;
z.l = 0;
defisoobj.m = 0;
defagentobj.m(j) = 0;
defdemandExp.m(i) = 0;
defz.m = 0;

$onechoV > implRep_gms
***********************************************
* written by GAMS/JAMS at 12/05/16 14:41:34
* for more information use JAMS option "Dict"
***********************************************

Variables  x1,x2,x3,x4,x5,x6,x7_1,x8,x9,x10,x11,x12,x13,x7_5,x7_6,x7_7,x7_8
          ,x7_9;

Positive Variables  x8,x9,x10,x11,x12,x13;

Equations  e1,e2,e3,e4,e5,e6,e7,e8,e9,e10,e11,e12,e13_1,e13_5,e13_6,e13_7
          ,e13_8,e13_9;


e1.. -(0.2448105734*x9*x9 + 59.94352881*x9 + 0.2699661008*x10*x10 + 47.36200134
     *x10 + 0.3712540694*x11*x11 + 59.73399117*x11 + 0.2134227446*x12*x12 + 
     52.86751401*x12 + 0.3000421338*x13*x13 + 33.92077449*x13 - (120 - 
     0.178820947388901*sqr(x7_1))*x7_1) + x1 - 120*x8 =E= 0;

e2.. -(0.2448105734*x9*x9 + 59.94352881*x9 - (120 - 0.178820947388901*sqr(x7_5)
     )*x9) + x2 =E= 0;

e3.. -(0.2699661008*x10*x10 + 47.36200134*x10 - (120 - 0.178820947388901*sqr(
     x7_6))*x10) + x3 =E= 0;

e4.. -(0.3712540694*x11*x11 + 59.73399117*x11 - (120 - 0.178820947388901*sqr(
     x7_7))*x11) + x4 =E= 0;

e5.. -(0.2134227446*x12*x12 + 52.86751401*x12 - (120 - 0.178820947388901*sqr(
     x7_8))*x12) + x5 =E= 0;

e6.. -(0.3000421338*x13*x13 + 33.92077449*x13 - (120 - 0.178820947388901*sqr(
     x7_9))*x13) + x6 =E= 0;

e7..    x8 + x9 + x10 + x11 + x12 + x13 =E= 17.269913736;

e8..    x8 + x9 + x10 + x11 + x12 + x13 =E= 17.269913736;

e9..    x8 + x9 + x10 + x11 + x12 + x13 =E= 17.269913736;

e10..    x8 + x9 + x10 + x11 + x12 + x13 =E= 17.269913736;

e11..    x8 + x9 + x10 + x11 + x12 + x13 =E= 17.269913736;

e12..    x8 + x9 + x10 + x11 + x12 + x13 =E= 17.269913736;

e13_1..    x7_1 - x9 - x10 - x11 - x12 - x13 =E= 0;

e13_5..    x7_5 - x9 - x10 - x11 - x12 - x13 =E= 0;

e13_6..    x7_6 - x9 - x10 - x11 - x12 - x13 =E= 0;

e13_7..    x7_7 - x9 - x10 - x11 - x12 - x13 =E= 0;

e13_8..    x7_8 - x9 - x10 - x11 - x12 - x13 =E= 0;

e13_9..    x7_9 - x9 - x10 - x11 - x12 - x13 =E= 0;

* set non-default bounds
x8.up = 5;
x9.up = 1.71747132;
x10.up = 8.43266708;
x11.up = 5.50375356;
x12.up = 3.01137904;
x13.up = 2.92212117;

Model m / e1,e2,e3,e4,e5,e6,e7,e8,e9,e10,e11,e12,e13_1,e13_5,e13_6,e13_7
         ,e13_8,e13_9 /;

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


File empinfo / '%emp.info%' /;

Put empinfo 'equilibrium' /;
Put 'min',x1,x8,e1,e7 /;
Put 'min',x2,x9,x7_5,e2,e8,e13_5 /;
Put 'min',x3,x10,x7_6,e3,e9,e13_6 /;
Put 'min',x4,x11,x7_7,e4,e10,e13_7 /;
Put 'min',x5,x12,x7_8,e5,e11,e13_8 /;
Put 'min',x6,x13,x7_9,e6,e12,e13_9 /;
Put 'vi',e13_1,x7_1 /;
Putclose empinfo;

m.optfile = 0;

Solve m using EMP;
$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 -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 12/05/16 14:41:34

********************************************************************************
 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 isoobj q0
     4:defisoobj defdemandExp('0')
     5:min agentobj('1')
     6:q('1','1')
     7:z
     8:defagentobj('1') defdemandExp('1')
     9:min agentobj('2')
    10:q('2','1')
    11:z
    12:defagentobj('2') defdemandExp('2')
    13:min agentobj('3')
    14:q('3','1')
    15:z
    16:defagentobj('3') defdemandExp('3')
    17:min agentobj('4')
    18:q('4','1')
    19:z
    20:defagentobj('4') defdemandExp('4')
    21:min agentobj('5')
    22:q('5','1')
    23:z
    24:defagentobj('5') defdemandExp('5')


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


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

                  e1  defisoobj
                  e2  defagentobj(1)
                  e3  defagentobj(2)
                  e4  defagentobj(3)
                  e5  defagentobj(4)
                  e6  defagentobj(5)
                  e7  defdemandExp(0)
                  e8  defdemandExp(1)
                  e9  defdemandExp(2)
                 e10  defdemandExp(3)
                 e11  defdemandExp(4)
                 e12  defdemandExp(5)
               e13_1  defz
               e13_5  defz
               e13_6  defz
               e13_7  defz
               e13_8  defz
               e13_9  defz


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

                  x1  isoobj
                  x2  agentobj(1)
                  x3  agentobj(2)
                  x4  agentobj(3)
                  x5  agentobj(4)
                  x6  agentobj(5)
                x7_1  z
                  x8  q0
                  x9  q(1,1)
                 x10  q(2,1)
                 x11  q(3,1)
                 x12  q(4,1)
                 x13  q(5,1)
                x7_5  z
                x7_6  z
                x7_7  z
                x7_8  z
                x7_9  z
$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';

* testing with replication and matching
putclose opt
  'Dict     implRepMMDict.txt' /
  'FileName implRepMM.gms' /
  'CopyImplVar' /
  'MixMatch' /
  ;

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(isoobj.l+267.374) > tol ]        'bad isoobj.l', isoobj.l;
abort$[ abs(agentobj.l('1')+ 10.825) > tol ] 'bad agentobj.l("1")', agentobj.l;
abort$[ abs(agentobj.l('2')+102.696) > tol ] 'bad agentobj.l("2")', agentobj.l;
abort$[ abs(agentobj.l('3')+ 21.109) > tol ] 'bad agentobj.l("3")', agentobj.l;
abort$[ abs(agentobj.l('4')+ 39.619) > tol ] 'bad agentobj.l("4")', agentobj.l;
abort$[ abs(agentobj.l('5')+ 93.125) > tol ] 'bad agentobj.l("5")', agentobj.l;
abort$[ abs(q0.l-0) > tol ]                  'bad q0.l', q0.l;
abort$[ abs(q.l('1','1')-1.717) > tol ]      'bad q.l("1","1")', q.l;
abort$[ abs(q.l('2','1')-5.788) > tol ]      'bad q.l("2","1")', q.l;
abort$[ abs(q.l('3','1')-3.831) > tol ]      'bad q.l("3","1")', q.l;
abort$[ abs(q.l('4','1')-3.011) > tol ]      'bad q.l("4","1")', q.l;
abort$[ abs(q.l('5','1')-2.922) > tol ]      'bad q.l("5","1")', q.l;
abort$[ abs(z.l-17.269) > tol ]              'bad z.l', z.l;
abort$[ smax{i, abs(defdemandExp.m(i)-19.571)} > tol ]
     'bad defdemandExp.m(i)', defdemandExp.m;

isoobj.l = 0;
agentobj.l(j) = 0;
q0.l = 0;
q.l(j,k) = 0;
z.l = 0;
defisoobj.m = 0;
defagentobj.m(j) = 0;
defdemandExp.m(i) = 0;
defz.m = 0;

$onechoV > implRepMM_gms
***********************************************
* written by GAMS/JAMS at 12/05/16 14:42:36
* for more information use JAMS option "Dict"
***********************************************

Variables  x1,x2,x3,x4,x5,x6,x7_5,x8,x9,x10,x11,x12,x13,x7_6,x7_7,x7_8,x7_9;

Positive Variables  x8,x9,x10,x11,x12,x13;

Equations  e1,e2,e3,e4,e5,e6,e7,e8,e9,e10,e11,e12,e13_5,e13_6,e13_7,e13_8
          ,e13_9;


e1.. -(0.2448105734*x9*x9 + 59.94352881*x9 + 0.2699661008*x10*x10 + 47.36200134
     *x10 + 0.3712540694*x11*x11 + 59.73399117*x11 + 0.2134227446*x12*x12 + 
     52.86751401*x12 + 0.3000421338*x13*x13 + 33.92077449*x13 - (120 - 
     0.178820947388901*sqr(x7_5))*x7_5) + x1 - 120*x8 =E= 0;

e2.. -(0.2448105734*x9*x9 + 59.94352881*x9 - (120 - 0.178820947388901*sqr(x7_5)
     )*x9) + x2 =E= 0;

e3.. -(0.2699661008*x10*x10 + 47.36200134*x10 - (120 - 0.178820947388901*sqr(
     x7_6))*x10) + x3 =E= 0;

e4.. -(0.3712540694*x11*x11 + 59.73399117*x11 - (120 - 0.178820947388901*sqr(
     x7_7))*x11) + x4 =E= 0;

e5.. -(0.2134227446*x12*x12 + 52.86751401*x12 - (120 - 0.178820947388901*sqr(
     x7_8))*x12) + x5 =E= 0;

e6.. -(0.3000421338*x13*x13 + 33.92077449*x13 - (120 - 0.178820947388901*sqr(
     x7_9))*x13) + x6 =E= 0;

e7..    x8 + x9 + x10 + x11 + x12 + x13 =E= 17.269913736;

e8..    x8 + x9 + x10 + x11 + x12 + x13 =E= 17.269913736;

e9..    x8 + x9 + x10 + x11 + x12 + x13 =E= 17.269913736;

e10..    x8 + x9 + x10 + x11 + x12 + x13 =E= 17.269913736;

e11..    x8 + x9 + x10 + x11 + x12 + x13 =E= 17.269913736;

e12..    x8 + x9 + x10 + x11 + x12 + x13 =E= 17.269913736;

e13_5..    x7_5 - x9 - x10 - x11 - x12 - x13 =E= 0;

e13_6..    x7_6 - x9 - x10 - x11 - x12 - x13 =E= 0;

e13_7..    x7_7 - x9 - x10 - x11 - x12 - x13 =E= 0;

e13_8..    x7_8 - x9 - x10 - x11 - x12 - x13 =E= 0;

e13_9..    x7_9 - x9 - x10 - x11 - x12 - x13 =E= 0;

* set non-default bounds
x8.up = 5;
x9.up = 1.71747132;
x10.up = 8.43266708;
x11.up = 5.50375356;
x12.up = 3.01137904;
x13.up = 2.92212117;

Model m / e1,e2,e3,e4,e5,e6,e7,e8,e9,e10,e11,e12,e13_5,e13_6,e13_7,e13_8
         ,e13_9 /;

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


File empinfo / '%emp.info%' /;

Put empinfo 'equilibrium' /;
Put 'min',x1,x8,e1,e7 /;
Put 'min',x2,x9,x7_5,e2,e8,e13_5 /;
Put 'min',x3,x10,x7_6,e3,e9,e13_6 /;
Put 'min',x4,x11,x7_7,e4,e10,e13_7 /;
Put 'min',x5,x12,x7_8,e5,e11,e13_8 /;
Put 'min',x6,x13,x7_9,e6,e12,e13_9 /;
Putclose empinfo;

m.optfile = 0;

Solve m using EMP;
$offecho

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

$onecho > implRepMM_dict
* written by GAMS/JAMS at 12/05/16 14:42:36

********************************************************************************
 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 isoobj q0
     4:defisoobj defdemandExp('0')
     5:min agentobj('1')
     6:q('1','1')
     7:z
     8:defagentobj('1') defdemandExp('1')
     9:min agentobj('2')
    10:q('2','1')
    11:z
    12:defagentobj('2') defdemandExp('2')
    13:min agentobj('3')
    14:q('3','1')
    15:z
    16:defagentobj('3') defdemandExp('3')
    17:min agentobj('4')
    18:q('4','1')
    19:z
    20:defagentobj('4') defdemandExp('4')
    21:min agentobj('5')
    22:q('5','1')
    23:z
    24:defagentobj('5') defdemandExp('5')


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


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

                  e1  defisoobj
                  e2  defagentobj(1)
                  e3  defagentobj(2)
                  e4  defagentobj(3)
                  e5  defagentobj(4)
                  e6  defagentobj(5)
                  e7  defdemandExp(0)
                  e8  defdemandExp(1)
                  e9  defdemandExp(2)
                 e10  defdemandExp(3)
                 e11  defdemandExp(4)
                 e12  defdemandExp(5)
               e13_5  defz
               e13_6  defz
               e13_7  defz
               e13_8  defz
               e13_9  defz


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

                  x1  isoobj
                  x2  agentobj(1)
                  x3  agentobj(2)
                  x4  agentobj(3)
                  x5  agentobj(4)
                  x6  agentobj(5)
                x7_5  z
                  x8  q0
                  x9  q(1,1)
                 x10  q(2,1)
                 x11  q(3,1)
                 x12  q(4,1)
                 x13  q(5,1)
                x7_6  z
                x7_7  z
                x7_8  z
                x7_9  z
$offecho

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

* testing with implicit and GNEP shared constraint

defdemand..
    q0 + sum((j,k), q(j,k)) =E= d;
    
model ms 'implicit with GNEP shared constraint'
      / defisoobj, defagentobj, defdemand, defz /;

put info 'equilibrium';
put / 'implicit', z, defz;
put / 'min', isoobj, q0;
put / defisoobj, defdemand;
loop(j,
    put / 'min', agentobj(j);
    loop(k, put / q(j,k););
    put / z;
    put / defagentobj(j), defdemand;
);
putclose;

putclose opt
  'Dict     implGNEPDict.txt' /
  'FileName implGNEP.gms' /
  'SharedEqu' ;

ms.optfile = 1;
solve ms using emp;
abort$[ms.solvestat <> %solvestat.NormalCompletion%]
   'wrong ms.solvestat', ms.solvestat;
abort$[ms.modelstat  > %modelstat.LocallyOptimal%]
   'wrong ms.modelstat', ms.modelstat;
abort$[ abs(isoobj.l+267.374) > tol ]        'bad isoobj.l', isoobj.l;
abort$[ abs(agentobj.l('1')+ 10.825) > tol ] 'bad agentobj.l("1")', agentobj.l;
abort$[ abs(agentobj.l('2')+102.696) > tol ] 'bad agentobj.l("2")', agentobj.l;
abort$[ abs(agentobj.l('3')+ 21.109) > tol ] 'bad agentobj.l("3")', agentobj.l;
abort$[ abs(agentobj.l('4')+ 39.619) > tol ] 'bad agentobj.l("4")', agentobj.l;
abort$[ abs(agentobj.l('5')+ 93.125) > tol ] 'bad agentobj.l("5")', agentobj.l;
abort$[ abs(q0.l-0) > tol ]                  'bad q0.l', q0.l;
abort$[ abs(q.l('1','1')-1.717) > tol ]      'bad q.l("1","1")', q.l;
abort$[ abs(q.l('2','1')-5.788) > tol ]      'bad q.l("2","1")', q.l;
abort$[ abs(q.l('3','1')-3.831) > tol ]      'bad q.l("3","1")', q.l;
abort$[ abs(q.l('4','1')-3.011) > tol ]      'bad q.l("4","1")', q.l;
abort$[ abs(q.l('5','1')-2.922) > tol ]      'bad q.l("5","1")', q.l;
abort$[ abs(z.l-17.269) > tol ]              'bad z.l', z.l;

set ag / 1*6 /;
parameter defdemand_m(ag);
execute_load '%gams.scrdir%/ugdx.dat', defdemand_m=defdemand;

abort$[ smax{ag, abs(defdemand_m(ag)-19.571)} > tol ]
     'bad defdemand_m(ag)', defdemand_m;

isoobj.l = 0;
agentobj.l(j) = 0;
q0.l = 0;
q.l(j,k) = 0;
z.l = 0;
defisoobj.m = 0;
defagentobj.m(j) = 0;
defdemand.m = 0;
defz.m = 0;

$onecho > implGNEP_gms
***********************************************
* written by GAMS/JAMS at 12/05/16 14:43:13
* for more information use JAMS option "Dict"
***********************************************

Variables  x7,x8,x9,x10,x11,x12,x13,u7_4,u7_5,u7_6,u7_7,u7_8,u7_9;

Positive Variables  x8,x9,x10,x11,x12,x13;

Equations  e7_4,e8,e7_5,e7_6,e7_7,e7_8,e7_9,dL_dx8,dL_dx9,dL_dx10,dL_dx11
          ,dL_dx12,dL_dx13;


e7_4..    x8 + x9 + x10 + x11 + x12 + x13 =E= 17.269913736;

e8..    x7 - x9 - x10 - x11 - x12 - x13 =E= 0;

e7_5..   x8 + x9 + x10 + x11 + x12 + x13 =E= 17.269913736;

e7_6..   x8 + x9 + x10 + x11 + x12 + x13 =E= 17.269913736;

e7_7..   x8 + x9 + x10 + x11 + x12 + x13 =E= 17.269913736;

e7_8..   x8 + x9 + x10 + x11 + x12 + x13 =E= 17.269913736;

e7_9..   x8 + x9 + x10 + x11 + x12 + x13 =E= 17.269913736;

dL_dx8.. 120 - u7_4 + eps*x8 =N= 0;

dL_dx9.. (-(59.94352881 + 0.5*(0.4896211468*x9 + 0.4896211468*x9) - (120 - 
         0.178820947388901*sqr(x7))))/(-1) + ((-0.357641894777802*x7*x9)/(-1)
         )*(1) - u7_5 =N= 0;

dL_dx10.. (-(47.36200134 + 0.5*(0.5399322016*x10 + 0.5399322016*x10) - (120 - 
          0.178820947388901*sqr(x7))))/(-1) + ((-0.357641894777802*x7*x10)/(-1)
          )*(1) - u7_6 =N= 0;

dL_dx11.. (-(59.73399117 + 0.5*(0.7425081388*x11 + 0.7425081388*x11) - (120 - 
          0.178820947388901*sqr(x7))))/(-1) + ((-0.357641894777802*x7*x11)/(-1)
          )*(1) - u7_7 =N= 0;

dL_dx12.. (-(52.86751401 + 0.5*(0.4268454892*x12 + 0.4268454892*x12) - (120 - 
          0.178820947388901*sqr(x7))))/(-1) + ((-0.357641894777802*x7*x12)/(-1)
          )*(1) - u7_8 =N= 0;

dL_dx13.. (-(33.92077449 + 0.5*(0.6000842676*x13 + 0.6000842676*x13) - (120 - 
          0.178820947388901*sqr(x7))))/(-1) + ((-0.357641894777802*x7*x13)/(-1)
          )*(1) - u7_9 =N= 0;

* set non-default bounds
x8.up = 5;
x9.up = 1.71747132;
x10.up = 8.43266708;
x11.up = 5.50375356;
x12.up = 3.01137904;
x13.up = 2.92212117;

Model m / e7_4.u7_4,e8.x7,e7_5.u7_5,e7_6.u7_6,e7_7.u7_7,e7_8.u7_8,e7_9.u7_9
         ,dL_dx8.x8,dL_dx9.x9,dL_dx10.x10,dL_dx11.x11,dL_dx12.x12
         ,dL_dx13.x13 /;

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

Solve m using MCP;
$offecho

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

$onecho > implGNEP_dict
* written by GAMS/JAMS at 12/05/16 14:43:13

********************************************************************************
 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 isoobj q0
     4:defisoobj defdemand
     5:min agentobj('1')
     6:q('1','1')
     7:z
     8:defagentobj('1') defdemand
     9:min agentobj('2')
    10:q('2','1')
    11:z
    12:defagentobj('2') defdemand
    13:min agentobj('3')
    14:q('3','1')
    15:z
    16:defagentobj('3') defdemand
    17:min agentobj('4')
    18:q('4','1')
    19:z
    20:defagentobj('4') defdemand
    21:min agentobj('5')
    22:q('5','1')
    23:z
    24:defagentobj('5') defdemand


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


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

      {reformulated}  defisoobj
      {reformulated}  defagentobj(1)
      {reformulated}  defagentobj(2)
      {reformulated}  defagentobj(3)
      {reformulated}  defagentobj(4)
      {reformulated}  defagentobj(5)
                e7_4  defdemand
                  e8  defz
                e7_5  defdemand
                e7_6  defdemand
                e7_7  defdemand
                e7_8  defdemand
                e7_9  defdemand
              dL_dx8  {new}
              dL_dx9  {new}
             dL_dx10  {new}
             dL_dx11  {new}
             dL_dx12  {new}
             dL_dx13  {new}


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

      {reformulated}  isoobj
      {reformulated}  agentobj(1)
      {reformulated}  agentobj(2)
      {reformulated}  agentobj(3)
      {reformulated}  agentobj(4)
      {reformulated}  agentobj(5)
                  x7  z
                  x8  q0
                  x9  q(1,1)
                 x10  q(2,1)
                 x11  q(3,1)
                 x12  q(4,1)
                 x13  q(5,1)
                u7_4  {new}
                u7_5  {new}
                u7_6  {new}
                u7_7  {new}
                u7_8  {new}
                u7_9  {new}
$offecho

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

* testing with implicit and VI shared constraint
put info 'equilibrium';
put / 'implicit', z, defz;
put / 'visol', defdemand;
put / 'min', isoobj, q0;
put / defisoobj, defdemand;
loop(j,
    put / 'min', agentobj(j);
    loop(k, put / q(j,k););
    put / z;
    put / defagentobj(j), defdemand;
);
putclose;

putclose opt
  'Dict     implVIDict.txt' /
  'FileName implVI.gms' ;

ms.optfile = 1;
solve ms using emp;
abort$[ms.solvestat <> %solvestat.NormalCompletion%]
   'wrong ms.solvestat', ms.solvestat;
abort$[ms.modelstat  > %modelstat.LocallyOptimal%]
   'wrong ms.modelstat', ms.modelstat;
abort$[ abs(isoobj.l+267.374) > tol ]        'bad isoobj.l', isoobj.l;
abort$[ abs(agentobj.l('1')+ 10.825) > tol ] 'bad agentobj.l("1")', agentobj.l;
abort$[ abs(agentobj.l('2')+102.696) > tol ] 'bad agentobj.l("2")', agentobj.l;
abort$[ abs(agentobj.l('3')+ 21.109) > tol ] 'bad agentobj.l("3")', agentobj.l;
abort$[ abs(agentobj.l('4')+ 39.619) > tol ] 'bad agentobj.l("4")', agentobj.l;
abort$[ abs(agentobj.l('5')+ 93.125) > tol ] 'bad agentobj.l("5")', agentobj.l;
abort$[ abs(q0.l-0) > tol ]                  'bad q0.l', q0.l;
abort$[ abs(q.l('1','1')-1.717) > tol ]      'bad q.l("1","1")', q.l;
abort$[ abs(q.l('2','1')-5.788) > tol ]      'bad q.l("2","1")', q.l;
abort$[ abs(q.l('3','1')-3.831) > tol ]      'bad q.l("3","1")', q.l;
abort$[ abs(q.l('4','1')-3.011) > tol ]      'bad q.l("4","1")', q.l;
abort$[ abs(q.l('5','1')-2.922) > tol ]      'bad q.l("5","1")', q.l;
abort$[ abs(z.l-17.269) > tol ]              'bad z.l', z.l;
abort$[ abs(defdemand.m-19.571) > tol ]     'bad defdemand.m', defdemand.m;

isoobj.l = 0;
agentobj.l(j) = 0;
q0.l = 0;
q.l(j,k) = 0;
z.l = 0;
defisoobj.m = 0;
defagentobj.m(j) = 0;
defdemand.m = 0;
defz.m = 0;

$onecho > implVI_gms
***********************************************
* written by GAMS/JAMS at 12/05/16 00:11:35
* for more information use JAMS option "Dict"
***********************************************

Variables  x7,x8,x9,x10,x11,x12,x13,u7;

Positive Variables  x8,x9,x10,x11,x12,x13;

Equations  e7,e8,dL_dx8,dL_dx9,dL_dx10,dL_dx11,dL_dx12,dL_dx13;


e7..    x8 + x9 + x10 + x11 + x12 + x13 =E= 17.269913736;

e8..    x7 - x9 - x10 - x11 - x12 - x13 =E= 0;

dL_dx8.. 120 - u7 + eps*x8 =N= 0;

dL_dx9.. (-(59.94352881 + 0.5*(0.4896211468*x9 + 0.4896211468*x9) - (120 - 
         0.178820947388901*sqr(x7))))/(-1) + ((-0.357641894777802*x7*x9)/(-1)
         )*(1) - u7 =N= 0;

dL_dx10.. (-(47.36200134 + 0.5*(0.5399322016*x10 + 0.5399322016*x10) - (120 - 
          0.178820947388901*sqr(x7))))/(-1) + ((-0.357641894777802*x7*x10)/(-1)
          )*(1) - u7 =N= 0;

dL_dx11.. (-(59.73399117 + 0.5*(0.7425081388*x11 + 0.7425081388*x11) - (120 - 
          0.178820947388901*sqr(x7))))/(-1) + ((-0.357641894777802*x7*x11)/(-1)
          )*(1) - u7 =N= 0;

dL_dx12.. (-(52.86751401 + 0.5*(0.4268454892*x12 + 0.4268454892*x12) - (120 - 
          0.178820947388901*sqr(x7))))/(-1) + ((-0.357641894777802*x7*x12)/(-1)
          )*(1) - u7 =N= 0;

dL_dx13.. (-(33.92077449 + 0.5*(0.6000842676*x13 + 0.6000842676*x13) - (120 - 
          0.178820947388901*sqr(x7))))/(-1) + ((-0.357641894777802*x7*x13)/(-1)
          )*(1) - u7 =N= 0;

* set non-default bounds
x8.up = 5;
x9.up = 1.71747132;
x10.up = 8.43266708;
x11.up = 5.50375356;
x12.up = 3.01137904;
x13.up = 2.92212117;

Model m / e7.u7,e8.x7,dL_dx8.x8,dL_dx9.x9,dL_dx10.x10,dL_dx11.x11
         ,dL_dx12.x12,dL_dx13.x13 /;

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

Solve m using MCP;
$offecho

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

$onecho > implVI_dict
* written by GAMS/JAMS at 12/05/16 00:11:35

********************************************************************************
 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:visol defdemand
     4:min isoobj q0
     5:defisoobj defdemand
     6:min agentobj('1')
     7:q('1','1')
     8:z
     9:defagentobj('1') defdemand
    10:min agentobj('2')
    11:q('2','1')
    12:z
    13:defagentobj('2') defdemand
    14:min agentobj('3')
    15:q('3','1')
    16:z
    17:defagentobj('3') defdemand
    18:min agentobj('4')
    19:q('4','1')
    20:z
    21:defagentobj('4') defdemand
    22:min agentobj('5')
    23:q('5','1')
    24:z
    25:defagentobj('5') defdemand


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


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

      {reformulated}  defisoobj
      {reformulated}  defagentobj(1)
      {reformulated}  defagentobj(2)
      {reformulated}  defagentobj(3)
      {reformulated}  defagentobj(4)
      {reformulated}  defagentobj(5)
                  e7  defdemand
                  e8  defz
              dL_dx8  {new}
              dL_dx9  {new}
             dL_dx10  {new}
             dL_dx11  {new}
             dL_dx12  {new}
             dL_dx13  {new}


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

      {reformulated}  isoobj
      {reformulated}  agentobj(1)
      {reformulated}  agentobj(2)
      {reformulated}  agentobj(3)
      {reformulated}  agentobj(4)
      {reformulated}  agentobj(5)
                  x7  z
                  x8  q0
                  x9  q(1,1)
                 x10  q(2,1)
                 x11  q(3,1)
                 x12  q(4,1)
                 x13  q(5,1)
                  u7  {new}
$offecho

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