-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
61 lines (52 loc) · 1.9 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
#include <iostream>
#include "Precinct.h"
#include "Graph.h"
#include "Partition.h"
#include <fstream>
#include <string>
using std::cout;
using std::endl;
void recombinationWithOutput(Partition& partition, std::string filename) {
// dry run to reach equilibrium convergence
for (int i = 0; i < 20000; ++i) {
partition.recombination();
if (i > 0 && i % 1000 == 0) {
cout << "dry run finished " << i << endl;
}
}
std::ofstream fout(filename);
for (int i = 0; i < 20000; ++i) {
partition.recombination();
fout << partition.getMeanMedian() << endl;
if (i > 0 && i % 1000 == 0) {
cout << "saved run finished " << i << endl;
}
}
}
int main(int argc, char *argv[]) {
srand(time(NULL));
if (argc != 3) {
std::cerr << "Please specify BOTH input filename and output prefix" << endl;
std::cerr << "./recombination <input filename> <output prefix>" << endl;
std::cerr << "eg ./recombination cdata.txt ./output/mean-median" << endl;
return 1;
}
Graph graph(argv[1]);
std::string outputPrefix = argv[2];
// MST
Partition mstPartition(&graph, 10, Partition::SpanningTreeAlgorithm::MST);
cout << "MST Recom" << endl;
std::string mstFilename = outputPrefix + "-mst.txt";
// std::string mstFilename = "./output/mean-median-mst-pa.txt";
recombinationWithOutput(mstPartition, mstFilename);
cout << "MST Recom output to" + mstFilename << endl;
cout << endl;
// Wilson
Partition wilsonPartition(&graph, 10, Partition::SpanningTreeAlgorithm::WILSON);
cout << "Wilson Recom" << endl;
std::string wilsonFilename = outputPrefix + "-wilson.txt";
// std::string wilsonFilename = "./output/mean-median-wilson-pa.txt";
recombinationWithOutput(wilsonPartition, wilsonFilename);
cout << "MST Recom output to" + wilsonFilename << endl;
cout << endl;
}