Building the external function evaluator

Top  Previous  Next

The user must write a custom DLL to evaluate the functions.  It must be callable as the function

 

GEFUNC (icntr, x, f, d, msgcb)

 

This code is created in a programming language (C, Delphi, Fortran etc.).

The GEFUNC parameters are

icntris used to communicate control information between the solver and the DLL and includes the number of the equation to be evaluated
xis vector of variable values passed from GAMS to the solver
fis evaluated value of the external function value at  point x
dis a vector containing derivatives of each variable in the function evaluated at the point x
msgcbis a parameter that allows messages to be passed

Also the function must return a control code indicating whether any problems were encountered.  In doing this care must be taken to insure that the derivatives and functions are continuous.

Notes:

The DLL must generally have the extension DLL (note other extensions are used on non windows platforms).
The DLL must generally be named with the name of the model solved but one can alter this using a file statement and including the named file in the Model statement  as follows

 file mydll /targetname.dll/;

 model m /eq1,eq2,mydll/;

 

 where targetname.dll becomes the active name for the DLL.

Example:

(external.gms, extern.zip)

Suppose I use an example from the GAMS web page.  Namely suppose I wish to specify the objective function of a quadratic model via an external function.  In such a case one would define the objective function as follows (external.gms)

 

zdefX .. sum(i, ord(i)*x(i) ) + (card(i)+1)* z =X= 1;

 

and would also define an external DLL which evaluates this function.  A Delphi version of this is in extern.zip.