problem.addcbintsol
problem.addcbintsol |
Purpose
Declares a user integer solution callback function, called every time an integer solution is found by heuristics or during the Branch and Bound search. This callback function will be called in addition to any callbacks already added by addcbintsol.
Synopsis
problem.addcbintsol(callback, data, priority)
callback(my_prob, my_object)
Arguments
callback
|
The callback function which takes two arguments,
my_prob and
my_object, and has no return value. This function is called if the current node is found to have an integer feasible solution, i.e. every time an integer feasible solution is found.
|
my_prob
|
The problem passed to the callback function,
callback.
|
my_object
|
The user-defined object passed as
object when setting up the callback with
addcbintsol.
|
data
|
A user-defined object to be passed to the callback function,
callback.
|
priority
|
An integer that determines the order in which multiple integer solution callbacks will be invoked. The callback added with a higher priority will be called before a callback with a lower priority. Set to 0 if not required.
|
Example
The following example prints integer solutions as they are discovered in the global search:
prob.addcbintsol(printsol, None, 0) prob.mipoptimize("")
The callback function might resemble:
def printsol(my_prob, object): cols = my_prob.attributes.originalcols objval = my_prob.attributes.lpobjval x = [] my_prob.getlpsol(x, None, None, None) print("Integer solution found:", objval, "; values:") print(x)
Further information
1. This callback is useful if the user wants to retrieve the integer solution when it is found.
2. To retrieve the integer solution, use either
problem.getlpsol or
problem.getpresolvesol.
problem.getmipsol always returns the last integer solution found and, if called from the
intsol callback, it will not necessarily return the solution that caused the invocation of the callback (for example, it is possible that when solving with multiple MP threads, another thread finds a new integer solution before the user calls
problem.getmipsol).
3. This callback is called after a new integer solution was found by the Optimizer. Use a callback set by
problem.addcbpreintsol in order to be notified before a new integer solution is accepted by the Optimizer, which allows for the new solution to be rejected.
Related topics