-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.h
156 lines (137 loc) · 3.25 KB
/
common.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#pragma once
#ifdef _MSC_VER
#pragma warning( disable : 4267 ) // implicit conversion, possible loss of data
#endif
#if defined(WIN32) || defined(_WIN32)
#define PATH_SEPARATOR "\\"
#else
#define PATH_SEPARATOR "/"
#endif
#define XPRESS
#include <tuple>
#include <sstream>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
#include <limits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <memory>
#include <algorithm>
#include <thread>
#include "Timer.h"
struct Predicate;
typedef std::map<std::string, double> Point;
typedef std::shared_ptr<Point> PointPtr;
double const EPSILON_PREDICATE = 1e-8;
typedef std::set<std::string> problem_names;
typedef std::map<std::string, int> Str2Int;
typedef std::map<int, std::string> Int2Str;
typedef std::map<std::string, double> Str2Dbl;
typedef std::vector<int> IntVector;
typedef std::vector<char> CharVector;
typedef std::vector<double> DblVector;
typedef std::vector<std::string> StrVector;
typedef std::map < std::string, Str2Int> CouplingMap;
typedef std::map <std::string, IntVector> SlaveCutId;
typedef std::tuple <int, std::string, int, bool> ActiveCut;
typedef std::vector<ActiveCut> ActiveCutStorage;
typedef std::pair<std::string, std::string> mps_coupling;
typedef std::list<mps_coupling> mps_coupling_list;
struct Predicate {
bool operator()(PointPtr const & lhs, PointPtr const & rhs)const {
return *lhs < *rhs;
}
bool operator()(Point const & lhs, Point const & rhs)const {
Point::const_iterator it1(lhs.begin());
Point::const_iterator it2(rhs.begin());
Point::const_iterator end1(lhs.end());
Point::const_iterator end2(rhs.end());
while (it1 != end1 && it2 != end2) {
if (it1->first != it2->first) {
return it1->first < it2->first;
}
else {
if (std::fabs(it1->second - it2->second) < EPSILON_PREDICATE) {
it1++;
it2++;
}
else {
return it1->second < it2->second;
}
}
}
if (it1 == end1 && it2 == end2) {
return false;
}
else {
return (it1 == end1);
}
}
};
// Definition of optimality codes
enum SOLVER_STATUS {
OPTIMAL,
INFEASIBLE,
UNBOUNDED,
};
/*!
* \brief Stream output overloading for point
*
* \param stream : stream output
*
* \param rhs : point
*/
inline std::ostream & operator<<(std::ostream & stream, Point const & rhs) {
for (auto const & kvp : rhs) {
if (kvp.second > 0) {
if (kvp.second == 1) {
stream << "+";
stream << kvp.first;
}
else {
stream << "+";
stream << kvp.second;
stream << kvp.first;
}
}
else if (kvp.second < 0) {
stream << kvp.second;
stream << kvp.first;
}
}
return stream;
}
/*!
* \struct BendersData
* \brief Structure used to manage every benders data
*/
struct BendersData {
int nbasis;
double timer_slaves;
double timer_master;
double lb;
double ub;
double best_ub;
int maxsimplexiter;
int minsimplexiter;
int deletedcut;
int it;
bool stop;
double alpha;
std::vector<double> alpha_i;
double slave_cost;
double invest_cost;
Point bestx;
Point x0;
int nslaves;
double dnslaves;
int master_status;
int nrandom;
};
double norm_point(Point const & x0, Point const & x1);
int norm_int(IntVector const & x0, IntVector const & x1);
std::ostream & operator<<(std::ostream & stream, std::vector<IntVector> const & rhs);