Loading...
Searching...
No Matches
ReducedCostFixing.h
1//
2// Created by henri on 24.11.24.
3//
4
5#ifndef IDOL_REDUCEDCOSTFIXING_H
6#define IDOL_REDUCEDCOSTFIXING_H
7
8#include "idol/mixed-integer/optimizers/branch-and-bound/callbacks/BranchAndBoundCallback.h"
9
10namespace idol {
11 template<class> class ReducedCostFixing;
12}
13
14template<class NodeInfoT = idol::DefaultNodeInfo>
16public:
17 class Strategy : public BranchAndBoundCallback<NodeInfoT> {
18 unsigned int m_last_node_id = -1;
19 protected:
20 void operator()(CallbackEvent t_event) override {
21
22 if (t_event != InvalidSolution) {
23 return;
24 }
25
26 if (m_last_node_id == this->node().id()) {
27 return;
28 }
29 m_last_node_id = this->node().id();
30
31 const auto& original_model = this->original_model();
32 const auto& relaxation = this->relaxation();
33 const double best_obj = this->best_obj();
34 const double current_obj = this->relaxation().get_best_obj();
35 const double tol_mip_absolute_gap = original_model.optimizer().get_tol_mip_absolute_gap();
36
37 for (const auto &var : original_model.vars()) {
38
39 double reduced_cost = relaxation.get_var_reduced_cost(var);
40
41 if (current_obj + reduced_cost > best_obj + tol_mip_absolute_gap) {
42 const double relaxation_lb = relaxation.get_var_lb(var);
43 const double current_ub = relaxation.get_var_ub(var);
44 //if (!equals(relaxation_lb, current_ub, Tolerance::Integer)) {
45 this->add_local_variable_branching(var, LessOrEqual, relaxation_lb);
46 //}
47 }
48
49 if (current_obj - reduced_cost > best_obj + tol_mip_absolute_gap) {
50 const double relaxation_ub = relaxation.get_var_ub(var);
51 const double current_lb = relaxation.get_var_lb(var);
52 //if (!equals(relaxation_ub, current_lb, Tolerance::Integer)) {
53 this->add_local_variable_branching(var, GreaterOrEqual, relaxation_ub);
54 //}
55 }
56
57 }
58
59 }
60 };
61
62 BranchAndBoundCallback<NodeInfoT> *operator()() override {
63 return new Strategy();
64 }
65
66 BranchAndBoundCallbackFactory<NodeInfoT> *clone() const override {
67 return new ReducedCostFixing();
68 }
69};
70
71#endif //IDOL_REDUCEDCOSTFIXING_H
const Node< NodeInfoT > & node() const
void operator()(CallbackEvent t_event) override