idol
A C++ Framework for Optimization
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
36 for (const auto &var : original_model.vars()) {
37
38 double reduced_cost = relaxation.get_var_reduced_cost(var);
39
40 if (current_obj + reduced_cost > best_obj + Tolerance::MIPAbsoluteGap) {
41 const double relaxation_lb = relaxation.get_var_lb(var);
42 const double current_ub = relaxation.get_var_ub(var);
43 //if (!equals(relaxation_lb, current_ub, Tolerance::Integer)) {
44 this->add_local_variable_branching(var, LessOrEqual, relaxation_lb);
45 //}
46 }
47
48 if (current_obj - reduced_cost > best_obj + Tolerance::MIPAbsoluteGap) {
49 const double relaxation_ub = relaxation.get_var_ub(var);
50 const double current_lb = relaxation.get_var_lb(var);
51 //if (!equals(relaxation_ub, current_lb, Tolerance::Integer)) {
52 this->add_local_variable_branching(var, GreaterOrEqual, relaxation_ub);
53 //}
54 }
55
56 }
57
58 }
59 };
60
61 BranchAndBoundCallback<NodeInfoT> *operator()() override {
62 return new Strategy();
63 }
64
65 BranchAndBoundCallbackFactory<NodeInfoT> *clone() const override {
66 return new ReducedCostFixing();
67 }
68};
69
70#endif //IDOL_REDUCEDCOSTFIXING_H
const Node< NodeInfoT > & node() const
void operator()(CallbackEvent t_event) override
static double MIPAbsoluteGap
Definition numericals.h:63