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);