mcp12.gms : Test varList matching in model statement

Description

Test varList matching in model statement.
In particular, test on valid inputs.

Contributor: Steven Dirkse, September 2024


Small Model of Type : MCP


Category : GAMS Test library


Main file : mcp12.gms

$title Test varList matching in model statement (MCP12, SEQ=965)

$ontext
Test varList matching in model statement.
In particular, test on valid inputs.

Contributor: Steven Dirkse, September 2024
$offtext

scalar
  XX 'include x in the model'
  x_ 'value of x at solution' / 0.5 /
  ;
set
  u / a, b, c /
  j1(u)
  j2(u)
  j3(u)
  ;
alias(u,a);
parameter
  v1_(u) 'value of v1 at solution'
  v2_(u) 'value of v2 at solution'
  v3_(u) 'value of v3 at solution'
  ;
v1_(u) = 1 + (ord(u)-1)/4;
v2_(u) = 2 + (ord(u)-1)/4;
v3_(u) = 3 + (ord(u)-1)/4;
variable
  v1(u)
  v2(u)
  v3(u)
  x
  ;
equation
  e(u)
  f(u)
  ;
$macro ERHS(j) [v1_(j) + v2_(j) + v3_(j) + x_]
$macro FRHS(j) [v1_(j) + v2_(j) + v3_(j)]

e(u)..  v1(u)$j1(u)       +  v2(u)$j2(u)       +  v3(u)$j3(u)       +  x$XX +
       v1_(u)$[not j1(u)] + v2_(u)$[not j2(u)] + v3_(u)$[not j2(u)] + x_$[not XX]
       =E= ERHS(u);

f(u)..  v1(u) + v2(u) + v3(u) =E= FRHS(u);



model me / e : ( v1 | v2 | v3 ) /;
model mf / f : ( v1 | v2 | v3 ) /;

$macro CHECK_MOD(m) abort$[m.solvestat <> 1] 'bad solvestat', m.solvestat


$ontext
------------------------------------------------------------------------
case: e.(v1,v2,v3) with an empty v-list for some tuple
rows:  e_a,  e_b,  e_c
cols: v1_a, v2_b       x
result: good match, assuming e_c is =E= and x is free
------------------------------------------------------------------------
$offtext
j1(u) = sameas(u,'a');
j2(u) = sameas(u,'b');
j3(u) = no;
XX = 1;

solve me using mcp;  CHECK_MOD(me);

v1.fx('a') = 1;
solve me using mcp;  CHECK_MOD(me);

v1.lo('a') = -INF;
solve me using mcp;  CHECK_MOD(me);

v1.up('a') = 0.25;
solve me using mcp;  CHECK_MOD(me);
v1.up('a') = INF;

$ontext
------------------------------------------------------------------------
case: e.(v1,v2,v3) with an singleton v-list for every tuple
rows:  e_a,  e_b,  e_c
cols: v1_a, v2_b, v3_c
result: good match, independent of bounds on any variables
------------------------------------------------------------------------
$offtext
j1(u) = sameas(u,'a');
j2(u) = sameas(u,'b');
j3(u) = sameas(u,'c');
XX = 0;

solve me using mcp;  CHECK_MOD(me);

v3.fx('c') = 1;
solve me using mcp;  CHECK_MOD(me);

v3.lo('c') = -INF;
solve me using mcp;  CHECK_MOD(me);

v3.up('c') = 0.25;
solve me using mcp;  CHECK_MOD(me);
v3.up('c') = INF;


$ontext
------------------------------------------------------------------------
case: f.(v1,v2,v3) with a full v-list for every tuple
rows:  e_a,  e_b,  e_c
cols: v1_a, v1_b, v1_c
      v2_a, v2_b, v2_c
      v3_a, v3_b, v3_c
result: good match, if we fix 2 or more variables for each tuple
------------------------------------------------------------------------
$offtext
* start with everything fixed
v1.fx(u) = v1_(u);
v2.fx(u) = v2_(u);
v3.fx(u) = v3_(u);

solve mf using mcp;  CHECK_MOD(mf);

v1.fx('c') = 8;
solve mf using mcp;  CHECK_MOD(mf);

v1.lo('c') = 0;
solve mf using mcp;  CHECK_MOD(mf);

v2.lo('b') = -INF;
v2.up('b') = INF;
solve mf using mcp;  CHECK_MOD(mf);


v1.up('a') = 1000;
v1.lo('a') = -1000;
solve mf using mcp;  CHECK_MOD(mf);

$onText
------------------------------------------------------------------------
case: all scalar = fs.(vs1,vs2,vs3)
rows:  fs
cols: va1
      va2
      va3
result: good match, if we fix 2 or more variables
------------------------------------------------------------------------
$offText

variable
  vs1
  vs2
  vs3
  ;

equation
  fs
  ;

fs..  vs1 + vs2 + vs3 =E= 1;

model mfs / fs : ( vs1 | vs2 | vs3 ) /;

* start with everything fixed
vs1.fx = 1;
vs2.fx = 1;
vs3.fx = 1;
solve mfs using mcp;  CHECK_MOD(mfs);

vs2.lo = -INF;
vs2.up = INF;
solve mfs using mcp;  CHECK_MOD(mfs);

$onText
------------------------------------------------------------------------
case: f.(v1,v2,v3) with a full v-list for every tuple - with extra dimension
rows:  fv_a,  fv_b,  fv_c
cols: vv1_a, vv1_b, vv1_c
      vv2_a, vv2_b, vv2_c
      vv3_a, vv3_b, vv3_c
result: good match, if we fix 2 or more variables for each tuple
------------------------------------------------------------------------
$offText

Set
  v / x, y, z /
  ;

Parameter
  vv1_(u,v) 'value of v1 at solution'
  vv2_(u,v) 'value of v2 at solution'
  vv3_(u,v) 'value of v3 at solution'
  ;
vv1_(u,v) = 1 + (ord(u)-1)/4 + (ord(v)-1)/4;
vv2_(u,v) = 2 + (ord(u)-1)/4 + (ord(v)-1)/4;
vv3_(u,v) = 3 + (ord(u)-1)/4 + (ord(v)-1)/4;

Variable
  vv1(u,v)
  vv2(u,v)
  vv3(u,v)
  ;
equation
  fv(u,v)
  ;

$macro FRHSV(j,v) [vv1_(j,v) + vv2_(j,v) + vv3_(j,v)]

fv(u,v)..  vv1(u,v) + vv2(u,v) + vv3(u,v) =E= FRHSV(u,v);

Model mfv / fv : ( vv1 | vv2 | vv3 ) /;

* start with everything fixed
vv1.fx(u,v) = vv1_(u,v);
vv2.fx(u,v) = vv2_(u,v);
vv3.fx(u,v) = vv3_(u,v);

solve mfv using mcp;  CHECK_MOD(mfv);

vv1.fx('c',v) = 8;
solve mfv using mcp;  CHECK_MOD(mfv);

vv1.lo('c',v) = 0;
solve mfv using mcp;  CHECK_MOD(mfv);

vv2.lo('b',v) = -INF;
vv2.up('b',v) = INF;
solve mfv using mcp;  CHECK_MOD(mfv);


vv1.up('a',v) = 1000;
vv1.lo('a',v) = -1000;
solve mfv using mcp;  CHECK_MOD(mfv);