SLPsetcallback


Purpose
Set a Mosel function to be used as an SLP callback
Synopsis
procedure SLPsetcallback(cbNumber:integer, cbFunc:string)
Arguments
cbNumber 
the number of the callback. This can be one of the Xpress-SLP constants named to match the callbacks.
cbFunc 
string holding the name of the Mosel function or procedure to receive the callback. An empty string removes any previously-defined callback of this type.
Example
The following is a small example of a callback function. The name of the function (myIterStart) is used in the SLPsetcallback procedure.
function myIterStart : integer
  writeln("SLP iteration ", getparam("xslp_iter")
  returned := 0
end-function
...
SLPsetcallback(2, "myIterStart")
SLPsetcallback(xslp_iterstart, "myIterStart")
The first usage of SLPsetcallback sets SLP callback number 2 to be the Mosel function myIterStart in the current model. The second usage does the same thing, but is more readable because it uses the constant xslp_iterstart instead of the number 2. In addition, the second example is more robust because it will continue to work even if the value of the parameter changes.
The next example shows a callback function to be used within global optimization. It tests the value of the parameter xslp_errorcosts which is the total feasibility error cost of the solution. If it is significant (>10) then the node is declared infeasible (the function returns a nonzero value). The name of the function (MyNodeCB) is used in the SLPsetcallback procedure.
function MyNodeCB(feas:integer) : integer
  if getparams("xslp_errorcosts") > 10 then
    returned := 1
    writeln("Terminated on feasibility error costs")
  else
    returned := 0
end-function
...
SLPsetcallback(xslp_slpnode, "MyNodeCB")
Further information

This function defines a Mosel function or procedure to be the callback function at a defined point in the Xpress-SLP optimization. The callback type is given in the first argument, either as a number or — better — by using one of the defined Xpress-SLP constants. The name of the function or procedure is given as a string in the second argument.

If the function cannot be identified as a Mosel function, it will be checked against the user function list. If it is found there, then the user function will be used as the callback. This extension can only be used if the user function has the correct linkage to be a callback (an Excel spreadsheet, for example, would not qualify). It is primarily intended to be used where the callback is in a compiled external library.

The function itself must behave like the corresponding Xpress-SLP callback function: in general, this means that the functions are declared as of type integer; the normal return value is zero and the abnormal return value is nonzero. See the Xpress-SLP Reference Manual for more details. Most of the Mosel callback functions do not take arguments. The exceptions are:

XSLPcascadevar(VarNum:integer) : integer
XSLPitervar(VarNum:integer) : integer
which have one integer argument holding the number of the variable being processed.

XSLPoptnode(feas:integer) : integer
XSLPprenode(feas:integer) : integer
XSLPslpnode(feas:integer) : integer
which have one integer argument holding the current value of the feasibility flag. The value of the flag can be checked, but cannot be changed. It is set to 1 if the callback function returns a nonzero value.

XSLPslpmessage(Message:string, MsgLen:integer, MsgType:integer)
which has arguments holding the message, message length and message type. This should be defined as a procedure rather than as a function, because there is no return value.
Note that if this callback is used, then the normal SLP message handling by Mosel will be over-ridden.




If you have any comments or suggestions about these pages, please send mail to docs@dashoptimization.com.