emppython1.gms : Three Simple EMP Models with Indexed EMP Syntax and Python Parser

Description

1) An equilibrium model using EMP Python syntax
2) Formulate the simplevi.gms example using EMP Python syntax
3) A combination of optimization and vi agents using EMP Python syntax

Contributor: Youngdae Kim (02/17/2019)


Small Model of Type : GAMS


Category : GAMS EMP library


Main file : emppython1.gms

$Title Three Simple EMP Models with Indexed EMP Syntax and Python Parser (EMPPYTHON1,SEQ=104)
$ontext

1) An equilibrium model using EMP Python syntax
2) Formulate the simplevi.gms example using EMP Python syntax
3) A combination of optimization and vi agents using EMP Python syntax

Contributor: Youngdae Kim (02/17/2019)

$offtext

* On the major platforms (Windows, Linux, Mac), GMSPYTHONHOME gets set automatically 
* if pySetup=1 (default). If the %gams.sysdir%GMSPython directory does not exist on 
* these platforms pySetup will be reset to 0 and GAMS relies on an external Python 
* setup.
$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

$title An equilibrium model using EMP Python syntax

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

variables obj(i);
positive variables x1(i);

equations defobj1(i);

defobj1(i)..
    obj(i) =E= x1(i)*(1 - sum(j, x1(j)));

model m1 / defobj1 /;

$onecho > empinfo.txt
equilibrium
max obj(i) s.t. x1(i), defobj1(i)
$offecho

$libinclude empmodel empinfo.txt

x1.up(i) = 1;
solve m1 using emp;

$title Formulate the simplevi.gms example using EMP Python syntax
sets
   k  / k1, k2 /
   l  / l1 * l3 /;

table A(k,l)
       l1     l2     l3
k1      1      1
k2             1      1;

parameter b(k) /
k1   6
k2   9
/;

positive variable
 x2(l)  'primal vars, perp to f(l)'
 ;

equations
 F(l)
 g(k)
 ;

F(l)..      2 * x2(l)             =n= 0    ;
g(k)..      sum {l, A(k,l)*x2(l)} =g= b(k) ;

model m2 / F, g /;

$onecho > empfile.txt
vi F(l), x2(l), g(k)
$offecho

$libinclude empmodel empfile.txt

solve m2 using emp;

$title A combination of optimization and vi agents using EMP Python syntax

* set i, alias j and variables obj(i) from example 1

variables y;
positive variables x3(i);

equations defobj3(i), defext;

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

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

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

$libinclude empmodel empfile.txt

model m3 / defobj3, defext /;

x3.up(i) = 1;
solve m3 using emp;