-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgraph_partitioning.cpp
More file actions
130 lines (115 loc) · 3.21 KB
/
Copy pathgraph_partitioning.cpp
File metadata and controls
130 lines (115 loc) · 3.21 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include"graph.h"
#include"loaders.h"
#include"partition.h"
#include"partitioners.h"
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#define MAX_PARTITIONS 10000
void run_heuristic(const char* heuristic_name,
int partitions_number,
const char* dataset,
const Graph& graph)
{
Partition partition;
time_t start = time(0);
if (strncmp(heuristic_name,"LDG",3) == 0)
{
linear_deterministic_greedy(graph,
partitions_number,
&partition);
}
else if (strncmp(heuristic_name,"FENNEL",6) == 0)
{
fennel(graph,
partitions_number,
&partition);
}
else if (strncmp(heuristic_name,"NNEIGHBORS",10) == 0)
{
non_neighbors_greedy(graph,
partitions_number,
&partition);
}
else
{
printf("Invalid heuristic name %s\n",heuristic_name);
exit(1);
}
time_t end = time(0);
int time = difftime(end, start);
printf("Partitioned in %d seconds\n",time);
double fraction_edges_cut = graph.get_fraction_edges_cut(partition);
double communication_volume = graph.get_communication_volume(partition);
double maximum_load = graph.get_normalized_maximum_load(partition);
printf("Dataset %s with heuristic %s and %d partitions:\n",
dataset,
heuristic_name,
partitions_number);
printf("Fraction edges cut = %f\nNormalized maximum load = %f\n",
fraction_edges_cut,
maximum_load);
printf("Communication volume %f\n\n",
communication_volume);
}
int main(int argc, char** argv)
{
Graph graph;
if (argc != 4)
{
printf("Invalid number of parameters\n");
printf("Usage: %s <dataset name> <heuristic names> <partitions number>\n",
argv[0]);
exit(1);
}
if (strncmp(argv[1],"slashdot",8) == 0)
snap_loader(&graph, SLASHDOT_FILE);
else if (strncmp(argv[1],"amazon",6) == 0) {
snap_loader(&graph, AMAZON_FILE);
}
else if (strncmp(argv[1],"livejournal",11) == 0)
snap_loader(&graph, LIVEJOURNAL_FILE);
else if (strncmp(argv[1],"facebook",8) == 0)
snap_loader(&graph, FACEBOOK_FILE);
else if (strncmp(argv[1],"4elt",4) == 0)
elt_loader(&graph);
else if (strncmp(argv[1],"twitter",7) == 0)
twitter_loader(&graph);
else if (strncmp(argv[1],"pre.amazon",11) == 0) {
preprocessed_loader(&graph, AMAZON_FILE);
}
else
{
printf("Invalid dataset name %s\n",argv[1]);
exit(1);
}
int partitions_number = strtol(argv[3], NULL, 10);
if (partitions_number < 1 || partitions_number > MAX_PARTITIONS)
{
printf("Invalid partition number %s\n",argv[3]);
exit(1);
}
bool heuristics_valid = false;
if (strstr(argv[2],"LDG") != NULL)
{
run_heuristic("LDG",partitions_number,argv[1],graph);
heuristics_valid = true;
}
if (strstr(argv[2],"FENNEL") != NULL)
{
run_heuristic("FENNEL",partitions_number,argv[1],graph);
heuristics_valid = true;
}
if (strstr(argv[2],"NNEIGHBORS") != NULL)
{
run_heuristic("NNEIGHBORS",partitions_number,argv[1],graph);
heuristics_valid = true;
}
if (!heuristics_valid)
{
printf("Invalid heuristic name %s\n",argv[2]);
exit(1);
}
return 0;
}