idol
A C++ Framework for Optimization
Loading...
Searching...
No Matches
BestEstimate.h
1//
2// Created by henri on 22/03/23.
3//
4
5#ifndef IDOL_BESTESTIMATE_IMPL_H
6#define IDOL_BESTESTIMATE_IMPL_H
7
8#include "NodeSelectionRule.h"
9#include "idol/mixed-integer/optimizers/branch-and-bound/nodes/NodeSet.h"
10#include "idol/general/utils/exceptions/Exception.h"
11#include <optional>
12
13namespace idol::NodeSelectionRules {
14 template<class NodeT> class BestEstimate;
15}
16
17template<class NodeT>
19 std::optional<double> m_root_node_obj;
20 std::optional<double> m_root_node_sum_of_infeasibilities;
21
22 double compute_score(const Node<NodeT>& t_node) {
23
24 const double node_obj = t_node.info().objective_value();
25 const double node_sum_of_infeasibilities = t_node.info().sum_of_infeasibilities();
26 const double incumbent_obj = this->parent().incumbent().info().objective_value();
27
28 return node_obj - ( m_root_node_obj.value() - incumbent_obj ) * node_sum_of_infeasibilities / m_root_node_sum_of_infeasibilities.value();
29 }
30public:
32
33 typename NodeSet<Node<NodeT>>::const_iterator operator()(const NodeSet<Node<NodeT>>& t_active_nodes) override {
34
35 if (t_active_nodes.size() == 1 && t_active_nodes.by_objective_value().begin()->id() == 0) {
36 const auto& root_node_it = t_active_nodes.by_objective_value().begin();
37 m_root_node_obj = (double) root_node_it->info().objective_value();
38 m_root_node_sum_of_infeasibilities = root_node_it->info().sum_of_infeasibilities();
39 return root_node_it;
40 }
41
42 if (!this->parent().has_incumbent()) {
43 return t_active_nodes.by_objective_value().begin();
44 }
45
46 double max = std::numeric_limits<double>::lowest();
47 typename NodeSet<Node<NodeT>>::const_iterator argmax;
48 for (auto it = t_active_nodes.by_objective_value().begin(),
49 end = t_active_nodes.by_objective_value().end() ; it != end ; ++it) {
50
51 const double score = compute_score(*it);
52
53 if (score > max) {
54 max = score;
55 argmax = it;
56 }
57
58 }
59
60 return argmax;
61 }
62};
63
64#endif //IDOL_BESTESTIMATE_IMPL_H