-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_test.c
94 lines (82 loc) · 1.97 KB
/
run_test.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
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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <ctype.h>
#include "digraph.h"
#include "packed_graph.h"
#include "small_world.h"
#include "dijkstra.h"
#include "stats.h"
#include "bfs.h"
#include "graph.h"
void print_useage(char* prog_name)
{
printf("Useage:\n");
printf("%s [-n nodes] [-k distance] [-b rand] [-p] [-g file]\n", prog_name);
printf("\n");
printf("-n: The number of nodes in the graph.\n");
printf("-k: The distance of the furthest neighbour.\n");
printf("-b: The small-world randomisation "
"(shuold be a float in the interval (0, 1).\n");
printf("-p: Whether to use parallelisation for graph processing.\n");
printf("-g: File to save the graph to in graphviz format.\n");
}
int main(int argc, char *argv[])
{
digraph_t digraph;
size_t n = 20; // Number of nodes
size_t k = 2; // Distance of furthest neighbour
double b = 0.5; // Small-world Randomisation
int parallelise = 0;
char *graph_file = NULL;
int opt;
while((opt = getopt(argc, argv, "n:k:b:pg:")) != -1)
{
switch(opt)
{
case 'n':
n = atoi(optarg);
break;
case 'k':
k = atoi(optarg);
break;
case 'b':
b = atoi(optarg);
break;
case 'p':
parallelise = 1;
break;
case 'g':
graph_file = optarg;
break;
default:
print_useage(argv[0]);
exit(-1);
}
}
digraph_init(&digraph, n, k);
small_world_init(&digraph, k, b);
if (graph_file != NULL)
{
FILE *f = fopen(graph_file, "w");
if (f == NULL)
{
fprintf(stderr, "Could not open graph file.\n");
digraph_free(&digraph);
return 1;
}
graph_t graph;
graph_init( &graph, ( &digraph )->num_nodes );
small_world_to_graph( &digraph, &graph );
graph_fprint(f, &graph);
graph_destory(&graph); // Srysly guise...
fclose(f);
}
packed_graph *graph = digraph_to_packed(&digraph);
stats s = find_stats_for_graph(graph, parallelise);
stats_fprintf(&s, graph, stdout);
packed_free(graph);
digraph_free(&digraph);
return 0;
}