emppy2.gms : Formulate the simplevi.gms example using emp python

Description

Formulate the simplevi.gms example using emp python.

Contributor: Youngdae Kim (10.26.2018)


Small Model of Type : GAMS


Category : GAMS Test library


Main file : emppy2.gms

$title 'Formulate the simplevi.gms example using emp python' (EMPPY2,SEQ=790)

$onText
Formulate the simplevi.gms example using emp python.

Contributor: Youngdae Kim (10.26.2018)
$offText


$log --- Using Python library %sysEnv.GMSPYTHONLIB%

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

sets
 I  / i1, i2 /
 J  / j1 * j3 /
 ;

table A(I,J)
       j1        j2     j3
i1      1         1
i2                1      1 ;

parameter b(I) /
i1   6
i2   9
/;

positive variable
 x(J)  'primal vars, perp to f(J)'
 ;

equations
 F(J)
 g(I)
 ;

F(J)..      2 * x(J)             =n= 0    ;
g(I)..      sum {j, A(I,J)*x(J)} =g= b(I) ;

model m / F, g/;

$onEcho > empfile.txt
vi F(J), x(J), g(I)
$offEcho

$libInclude empmodel empfile.txt

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

solve m using emp;

abort$[m.solvestat <> %solveStat.normalCompletion%]
     'wrong m.solvestat', m.solvestat;
abort$[m.modelstat <> %modelStat.optimal%]
     'wrong m.modelstat', m.modelstat;
abort$[ abs(F.l('j1') -  2) > tol ] 'bad F.l("j1")', F.l;
abort$[ abs(F.l('j2') - 10) > tol ] 'bad F.l("j2")', F.l;
abort$[ abs(F.l('j3') -  8) > tol ] 'bad F.l("j2")', F.l;
abort$[ abs(g.l('i1') - 6) > tol ] 'bad g.l("i1")', g.l;
abort$[ abs(g.l('i2') - 9) > tol ] 'bad g.l("i2")', g.l;
abort$[ abs(x.l('j1') - 1) > tol ] 'bad x.l("j1")', x.l;
abort$[ abs(x.l('j2') - 5) > tol ] 'bad x.l("j2")', x.l;
abort$[ abs(x.l('j3') - 4) > tol ] 'bad x.l("j2")', x.l;

$onEcho > m_gms
***********************************************
* written by GAMS/JAMS at 10/26/18 23:38:39
* for more information use JAMS option "Dict"
***********************************************

Variables  x1,x2,x3,u4,u5;

Positive Variables  x1,x2,x3;

Positive Variables  u4,u5;

Equations  e1,e2,e3,e4,e5;


e1..    2*x1 - u4 =N= 0;

e2..    2*x2 - u4 - u5 =N= 0;

e3..    2*x3 - u5 =N= 0;

e4..    x1 + x2 =G= 6;

e5..    x2 + x3 =G= 9;

Model m / e1.x1,e2.x2,e3.x3,e4.u4,e5.u5 /;

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 -I reslim -bw m.gms.want m.gms.got'
abort$errorlevel 'Files m.gms.want and m.gms.got differ';