-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
67 lines (56 loc) · 1.93 KB
/
main.c
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
#include "graph.h"
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
vertex_t* hda_attack(graph_t*, vertex_t* []);
vertex_t* simple_assign(graph_t*, vertex_t*, vertex_t* []);
vertex_t* sort_assign(graph_t*, vertex_t*, vertex_t* []);
vertex_t* simple_recover(vertex_t*, vertex_t*);
vertex_t* tdr_recover(vertex_t*, vertex_t*);
double robust(vertex_t*, size_t n);
void dump(graph_t*, vertex_t*, vertex_t*, int);
vertex_t* (*attack) (graph_t*, vertex_t* []) = hda_attack;
vertex_t* (*assign) (graph_t*, vertex_t*, vertex_t* []) = simple_assign;
vertex_t* (*recover) (vertex_t*, vertex_t*) = simple_recover;
const char* filename = NULL;
int ps = 0;
static
int usage(const char* name) {
printf("usage: %s [-o|-O] [-p] <filename>\n", name);
puts( "\t-o : use simple optimization\n"
"\t-O : use tree depth reduction optimization\n"
"\t-p : print q ~ s(q) plot"
"\t-s : print attack sequence"
);
return -1;
}
static
int parse_args(int argc, char* argv[]) {
int i;
for (i=1; i!=argc; ++i) {
if (argv[i][0]=='-') {
switch (argv[i][1]) {
case 'O': recover = tdr_recover;
case 'o': assign = sort_assign; break;
case 'p': ps |= 1; break;
case 's': ps |= 2; break;
default: return 1;
}
} else if (filename == NULL) {
filename = argv[i];
} else return 1;
}
return 0;
}
int main(int argc, char* argv[]) {
if (parse_args(argc, argv)) return usage(argv[0]);
graph_t* graph = graph_read_csv(filename);
size_t n = graph->vertex_count;
vertex_t** buffer = (vertex_t**) calloc(n, sizeof(vertex_t*));
vertex_t* sequence = attack(graph, buffer);
sequence = assign(graph, recover(sequence, buffer[0]), buffer);
if (ps) dump(graph, sequence, buffer[0], ps);
else printf("%lf\n", robust(sequence, n));
free(buffer);
return 0;
}