10 #ifndef UNDIRECTED_GRAPH_HPP 11 #define UNDIRECTED_GRAPH_HPP 13 #include <boost/graph/adjacency_iterator.hpp> 14 #include <boost/graph/properties.hpp> 15 #include <boost/static_assert.hpp> 17 #include <boost/iterator/transform_iterator.hpp> 19 #include <boost/type_traits.hpp> 27 template <
class B
idirectionalGraph,
class GraphRef = const B
idirectionalGraph&>
30 typedef boost::graph_traits<BidirectionalGraph> Traits;
32 BOOST_STATIC_ASSERT(( boost::is_same<boost::bidirectional_tag, typename BidirectionalGraph::directed_category>::value ));
49 typedef edge_descriptor (*make_undirected_edge_descriptor)(
typename Traits::edge_descriptor);
53 {
return std::make_pair(e,
false); }
55 public boost::transform_iterator<make_undirected_edge_descriptor, typename Traits::out_edge_iterator>
57 typedef boost::transform_iterator<make_undirected_edge_descriptor, typename Traits::out_edge_iterator>
63 : base_type(e, make_out_edge_descriptor) {}
67 {
return std::make_pair(e,
true); }
69 public boost::transform_iterator<make_undirected_edge_descriptor, typename Traits::in_edge_iterator>
71 typedef boost::transform_iterator<make_undirected_edge_descriptor, typename Traits::in_edge_iterator>
77 : base_type(e, make_in_edge_descriptor) {}
82 public boost::transform_iterator<make_undirected_edge_descriptor, typename Traits::edge_iterator>
84 typedef boost::transform_iterator<make_undirected_edge_descriptor, typename Traits::edge_iterator>
89 : base_type(e, make_out_edge_descriptor) {}
102 <
typename Traits::adjacency_iterator
103 ,
typename BidirectionalGraph::inv_adjacency_iterator
116 typedef typename BidirectionalGraph::edge_property_type
118 typedef typename BidirectionalGraph::vertex_property_type
123 {
return Traits::null_vertex(); }
126 typename boost::graph::detail::bundled_result<BidirectionalGraph,
127 edge_descriptor>::type&
129 {
return m_g[x.first]; }
131 typename boost::graph::detail::bundled_result<BidirectionalGraph,
132 edge_descriptor>::type
const&
134 {
return m_g[x.first]; }
138 typename boost::graph::detail::bundled_result<BidirectionalGraph,
139 vertex_descriptor>::type&
143 typename boost::graph::detail::bundled_result<BidirectionalGraph,
144 vertex_descriptor>::type
const&
154 template <
class B
idirectionalGraph>
161 template <
class B
idirectionalGraph>
168 template <
class B
idirectionalGraph,
class GRef>
169 std::pair<typename undirected_graph<BidirectionalGraph>::vertex_iterator,
176 template <
class B
idirectionalGraph,
class GRef>
177 std::pair<typename undirected_graph<BidirectionalGraph>::edge_iterator,
184 template <
class B
idirectionalGraph,
class GRef>
185 inline std::pair<typename undirected_graph<BidirectionalGraph,GRef>::out_edge_iterator,
187 out_edges(
const typename BidirectionalGraph::vertex_descriptor u,
190 std::pair<
typename BidirectionalGraph::out_edge_iterator,
191 typename BidirectionalGraph::out_edge_iterator>
193 std::pair<
typename BidirectionalGraph::in_edge_iterator,
194 typename BidirectionalGraph::in_edge_iterator>
198 return std::make_pair(
199 edge_iterator(in_edges.first, in_edges.second, out_edges.first, out_edges.first),
200 edge_iterator(in_edges.second, in_edges.second, out_edges.second, out_edges.second));
203 template <
class B
idirectionalGraph,
class GRef>
204 inline typename BidirectionalGraph::vertices_size_type
210 template <
class B
idirectionalGraph,
class GRef>
217 template <
class B
idirectionalGraph,
class GRef>
218 inline typename BidirectionalGraph::degree_size_type
219 out_degree(
const typename BidirectionalGraph::vertex_descriptor u,
225 template <
class B
idirectionalGraph,
class GRef>
226 inline std::pair<typename BidirectionalGraph::edge_descriptor, bool>
227 edge(
const typename BidirectionalGraph::vertex_descriptor u,
228 const typename BidirectionalGraph::vertex_descriptor v,
234 template <
class B
idirectionalGraph,
class GRef>
235 inline std::pair<
typename BidirectionalGraph::out_edge_iterator,
236 typename BidirectionalGraph::out_edge_iterator>
237 in_edges(
const typename BidirectionalGraph::vertex_descriptor u,
241 template <
class B
idirectionalGraph,
class GRef>
242 inline std::pair<typename undirected_graph<BidirectionalGraph,GRef>::adjacency_iterator,
247 std::pair<
typename BidirectionalGraph::adjacency_iterator,
248 typename BidirectionalGraph::adjacency_iterator>
250 std::pair<
typename BidirectionalGraph::inv_adjacency_iterator,
251 typename BidirectionalGraph::inv_adjacency_iterator>
252 inv_adjacency = boost::inv_adjacent_vertices(u, g.
m_g);
255 return std::make_pair(
256 adjacency_iterator(adjacency.first, adjacency.second, inv_adjacency.first, inv_adjacency.first),
257 adjacency_iterator(adjacency.second, adjacency.second, inv_adjacency.second, inv_adjacency.second));
260 template <
class B
idirectionalGraph,
class GRef>
261 inline typename BidirectionalGraph::degree_size_type
262 in_degree(
const typename BidirectionalGraph::vertex_descriptor u,
266 template <
class Edge,
class B
idirectionalGraph,
class GRef>
267 inline typename boost::graph_traits<BidirectionalGraph>::vertex_descriptor
276 template <
class Edge,
class B
idirectionalGraph,
class GRef>
277 inline typename boost::graph_traits<BidirectionalGraph>::vertex_descriptor
290 template <
class UndirectedGraph,
class Property,
class Tag>
292 typedef typename UndirectedGraph::base_type
Graph;
293 typedef boost::property_map<Graph, Tag>
PMap;
294 typedef typename PMap::type
type;
300 template <
class UndirectedGraph,
class Property,
class Tag>
302 typedef typename UndirectedGraph::base_type
Graph;
303 typedef boost::property_map<Graph, Tag>
PMap;
304 typedef typename PMap::type
type;
313 template<
typename PropertyMap>
320 PropertyMap&
map() {
return m_map; }
321 PropertyMap
const&
map()
const {
return m_map; }
327 template<
typename PropertyMap,
typename EdgeDescriptor,
typename ValueType>
329 EdgeDescriptor e, ValueType value)
330 {
put(map.
map(), e.first, value); }
331 template<
typename PropertyMap,
typename EdgeDescriptor>
332 typename boost::property_traits<PropertyMap>::value_type
335 {
return get(map.
map(), e.first); }
337 template<
typename PropertyMap>
346 template<
typename PropertyMap>
347 struct property_traits<
utilmm::undirected_property_map<PropertyMap> >
348 : property_traits<PropertyMap> {};
351 struct vertex_property_selector<utilmm::undirected_graph_tag> {
356 struct edge_property_selector<utilmm::undirected_graph_tag> {
361 template<
typename B
idirGraph,
typename GRef,
typename Property>
363 template<
typename B
idirGraph,
typename Property>
365 {
typedef typename property_map<BidirGraph, Property>::const_type
type; };
366 template<
typename B
idirGraph,
typename Property>
368 {
typedef typename property_map<BidirGraph, Property>::type
type; };
371 template <
class B
idirGraph,
class GRef,
class Property>
375 return get(p, g.m_g);
378 template <
class B
idirGraph,
class GRef,
class Property>
382 return get(p, g.m_g);
385 template <
class B
idirectionalGraph,
class GRef,
class Property,
class Key>
386 typename property_traits<
387 typename property_map<BidirectionalGraph, Property>::const_type
391 return get(p, g.m_g, k);
394 template <
class B
idirectionalGraph,
class GRef,
class Property,
class Key,
class Value>
402 template<
typename BidirectionalGraph,
typename GRef,
typename Tag,
411 template<
typename B
idirectionalGraph,
typename GRef,
typename Tag>
413 typename graph_property<BidirectionalGraph, Tag>::type
adjacency_iterator inv_adjacency_iterator
Definition: undirected_graph.hh:105
property_map< BidirGraph, Property >::type type
Definition: undirected_graph.hh:368
PMap::const_type const_type
Definition: undirected_graph.hh:295
boost::graph_traits< BidirectionalGraph >::vertex_descriptor source(const Edge &e, const undirected_graph< BidirectionalGraph, GRef > &g)
Definition: undirected_graph.hh:268
std::pair< typename undirected_graph< BidirectionalGraph >::vertex_iterator, typename undirected_graph< BidirectionalGraph >::vertex_iterator > vertices(const undirected_graph< BidirectionalGraph, GRef > &g)
Definition: undirected_graph.hh:171
Definition: undirected_graph.hh:345
static edge_descriptor make_out_edge_descriptor(typename Traits::edge_descriptor e)
Definition: undirected_graph.hh:52
PropertyMap & map()
Definition: undirected_graph.hh:320
undirected_graph(GraphRef g)
Definition: undirected_graph.hh:38
base_in_edge_iterator(typename Traits::in_edge_iterator e)
Definition: undirected_graph.hh:76
undirected_property_map(PropertyMap pmap)
Definition: undirected_graph.hh:317
undirected_property_map< PropertyMap > make_undirected_edge_map(PropertyMap pmap)
Definition: undirected_graph.hh:338
std::pair< typename undirected_graph< BidirectionalGraph, GRef >::adjacency_iterator, typename undirected_graph< BidirectionalGraph, GRef >::adjacency_iterator > adjacent_vertices(const typename BidirectionalGraph::vertex_descriptor u, const undirected_graph< BidirectionalGraph, GRef > &g)
Definition: undirected_graph.hh:244
boost::graph::detail::bundled_result< BidirectionalGraph, vertex_descriptor >::type & operator[](vertex_descriptor x)
Definition: undirected_graph.hh:140
static vertex_descriptor null_vertex()
Definition: undirected_graph.hh:122
std::pair< typename Traits::edge_descriptor, bool > edge_descriptor
Definition: undirected_graph.hh:48
base_out_edge_iterator(typename Traits::out_edge_iterator e)
Definition: undirected_graph.hh:62
Traits::edge_iterator traits_edge_iterator
Definition: undirected_graph.hh:111
iterator_sequence< base_in_edge_iterator, base_out_edge_iterator > in_edge_iterator
Definition: undirected_graph.hh:97
GraphRef m_g
Definition: undirected_graph.hh:151
std::pair< typename BidirectionalGraph::edge_descriptor, bool > edge(const typename BidirectionalGraph::vertex_descriptor u, const typename BidirectionalGraph::vertex_descriptor v, const undirected_graph< BidirectionalGraph, GRef > &g)
Definition: undirected_graph.hh:227
Definition: undirected_graph.hh:301
Definition: undirected_graph.hh:289
std::pair< typename BidirectionalGraph::out_edge_iterator, typename BidirectionalGraph::out_edge_iterator > in_edges(const typename BidirectionalGraph::vertex_descriptor u, const undirected_graph< BidirectionalGraph, GRef > &g)
Definition: undirected_graph.hh:237
PMap::type type
Definition: undirected_graph.hh:294
utilmm::detail::undirected_graph_edge_property_selector type
Definition: undirected_graph.hh:357
boost::undirected_tag directed_category
Definition: undirected_graph.hh:42
base_out_edge_iterator()
Definition: undirected_graph.hh:61
property_map< BidirGraph, Property >::const_type type
Definition: undirected_graph.hh:365
UndirectedGraph::base_type Graph
Definition: undirected_graph.hh:302
Definition: undirected_graph.hh:28
BidirectionalGraph::degree_size_type in_degree(const typename BidirectionalGraph::vertex_descriptor u, const undirected_graph< BidirectionalGraph, GRef > &g)
Definition: undirected_graph.hh:262
Definition: undirected_graph.hh:54
Traits::edge_parallel_category edge_parallel_category
Definition: undirected_graph.hh:43
static edge_descriptor make_in_edge_descriptor(typename Traits::edge_descriptor e)
Definition: undirected_graph.hh:66
Traits::traversal_category traversal_category
Definition: undirected_graph.hh:44
Traits::vertex_iterator vertex_iterator
Definition: undirected_graph.hh:108
Definition: undirected_graph.hh:291
utilmm::detail::undirected_graph_vertex_property_selector type
Definition: undirected_graph.hh:352
Definition: undirected_graph.hh:299
undirected_graph_tag graph_tag
Definition: undirected_graph.hh:120
boost::graph::detail::bundled_result< BidirectionalGraph, edge_descriptor >::type const & operator[](edge_descriptor x) const
Definition: undirected_graph.hh:133
boost::property_map< Graph, Tag > PMap
Definition: undirected_graph.hh:303
Traits::vertex_descriptor vertex_descriptor
Definition: undirected_graph.hh:41
edge_iterator()
Definition: undirected_graph.hh:87
Definition: undirected_graph.hh:68
boost::graph::detail::bundled_result< BidirectionalGraph, edge_descriptor >::type & operator[](edge_descriptor x)
Definition: undirected_graph.hh:128
Traits::degree_size_type degree_size_type
Definition: undirected_graph.hh:93
base_in_edge_iterator()
Definition: undirected_graph.hh:75
BidirectionalGraph::vertices_size_type num_vertices(const undirected_graph< BidirectionalGraph, GRef > &g)
Definition: undirected_graph.hh:205
Definition: undirected_graph.hh:81
undirected_graph< BidirectionalGraph >::edges_size_type num_edges(const undirected_graph< BidirectionalGraph, GRef > &g)
Definition: undirected_graph.hh:212
iterator_sequence< typename Traits::adjacency_iterator, typename BidirectionalGraph::inv_adjacency_iterator > adjacency_iterator
Definition: undirected_graph.hh:104
PropertyMap const & map() const
Definition: undirected_graph.hh:321
Definition: auto_flag.hh:6
edge_iterator(typename Traits::edge_iterator e)
Definition: undirected_graph.hh:88
BidirectionalGraph::edge_property_type edge_property_type
Definition: undirected_graph.hh:117
BidirectionalGraph::vertex_property_type vertex_property_type
Definition: undirected_graph.hh:119
boost::property_map< Graph, Tag > PMap
Definition: undirected_graph.hh:293
void put(undirected_property_map< PropertyMap > &map, EdgeDescriptor e, ValueType value)
Definition: undirected_graph.hh:328
void set_property(const utilmm::undirected_graph< BidirectionalGraph, GRef > &g, Tag tag, const Value &value)
Definition: undirected_graph.hh:405
PMap::type type
Definition: undirected_graph.hh:304
in_edge_iterator out_edge_iterator
Definition: undirected_graph.hh:98
PMap::const_type const_type
Definition: undirected_graph.hh:305
graph_property< BidirectionalGraph, Tag >::type get_property(const utilmm::undirected_graph< BidirectionalGraph, GRef > &g, Tag tag)
Definition: undirected_graph.hh:414
Traits::edges_size_type edges_size_type
Definition: undirected_graph.hh:113
Definition: undirected_graph.hh:314
BidirectionalGraph base_type
Definition: undirected_graph.hh:35
std::pair< typename undirected_graph< BidirectionalGraph >::edge_iterator, typename undirected_graph< BidirectionalGraph >::edge_iterator > edges(const undirected_graph< BidirectionalGraph, GRef > &g)
Definition: undirected_graph.hh:179
std::pair< typename undirected_graph< BidirectionalGraph, GRef >::out_edge_iterator, typename undirected_graph< BidirectionalGraph, GRef >::out_edge_iterator > out_edges(const typename BidirectionalGraph::vertex_descriptor u, const undirected_graph< BidirectionalGraph, GRef > &g)
Definition: undirected_graph.hh:187
boost::graph::detail::bundled_result< BidirectionalGraph, vertex_descriptor >::type const & operator[](vertex_descriptor x) const
Definition: undirected_graph.hh:145
BidirectionalGraph::degree_size_type out_degree(const typename BidirectionalGraph::vertex_descriptor u, const undirected_graph< BidirectionalGraph, GRef > &g)
Definition: undirected_graph.hh:219
undirected_graph< BidirectionalGraph > make_undirected_graph(const BidirectionalGraph &g)
Definition: undirected_graph.hh:156
UndirectedGraph::base_type Graph
Definition: undirected_graph.hh:292
boost::graph_traits< BidirectionalGraph >::vertex_descriptor target(const Edge &e, const undirected_graph< BidirectionalGraph, GRef > &g)
Definition: undirected_graph.hh:278
Definition: undirected_graph.hh:22
Definition: undirected_graph.hh:362
Traits::vertices_size_type vertices_size_type
Definition: undirected_graph.hh:112
Definition: iterator_sequence.hh:14