-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathDaidalusBatch.cpp
243 lines (221 loc) · 6.87 KB
/
DaidalusBatch.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
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*
* Copyright (c) 2011-2015 United States Government as represented by
* the National Aeronautics and Space Administration. No copyright
* is claimed in the United States under Title 17, U.S.Code. All Other
* Rights Reserved.
*/
#include "Daidalus.h"
#include <iostream>
#include <fstream>
#include "DaidalusProcessor.h"
using namespace larcfm;
const int STANDARD = 0;
const int PVS = 1;
class DaidalusBatch : public DaidalusProcessor {
public:
bool verbose;
bool raw;
int format;
std::ostream* out;
DaidalusBatch() {
verbose = false;
raw = false;
format = STANDARD;
out = &std::cout;
}
static void printHelpMsg() {
std::cout << "Usage:" << std::endl;
std::cout << " DaidalusBatch [<options>] files\n" << std::endl;
std::cout << "Valid <options>:" << std::endl;
std::cout << " --help\n\tPrint this message" << std::endl;
std::cout << " --config <configuration-file> | no_sum | nom_a | nom_b | cd3d | tcasii\n\tLoad <configuration-file>" << std::endl;
std::cout << " --out <file>\n\tOutput information to <file>" << std::endl;
std::cout << " --verbose\n\tPrint extra information" << std::endl;
std::cout << " --raw\n\tPrint raw information" << std::endl;
std::cout << " --pvs\n\tProduce PVS output format" << std::endl;
std::cout << " --<key>=<val>\n\t<key> is any configuration variable and val is its value (including units, if any), e.g., --lookahead_time=\"5[min]\"" << std::endl;
std::cout << " --precision <n>\n\tOutput decimal precision" << std::endl;
std::cerr << " --instantaneous\n\tOverride configuration to do instantaneous bands" << std::endl;
std::cerr << " --nohystereis\n\tOverride configuation to disable hysteresis" << std::endl;
std::cout << getHelpString() << std::endl;
exit(0);
}
static std::string stringList2PVS(const std::string& msg, const std::vector<TrafficState>& l) {
std::string s="%%% ";
s += msg+": "+Fmi(l.size())+"\n(:";
bool first = true;
for (TrafficState::nat ac=0; ac < l.size(); ++ac) {
if (first) {
first = false;
s+=" ";
} else {
s+=", ";
}
s+="\""+l[ac].getId()+"\"";
}
s+=" :)";
if (l.empty()) {
s+="::list[string]";
}
return s;
}
void header(Daidalus& daa, const std::string& filename) {
switch (format) {
case STANDARD:
break;
case PVS:
break;
default:
break;
}
}
void printOutput(Daidalus& daa) {
switch (format) {
case STANDARD:
(*out) << daa.outputString();
if (raw) {
(*out) << daa.rawString();
}
break;
case PVS:
(*out) << daa.toPVS(false);
break;
}
}
void contours(Daidalus& daa, const std::string& filename) {
}
void processTime(Daidalus& daa, const std::string& filename) {
header(daa,filename);
printOutput(daa);
}
};
int main(int argc, const char* argv[]) {
DaidalusBatch walker;
int a;
std::string config = "";
std::string output = "";
std::string options = "";
ParameterData params;
int precision = 6;
bool do_inst = false;
bool no_hyst = false;
for (a=1;a < argc && argv[a][0]=='-'; ++a) {
std::string arga = argv[a];
options += arga + " ";
if (walker.processOptions(argv,argc,a)) {
++a;
options += walker.getOptionsString();
} if (arga == "--help" || arga == "-help" || arga == "-h") {
DaidalusBatch::printHelpMsg();
} else if (startsWith(arga,"--conf") || startsWith(arga,"-conf") || arga == "-c") {
config = argv[++a];
arga = argv[a];
options += arga + " ";
} else if (startsWith(arga,"--out") || startsWith(arga,"-out") || arga == "-o") {
output = argv[++a];
} else if (arga == "--verbose" || arga == "-verbose" || arga == "-v") {
walker.verbose = true;
} else if (arga == "--raw" || arga == "-raw" || arga == "-r") {
walker.raw = true;
} else if (arga == "--pvs" || arga == "-pvs") {
walker.format = PVS;
} else if (startsWith(arga,"--prec") || startsWith(arga,"-prec")) {
++a;
std::istringstream(argv[a]) >> precision;
options += arga+" ";
} else if (startsWith(arga,"--inst") || startsWith(arga,"-inst")) {
// Use the given configuration, but do instantaneous bands
do_inst = true;
} else if (startsWith(arga,"--nohys") || startsWith(arga,"-nohys")) {
// Use the given configuration, but disable hysteresis
no_hyst = true;
} else if (startsWith(arga,"-") && arga.find('=') != std::string::npos) {
std::string keyval = arga.substr(arga.find_last_of('-')+1);
params.set(keyval);
} else if (argv[a][0] == '-') {
std::cout << "Invalid option: " << arga << std::endl;
exit(0);
}
}
std::vector<std::string> txtFiles = std::vector<std::string>();
for (;a < argc; ++a) {
std::string arga(argv[a]);
txtFiles.push_back(arga);
}
if (txtFiles.empty()) {
walker.printHelpMsg();
}
std::ofstream fout;
if (output != "") {
fout.open(output.c_str());
walker.out = &fout;
}
DaidalusParameters::setDefaultOutputPrecision(precision);
Daidalus daa;
if (config == "") {
// Configure alerters as in DO_365B Phase I, Phase II, and Non-Cooperative, with SUM
daa.set_DO_365B();
} else if (!daa.loadFromFile(config)) {
if (config == "no_sum") {
// Configure DAIDALUS as in DO-365B, without SUM
daa.set_DO_365B(true,false);
} else if (config == "nom_a") {
// Configure DAIDALUS to Nominal A: Buffered DWC, Kinematic Bands, Turn Rate 1.5 [deg/s]
daa.set_Buffered_WC_DO_365(false);
} else if (config == "nom_b") {
// Configure DAIDALUS to Nominal B: Buffered DWS, Kinematic Bands, Turn Rate 3.0 [deg/s]
daa.set_Buffered_WC_DO_365(true);
} else if (config == "cd3d") {
// Configure DAIDALUS to CD3D parameters: Cylinder (5nmi,1000ft), Instantaneous Bands, Only Corrective Volume
daa.set_CD3D();
} else if (config == "tcasii") {
// Configure DAIDALUS to ideal TCASII logic: TA is Preventive Volume and RA is Corrective One
daa.set_TCASII();
} else {
std::cerr << "** Error: File " << config << " not found" << std::endl;
exit(1);
}
}
if (params.size() > 0) {
daa.setParameterData(params);
}
if (do_inst) {
daa.setInstantaneousBands();
}
if (no_hyst) {
daa.disableHysteresis();
}
switch (walker.format) {
case STANDARD:
if (walker.verbose) {
(*walker.out) << "# " << Daidalus::release() << std::endl;
(*walker.out) << "# Options: " << options << std::endl;
(*walker.out) << "#\n" << daa.toString() << "#\n" << std::endl;
}
break;
case PVS:
(*walker.out) << "%%% " << Daidalus::release() << std::endl;
(*walker.out) << "%%% Options: " << options << std::endl;
break;
default:
break;
}
for (unsigned int i=0; i < txtFiles.size(); ++i) {
std::string filename(txtFiles[i]);
switch (walker.format) {
case STANDARD:
(*walker.out) << "# File: "<< filename << std::endl;
break;
case PVS:
(*walker.out) << "%%% File:\n" << filename << std::endl;
(*walker.out) << "%%% Parameters:\n" << daa.getCore().parameters.toPVS() << std::endl;
break;
default:
break;
}
walker.processFile(filename,daa);
}
if (output != "") {
fout.close();
}
}//main