-
Notifications
You must be signed in to change notification settings - Fork 283
Expand file tree
/
Copy pathmain.cc
More file actions
114 lines (77 loc) · 2.45 KB
/
main.cc
File metadata and controls
114 lines (77 loc) · 2.45 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
#include <filesystem>
#include <vector>
#include <iostream>
#include <fstream>
#include <stdint.h>
#include <unistd.h>
#include <MP4.h>
#include "tree.h"
#include "aux.h"
void print_help(char *argv[]) {
std::cout << "Usage: " << argv[0] << " <option(s)> -o output_dir" << std::endl;
std::cout << "\n";
std::cout << "Options:" << std::endl;
std::cout << "\t -n num_nodes: number of nodes in the tree. Default: 8" << std::endl;
std::cout << "\t -c corpus_size: number of testcases to generate. Default: 10" << std::endl;
std::cout << std::endl;
std::cout << "\t -o output_dir: output directory" << std::endl;
}
int main(int argc, char *argv[]) {
if(argc < 2){
print_help(argv);
exit(EXIT_FAILURE);
}
std::string output_dir = "";
uint32_t num_children = 0;
uint32_t max_depth = 0;
uint32_t num_nodes = 8;
uint32_t corpus_size = 10;
int ch;
while ((ch = getopt(argc, argv, "n:c:o:")) != -1) {
switch (ch) {
case 'n': {
num_nodes = std::stoi(optarg);
break;
}
case 'c': {
corpus_size = std::stoi(optarg);
break;
}
case 'o': {
output_dir = optarg;
break;
}
default:
print_help(argv);
exit(EXIT_FAILURE);
}
}
if(output_dir == ""){
std::cerr << "Output directory not specified" << std::endl;
exit(EXIT_FAILURE);
}
std::filesystem::path dir = output_dir;
if(!std::filesystem::exists(dir)){
std::cerr << "Output directory does not exist" << std::endl;
exit(EXIT_FAILURE);
}
if(num_nodes < 1 || num_nodes > 20){
std::cerr << "Number of nodes must be between 1 and 20" << std::endl;
exit(EXIT_FAILURE);
}
std::cout << "Generating " << corpus_size << " testcases with " << num_nodes << " nodes" << std::endl;
for(int i=0; i < corpus_size; i++){
RandomTree tree(num_nodes);
MP4_labeler labeler(&tree);
#ifdef DEBUG
std::string dot = tree.dot_format();
std::cout << dot << std::endl;
#endif
std::string file_content = labeler.serialize();
std::string output_file = output_dir + "/out_" + std::to_string(i);
if(!write_to_file(file_content, output_file)){
std::cerr << "Error writing to file" << std::endl;
exit(EXIT_FAILURE);
}
}
}