idol
A C++ Framework for Optimization
Loading...
Searching...
No Matches
StrongBranching.h
1//
2// Created by henri on 17.10.23.
3//
4
5#ifndef IDOL_STRONGBRANCHING_H
6#define IDOL_STRONGBRANCHING_H
7
8#include "VariableBranching.h"
9#include "idol/mixed-integer/optimizers/branch-and-bound/branching-rules/impls/NodeScoreFunction.h"
10#include "idol/mixed-integer/optimizers/branch-and-bound/branching-rules/impls/strong-branching/StrongBranchingPhase.h"
11#include "idol/mixed-integer/optimizers/branch-and-bound/branching-rules/impls/StrongBranching.h"
12
13namespace idol {
14 class StrongBranching;
15}
16
18public:
19 StrongBranching() = default;
20
21 template<class IteratorT>
22 StrongBranching(IteratorT t_begin, IteratorT t_end) : idol::VariableBranching(t_begin, t_end) {}
23
24 template<class NodeInfoT>
25 class Strategy : public VariableBranching::Strategy<NodeInfoT> {
26 std::optional<unsigned int> m_max_n_variables;
27 std::unique_ptr<NodeScoreFunction> m_node_scoring_function;
28 std::list<StrongBranchingPhase> m_phases;
29
30 public:
31 Strategy() = default;
32
33 Strategy(const Strategy<NodeInfoT>& t_src);
34
35 explicit Strategy(const StrongBranching& t_parent);
36
38 operator()(const Optimizers::BranchAndBound<NodeInfoT> &t_parent) const override {
40 t_parent,
42 m_max_n_variables.has_value() ? m_max_n_variables.value() : 100,
43 m_node_scoring_function ? m_node_scoring_function->clone() : new NodeScoreFunctions::Product(),
44 m_phases
45 );
46 }
47
48 VariableBranching::Strategy<NodeInfoT> *clone() const override {
49 return new Strategy(*this);
50 }
51 };
52
53 StrongBranching& with_max_n_variables(unsigned int t_n_variables);
54
55 StrongBranching& with_node_scoring_function(const NodeScoreFunction& t_score_function);
56
57 StrongBranching& add_phase(const StrongBranchingPhaseType &t_phase, unsigned int t_max_n_variables, unsigned int t_max_depth);
58private:
59 std::optional<unsigned int> m_max_n_variables;
60 std::unique_ptr<NodeScoreFunction> m_node_scoring_function;
61 std::list<StrongBranchingPhase> m_phases;
62};
63
64template<class NodeInfoT>
66 : VariableBranching::Strategy<NodeInfoT>(t_parent),
67 m_max_n_variables(t_parent.m_max_n_variables),
68 m_node_scoring_function(t_parent.m_node_scoring_function ? t_parent.m_node_scoring_function->clone() : nullptr),
69 m_phases(t_parent.m_phases) {
70
71}
72
73template<class NodeInfoT>
74idol::StrongBranching::Strategy<NodeInfoT>::Strategy(const Strategy<NodeInfoT>& t_src)
75 : VariableBranching::Strategy<NodeInfoT>(t_src),
76 m_max_n_variables(t_src.m_max_n_variables),
77 m_node_scoring_function(t_src.m_node_scoring_function ? t_src.m_node_scoring_function->clone() : nullptr),
78 m_phases(t_src.m_phases)
79{}
80
81#endif //IDOL_STRONGBRANCHING_H