exmcp2.gms : External Equation - Example MCP 2

Description

DLL Test Problem Number MCP2 -- dense nonlinear system


Small Model of Type : GAMS


Category : GAMS Test library


Main file : exmcp2.gms

$Title External Equation - Example MCP 2 (EXMCP2,SEQ=574)

$ontext
  DLL Test Problem Number MCP2 -- dense nonlinear system
$offtext


set     i       /i1*i8/;
alias (i,j);

variables       x(i)    Unknowns;
equations       equ(j)  System of equations
                equx(j) System of equations with external equations;

equ(j)..        sqr(x(j)) + sum(i, 0.1 * ord(i) * x(i)) =e= 1;

equx(j)..       sum(i, ord(i) * x(i)) =x= ord(j);

parameter       x0(J)   Starting point (for GAMS and external equations);

x0(j) = uniform(0,1);
option sysout=on;


x.l(j) = x0(j);

$                             set pre
$ifi %system.filesys%==unix  $set pre 'lib'
$                             set suf '64'
$ifi %system.buildcode%==vs8 $set suf

$set N     exmcp2
$set cN    %pre%%N%c%suf%
$set c_cbN %pre%%N%c_cb%suf%
$set fN    %pre%%N%f%suf%
$set f_cbN %pre%%N%f_cb%suf%

model %N%      'GAMS implementation'                         / equ /;
model %cN%     'External equations in C'                     / equx /;
model %c_cbN%  'External equations in C, with callbacks'     / equx /;
model %fN%     'External equations in F77'                   / equx /;
model %f_cbN%  'External equations in F77, with callbacks'   / equx /;

scalar totdist /0/;
parameter solution(J,*);

*       Check that the model dimension here is consistent
*       with the external equation implementation
abort$(card(i) ne 8) " Inconsistent dimension -- it must equal 8!";

$onechoV > runme.gms
x.l(j) = x0(j);
solve %1 using mcp;
solution(j,"%1") = x.l(j);
totdist = totdist + sum {J, abs(x.l(J)-solution(J,'exmcp2'))};
$offecho

$                             set ext '.dll'
$ifi %system.filesys%==unix  $set ext '.so'
$ifi %system.buildcode%==deg $set ext '.dylib'

$                             set eq
$ifi %system.filesys%==unix  $set eq "'"

$if set runall  $set runC '1' set runC_cb '1' set runF '1' set runF_cb '1'

$ifthen not set nocomp
$  ifi set runC    $call gams complink lo=%gams.lo% --lang=c         --files=exmcp2c.c                                        --libname=%cN%%ext%
$  if errorlevel 1 $abort Error compiling C Library
$  ifi set runC_cb $call gams complink lo=%gams.lo% --lang=c         --files=exmcp2c_cb.c                                     --libname=%c_cbN%%ext%
$  if errorlevel 1 $abort Error compiling C Library
$  ifi set runF    $call gams complink lo=%gams.lo% --lang=fortran90 --files=%eq%"gehelper.f90 exmcp2f.f90"%eq%               --libname=%fN%%ext%
$  if errorlevel 1 $abort Error compiling Fortran90 Library
$  ifi set runF_cb $call gams complink lo=%gams.lo% --lang=fortran90 --files=%eq%"gehelper.f90 msg2_f.f90 exmcp2f_cb.f90"%eq% --libname=%f_cbN%%ext%
$  if errorlevel 1 $abort Error compiling Fortran90 Library
$endif

$                batinclude runme %N%
$if set runC    $batinclude runme %cN%
$if set runC_cb $batinclude runme %c_cbN%
$if set runF    $batinclude runme %fN%
$if set runF_cb $batinclude runme %f_cbN%

display solution;

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