User Defined Functions

The @USER function allows the use of custom functions of your own design in LINGO. In Windows versions of LINGO, you provide a  Dynamic Link Library (DLL) that contains your @USER function. Most programming languages that support Windows should allow you to build a DLL. For platforms other than Windows, you provide LINGO with a compiled C or FORTRAN subroutine containing your @USER function.

From the perspective of a LINGO modeler, an @USER function is a function that can take any number of arguments, but must take at least one. It returns a result calculated by the user-written routine.

From the perspective of the programmer writing the custom function, an @USER function takes only two input arguments and returns a single result. The two input arguments consist of:

1.an integer specifying the number of arguments encountered in the @USER reference in the LINGO model, and
2.a vector containing the values of the arguments in the order in which they were encountered in the @USER reference in double precision format (i.e., an 8 byte floating point format).

In other words, although to the LINGO modeler an @USER function can appear to take any number of arguments, to the programmer implementing the @USER function, only two input arguments are passed.

It is possible to use multiple functions with @USER by writing and compiling each function as a separate subroutine and taking an argument to @USER as the index number of the subroutine that you want to branch to.