selkie14.gms : SELKIE test suite: isolated implicit variable

Description

Test isolated implicit variable. In the example, z is an isolated implicit
variable with respect to the first agent.

The problem has a unique solution (x*,y*,z*,q*) = (0.5,2.25,2.25,0.25).

Contributor: Youngdae Kim (09.10.2017)


Small Model of Type : GAMS


Category : GAMS Test library


Main file : selkie14.gms

$title 'SELKIE test suite: isolated implicit variable'  (SELKIE14,SEQ=770)

$ontext

Test isolated implicit variable. In the example, z is an isolated implicit
variable with respect to the first agent.

The problem has a unique solution (x*,y*,z*,q*) = (0.5,2.25,2.25,0.25).

Contributor: Youngdae Kim (09.10.2017)

$offtext

$if not set TESTTOL $set TESTTOL 1e-4
scalar tol / %TESTTOL% /;
file opt   / 'selkie.opt' /;
file info  / '%emp.info%' /;

variable objx, objy, z, q;
positive variable x, y;

equation defobjx, implz, implq, defobjy;

defobjx..
    objx =E= sqr(x-1) + q + 1;

implz..
    z =E= sqr(x) + 2;

implq..
    q =E= sqr(x);

defobjy..
    objy =E= sqr(y-z) + 1;

model m / defobjx, implz, implq, defobjy /;

put info 'equilibrium';
put / 'implicit z implz';
put / 'implicit q implq';
put / 'min objx x z q defobjx';
put / 'min objy y defobjy';
putclose;

* Run without removing isolated implicit variables.
putclose opt 'remove_isolated_implvar no';
m.optfile = 1;

option emp = selkie;
solve m using emp;

abort$[ abs(x.l    - 0.5)  > tol ] 'bad x.l', x.l;
abort$[ abs(y.l    - 2.25) > tol ] 'bad y.l', y.l;
abort$[ abs(z.l    - 2.25) > tol ] 'bad z.l', z.l;
abort$[ abs(q.l    - 0.25) > tol ] 'bad q.l', q.l;
abort$[ abs(objx.l - 1.5)  > tol ] 'bad objx.l', objx.l;
abort$[ abs(objy.l - 1)    > tol ] 'bad objy.l', objy.l;

$onecho > agent1_gms

Variables  x1,x3,x4,x5;

Positive Variables  x5;

Equations  e1,e2,e3;

e1.. -sqr((-1) + x5) + x1 - x4 =E= 1;

e2.. -sqr(x5) + x3 =E= 2;

e3.. -sqr(x5) + x4 =E= 0;



Model m / e1,e2,e3 /;

Solve m using nlp minimizing x1;

$offecho

execute 'cat agent1_gms > agent1.gms.want';
execute 'cat "%gams.scrdir%agent1.gms" > agent1.gms.got';
execute '=diff -bw agent1.gms.want agent1.gms.got';
abort$errorlevel 'Files agent1.gms.want and agent1.gms.got differ';

$onecho > agent2_gms

Variables  x2,x3,x6;

Positive Variables  x6;

Equations  e4;

e4.. -sqr(x6 - x3) + x2 =E= 1;



* fix levels belonging to other agents
x3.fx = 0;

Model m / e4 /;

Solve m using nlp minimizing x2;

$offecho

execute 'cat agent2_gms > agent2.gms.want';
execute 'cat "%gams.scrdir%agent2.gms" > agent2.gms.got';
execute '=diff -bw agent2.gms.want agent2.gms.got';
abort$errorlevel 'Files agent2.gms.want and agent2.gms.got differ';

x.l = 0; x.m = 0;
y.l = 0; y.m = 0;
z.l = 0; z.m = 0;
q.l = 0; q.m = 0;
objx.l = 0; objx.m = 0;
objy.l = 0; objy.m = 0;

defobjx.m = 0;
implz.m = 0;
implq.m = 0;
defobjy.m = 0;

* Run with isolated implicit variables removed.
putclose opt 'remove_isolated_implvar yes';
m.optfile = 1;

option emp = selkie;
solve m using emp;

abort$[ abs(x.l    - 0.5)  > tol ] 'bad x.l', x.l;
abort$[ abs(y.l    - 2.25) > tol ] 'bad y.l', y.l;
abort$[ abs(z.l    - 2.25) > tol ] 'bad z.l', z.l;
abort$[ abs(q.l    - 0.25) > tol ] 'bad q.l', q.l;
abort$[ abs(objx.l - 1.5)  > tol ] 'bad objx.l', objx.l;
abort$[ abs(objy.l - 1)    > tol ] 'bad objy.l', objy.l;

$onecho > agent1_rm_gms

Variables  x1,x4,x5;

Positive Variables  x5;

Equations  e1,e3;

e1.. -sqr((-1) + x5) + x1 - x4 =E= 1;

e3.. -sqr(x5) + x4 =E= 0;



Model m / e1,e3 /;

Solve m using nlp minimizing x1;

$offecho

execute 'cat agent1_rm_gms > agent1_rm.gms.want';
execute 'cat "%gams.scrdir%agent1.gms" > agent1_rm.gms.got';
execute '=diff -bw agent1_rm.gms.want agent1_rm.gms.got';
abort$errorlevel 'Files agent1_rm.gms.want and agent1_rm.gms.got differ';

$onecho > agent2_rm_gms

Variables  x2,x3,x6;

Positive Variables  x6;

Equations  e4;

e4.. -sqr(x6 - x3) + x2 =E= 1;



* fix levels belonging to other agents
x3.fx = 0;

Model m / e4 /;

Solve m using nlp minimizing x2;

$offecho

execute 'cat agent2_rm_gms > agent2_rm.gms.want';
execute 'cat "%gams.scrdir%agent2.gms" > agent2_rm.gms.got';
execute '=diff -bw agent2_rm.gms.want agent2_rm.gms.got';
abort$errorlevel 'Files agent2_rm.gms.want and agent2_rm.gms.got differ';