Initializing help system before first use

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

© 2001-2019 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.