Download LINDO API USER MANUAL

Transcript
SOLVING NONLINEAR PROGRAMS
347
Usercalc()
Description:
In Grey-box style interface, this is the user/front-end supplied routine, required by the
EP_USER operator, to compute the value of a user-defined function for a given set of
arguments. The arguments the function uses are passed through in a double array of a prespecified size.
This function name used here, Usercalc(), is arbitrary, and is merely for illustration. Since
this function will reside in your calling application, you may choose any name you wish.
However, the interface described below must be duplicated.
This function should be provided for all nonlinear models that contain the EP_USER
operator. This operator is particularly useful in expressing nonlinear relations, which are
difficult or impossible to express in closed form. You should use the LSsetUsercalc() routine
to identify your Usercalc() routine to LINDO API.
Returns:
Returns a value greater than 0 if a numerical error occurred while computing the function
value (e.g., square root of a negative number). Otherwise, return 0.
Prototype:
int
Usercalc ( pLSmodel pModel, int nArgs, double *pdValues,
void *pUserData, double *pdFuncVal);
Input Arguments:
Name
Description
pModel
Pointer to an instance of LSmodel.
nArgs
The number of arguments the function requires to evaluate the
function value.
pdValues
A pointer to a double array containing the values of the
arguments that will be used to evaluate the function. The size
of this array is specified by nArgs.
pUserData
Pointer to a user data area or structure in which any other data
needed to calculate function values can be stored (e.g., input
for a simulation experiment). LINDO API obtains the value of
this pointer when the Usercalc() routine is established through
a call to LSsetFuncalc() (see below). Subsequently, whenever
LINDO API calls your Usercalc() routine, it passes the same
pointer value through pUserData. Any data that Usercalc()
needs to compute the function value could be stored in the data
structure pointed to by pUserData.
Output Arguments:
Name
Description
pdFuncVal
*pdFuncVal returns the value of the function.