Skip to content

Instantly share code, notes, and snippets.

@Hermann-SW
Last active April 5, 2022 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hermann-SW/1131d33bd4db45188eefff179635a30e to your computer and use it in GitHub Desktop.
Save Hermann-SW/1131d33bd4db45188eefff179635a30e to your computer and use it in GitHub Desktop.
Replaced hardcoded example graph by code to read fulgen.c output; here C60
//=======================================================================
// Copyright 2007 Aaron Windsor
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//=======================================================================
// Replaced hardcoded example graph by code to read fulgen.c output; here C60 fulleren:
// $ ~/plantri52/fullgen 60 ipr code 6 stdout 2>/dev/null | ./planar_face_traversal
//=======================================================================
#include <iostream>
#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 <vector>
#include <boost/graph/planar_face_traversal.hpp>
#include <boost/graph/boyer_myrvold_planar_test.hpp>
using namespace boost;
// Some planar face traversal visitors that will
// print the vertices and edges on the faces
struct output_visitor : public planar_face_traversal_visitor
{
void begin_face() { std::cout << "New face: "; }
void end_face() { std::cout << std::endl; }
};
struct vertex_output_visitor : public output_visitor
{
template < typename Vertex > void next_vertex(Vertex v)
{
std::cout << v << " ";
}
};
struct edge_output_visitor : public output_visitor
{
template < typename Edge > void next_edge(Edge e) { std::cout << e << " "; }
};
int main(int argc, char** argv)
{
typedef adjacency_list< vecS, vecS, undirectedS,
property< vertex_index_t, int >, property< edge_index_t, int > >
graph;
graph g;
std::string line;
getline(std::cin, line);
while(getline(std::cin, line)){
int v, dummy, w;
std::stringstream s_stream(line);
s_stream >> v >> dummy >> dummy >> dummy;
if (v==0)
break;
while (s_stream >> w){
if (v < w)
add_edge(v-1, w-1, g);
}
}
// Initialize the interior edge index
property_map< graph, edge_index_t >::type e_index = get(edge_index, g);
graph_traits< graph >::edges_size_type edge_count = 0;
graph_traits< graph >::edge_iterator ei, ei_end;
for (boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
put(e_index, *ei, edge_count++);
// Test for planarity - we know it is planar, we just want to
// compute the planar embedding as a side-effect
typedef std::vector< graph_traits< graph >::edge_descriptor > vec_t;
std::vector< vec_t > embedding(num_vertices(g));
if (boyer_myrvold_planarity_test(boyer_myrvold_params::graph = g,
boyer_myrvold_params::embedding = &embedding[0]))
std::cout << "Input graph is planar" << std::endl;
else
std::cout << "Input graph is not planar" << std::endl;
std::cout << std::endl << "Vertices on the faces: " << std::endl;
vertex_output_visitor v_vis;
planar_face_traversal(g, &embedding[0], v_vis);
std::cout << std::endl << "Edges on the faces: " << std::endl;
edge_output_visitor e_vis;
planar_face_traversal(g, &embedding[0], e_vis);
return 0;
}
@Hermann-SW
Copy link
Author

https://forums.raspberrypi.com/viewtopic.php?p=1990922#p1990922

pi@pi400-64:~/boost/example $ ~/plantri52/fullgen 60 ipr code 6 stdout 2>/dev/null  | ./planar_face_traversal
Input graph is planar

Vertices on the faces: 
New face: 0 17 16 19 18 
New face: 17 0 1 39 53 52 
New face: 0 18 32 31 2 1 
New face: 1 2 3 40 39 
New face: 2 31 30 29 4 3 
New face: 3 4 5 42 41 40 
New face: 4 29 28 6 5 
New face: 5 6 7 44 43 42 
New face: 6 28 27 26 8 7 
New face: 7 8 9 45 44 
New face: 8 26 25 24 10 9 
New face: 9 10 11 47 46 45 
New face: 10 24 23 12 11 
New face: 11 12 13 49 48 47 
New face: 12 23 22 21 14 13 
New face: 13 14 15 50 49 
New face: 14 21 20 19 16 15 
New face: 15 16 17 52 51 50 
New face: 18 19 20 34 33 32 
New face: 20 21 22 35 34 
New face: 22 23 24 25 36 35 
New face: 25 26 27 37 36 
New face: 27 28 29 30 38 37 
New face: 30 31 32 33 38 
New face: 33 34 35 36 37 38 
New face: 39 40 41 55 54 53 
New face: 41 42 43 56 55 
New face: 43 44 45 46 57 56 
New face: 46 47 48 58 57 
New face: 48 49 50 51 59 58 
New face: 51 52 53 54 59 
New face: 54 55 56 57 58 59 

Edges on the faces: 
New face: (0,17) (17,16) (16,19) (19,18) (0,18) 
New face: (0,17) (0,1) (1,39) (39,53) (52,53) (17,52) 
New face: (0,18) (18,32) (31,32) (2,31) (2,1) (0,1) 
New face: (1,2) (3,2) (3,40) (39,40) (1,39) 
New face: (2,31) (31,30) (30,29) (4,29) (4,3) (3,2) 
New face: (3,4) (5,4) (5,42) (41,42) (40,41) (3,40) 
New face: (4,29) (29,28) (6,28) (6,5) (5,4) 
New face: (5,6) (7,6) (7,44) (43,44) (42,43) (5,42) 
New face: (6,28) (28,27) (27,26) (8,26) (8,7) (7,6) 
New face: (7,8) (9,8) (9,45) (44,45) (7,44) 
New face: (8,26) (26,25) (25,24) (10,24) (10,9) (9,8) 
New face: (9,10) (11,10) (11,47) (46,47) (45,46) (9,45) 
New face: (10,24) (24,23) (12,23) (12,11) (11,10) 
New face: (11,12) (13,12) (13,49) (48,49) (47,48) (11,47) 
New face: (12,23) (23,22) (22,21) (14,21) (14,13) (13,12) 
New face: (13,14) (15,14) (15,50) (49,50) (13,49) 
New face: (14,21) (21,20) (20,19) (16,19) (16,15) (15,14) 
New face: (15,16) (17,16) (17,52) (51,52) (50,51) (15,50) 
New face: (18,19) (20,19) (20,34) (33,34) (32,33) (18,32) 
New face: (20,21) (22,21) (22,35) (34,35) (20,34) 
New face: (22,23) (24,23) (25,24) (25,36) (35,36) (22,35) 
New face: (25,26) (27,26) (27,37) (36,37) (25,36) 
New face: (27,28) (29,28) (30,29) (30,38) (37,38) (27,37) 
New face: (30,31) (31,32) (32,33) (33,38) (30,38) 
New face: (33,34) (34,35) (35,36) (36,37) (37,38) (33,38) 
New face: (39,40) (40,41) (41,55) (54,55) (53,54) (39,53) 
New face: (41,42) (42,43) (43,56) (55,56) (41,55) 
New face: (43,44) (44,45) (45,46) (46,57) (56,57) (43,56) 
New face: (46,47) (47,48) (48,58) (57,58) (46,57) 
New face: (48,49) (49,50) (50,51) (51,59) (58,59) (48,58) 
New face: (51,52) (52,53) (53,54) (54,59) (51,59) 
New face: (54,55) (55,56) (56,57) (57,58) (58,59) (54,59) 
pi@pi400-64:~/boost/example $ 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment