idol
A C++ Framework for Optimization
Loading...
Searching...
No Matches
BranchingWithPriority.h
1//
2// Created by henri on 09.11.23.
3//
4
5#ifndef IDOL_IMPL_BRANCHINGWITHPRIORITY_H
6#define IDOL_IMPL_BRANCHINGWITHPRIORITY_H
7
8
9#include <list>
10#include "BranchingRule.h"
11#include "idol/mixed-integer/modeling/variables/Var.h"
12#include "idol/general/utils/Point.h"
13#include "idol/mixed-integer/optimizers/branch-and-bound/branching-rules/factories/BranchingRuleFactory.h"
14
15namespace idol::BranchingRules {
16 template<class>
17 class BranchingWithPriority;
18}
19
20template<class NodeInfoT>
22
23 using ListOfBranchingRules = std::list<std::unique_ptr<BranchingRule<NodeInfoT>>>;
24 using BranchingRuleIterator = typename ListOfBranchingRules::const_iterator;
25
26 ListOfBranchingRules m_branching_rules;
27public:
29 const std::list<std::unique_ptr<::idol::BranchingRuleFactory<NodeInfoT>>>& t_factories)
30 : BranchingRule<NodeInfoT>(t_parent)
31 {
32 for (auto& factory : t_factories) {
33 m_branching_rules.emplace_back(factory->operator()(t_parent));
34 }
35 }
36
37 void initialize() override {
38
40
41 for (auto& branching_rule : m_branching_rules) {
42 branching_rule->initialize();
43 }
44
45 }
46
47 bool is_valid(const Node<NodeInfoT> &t_node) override {
48
49 for (auto& branching_rule : m_branching_rules) {
50
51 if (!branching_rule->is_valid(t_node)) {
52 return false;
53 }
54
55 }
56
57 return true;
58 }
59
60 std::list<NodeInfoT*> create_child_nodes(const Node<NodeInfoT> &t_node) override {
61
62 for (auto& branching_rule : m_branching_rules) {
63
64 auto result = branching_rule->create_child_nodes(t_node);
65
66 if (!result.empty()) {
67 return result;
68 }
69
70 }
71
72 return {};
73 }
74
75};
76
77#endif //IDOL_IMPL_BRANCHINGWITHPRIORITY_H