-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNodeExplorer.h
127 lines (92 loc) · 3.82 KB
/
NodeExplorer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//
// Created by nandgate on 10/27/2024.
//
#ifndef NODEEXPLORER_H
#define NODEEXPLORER_H
#include <utility>
#include "DD.h"
#include "Cut.h"
#include "gurobi_c++.h"
#include "grb.h"
// #include "DDSolver.h"
// extern const Network network;
//
class OutObject{
public:
double lb;
double ub;
vector<Node_t> nodes;
bool success;
OutObject(double lb_, double ub_, vector<Node_t> nodes_, bool s) :
lb{lb_}, ub{ub_}, nodes{std::move(nodes_)}, success{s}{}
};
class NodeExplorer {
//shared_ptr<Network> networkPtr;
//CutContainer feasibilityCuts;
//CutContainer optimalityCuts;
GRBEnv env = GRBEnv();
const shared_ptr<Network> networkPtr;
public:
CutContainer feasibilityCuts;
CutContainer optimalityCuts;
explicit NodeExplorer(const shared_ptr<Network>& networkPtr_) : networkPtr{networkPtr_}, feasibilityCuts{FEASIBILITY}, optimalityCuts{OPTIMALITY} {
// env = GRBEnv();
env.set(GRB_IntParam_OutputFlag,0);
env.set(GRB_IntParam_Threads,1);
}
NodeExplorer(const shared_ptr<Network>& networkPtr_, pair<CutContainer, CutContainer> cuts): networkPtr{networkPtr_}, feasibilityCuts{cuts.first}, optimalityCuts{cuts.second} {
env.set(GRB_IntParam_OutputFlag,0);
env.set(GRB_IntParam_Threads,1);
}
pair<CutContainer, CutContainer> getCuts() noexcept { return {feasibilityCuts, optimalityCuts};}
OutObject process(Node_t node, double optimalLB);
OutObject process2(Node_t node, double optimalLB);
OutObject process3(Node_t node, double optimalLB);
OutObject process4(Node_t node, double optimalLB, const pair<vector<CutContainer *>, vector<CutContainer *>>& globalCuts);
void clearCuts();
#ifdef SOLVER_STATS
void displayCutStats() const noexcept {
cout << "Number of feasibility cuts in the container " << feasibilityCuts.cuts.size() << endl;
cout << "Number of optimality cuts in the container: " << optimalityCuts.cuts.size() << endl;
}
#endif
};
namespace Inavap {
/* Return Object from the Node Explorer to the DDSolver. */
using OutObject = struct OutObj{
double lb = std::numeric_limits<double>::lowest();
/* reason: new (empty) nodes should not be processed (or sent to queue) if not initialized. */
double ub = std::numeric_limits<double>::lowest();
vector<Node> nodes;
uint16_t status; // status bits after processing the node.
/* this will hold the status of the node explorer operation on the given node.
* 0X0 - fail
* 0X1 - success
* 0X2 - Success (with empty nodes returned).
*/
// OutObj() = default;
OutObj(const double lb_, const double ub_, vector<Node> nodes_, const uint16_t status_) :
lb{lb_}, ub{ub_}, nodes{std::move(nodes_)}, status{status_}{}
//
};
static auto INVALID_OBJECT = OutObject{std::numeric_limits<double>::lowest(),
std::numeric_limits<double>::lowest(),
{}, false};
class NodeExplorer {
GRBEnv env = GRBEnv();
const shared_ptr<Network> networkPtr;
public:
CutContainer feasibilityCuts; // local feasibility cuts.
CutContainer optimalityCuts; // local optimality cuts.
// vector<CutContainer *> globalFCuts;
// vector<CutContainer *> globalOCuts;
explicit NodeExplorer(const shared_ptr<Network>& networkPtr_): networkPtr{networkPtr_} {
env.set(GRB_IntParam_OutputFlag,0);
env.set(GRB_IntParam_Threads,1);
}
OutObject process(Node node, double optimalLB,
const vector<CutContainer *> &globalFCuts, const vector<CutContainer *> &globalOCuts);
OutObject process2(Node node, double optimalLB);
};
}
#endif //NODEEXPLORER_H