On Wed, 28 Sep 2011, Pablo Fleurquin wrote:
Hi,
My name is Pablo Fleurquin. I am a student of M.Sc in Physics at the UIB (Palma de Mallorca, Spain) and I'm also working in the IFISC institute (Institute for Interdisciplinary Science and Complex Systems).
I have a question regarding the Depth First Search algorithm. I have been looking at the Boost library page but I'm a newbie with this stuff.
Having a directed graph G (that could be a connected graph or not), I want my program to find the cycles within the graph and remove all the edges that are part of them. It doesn't matter which cycle is erased first as long as the result is the graph G without edge that formely were part of a cycle (in other words, the remaining edges are those that doesn´t form cycles) [attached is example1]
Intuitively, I am sure that using the depth_first_search() function and recalling it recursively for each "new" graph G "with less" cycles will finally arrive to graph G with no cycles. The problem is that I have the idea, but my knowledge of c++ is not so vast to implement this code.
I'm not clear on what you're trying to do. Are you trying to remove all edges that are in any cycle in the initial graph? Or do you want to just remove enough edges to get a graph without any cycles at the end? The figures you sent suggest the first case. If you want that, one way I'd suggest is to compute the strongly connected components of your graph (using boost::strongly_connected_components) and remove any edge whose endpoints are in the same component. That will likely give you what you want, even handling the case where cycles overlap. -- Jeremiah Willcock