-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_valid_info.cpp
74 lines (60 loc) · 1.66 KB
/
gen_valid_info.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
#include "defs.h"
char inFilename[FILENAME_LEN];
char outFilename[FILENAME_LEN];
using namespace std;
/* helper */
void usage(int argc, char **argv)
{
printf("%s\n", argv[0]);
printf("Usage:\n");
printf("%s -in <graph filename>\n", argv[0]);
printf("Options:\n");
printf(" -in <graph filename>\n");
printf(" -out <output filename for the answer>\n");
exit(1);
}
/* initialization */
void init(int argc, char **argv)
{
int l;
bool no_inFilename = true;
bool no_outFilename = true;
inFilename[0] = outFilename[0] = '\0';
for (int i = 1; i < argc; i++) {
if (!strcmp(argv[i], "-in")) {
l = strlen(argv[++i]);
strncpy(inFilename, argv[i], (l > FILENAME_LEN - 1 ? FILENAME_LEN - 1 : l));
no_inFilename = false;
}
if (!strcmp(argv[i], "-out")) {
l = strlen(argv[++i]);
strncpy(outFilename, argv[i], (l > FILENAME_LEN - 1 ? FILENAME_LEN - 1 : l));
no_outFilename = false;
}
}
if (no_inFilename) {
usage(argc, argv);
}
if (no_outFilename) {
sprintf(outFilename, "%s.ans", inFilename);
}
}
int main(int argc, char **argv)
{
graph_t g;
init(argc, argv);
/* read graph from the file */
readGraph(&g, inFilename);
double *answer = new double[g.n];
assert(answer != NULL);
/* get the right answer */
run(&g, answer);
FILE *f = fopen(outFilename, "wb");
assert(f != NULL);
/* write the answer */
assert(fwrite(answer, sizeof(double), g.n, f) == g.n);
fclose(f);
delete[] answer;
freeGraph(&g);
return 0;
}