Description
Test functionality of the GAMS embedded code facility for GAMS during execution time Contributor: Michael Bussieck, January 2023
Small Model of Type : GAMS
Category : GAMS Test library
Main file : embgms02.gms
$title 'Test for embedded code facility' (EMBGMS02,SEQ=926)
$onText
Test functionality of the GAMS embedded code facility for GAMS during execution time
Contributor: Michael Bussieck, January 2023
$offText
Set i / i1 text for i1
i2 text for i2 /
iout(i)
j / j1*j3 /
ij(i,j) / #i.#j /
i_want(i) / i1, i2 /
i_want_ex(i) / i1 text 1, i2 text 2 /
ij_want(i,j) / i1.j1, i1.j2 /
ij_want_merge(i,j) / i1.j1, i1.j2, i1.j3 /
ij_want_ex(i,j) / i1.j1 text 1, i1.j2 text 2/;
Scalar p0 /0.14/
p0_want / 0.14 /;
Parameter p1(i) / #i 1.14 /
p2(i,j) / #i.#j 2.14 /
p1_want(i) / #i 1.14 /
p2_want(i,j) / i1.j1 2.14, i1.j2 2.14 /
p2_want_merge(i,j) / i1.j1 2.14, i1.j2 2.14, i1.j3 2.14 /;
Variable v0 / fx 0.14 /
v1(i) / #i.fx 1.14 /
v2(i,j) / #i.#j.fx 2.14 /
v0_want / l 0.14, m 0, lo 0, up 10, scale 1 /
v1_want(i) / i1.(l 1.14, m 0, lo 0, up 10, scale 1),
i2.(l 1.14, m 0, lo 0, up 10, scale 1) /
v2_want(i,j) / i1.j1.(l 2.14, m 0, lo 0, up 10, scale 1),
i1.j2.(l 2.14, m 0, lo 0, up 10, scale 1) /
v2_want_merge(i,j) / i1.j1.(l 2.14, m 0, lo 0, up 10, scale 1),
i1.j2.(l 2.14, m 0, lo 0, up 10, scale 1),
i1.j3.(l 2.14, m 0, lo 0, up 10, scale 1) /;
equation e0 / fx 0.14 /
e1(i) / #i.fx 1.14 /
e2(i,j) / #i.#j.fx 2.14 /
e0_want / l 0.14, m 0, lo 0, up 10, scale 1 /
e1_want(i) / i1.(l 1.14, m 0, lo 0, up 10, scale 1),
i2.(l 1.14, m 0, lo 0, up 10, scale 1) /
e2_want(i,j) / i1.j1.(l 2.14, m 0, lo 0, up 10, scale 1),
i1.j2.(l 2.14, m 0, lo 0, up 10, scale 1) /
e2_want_merge(i,j) / i1.j1.(l 2.14, m 0, lo 0, up 10, scale 1),
i1.j2.(l 2.14, m 0, lo 0, up 10, scale 1),
i1.j3.(l 2.14, m 0, lo 0, up 10, scale 1) /;
$call rm -f embgms02_log.txt
$onEchoV > checkData
execute_unload 'have.gdx', %1;
execute 'gdxdiff wanted.gdx have.gdx >> embgms02_log.txt';
abort$errorlevel '%2';
$offEcho
put_utility 'save' / 'embgms02';
*** Test default list behavior ***
*Test 1.1: Test default list behavior of scalars
*Test 1.2: Test default list behavior of one dimensional parameters
*Test 1.3: Test default list behavior of multi dimensional parameters
*Test 1.4: Test default list behavior of one dimensional sets
*Test 1.5: Test default list behavior of multi dimensional sets
*Test 1.6: Test default list behavior of scalar variables
*Test 1.7: Test default list behavior of one dimensional variables
*Test 1.8: Test default list behavior of multi dimensional variables
*Test 1.9: Test default list behavior of scalar equations
*Test 1.10: Test default list behavior of one dimensional equations
*Test 1.11: Test default list behavior of multi dimensional equations
*** Test writing symbol data using labels ***
execute_unload 'wanted.gdx', p0_want=p0;
option clear=p0;
put_utility 'xsave' / 'embgms02';
$batInclude checkData p0 'Test 4.1 failed in GAMS'
*Test 4.2: Test writing of one dimensional parameters
execute_unload 'wanted.gdx', p1_want=p1;
option clear=p1;
put_utility 'save' / 'embgms02';
$batInclude checkData p1 'Test 4.2 failed in GAMS'
*Test 4.3: Test writing of multi dimensional parameters
execute_unload 'wanted.gdx', p2_want=p2;
option clear=p2;
put_utility 'xsave' / 'embgms02';
$batInclude checkData p2 'Test 4.3 failed in GAMS'
*Test 4.4: Test writing of one dimensional sets
execute_unload 'wanted.gdx', i_want=iout;
option clear=iout;
put_utility 'save' / 'embgms02';
$batInclude checkData iout 'Test 4.4a failed in GAMS'
execute_unload 'wanted.gdx', i_want_ex=iout;
option clear=iout;
put_utility 'xsave' / 'embgms02';
$batInclude checkData iout 'Test 4.4b failed in GAMS'
*Test 4.5: Test writing of multi dimensional sets
execute_unload 'wanted.gdx', ij_want=ij;
option clear=ij;
put_utility 'save' / 'embgms02';
$batInclude checkData ij 'Test 4.5a failed in GAMS'
execute_unload 'wanted.gdx', ij_want_ex=ij;
option clear=ij;
put_utility 'xsave' / 'embgms02';
$batInclude checkData ij 'Test 4.5b failed in GAMS'
*Test 4.6: Test writing of scalar variable
execute_unload 'wanted.gdx', v0_want=v0;
option clear=v0;
put_utility 'save' / 'embgms02';
$batInclude checkData v0 'Test 4.6 failed in GAMS'
*Test 4.7: Test writing of one dimensonal variables
execute_unload 'wanted.gdx', v1_want=v1;
option clear=v1;
put_utility 'xsave' / 'embgms02';
$batInclude checkData v1 'Test 4.7 failed in GAMS'
*Test 4.8: Test writing of multi dimensonal variables
execute_unload 'wanted.gdx', v2_want=v2;
option clear=v2;
put_utility 'save' / 'embgms02';
$batInclude checkData v2 'Test 4.8 failed in GAMS'
*Test 4.9: Test writing of scalar equations
execute_unload 'wanted.gdx', e0_want=e0;
option clear=e0;
put_utility 'xsave' / 'embgms02';
$batInclude checkData e0 'Test 4.9 failed in GAMS'
*Test 4.10: Test writing of one dimensonal equations
execute_unload 'wanted.gdx', e1_want=e1;
option clear=e1;
put_utility 'save' / 'embgms02';
$batInclude checkData e1 'Test 4.10 failed in GAMS'
*Test 4.11: Test writing of multi dimensonal equations
execute_unload 'wanted.gdx', e2_want=e2;
option clear=e2;
put_utility 'xsave' / 'embgms02';
$batInclude checkData e2 'Test 4.11 failed in GAMS'