forked from SNUCSE-CTA/graph-analysis-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
168 lines (130 loc) · 4.13 KB
/
main.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
#include <stdio.h>
#include <getopt.h>
#include "snugal.h"
void usage(void);
int main(int argc, char* argv[])
{
if (argc < 2) {
usage();
return 1;
}
bool directed = false; // suppose given graph is undirected.
while (true) {
static struct option long_options[] = {
{"directed", 0, NULL, 'd'},
{"undirected", 0, NULL, 'u'},
{"help", 0, NULL, 'h'},
{0, 0, 0, 0}
};
int option = getopt_long(argc, argv, "duh", long_options, NULL);
if (option < 0) {
break;
}
switch (option) {
case 'd':
directed = true;
break;
case 'u':
directed = false;
break;
case 'h':
usage();
return 0;
default:
usage();
return 1;
}
}
// There exists no non-option argument.
// That is, input file path is not given.
if (argc <= optind) {
fprintf(stderr, "input file is not given.\n");
return 1;
}
// Suppose input file path is the first non-option argument.
std::string input_path(argv[optind]);
// Extract name of given graph from input path.
std::size_t slash = input_path.rfind("/");
if (slash == std::string::npos) {
slash = -1;
}
std::size_t dot = input_path.rfind(".");
if (dot == std::string::npos) {
dot = input_path.length();
}
std::string graph_name = input_path.substr(slash+1, dot-(slash+1));
if (directed) {
snu::DSGraph graph;
int parse_status = snu::parseDSGraph(input_path, graph);
switch (parse_status) {
case snu::PARSE_SUCCESS:
break;
case snu::PARSE_FAILURE_NO_INPUT:
fprintf(stderr, "input file is not locatable.\n");
return 1;
case snu::PARSE_FAILURE_INVALID_INPUT:
fprintf(stderr, "input data is invalid.\n");
return 1;
case snu::PARSE_FAILURE_INVALID_FILETYPE:
fprintf(stderr, "this filetype is not supported.\n");
return 1;
case snu::PARSE_FAILURE_ADD_VERTEX:
case snu::PARSE_FAILURE_ADD_EDGE:
fprintf(stderr, "internal error\n");
return 1;
default:
return 1;
}
snu::StatResult result;
snu::initStat(result);
snu::basicStat(graph, result);
snu::connectStat(graph, result);
snu::Plot plot(graph_name);
snu::makePlot(graph, plot);
snu::makeDSHtml(graph_name.c_str(), result, plot);
}
else {
snu::USGraph graph;
int parse_status = snu::parseUSGraph(input_path, graph);
switch (parse_status) {
case snu::PARSE_SUCCESS:
break;
case snu::PARSE_FAILURE_NO_INPUT:
fprintf(stderr, "input file is not locatable.\n");
return 1;
case snu::PARSE_FAILURE_INVALID_INPUT:
fprintf(stderr, "input data is invalid.\n");
return 1;
case snu::PARSE_FAILURE_INVALID_FILETYPE:
fprintf(stderr, "this filetype is not supported.\n");
return 1;
case snu::PARSE_FAILURE_ADD_VERTEX:
case snu::PARSE_FAILURE_ADD_EDGE:
fprintf(stderr, "internal error\n");
return 1;
default:
return 1;
}
snu::StatResult result;
snu::initStat(result);
snu::basicStat(graph, result);
snu::connectStat(graph, result);
snu::countStat(graph, result);
snu::Plot plot(graph_name);
snu::makePlot(graph, plot);
snu::makeUSHtml(graph_name.c_str(), result, plot);
}
return 0;
}
void usage(void)
{
printf(" usage: main <input file> [options]\n");
printf("\n");
printf(" options:\n");
printf(" -d | --directed set graph directed\n");
printf(" -u | --undirected set graph undirected (default)\n");
printf(" -h | --help print this list of help\n");
printf("\n");
printf(" e.g. ./main some_path/some_graph.snap --directed\n");
return;
}