I want to save what are the outer nodes of my graph. For that, I have the following code (I am showing the parts I believe are relevant for the problem, I do have all the #include headers etc...):
typedef adjacency_list <
setS,
vecS,
undirectedS,
property<vertex_index_t, int>,
property<edge_index_t, int>
> SimpleGraph;
struct output_visitor : public planar_face_traversal_visitor{
int c = 0;
vector<int> vertexOuter;
vector<int> save_vertexOuter;
void begin_face(){cout << "New face: ";};
void end_face(){
if (c>3){
save_vertexOuter = vertexOuter;
}
cout << "End face "<< endl;
vertexOuter.clear();
c = 0;
};
};
struct vertex_output_visitor : public output_visitor
{
template <typename Vertex>
void next_vertex(Vertex v){
cout << v << " ";
vertexOuter.push_back(v);
c ++;
}
};
SimpleGraph BuildGraph(int i, vector<vector<int>> structureInfo){
// arguments of the function are not relevant here
// I am just passing graphs from a dataset
int j;
SimpleGraph g;
vector <int> adjList = structureInfo[i];
for(int j =0; j<adjList.size(); j++){
cout << adjList[j] << " ";
}
for (j = 0; j<adjList.size()-1; j+=2){
add_edge(adjList[j], adjList[j+1], g);
}
return g;
}
SimpleGraph tempGSN = BuildGraph(i, gs_N);
vector<vec_t> embedding(num_vertices(tempGSN));
bool is_planar = boost::boyer_myrvold_planarity_test(tempGSN, boost::boyer_myrvold_params::embedding = &embedding[0]);
if (is_planar){
vertex_output_visitor v_vis;
planar_face_traversal(tempGSN, &embedding[0], v_vis);
for (int j = 0; j < v_vis.save_vertexOuter.size()-1; j+=1 ){
Do something;}
}
So far, the code has worked correctly on small graphs (num nodes < 8), but it has started to fail at n = 9 and I don't understand why. For instance, for an adjacency list
0 3 0 4 0 6 0 7 1 3 1 5 1 6 2 4 2 5 2 6 3 6 3 7 4 6 5 6
it returns
New face: 0 3 1 5 2 4 End face
New face: 6 End face
New face: 7 End face
which does not make sense. The correct outer face would be 0 7 3 1 5 2 4.
I would be grateful for any help spotting the problem. Thanks!
Interpreting your graph as an edgelist (not an adjacency list, because that didn't seem to make sense):
I worked out that your 0 7 3 1 5 2 4 sequence stems from the plane drawing representation:
So I concur that there is something amiss. I cleaned up/simplified your code and extended it with excursions into potential causes, but none of the excursions lead to any change in behaviour.
The only insight I gained - which makes intuitive sense from both the planar drawing above and the output of the raw embedding is the point 7 is creating the problem.
If you look at the ordering of the edges for vertex 0, you will notice that they are not in consistent clockwise order (referring to the image again).
This could either be a bug, or me misunderstanding the full preconditions for the planarity-test algorithm. I suggest you take the question up at the Boost devs.
Complete Listing
This includes:
Live On Compiler Explorero
Original: (
--dump --traverse --make_bi):Removing vertex 7: (
--traverse 7) https://godbolt.org/z/7e3Mfx:Some advanced excursions:
--traverse --make_max 7 --drawhttps://godbolt.org/z/bbdba5: