idol
A C++ Framework for Optimization
Loading...
Searching...
No Matches
StrongBranchingPhase.h
1//
2// Created by henri on 18.10.23.
3//
4
5#ifndef IDOL_STRONGBRANCHINGPHASE_H
6#define IDOL_STRONGBRANCHINGPHASE_H
7
8#include "idol/general/optimizers/Optimizer.h"
9#include <optional>
10#include <memory>
11
12namespace idol {
13
14 class StrongBranchingPhase;
15 class StrongBranchingPhaseType;
16
17 namespace StrongBranchingPhases {
18 class WithNodeOptimizer;
19 class WithIterationLimit;
20 }
21
22}
23
25public:
26 virtual ~StrongBranchingPhaseType() = default;
27
28 virtual void build(Optimizer& t_optimizer) = 0;
29
30 virtual void clean(Optimizer& t_optimizer) = 0;
31
32 [[nodiscard]] virtual StrongBranchingPhaseType* clone() const = 0;
33};
34
36 std::unique_ptr<StrongBranchingPhaseType> m_phase_type;
37 unsigned int m_max_n_variables;
38 unsigned int m_max_depth;
39public:
40 StrongBranchingPhase(const StrongBranchingPhaseType& t_phase_type, unsigned int t_max_n_variables, unsigned int t_max_depth);
41
44
45 [[nodiscard]] const StrongBranchingPhaseType& type() const { return *m_phase_type; }
46
47 [[nodiscard]] StrongBranchingPhaseType& type() { return *m_phase_type; }
48
49 [[nodiscard]] unsigned int max_n_variables() const { return m_max_n_variables; }
50
51 [[nodiscard]] unsigned int max_depth() const { return m_max_depth; }
52};
53
54
56public:
57 void build(Optimizer &t_optimizer) override {
58 // Intentionally left blank
59 }
60
61 void clean(Optimizer &t_optimizer) override {
62 // Intentionally left blank
63 }
64
65 [[nodiscard]] WithNodeOptimizer *clone() const override {
66 return new WithNodeOptimizer(*this);
67 }
68};
69
71 const unsigned int m_iteration_limit;
72 std::optional<unsigned int> m_old_iteration_limit;
73public:
74 explicit WithIterationLimit(unsigned int t_iteration_limit) : m_iteration_limit(t_iteration_limit) {}
75
76 void build(Optimizer &t_optimizer) override {
77 m_old_iteration_limit = t_optimizer.get_param_iteration_limit();
78 t_optimizer.set_param_iteration_limit(m_iteration_limit);
79 }
80
81 void clean(Optimizer &t_optimizer) override {
82 t_optimizer.set_param_iteration_limit(m_old_iteration_limit.value());
83 m_old_iteration_limit.reset();
84 }
85
86 [[nodiscard]] WithIterationLimit *clone() const override {
87 return new WithIterationLimit(*this);
88 }
89};
90
91#endif //IDOL_STRONGBRANCHINGPHASE_H