ex6.gms : External Equation - Example 6

Description

This example demonstrates the use for two Jacobian elements
in the external equation that are identified with constant
derivatives.


Small Model of Type : GAMS


Category : GAMS Test library


Main file : ex6.gms

$title  External Equation - Example 6 (EX6,SEQ=963)

$onText

  This example demonstrates the use for two Jacobian elements
  in the external equation that are identified with constant
  derivatives.

$offText


Variable x, y, xp, yp, z1, z2, obj;
Equation setx, sety, defxz1, defxz2, defz1, defz2, deforder, defobj;

setx.. x =e= 0.5 + xp;
sety.. y =e= 0.7 + yp;

defxz1..   1*x + 2*y + 3*z1      =x= 1;
defxz2..   1*x + 2*y +      4*z2 =x= 2;

defz1..    sin(x) + cos(y) =e= z1;
defz2..    cos(x) - sin(y) =e= z2;

deforder.. z1 =g= z2 + 0.01;
defobj..   obj =e= sqr(xp) + sqr(yp);

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

$set N     ex6
$set cN    %pre%%N%c%suf%
$set fN    %pre%%N%f%suf%

model %N%      'GAMS implementation'                               / setx, sety, defz1,  defz2,  deforder, defobj /;
model %cN%     'C External equation with file names communicated'  / setx, sety, defxz1, defxz2, deforder, defobj /;

option limcol = 0;
$onText
   Check the solution against the targets:
$offText
parameter report(*,*) Solution Summary;
scalar totdist /0/;

$onEchoV > runme.gms
x.l=0; y.l=0; xp.l=0; yp.l=0; z1.l=0; z2.l=0; obj.l=0;
x.m=0; y.m=0; xp.m=0; yp.m=0; z1.m=0; z2.m=0; obj.m=0;
setx.l=0; sety.l=0; defxz1.l=0; defxz2.l=0; defz1.l=0; defz2.l=0; deforder.l=0; defobj.l=0;
solve %1 using nlp minimizing obj;
abort$(%1.solvestat <> 1) 'problems running model %1';
report('x',  '%1') = x.l;
report('y',  '%1') = y.l;
report('obj','%1') = obj.l;
totdist = totdist + abs(x0 - x.l) + abs(y0 - y.l);
$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'

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

scalar x0 / 0.5 /, y0 / 0.7 /;
$ifThenE sameas('%gams.nlp%','conopt')or(sameas('%gams.nlp%',''))
$  echo rtzern 1e-15 > conopt.opt
   %cN%.optfile = 1;
$endIf  

$             batInclude runme %N%
$if set runC $batInclude runme %cN%

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