forked from jeffythedragonslayer/lipton-tarjan
-
Notifications
You must be signed in to change notification settings - Fork 1
/
graphgen.cpp
59 lines (49 loc) · 1.85 KB
/
graphgen.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
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/properties.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/property_map/property_map.hpp>
#include <boost/ref.hpp>
#include <boost/graph/boyer_myrvold_planar_test.hpp>
#include <boost/graph/is_kuratowski_subgraph.hpp>
#include <boost/graph/connected_components.hpp>
#include <vector>
#include <iostream>
using namespace std;
using namespace boost;
typedef adjacency_list<vecS, vecS, undirectedS> Graph;
typedef graph_traits<Graph>::vertex_descriptor VertDesc;
typedef graph_traits<Graph>::edge_iterator EdgeIter;
int main(int argc, char** argv)
{
if( argc < 3 ){
cerr << "Usage: planargen n e\n";
cerr << " n - number of vertices\n";
cerr << " e - number of edges (<= 3n-6)\n";
return 0;
}
int n = atoi(argv[1]);
int e = atof(argv[2]);
if( e > 3*n - 6 ){
cerr << "Planr graph must have <= 3*n - 6 edges!\n";
return 0;
}
Graph g(n);
uint v1, v2;
for( uint i = 0; i < e; ++i ){
if( i < n ) v1 = i; // force all verts to be used at least once
else v1 = rand() % n;
do { v2 = rand() % n; } while( v1 == v2 );
if( edge(v1, v2, g).second ) continue;
auto g_tmp = g;
add_edge(v1, v2, g_tmp);
if( boyer_myrvold_planarity_test(g_tmp) ){
g = g_tmp;
cout << v1 << ", " << v2 << '\n';
cerr << (i*100.0/e) << "%\n";
} else --i;
}
vector<int> component(num_vertices(g));
int num = connected_components(g, &component[0]);
vector<int>::size_type i;
cerr << "Total number of components: " << num << endl;
}