14 #ifndef INCLUDED_utility_graph_ring_detection_HH
15 #define INCLUDED_utility_graph_ring_detection_HH
21 #include <platform/types.hh>
23 #include <boost/graph/undirected_dfs.hpp>
34 template<
class Graph,
class DistanceMap,
class LabelMap >
36 typedef typename boost::graph_traits<Graph>::edge_descriptor
Edge;
37 typedef typename boost::graph_traits<Graph>::vertex_descriptor
VD;
56 typename boost::graph_traits<Graph>::adjacency_iterator iter,
end;
58 for ( boost::tie(iter,end) = boost::adjacent_vertices(source,graph); iter !=
end; ++iter, ++
index ) {
59 boost::put(
labels_,*iter,index);
67 VD const & parent( boost::source(e,g) );
68 VD const & child( boost::target(e,g) );
70 if ( distance == 1 ) {
return false; }
82 VD const & left( boost::source(e,g) );
83 VD const & right( boost::target(e,g) );
95 if ( ringsize <
size_ ) {
106 template <
class Graph >
110 typedef typename boost::graph_traits< Graph>::vertex_descriptor VD;
132 typedef typename std::map<VD,platform::Size> DataStore;
133 typedef typename boost::associative_property_map< DataStore > DataStoreMap;
135 DataStore distancestore;
136 DataStoreMap distances(distancestore);
137 DataStore labelstore;
138 DataStoreMap labels(labelstore);
144 return smallest_size;
148 template<
class Graph,
class EdgeMap,
class PathMap >
150 typedef typename boost::graph_traits<Graph>::edge_descriptor
Edge;
151 typedef typename boost::graph_traits<Graph>::vertex_descriptor
VD;
171 typename PathMap::mapped_type
path(
pathmap_[boost::source(u,g)] );
177 typename PathMap::mapped_type
const &
path(
pathmap_[boost::source(u,g)] );
178 typename PathMap::mapped_type
const & path2(
pathmap_[boost::target(u,g)] );
180 edgemap_[boost::source(u,g)][boost::target(u,g)] =
true;
181 edgemap_[boost::target(u,g)][boost::source(u,g)] =
true;
183 for ( iter = path.begin(), iter_end = path.end(); iter != iter_end; ++iter ) {
184 if ( path2.count( *iter ) == 0 ) {
188 edgemap_[boost::source(*iter,g)][boost::target(*iter,g)] =
true;
189 edgemap_[boost::target(*iter,g)][boost::source(*iter,g)] =
true;
196 utility_exit_with_message(
"Found forward or cross edge when detecting cycles - should not happen with an undirected graph." );
200 template <
class Graph >
201 std::map< typename boost::graph_traits<Graph>::vertex_descriptor, std::map< typename boost::graph_traits<Graph>::vertex_descriptor,
bool > >
203 typedef typename boost::graph_traits<Graph>::edge_descriptor Edge;
204 typedef typename boost::graph_traits<Graph>::vertex_descriptor VD;
205 typedef typename std::map< typename boost::graph_traits<Graph>::vertex_descriptor, std::map< typename boost::graph_traits<Graph>::vertex_descriptor,
bool > > EdgeMap;
206 typedef typename std::map< VD, std::set< Edge > > PathMap;
207 typedef typename std::map< VD, boost::default_color_type> VertexColorMap;
208 typedef typename std::map< Edge, boost::default_color_type> EdgeColorMap;
213 VertexColorMap vertexcolormap;
214 EdgeColorMap edgecolormap;
215 boost::associative_property_map<VertexColorMap> vertexcolorproperty(vertexcolormap);
216 boost::associative_property_map<EdgeColorMap> edgecolorproperty(edgecolormap);
221 boost::undirected_dfs(graph, vis, vertexcolorproperty, edgecolorproperty);
#define utility_exit_with_message(m)
Exit with file + line + message.
A class to implement the behavior of the smallest ring size finding algorithm, accessible through the...
platform::Size stop_level_
utility::keys::KeyLookup< KeyType >::const_iterator const_iterator
Key collection iterators.
vector0: std::vector with assert-checked bounds
void breadth_first_search_prune(const VertexListGraph &g, typename boost::graph_traits< VertexListGraph >::vertex_descriptor s, BFSVisitor vis, ColorMap color, Buffer &Q)
breadth_first_search_prune is a slightly modified versions of the Boost functions breadth_first_searc...
boost::graph_traits< Graph >::edge_descriptor Edge
boost::graph_traits< Graph >::edge_descriptor Edge
RingEdgeAnnotationVisitor(EdgeMap &edgemap, PathMap &pathmap)
RingSizeVisitor(VD const &source, Graph const &graph, DistanceMap &distances, LabelMap &labels, platform::Size &size, platform::Size const &max_size=2 *999999)
utility::keys::lookup::end< KeyType > const end
void forward_or_cross_edge(Edge, const Graph &)
platform::Size smallest_ring_size(typename boost::graph_traits< Graph >::vertex_descriptor const &vd, Graph const &graph, platform::Size const &max_ring_size=2 *999999)
A boost graph-based function to find the size of the smallest ring for a given vertex. Will return the maximum ring size, or 999999 for no ring. If there is a maximum ring size, That can be set to limit the amount of search needed.
void examine_edge(Edge, const Graph &)
Fstring::size_type index(Fstring const &s, Fstring const &ss)
First Index Position of a Substring in an Fstring.
std::map< typename boost::graph_traits< Graph >::vertex_descriptor, std::map< typename boost::graph_traits< Graph >::vertex_descriptor, bool > > annotate_ring_edges(Graph &graph)
boost::graph_traits< Graph >::vertex_descriptor VD
Program exit functions and macros.
A breadth first search with pruning for boost graphs.
bool gray_target(Edge const &e, Graph const &g)
bool tree_edge(Edge const &e, Graph const &g)
T distance(MathVector< T > const &VECTOR_A, MathVector< T > const &VECTOR_B)
void tree_edge(Edge u, const Graph &g)
boost::graph_traits< Graph >::vertex_descriptor VD
void back_edge(Edge u, const Graph &g)