BranchAndBoundCallback

This class can be used to create callbacks to run on idol’s branch-and-bound implementation.

Warning

BranchAndBoundCallback-s is an advanced feature.

Please, make sure that what you are trying do cannot be done with a solver-independent callback first, or with pre-existing callbacks, e.g., UserCutCallback or LazyCutCallback.

The advantage of using a BranchAndBoundCallback instead of a standard solver-independent Callback lies in the possibility to access specific information regarding the execution of the branch-and-bound algorithm. For instance, accessing a node’s information, or the current relaxation model being solved.

Example

Here is an example of callback which prints out the event triggering it and, when the event corresponds to NodeLoaded, prints the node’s model to be solved.

class MyCallback : public BranchAndBoundCallbackFactory<NodeInfo> {
public:
    class Strategy : public BranchAndBoundCallback<NodeInfo> {
    protected:
        void operator()(CallbackEvent t_event) override {

            std::cout << "MyCallback is called for " << t_event << std::endl;

            if (t_event != NodeLoaded) {
                return;
            }

            std::cout << "The problem being solve at node " << node().id() << std::endl;
            std::cout << relaxation() << std::endl;

        }
    };

    BranchAndBoundCallback<NodeInfo> *operator()() override {
        return new Strategy();
    }

    [[nodiscard]] BranchAndBoundCallbackFactory<NodeInfo> *clone() const override {
        return new MyCallback(*this);
    }
};

Then, this callback can be used as follows.

model.use(
    BranchAndBound()
        .with_node_optimizer(GLPK::ContinuousRelaxation())
        .with_branching_rule(MostInfeasible())
        .with_node_selection_rule(DepthFirst())
        .with_callback(MyCallback());
);

Hint

By default, most of the objects returned by BranchAndBoundCallback methods are const. If you wish to access non-const versions (e.g., if you want to perform non-standard updates to the relaxed model or want to change the node’s current information manually), you should use the advanced interface obtained by calling BranchAndBoundCallback::advanced_interface.

Doxygen

Warning

doxygenclass: Cannot find class “idol::BranchAndBoundCallback” in doxygen xml output for project “idol” from directory: _build/xml/