exmcp5.gms : Intermixed External Rows: External Equation - Example MCP 5

Description


Small Model of Type : GAMS


Category : GAMS Test library


Main file : exmcp5.gms

$title Intermixed External Rows: External Equation - Example MCP 5 (EXMCP5,SEQ=577)

set i / i1 * i5 /;
set c / c1 * c3 /;
alias (i,j), (c,d);

scalar NI, NC;
NI = card(i);
NC = card(c);

positive variables
  u(i)  'external variables 1..NI'
  v(i)  'external variables NI+1..NI+NI'
  w(c)
  x(c)  'external variables 2*NI+1..2*NI+NC'
  y(i)
  ;
equations
  du(i)
  dv(i)
  ev(i)  'external version of dv: 1..NI'
  dw(c)
  dx(c)
  ex(c)  'external version of dx: NI+1..NI+NC'
  dy(i)
  ;

du(i) .. sqr(u(i)) =n= ord(i) - 2.5;

dv(i) .. exp(v(i)) =n= u(i);
ev(i) .. ord(i)*u(i) + (NI+ord(i))*v(i) =x= ord(i);

dw(c) .. w(c)**1.5 =n= 0.1 * sum{j, u(j)};

dx(c) .. x(c)**1.75 =n= 0.2 * sum{i, u(i)};
ex(c) .. (2*NI + ord(c))*x(c) + sum{i, ord(i)*u(i)} =x= NI + ord(c);

dy(i) .. 5*y(i) =g= u(i) - v(i) + sqrt(.125 * sum{c, x(c)});

$                             set pre
$ifI %system.filesys%==unix  $set pre 'lib'
$                             set suf '64'

$set N     exmcp5
$set cN    %pre%%N%c%suf%

model %N%      'GAMS implementation'                         / du.u, dv.v, dw.w, dx.x, dy.y /;
model %cN%     'External equations in C'                     / du.u, ev.v, dw.w, ex.x, dy.y /;

$                             set ext '.dll'
$ifI %system.filesys%==unix  $set ext '.so'
$ifI %system.platform%==dex  $set ext '.dylib'
$ifI %system.platform%==dax  $set ext '.dylib'

$ifThen not set nocomp
$  call gams complink lo=%gams.lo% --lang=c --files=exmcp5c.c --libname=%cN%%ext%
$  if errorlevel 1 $abort Error compiling C Library
$endIf

w.lo(c) = 1e-4;
x.lo(c) = 1e-4;

scalar totdist  / 0 /;
parameter solution_u(i,*), solution_v(i,*), solution_w(c,*), solution_x(c,*), solution_y(i,*);

u.l(i) = 0;
v.l(i) = 0;
w.l(c) = 0;
x.l(c) = 0;
y.l(j) = 0;
solve %N% using mcp;
solution_u(i,'%N%') = u.l(i);
solution_v(i,'%N%') = v.l(i);
solution_w(c,'%N%') = w.l(c);
solution_x(c,'%N%') = x.l(c);
solution_y(i,'%N%') = y.l(i);


u.l(i) = 0;
v.l(i) = 0;
w.l(c) = 0;
x.l(c) = 0;
y.l(i) = 0;
solve %cN% using mcp;
solution_u(i,'%cN%') = u.l(i);
solution_v(i,'%cN%') = v.l(i);
solution_w(c,'%cN%') = w.l(c);
solution_x(c,'%cN%') = x.l(c);
solution_y(i,'%cN%') = y.l(i);

totdist = totdist + sum {i, abs(u.l(i)-solution_u(i,'%N%'))};
totdist = totdist + sum {i, abs(v.l(i)-solution_v(i,'%N%'))};
totdist = totdist + sum {c, abs(w.l(c)-solution_w(c,'%N%'))};
totdist = totdist + sum {c, abs(x.l(c)-solution_x(c,'%N%'))};
totdist = totdist + sum {i, abs(y.l(i)-solution_y(i,'%N%'))};

display solution_u, solution_v, solution_w, solution_x, solution_y;

if {(totdist < 1.0E-6),
  display "@@@@ #Test passed.";
else
  abort totdist, "@@@@ #Test not passed. Inspect exmcp5.lst for details.";
};