My problem should be pretty simple, given the graph (BGL adjacency_list), is there a simple algorithm for deleting loops? My first attempt was to use the DFS visitor to detect an edge that would close the loop and then delete it, but I could not implement it correctly.
Any suggestions? Code examples would be better.
The acceleration is great. It has a method depth_first_searchthat takes a visitor. You can see more information about this here .
depth_first_search
All you have to do is implement the visitor as follows:
class CycleTerminator : public boost::dfs_visitor<> { template <class Edge, class Graph> void back_edge(Edge e, Graph& g) { //implement } };
, , - , .
DFS, . , node, , . .
- .
void walk(current_node, previous_node) if visited[current_node] remove edge between current_node and previous_node return end visited[current_node] = true for (each adjacent node) walk(adjacent_node, current_node) end end