-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathemst_main.cc
48 lines (46 loc) · 1.22 KB
/
emst_main.cc
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
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <cassert>
#include "instance.h"
#include "emst.h"
void usage(int exit_code) {
std::cout << "Usage: emst_main.exe <file-name>" << std::endl;
std::exit(exit_code);
}
int main(int argc, char **argv) {
if(argc != 2) {
usage(1);
}
std::string file_name(argv[1]);
std::ifstream ifs(file_name);
if(!ifs.good()) {
std::cout << "Cannot open file " << file_name << std::endl;
usage(2);
}
instance ins = from_stream(ifs);
// Only 2d is admitted here
assert(ins.dim_sizes.size() == 2);
compute_emst_subnets(ins);
// Print a friendly format for drawing
int num_nets = ins.nets.size();
std::cout << num_nets << std::endl;
for(int net = 0; net < num_nets; ++net) {
int num_vertices = ins.nets[net].vertices.size();
std::cout << num_vertices << std::endl;
for(auto& vertex : ins.nets[net].vertices) {
bool first = true;
for(auto& component : vertex) {
if(!first) {
std::cout << " ";
}
first = false;
std::cout << component;
}
std::cout << std::endl;
}
for(auto& uv : ins.nets[net].subnets) {
std::cout << uv[0] << " " << uv[1] << std::endl;
}
}
}