-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain-routing.cpp
108 lines (96 loc) · 2.89 KB
/
main-routing.cpp
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
#include <iostream>
#include <iomanip>
#include <getopt.h>
#include "Routing/Algorithms/Probability/Helpers/Utility.h"
#include "Routing/Pipeline/PipelineConfig.h"
#include "Routing/Pipeline/RoutingPipeline.h"
#include "Routing/Data/Utility/FilesystemUtil.h"
#include "Routing/Algorithms/OneToMany/DistanceMatrix.h"
using namespace std;
using namespace Routing;
using namespace Routing::Pipeline;
using namespace Routing::DistanceMatrix;
void usage() {
cout << "Usage: routing-cli -c [config_file] -i [input_file] -o [output_file] [-x]" << endl;
}
int main(int argc, char **argv) {
/**
* Parse command line arguments
*/
int ch;
string configFile, inputFile, outputFile;
bool distMatrix = false;
while ((ch = getopt(argc, argv, "c:i:o:x")) != -1) {
switch (ch) {
case 'c':
configFile = optarg;
break;
case 'i':
inputFile = optarg;
break;
case 'o':
outputFile = optarg;
break;
case 'x':
distMatrix = true;
break;
case ':':
cerr << "Missing argument." << endl;
exit(EXIT_FAILURE);
case '?':
default:
cerr << "Invalid command line parameters." << endl;
usage();
exit(EXIT_FAILURE);
}
}
argc -= optind;
argv += optind;
try {
/**
* Load configuration
*/
PipelineConfig pipelineConfig(configFile);
cout << pipelineConfig << endl;
/**
* Distance matrix mode
*/
if (distMatrix) {
if (!Utils::CheckFileExists(inputFile)) {
cerr << "ERROR: Input file: " << inputFile << " does not exist." << endl;
return EXIT_FAILURE;
}
DistanceMatrix::ComputeDistanceMatrix(inputFile, outputFile, pipelineConfig);
return EXIT_SUCCESS;
}
/**
* Pipeline mode - Load input file
*/
vector<RoutingRequest> requests = RoutingRequest::LoadRequests(
inputFile,
false);
/**
* Run pipeline
*/
RoutingPipeline pipeline(pipelineConfig);
for (auto &req : requests) {
try {
pipeline.ProcessRequest(req);
}
catch (const Exception::PipelineException &pe) {
cerr << pe.what() << pe.msg << endl;
continue;
}
catch (const Exception::NodeNotFoundException &ne) {
cerr << ne.what() << ne.nodeId << endl;
continue;
}
cout << req << endl;
}
}
catch (const Exception::PipelineException &pe) {
cerr << pe.what() << endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}