-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
74 lines (62 loc) · 2.39 KB
/
main.cpp
File metadata and controls
74 lines (62 loc) · 2.39 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
#include <iostream>
#include "graph.hpp"
#include "graph_io.hpp"
#include "quickbb.hpp"
constexpr char PROGRAM_NAME[] = "quickbb";
void print_help() {
std::cout << PROGRAM_NAME << "[options] < file" << std::endl <<
"Reads a Graph G in .gr format and writes a tree-decomposition of G to stdout" << std::endl <<
"Options:" << std::endl <<
"-h | --help Print this help" << std::endl <<
"-t | --time <time> Sets maximum timeout in seconds. Defaults to 360." << std::endl <<
"-o | --output <file> Specifies output file. If none given, outputs to stdout" << std::endl <<
"-i | --input <file> Specifies input file. If none given, reads from stdin" << std::endl;
}
int main(int argc, char *argv[]) {
std::vector<std::string> args;
size_t alloted_time = 360;
for (auto i = 1; i < argc; i++) {
args.emplace_back(argv[i]);
}
auto help_pred = [](const std::string &a) {
return a == "-h" || a == "--help";
};
auto help = std::find_if(args.begin(), args.end(), help_pred) != args.end();
if (help) {
print_help();
return 0;
}
auto time_pred = [](const std::string &a) {
return a == "-t" || a == "--time";
};
auto time = std::find_if(args.begin(), args.end(), time_pred);
if (time != args.end() && ++time != args.end()) {
alloted_time = std::stoi(*time);
}
auto output_pred = [](const std::string &a) {
return a == "-o" || a == "--output";
};
auto output_file = std::find_if(args.begin(), args.end(), output_pred);
auto has_output_file = false;
std::ofstream output_file_stream;
if (output_file != args.end() && ++output_file != args.end()) {
output_file_stream.open(*output_file);
has_output_file = true;
}
auto input_pred = [](const std::string &a) {
return a == "-i" || a == "--input";
};
auto input_file = std::find_if(args.begin(), args.end(), input_pred);
auto has_input_file = false;
std::ifstream input_file_stream;
if (input_file != args.end() && ++input_file != args.end()) {
input_file_stream.open(*input_file);
has_input_file = true;
}
Graph graph;
graph = read_pace(has_input_file ? input_file_stream : std::cin);
auto[tw, elimination_order] = quickbb(graph, alloted_time);
auto t = td_from_order(graph, elimination_order);
write_pace(t, tw, graph.order(), has_output_file ? output_file_stream : std::cout);
return 0;
}