[Lemon-user] Topological sort of a subgraph
Ron Mayerson
ron.mayerson at yahoo.com
Sat Sep 1 15:58:25 CEST 2012
Hi everybody,
I'm faced with the problem of topologically sorting the nodes of a subgraph. The actual code looks something like this:
lemon::ListDigraph digraph;
// add arcs + nodes to digraph
lemon::ListDigraph::NodeMap<bool> nodeMap(digraph);
lemon::ListDigraph::ArcMap<bool> arcMap(digraph);
lemon::SubDigraph<lemon::ListDigraph> subgraph(digraph, nodeMap, arcMap);
// disable some arcs + node
if( dag(subgraph) )
{
std::vector<lemon::SubDigraph<lemon::ListDigraph>::Node> nodes;
lemon::LoggerBoolMap<std::back_insert_iterator<std::vector<lemon::SubDigraph<lemon::ListDigraph>::Node> > > map(std::back_inserter(nodes));
lemon::topologicalSort(subgraph, map);
for (std::vector<lemon::SubDigraph<lemon::ListDigraph>::Node>::reverse_iterator it = nodes.rbegin();
it != nodes.rend(); ++it)
{
// do something with node (*it)
}
}
The last part is mainly adopted from: http://lemon.cs.elte.hu/pipermail/lemon-user/2012-August/000609.html
The problem with this solution is that one of the nodes (the root node of subgraph) does not show up when iterating through the nodes.
Does anyone have an explanation for this? Are there any other possible solutions for a topological sort of subgraph + iteration? (a code example would be great)
Thanks very much!
Ron
More information about the Lemon-user
mailing list