selkie03.gms : SELKIE test suite

Description

Contributor: Youngdae Kim (06.26.2017)


Small Model of Type : GAMS


Category : GAMS Test library


Main file : selkie03.gms

$title 'SELKIE test suite'  (SELKIE03,SEQ=759)

$ontext

Contributor: Youngdae Kim (06.26.2017)

$offtext

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

Sets	i      	Nodes at which value function is evaluated	/1*5/,
	ia	Terms for function approximation		/coef0*coef2/;

alias(i,j);

Parameters
	kbar(i)		Capital stock at node i;

kbar(i) = i.val;

variables
        OBJ1            Objective for utility,
        OBJ2            Objective for least squares,
	U(i)		Nodal approximations of utility,
	A(ia)		Terms in the value function approximation;

equations
        utility         Present value benefit function,
        udef(i)         Nodal approximations of utility,
	objdef		Least squares objective;

utility..       OBJ1 =e= sum(i, U(i));

udef(i)..       U(i) =e= 0;

objdef..	OBJ2 =e= sum(j, sqr(sum(ia,A(ia)*power(kbar(j),ord(ia)-1)) - u(j)));

model m / utility, udef, objdef /;

put info 'equilibrium';
put 'min', OBJ2, 'A', objdef;
put 'max', OBJ1, 'U', utility, 'udef';
putclose;

option emp = selkie;
solve m using emp;
abort$[ smax{ia, abs(A.l(ia))} > tol ] 'bad A.l(ia)', A.l;
abort$[ smax{i,  abs(U.l(i))}  > tol ] 'bad U.l(i)', U.l;

$onecho > agent1_gms

Variables  x2,x3,x4,x5,x6,x7,x8,x9,x10;

Equations  e7;

e7.. -(sqr(x8 - x3 + x9 + x10) + sqr(x8 - x4 + 2*x9 + 4*x10) + sqr(x8 - x5 + 3*
     x9 + 9*x10) + sqr(x8 - x6 + 4*x9 + 16*x10) + sqr(x8 - x7 + 5*x9 + 25*x10))
      + x2 =E= 0;



* fix levels belonging to other agents
x3.fx = 0;
x4.fx = 0;
x5.fx = 0;
x6.fx = 0;
x7.fx = 0;

Model m / e7 /;

Solve m using nlp minimizing x2;

$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  x1,x3,x4,x5,x6,x7;

Equations  e1,e2,e3,e4,e5,e6;

e1..    x1 - x3 - x4 - x5 - x6 - x7 =E= 0;

e2..    x3 =E= 0;

e3..    x4 =E= 0;

e4..    x5 =E= 0;

e5..    x6 =E= 0;

e6..    x7 =E= 0;



Model m / e1,e2,e3,e4,e5,e6 /;

Solve m using nlp maximizing x1;

$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';

* Test the model without writing agent's problem into a file.
putclose opt 'write_agent_model   no';
m.optfile = 1;

OBJ1.l = 0;
OBJ2.l = 0;
A.l(ia) = 0;
U.l(i) = 0;

solve m using emp;
abort$[ smax{ia, abs(A.l(ia))} > tol ] 'bad A.l(ia)', A.l;
abort$[ smax{i,  abs(U.l(i))}  > tol ] 'bad U.l(i)', U.l;