3 #include <boost/graph/breadth_first_search.hpp>
4 #include <boost/graph/filtered_graph.hpp>
5 #include <boost/graph/adjacency_list.hpp>
22 template <
typename Graph>
24 typename boost::graph_traits <Graph>::vertex_descriptor old_vertex,
typename boost::graph_traits <Graph>::vertex_descriptor new_vertex)
26 if (old_vertex != new_vertex)
28 boost::add_edge(boost::source(edge, graph), new_vertex, *((
typename Graph::edge_property_type*) edge.get_property()), graph);
29 boost::remove_edge(edge, graph);
42 template <
typename Graph>
44 typename boost::graph_traits <Graph>::vertex_descriptor old_vertex,
typename boost::graph_traits <Graph>::vertex_descriptor new_vertex)
46 if (old_vertex != new_vertex)
48 boost::add_edge(boost::target(edge, graph), new_vertex, *((
typename Graph::edge_property_type*) edge.get_property()), graph);
49 boost::remove_edge(edge, graph);
62 template <
typename Graph>
63 void reconnect_edge(Graph& graph,
typename boost::graph_traits <Graph>::edge_descriptor edge,
64 typename boost::graph_traits <Graph>::vertex_descriptor old_vertex,
typename boost::graph_traits <Graph>::vertex_descriptor new_vertex)
66 if (boost::source(edge, graph) == old_vertex)
79 template <
typename OutputIterator,
typename EventTag>
103 template <
typename Vertex,
typename Graph>
108 *_iterator++ = vertex;
121 OutputIterator _iterator;
132 template <
typename OutputIterator,
typename EventTag>
150 template <
typename Graph,
typename IndexMap,
typename VertexSequence>
151 bool is_path(
const Graph& graph,
const IndexMap index_map, VertexSequence& path)
153 typedef boost::graph_traits <Graph> traits;
154 typename traits::vertex_iterator vertex_iter, vertex_end;
155 typename traits::vertex_descriptor start = traits::null_vertex();
157 size_t path_length = 0;
158 for (boost::tie(vertex_iter, vertex_end) = boost::vertices(graph); vertex_iter != vertex_end; ++vertex_iter)
160 size_t degree = boost::out_degree(*vertex_iter, graph);
163 else if (degree == 1)
164 start = *vertex_iter;
165 path_length += degree;
167 if (start == traits::null_vertex())
170 path_length = path_length / 2 + 1;
172 size_t size_before = path.size();
175 boost::breadth_first_search(graph, start, boost::vertex_index_map(index_map).visitor(boost::make_bfs_visitor(
detail::write_vertex(
176 std::back_inserter(path), boost::on_discover_vertex()))));
178 return path.size() - size_before == path_length;
189 template <
typename Graph,
typename IndexMap>
190 bool is_path(
const Graph& graph,
const IndexMap index_map)
192 std::vector <typename boost::graph_traits <Graph>::vertex_descriptor> path;
193 path.reserve(boost::num_vertices(graph));
194 return is_path(graph, index_map, path);
204 template <
typename Graph>
207 return is_path(g, boost::get(boost::vertex_index, g));
219 template <
typename Graph,
typename IndexMap,
typename Vertex>
224 typedef boost::graph_traits <Graph> traits;
225 typename traits::vertex_iterator vertex_iter, vertex_end;
226 typename traits::edge_iterator edge_iter, edge_end;
229 for (boost::tie(edge_iter, edge_end) = boost::edges(graph); edge_iter != edge_end; ++edge_iter)
234 for (boost::tie(vertex_iter, vertex_end) = boost::vertices(graph); vertex_iter != vertex_end; ++vertex_iter)
236 if (boost::out_degree(*vertex_iter, graph) == edges)
238 vertex = *vertex_iter;
254 template <
typename Graph,
typename Vertex>
257 return find_star_vertex(graph, boost::get(boost::vertex_index, graph), vertex);
268 template <
typename Graph,
typename IndexMap>
269 bool is_star(
const Graph& graph,
const IndexMap index_map)
271 typename boost::graph_traits <Graph>::vertex_descriptor vertex;
282 template <
typename Graph>
285 return is_star(graph, boost::get(boost::vertex_index, graph));
295 template <
typename Graph,
typename VertexSet>
298 typedef boost::graph_traits <Graph> traits;
299 typename traits::edge_iterator edge_iter, edge_end;
301 for (boost::tie(edge_iter, edge_end) = boost::edges(graph); edge_iter != edge_end; ++edge_iter)
303 vertex_set.insert(boost::source(*edge_iter, graph));
304 vertex_set.insert(boost::target(*edge_iter, graph));
#define CMR_UNUSED(x)
Definition: env.h:24
vertex_writer< OutputIterator, EventTag > write_vertex(OutputIterator iterator, EventTag tag)
Definition: graph_utils.hpp:133
bool find_star_vertex(const Graph &graph, const IndexMap index_map, Vertex &vertex)
Definition: graph_utils.hpp:220
bool is_path(const Graph &graph, const IndexMap index_map, VertexSequence &path)
Definition: graph_utils.hpp:151
void used_vertices(const Graph &graph, VertexSet &vertex_set)
Definition: graph_utils.hpp:296
void reconnect_edge_target(Graph &graph, typename boost::graph_traits< Graph >::edge_descriptor edge, typename boost::graph_traits< Graph >::vertex_descriptor old_vertex, typename boost::graph_traits< Graph >::vertex_descriptor new_vertex)
Definition: graph_utils.hpp:23
bool is_star(const Graph &graph, const IndexMap index_map)
Definition: graph_utils.hpp:269
void reconnect_edge(Graph &graph, typename boost::graph_traits< Graph >::edge_descriptor edge, typename boost::graph_traits< Graph >::vertex_descriptor old_vertex, typename boost::graph_traits< Graph >::vertex_descriptor new_vertex)
Definition: graph_utils.hpp:63
void reconnect_edge_source(Graph &graph, typename boost::graph_traits< Graph >::edge_descriptor edge, typename boost::graph_traits< Graph >::vertex_descriptor old_vertex, typename boost::graph_traits< Graph >::vertex_descriptor new_vertex)
Definition: graph_utils.hpp:43
Definition: algorithm.hpp:14
Definition: graph_utils.hpp:81
void operator()(Vertex vertex, const Graph &graph)
Definition: graph_utils.hpp:104
vertex_writer(OutputIterator iterator)
Definition: graph_utils.hpp:90
OutputIterator iterator() const
Definition: graph_utils.hpp:115
EventTag event_filter
Definition: graph_utils.hpp:82