The following code is not compiled.
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/topological_sort.hpp>
#include <boost/function_output_iterator.hpp>
typedef boost::adjacency_list<
boost::setS, // outedge list
boost::setS, // vertex list
boost::directedS, // undirected
boost::no_property, // vertex prop
boost::no_property, // edge prop
boost::no_property, // graph prop
boost::setS // edgelist
> Graph;
bool hasCycle(const Graph& aG)
{
try {
boost::topological_sort(
aG,
boost::make_function_output_iterator([](int){}));
} catch(boost::not_a_dag const&)
{
return true;
}
return false;
}
It works after changing vertice lists to be vecS http://coliru.stacked-crooked.com/a/abeb9e3f96e92af0
Is this limitation because DFS needs a deterministic visits?
Thank you,
The "limitation" is documented as the need for a vertex index. You could add one (note that you also should replace
int
byGraph::vertex_descriptor
), or adjust the graph type to include one:Adding an external index property map
Live On Coliru
Adding an internal index property map
This amounts to shifting the burden to the caller. This might make (a lot of) sense depending on the performance requirements for you application.
Live On Coliru