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'

$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.platform%==dex  $set ext '.dylib'
$ifI %system.platform%==dax  $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.";
};