[Previous] [Next chapter]
Callbacks
PurposeA callback is a user-specified function called at a specific point or points in the SLP optimization procedure, and which allows the user to intervene in the optimization process.Synopsis(1) procedure CbMessage(Message:string, MsgLen:integer, MsgType:integer)(2) function CbType1:integer(3) function CbType2(VarNum:integer):integer(4) function CbType3(Flag:integer):integerArguments
Message Message text to be printed MsgLen Length of message text MsgType Type of message
4 Error 3 Warning 0,1,2 Information negative Program is finishing VarNum Number of the variable being processed Flag Feasibility flagReturn valueThe procedure form of the callback is only used for xslp_slpmessage. All other forms return a value to the calling program. 0 Normal 1 Mark node as infeasible (MISLP callbacks) or terminate current SLP procedureExampleThe following example defines a callback for xslp_optnode which marks the node as infeasible (so that the branch is not worth pursuing further) if the error costs are too high.SLPsetcallback(xslp_optnode,"MyOptNode") ... function MyOptNode(Flag:integer):integer if getparam("xslp_errorcosts") > 1000 then returned := 1 else returned := 0 end-if end-functionFurther informationAll callbacks are of type CbType1 except the following:
- xslp_cascadevar
- CbType2
- xslp_itervar
- CbType2
- xslp_optnode
- CbType3
- xslp_prenode
- CbType3
- xslp_slpmessage
- CbMessage
- xslp_slpnode
- CbType3
If a function of type CbType1 returns a nonzero value then generally the current part of the SLP optimization procedure is terminated as follows:
- xslp_cascadeend
- No effect
- xslp_cascadestart
- Cascading for the current SLP iteration is omitted
- xslp_slpdestroy
- No effect
- xslp_intsol
- No effect
- xslp_iterend
- The SLP optimization is terminated
- xslp_iterstart
- The SLP optimization is terminated
- xslp_slpend
- The SLP optimizer returns an error code
- xslp_slpstart
- The SLP optimization is omitted
Functions of type CbType2 receive the number of the variable which is currently being processed.
xslp_itervar returns the convergence status of the variable:xslp_cascadevar can change the cascaded value for the variable. Its return value is ignored.
- 0
- No change to the convergence status
- <
0
- Variable has not converged
- n >
0
- Variable has converged with status n
Functions of type CbType3 receive the feasibility status flag. This is normally zero (node is feasible) on entry. The functions cannot change the value of the flag, but the flag is set to a nonzero value if the function returns a nonzero value. A nonzero value for the flag means that the node has been declared infeasible and will not be examined further during the MISLP search.
Related topics
If you have any comments or suggestions about these pages, please send mail to docs@dashoptimization.com.