lundi 25 avril 2022

How to iterate over boost graph and hide not connected vertex?

The following figure shows bi-directional graph. I have represented following graph using boost-graph. In boost-graph every edge is also considered as vertex. So L1,L2 and L3 are also vertices.
Graph

Now I want to hide vertex v1. So all the edges connected to v1 must be hide. So L1 and L2 vertices will be hidden. Now L1 is attached to V2 and V2 does not have any further attachement so V2 must be hidden. But V3 will not be hidden as it has connection with L3.

So hidden will be V1, V2, L1 and L2

For that I have traversed through boost-graph. But I was able to hide only V1 , L1 and L2. But not V2.
How to find neighbour of L1 ?

If V2 had line L4 connected, then that must be hide.
Again if L4 had V5 connected then that also be hide. Then it will create chain of removable vertices. So how to deal with this ?

Here is my code:
(vertex -> V1) and (graph -> boost graph )

 //Finding out edges of vertex
    boost::graph_traits<BGType>::out_edge_iterator ei, ei_end;
    boost::tie(ei, ei_end) = out_edges( vertex, graph ); 
    for( boost::tie(ei, ei_end) = out_edges(vertex, graph); ei != ei_end; ++ei)
    {
        auto target = boost::target ( *ei, graph );
        graph[target]._isVisible = false;
    }

    //Finding in edges of vertex
    boost::graph_traits<BGType>::in_edge_iterator ein, ein_end;
    boost::tie(ein, ein_end) = in_edges( vertex, graph ); 
    for( boost::tie(ein, ein_end) = in_edges(vertex, graph); ein != ein_end; ++ein)
    {
        auto source = boost::source ( *ein, graph ); 
        graph[source]._isVisible = false;
    }

Aucun commentaire:

Enregistrer un commentaire