-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
179 lines (162 loc) · 5 KB
/
main.cpp
File metadata and controls
179 lines (162 loc) · 5 KB
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <iomanip>
#include "brpstate.h"
#include "branchandbound.h"
#include "genpolicy.h"
using namespace std;
// UB procedure for exact methods
unique_ptr<BRPPolicy> ubSolver;
// UB procedure for heuristic methods
unique_ptr<BRPPolicy> hubSolver;
bool verbose;
// for SmSEQC-X procedures
string condensationProcedure = "tricoire";
extern clock_t ticksInLB1;
extern clock_t ticksInLB2;
extern clock_t ticksInLB3;
extern map<int, long long> countForGap;
extern long long timeInLB1, timeInLB2, timeInLB3;
int main(int argc, char **argv) {
string instanceFname = "instances/caserta/data3-3-1.dat";
int seed = 0;
string experiment = "branch-and-bound";
string bbStrategy = "depth";
string maxHeightType = "unlimited";//2H-1";
int H = 3;
int S = 3;
string method = "LA-1";
string ubMethod = "LA-1";
string hubMethod = "FM";
string scriptFile = "";
int LB = 1;
// string condensationProcedure = "none";
verbose = false;
bool debug = false;
int timeLimit = 0;
int i = 1;
while (i<argc){
string tmp = argv[i];
if (tmp == "-i") {
i++;
instanceFname = argv[i];
i++;
} else if (tmp == "-maxHeight") {
i++;
maxHeightType = argv[i];
i++;
} else if (tmp == "-m") {
i++;
method = argv[i];
i++;
} else if (tmp == "-sf") {
i++;
scriptFile = argv[i];
i++;
} else if (tmp == "-ub") {
i++;
ubMethod = argv[i];
i++;
} else if (tmp == "-hub") {
i++;
hubMethod = argv[i];
i++;
} else if (tmp == "-lb") {
i++;
LB = atoi(argv[i]);
i++;
} else if (tmp == "-tl") {
i++;
timeLimit = atoi(argv[i]);
i++;
} else if (tmp == "-cp") {
i++;
condensationProcedure = argv[i];
i++;
} else if (tmp == "-bbs") {
i++;
bbStrategy = argv[i];
i++;
} else if (tmp == "-v") {
i++;
verbose = true;
} else if (tmp == "-d") {
i++;
debug = true;
} else {
cerr << "unrecognized option: " << tmp << endl;
exit(5);
}
}
// dump parameter settings
cout << "-----------------------------------------------------------" << endl;
cout << "Parameter settings" << endl;
cout << "-----------------------------------------------------------" << endl;
cout << "Solution method:\t\t" << method << endl;
cout << "LB version:\t\t\t" << LB << endl;
cout << "BB strategy:\t\t\t" << bbStrategy << endl;
cout << "UB method:\t\t\t" << ubMethod << endl;
cout << "UB method for heuristics:\t" << hubMethod << endl;
cout << "condensation procedure:\t\t" << condensationProcedure << endl;
cout << "Instance file:\t\t\t" << instanceFname << endl;
cout << "max. height:\t\t\t" << maxHeightType << endl;
cout << "Time limit:\t\t\t" << timeLimit << endl;
cout << "script file:\t\t\t" << scriptFile << endl;
cout << "-----------------------------------------------------------" << endl;
const BRPState s(instanceFname, maxHeightType);
if ( verbose ) {
cout << s << endl;
}
if ( scriptFile != "" ) {
s.writeInstanceToFile(scriptFile);
}
// cout << "LB1 = " << s.LB1() << endl;
// cout << "LB2 = " << s.LB2() << endl;
// cout << "LB3 = " << s.LB3() << endl;
cout << "initialising random number generator: srandom(" << seed << ");\n";
srandom(seed);
//
BRPState::lbVersion = LB;
// method used for UB calculation
ubSolver = genPolicy(ubMethod, s, timeLimit, bbStrategy, true);
hubSolver = genPolicy(hubMethod, s, timeLimit, bbStrategy, true);
//
// main solver we use
auto solver = genPolicy(method, s, timeLimit, bbStrategy);
clock_t ticksBefore = clock();
shared_ptr<BRPState> result = solver->solve(s);
clock_t ticksAfter = clock();
cout << method << "\t used " << result->nRelocations() << " relocations in "
<< ( (double) (ticksAfter - ticksBefore) / CLOCKS_PER_SEC)
<< " s" << endl;
if ( scriptFile != "" ) {
result->appendSolutionToFile(scriptFile);
}
if ( verbose ) {
result->displaySolution();
}
if (LB == -1) {
cout << "Time spent in LB1: " << ((double)ticksInLB1) / CLOCKS_PER_SEC
<< endl;
cout << "Time spent in LB2: " << ((double)ticksInLB2) / CLOCKS_PER_SEC
<< endl;
cout << "Time spent in LB3: " << ((double)ticksInLB3) / CLOCKS_PER_SEC
<< endl;
cout << "/!\\ IMPORTANT NOTE: times are inaccurate"
<< " since a single call typically takes less than one tick"
<< endl;
long long nNodes = 0;
for (auto it=countForGap.begin(); it != countForGap.end(); it++) {
nNodes += it->second;
}
cout << nNodes << " nodes" << endl;
cout.setf(ios::fixed);
cout.precision(2);
for (auto it=countForGap.begin(); it != countForGap.end(); it++) {
cout << "gap = " << it->first << " :\t" << it->second << " nodes\t-\t"
<< 100.0 * it->second / nNodes << " %" << endl;
}
}
}