emppy3.gms : Test a combination of optimization and vi agents using emp python

Description

Test a combination of optimization and vi agents using emp python.

Contributor: Youngdae Kim (10.26.2018)


Small Model of Type : GAMS


Category : GAMS Test library


Main file : emppy3.gms

$title 'Test a combination of optimization and vi agents using emp python' (EMPPY3,SEQ=791)

$ontext
Test a combination of optimization and vi agents using emp python.

Contributor: Youngdae Kim (10.26.2018)
$offtext


* On the major platforms, GMSPYTHONHOME gets set automatically, otherwise the
* user has to set it. This condition can also be removed, if one has set up its
* Python environment appropriately
$if not setEnv GMSPYTHONHOME
$if %gams.pySetup%==1 $abort.noError Embedded code Python not ready to be used
$if not setEnv GMSPYTHONHOME $log --- Using external Python

$if not set TESTTOL $set TESTTOL 1e-3
scalar tol / %TESTTOL% /;
file opt   / 'jams.opt' /;

set i / 1*3 /;
alias(i,j);

variables obj(i), y;
positive variables x(i);

equations defobj(i), defext;

defobj(i)..
    obj(i) =E= x(i)*(1 - sum(j, x(j))) + y;

defext..
    1 - sum(j, x(j)) - y =E= 0;

$onecho > empfile.txt
equilibrium
max obj(i) s.t. x(i), defobj(i)
vi defext, y
$offecho

$libinclude empmodel empfile.txt

model m / defobj, defext /;

putclose opt 'FileName m.gms';
m.optfile = 1;

x.up(i) = 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$[ smax{i, abs(obj.l(i) - 0.312)} > tol ] 'bad obj.l', obj.l;
abort$[ smax{i, abs(x.l(i) - 0.25)} > tol ] 'bad x.l', x.l;
abort$[ abs(y.l - 0.25) > tol ] 'bad y.l', y.l;

$onecho > m_gms
***********************************************
* written by GAMS/JAMS at 10/27/18 00:02:22
* for more information use JAMS option "Dict"
***********************************************

Variables  x4,x5,x6,x7;

Positive Variables  x5,x6,x7;

Equations  e4,dL_dx5,dL_dx6,dL_dx7;


e4..  - x4 - x5 - x6 - x7 =E= -1;

dL_dx5.. (-(1 - x5 - x6 - x7 - x5))/(1) =N= 0;

dL_dx6.. (-(1 - x5 - x6 - x7 - x6))/(1) =N= 0;

dL_dx7.. (-(1 - x5 - x6 - x7 - x7))/(1) =N= 0;

* set non-default bounds
x5.up = 1;
x6.up = 1;
x7.up = 1;

Model m / e4.x4,dL_dx5.x5,dL_dx6.x6,dL_dx7.x7 /;

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

Solve m using MCP;
$offecho

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