XSLPsetcbformula
XSLPsetcbformula |
Purpose
Set a callback to be used in formula evaluation when an unknown token is found
Synopsis
int XPRS_CC XSLPsetcbformula(XSLPprob Prob, int (XPRS_CC *UserFunc) (XSLPprob myProb, void *myObject, double Value, double *Result), void *Object);
Arguments
Prob
|
The current SLP problem.
|
UserFunc
|
The function to be called during formula evaluation.
UserFunc returns an integer value. At present the value is ignored.
|
myProb
|
The problem passed to the callback function.
|
myObject
|
The user-defined object passed as
Object to
XSLPsetcbformula.
|
Value
|
The
Value of the unknown token.
|
Result
|
Address of a double precision value to hold the result of the calculation.
|
Object
|
Address of a user-defined object, which can be used for any purpose by the function.
Object is passed to
UserFunc as
myObject.
|
Example
The following example sets a callback to process unknown tokens in formulae. It then creates a formula with an unknown token, and evaluates it.
int XPRS_CC MyCB(XSLPprob MyProb, void *MyObject, double MyValue, double *Result) { union { char *p; double d;} z; z.d = MyValue; if (z.p != NULL) *Result = atof(z.p); else *Result = 0; return(0); } ... int Type[10]; double Value[10]; int nToken; double Answer; union { char *p; double d;} z; XSLPsetcbformula(prob,MyCB,NULL); nToken = 0; Type[nToken] = XSLP_CON; Value[nToken++] = 10; Type[nToken] = XSLP_UNKNOWN; z.p = "25.2"; Value[nToken++] = z.d; Type[nToken] = XSLP_OP; Value[nToken++] = XSLP_PLUS; Type[nToken] = XSLP_EOF; Value[nToken++] = 0; XSLPevaluateformula(prob,1,Type,Value,&Answer); printf("Answer = %lg",Answer);
This demonstrates how the Value of an unknown token can be set in any way, as long as the routine that sets the token up and the callback agree on how it is to be interpreted.
In this case, the value actually contains the address of a character string, which is converted by the callback into a real number.
Related topics