diff options
author | robot-contrib <robot-contrib@yandex-team.com> | 2022-09-19 19:34:42 +0300 |
---|---|---|
committer | robot-contrib <robot-contrib@yandex-team.com> | 2022-09-19 19:34:42 +0300 |
commit | c3b5c9d37a43563ea418c6d6fe40feb97c2b5c47 (patch) | |
tree | ef852d1f623015e13861d272b179a688806f449e | |
parent | de8ed12807e529db73db4fe1349384868c5b3050 (diff) | |
download | ydb-c3b5c9d37a43563ea418c6d6fe40feb97c2b5c47.tar.gz |
Update contrib/restricted/boost/graph to 1.80.0
63 files changed, 18225 insertions, 16410 deletions
diff --git a/contrib/restricted/boost/core/include/boost/iterator.hpp b/contrib/restricted/boost/core/include/boost/iterator.hpp deleted file mode 100644 index 4a780e8aef..0000000000 --- a/contrib/restricted/boost/core/include/boost/iterator.hpp +++ /dev/null @@ -1,22 +0,0 @@ -// (C) Copyright Beman Dawes 2000. Distributed under the Boost -// Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -#ifndef BOOST_ITERATOR_HPP -#define BOOST_ITERATOR_HPP - -#include <boost/config/header_deprecated.hpp> - -BOOST_HEADER_DEPRECATED("<iterator>") - -#include <iterator> -#include <cstddef> // std::ptrdiff_t - -namespace boost -{ - -using std::iterator; - -} // namespace boost - -#endif // BOOST_ITERATOR_HPP diff --git a/contrib/restricted/boost/graph/README.md b/contrib/restricted/boost/graph/README.md index 7a4dc73559..9fab52051f 100644 --- a/contrib/restricted/boost/graph/README.md +++ b/contrib/restricted/boost/graph/README.md @@ -1,4 +1,5 @@ -Boost Graph Library +Boost Graph Library [![Build Status](https://drone.cpp.al/api/badges/boostorg/graph/status.svg)](https://drone.cpp.al/boostorg/graph)[![Build Status](https://github.com/boostorg/graph/workflows/CI/badge.svg?branch=develop)](https://github.com/boostorg/graph/actions) + =================== A generic interface for traversing graphs, using C++ templates. @@ -7,9 +8,14 @@ The full documentation is available on [boost.org](http://www.boost.org/doc/libs ## Support, bugs and feature requests ## -Bugs and feature requests can be reported through the [Trac issue tracker](https://svn.boost.org/trac/boost/query?component=graph&desc=1&order=id) -(see [open issues](https://svn.boost.org/trac/boost/query?status=!closed&component=graph&desc=1&order=id) and -[closed issues](https://svn.boost.org/trac/boost/query?status=closed&component=graph&col=id&col=summary&col=status&col=owner&col=type&col=milestone&col=version&desc=1&order=id)). [Here](http://lists.boost.org/Archives/boost/2015/04/221780.php) is why Trac is still in use. +Bugs and feature requests can be reported through the [Github issue page](https://github.com/boostorg/graph/issues). + +See also: + +* [Current open issues](https://github.com/boostorg/graph/issues) +* [Closed issues](https://github.com/boostorg/graph/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aclosed) +* Old issues still open on [Trac](https://svn.boost.org/trac/boost/query?status=!closed&component=graph&desc=1&order=id) +* Closed issues on [Trac](https://svn.boost.org/trac/boost/query?status=closed&component=graph&col=id&col=summary&col=status&col=owner&col=type&col=milestone&col=version&desc=1&order=id) You can submit your changes through a [pull request](https://github.com/boostorg/graph/pulls). One of the maintainers will take a look (remember that it can take some time). @@ -18,24 +24,29 @@ There is no mailing-list specific to Boost Graph, although you can use the gener ## Development ## -Clone the whole boost project, which includes the individual Boost projects as submodules ([see boost+git doc](https://github.com/boostorg/boost/wiki/Getting-Started)): +| | Master | Develop | +|------------------|----------|-------------| +| Github Actions | [![Build Status](https://github.com/boostorg/graph/workflows/CI/badge.svg?branch=master)](https://github.com/boostorg/graph/actions) | [![Build Status](https://github.com/boostorg/graph/workflows/CI/badge.svg?branch=develop)](https://github.com/boostorg/graph/actions) | +|Drone | [![Build Status](https://drone.cpp.al/api/badges/boostorg/graph/status.svg?ref=refs/heads/master)](https://drone.cpp.al/boostorg/graph) | [![Build Status](https://drone.cpp.al/api/badges/boostorg/graph/status.svg)](https:/drone.cpp.al/boostorg/graph) | + +Clone the whole boost project, which includes the individual Boost projects as submodules ([see boost+git doc](https://github.com/boostorg/boost/wiki/Getting-Started)): git clone https://github.com/boostorg/boost cd boost git submodule update --init -The Boost Graph Library is located in `libs/graph/`. +The Boost Graph Library is located in `libs/graph/`. Boost Graph Library is mostly made of headers but also contains some compiled components. Here are the build commands: - - ./bootstrap.sh <- compile b2 + + ./bootstrap.sh <- compile b2 ./b2 headers <- just installs headers ./b2 <- build compiled components **Note:** The Boost Graph Library cannot currently be built outside of Boost itself. ### Running tests ### -First, make sure you are in `libs/graph/test`. +First, make sure you are in `libs/graph/test`. You can either run all the 300+ tests listed in `Jamfile.v2` or run a single test: ../../../b2 <- run all tests diff --git a/contrib/restricted/boost/graph/include/boost/graph/adjacency_iterator.hpp b/contrib/restricted/boost/graph/include/boost/graph/adjacency_iterator.hpp index c134fe5ad3..4693e3a3a6 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/adjacency_iterator.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/adjacency_iterator.hpp @@ -10,93 +10,84 @@ #ifndef BOOST_ADJACENCY_ITERATOR_HPP #define BOOST_ADJACENCY_ITERATOR_HPP -#include <boost/detail/iterator.hpp> +#include <iterator> #include <boost/iterator/iterator_adaptor.hpp> #include <boost/graph/graph_traits.hpp> namespace boost { - template <class Graph, class Vertex, class OutEdgeIter, class Difference> - struct adjacency_iterator - : iterator_adaptor< - adjacency_iterator<Graph,Vertex,OutEdgeIter,Difference> - , OutEdgeIter - , Vertex - , use_default - , Vertex - , Difference - > - { - typedef iterator_adaptor< - adjacency_iterator<Graph,Vertex,OutEdgeIter,Difference> - , OutEdgeIter - , Vertex - , use_default - , Vertex - , Difference - > super_t; - - inline adjacency_iterator() {} - inline adjacency_iterator(OutEdgeIter const& i, const Graph* g) : super_t(i), m_g(g) { } - - inline Vertex - dereference() const - { return target(*this->base(), *m_g); } - - const Graph* m_g; - }; - - template <class Graph, - class Vertex = typename graph_traits<Graph>::vertex_descriptor, - class OutEdgeIter=typename graph_traits<Graph>::out_edge_iterator> - class adjacency_iterator_generator - { - typedef typename boost::detail::iterator_traits<OutEdgeIter> - ::difference_type difference_type; - public: - typedef adjacency_iterator<Graph,Vertex,OutEdgeIter,difference_type> type; - }; - - template <class Graph, class Vertex, class InEdgeIter, class Difference> - struct inv_adjacency_iterator - : iterator_adaptor< - inv_adjacency_iterator<Graph,Vertex,InEdgeIter,Difference> - , InEdgeIter - , Vertex - , use_default - , Vertex - , Difference - > +template < class Graph, class Vertex, class OutEdgeIter, class Difference > +struct adjacency_iterator +: iterator_adaptor< + adjacency_iterator< Graph, Vertex, OutEdgeIter, Difference >, OutEdgeIter, + Vertex, use_default, Vertex, Difference > +{ + typedef iterator_adaptor< + adjacency_iterator< Graph, Vertex, OutEdgeIter, Difference >, + OutEdgeIter, Vertex, use_default, Vertex, Difference > + super_t; + + inline adjacency_iterator() {} + inline adjacency_iterator(OutEdgeIter const& i, const Graph* g) + : super_t(i), m_g(g) + { + } + + inline Vertex dereference() const { return target(*this->base(), *m_g); } + + const Graph* m_g; +}; + +template < class Graph, + class Vertex = typename graph_traits< Graph >::vertex_descriptor, + class OutEdgeIter = typename graph_traits< Graph >::out_edge_iterator > +class adjacency_iterator_generator +{ + typedef + typename std::iterator_traits< OutEdgeIter >::difference_type + difference_type; + +public: + typedef adjacency_iterator< Graph, Vertex, OutEdgeIter, difference_type > + type; +}; + +template < class Graph, class Vertex, class InEdgeIter, class Difference > +struct inv_adjacency_iterator +: iterator_adaptor< + inv_adjacency_iterator< Graph, Vertex, InEdgeIter, Difference >, + InEdgeIter, Vertex, use_default, Vertex, Difference > +{ + typedef iterator_adaptor< + inv_adjacency_iterator< Graph, Vertex, InEdgeIter, Difference >, + InEdgeIter, Vertex, use_default, Vertex, Difference > + super_t; + + inline inv_adjacency_iterator() {} + inline inv_adjacency_iterator(InEdgeIter const& i, const Graph* g) + : super_t(i), m_g(g) { - typedef iterator_adaptor< - inv_adjacency_iterator<Graph,Vertex,InEdgeIter,Difference> - , InEdgeIter - , Vertex - , use_default - , Vertex - , Difference - > super_t; - - inline inv_adjacency_iterator() { } - inline inv_adjacency_iterator(InEdgeIter const& i, const Graph* g) : super_t(i), m_g(g) { } - - inline Vertex - dereference() const - { return source(*this->base(), *m_g); } - - const Graph* m_g; - }; - - template <class Graph, - class Vertex = typename graph_traits<Graph>::vertex_descriptor, - class InEdgeIter = typename graph_traits<Graph>::in_edge_iterator> - class inv_adjacency_iterator_generator { - typedef typename boost::detail::iterator_traits<InEdgeIter> - ::difference_type difference_type; - public: - typedef inv_adjacency_iterator<Graph, Vertex, InEdgeIter, difference_type> type; - }; + } + + inline Vertex dereference() const { return source(*this->base(), *m_g); } + + const Graph* m_g; +}; + +template < class Graph, + class Vertex = typename graph_traits< Graph >::vertex_descriptor, + class InEdgeIter = typename graph_traits< Graph >::in_edge_iterator > +class inv_adjacency_iterator_generator +{ + typedef + typename std::iterator_traits< InEdgeIter >::difference_type + difference_type; + +public: + typedef inv_adjacency_iterator< Graph, Vertex, InEdgeIter, difference_type > + type; +}; } // namespace boost diff --git a/contrib/restricted/boost/graph/include/boost/graph/adjacency_list.hpp b/contrib/restricted/boost/graph/include/boost/graph/adjacency_list.hpp index da80063df4..e5050b5b62 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/adjacency_list.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/adjacency_list.hpp @@ -11,7 +11,6 @@ #ifndef BOOST_GRAPH_ADJACENCY_LIST_HPP #define BOOST_GRAPH_ADJACENCY_LIST_HPP - #include <boost/config.hpp> #include <vector> @@ -36,238 +35,272 @@ #include <boost/graph/properties.hpp> #include <boost/graph/named_graph.hpp> -namespace boost { - - //=========================================================================== - // Selectors for the VertexList and EdgeList template parameters of - // adjacency_list, and the container_gen traits class which is used - // to map the selectors to the container type used to implement the - // graph. - - struct vecS { }; - struct listS { }; - struct setS { }; - struct mapS { }; - struct multisetS { }; - struct multimapS { }; - struct hash_setS { }; - struct hash_mapS { }; - struct hash_multisetS { }; - struct hash_multimapS { }; - - template <class Selector, class ValueType> - struct container_gen { }; - - template <class ValueType> - struct container_gen<listS, ValueType> { - typedef std::list<ValueType> type; - }; - - template <class ValueType> - struct container_gen<vecS, ValueType> { - typedef std::vector<ValueType> type; - }; - - template <class ValueType> - struct container_gen<mapS, ValueType> { - typedef std::set<ValueType> type; - }; - - template <class ValueType> - struct container_gen<setS, ValueType> { - typedef std::set<ValueType> type; - }; - - template <class ValueType> - struct container_gen<multisetS, ValueType> { - typedef std::multiset<ValueType> type; - }; - - template <class ValueType> - struct container_gen<multimapS, ValueType> { - typedef std::multiset<ValueType> type; - }; - - template <class ValueType> - struct container_gen<hash_setS, ValueType> { - typedef boost::unordered_set<ValueType> type; - }; - - template <class ValueType> - struct container_gen<hash_mapS, ValueType> { - typedef boost::unordered_set<ValueType> type; - }; - - template <class ValueType> - struct container_gen<hash_multisetS, ValueType> { - typedef boost::unordered_multiset<ValueType> type; - }; - - template <class ValueType> - struct container_gen<hash_multimapS, ValueType> { - typedef boost::unordered_multiset<ValueType> type; - }; - - template <class StorageSelector> - struct parallel_edge_traits { }; - - template <> - struct parallel_edge_traits<vecS> { - typedef allow_parallel_edge_tag type; }; - - template <> - struct parallel_edge_traits<listS> { - typedef allow_parallel_edge_tag type; }; - - template <> - struct parallel_edge_traits<setS> { - typedef disallow_parallel_edge_tag type; }; - - template <> - struct parallel_edge_traits<multisetS> { - typedef allow_parallel_edge_tag type; }; - - template <> - struct parallel_edge_traits<hash_setS> { +namespace boost +{ + +//=========================================================================== +// Selectors for the VertexList and EdgeList template parameters of +// adjacency_list, and the container_gen traits class which is used +// to map the selectors to the container type used to implement the +// graph. + +struct vecS +{ +}; +struct listS +{ +}; +struct setS +{ +}; +struct mapS +{ +}; +struct multisetS +{ +}; +struct multimapS +{ +}; +struct hash_setS +{ +}; +struct hash_mapS +{ +}; +struct hash_multisetS +{ +}; +struct hash_multimapS +{ +}; + +template < class Selector, class ValueType > struct container_gen +{ +}; + +template < class ValueType > struct container_gen< listS, ValueType > +{ + typedef std::list< ValueType > type; +}; + +template < class ValueType > struct container_gen< vecS, ValueType > +{ + typedef std::vector< ValueType > type; +}; + +template < class ValueType > struct container_gen< mapS, ValueType > +{ + typedef std::set< ValueType > type; +}; + +template < class ValueType > struct container_gen< setS, ValueType > +{ + typedef std::set< ValueType > type; +}; + +template < class ValueType > struct container_gen< multisetS, ValueType > +{ + typedef std::multiset< ValueType > type; +}; + +template < class ValueType > struct container_gen< multimapS, ValueType > +{ + typedef std::multiset< ValueType > type; +}; + +template < class ValueType > struct container_gen< hash_setS, ValueType > +{ + typedef boost::unordered_set< ValueType > type; +}; + +template < class ValueType > struct container_gen< hash_mapS, ValueType > +{ + typedef boost::unordered_set< ValueType > type; +}; + +template < class ValueType > struct container_gen< hash_multisetS, ValueType > +{ + typedef boost::unordered_multiset< ValueType > type; +}; + +template < class ValueType > struct container_gen< hash_multimapS, ValueType > +{ + typedef boost::unordered_multiset< ValueType > type; +}; + +template < class StorageSelector > struct parallel_edge_traits +{ +}; + +template <> struct parallel_edge_traits< vecS > +{ + typedef allow_parallel_edge_tag type; +}; + +template <> struct parallel_edge_traits< listS > +{ + typedef allow_parallel_edge_tag type; +}; + +template <> struct parallel_edge_traits< setS > +{ + typedef disallow_parallel_edge_tag type; +}; + +template <> struct parallel_edge_traits< multisetS > +{ + typedef allow_parallel_edge_tag type; +}; + +template <> struct parallel_edge_traits< hash_setS > +{ typedef disallow_parallel_edge_tag type; - }; +}; - // mapS is obsolete, replaced with setS - template <> - struct parallel_edge_traits<mapS> { - typedef disallow_parallel_edge_tag type; }; +// mapS is obsolete, replaced with setS +template <> struct parallel_edge_traits< mapS > +{ + typedef disallow_parallel_edge_tag type; +}; - template <> - struct parallel_edge_traits<hash_mapS> { +template <> struct parallel_edge_traits< hash_mapS > +{ typedef disallow_parallel_edge_tag type; - }; +}; - template <> - struct parallel_edge_traits<hash_multisetS> { +template <> struct parallel_edge_traits< hash_multisetS > +{ typedef allow_parallel_edge_tag type; - }; +}; - template <> - struct parallel_edge_traits<hash_multimapS> { +template <> struct parallel_edge_traits< hash_multimapS > +{ typedef allow_parallel_edge_tag type; - }; +}; - namespace detail { - template <class Directed> struct is_random_access { - enum { value = false}; - typedef mpl::false_ type; +namespace detail +{ + template < class Directed > struct is_random_access + { + enum + { + value = false + }; + typedef mpl::false_ type; }; - template <> - struct is_random_access<vecS> { - enum { value = true }; - typedef mpl::true_ type; + template <> struct is_random_access< vecS > + { + enum + { + value = true + }; + typedef mpl::true_ type; }; - } // namespace detail - - template <typename Selector> struct is_distributed_selector: mpl::false_ {}; - +} // namespace detail - //=========================================================================== - // The adjacency_list_traits class, which provides a way to access - // some of the associated types of an adjacency_list type without - // having to first create the adjacency_list type. This is useful - // when trying to create interior vertex or edge properties who's - // value type is a vertex or edge descriptor. +template < typename Selector > struct is_distributed_selector : mpl::false_ +{ +}; - template <class OutEdgeListS = vecS, - class VertexListS = vecS, - class DirectedS = directedS, - class EdgeListS = listS> - struct adjacency_list_traits - { - typedef typename detail::is_random_access<VertexListS>::type - is_rand_access; +//=========================================================================== +// The adjacency_list_traits class, which provides a way to access +// some of the associated types of an adjacency_list type without +// having to first create the adjacency_list type. This is useful +// when trying to create interior vertex or edge properties who's +// value type is a vertex or edge descriptor. + +template < class OutEdgeListS = vecS, class VertexListS = vecS, + class DirectedS = directedS, class EdgeListS = listS > +struct adjacency_list_traits +{ + typedef + typename detail::is_random_access< VertexListS >::type is_rand_access; typedef typename DirectedS::is_bidir_t is_bidir; typedef typename DirectedS::is_directed_t is_directed; - typedef typename mpl::if_<is_bidir, - bidirectional_tag, - typename mpl::if_<is_directed, - directed_tag, undirected_tag - >::type - >::type directed_category; + typedef typename mpl::if_< is_bidir, bidirectional_tag, + typename mpl::if_< is_directed, directed_tag, + undirected_tag >::type >::type directed_category; - typedef typename parallel_edge_traits<OutEdgeListS>::type - edge_parallel_category; + typedef typename parallel_edge_traits< OutEdgeListS >::type + edge_parallel_category; typedef std::size_t vertices_size_type; typedef void* vertex_ptr; - typedef typename mpl::if_<is_rand_access, - vertices_size_type, vertex_ptr>::type vertex_descriptor; - typedef detail::edge_desc_impl<directed_category, vertex_descriptor> - edge_descriptor; + typedef typename mpl::if_< is_rand_access, vertices_size_type, + vertex_ptr >::type vertex_descriptor; + typedef detail::edge_desc_impl< directed_category, vertex_descriptor > + edge_descriptor; - private: +private: // Logic to figure out the edges_size_type - struct dummy {}; - typedef typename container_gen<EdgeListS, dummy>::type EdgeContainer; + struct dummy + { + }; + typedef typename container_gen< EdgeListS, dummy >::type EdgeContainer; typedef typename DirectedS::is_bidir_t BidirectionalT; typedef typename DirectedS::is_directed_t DirectedT; - typedef typename mpl::and_<DirectedT, - typename mpl::not_<BidirectionalT>::type >::type on_edge_storage; - public: - typedef typename mpl::if_<on_edge_storage, - std::size_t, typename EdgeContainer::size_type - >::type edges_size_type; + typedef typename mpl::and_< DirectedT, + typename mpl::not_< BidirectionalT >::type >::type on_edge_storage; - }; +public: + typedef typename mpl::if_< on_edge_storage, std::size_t, + typename EdgeContainer::size_type >::type edges_size_type; +}; } // namespace boost #include <boost/graph/detail/adjacency_list.hpp> -namespace boost { - - //=========================================================================== - // The adjacency_list class. - // - - template <class OutEdgeListS = vecS, // a Sequence or an AssociativeContainer - class VertexListS = vecS, // a Sequence or a RandomAccessContainer - class DirectedS = directedS, - class VertexProperty = no_property, - class EdgeProperty = no_property, - class GraphProperty = no_property, - class EdgeListS = listS> - class adjacency_list - : public detail::adj_list_gen< - adjacency_list<OutEdgeListS,VertexListS,DirectedS, - VertexProperty,EdgeProperty,GraphProperty,EdgeListS>, - VertexListS, OutEdgeListS, DirectedS, - VertexProperty, EdgeProperty, - GraphProperty, EdgeListS>::type, - // Support for named vertices - public graph::maybe_named_graph< - adjacency_list<OutEdgeListS,VertexListS,DirectedS, - VertexProperty,EdgeProperty,GraphProperty,EdgeListS>, - typename adjacency_list_traits<OutEdgeListS, VertexListS, DirectedS, - EdgeListS>::vertex_descriptor, - VertexProperty> - { - public: +namespace boost +{ + +//=========================================================================== +// The adjacency_list class. +// + +template < class OutEdgeListS = vecS, // a Sequence or an AssociativeContainer + class VertexListS = vecS, // a Sequence or a RandomAccessContainer + class DirectedS = directedS, class VertexProperty = no_property, + class EdgeProperty = no_property, class GraphProperty = no_property, + class EdgeListS = listS > +class adjacency_list +: public detail::adj_list_gen< + adjacency_list< OutEdgeListS, VertexListS, DirectedS, VertexProperty, + EdgeProperty, GraphProperty, EdgeListS >, + VertexListS, OutEdgeListS, DirectedS, VertexProperty, EdgeProperty, + GraphProperty, EdgeListS >::type, + // Support for named vertices + public graph::maybe_named_graph< + adjacency_list< OutEdgeListS, VertexListS, DirectedS, VertexProperty, + EdgeProperty, GraphProperty, EdgeListS >, + typename adjacency_list_traits< OutEdgeListS, VertexListS, DirectedS, + EdgeListS >::vertex_descriptor, + VertexProperty > +{ +public: typedef GraphProperty graph_property_type; - typedef typename lookup_one_property<GraphProperty, graph_bundle_t>::type graph_bundled; + typedef typename lookup_one_property< GraphProperty, graph_bundle_t >::type + graph_bundled; typedef VertexProperty vertex_property_type; - typedef typename lookup_one_property<VertexProperty, vertex_bundle_t>::type vertex_bundled; + typedef + typename lookup_one_property< VertexProperty, vertex_bundle_t >::type + vertex_bundled; typedef EdgeProperty edge_property_type; - typedef typename lookup_one_property<EdgeProperty, edge_bundle_t>::type edge_bundled; + typedef typename lookup_one_property< EdgeProperty, edge_bundle_t >::type + edge_bundled; - private: +private: typedef adjacency_list self; - typedef typename detail::adj_list_gen< - self, VertexListS, OutEdgeListS, DirectedS, - vertex_property_type, edge_property_type, GraphProperty, EdgeListS - >::type Base; + typedef typename detail::adj_list_gen< self, VertexListS, OutEdgeListS, + DirectedS, vertex_property_type, edge_property_type, GraphProperty, + EdgeListS >::type Base; - public: +public: typedef typename Base::stored_vertex stored_vertex; typedef typename Base::vertices_size_type vertices_size_type; typedef typename Base::edges_size_type edges_size_type; @@ -279,155 +312,164 @@ namespace boost { typedef DirectedS directed_selector; typedef EdgeListS edge_list_selector; - adjacency_list(const GraphProperty& p = GraphProperty()) - : m_property(new graph_property_type(p)) - { } + : m_property(new graph_property_type(p)) + { + } adjacency_list(const adjacency_list& x) - : Base(x), m_property(new graph_property_type(*x.m_property)) - { } - - adjacency_list& operator=(const adjacency_list& x) { - // TBD: probably should give the strong guarantee - if (&x != this) { - Base::operator=(x); - - // Copy/swap the ptr since we can't just assign it... - property_ptr p(new graph_property_type(*x.m_property)); - m_property.swap(p); - } - return *this; + : Base(x), m_property(new graph_property_type(*x.m_property)) + { + } + + adjacency_list& operator=(const adjacency_list& x) + { + // TBD: probably should give the strong guarantee + if (&x != this) + { + Base::operator=(x); + + // Copy/swap the ptr since we can't just assign it... + property_ptr p(new graph_property_type(*x.m_property)); + m_property.swap(p); + } + return *this; } // Required by Mutable Graph adjacency_list(vertices_size_type num_vertices, - const GraphProperty& p = GraphProperty()) - : Base(num_vertices), m_property(new graph_property_type(p)) - { } + const GraphProperty& p = GraphProperty()) + : Base(num_vertices), m_property(new graph_property_type(p)) + { + } // Required by Iterator Constructible Graph - template <class EdgeIterator> - adjacency_list(EdgeIterator first, EdgeIterator last, - vertices_size_type n, - edges_size_type = 0, - const GraphProperty& p = GraphProperty()) - : Base(n, first, last), m_property(new graph_property_type(p)) - { } + template < class EdgeIterator > + adjacency_list(EdgeIterator first, EdgeIterator last, vertices_size_type n, + edges_size_type = 0, const GraphProperty& p = GraphProperty()) + : Base(n, first, last), m_property(new graph_property_type(p)) + { + } - template <class EdgeIterator, class EdgePropertyIterator> + template < class EdgeIterator, class EdgePropertyIterator > adjacency_list(EdgeIterator first, EdgeIterator last, - EdgePropertyIterator ep_iter, - vertices_size_type n, - edges_size_type = 0, - const GraphProperty& p = GraphProperty()) - : Base(n, first, last, ep_iter), m_property(new graph_property_type(p)) - { } - - void swap(adjacency_list& x) { - // Is there a more efficient way to do this? - adjacency_list tmp(x); - x = *this; - *this = tmp; + EdgePropertyIterator ep_iter, vertices_size_type n, edges_size_type = 0, + const GraphProperty& p = GraphProperty()) + : Base(n, first, last, ep_iter), m_property(new graph_property_type(p)) + { + } + + void swap(adjacency_list& x) + { + // Is there a more efficient way to do this? + adjacency_list tmp(x); + x = *this; + *this = tmp; } void clear() { - this->clearing_graph(); - Base::clear(); + this->clearing_graph(); + Base::clear(); } #ifndef BOOST_GRAPH_NO_BUNDLED_PROPERTIES // Directly access a vertex or edge bundle vertex_bundled& operator[](vertex_descriptor v) - { return get(vertex_bundle, *this)[v]; } + { + return get(vertex_bundle, *this)[v]; + } const vertex_bundled& operator[](vertex_descriptor v) const - { return get(vertex_bundle, *this)[v]; } + { + return get(vertex_bundle, *this)[v]; + } edge_bundled& operator[](edge_descriptor e) - { return get(edge_bundle, *this)[e]; } + { + return get(edge_bundle, *this)[e]; + } const edge_bundled& operator[](edge_descriptor e) const - { return get(edge_bundle, *this)[e]; } + { + return get(edge_bundle, *this)[e]; + } - graph_bundled& operator[](graph_bundle_t) - { return get_property(*this); } + graph_bundled& operator[](graph_bundle_t) { return get_property(*this); } graph_bundled const& operator[](graph_bundle_t) const - { return get_property(*this); } + { + return get_property(*this); + } #endif // protected: (would be protected if friends were more portable) - typedef scoped_ptr<graph_property_type> property_ptr; - property_ptr m_property; - }; + typedef scoped_ptr< graph_property_type > property_ptr; + property_ptr m_property; +}; -#define ADJLIST_PARAMS \ +#define ADJLIST_PARAMS \ typename OEL, typename VL, typename D, typename VP, typename EP, \ - typename GP, typename EL -#define ADJLIST adjacency_list<OEL,VL,D,VP,EP,GP,EL> + typename GP, typename EL +#define ADJLIST adjacency_list< OEL, VL, D, VP, EP, GP, EL > - template<ADJLIST_PARAMS, typename Tag, typename Value> - inline void set_property(ADJLIST& g, Tag tag, Value const& value) { +template < ADJLIST_PARAMS, typename Tag, typename Value > +inline void set_property(ADJLIST& g, Tag tag, Value const& value) +{ get_property_value(*g.m_property, tag) = value; - } +} - template<ADJLIST_PARAMS, typename Tag> - inline typename graph_property<ADJLIST, Tag>::type& - get_property(ADJLIST& g, Tag tag) { +template < ADJLIST_PARAMS, typename Tag > +inline typename graph_property< ADJLIST, Tag >::type& get_property( + ADJLIST& g, Tag tag) +{ return get_property_value(*g.m_property, tag); - } +} - template<ADJLIST_PARAMS, typename Tag> - inline typename graph_property<ADJLIST, Tag>::type const& - get_property(ADJLIST const& g, Tag tag) { +template < ADJLIST_PARAMS, typename Tag > +inline typename graph_property< ADJLIST, Tag >::type const& get_property( + ADJLIST const& g, Tag tag) +{ return get_property_value(*g.m_property, tag); - } - - // dwa 09/25/00 - needed to be more explicit so reverse_graph would work. - template <class Directed, class Vertex, - class OutEdgeListS, - class VertexListS, - class DirectedS, - class VertexProperty, - class EdgeProperty, - class GraphProperty, class EdgeListS> - inline Vertex - source(const detail::edge_base<Directed,Vertex>& e, - const adjacency_list<OutEdgeListS, VertexListS, DirectedS, - VertexProperty, EdgeProperty, GraphProperty, EdgeListS>&) - { +} + +// dwa 09/25/00 - needed to be more explicit so reverse_graph would work. +template < class Directed, class Vertex, class OutEdgeListS, class VertexListS, + class DirectedS, class VertexProperty, class EdgeProperty, + class GraphProperty, class EdgeListS > +inline Vertex source(const detail::edge_base< Directed, Vertex >& e, + const adjacency_list< OutEdgeListS, VertexListS, DirectedS, VertexProperty, + EdgeProperty, GraphProperty, EdgeListS >&) +{ return e.m_source; - } - - template <class Directed, class Vertex, class OutEdgeListS, - class VertexListS, class DirectedS, class VertexProperty, - class EdgeProperty, class GraphProperty, class EdgeListS> - inline Vertex - target(const detail::edge_base<Directed,Vertex>& e, - const adjacency_list<OutEdgeListS, VertexListS, DirectedS, - VertexProperty, EdgeProperty, GraphProperty, EdgeListS>&) - { +} + +template < class Directed, class Vertex, class OutEdgeListS, class VertexListS, + class DirectedS, class VertexProperty, class EdgeProperty, + class GraphProperty, class EdgeListS > +inline Vertex target(const detail::edge_base< Directed, Vertex >& e, + const adjacency_list< OutEdgeListS, VertexListS, DirectedS, VertexProperty, + EdgeProperty, GraphProperty, EdgeListS >&) +{ return e.m_target; - } +} // Mutability Traits -template <ADJLIST_PARAMS> -struct graph_mutability_traits<ADJLIST> { +template < ADJLIST_PARAMS > struct graph_mutability_traits< ADJLIST > +{ typedef mutable_property_graph_tag category; }; // Can't remove vertices from adjacency lists with VL==vecS -template <typename OEL, typename D, typename VP, typename EP, typename GP, typename EL> -struct graph_mutability_traits< adjacency_list<OEL,vecS,D,VP,EP,GP,EL> > { +template < typename OEL, typename D, typename VP, typename EP, typename GP, + typename EL > +struct graph_mutability_traits< adjacency_list< OEL, vecS, D, VP, EP, GP, EL > > +{ typedef add_only_property_graph_tag category; }; #undef ADJLIST_PARAMS #undef ADJLIST - } // namespace boost - #endif // BOOST_GRAPH_ADJACENCY_LIST_HPP diff --git a/contrib/restricted/boost/graph/include/boost/graph/boykov_kolmogorov_max_flow.hpp b/contrib/restricted/boost/graph/include/boost/graph/boykov_kolmogorov_max_flow.hpp index 1edc1323ef..eb0189eb5f 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/boykov_kolmogorov_max_flow.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/boykov_kolmogorov_max_flow.hpp @@ -61,741 +61,944 @@ // Kolmogorov, V. "Graph Based Algorithms for Scene Reconstruction from Two or // More Views". PhD thesis, Cornell University, Sep 2003. -namespace boost { - -namespace detail { - -template <class Graph, - class EdgeCapacityMap, - class ResidualCapacityEdgeMap, - class ReverseEdgeMap, - class PredecessorMap, - class ColorMap, - class DistanceMap, - class IndexMap> -class bk_max_flow { - typedef typename property_traits<EdgeCapacityMap>::value_type tEdgeVal; - typedef graph_traits<Graph> tGraphTraits; - typedef typename tGraphTraits::vertex_iterator vertex_iterator; - typedef typename tGraphTraits::vertex_descriptor vertex_descriptor; - typedef typename tGraphTraits::edge_descriptor edge_descriptor; - typedef typename tGraphTraits::edge_iterator edge_iterator; - typedef typename tGraphTraits::out_edge_iterator out_edge_iterator; - typedef boost::queue<vertex_descriptor> tQueue; //queue of vertices, used in adoption-stage - typedef typename property_traits<ColorMap>::value_type tColorValue; - typedef color_traits<tColorValue> tColorTraits; - typedef typename property_traits<DistanceMap>::value_type tDistanceVal; +namespace boost +{ + +namespace detail +{ + + template < class Graph, class EdgeCapacityMap, + class ResidualCapacityEdgeMap, class ReverseEdgeMap, + class PredecessorMap, class ColorMap, class DistanceMap, + class IndexMap > + class bk_max_flow + { + typedef + typename property_traits< EdgeCapacityMap >::value_type tEdgeVal; + typedef graph_traits< Graph > tGraphTraits; + typedef typename tGraphTraits::vertex_iterator vertex_iterator; + typedef typename tGraphTraits::vertex_descriptor vertex_descriptor; + typedef typename tGraphTraits::edge_descriptor edge_descriptor; + typedef typename tGraphTraits::edge_iterator edge_iterator; + typedef typename tGraphTraits::out_edge_iterator out_edge_iterator; + typedef boost::queue< vertex_descriptor > + tQueue; // queue of vertices, used in adoption-stage + typedef typename property_traits< ColorMap >::value_type tColorValue; + typedef color_traits< tColorValue > tColorTraits; + typedef + typename property_traits< DistanceMap >::value_type tDistanceVal; public: - bk_max_flow(Graph& g, - EdgeCapacityMap cap, - ResidualCapacityEdgeMap res, - ReverseEdgeMap rev, - PredecessorMap pre, - ColorMap color, - DistanceMap dist, - IndexMap idx, - vertex_descriptor src, - vertex_descriptor sink): - m_g(g), - m_index_map(idx), - m_cap_map(cap), - m_res_cap_map(res), - m_rev_edge_map(rev), - m_pre_map(pre), - m_tree_map(color), - m_dist_map(dist), - m_source(src), - m_sink(sink), - m_active_nodes(), - m_in_active_list_vec(num_vertices(g), false), - m_in_active_list_map(make_iterator_property_map(m_in_active_list_vec.begin(), m_index_map)), - m_has_parent_vec(num_vertices(g), false), - m_has_parent_map(make_iterator_property_map(m_has_parent_vec.begin(), m_index_map)), - m_time_vec(num_vertices(g), 0), - m_time_map(make_iterator_property_map(m_time_vec.begin(), m_index_map)), - m_flow(0), - m_time(1), - m_last_grow_vertex(graph_traits<Graph>::null_vertex()){ - // initialize the color-map with gray-values - vertex_iterator vi, v_end; - for(boost::tie(vi, v_end) = vertices(m_g); vi != v_end; ++vi){ - set_tree(*vi, tColorTraits::gray()); - } - // Initialize flow to zero which means initializing - // the residual capacity equal to the capacity - edge_iterator ei, e_end; - for(boost::tie(ei, e_end) = edges(m_g); ei != e_end; ++ei) { - put(m_res_cap_map, *ei, get(m_cap_map, *ei)); - BOOST_ASSERT(get(m_rev_edge_map, get(m_rev_edge_map, *ei)) == *ei); //check if the reverse edge map is build up properly - } - //init the search trees with the two terminals - set_tree(m_source, tColorTraits::black()); - set_tree(m_sink, tColorTraits::white()); - put(m_time_map, m_source, 1); - put(m_time_map, m_sink, 1); - } - - tEdgeVal max_flow(){ - //augment direct paths from SOURCE->SINK and SOURCE->VERTEX->SINK - augment_direct_paths(); - //start the main-loop - while(true){ - bool path_found; - edge_descriptor connecting_edge; - boost::tie(connecting_edge, path_found) = grow(); //find a path from source to sink - if(!path_found){ - //we're finished, no more paths were found - break; - } - ++m_time; - augment(connecting_edge); //augment that path - adopt(); //rebuild search tree structure + bk_max_flow(Graph& g, EdgeCapacityMap cap, ResidualCapacityEdgeMap res, + ReverseEdgeMap rev, PredecessorMap pre, ColorMap color, + DistanceMap dist, IndexMap idx, vertex_descriptor src, + vertex_descriptor sink) + : m_g(g) + , m_index_map(idx) + , m_cap_map(cap) + , m_res_cap_map(res) + , m_rev_edge_map(rev) + , m_pre_map(pre) + , m_tree_map(color) + , m_dist_map(dist) + , m_source(src) + , m_sink(sink) + , m_active_nodes() + , m_in_active_list_vec(num_vertices(g), false) + , m_in_active_list_map(make_iterator_property_map( + m_in_active_list_vec.begin(), m_index_map)) + , m_has_parent_vec(num_vertices(g), false) + , m_has_parent_map( + make_iterator_property_map(m_has_parent_vec.begin(), m_index_map)) + , m_time_vec(num_vertices(g), 0) + , m_time_map( + make_iterator_property_map(m_time_vec.begin(), m_index_map)) + , m_flow(0) + , m_time(1) + , m_last_grow_vertex(graph_traits< Graph >::null_vertex()) + { + // initialize the color-map with gray-values + vertex_iterator vi, v_end; + for (boost::tie(vi, v_end) = vertices(m_g); vi != v_end; ++vi) + { + set_tree(*vi, tColorTraits::gray()); + } + // Initialize flow to zero which means initializing + // the residual capacity equal to the capacity + edge_iterator ei, e_end; + for (boost::tie(ei, e_end) = edges(m_g); ei != e_end; ++ei) + { + put(m_res_cap_map, *ei, get(m_cap_map, *ei)); + BOOST_ASSERT(get(m_rev_edge_map, get(m_rev_edge_map, *ei)) + == *ei); // check if the reverse edge map is build up + // properly + } + // init the search trees with the two terminals + set_tree(m_source, tColorTraits::black()); + set_tree(m_sink, tColorTraits::white()); + put(m_time_map, m_source, 1); + put(m_time_map, m_sink, 1); } - return m_flow; - } - // the complete class is protected, as we want access to members in - // derived test-class (see test/boykov_kolmogorov_max_flow_test.cpp) - protected: - void augment_direct_paths(){ - // in a first step, we augment all direct paths from source->NODE->sink - // and additionally paths from source->sink. This improves especially - // graphcuts for segmentation, as most of the nodes have source/sink - // connects but shouldn't have an impact on other maxflow problems - // (this is done in grow() anyway) - out_edge_iterator ei, e_end; - for(boost::tie(ei, e_end) = out_edges(m_source, m_g); ei != e_end; ++ei){ - edge_descriptor from_source = *ei; - vertex_descriptor current_node = target(from_source, m_g); - if(current_node == m_sink){ - tEdgeVal cap = get(m_res_cap_map, from_source); - put(m_res_cap_map, from_source, 0); - m_flow += cap; - continue; - } - edge_descriptor to_sink; - bool is_there; - boost::tie(to_sink, is_there) = lookup_edge(current_node, m_sink, m_g); - if(is_there){ - tEdgeVal cap_from_source = get(m_res_cap_map, from_source); - tEdgeVal cap_to_sink = get(m_res_cap_map, to_sink); - if(cap_from_source > cap_to_sink){ - set_tree(current_node, tColorTraits::black()); - add_active_node(current_node); - set_edge_to_parent(current_node, from_source); - put(m_dist_map, current_node, 1); - put(m_time_map, current_node, 1); - // add stuff to flow and update residuals. we dont need to - // update reverse_edges, as incoming/outgoing edges to/from - // source/sink don't count for max-flow - put(m_res_cap_map, from_source, get(m_res_cap_map, from_source) - cap_to_sink); - put(m_res_cap_map, to_sink, 0); - m_flow += cap_to_sink; - } else if(cap_to_sink > 0){ - set_tree(current_node, tColorTraits::white()); - add_active_node(current_node); - set_edge_to_parent(current_node, to_sink); - put(m_dist_map, current_node, 1); - put(m_time_map, current_node, 1); - // add stuff to flow and update residuals. we dont need to update - // reverse_edges, as incoming/outgoing edges to/from source/sink - // don't count for max-flow - put(m_res_cap_map, to_sink, get(m_res_cap_map, to_sink) - cap_from_source); - put(m_res_cap_map, from_source, 0); - m_flow += cap_from_source; + tEdgeVal max_flow() + { + // augment direct paths from SOURCE->SINK and SOURCE->VERTEX->SINK + augment_direct_paths(); + // start the main-loop + while (true) + { + bool path_found; + edge_descriptor connecting_edge; + boost::tie(connecting_edge, path_found) + = grow(); // find a path from source to sink + if (!path_found) + { + // we're finished, no more paths were found + break; + } + ++m_time; + augment(connecting_edge); // augment that path + adopt(); // rebuild search tree structure } - } else if(get(m_res_cap_map, from_source)){ - // there is no sink connect, so we can't augment this path, but to - // avoid adding m_source to the active nodes, we just activate this - // node and set the approciate things - set_tree(current_node, tColorTraits::black()); - set_edge_to_parent(current_node, from_source); - put(m_dist_map, current_node, 1); - put(m_time_map, current_node, 1); - add_active_node(current_node); - } - } - for(boost::tie(ei, e_end) = out_edges(m_sink, m_g); ei != e_end; ++ei){ - edge_descriptor to_sink = get(m_rev_edge_map, *ei); - vertex_descriptor current_node = source(to_sink, m_g); - if(get(m_res_cap_map, to_sink)){ - set_tree(current_node, tColorTraits::white()); - set_edge_to_parent(current_node, to_sink); - put(m_dist_map, current_node, 1); - put(m_time_map, current_node, 1); - add_active_node(current_node); - } + return m_flow; } - } - - /** - * Returns a pair of an edge and a boolean. if the bool is true, the - * edge is a connection of a found path from s->t , read "the link" and - * source(returnVal, m_g) is the end of the path found in the source-tree - * target(returnVal, m_g) is the beginning of the path found in the sink-tree - */ - std::pair<edge_descriptor, bool> grow(){ - BOOST_ASSERT(m_orphans.empty()); - vertex_descriptor current_node; - while((current_node = get_next_active_node()) != graph_traits<Graph>::null_vertex()){ //if there is one - BOOST_ASSERT(get_tree(current_node) != tColorTraits::gray() && - (has_parent(current_node) || - current_node == m_source || - current_node == m_sink)); - - if(get_tree(current_node) == tColorTraits::black()){ - //source tree growing + + // the complete class is protected, as we want access to members in + // derived test-class (see test/boykov_kolmogorov_max_flow_test.cpp) + protected: + void augment_direct_paths() + { + // in a first step, we augment all direct paths from + // source->NODE->sink and additionally paths from source->sink. This + // improves especially graphcuts for segmentation, as most of the + // nodes have source/sink connects but shouldn't have an impact on + // other maxflow problems (this is done in grow() anyway) out_edge_iterator ei, e_end; - if(current_node != m_last_grow_vertex){ - m_last_grow_vertex = current_node; - boost::tie(m_last_grow_edge_it, m_last_grow_edge_end) = out_edges(current_node, m_g); - } - for(; m_last_grow_edge_it != m_last_grow_edge_end; ++m_last_grow_edge_it) { - edge_descriptor out_edge = *m_last_grow_edge_it; - if(get(m_res_cap_map, out_edge) > 0){ //check if we have capacity left on this edge - vertex_descriptor other_node = target(out_edge, m_g); - if(get_tree(other_node) == tColorTraits::gray()){ //it's a free node - set_tree(other_node, tColorTraits::black()); //aquire other node to our search tree - set_edge_to_parent(other_node, out_edge); //set us as parent - put(m_dist_map, other_node, get(m_dist_map, current_node) + 1); //and update the distance-heuristic - put(m_time_map, other_node, get(m_time_map, current_node)); - add_active_node(other_node); - } else if(get_tree(other_node) == tColorTraits::black()) { - // we do this to get shorter paths. check if we are nearer to - // the source as its parent is - if(is_closer_to_terminal(current_node, other_node)){ - set_edge_to_parent(other_node, out_edge); - put(m_dist_map, other_node, get(m_dist_map, current_node) + 1); - put(m_time_map, other_node, get(m_time_map, current_node)); - } - } else{ - BOOST_ASSERT(get_tree(other_node)==tColorTraits::white()); - //kewl, found a path from one to the other search tree, return - // the connecting edge in src->sink dir - return std::make_pair(out_edge, true); + for (boost::tie(ei, e_end) = out_edges(m_source, m_g); ei != e_end; + ++ei) + { + edge_descriptor from_source = *ei; + vertex_descriptor current_node = target(from_source, m_g); + if (current_node == m_sink) + { + tEdgeVal cap = get(m_res_cap_map, from_source); + put(m_res_cap_map, from_source, 0); + m_flow += cap; + continue; + } + edge_descriptor to_sink; + bool is_there; + boost::tie(to_sink, is_there) + = lookup_edge(current_node, m_sink, m_g); + if (is_there) + { + tEdgeVal cap_from_source = get(m_res_cap_map, from_source); + tEdgeVal cap_to_sink = get(m_res_cap_map, to_sink); + if (cap_from_source > cap_to_sink) + { + set_tree(current_node, tColorTraits::black()); + add_active_node(current_node); + set_edge_to_parent(current_node, from_source); + put(m_dist_map, current_node, 1); + put(m_time_map, current_node, 1); + // add stuff to flow and update residuals. we dont need + // to update reverse_edges, as incoming/outgoing edges + // to/from source/sink don't count for max-flow + put(m_res_cap_map, from_source, + get(m_res_cap_map, from_source) - cap_to_sink); + put(m_res_cap_map, to_sink, 0); + m_flow += cap_to_sink; + } + else if (cap_to_sink > 0) + { + set_tree(current_node, tColorTraits::white()); + add_active_node(current_node); + set_edge_to_parent(current_node, to_sink); + put(m_dist_map, current_node, 1); + put(m_time_map, current_node, 1); + // add stuff to flow and update residuals. we dont need + // to update reverse_edges, as incoming/outgoing edges + // to/from source/sink don't count for max-flow + put(m_res_cap_map, to_sink, + get(m_res_cap_map, to_sink) - cap_from_source); + put(m_res_cap_map, from_source, 0); + m_flow += cap_from_source; + } + } + else if (get(m_res_cap_map, from_source)) + { + // there is no sink connect, so we can't augment this path, + // but to avoid adding m_source to the active nodes, we just + // activate this node and set the approciate things + set_tree(current_node, tColorTraits::black()); + set_edge_to_parent(current_node, from_source); + put(m_dist_map, current_node, 1); + put(m_time_map, current_node, 1); + add_active_node(current_node); } - } - } //for all out-edges - } //source-tree-growing - else{ - BOOST_ASSERT(get_tree(current_node) == tColorTraits::white()); - out_edge_iterator ei, e_end; - if(current_node != m_last_grow_vertex){ - m_last_grow_vertex = current_node; - boost::tie(m_last_grow_edge_it, m_last_grow_edge_end) = out_edges(current_node, m_g); } - for(; m_last_grow_edge_it != m_last_grow_edge_end; ++m_last_grow_edge_it){ - edge_descriptor in_edge = get(m_rev_edge_map, *m_last_grow_edge_it); - if(get(m_res_cap_map, in_edge) > 0){ //check if there is capacity left - vertex_descriptor other_node = source(in_edge, m_g); - if(get_tree(other_node) == tColorTraits::gray()){ //it's a free node - set_tree(other_node, tColorTraits::white()); //aquire that node to our search tree - set_edge_to_parent(other_node, in_edge); //set us as parent - add_active_node(other_node); //activate that node - put(m_dist_map, other_node, get(m_dist_map, current_node) + 1); //set its distance - put(m_time_map, other_node, get(m_time_map, current_node));//and time - } else if(get_tree(other_node) == tColorTraits::white()){ - if(is_closer_to_terminal(current_node, other_node)){ - //we are closer to the sink than its parent is, so we "adopt" him - set_edge_to_parent(other_node, in_edge); - put(m_dist_map, other_node, get(m_dist_map, current_node) + 1); - put(m_time_map, other_node, get(m_time_map, current_node)); - } - } else{ - BOOST_ASSERT(get_tree(other_node)==tColorTraits::black()); - //kewl, found a path from one to the other search tree, - // return the connecting edge in src->sink dir - return std::make_pair(in_edge, true); + for (boost::tie(ei, e_end) = out_edges(m_sink, m_g); ei != e_end; + ++ei) + { + edge_descriptor to_sink = get(m_rev_edge_map, *ei); + vertex_descriptor current_node = source(to_sink, m_g); + if (get(m_res_cap_map, to_sink)) + { + set_tree(current_node, tColorTraits::white()); + set_edge_to_parent(current_node, to_sink); + put(m_dist_map, current_node, 1); + put(m_time_map, current_node, 1); + add_active_node(current_node); } - } - } //for all out-edges - } //sink-tree growing - - //all edges of that node are processed, and no more paths were found. - // remove if from the front of the active queue - finish_node(current_node); - } //while active_nodes not empty - - //no active nodes anymore and no path found, we're done - return std::make_pair(edge_descriptor(), false); - } - - /** - * augments path from s->t and updates residual graph - * source(e, m_g) is the end of the path found in the source-tree - * target(e, m_g) is the beginning of the path found in the sink-tree - * this phase generates orphans on satured edges, if the attached verts are - * from different search-trees orphans are ordered in distance to - * sink/source. first the farest from the source are front_inserted into - * the orphans list, and after that the sink-tree-orphans are - * front_inserted. when going to adoption stage the orphans are popped_front, - * and so we process the nearest verts to the terminals first - */ - void augment(edge_descriptor e) { - BOOST_ASSERT(get_tree(target(e, m_g)) == tColorTraits::white()); - BOOST_ASSERT(get_tree(source(e, m_g)) == tColorTraits::black()); - BOOST_ASSERT(m_orphans.empty()); - - const tEdgeVal bottleneck = find_bottleneck(e); - //now we push the found flow through the path - //for each edge we saturate we have to look for the verts that belong to that edge, one of them becomes an orphans - //now process the connecting edge - put(m_res_cap_map, e, get(m_res_cap_map, e) - bottleneck); - BOOST_ASSERT(get(m_res_cap_map, e) >= 0); - put(m_res_cap_map, get(m_rev_edge_map, e), get(m_res_cap_map, get(m_rev_edge_map, e)) + bottleneck); - - //now we follow the path back to the source - vertex_descriptor current_node = source(e, m_g); - while(current_node != m_source){ - edge_descriptor pred = get_edge_to_parent(current_node); - put(m_res_cap_map, pred, get(m_res_cap_map, pred) - bottleneck); - BOOST_ASSERT(get(m_res_cap_map, pred) >= 0); - put(m_res_cap_map, get(m_rev_edge_map, pred), get(m_res_cap_map, get(m_rev_edge_map, pred)) + bottleneck); - if(get(m_res_cap_map, pred) == 0){ - set_no_parent(current_node); - m_orphans.push_front(current_node); - } - current_node = source(pred, m_g); + } } - //then go forward in the sink-tree - current_node = target(e, m_g); - while(current_node != m_sink){ - edge_descriptor pred = get_edge_to_parent(current_node); - put(m_res_cap_map, pred, get(m_res_cap_map, pred) - bottleneck); - BOOST_ASSERT(get(m_res_cap_map, pred) >= 0); - put(m_res_cap_map, get(m_rev_edge_map, pred), get(m_res_cap_map, get(m_rev_edge_map, pred)) + bottleneck); - if(get(m_res_cap_map, pred) == 0){ - set_no_parent(current_node); - m_orphans.push_front(current_node); - } - current_node = target(pred, m_g); + + /** + * Returns a pair of an edge and a boolean. if the bool is true, the + * edge is a connection of a found path from s->t , read "the link" and + * source(returnVal, m_g) is the end of the path found in the + * source-tree target(returnVal, m_g) is the beginning of the path found + * in the sink-tree + */ + std::pair< edge_descriptor, bool > grow() + { + BOOST_ASSERT(m_orphans.empty()); + vertex_descriptor current_node; + while ((current_node = get_next_active_node()) + != graph_traits< Graph >::null_vertex()) + { // if there is one + BOOST_ASSERT(get_tree(current_node) != tColorTraits::gray() + && (has_parent(current_node) || current_node == m_source + || current_node == m_sink)); + + if (get_tree(current_node) == tColorTraits::black()) + { + // source tree growing + out_edge_iterator ei, e_end; + if (current_node != m_last_grow_vertex) + { + m_last_grow_vertex = current_node; + boost::tie(m_last_grow_edge_it, m_last_grow_edge_end) + = out_edges(current_node, m_g); + } + for (; m_last_grow_edge_it != m_last_grow_edge_end; + ++m_last_grow_edge_it) + { + edge_descriptor out_edge = *m_last_grow_edge_it; + if (get(m_res_cap_map, out_edge) > 0) + { // check if we have capacity left on this edge + vertex_descriptor other_node + = target(out_edge, m_g); + if (get_tree(other_node) == tColorTraits::gray()) + { // it's a free node + set_tree(other_node, + tColorTraits::black()); // aquire other node + // to our search + // tree + set_edge_to_parent( + other_node, out_edge); // set us as parent + put(m_dist_map, other_node, + get(m_dist_map, current_node) + + 1); // and update the + // distance-heuristic + put(m_time_map, other_node, + get(m_time_map, current_node)); + add_active_node(other_node); + } + else if (get_tree(other_node) + == tColorTraits::black()) + { + // we do this to get shorter paths. check if we + // are nearer to the source as its parent is + if (is_closer_to_terminal( + current_node, other_node)) + { + set_edge_to_parent(other_node, out_edge); + put(m_dist_map, other_node, + get(m_dist_map, current_node) + 1); + put(m_time_map, other_node, + get(m_time_map, current_node)); + } + } + else + { + BOOST_ASSERT(get_tree(other_node) + == tColorTraits::white()); + // kewl, found a path from one to the other + // search tree, return + // the connecting edge in src->sink dir + return std::make_pair(out_edge, true); + } + } + } // for all out-edges + } // source-tree-growing + else + { + BOOST_ASSERT( + get_tree(current_node) == tColorTraits::white()); + out_edge_iterator ei, e_end; + if (current_node != m_last_grow_vertex) + { + m_last_grow_vertex = current_node; + boost::tie(m_last_grow_edge_it, m_last_grow_edge_end) + = out_edges(current_node, m_g); + } + for (; m_last_grow_edge_it != m_last_grow_edge_end; + ++m_last_grow_edge_it) + { + edge_descriptor in_edge + = get(m_rev_edge_map, *m_last_grow_edge_it); + if (get(m_res_cap_map, in_edge) > 0) + { // check if there is capacity left + vertex_descriptor other_node = source(in_edge, m_g); + if (get_tree(other_node) == tColorTraits::gray()) + { // it's a free node + set_tree(other_node, + tColorTraits::white()); // aquire that node + // to our search + // tree + set_edge_to_parent( + other_node, in_edge); // set us as parent + add_active_node( + other_node); // activate that node + put(m_dist_map, other_node, + get(m_dist_map, current_node) + + 1); // set its distance + put(m_time_map, other_node, + get(m_time_map, current_node)); // and time + } + else if (get_tree(other_node) + == tColorTraits::white()) + { + if (is_closer_to_terminal( + current_node, other_node)) + { + // we are closer to the sink than its parent + // is, so we "adopt" him + set_edge_to_parent(other_node, in_edge); + put(m_dist_map, other_node, + get(m_dist_map, current_node) + 1); + put(m_time_map, other_node, + get(m_time_map, current_node)); + } + } + else + { + BOOST_ASSERT(get_tree(other_node) + == tColorTraits::black()); + // kewl, found a path from one to the other + // search tree, + // return the connecting edge in src->sink dir + return std::make_pair(in_edge, true); + } + } + } // for all out-edges + } // sink-tree growing + + // all edges of that node are processed, and no more paths were + // found. + // remove if from the front of the active queue + finish_node(current_node); + } // while active_nodes not empty + + // no active nodes anymore and no path found, we're done + return std::make_pair(edge_descriptor(), false); } - //and add it to the max-flow - m_flow += bottleneck; - } - - /** - * returns the bottleneck of a s->t path (end_of_path is last vertex in - * source-tree, begin_of_path is first vertex in sink-tree) - */ - inline tEdgeVal find_bottleneck(edge_descriptor e){ - BOOST_USING_STD_MIN(); - tEdgeVal minimum_cap = get(m_res_cap_map, e); - vertex_descriptor current_node = source(e, m_g); - //first go back in the source tree - while(current_node != m_source){ - edge_descriptor pred = get_edge_to_parent(current_node); - minimum_cap = min BOOST_PREVENT_MACRO_SUBSTITUTION(minimum_cap, get(m_res_cap_map, pred)); - current_node = source(pred, m_g); + + /** + * augments path from s->t and updates residual graph + * source(e, m_g) is the end of the path found in the source-tree + * target(e, m_g) is the beginning of the path found in the sink-tree + * this phase generates orphans on satured edges, if the attached verts + * are from different search-trees orphans are ordered in distance to + * sink/source. first the farest from the source are front_inserted into + * the orphans list, and after that the sink-tree-orphans are + * front_inserted. when going to adoption stage the orphans are + * popped_front, and so we process the nearest verts to the terminals + * first + */ + void augment(edge_descriptor e) + { + BOOST_ASSERT(get_tree(target(e, m_g)) == tColorTraits::white()); + BOOST_ASSERT(get_tree(source(e, m_g)) == tColorTraits::black()); + BOOST_ASSERT(m_orphans.empty()); + + const tEdgeVal bottleneck = find_bottleneck(e); + // now we push the found flow through the path + // for each edge we saturate we have to look for the verts that + // belong to that edge, one of them becomes an orphans now process + // the connecting edge + put(m_res_cap_map, e, get(m_res_cap_map, e) - bottleneck); + BOOST_ASSERT(get(m_res_cap_map, e) >= 0); + put(m_res_cap_map, get(m_rev_edge_map, e), + get(m_res_cap_map, get(m_rev_edge_map, e)) + bottleneck); + + // now we follow the path back to the source + vertex_descriptor current_node = source(e, m_g); + while (current_node != m_source) + { + edge_descriptor pred = get_edge_to_parent(current_node); + put(m_res_cap_map, pred, get(m_res_cap_map, pred) - bottleneck); + BOOST_ASSERT(get(m_res_cap_map, pred) >= 0); + put(m_res_cap_map, get(m_rev_edge_map, pred), + get(m_res_cap_map, get(m_rev_edge_map, pred)) + bottleneck); + if (get(m_res_cap_map, pred) == 0) + { + set_no_parent(current_node); + m_orphans.push_front(current_node); + } + current_node = source(pred, m_g); + } + // then go forward in the sink-tree + current_node = target(e, m_g); + while (current_node != m_sink) + { + edge_descriptor pred = get_edge_to_parent(current_node); + put(m_res_cap_map, pred, get(m_res_cap_map, pred) - bottleneck); + BOOST_ASSERT(get(m_res_cap_map, pred) >= 0); + put(m_res_cap_map, get(m_rev_edge_map, pred), + get(m_res_cap_map, get(m_rev_edge_map, pred)) + bottleneck); + if (get(m_res_cap_map, pred) == 0) + { + set_no_parent(current_node); + m_orphans.push_front(current_node); + } + current_node = target(pred, m_g); + } + // and add it to the max-flow + m_flow += bottleneck; } - //then go forward in the sink-tree - current_node = target(e, m_g); - while(current_node != m_sink){ - edge_descriptor pred = get_edge_to_parent(current_node); - minimum_cap = min BOOST_PREVENT_MACRO_SUBSTITUTION(minimum_cap, get(m_res_cap_map, pred)); - current_node = target(pred, m_g); + + /** + * returns the bottleneck of a s->t path (end_of_path is last vertex in + * source-tree, begin_of_path is first vertex in sink-tree) + */ + inline tEdgeVal find_bottleneck(edge_descriptor e) + { + BOOST_USING_STD_MIN(); + tEdgeVal minimum_cap = get(m_res_cap_map, e); + vertex_descriptor current_node = source(e, m_g); + // first go back in the source tree + while (current_node != m_source) + { + edge_descriptor pred = get_edge_to_parent(current_node); + minimum_cap = min BOOST_PREVENT_MACRO_SUBSTITUTION( + minimum_cap, get(m_res_cap_map, pred)); + current_node = source(pred, m_g); + } + // then go forward in the sink-tree + current_node = target(e, m_g); + while (current_node != m_sink) + { + edge_descriptor pred = get_edge_to_parent(current_node); + minimum_cap = min BOOST_PREVENT_MACRO_SUBSTITUTION( + minimum_cap, get(m_res_cap_map, pred)); + current_node = target(pred, m_g); + } + return minimum_cap; } - return minimum_cap; - } - - /** - * rebuild search trees - * empty the queue of orphans, and find new parents for them or just drop - * them from the search trees - */ - void adopt(){ - while(!m_orphans.empty() || !m_child_orphans.empty()){ - vertex_descriptor current_node; - if(m_child_orphans.empty()){ - //get the next orphan from the main-queue and remove it - current_node = m_orphans.front(); - m_orphans.pop_front(); - } else{ - current_node = m_child_orphans.front(); - m_child_orphans.pop(); - } - if(get_tree(current_node) == tColorTraits::black()){ - //we're in the source-tree - tDistanceVal min_distance = (std::numeric_limits<tDistanceVal>::max)(); - edge_descriptor new_parent_edge; - out_edge_iterator ei, e_end; - for(boost::tie(ei, e_end) = out_edges(current_node, m_g); ei != e_end; ++ei){ - const edge_descriptor in_edge = get(m_rev_edge_map, *ei); - BOOST_ASSERT(target(in_edge, m_g) == current_node); //we should be the target of this edge - if(get(m_res_cap_map, in_edge) > 0){ - vertex_descriptor other_node = source(in_edge, m_g); - if(get_tree(other_node) == tColorTraits::black() && has_source_connect(other_node)){ - if(get(m_dist_map, other_node) < min_distance){ - min_distance = get(m_dist_map, other_node); - new_parent_edge = in_edge; - } + + /** + * rebuild search trees + * empty the queue of orphans, and find new parents for them or just + * drop them from the search trees + */ + void adopt() + { + while (!m_orphans.empty() || !m_child_orphans.empty()) + { + vertex_descriptor current_node; + if (m_child_orphans.empty()) + { + // get the next orphan from the main-queue and remove it + current_node = m_orphans.front(); + m_orphans.pop_front(); } - } - } - if(min_distance != (std::numeric_limits<tDistanceVal>::max)()){ - set_edge_to_parent(current_node, new_parent_edge); - put(m_dist_map, current_node, min_distance + 1); - put(m_time_map, current_node, m_time); - } else{ - put(m_time_map, current_node, 0); - for(boost::tie(ei, e_end) = out_edges(current_node, m_g); ei != e_end; ++ei){ - edge_descriptor in_edge = get(m_rev_edge_map, *ei); - vertex_descriptor other_node = source(in_edge, m_g); - if(get_tree(other_node) == tColorTraits::black() && other_node != m_source){ - if(get(m_res_cap_map, in_edge) > 0){ - add_active_node(other_node); - } - if(has_parent(other_node) && source(get_edge_to_parent(other_node), m_g) == current_node){ - //we are the parent of that node - //it has to find a new parent, too - set_no_parent(other_node); - m_child_orphans.push(other_node); - } + else + { + current_node = m_child_orphans.front(); + m_child_orphans.pop(); + } + if (get_tree(current_node) == tColorTraits::black()) + { + // we're in the source-tree + tDistanceVal min_distance + = (std::numeric_limits< tDistanceVal >::max)(); + edge_descriptor new_parent_edge; + out_edge_iterator ei, e_end; + for (boost::tie(ei, e_end) = out_edges(current_node, m_g); + ei != e_end; ++ei) + { + const edge_descriptor in_edge + = get(m_rev_edge_map, *ei); + BOOST_ASSERT(target(in_edge, m_g) + == current_node); // we should be the target of this + // edge + if (get(m_res_cap_map, in_edge) > 0) + { + vertex_descriptor other_node = source(in_edge, m_g); + if (get_tree(other_node) == tColorTraits::black() + && has_source_connect(other_node)) + { + if (get(m_dist_map, other_node) < min_distance) + { + min_distance = get(m_dist_map, other_node); + new_parent_edge = in_edge; + } + } + } + } + if (min_distance + != (std::numeric_limits< tDistanceVal >::max)()) + { + set_edge_to_parent(current_node, new_parent_edge); + put(m_dist_map, current_node, min_distance + 1); + put(m_time_map, current_node, m_time); + } + else + { + put(m_time_map, current_node, 0); + for (boost::tie(ei, e_end) + = out_edges(current_node, m_g); + ei != e_end; ++ei) + { + edge_descriptor in_edge = get(m_rev_edge_map, *ei); + vertex_descriptor other_node = source(in_edge, m_g); + if (get_tree(other_node) == tColorTraits::black() + && other_node != m_source) + { + if (get(m_res_cap_map, in_edge) > 0) + { + add_active_node(other_node); + } + if (has_parent(other_node) + && source( + get_edge_to_parent(other_node), m_g) + == current_node) + { + // we are the parent of that node + // it has to find a new parent, too + set_no_parent(other_node); + m_child_orphans.push(other_node); + } + } + } + set_tree(current_node, tColorTraits::gray()); + } // no parent found + } // source-tree-adoption + else + { + // now we should be in the sink-tree, check that... + BOOST_ASSERT( + get_tree(current_node) == tColorTraits::white()); + out_edge_iterator ei, e_end; + edge_descriptor new_parent_edge; + tDistanceVal min_distance + = (std::numeric_limits< tDistanceVal >::max)(); + for (boost::tie(ei, e_end) = out_edges(current_node, m_g); + ei != e_end; ++ei) + { + const edge_descriptor out_edge = *ei; + if (get(m_res_cap_map, out_edge) > 0) + { + const vertex_descriptor other_node + = target(out_edge, m_g); + if (get_tree(other_node) == tColorTraits::white() + && has_sink_connect(other_node)) + if (get(m_dist_map, other_node) < min_distance) + { + min_distance = get(m_dist_map, other_node); + new_parent_edge = out_edge; + } + } + } + if (min_distance + != (std::numeric_limits< tDistanceVal >::max)()) + { + set_edge_to_parent(current_node, new_parent_edge); + put(m_dist_map, current_node, min_distance + 1); + put(m_time_map, current_node, m_time); + } + else + { + put(m_time_map, current_node, 0); + for (boost::tie(ei, e_end) + = out_edges(current_node, m_g); + ei != e_end; ++ei) + { + const edge_descriptor out_edge = *ei; + const vertex_descriptor other_node + = target(out_edge, m_g); + if (get_tree(other_node) == tColorTraits::white() + && other_node != m_sink) + { + if (get(m_res_cap_map, out_edge) > 0) + { + add_active_node(other_node); + } + if (has_parent(other_node) + && target( + get_edge_to_parent(other_node), m_g) + == current_node) + { + // we were it's parent, so it has to find a + // new one, too + set_no_parent(other_node); + m_child_orphans.push(other_node); + } + } + } + set_tree(current_node, tColorTraits::gray()); + } // no parent found + } // sink-tree adoption + } // while !orphans.empty() + } // adopt + + /** + * return next active vertex if there is one, otherwise a null_vertex + */ + inline vertex_descriptor get_next_active_node() + { + while (true) + { + if (m_active_nodes.empty()) + return graph_traits< Graph >::null_vertex(); + vertex_descriptor v = m_active_nodes.front(); + + // if it has no parent, this node can't be active (if its not + // source or sink) + if (!has_parent(v) && v != m_source && v != m_sink) + { + m_active_nodes.pop(); + put(m_in_active_list_map, v, false); + } + else + { + BOOST_ASSERT(get_tree(v) == tColorTraits::black() + || get_tree(v) == tColorTraits::white()); + return v; } - } - set_tree(current_node, tColorTraits::gray()); - } //no parent found - } //source-tree-adoption - else{ - //now we should be in the sink-tree, check that... - BOOST_ASSERT(get_tree(current_node) == tColorTraits::white()); - out_edge_iterator ei, e_end; - edge_descriptor new_parent_edge; - tDistanceVal min_distance = (std::numeric_limits<tDistanceVal>::max)(); - for(boost::tie(ei, e_end) = out_edges(current_node, m_g); ei != e_end; ++ei){ - const edge_descriptor out_edge = *ei; - if(get(m_res_cap_map, out_edge) > 0){ - const vertex_descriptor other_node = target(out_edge, m_g); - if(get_tree(other_node) == tColorTraits::white() && has_sink_connect(other_node)) - if(get(m_dist_map, other_node) < min_distance){ - min_distance = get(m_dist_map, other_node); - new_parent_edge = out_edge; - } - } } - if(min_distance != (std::numeric_limits<tDistanceVal>::max)()){ - set_edge_to_parent(current_node, new_parent_edge); - put(m_dist_map, current_node, min_distance + 1); - put(m_time_map, current_node, m_time); - } else{ - put(m_time_map, current_node, 0); - for(boost::tie(ei, e_end) = out_edges(current_node, m_g); ei != e_end; ++ei){ - const edge_descriptor out_edge = *ei; - const vertex_descriptor other_node = target(out_edge, m_g); - if(get_tree(other_node) == tColorTraits::white() && other_node != m_sink){ - if(get(m_res_cap_map, out_edge) > 0){ - add_active_node(other_node); - } - if(has_parent(other_node) && target(get_edge_to_parent(other_node), m_g) == current_node){ - //we were it's parent, so it has to find a new one, too - set_no_parent(other_node); - m_child_orphans.push(other_node); - } + } + + /** + * adds v as an active vertex, but only if its not in the list already + */ + inline void add_active_node(vertex_descriptor v) + { + BOOST_ASSERT(get_tree(v) != tColorTraits::gray()); + if (get(m_in_active_list_map, v)) + { + if (m_last_grow_vertex == v) + { + m_last_grow_vertex = graph_traits< Graph >::null_vertex(); } - } - set_tree(current_node, tColorTraits::gray()); - } //no parent found - } //sink-tree adoption - } //while !orphans.empty() - } //adopt - - /** - * return next active vertex if there is one, otherwise a null_vertex - */ - inline vertex_descriptor get_next_active_node(){ - while(true){ - if(m_active_nodes.empty()) - return graph_traits<Graph>::null_vertex(); - vertex_descriptor v = m_active_nodes.front(); - - //if it has no parent, this node can't be active (if its not source or sink) - if(!has_parent(v) && v != m_source && v != m_sink){ + return; + } + else + { + put(m_in_active_list_map, v, true); + m_active_nodes.push(v); + } + } + + /** + * finish_node removes a node from the front of the active queue (its + * called in grow phase, if no more paths can be found using this node) + */ + inline void finish_node(vertex_descriptor v) + { + BOOST_ASSERT(m_active_nodes.front() == v); m_active_nodes.pop(); put(m_in_active_list_map, v, false); - } else{ - BOOST_ASSERT(get_tree(v) == tColorTraits::black() || get_tree(v) == tColorTraits::white()); - return v; - } + m_last_grow_vertex = graph_traits< Graph >::null_vertex(); + } + + /** + * removes a vertex from the queue of active nodes (actually this does + * nothing, but checks if this node has no parent edge, as this is the + * criteria for being no more active) + */ + inline void remove_active_node(vertex_descriptor v) + { + BOOST_ASSERT(!has_parent(v)); } - } - - /** - * adds v as an active vertex, but only if its not in the list already - */ - inline void add_active_node(vertex_descriptor v){ - BOOST_ASSERT(get_tree(v) != tColorTraits::gray()); - if(get(m_in_active_list_map, v)){ - if (m_last_grow_vertex == v) { - m_last_grow_vertex = graph_traits<Graph>::null_vertex(); - } - return; - } else{ - put(m_in_active_list_map, v, true); - m_active_nodes.push(v); + + /** + * returns the search tree of v; tColorValue::black() for source tree, + * white() for sink tree, gray() for no tree + */ + inline tColorValue get_tree(vertex_descriptor v) const + { + return get(m_tree_map, v); } - } - - /** - * finish_node removes a node from the front of the active queue (its called in grow phase, if no more paths can be found using this node) - */ - inline void finish_node(vertex_descriptor v){ - BOOST_ASSERT(m_active_nodes.front() == v); - m_active_nodes.pop(); - put(m_in_active_list_map, v, false); - m_last_grow_vertex = graph_traits<Graph>::null_vertex(); - } - - /** - * removes a vertex from the queue of active nodes (actually this does nothing, - * but checks if this node has no parent edge, as this is the criteria for - * being no more active) - */ - inline void remove_active_node(vertex_descriptor v){ - BOOST_ASSERT(!has_parent(v)); - } - - /** - * returns the search tree of v; tColorValue::black() for source tree, - * white() for sink tree, gray() for no tree - */ - inline tColorValue get_tree(vertex_descriptor v) const { - return get(m_tree_map, v); - } - - /** - * sets search tree of v; tColorValue::black() for source tree, white() - * for sink tree, gray() for no tree - */ - inline void set_tree(vertex_descriptor v, tColorValue t){ - put(m_tree_map, v, t); - } - - /** - * returns edge to parent vertex of v; - */ - inline edge_descriptor get_edge_to_parent(vertex_descriptor v) const{ - return get(m_pre_map, v); - } - - /** - * returns true if the edge stored in m_pre_map[v] is a valid entry - */ - inline bool has_parent(vertex_descriptor v) const{ - return get(m_has_parent_map, v); - } - - /** - * sets edge to parent vertex of v; - */ - inline void set_edge_to_parent(vertex_descriptor v, edge_descriptor f_edge_to_parent){ - BOOST_ASSERT(get(m_res_cap_map, f_edge_to_parent) > 0); - put(m_pre_map, v, f_edge_to_parent); - put(m_has_parent_map, v, true); - } - - /** - * removes the edge to parent of v (this is done by invalidating the - * entry an additional map) - */ - inline void set_no_parent(vertex_descriptor v){ - put(m_has_parent_map, v, false); - } - - /** - * checks if vertex v has a connect to the sink-vertex (@var m_sink) - * @param v the vertex which is checked - * @return true if a path to the sink was found, false if not - */ - inline bool has_sink_connect(vertex_descriptor v){ - tDistanceVal current_distance = 0; - vertex_descriptor current_vertex = v; - while(true){ - if(get(m_time_map, current_vertex) == m_time){ - //we found a node which was already checked this round. use it for distance calculations - current_distance += get(m_dist_map, current_vertex); - break; - } - if(current_vertex == m_sink){ - put(m_time_map, m_sink, m_time); - break; - } - if(has_parent(current_vertex)){ - //it has a parent, so get it - current_vertex = target(get_edge_to_parent(current_vertex), m_g); - ++current_distance; - } else{ - //no path found - return false; - } + + /** + * sets search tree of v; tColorValue::black() for source tree, white() + * for sink tree, gray() for no tree + */ + inline void set_tree(vertex_descriptor v, tColorValue t) + { + put(m_tree_map, v, t); } - current_vertex=v; - while(get(m_time_map, current_vertex) != m_time){ - put(m_dist_map, current_vertex, current_distance); - --current_distance; - put(m_time_map, current_vertex, m_time); - current_vertex = target(get_edge_to_parent(current_vertex), m_g); + + /** + * returns edge to parent vertex of v; + */ + inline edge_descriptor get_edge_to_parent(vertex_descriptor v) const + { + return get(m_pre_map, v); + } + + /** + * returns true if the edge stored in m_pre_map[v] is a valid entry + */ + inline bool has_parent(vertex_descriptor v) const + { + return get(m_has_parent_map, v); + } + + /** + * sets edge to parent vertex of v; + */ + inline void set_edge_to_parent( + vertex_descriptor v, edge_descriptor f_edge_to_parent) + { + BOOST_ASSERT(get(m_res_cap_map, f_edge_to_parent) > 0); + put(m_pre_map, v, f_edge_to_parent); + put(m_has_parent_map, v, true); } - return true; - } - - /** - * checks if vertex v has a connect to the source-vertex (@var m_source) - * @param v the vertex which is checked - * @return true if a path to the source was found, false if not - */ - inline bool has_source_connect(vertex_descriptor v){ - tDistanceVal current_distance = 0; - vertex_descriptor current_vertex = v; - while(true){ - if(get(m_time_map, current_vertex) == m_time){ - //we found a node which was already checked this round. use it for distance calculations - current_distance += get(m_dist_map, current_vertex); - break; - } - if(current_vertex == m_source){ - put(m_time_map, m_source, m_time); - break; - } - if(has_parent(current_vertex)){ - //it has a parent, so get it - current_vertex = source(get_edge_to_parent(current_vertex), m_g); - ++current_distance; - } else{ - //no path found - return false; - } + + /** + * removes the edge to parent of v (this is done by invalidating the + * entry an additional map) + */ + inline void set_no_parent(vertex_descriptor v) + { + put(m_has_parent_map, v, false); } - current_vertex=v; - while(get(m_time_map, current_vertex) != m_time){ - put(m_dist_map, current_vertex, current_distance); - --current_distance; - put(m_time_map, current_vertex, m_time); - current_vertex = source(get_edge_to_parent(current_vertex), m_g); + + /** + * checks if vertex v has a connect to the sink-vertex (@var m_sink) + * @param v the vertex which is checked + * @return true if a path to the sink was found, false if not + */ + inline bool has_sink_connect(vertex_descriptor v) + { + tDistanceVal current_distance = 0; + vertex_descriptor current_vertex = v; + while (true) + { + if (get(m_time_map, current_vertex) == m_time) + { + // we found a node which was already checked this round. use + // it for distance calculations + current_distance += get(m_dist_map, current_vertex); + break; + } + if (current_vertex == m_sink) + { + put(m_time_map, m_sink, m_time); + break; + } + if (has_parent(current_vertex)) + { + // it has a parent, so get it + current_vertex + = target(get_edge_to_parent(current_vertex), m_g); + ++current_distance; + } + else + { + // no path found + return false; + } + } + current_vertex = v; + while (get(m_time_map, current_vertex) != m_time) + { + put(m_dist_map, current_vertex, current_distance); + --current_distance; + put(m_time_map, current_vertex, m_time); + current_vertex + = target(get_edge_to_parent(current_vertex), m_g); + } + return true; } - return true; - } - - /** - * returns true, if p is closer to a terminal than q - */ - inline bool is_closer_to_terminal(vertex_descriptor p, vertex_descriptor q){ - //checks the timestamps first, to build no cycles, and after that the real distance - return (get(m_time_map, q) <= get(m_time_map, p) && - get(m_dist_map, q) > get(m_dist_map, p)+1); - } - - //////// - // member vars - //////// - Graph& m_g; - IndexMap m_index_map; - EdgeCapacityMap m_cap_map; - ResidualCapacityEdgeMap m_res_cap_map; - ReverseEdgeMap m_rev_edge_map; - PredecessorMap m_pre_map; //stores paths found in the growth stage - ColorMap m_tree_map; //maps each vertex into one of the two search tree or none (gray()) - DistanceMap m_dist_map; //stores distance to source/sink nodes - vertex_descriptor m_source; - vertex_descriptor m_sink; - - tQueue m_active_nodes; - std::vector<bool> m_in_active_list_vec; - iterator_property_map<std::vector<bool>::iterator, IndexMap> m_in_active_list_map; - - std::list<vertex_descriptor> m_orphans; - tQueue m_child_orphans; // we use a second queuqe for child orphans, as they are FIFO processed - - std::vector<bool> m_has_parent_vec; - iterator_property_map<std::vector<bool>::iterator, IndexMap> m_has_parent_map; - - std::vector<long> m_time_vec; //timestamp of each node, used for sink/source-path calculations - iterator_property_map<std::vector<long>::iterator, IndexMap> m_time_map; - tEdgeVal m_flow; - long m_time; - vertex_descriptor m_last_grow_vertex; - out_edge_iterator m_last_grow_edge_it; - out_edge_iterator m_last_grow_edge_end; -}; - -} //namespace boost::detail + + /** + * checks if vertex v has a connect to the source-vertex (@var m_source) + * @param v the vertex which is checked + * @return true if a path to the source was found, false if not + */ + inline bool has_source_connect(vertex_descriptor v) + { + tDistanceVal current_distance = 0; + vertex_descriptor current_vertex = v; + while (true) + { + if (get(m_time_map, current_vertex) == m_time) + { + // we found a node which was already checked this round. use + // it for distance calculations + current_distance += get(m_dist_map, current_vertex); + break; + } + if (current_vertex == m_source) + { + put(m_time_map, m_source, m_time); + break; + } + if (has_parent(current_vertex)) + { + // it has a parent, so get it + current_vertex + = source(get_edge_to_parent(current_vertex), m_g); + ++current_distance; + } + else + { + // no path found + return false; + } + } + current_vertex = v; + while (get(m_time_map, current_vertex) != m_time) + { + put(m_dist_map, current_vertex, current_distance); + --current_distance; + put(m_time_map, current_vertex, m_time); + current_vertex + = source(get_edge_to_parent(current_vertex), m_g); + } + return true; + } + + /** + * returns true, if p is closer to a terminal than q + */ + inline bool is_closer_to_terminal( + vertex_descriptor p, vertex_descriptor q) + { + // checks the timestamps first, to build no cycles, and after that + // the real distance + return (get(m_time_map, q) <= get(m_time_map, p) + && get(m_dist_map, q) > get(m_dist_map, p) + 1); + } + + //////// + // member vars + //////// + Graph& m_g; + IndexMap m_index_map; + EdgeCapacityMap m_cap_map; + ResidualCapacityEdgeMap m_res_cap_map; + ReverseEdgeMap m_rev_edge_map; + PredecessorMap m_pre_map; // stores paths found in the growth stage + ColorMap m_tree_map; // maps each vertex into one of the two search tree + // or none (gray()) + DistanceMap m_dist_map; // stores distance to source/sink nodes + vertex_descriptor m_source; + vertex_descriptor m_sink; + + tQueue m_active_nodes; + std::vector< bool > m_in_active_list_vec; + iterator_property_map< std::vector< bool >::iterator, IndexMap > + m_in_active_list_map; + + std::list< vertex_descriptor > m_orphans; + tQueue m_child_orphans; // we use a second queuqe for child orphans, as + // they are FIFO processed + + std::vector< bool > m_has_parent_vec; + iterator_property_map< std::vector< bool >::iterator, IndexMap > + m_has_parent_map; + + std::vector< long > m_time_vec; // timestamp of each node, used for + // sink/source-path calculations + iterator_property_map< std::vector< long >::iterator, IndexMap > + m_time_map; + tEdgeVal m_flow; + long m_time; + vertex_descriptor m_last_grow_vertex; + out_edge_iterator m_last_grow_edge_it; + out_edge_iterator m_last_grow_edge_end; + }; + +} // namespace boost::detail /** - * non-named-parameter version, given everything - * this is the catch all version - */ -template<class Graph, - class CapacityEdgeMap, - class ResidualCapacityEdgeMap, - class ReverseEdgeMap, class PredecessorMap, - class ColorMap, - class DistanceMap, - class IndexMap> -typename property_traits<CapacityEdgeMap>::value_type -boykov_kolmogorov_max_flow(Graph& g, - CapacityEdgeMap cap, - ResidualCapacityEdgeMap res_cap, - ReverseEdgeMap rev_map, - PredecessorMap pre_map, - ColorMap color, - DistanceMap dist, - IndexMap idx, - typename graph_traits<Graph>::vertex_descriptor src, - typename graph_traits<Graph>::vertex_descriptor sink) + * non-named-parameter version, given everything + * this is the catch all version + */ +template < class Graph, class CapacityEdgeMap, class ResidualCapacityEdgeMap, + class ReverseEdgeMap, class PredecessorMap, class ColorMap, + class DistanceMap, class IndexMap > +typename property_traits< CapacityEdgeMap >::value_type +boykov_kolmogorov_max_flow(Graph& g, CapacityEdgeMap cap, + ResidualCapacityEdgeMap res_cap, ReverseEdgeMap rev_map, + PredecessorMap pre_map, ColorMap color, DistanceMap dist, IndexMap idx, + typename graph_traits< Graph >::vertex_descriptor src, + typename graph_traits< Graph >::vertex_descriptor sink) { - typedef typename graph_traits<Graph>::vertex_descriptor vertex_descriptor; - typedef typename graph_traits<Graph>::edge_descriptor edge_descriptor; - - //as this method is the last one before we instantiate the solver, we do the concept checks here - BOOST_CONCEPT_ASSERT(( VertexListGraphConcept<Graph> )); //to have vertices(), num_vertices(), - BOOST_CONCEPT_ASSERT(( EdgeListGraphConcept<Graph> )); //to have edges() - BOOST_CONCEPT_ASSERT(( IncidenceGraphConcept<Graph> )); //to have source(), target() and out_edges() - BOOST_CONCEPT_ASSERT(( ReadablePropertyMapConcept<CapacityEdgeMap, edge_descriptor> )); //read flow-values from edges - BOOST_CONCEPT_ASSERT(( ReadWritePropertyMapConcept<ResidualCapacityEdgeMap, edge_descriptor> )); //write flow-values to residuals - BOOST_CONCEPT_ASSERT(( ReadablePropertyMapConcept<ReverseEdgeMap, edge_descriptor> )); //read out reverse edges - BOOST_CONCEPT_ASSERT(( ReadWritePropertyMapConcept<PredecessorMap, vertex_descriptor> )); //store predecessor there - BOOST_CONCEPT_ASSERT(( ReadWritePropertyMapConcept<ColorMap, vertex_descriptor> )); //write corresponding tree - BOOST_CONCEPT_ASSERT(( ReadWritePropertyMapConcept<DistanceMap, vertex_descriptor> )); //write distance to source/sink - BOOST_CONCEPT_ASSERT(( ReadablePropertyMapConcept<IndexMap, vertex_descriptor> )); //get index 0...|V|-1 - BOOST_ASSERT(num_vertices(g) >= 2 && src != sink); - - detail::bk_max_flow< - Graph, CapacityEdgeMap, ResidualCapacityEdgeMap, ReverseEdgeMap, - PredecessorMap, ColorMap, DistanceMap, IndexMap - > algo(g, cap, res_cap, rev_map, pre_map, color, dist, idx, src, sink); - - return algo.max_flow(); + typedef typename graph_traits< Graph >::vertex_descriptor vertex_descriptor; + typedef typename graph_traits< Graph >::edge_descriptor edge_descriptor; + + // as this method is the last one before we instantiate the solver, we do + // the concept checks here + BOOST_CONCEPT_ASSERT( + (VertexListGraphConcept< Graph >)); // to have vertices(), + // num_vertices(), + BOOST_CONCEPT_ASSERT((EdgeListGraphConcept< Graph >)); // to have edges() + BOOST_CONCEPT_ASSERT( + (IncidenceGraphConcept< Graph >)); // to have source(), target() and + // out_edges() + BOOST_CONCEPT_ASSERT((ReadablePropertyMapConcept< CapacityEdgeMap, + edge_descriptor >)); // read flow-values from edges + BOOST_CONCEPT_ASSERT((ReadWritePropertyMapConcept< ResidualCapacityEdgeMap, + edge_descriptor >)); // write flow-values to residuals + BOOST_CONCEPT_ASSERT((ReadablePropertyMapConcept< ReverseEdgeMap, + edge_descriptor >)); // read out reverse edges + BOOST_CONCEPT_ASSERT((ReadWritePropertyMapConcept< PredecessorMap, + vertex_descriptor >)); // store predecessor there + BOOST_CONCEPT_ASSERT((ReadWritePropertyMapConcept< ColorMap, + vertex_descriptor >)); // write corresponding tree + BOOST_CONCEPT_ASSERT((ReadWritePropertyMapConcept< DistanceMap, + vertex_descriptor >)); // write distance to source/sink + BOOST_CONCEPT_ASSERT((ReadablePropertyMapConcept< IndexMap, + vertex_descriptor >)); // get index 0...|V|-1 + BOOST_ASSERT(num_vertices(g) >= 2 && src != sink); + + detail::bk_max_flow< Graph, CapacityEdgeMap, ResidualCapacityEdgeMap, + ReverseEdgeMap, PredecessorMap, ColorMap, DistanceMap, IndexMap > + algo(g, cap, res_cap, rev_map, pre_map, color, dist, idx, src, sink); + + return algo.max_flow(); } /** - * non-named-parameter version, given capacity, residucal_capacity, + * non-named-parameter version, given capacity, residual_capacity, * reverse_edges, and an index map. */ -template<class Graph, - class CapacityEdgeMap, - class ResidualCapacityEdgeMap, - class ReverseEdgeMap, - class IndexMap> -typename property_traits<CapacityEdgeMap>::value_type -boykov_kolmogorov_max_flow(Graph& g, - CapacityEdgeMap cap, - ResidualCapacityEdgeMap res_cap, - ReverseEdgeMap rev, - IndexMap idx, - typename graph_traits<Graph>::vertex_descriptor src, - typename graph_traits<Graph>::vertex_descriptor sink) +template < class Graph, class CapacityEdgeMap, class ResidualCapacityEdgeMap, + class ReverseEdgeMap, class IndexMap > +typename property_traits< CapacityEdgeMap >::value_type +boykov_kolmogorov_max_flow(Graph& g, CapacityEdgeMap cap, + ResidualCapacityEdgeMap res_cap, ReverseEdgeMap rev, IndexMap idx, + typename graph_traits< Graph >::vertex_descriptor src, + typename graph_traits< Graph >::vertex_descriptor sink) { - typename graph_traits<Graph>::vertices_size_type n_verts = num_vertices(g); - std::vector<typename graph_traits<Graph>::edge_descriptor> predecessor_vec(n_verts); - std::vector<default_color_type> color_vec(n_verts); - std::vector<typename graph_traits<Graph>::vertices_size_type> distance_vec(n_verts); - return - boykov_kolmogorov_max_flow( - g, cap, res_cap, rev, - make_iterator_property_map(predecessor_vec.begin(), idx), - make_iterator_property_map(color_vec.begin(), idx), - make_iterator_property_map(distance_vec.begin(), idx), - idx, src, sink); + typename graph_traits< Graph >::vertices_size_type n_verts + = num_vertices(g); + std::vector< typename graph_traits< Graph >::edge_descriptor > + predecessor_vec(n_verts); + std::vector< default_color_type > color_vec(n_verts); + std::vector< typename graph_traits< Graph >::vertices_size_type > + distance_vec(n_verts); + return boykov_kolmogorov_max_flow(g, cap, res_cap, rev, + make_iterator_property_map(predecessor_vec.begin(), idx), + make_iterator_property_map(color_vec.begin(), idx), + make_iterator_property_map(distance_vec.begin(), idx), idx, src, sink); } /** @@ -803,71 +1006,62 @@ boykov_kolmogorov_max_flow(Graph& g, * reverse_edges, color_map and an index map. Use this if you are interested in * the minimum cut, as the color map provides that info. */ -template<class Graph, - class CapacityEdgeMap, - class ResidualCapacityEdgeMap, - class ReverseEdgeMap, - class ColorMap, - class IndexMap> -typename property_traits<CapacityEdgeMap>::value_type -boykov_kolmogorov_max_flow(Graph& g, - CapacityEdgeMap cap, - ResidualCapacityEdgeMap res_cap, - ReverseEdgeMap rev, - ColorMap color, - IndexMap idx, - typename graph_traits<Graph>::vertex_descriptor src, - typename graph_traits<Graph>::vertex_descriptor sink) +template < class Graph, class CapacityEdgeMap, class ResidualCapacityEdgeMap, + class ReverseEdgeMap, class ColorMap, class IndexMap > +typename property_traits< CapacityEdgeMap >::value_type +boykov_kolmogorov_max_flow(Graph& g, CapacityEdgeMap cap, + ResidualCapacityEdgeMap res_cap, ReverseEdgeMap rev, ColorMap color, + IndexMap idx, typename graph_traits< Graph >::vertex_descriptor src, + typename graph_traits< Graph >::vertex_descriptor sink) { - typename graph_traits<Graph>::vertices_size_type n_verts = num_vertices(g); - std::vector<typename graph_traits<Graph>::edge_descriptor> predecessor_vec(n_verts); - std::vector<typename graph_traits<Graph>::vertices_size_type> distance_vec(n_verts); - return - boykov_kolmogorov_max_flow( - g, cap, res_cap, rev, - make_iterator_property_map(predecessor_vec.begin(), idx), - color, - make_iterator_property_map(distance_vec.begin(), idx), - idx, src, sink); + typename graph_traits< Graph >::vertices_size_type n_verts + = num_vertices(g); + std::vector< typename graph_traits< Graph >::edge_descriptor > + predecessor_vec(n_verts); + std::vector< typename graph_traits< Graph >::vertices_size_type > + distance_vec(n_verts); + return boykov_kolmogorov_max_flow(g, cap, res_cap, rev, + make_iterator_property_map(predecessor_vec.begin(), idx), color, + make_iterator_property_map(distance_vec.begin(), idx), idx, src, sink); } /** * named-parameter version, some given */ -template<class Graph, class P, class T, class R> -typename property_traits<typename property_map<Graph, edge_capacity_t>::const_type>::value_type +template < class Graph, class P, class T, class R > +typename detail::edge_capacity_value< Graph, P, T, R >::type boykov_kolmogorov_max_flow(Graph& g, - typename graph_traits<Graph>::vertex_descriptor src, - typename graph_traits<Graph>::vertex_descriptor sink, - const bgl_named_params<P, T, R>& params) + typename graph_traits< Graph >::vertex_descriptor src, + typename graph_traits< Graph >::vertex_descriptor sink, + const bgl_named_params< P, T, R >& params) { - return - boykov_kolmogorov_max_flow( - g, - choose_const_pmap(get_param(params, edge_capacity), g, edge_capacity), - choose_pmap(get_param(params, edge_residual_capacity), g, edge_residual_capacity), - choose_const_pmap(get_param(params, edge_reverse), g, edge_reverse), - choose_pmap(get_param(params, vertex_predecessor), g, vertex_predecessor), - choose_pmap(get_param(params, vertex_color), g, vertex_color), - choose_pmap(get_param(params, vertex_distance), g, vertex_distance), - choose_const_pmap(get_param(params, vertex_index), g, vertex_index), - src, sink); + return boykov_kolmogorov_max_flow(g, + choose_const_pmap(get_param(params, edge_capacity), g, edge_capacity), + choose_pmap(get_param(params, edge_residual_capacity), g, + edge_residual_capacity), + choose_const_pmap(get_param(params, edge_reverse), g, edge_reverse), + choose_pmap( + get_param(params, vertex_predecessor), g, vertex_predecessor), + choose_pmap(get_param(params, vertex_color), g, vertex_color), + choose_pmap(get_param(params, vertex_distance), g, vertex_distance), + choose_const_pmap(get_param(params, vertex_index), g, vertex_index), + src, sink); } /** * named-parameter version, none given */ -template<class Graph> -typename property_traits<typename property_map<Graph, edge_capacity_t>::const_type>::value_type +template < class Graph > +typename property_traits< + typename property_map< Graph, edge_capacity_t >::const_type >::value_type boykov_kolmogorov_max_flow(Graph& g, - typename graph_traits<Graph>::vertex_descriptor src, - typename graph_traits<Graph>::vertex_descriptor sink) + typename graph_traits< Graph >::vertex_descriptor src, + typename graph_traits< Graph >::vertex_descriptor sink) { - bgl_named_params<int, buffer_param_t> params(0); // bogus empty param - return boykov_kolmogorov_max_flow(g, src, sink, params); + bgl_named_params< int, buffer_param_t > params(0); // bogus empty param + return boykov_kolmogorov_max_flow(g, src, sink, params); } } // namespace boost #endif // BOOST_BOYKOV_KOLMOGOROV_MAX_FLOW_HPP - diff --git a/contrib/restricted/boost/graph/include/boost/graph/breadth_first_search.hpp b/contrib/restricted/boost/graph/include/boost/graph/breadth_first_search.hpp index fc111d81b4..0993d55d1d 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/breadth_first_search.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/breadth_first_search.hpp @@ -24,252 +24,254 @@ #include <boost/graph/overloading.hpp> #include <boost/graph/graph_concepts.hpp> #include <boost/graph/two_bit_color_map.hpp> +#include <boost/graph/detail/mpi_include.hpp> #include <boost/concept/assert.hpp> -#ifdef BOOST_GRAPH_USE_MPI -#error #include <boost/graph/distributed/concepts.hpp> -#endif // BOOST_GRAPH_USE_MPI +#include BOOST_GRAPH_MPI_INCLUDE(<boost/graph/distributed/concepts.hpp>) -namespace boost { - - template <class Visitor, class Graph> - struct BFSVisitorConcept { - void constraints() { - BOOST_CONCEPT_ASSERT(( CopyConstructibleConcept<Visitor> )); - vis.initialize_vertex(u, g); - vis.discover_vertex(u, g); - vis.examine_vertex(u, g); - vis.examine_edge(e, g); - vis.tree_edge(e, g); - vis.non_tree_edge(e, g); - vis.gray_target(e, g); - vis.black_target(e, g); - vis.finish_vertex(u, g); +namespace boost +{ + +template < class Visitor, class Graph > struct BFSVisitorConcept +{ + void constraints() + { + BOOST_CONCEPT_ASSERT((CopyConstructibleConcept< Visitor >)); + vis.initialize_vertex(u, g); + vis.discover_vertex(u, g); + vis.examine_vertex(u, g); + vis.examine_edge(e, g); + vis.tree_edge(e, g); + vis.non_tree_edge(e, g); + vis.gray_target(e, g); + vis.black_target(e, g); + vis.finish_vertex(u, g); } Visitor vis; Graph g; - typename graph_traits<Graph>::vertex_descriptor u; - typename graph_traits<Graph>::edge_descriptor e; - }; - - - // Multiple-source version - template <class IncidenceGraph, class Buffer, class BFSVisitor, - class ColorMap, class SourceIterator> - void breadth_first_visit - (const IncidenceGraph& g, - SourceIterator sources_begin, SourceIterator sources_end, - Buffer& Q, BFSVisitor vis, ColorMap color) - { - BOOST_CONCEPT_ASSERT(( IncidenceGraphConcept<IncidenceGraph> )); - typedef graph_traits<IncidenceGraph> GTraits; + typename graph_traits< Graph >::vertex_descriptor u; + typename graph_traits< Graph >::edge_descriptor e; +}; + +// Multiple-source version +template < class IncidenceGraph, class Buffer, class BFSVisitor, class ColorMap, + class SourceIterator > +void breadth_first_visit(const IncidenceGraph& g, SourceIterator sources_begin, + SourceIterator sources_end, Buffer& Q, BFSVisitor vis, ColorMap color) +{ + BOOST_CONCEPT_ASSERT((IncidenceGraphConcept< IncidenceGraph >)); + typedef graph_traits< IncidenceGraph > GTraits; typedef typename GTraits::vertex_descriptor Vertex; - BOOST_CONCEPT_ASSERT(( BFSVisitorConcept<BFSVisitor, IncidenceGraph> )); - BOOST_CONCEPT_ASSERT(( ReadWritePropertyMapConcept<ColorMap, Vertex> )); - typedef typename property_traits<ColorMap>::value_type ColorValue; - typedef color_traits<ColorValue> Color; + BOOST_CONCEPT_ASSERT((BFSVisitorConcept< BFSVisitor, IncidenceGraph >)); + BOOST_CONCEPT_ASSERT((ReadWritePropertyMapConcept< ColorMap, Vertex >)); + typedef typename property_traits< ColorMap >::value_type ColorValue; + typedef color_traits< ColorValue > Color; typename GTraits::out_edge_iterator ei, ei_end; - for (; sources_begin != sources_end; ++sources_begin) { - Vertex s = *sources_begin; - put(color, s, Color::gray()); vis.discover_vertex(s, g); - Q.push(s); + for (; sources_begin != sources_end; ++sources_begin) + { + Vertex s = *sources_begin; + put(color, s, Color::gray()); + vis.discover_vertex(s, g); + Q.push(s); } - while (! Q.empty()) { - Vertex u = Q.top(); Q.pop(); vis.examine_vertex(u, g); - for (boost::tie(ei, ei_end) = out_edges(u, g); ei != ei_end; ++ei) { - Vertex v = target(*ei, g); vis.examine_edge(*ei, g); - ColorValue v_color = get(color, v); - if (v_color == Color::white()) { vis.tree_edge(*ei, g); - put(color, v, Color::gray()); vis.discover_vertex(v, g); - Q.push(v); - } else { vis.non_tree_edge(*ei, g); - if (v_color == Color::gray()) vis.gray_target(*ei, g); - else vis.black_target(*ei, g); - } - } // end for - put(color, u, Color::black()); vis.finish_vertex(u, g); + while (!Q.empty()) + { + Vertex u = Q.top(); + Q.pop(); + vis.examine_vertex(u, g); + for (boost::tie(ei, ei_end) = out_edges(u, g); ei != ei_end; ++ei) + { + Vertex v = target(*ei, g); + vis.examine_edge(*ei, g); + ColorValue v_color = get(color, v); + if (v_color == Color::white()) + { + vis.tree_edge(*ei, g); + put(color, v, Color::gray()); + vis.discover_vertex(v, g); + Q.push(v); + } + else + { + vis.non_tree_edge(*ei, g); + if (v_color == Color::gray()) + vis.gray_target(*ei, g); + else + vis.black_target(*ei, g); + } + } // end for + put(color, u, Color::black()); + vis.finish_vertex(u, g); } // end while - } // breadth_first_visit - - // Single-source version - template <class IncidenceGraph, class Buffer, class BFSVisitor, - class ColorMap> - void breadth_first_visit - (const IncidenceGraph& g, - typename graph_traits<IncidenceGraph>::vertex_descriptor s, - Buffer& Q, BFSVisitor vis, ColorMap color) - { - typename graph_traits<IncidenceGraph>::vertex_descriptor sources[1] = {s}; +} // breadth_first_visit + +// Single-source version +template < class IncidenceGraph, class Buffer, class BFSVisitor, + class ColorMap > +void breadth_first_visit(const IncidenceGraph& g, + typename graph_traits< IncidenceGraph >::vertex_descriptor s, Buffer& Q, + BFSVisitor vis, ColorMap color) +{ + typename graph_traits< IncidenceGraph >::vertex_descriptor sources[1] + = { s }; breadth_first_visit(g, sources, sources + 1, Q, vis, color); - } - - - template <class VertexListGraph, class SourceIterator, - class Buffer, class BFSVisitor, - class ColorMap> - void breadth_first_search - (const VertexListGraph& g, - SourceIterator sources_begin, SourceIterator sources_end, - Buffer& Q, BFSVisitor vis, ColorMap color) - { +} + +template < class VertexListGraph, class SourceIterator, class Buffer, + class BFSVisitor, class ColorMap > +void breadth_first_search(const VertexListGraph& g, + SourceIterator sources_begin, SourceIterator sources_end, Buffer& Q, + BFSVisitor vis, ColorMap color) +{ // Initialization - typedef typename property_traits<ColorMap>::value_type ColorValue; - typedef color_traits<ColorValue> Color; - typename boost::graph_traits<VertexListGraph>::vertex_iterator i, i_end; - for (boost::tie(i, i_end) = vertices(g); i != i_end; ++i) { - vis.initialize_vertex(*i, g); - put(color, *i, Color::white()); + typedef typename property_traits< ColorMap >::value_type ColorValue; + typedef color_traits< ColorValue > Color; + typename boost::graph_traits< VertexListGraph >::vertex_iterator i, i_end; + for (boost::tie(i, i_end) = vertices(g); i != i_end; ++i) + { + vis.initialize_vertex(*i, g); + put(color, *i, Color::white()); } breadth_first_visit(g, sources_begin, sources_end, Q, vis, color); - } - - template <class VertexListGraph, class Buffer, class BFSVisitor, - class ColorMap> - void breadth_first_search - (const VertexListGraph& g, - typename graph_traits<VertexListGraph>::vertex_descriptor s, - Buffer& Q, BFSVisitor vis, ColorMap color) - { - typename graph_traits<VertexListGraph>::vertex_descriptor sources[1] = {s}; +} + +template < class VertexListGraph, class Buffer, class BFSVisitor, + class ColorMap > +void breadth_first_search(const VertexListGraph& g, + typename graph_traits< VertexListGraph >::vertex_descriptor s, Buffer& Q, + BFSVisitor vis, ColorMap color) +{ + typename graph_traits< VertexListGraph >::vertex_descriptor sources[1] + = { s }; breadth_first_search(g, sources, sources + 1, Q, vis, color); - } - - namespace graph { struct bfs_visitor_event_not_overridden {}; } +} +namespace graph +{ + struct bfs_visitor_event_not_overridden + { + }; +} - template <class Visitors = null_visitor> - class bfs_visitor { - public: - bfs_visitor() { } - bfs_visitor(Visitors vis) : m_vis(vis) { } +template < class Visitors = null_visitor > class bfs_visitor +{ +public: + bfs_visitor() {} + bfs_visitor(Visitors vis) : m_vis(vis) {} - template <class Vertex, class Graph> - graph::bfs_visitor_event_not_overridden - initialize_vertex(Vertex u, Graph& g) + template < class Vertex, class Graph > + graph::bfs_visitor_event_not_overridden initialize_vertex( + Vertex u, Graph& g) { - invoke_visitors(m_vis, u, g, ::boost::on_initialize_vertex()); - return graph::bfs_visitor_event_not_overridden(); + invoke_visitors(m_vis, u, g, ::boost::on_initialize_vertex()); + return graph::bfs_visitor_event_not_overridden(); } - template <class Vertex, class Graph> - graph::bfs_visitor_event_not_overridden - discover_vertex(Vertex u, Graph& g) + template < class Vertex, class Graph > + graph::bfs_visitor_event_not_overridden discover_vertex(Vertex u, Graph& g) { - invoke_visitors(m_vis, u, g, ::boost::on_discover_vertex()); - return graph::bfs_visitor_event_not_overridden(); + invoke_visitors(m_vis, u, g, ::boost::on_discover_vertex()); + return graph::bfs_visitor_event_not_overridden(); } - template <class Vertex, class Graph> - graph::bfs_visitor_event_not_overridden - examine_vertex(Vertex u, Graph& g) + template < class Vertex, class Graph > + graph::bfs_visitor_event_not_overridden examine_vertex(Vertex u, Graph& g) { - invoke_visitors(m_vis, u, g, ::boost::on_examine_vertex()); - return graph::bfs_visitor_event_not_overridden(); + invoke_visitors(m_vis, u, g, ::boost::on_examine_vertex()); + return graph::bfs_visitor_event_not_overridden(); } - template <class Edge, class Graph> - graph::bfs_visitor_event_not_overridden - examine_edge(Edge e, Graph& g) + template < class Edge, class Graph > + graph::bfs_visitor_event_not_overridden examine_edge(Edge e, Graph& g) { - invoke_visitors(m_vis, e, g, ::boost::on_examine_edge()); - return graph::bfs_visitor_event_not_overridden(); + invoke_visitors(m_vis, e, g, ::boost::on_examine_edge()); + return graph::bfs_visitor_event_not_overridden(); } - template <class Edge, class Graph> - graph::bfs_visitor_event_not_overridden - tree_edge(Edge e, Graph& g) + template < class Edge, class Graph > + graph::bfs_visitor_event_not_overridden tree_edge(Edge e, Graph& g) { - invoke_visitors(m_vis, e, g, ::boost::on_tree_edge()); - return graph::bfs_visitor_event_not_overridden(); + invoke_visitors(m_vis, e, g, ::boost::on_tree_edge()); + return graph::bfs_visitor_event_not_overridden(); } - template <class Edge, class Graph> - graph::bfs_visitor_event_not_overridden - non_tree_edge(Edge e, Graph& g) + template < class Edge, class Graph > + graph::bfs_visitor_event_not_overridden non_tree_edge(Edge e, Graph& g) { - invoke_visitors(m_vis, e, g, ::boost::on_non_tree_edge()); - return graph::bfs_visitor_event_not_overridden(); + invoke_visitors(m_vis, e, g, ::boost::on_non_tree_edge()); + return graph::bfs_visitor_event_not_overridden(); } - template <class Edge, class Graph> - graph::bfs_visitor_event_not_overridden - gray_target(Edge e, Graph& g) + template < class Edge, class Graph > + graph::bfs_visitor_event_not_overridden gray_target(Edge e, Graph& g) { - invoke_visitors(m_vis, e, g, ::boost::on_gray_target()); - return graph::bfs_visitor_event_not_overridden(); + invoke_visitors(m_vis, e, g, ::boost::on_gray_target()); + return graph::bfs_visitor_event_not_overridden(); } - template <class Edge, class Graph> - graph::bfs_visitor_event_not_overridden - black_target(Edge e, Graph& g) + template < class Edge, class Graph > + graph::bfs_visitor_event_not_overridden black_target(Edge e, Graph& g) { - invoke_visitors(m_vis, e, g, ::boost::on_black_target()); - return graph::bfs_visitor_event_not_overridden(); + invoke_visitors(m_vis, e, g, ::boost::on_black_target()); + return graph::bfs_visitor_event_not_overridden(); } - template <class Vertex, class Graph> - graph::bfs_visitor_event_not_overridden - finish_vertex(Vertex u, Graph& g) + template < class Vertex, class Graph > + graph::bfs_visitor_event_not_overridden finish_vertex(Vertex u, Graph& g) { - invoke_visitors(m_vis, u, g, ::boost::on_finish_vertex()); - return graph::bfs_visitor_event_not_overridden(); + invoke_visitors(m_vis, u, g, ::boost::on_finish_vertex()); + return graph::bfs_visitor_event_not_overridden(); } - BOOST_GRAPH_EVENT_STUB(on_initialize_vertex,bfs) - BOOST_GRAPH_EVENT_STUB(on_discover_vertex,bfs) - BOOST_GRAPH_EVENT_STUB(on_examine_vertex,bfs) - BOOST_GRAPH_EVENT_STUB(on_examine_edge,bfs) - BOOST_GRAPH_EVENT_STUB(on_tree_edge,bfs) - BOOST_GRAPH_EVENT_STUB(on_non_tree_edge,bfs) - BOOST_GRAPH_EVENT_STUB(on_gray_target,bfs) - BOOST_GRAPH_EVENT_STUB(on_black_target,bfs) - BOOST_GRAPH_EVENT_STUB(on_finish_vertex,bfs) - - protected: + BOOST_GRAPH_EVENT_STUB(on_initialize_vertex, bfs) + BOOST_GRAPH_EVENT_STUB(on_discover_vertex, bfs) + BOOST_GRAPH_EVENT_STUB(on_examine_vertex, bfs) + BOOST_GRAPH_EVENT_STUB(on_examine_edge, bfs) + BOOST_GRAPH_EVENT_STUB(on_tree_edge, bfs) + BOOST_GRAPH_EVENT_STUB(on_non_tree_edge, bfs) + BOOST_GRAPH_EVENT_STUB(on_gray_target, bfs) + BOOST_GRAPH_EVENT_STUB(on_black_target, bfs) + BOOST_GRAPH_EVENT_STUB(on_finish_vertex, bfs) + +protected: Visitors m_vis; - }; - template <class Visitors> - bfs_visitor<Visitors> - make_bfs_visitor(Visitors vis) { - return bfs_visitor<Visitors>(vis); - } - typedef bfs_visitor<> default_bfs_visitor; - - - namespace detail { - - template <class VertexListGraph, class ColorMap, class BFSVisitor, - class P, class T, class R> - void bfs_helper - (VertexListGraph& g, - typename graph_traits<VertexListGraph>::vertex_descriptor s, - ColorMap color, - BFSVisitor vis, - const bgl_named_params<P, T, R>& params, - boost::mpl::false_) +}; +template < class Visitors > +bfs_visitor< Visitors > make_bfs_visitor(Visitors vis) +{ + return bfs_visitor< Visitors >(vis); +} +typedef bfs_visitor<> default_bfs_visitor; + +namespace detail +{ + + template < class VertexListGraph, class ColorMap, class BFSVisitor, class P, + class T, class R > + void bfs_helper(VertexListGraph& g, + typename graph_traits< VertexListGraph >::vertex_descriptor s, + ColorMap color, BFSVisitor vis, + const bgl_named_params< P, T, R >& params, boost::mpl::false_) { - typedef graph_traits<VertexListGraph> Traits; - // Buffer default - typedef typename Traits::vertex_descriptor Vertex; - typedef boost::queue<Vertex> queue_t; - queue_t Q; - breadth_first_search - (g, s, - choose_param(get_param(params, buffer_param_t()), boost::ref(Q)).get(), - vis, color); + typedef graph_traits< VertexListGraph > Traits; + // Buffer default + typedef typename Traits::vertex_descriptor Vertex; + typedef boost::queue< Vertex > queue_t; + queue_t Q; + breadth_first_search(g, s, + choose_param(get_param(params, buffer_param_t()), boost::ref(Q)) + .get(), + vis, color); } #ifdef BOOST_GRAPH_USE_MPI - template <class DistributedGraph, class ColorMap, class BFSVisitor, - class P, class T, class R> - void bfs_helper - (DistributedGraph& g, - typename graph_traits<DistributedGraph>::vertex_descriptor s, - ColorMap color, - BFSVisitor vis, - const bgl_named_params<P, T, R>& params, - boost::mpl::true_); + template < class DistributedGraph, class ColorMap, class BFSVisitor, + class P, class T, class R > + void bfs_helper(DistributedGraph& g, + typename graph_traits< DistributedGraph >::vertex_descriptor s, + ColorMap color, BFSVisitor vis, + const bgl_named_params< P, T, R >& params, boost::mpl::true_); #endif // BOOST_GRAPH_USE_MPI //------------------------------------------------------------------------- @@ -277,126 +279,122 @@ namespace boost { // function dispatching so that we don't require vertex index if // the color default is not being used. - template <class ColorMap> - struct bfs_dispatch { - template <class VertexListGraph, class P, class T, class R> - static void apply - (VertexListGraph& g, - typename graph_traits<VertexListGraph>::vertex_descriptor s, - const bgl_named_params<P, T, R>& params, - ColorMap color) - { - bfs_helper - (g, s, color, - choose_param(get_param(params, graph_visitor), - make_bfs_visitor(null_visitor())), - params, - boost::mpl::bool_< - boost::is_base_and_derived< - distributed_graph_tag, - typename graph_traits<VertexListGraph>::traversal_category>::value>()); - } + template < class ColorMap > struct bfs_dispatch + { + template < class VertexListGraph, class P, class T, class R > + static void apply(VertexListGraph& g, + typename graph_traits< VertexListGraph >::vertex_descriptor s, + const bgl_named_params< P, T, R >& params, ColorMap color) + { + bfs_helper(g, s, color, + choose_param(get_param(params, graph_visitor), + make_bfs_visitor(null_visitor())), + params, + boost::mpl::bool_< + boost::is_base_and_derived< distributed_graph_tag, + typename graph_traits< + VertexListGraph >::traversal_category >::value >()); + } }; - template <> - struct bfs_dispatch<param_not_found> { - template <class VertexListGraph, class P, class T, class R> - static void apply - (VertexListGraph& g, - typename graph_traits<VertexListGraph>::vertex_descriptor s, - const bgl_named_params<P, T, R>& params, - param_not_found) - { - null_visitor null_vis; - - bfs_helper - (g, s, - make_two_bit_color_map - (num_vertices(g), - choose_const_pmap(get_param(params, vertex_index), - g, vertex_index)), - choose_param(get_param(params, graph_visitor), - make_bfs_visitor(null_vis)), - params, - boost::mpl::bool_< - boost::is_base_and_derived< - distributed_graph_tag, - typename graph_traits<VertexListGraph>::traversal_category>::value>()); - } + template <> struct bfs_dispatch< param_not_found > + { + template < class VertexListGraph, class P, class T, class R > + static void apply(VertexListGraph& g, + typename graph_traits< VertexListGraph >::vertex_descriptor s, + const bgl_named_params< P, T, R >& params, param_not_found) + { + null_visitor null_vis; + + bfs_helper(g, s, + make_two_bit_color_map(num_vertices(g), + choose_const_pmap( + get_param(params, vertex_index), g, vertex_index)), + choose_param(get_param(params, graph_visitor), + make_bfs_visitor(null_vis)), + params, + boost::mpl::bool_< + boost::is_base_and_derived< distributed_graph_tag, + typename graph_traits< + VertexListGraph >::traversal_category >::value >()); + } }; - } // namespace detail +} // namespace detail #if 1 - // Named Parameter Variant - template <class VertexListGraph, class P, class T, class R> - void breadth_first_search - (const VertexListGraph& g, - typename graph_traits<VertexListGraph>::vertex_descriptor s, - const bgl_named_params<P, T, R>& params) - { +// Named Parameter Variant +template < class VertexListGraph, class P, class T, class R > +void breadth_first_search(const VertexListGraph& g, + typename graph_traits< VertexListGraph >::vertex_descriptor s, + const bgl_named_params< P, T, R >& params) +{ // The graph is passed by *const* reference so that graph adaptors // (temporaries) can be passed into this function. However, the // graph is not really const since we may write to property maps // of the graph. - VertexListGraph& ng = const_cast<VertexListGraph&>(g); - typedef typename get_param_type< vertex_color_t, bgl_named_params<P,T,R> >::type C; - detail::bfs_dispatch<C>::apply(ng, s, params, - get_param(params, vertex_color)); - } + VertexListGraph& ng = const_cast< VertexListGraph& >(g); + typedef typename get_param_type< vertex_color_t, + bgl_named_params< P, T, R > >::type C; + detail::bfs_dispatch< C >::apply( + ng, s, params, get_param(params, vertex_color)); +} #endif +// This version does not initialize colors, user has to. - // This version does not initialize colors, user has to. - - template <class IncidenceGraph, class P, class T, class R> - void breadth_first_visit - (const IncidenceGraph& g, - typename graph_traits<IncidenceGraph>::vertex_descriptor s, - const bgl_named_params<P, T, R>& params) - { +template < class IncidenceGraph, class P, class T, class R > +void breadth_first_visit(const IncidenceGraph& g, + typename graph_traits< IncidenceGraph >::vertex_descriptor s, + const bgl_named_params< P, T, R >& params) +{ // The graph is passed by *const* reference so that graph adaptors // (temporaries) can be passed into this function. However, the // graph is not really const since we may write to property maps // of the graph. - IncidenceGraph& ng = const_cast<IncidenceGraph&>(g); + IncidenceGraph& ng = const_cast< IncidenceGraph& >(g); - typedef graph_traits<IncidenceGraph> Traits; + typedef graph_traits< IncidenceGraph > Traits; // Buffer default typedef typename Traits::vertex_descriptor vertex_descriptor; - typedef boost::queue<vertex_descriptor> queue_t; + typedef boost::queue< vertex_descriptor > queue_t; queue_t Q; - breadth_first_visit - (ng, s, - choose_param(get_param(params, buffer_param_t()), boost::ref(Q)).get(), - choose_param(get_param(params, graph_visitor), - make_bfs_visitor(null_visitor())), - choose_pmap(get_param(params, vertex_color), ng, vertex_color) - ); - } - - namespace graph { - namespace detail { - template <typename Graph, typename Source> - struct breadth_first_search_impl { - typedef void result_type; - template <typename ArgPack> - void operator()(const Graph& g, const Source& source, const ArgPack& arg_pack) { - using namespace boost::graph::keywords; - typename boost::graph_traits<Graph>::vertex_descriptor sources[1] = {source}; - boost::queue<typename boost::graph_traits<Graph>::vertex_descriptor> Q; - boost::breadth_first_search(g, - &sources[0], - &sources[1], - boost::unwrap_ref(arg_pack[_buffer | boost::ref(Q)]), - arg_pack[_visitor | make_bfs_visitor(null_visitor())], - boost::detail::make_color_map_from_arg_pack(g, arg_pack)); - } - }; + breadth_first_visit(ng, s, + choose_param(get_param(params, buffer_param_t()), boost::ref(Q)).get(), + choose_param( + get_param(params, graph_visitor), make_bfs_visitor(null_visitor())), + choose_pmap(get_param(params, vertex_color), ng, vertex_color)); +} + +namespace graph +{ + namespace detail + { + template < typename Graph, typename Source > + struct breadth_first_search_impl + { + typedef void result_type; + template < typename ArgPack > + void operator()( + const Graph& g, const Source& source, const ArgPack& arg_pack) + { + using namespace boost::graph::keywords; + typename boost::graph_traits< Graph >::vertex_descriptor + sources[1] + = { source }; + boost::queue< + typename boost::graph_traits< Graph >::vertex_descriptor > + Q; + boost::breadth_first_search(g, &sources[0], &sources[1], + boost::unwrap_ref(arg_pack[_buffer | boost::ref(Q)]), + arg_pack[_visitor | make_bfs_visitor(null_visitor())], + boost::detail::make_color_map_from_arg_pack(g, arg_pack)); + } + }; } BOOST_GRAPH_MAKE_FORWARDING_FUNCTION(breadth_first_search, 2, 4) - } +} #if 0 // Named Parameter Variant @@ -405,9 +403,6 @@ namespace boost { } // namespace boost -#ifdef BOOST_GRAPH_USE_MPI -# error #include <boost/graph/distributed/breadth_first_search.hpp> -#endif +#include BOOST_GRAPH_MPI_INCLUDE(<boost/graph/distributed/breadth_first_search.hpp>) #endif // BOOST_GRAPH_BREADTH_FIRST_SEARCH_HPP - diff --git a/contrib/restricted/boost/graph/include/boost/graph/buffer_concepts.hpp b/contrib/restricted/boost/graph/include/boost/graph/buffer_concepts.hpp index 233a7206b9..1eb48abcfa 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/buffer_concepts.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/buffer_concepts.hpp @@ -13,78 +13,83 @@ #include <boost/type_traits/remove_reference.hpp> #include <boost/concept/detail/concept_def.hpp> -namespace boost { +namespace boost +{ - BOOST_concept(Buffer, (B)) - { +BOOST_concept(Buffer, (B)) +{ typedef typename B::value_type value_type; typedef typename B::size_type size_type; - - BOOST_CONCEPT_USAGE(Buffer) { - typedef typename boost::add_reference<value_type>::type reference; - - BOOST_CONCEPT_ASSERT((Assignable<value_type>)); - - buf.push(g_ct); - buf.pop(); - reference t = buf.top(); - boost::ignore_unused_variable_warning(t); + + BOOST_CONCEPT_USAGE(Buffer) + { + typedef typename boost::add_reference< value_type >::type reference; + + BOOST_CONCEPT_ASSERT((Assignable< value_type >)); + + buf.push(g_ct); + buf.pop(); + reference t = buf.top(); + boost::ignore_unused_variable_warning(t); } - - void const_constraints(const B& cbuf) { - typedef typename boost::add_const<typename boost::remove_reference<value_type>::type>::type& const_reference; - - const_reference ct = cbuf.top(); - s = cbuf.size(); - if (cbuf.empty()) - dummy = __LINE__; + + void const_constraints(const B& cbuf) + { + typedef typename boost::add_const< + typename boost::remove_reference< value_type >::type >::type& + const_reference; + + const_reference ct = cbuf.top(); + s = cbuf.size(); + if (cbuf.empty()) + dummy = __LINE__; } - + int dummy; - + static const value_type g_ct; size_type s; B buf; - }; - - BOOST_concept(UpdatableQueue, (Q)) - : Buffer<Q> - { - BOOST_CONCEPT_USAGE(UpdatableQueue) { - q.update(g_ct); - } - - void const_constraints(const Q& cq) { - if (cq.contains(g_ct)) - dummy = __LINE__; +}; + +BOOST_concept(UpdatableQueue, (Q)) : Buffer< Q > +{ + BOOST_CONCEPT_USAGE(UpdatableQueue) { q.update(g_ct); } + + void const_constraints(const Q& cq) + { + if (cq.contains(g_ct)) + dummy = __LINE__; } - + int dummy; - - static const typename Buffer<Q>::value_type g_ct; + + static const typename Buffer< Q >::value_type g_ct; Q q; - }; - - BOOST_concept(KeyedUpdatableQueue, (Q)) - : UpdatableQueue<Q> - { +}; + +BOOST_concept(KeyedUpdatableQueue, (Q)) : UpdatableQueue< Q > +{ typedef typename Q::key_type key_type; typedef typename Q::key_map key_map; - - BOOST_CONCEPT_USAGE(KeyedUpdatableQueue) { - BOOST_CONCEPT_ASSERT((boost::ReadWritePropertyMapConcept<key_map, typename Buffer<Q>::value_type>)); + + BOOST_CONCEPT_USAGE(KeyedUpdatableQueue) + { + BOOST_CONCEPT_ASSERT((boost::ReadWritePropertyMapConcept< key_map, + typename Buffer< Q >::value_type >)); } - - void const_constraints(const Q& cq) { - km = cq.keys(); - k = get(km, g_ct); + + void const_constraints(const Q& cq) + { + km = cq.keys(); + k = get(km, g_ct); } - - static const typename Buffer<Q>::value_type g_ct; + + static const typename Buffer< Q >::value_type g_ct; key_type k; key_map km; Q q; - }; +}; } // end `namespace boost` #include <boost/concept/detail/concept_undef.hpp> diff --git a/contrib/restricted/boost/graph/include/boost/graph/compressed_sparse_row_graph.hpp b/contrib/restricted/boost/graph/include/boost/graph/compressed_sparse_row_graph.hpp index 7b91d4d6c0..e777d8c4b2 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/compressed_sparse_row_graph.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/compressed_sparse_row_graph.hpp @@ -47,7 +47,8 @@ #include <boost/property_map/transform_value_property_map.hpp> #include <boost/mpl/print.hpp> -namespace boost { +namespace boost +{ // A tag type indicating that the graph in question is a compressed // sparse row graph. This is an internal detail of the BGL. @@ -56,24 +57,36 @@ struct csr_graph_tag; // A type (edges_are_sorted_t) and a value (edges_are_sorted) used to indicate // that the edge list passed into the CSR graph is already sorted by source // vertex. -enum edges_are_sorted_t {edges_are_sorted}; +enum edges_are_sorted_t +{ + edges_are_sorted +}; // A type (edges_are_sorted_global_t) and a value (edges_are_sorted_global) // used to indicate that the edge list passed into the CSR graph is already // sorted by source vertex. -enum edges_are_sorted_global_t {edges_are_sorted_global}; +enum edges_are_sorted_global_t +{ + edges_are_sorted_global +}; // A type (edges_are_unsorted_t) and a value (edges_are_unsorted) used to // indicate that the edge list passed into the CSR graph is not sorted by // source vertex. This version caches the edge information in memory, and thus // requires only a single pass over the input data. -enum edges_are_unsorted_t {edges_are_unsorted}; +enum edges_are_unsorted_t +{ + edges_are_unsorted +}; // A type (edges_are_unsorted_multi_pass_t) and a value // (edges_are_unsorted_multi_pass) used to indicate that the edge list passed // into the CSR graph is not sorted by source vertex. This version uses less // memory but requires multi-pass capability on the iterators. -enum edges_are_unsorted_multi_pass_t {edges_are_unsorted_multi_pass}; +enum edges_are_unsorted_multi_pass_t +{ + edges_are_unsorted_multi_pass +}; // A type (edges_are_unsorted_multi_pass_global_t) and a value // (edges_are_unsorted_multi_pass_global) used to indicate that the edge list @@ -81,14 +94,20 @@ enum edges_are_unsorted_multi_pass_t {edges_are_unsorted_multi_pass}; // less memory but requires multi-pass capability on the iterators. The // global mapping and filtering is done here because it is often faster and it // greatly simplifies handling of edge properties. -enum edges_are_unsorted_multi_pass_global_t {edges_are_unsorted_multi_pass_global}; +enum edges_are_unsorted_multi_pass_global_t +{ + edges_are_unsorted_multi_pass_global +}; // A type (construct_inplace_from_sources_and_targets_t) and a value // (construct_inplace_from_sources_and_targets) used to indicate that mutable // vectors of sources and targets (and possibly edge properties) are being used // to construct the CSR graph. These vectors are sorted in-place and then the // targets and properties are swapped into the graph data structure. -enum construct_inplace_from_sources_and_targets_t {construct_inplace_from_sources_and_targets}; +enum construct_inplace_from_sources_and_targets_t +{ + construct_inplace_from_sources_and_targets +}; // A type (construct_inplace_from_sources_and_targets_global_t) and a value // (construct_inplace_from_sources_and_targets_global) used to indicate that @@ -99,7 +118,10 @@ enum construct_inplace_from_sources_and_targets_t {construct_inplace_from_source // used, and a map is required to convert those to local indices. This // constructor is intended for internal use by the various CSR graphs // (sequential and distributed). -enum construct_inplace_from_sources_and_targets_global_t {construct_inplace_from_sources_and_targets_global}; +enum construct_inplace_from_sources_and_targets_global_t +{ + construct_inplace_from_sources_and_targets_global +}; // A type (edges_are_unsorted_global_t) and a value (edges_are_unsorted_global) // used to indicate that the edge list passed into the CSR graph is not sorted @@ -108,61 +130,75 @@ enum construct_inplace_from_sources_and_targets_global_t {construct_inplace_from // edge information in memory, and thus requires only a single pass over the // input data. This constructor is intended for internal use by the // distributed CSR constructors. -enum edges_are_unsorted_global_t {edges_are_unsorted_global}; +enum edges_are_unsorted_global_t +{ + edges_are_unsorted_global +}; /**************************************************************************** * Local helper macros to reduce typing and clutter later on. * ****************************************************************************/ -#define BOOST_CSR_GRAPH_TEMPLATE_PARMS \ - typename Directed, typename VertexProperty, typename EdgeProperty, \ - typename GraphProperty, typename Vertex, typename EdgeIndex -#define BOOST_CSR_GRAPH_TYPE \ - compressed_sparse_row_graph<Directed, VertexProperty, EdgeProperty, \ - GraphProperty, Vertex, EdgeIndex> -#define BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS \ - typename VertexProperty, typename EdgeProperty, \ - typename GraphProperty, typename Vertex, typename EdgeIndex -#define BOOST_DIR_CSR_GRAPH_TYPE \ - compressed_sparse_row_graph<directedS, VertexProperty, EdgeProperty, \ - GraphProperty, Vertex, EdgeIndex> -#define BOOST_BIDIR_CSR_GRAPH_TEMPLATE_PARMS \ - typename VertexProperty, typename EdgeProperty, \ - typename GraphProperty, typename Vertex, typename EdgeIndex -#define BOOST_BIDIR_CSR_GRAPH_TYPE \ - compressed_sparse_row_graph<bidirectionalS, VertexProperty, EdgeProperty, \ - GraphProperty, Vertex, EdgeIndex> - -namespace detail { - template <typename T> - struct default_construct_iterator: public boost::iterator_facade<default_construct_iterator<T>, T, boost::random_access_traversal_tag, const T&> { - typedef boost::iterator_facade<default_construct_iterator<T>, T, std::random_access_iterator_tag, const T&> base_type; - T saved_value; - const T& dereference() const {return saved_value;} - bool equal(default_construct_iterator /*i*/) const {return true;} - void increment() {} - void decrement() {} - void advance(typename base_type::difference_type) {} - typename base_type::difference_type distance_to(default_construct_iterator) const {return 0;} - }; - - template <typename Less> - struct compare_first { - Less less; - compare_first(Less less = Less()): less(less) {} - template <typename Tuple> - bool operator()(const Tuple& a, const Tuple& b) const { - return less(a.template get<0>(), b.template get<0>()); - } - }; - - template <int N, typename Result> - struct my_tuple_get_class { - typedef const Result& result_type; - template <typename Tuple> - result_type operator()(const Tuple& t) const { - return t.template get<N>(); - } - }; +#define BOOST_CSR_GRAPH_TEMPLATE_PARMS \ + typename Directed, typename VertexProperty, typename EdgeProperty, \ + typename GraphProperty, typename Vertex, typename EdgeIndex +#define BOOST_CSR_GRAPH_TYPE \ + compressed_sparse_row_graph< Directed, VertexProperty, EdgeProperty, \ + GraphProperty, Vertex, EdgeIndex > +#define BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS \ + typename VertexProperty, typename EdgeProperty, typename GraphProperty, \ + typename Vertex, typename EdgeIndex +#define BOOST_DIR_CSR_GRAPH_TYPE \ + compressed_sparse_row_graph< directedS, VertexProperty, EdgeProperty, \ + GraphProperty, Vertex, EdgeIndex > +#define BOOST_BIDIR_CSR_GRAPH_TEMPLATE_PARMS \ + typename VertexProperty, typename EdgeProperty, typename GraphProperty, \ + typename Vertex, typename EdgeIndex +#define BOOST_BIDIR_CSR_GRAPH_TYPE \ + compressed_sparse_row_graph< bidirectionalS, VertexProperty, EdgeProperty, \ + GraphProperty, Vertex, EdgeIndex > + +namespace detail +{ + template < typename T > + struct default_construct_iterator + : public boost::iterator_facade< default_construct_iterator< T >, T, + boost::random_access_traversal_tag, const T& > + { + typedef boost::iterator_facade< default_construct_iterator< T >, T, + std::random_access_iterator_tag, const T& > + base_type; + T saved_value; + const T& dereference() const { return saved_value; } + bool equal(default_construct_iterator /*i*/) const { return true; } + void increment() {} + void decrement() {} + void advance(typename base_type::difference_type) {} + typename base_type::difference_type distance_to( + default_construct_iterator) const + { + return 0; + } + }; + + template < typename Less > struct compare_first + { + Less less; + compare_first(Less less = Less()) : less(less) {} + template < typename Tuple > + bool operator()(const Tuple& a, const Tuple& b) const + { + return less(a.template get< 0 >(), b.template get< 0 >()); + } + }; + + template < int N, typename Result > struct my_tuple_get_class + { + typedef const Result& result_type; + template < typename Tuple > result_type operator()(const Tuple& t) const + { + return t.template get< N >(); + } + }; } /** Compressed sparse row graph. @@ -170,1428 +206,1545 @@ namespace detail { * Vertex and EdgeIndex should be unsigned integral types and should * specialize numeric_limits. */ -template<typename Directed = directedS, - typename VertexProperty = no_property, - typename EdgeProperty = no_property, - typename GraphProperty = no_property, - typename Vertex = std::size_t, - typename EdgeIndex = Vertex> +template < typename Directed = directedS, typename VertexProperty = no_property, + typename EdgeProperty = no_property, typename GraphProperty = no_property, + typename Vertex = std::size_t, + typename EdgeIndex = Vertex > class compressed_sparse_row_graph; // Not defined -template<typename VertexProperty, - typename EdgeProperty, - typename GraphProperty, - typename Vertex, - typename EdgeIndex> -class compressed_sparse_row_graph<directedS, VertexProperty, EdgeProperty, GraphProperty, Vertex, EdgeIndex> - : public detail::indexed_vertex_properties<BOOST_DIR_CSR_GRAPH_TYPE, - VertexProperty, Vertex, typed_identity_property_map<Vertex> > -{ - public: - typedef detail::indexed_vertex_properties<compressed_sparse_row_graph, - VertexProperty, Vertex, typed_identity_property_map<Vertex> > - inherited_vertex_properties; - - // Some tests to prevent use of "void" is a property type (as was done in some test cases): - BOOST_STATIC_ASSERT((!is_same<VertexProperty, void>::value)); - BOOST_STATIC_ASSERT((!is_same<EdgeProperty, void>::value)); - BOOST_STATIC_ASSERT((!is_same<GraphProperty, void>::value)); - - public: - // For Property Graph - typedef GraphProperty graph_property_type; - typedef typename lookup_one_property<GraphProperty, graph_bundle_t>::type graph_bundled; - - typedef detail::compressed_sparse_row_structure<EdgeProperty, Vertex, EdgeIndex> forward_type; - - public: - /* At this time, the compressed sparse row graph can only be used to - * create directed and bidirectional graphs. In the future, - * undirected CSR graphs will also be supported. - */ - // BOOST_STATIC_ASSERT((is_same<Directed, directedS>::value)); - - // Concept requirements: - // For Graph - typedef Vertex vertex_descriptor; - typedef detail::csr_edge_descriptor<Vertex, EdgeIndex> edge_descriptor; - typedef directed_tag directed_category; - typedef allow_parallel_edge_tag edge_parallel_category; - - class traversal_category: public incidence_graph_tag, - public adjacency_graph_tag, - public vertex_list_graph_tag, - public edge_list_graph_tag {}; - - static vertex_descriptor null_vertex() { return vertex_descriptor(-1); } - - // For VertexListGraph - typedef counting_iterator<Vertex> vertex_iterator; - typedef Vertex vertices_size_type; - - // For EdgeListGraph - typedef EdgeIndex edges_size_type; - - // For IncidenceGraph - typedef detail::csr_out_edge_iterator<compressed_sparse_row_graph> out_edge_iterator; - typedef EdgeIndex degree_size_type; - - // For AdjacencyGraph - typedef typename std::vector<Vertex>::const_iterator adjacency_iterator; - - // For EdgeListGraph - typedef detail::csr_edge_iterator<compressed_sparse_row_graph> edge_iterator; - - // For BidirectionalGraph (not implemented) - typedef void in_edge_iterator; - - // For internal use - typedef csr_graph_tag graph_tag; - - typedef typename forward_type::inherited_edge_properties::edge_bundled edge_bundled; - typedef typename forward_type::inherited_edge_properties::edge_push_back_type edge_push_back_type; - typedef typename forward_type::inherited_edge_properties::edge_property_type edge_property_type; - - // Constructors - - // Default constructor: an empty graph. - compressed_sparse_row_graph(): m_property() {} - - // With numverts vertices - compressed_sparse_row_graph(vertices_size_type numverts) - : inherited_vertex_properties(numverts), m_forward(numverts) {} - - // From number of vertices and unsorted list of edges - template <typename MultiPassInputIterator> - compressed_sparse_row_graph(edges_are_unsorted_multi_pass_t, - MultiPassInputIterator edge_begin, - MultiPassInputIterator edge_end, - vertices_size_type numverts, - const GraphProperty& prop = GraphProperty()) +template < typename VertexProperty, typename EdgeProperty, + typename GraphProperty, typename Vertex, typename EdgeIndex > +class compressed_sparse_row_graph< directedS, VertexProperty, EdgeProperty, + GraphProperty, Vertex, EdgeIndex > +: public detail::indexed_vertex_properties< BOOST_DIR_CSR_GRAPH_TYPE, + VertexProperty, Vertex, typed_identity_property_map< Vertex > > +{ +public: + typedef detail::indexed_vertex_properties< compressed_sparse_row_graph, + VertexProperty, Vertex, typed_identity_property_map< Vertex > > + inherited_vertex_properties; + + // Some tests to prevent use of "void" is a property type (as was done in + // some test cases): + BOOST_STATIC_ASSERT((!is_same< VertexProperty, void >::value)); + BOOST_STATIC_ASSERT((!is_same< EdgeProperty, void >::value)); + BOOST_STATIC_ASSERT((!is_same< GraphProperty, void >::value)); + +public: + // For Property Graph + typedef GraphProperty graph_property_type; + typedef typename lookup_one_property< GraphProperty, graph_bundle_t >::type + graph_bundled; + + typedef detail::compressed_sparse_row_structure< EdgeProperty, Vertex, + EdgeIndex > + forward_type; + +public: + /* At this time, the compressed sparse row graph can only be used to + * create directed and bidirectional graphs. In the future, + * undirected CSR graphs will also be supported. + */ + // BOOST_STATIC_ASSERT((is_same<Directed, directedS>::value)); + + // Concept requirements: + // For Graph + typedef Vertex vertex_descriptor; + typedef detail::csr_edge_descriptor< Vertex, EdgeIndex > edge_descriptor; + typedef directed_tag directed_category; + typedef allow_parallel_edge_tag edge_parallel_category; + + class traversal_category : public incidence_graph_tag, + public adjacency_graph_tag, + public vertex_list_graph_tag, + public edge_list_graph_tag + { + }; + + static vertex_descriptor null_vertex() { return vertex_descriptor(-1); } + + // For VertexListGraph + typedef counting_iterator< Vertex > vertex_iterator; + typedef Vertex vertices_size_type; + + // For EdgeListGraph + typedef EdgeIndex edges_size_type; + + // For IncidenceGraph + typedef detail::csr_out_edge_iterator< compressed_sparse_row_graph > + out_edge_iterator; + typedef EdgeIndex degree_size_type; + + // For AdjacencyGraph + typedef typename std::vector< Vertex >::const_iterator adjacency_iterator; + + // For EdgeListGraph + typedef detail::csr_edge_iterator< compressed_sparse_row_graph > + edge_iterator; + + // For BidirectionalGraph (not implemented) + typedef void in_edge_iterator; + + // For internal use + typedef csr_graph_tag graph_tag; + + typedef typename forward_type::inherited_edge_properties::edge_bundled + edge_bundled; + typedef + typename forward_type::inherited_edge_properties::edge_push_back_type + edge_push_back_type; + typedef typename forward_type::inherited_edge_properties::edge_property_type + edge_property_type; + + // Constructors + + // Default constructor: an empty graph. + compressed_sparse_row_graph() : m_property() {} + + // With numverts vertices + compressed_sparse_row_graph(vertices_size_type numverts) + : inherited_vertex_properties(numverts), m_forward(numverts) + { + } + + // From number of vertices and unsorted list of edges + template < typename MultiPassInputIterator > + compressed_sparse_row_graph(edges_are_unsorted_multi_pass_t, + MultiPassInputIterator edge_begin, MultiPassInputIterator edge_end, + vertices_size_type numverts, + const GraphProperty& prop = GraphProperty()) : inherited_vertex_properties(numverts), m_property(prop) - { - m_forward.assign_unsorted_multi_pass_edges(edge_begin, edge_end, numverts, typed_identity_property_map<vertices_size_type>(), keep_all()); - } - - // From number of vertices and unsorted list of edges, plus edge properties - template <typename MultiPassInputIterator, typename EdgePropertyIterator> - compressed_sparse_row_graph(edges_are_unsorted_multi_pass_t, - MultiPassInputIterator edge_begin, - MultiPassInputIterator edge_end, - EdgePropertyIterator ep_iter, - vertices_size_type numverts, - const GraphProperty& prop = GraphProperty()) + { + m_forward.assign_unsorted_multi_pass_edges(edge_begin, edge_end, + numverts, typed_identity_property_map< vertices_size_type >(), + keep_all()); + } + + // From number of vertices and unsorted list of edges, plus edge properties + template < typename MultiPassInputIterator, typename EdgePropertyIterator > + compressed_sparse_row_graph(edges_are_unsorted_multi_pass_t, + MultiPassInputIterator edge_begin, MultiPassInputIterator edge_end, + EdgePropertyIterator ep_iter, vertices_size_type numverts, + const GraphProperty& prop = GraphProperty()) : inherited_vertex_properties(numverts), m_forward(), m_property(prop) - { - m_forward.assign_unsorted_multi_pass_edges(edge_begin, edge_end, ep_iter, numverts, typed_identity_property_map<vertices_size_type>(), keep_all()); - } - - // From number of vertices and unsorted list of edges, with filter and - // global-to-local map - template <typename MultiPassInputIterator, typename GlobalToLocal, typename SourcePred> - compressed_sparse_row_graph(edges_are_unsorted_multi_pass_global_t, - MultiPassInputIterator edge_begin, - MultiPassInputIterator edge_end, - vertices_size_type numlocalverts, - const GlobalToLocal& global_to_local, - const SourcePred& source_pred, - const GraphProperty& prop = GraphProperty()) + { + m_forward.assign_unsorted_multi_pass_edges(edge_begin, edge_end, + ep_iter, numverts, + typed_identity_property_map< vertices_size_type >(), keep_all()); + } + + // From number of vertices and unsorted list of edges, with filter and + // global-to-local map + template < typename MultiPassInputIterator, typename GlobalToLocal, + typename SourcePred > + compressed_sparse_row_graph(edges_are_unsorted_multi_pass_global_t, + MultiPassInputIterator edge_begin, MultiPassInputIterator edge_end, + vertices_size_type numlocalverts, const GlobalToLocal& global_to_local, + const SourcePred& source_pred, + const GraphProperty& prop = GraphProperty()) : inherited_vertex_properties(numlocalverts), m_forward(), m_property(prop) - { - m_forward.assign_unsorted_multi_pass_edges(edge_begin, edge_end, numlocalverts, global_to_local, source_pred); - } - - // From number of vertices and unsorted list of edges, plus edge properties, - // with filter and global-to-local map - template <typename MultiPassInputIterator, typename EdgePropertyIterator, typename GlobalToLocal, typename SourcePred> - compressed_sparse_row_graph(edges_are_unsorted_multi_pass_global_t, - MultiPassInputIterator edge_begin, - MultiPassInputIterator edge_end, - EdgePropertyIterator ep_iter, - vertices_size_type numlocalverts, - const GlobalToLocal& global_to_local, - const SourcePred& source_pred, - const GraphProperty& prop = GraphProperty()) + { + m_forward.assign_unsorted_multi_pass_edges( + edge_begin, edge_end, numlocalverts, global_to_local, source_pred); + } + + // From number of vertices and unsorted list of edges, plus edge + // properties, with filter and global-to-local map + template < typename MultiPassInputIterator, typename EdgePropertyIterator, + typename GlobalToLocal, typename SourcePred > + compressed_sparse_row_graph(edges_are_unsorted_multi_pass_global_t, + MultiPassInputIterator edge_begin, MultiPassInputIterator edge_end, + EdgePropertyIterator ep_iter, vertices_size_type numlocalverts, + const GlobalToLocal& global_to_local, const SourcePred& source_pred, + const GraphProperty& prop = GraphProperty()) : inherited_vertex_properties(numlocalverts), m_forward(), m_property(prop) - { - m_forward.assign_unsorted_multi_pass_edges(edge_begin, edge_end, ep_iter, numlocalverts, global_to_local, source_pred); - } - - // From number of vertices and sorted list of edges (new interface) - template<typename InputIterator> - compressed_sparse_row_graph(edges_are_sorted_t, - InputIterator edge_begin, InputIterator edge_end, - vertices_size_type numverts, - edges_size_type numedges = 0, - const GraphProperty& prop = GraphProperty()) + { + m_forward.assign_unsorted_multi_pass_edges(edge_begin, edge_end, + ep_iter, numlocalverts, global_to_local, source_pred); + } + + // From number of vertices and sorted list of edges (new interface) + template < typename InputIterator > + compressed_sparse_row_graph(edges_are_sorted_t, InputIterator edge_begin, + InputIterator edge_end, vertices_size_type numverts, + edges_size_type numedges = 0, + const GraphProperty& prop = GraphProperty()) : m_property(prop) - { - m_forward.assign_from_sorted_edges(edge_begin, edge_end, typed_identity_property_map<vertices_size_type>(), keep_all(), numverts, numedges); - inherited_vertex_properties::resize(numverts); - } - - // From number of vertices and sorted list of edges (new interface) - template<typename InputIterator, typename EdgePropertyIterator> - compressed_sparse_row_graph(edges_are_sorted_t, - InputIterator edge_begin, InputIterator edge_end, - EdgePropertyIterator ep_iter, - vertices_size_type numverts, - edges_size_type numedges = 0, - const GraphProperty& prop = GraphProperty()) + { + m_forward.assign_from_sorted_edges(edge_begin, edge_end, + typed_identity_property_map< vertices_size_type >(), keep_all(), + numverts, numedges); + inherited_vertex_properties::resize(numverts); + } + + // From number of vertices and sorted list of edges (new interface) + template < typename InputIterator, typename EdgePropertyIterator > + compressed_sparse_row_graph(edges_are_sorted_t, InputIterator edge_begin, + InputIterator edge_end, EdgePropertyIterator ep_iter, + vertices_size_type numverts, edges_size_type numedges = 0, + const GraphProperty& prop = GraphProperty()) : m_property(prop) - { - m_forward.assign_from_sorted_edges(edge_begin, edge_end, ep_iter, typed_identity_property_map<vertices_size_type>(), keep_all(), numverts, numedges); - inherited_vertex_properties::resize(numverts); - } - - // From number of vertices and sorted list of edges, filtered and global (new interface) - template<typename InputIterator, typename GlobalToLocal, typename SourcePred> - compressed_sparse_row_graph(edges_are_sorted_global_t, - InputIterator edge_begin, InputIterator edge_end, - const GlobalToLocal& global_to_local, - const SourcePred& source_pred, - vertices_size_type numverts, - const GraphProperty& prop = GraphProperty()) + { + m_forward.assign_from_sorted_edges(edge_begin, edge_end, ep_iter, + typed_identity_property_map< vertices_size_type >(), keep_all(), + numverts, numedges); + inherited_vertex_properties::resize(numverts); + } + + // From number of vertices and sorted list of edges, filtered and global + // (new interface) + template < typename InputIterator, typename GlobalToLocal, + typename SourcePred > + compressed_sparse_row_graph(edges_are_sorted_global_t, + InputIterator edge_begin, InputIterator edge_end, + const GlobalToLocal& global_to_local, const SourcePred& source_pred, + vertices_size_type numverts, + const GraphProperty& prop = GraphProperty()) : m_property(prop) - { - m_forward.assign_from_sorted_edges(edge_begin, edge_end, global_to_local, source_pred, numverts, 0); - inherited_vertex_properties::resize(numverts); - } - - // From number of vertices and sorted list of edges (new interface) - template<typename InputIterator, typename EdgePropertyIterator, typename GlobalToLocal, typename SourcePred> - compressed_sparse_row_graph(edges_are_sorted_global_t, - InputIterator edge_begin, InputIterator edge_end, - EdgePropertyIterator ep_iter, - const GlobalToLocal& global_to_local, - const SourcePred& source_pred, - vertices_size_type numverts, - const GraphProperty& prop = GraphProperty()) + { + m_forward.assign_from_sorted_edges( + edge_begin, edge_end, global_to_local, source_pred, numverts, 0); + inherited_vertex_properties::resize(numverts); + } + + // From number of vertices and sorted list of edges (new interface) + template < typename InputIterator, typename EdgePropertyIterator, + typename GlobalToLocal, typename SourcePred > + compressed_sparse_row_graph(edges_are_sorted_global_t, + InputIterator edge_begin, InputIterator edge_end, + EdgePropertyIterator ep_iter, const GlobalToLocal& global_to_local, + const SourcePred& source_pred, vertices_size_type numverts, + const GraphProperty& prop = GraphProperty()) : m_property(prop) - { - m_forward.assign_from_sorted_edges(edge_begin, edge_end, ep_iter, global_to_local, source_pred, numverts, 0); - inherited_vertex_properties::resize(numverts); - } - - // From number of vertices and mutable vectors of sources and targets; - // vectors are returned with unspecified contents but are guaranteed not to - // share storage with the constructed graph. - compressed_sparse_row_graph(construct_inplace_from_sources_and_targets_t, - std::vector<vertex_descriptor>& sources, - std::vector<vertex_descriptor>& targets, - vertices_size_type numverts, - const GraphProperty& prop = GraphProperty()) + { + m_forward.assign_from_sorted_edges(edge_begin, edge_end, ep_iter, + global_to_local, source_pred, numverts, 0); + inherited_vertex_properties::resize(numverts); + } + + // From number of vertices and mutable vectors of sources and targets; + // vectors are returned with unspecified contents but are guaranteed not to + // share storage with the constructed graph. + compressed_sparse_row_graph(construct_inplace_from_sources_and_targets_t, + std::vector< vertex_descriptor >& sources, + std::vector< vertex_descriptor >& targets, vertices_size_type numverts, + const GraphProperty& prop = GraphProperty()) : inherited_vertex_properties(numverts), m_property(prop) - { - m_forward.assign_sources_and_targets_global(sources, targets, numverts, boost::typed_identity_property_map<vertices_size_type>()); - } - - // From number of vertices and mutable vectors of sources and targets, - // expressed with global vertex indices; vectors are returned with - // unspecified contents but are guaranteed not to share storage with the - // constructed graph. This constructor should only be used by the - // distributed CSR graph. - template <typename GlobalToLocal> - compressed_sparse_row_graph(construct_inplace_from_sources_and_targets_global_t, - std::vector<vertex_descriptor>& sources, - std::vector<vertex_descriptor>& targets, - vertices_size_type numlocalverts, - GlobalToLocal global_to_local, - const GraphProperty& prop = GraphProperty()) + { + m_forward.assign_sources_and_targets_global(sources, targets, numverts, + boost::typed_identity_property_map< vertices_size_type >()); + } + + // From number of vertices and mutable vectors of sources and targets, + // expressed with global vertex indices; vectors are returned with + // unspecified contents but are guaranteed not to share storage with the + // constructed graph. This constructor should only be used by the + // distributed CSR graph. + template < typename GlobalToLocal > + compressed_sparse_row_graph( + construct_inplace_from_sources_and_targets_global_t, + std::vector< vertex_descriptor >& sources, + std::vector< vertex_descriptor >& targets, + vertices_size_type numlocalverts, GlobalToLocal global_to_local, + const GraphProperty& prop = GraphProperty()) : inherited_vertex_properties(numlocalverts), m_property(prop) - { - m_forward.assign_sources_and_targets_global(sources, targets, numlocalverts, global_to_local); - } - - // From number of vertices and mutable vectors of sources, targets, and edge - // properties; vectors are returned with unspecified contents but are - // guaranteed not to share storage with the constructed graph. - compressed_sparse_row_graph(construct_inplace_from_sources_and_targets_t, - std::vector<vertex_descriptor>& sources, - std::vector<vertex_descriptor>& targets, - std::vector<typename forward_type::inherited_edge_properties::edge_bundled>& edge_props, - vertices_size_type numverts, - const GraphProperty& prop = GraphProperty()) + { + m_forward.assign_sources_and_targets_global( + sources, targets, numlocalverts, global_to_local); + } + + // From number of vertices and mutable vectors of sources, targets, and + // edge properties; vectors are returned with unspecified contents but are + // guaranteed not to share storage with the constructed graph. + compressed_sparse_row_graph(construct_inplace_from_sources_and_targets_t, + std::vector< vertex_descriptor >& sources, + std::vector< vertex_descriptor >& targets, + std::vector< + typename forward_type::inherited_edge_properties::edge_bundled >& + edge_props, + vertices_size_type numverts, + const GraphProperty& prop = GraphProperty()) : inherited_vertex_properties(numverts), m_property(prop) - { - m_forward.assign_sources_and_targets_global(sources, targets, edge_props, numverts, boost::typed_identity_property_map<vertices_size_type>()); - } - - // From number of vertices and mutable vectors of sources and targets and - // edge properties, expressed with global vertex indices; vectors are - // returned with unspecified contents but are guaranteed not to share - // storage with the constructed graph. This constructor should only be used - // by the distributed CSR graph. - template <typename GlobalToLocal> - compressed_sparse_row_graph(construct_inplace_from_sources_and_targets_global_t, - std::vector<vertex_descriptor>& sources, - std::vector<vertex_descriptor>& targets, - std::vector<typename forward_type::inherited_edge_properties::edge_bundled>& edge_props, - vertices_size_type numlocalverts, - GlobalToLocal global_to_local, - const GraphProperty& prop = GraphProperty()) + { + m_forward.assign_sources_and_targets_global(sources, targets, + edge_props, numverts, + boost::typed_identity_property_map< vertices_size_type >()); + } + + // From number of vertices and mutable vectors of sources and targets and + // edge properties, expressed with global vertex indices; vectors are + // returned with unspecified contents but are guaranteed not to share + // storage with the constructed graph. This constructor should only be + // used by the distributed CSR graph. + template < typename GlobalToLocal > + compressed_sparse_row_graph( + construct_inplace_from_sources_and_targets_global_t, + std::vector< vertex_descriptor >& sources, + std::vector< vertex_descriptor >& targets, + std::vector< + typename forward_type::inherited_edge_properties::edge_bundled >& + edge_props, + vertices_size_type numlocalverts, GlobalToLocal global_to_local, + const GraphProperty& prop = GraphProperty()) : inherited_vertex_properties(numlocalverts), m_property(prop) - { - m_forward.assign_sources_and_targets_global(sources, targets, edge_props, numlocalverts, global_to_local); - } - - // From number of vertices and single-pass range of unsorted edges. Data is - // cached in coordinate form before creating the actual graph. - template<typename InputIterator> - compressed_sparse_row_graph(edges_are_unsorted_t, - InputIterator edge_begin, InputIterator edge_end, - vertices_size_type numverts, - const GraphProperty& prop = GraphProperty()) + { + m_forward.assign_sources_and_targets_global( + sources, targets, edge_props, numlocalverts, global_to_local); + } + + // From number of vertices and single-pass range of unsorted edges. Data + // is cached in coordinate form before creating the actual graph. + template < typename InputIterator > + compressed_sparse_row_graph(edges_are_unsorted_t, InputIterator edge_begin, + InputIterator edge_end, vertices_size_type numverts, + const GraphProperty& prop = GraphProperty()) : inherited_vertex_properties(numverts), m_property(prop) - { - std::vector<vertex_descriptor> sources, targets; - boost::graph::detail::split_into_separate_coords - (edge_begin, edge_end, sources, targets); - m_forward.assign_sources_and_targets_global(sources, targets, numverts, boost::typed_identity_property_map<vertices_size_type>()); - } - - // From number of vertices and single-pass range of unsorted edges and - // single-pass range of edge properties. Data is cached in coordinate form - // before creating the actual graph. - template<typename InputIterator, typename EdgePropertyIterator> - compressed_sparse_row_graph(edges_are_unsorted_t, - InputIterator edge_begin, InputIterator edge_end, - EdgePropertyIterator ep_iter, - vertices_size_type numverts, - const GraphProperty& prop = GraphProperty()) + { + std::vector< vertex_descriptor > sources, targets; + boost::graph::detail::split_into_separate_coords( + edge_begin, edge_end, sources, targets); + m_forward.assign_sources_and_targets_global(sources, targets, numverts, + boost::typed_identity_property_map< vertices_size_type >()); + } + + // From number of vertices and single-pass range of unsorted edges and + // single-pass range of edge properties. Data is cached in coordinate form + // before creating the actual graph. + template < typename InputIterator, typename EdgePropertyIterator > + compressed_sparse_row_graph(edges_are_unsorted_t, InputIterator edge_begin, + InputIterator edge_end, EdgePropertyIterator ep_iter, + vertices_size_type numverts, + const GraphProperty& prop = GraphProperty()) : inherited_vertex_properties(numverts), m_property(prop) - { - std::vector<vertex_descriptor> sources, targets; - boost::graph::detail::split_into_separate_coords - (edge_begin, edge_end, sources, targets); - size_t numedges = sources.size(); - std::vector<typename forward_type::inherited_edge_properties::edge_bundled> edge_props(numedges); - for (size_t i = 0; i < numedges; ++i) { - edge_props[i] = *ep_iter++; + { + std::vector< vertex_descriptor > sources, targets; + boost::graph::detail::split_into_separate_coords( + edge_begin, edge_end, sources, targets); + size_t numedges = sources.size(); + std::vector< + typename forward_type::inherited_edge_properties::edge_bundled > + edge_props(numedges); + for (size_t i = 0; i < numedges; ++i) + { + edge_props[i] = *ep_iter++; + } + m_forward.assign_sources_and_targets_global(sources, targets, + edge_props, numverts, + boost::typed_identity_property_map< vertices_size_type >()); } - m_forward.assign_sources_and_targets_global(sources, targets, edge_props, numverts, boost::typed_identity_property_map<vertices_size_type>()); - } - - // From number of vertices and single-pass range of unsorted edges. Data is - // cached in coordinate form before creating the actual graph. Edges are - // filtered and transformed for use in a distributed graph. - template<typename InputIterator, typename GlobalToLocal, typename SourcePred> - compressed_sparse_row_graph(edges_are_unsorted_global_t, - InputIterator edge_begin, InputIterator edge_end, - vertices_size_type numlocalverts, - GlobalToLocal global_to_local, - const SourcePred& source_pred, - const GraphProperty& prop = GraphProperty()) + + // From number of vertices and single-pass range of unsorted edges. Data + // is cached in coordinate form before creating the actual graph. Edges + // are filtered and transformed for use in a distributed graph. + template < typename InputIterator, typename GlobalToLocal, + typename SourcePred > + compressed_sparse_row_graph(edges_are_unsorted_global_t, + InputIterator edge_begin, InputIterator edge_end, + vertices_size_type numlocalverts, GlobalToLocal global_to_local, + const SourcePred& source_pred, + const GraphProperty& prop = GraphProperty()) : inherited_vertex_properties(numlocalverts), m_property(prop) - { - std::vector<vertex_descriptor> sources, targets; - boost::graph::detail::split_into_separate_coords_filtered - (edge_begin, edge_end, sources, targets, source_pred); - m_forward.assign_sources_and_targets_global(sources, targets, numlocalverts, global_to_local); - } - - // From number of vertices and single-pass range of unsorted edges and - // single-pass range of edge properties. Data is cached in coordinate form - // before creating the actual graph. Edges are filtered and transformed for - // use in a distributed graph. - template<typename InputIterator, typename EdgePropertyIterator, - typename GlobalToLocal, typename SourcePred> - compressed_sparse_row_graph(edges_are_unsorted_global_t, - InputIterator edge_begin, InputIterator edge_end, - EdgePropertyIterator ep_iter, - vertices_size_type numlocalverts, - GlobalToLocal global_to_local, - const SourcePred& source_pred, - const GraphProperty& prop = GraphProperty()) + { + std::vector< vertex_descriptor > sources, targets; + boost::graph::detail::split_into_separate_coords_filtered( + edge_begin, edge_end, sources, targets, source_pred); + m_forward.assign_sources_and_targets_global( + sources, targets, numlocalverts, global_to_local); + } + + // From number of vertices and single-pass range of unsorted edges and + // single-pass range of edge properties. Data is cached in coordinate form + // before creating the actual graph. Edges are filtered and transformed + // for use in a distributed graph. + template < typename InputIterator, typename EdgePropertyIterator, + typename GlobalToLocal, typename SourcePred > + compressed_sparse_row_graph(edges_are_unsorted_global_t, + InputIterator edge_begin, InputIterator edge_end, + EdgePropertyIterator ep_iter, vertices_size_type numlocalverts, + GlobalToLocal global_to_local, const SourcePred& source_pred, + const GraphProperty& prop = GraphProperty()) : inherited_vertex_properties(numlocalverts), m_property(prop) - { - std::vector<vertex_descriptor> sources, targets; - std::vector<edge_bundled> edge_props; - boost::graph::detail::split_into_separate_coords_filtered - (edge_begin, edge_end, ep_iter, sources, targets, edge_props, source_pred); - m_forward.assign_sources_and_targets_global(sources, targets, edge_props, numlocalverts, global_to_local); - } - - - // Requires IncidenceGraph and a vertex index map - template<typename Graph, typename VertexIndexMap> - compressed_sparse_row_graph(const Graph& g, const VertexIndexMap& vi, - vertices_size_type numverts, - edges_size_type numedges) - : m_property() - { - assign(g, vi, numverts, numedges); - inherited_vertex_properties::resize(numverts); - } - - // Requires VertexListGraph and EdgeListGraph - template<typename Graph, typename VertexIndexMap> - compressed_sparse_row_graph(const Graph& g, const VertexIndexMap& vi) + { + std::vector< vertex_descriptor > sources, targets; + std::vector< edge_bundled > edge_props; + boost::graph::detail::split_into_separate_coords_filtered(edge_begin, + edge_end, ep_iter, sources, targets, edge_props, source_pred); + m_forward.assign_sources_and_targets_global( + sources, targets, edge_props, numlocalverts, global_to_local); + } + + // Requires IncidenceGraph and a vertex index map + template < typename Graph, typename VertexIndexMap > + compressed_sparse_row_graph(const Graph& g, const VertexIndexMap& vi, + vertices_size_type numverts, edges_size_type numedges) : m_property() - { - typename graph_traits<Graph>::edges_size_type numedges = num_edges(g); - if (is_same<typename graph_traits<Graph>::directed_category, undirectedS>::value) { - numedges *= 2; // Double each edge (actual doubling done by out_edges function) + { + assign(g, vi, numverts, numedges); + inherited_vertex_properties::resize(numverts); } - vertices_size_type numverts = num_vertices(g); - assign(g, vi, numverts, numedges); - inherited_vertex_properties::resize(numverts); - } - - // Requires vertex index map plus requirements of previous constructor - template<typename Graph> - explicit compressed_sparse_row_graph(const Graph& g) + + // Requires VertexListGraph and EdgeListGraph + template < typename Graph, typename VertexIndexMap > + compressed_sparse_row_graph(const Graph& g, const VertexIndexMap& vi) : m_property() - { - typename graph_traits<Graph>::edges_size_type numedges = num_edges(g); - if (is_same<typename graph_traits<Graph>::directed_category, undirectedS>::value) { - numedges *= 2; // Double each edge (actual doubling done by out_edges function) + { + typename graph_traits< Graph >::edges_size_type numedges = num_edges(g); + if (is_same< typename graph_traits< Graph >::directed_category, + undirectedS >::value) + { + numedges *= 2; // Double each edge (actual doubling done by + // out_edges function) + } + vertices_size_type numverts = num_vertices(g); + assign(g, vi, numverts, numedges); + inherited_vertex_properties::resize(numverts); + } + + // Requires vertex index map plus requirements of previous constructor + template < typename Graph > + explicit compressed_sparse_row_graph(const Graph& g) : m_property() + { + typename graph_traits< Graph >::edges_size_type numedges = num_edges(g); + if (is_same< typename graph_traits< Graph >::directed_category, + undirectedS >::value) + { + numedges *= 2; // Double each edge (actual doubling done by + // out_edges function) + } + assign(g, get(vertex_index, g), num_vertices(g), numedges); + } + + // From any graph (slow and uses a lot of memory) + // Requires IncidenceGraph and a vertex index map + // Internal helper function + // Note that numedges must be doubled for undirected source graphs + template < typename Graph, typename VertexIndexMap > + void assign(const Graph& g, const VertexIndexMap& vi, + vertices_size_type numverts, edges_size_type numedges) + { + m_forward.assign(g, vi, numverts, numedges); + inherited_vertex_properties::resize(numverts); + } + + // Requires the above, plus VertexListGraph and EdgeListGraph + template < typename Graph, typename VertexIndexMap > + void assign(const Graph& g, const VertexIndexMap& vi) + { + typename graph_traits< Graph >::edges_size_type numedges = num_edges(g); + if (is_same< typename graph_traits< Graph >::directed_category, + undirectedS >::value) + { + numedges *= 2; // Double each edge (actual doubling done by + // out_edges function) + } + vertices_size_type numverts = num_vertices(g); + m_forward.assign(g, vi, numverts, numedges); + inherited_vertex_properties::resize(numverts); + } + + // Requires the above, plus a vertex_index map. + template < typename Graph > void assign(const Graph& g) + { + typename graph_traits< Graph >::edges_size_type numedges = num_edges(g); + if (is_same< typename graph_traits< Graph >::directed_category, + undirectedS >::value) + { + numedges *= 2; // Double each edge (actual doubling done by + // out_edges function) + } + vertices_size_type numverts = num_vertices(g); + m_forward.assign(g, get(vertex_index, g), numverts, numedges); + inherited_vertex_properties::resize(numverts); + } + + // Add edges from a sorted (smallest sources first) range of pairs and edge + // properties + template < typename BidirectionalIteratorOrig, typename EPIterOrig, + typename GlobalToLocal > + void add_edges_sorted_internal(BidirectionalIteratorOrig first_sorted, + BidirectionalIteratorOrig last_sorted, EPIterOrig ep_iter_sorted, + const GlobalToLocal& global_to_local) + { + m_forward.add_edges_sorted_internal( + first_sorted, last_sorted, ep_iter_sorted, global_to_local); + } + + template < typename BidirectionalIteratorOrig, typename EPIterOrig > + void add_edges_sorted_internal(BidirectionalIteratorOrig first_sorted, + BidirectionalIteratorOrig last_sorted, EPIterOrig ep_iter_sorted) + { + m_forward.add_edges_sorted_internal(first_sorted, last_sorted, + ep_iter_sorted, + typed_identity_property_map< vertices_size_type >()); + } + + // Add edges from a sorted (smallest sources first) range of pairs + template < typename BidirectionalIteratorOrig > + void add_edges_sorted_internal(BidirectionalIteratorOrig first_sorted, + BidirectionalIteratorOrig last_sorted) + { + m_forward.add_edges_sorted_internal(first_sorted, last_sorted, + detail::default_construct_iterator< edge_bundled >()); + } + + template < typename BidirectionalIteratorOrig, typename GlobalToLocal > + void add_edges_sorted_internal_global( + BidirectionalIteratorOrig first_sorted, + BidirectionalIteratorOrig last_sorted, + const GlobalToLocal& global_to_local) + { + m_forward.add_edges_sorted_internal(first_sorted, last_sorted, + detail::default_construct_iterator< edge_bundled >(), + global_to_local); + } + + template < typename BidirectionalIteratorOrig, typename EPIterOrig, + typename GlobalToLocal > + void add_edges_sorted_internal_global( + BidirectionalIteratorOrig first_sorted, + BidirectionalIteratorOrig last_sorted, EPIterOrig ep_iter_sorted, + const GlobalToLocal& global_to_local) + { + m_forward.add_edges_sorted_internal( + first_sorted, last_sorted, ep_iter_sorted, global_to_local); + } + + // Add edges from a range of (source, target) pairs that are unsorted + template < typename InputIterator, typename GlobalToLocal > + inline void add_edges_internal(InputIterator first, InputIterator last, + const GlobalToLocal& global_to_local) + { + typedef compressed_sparse_row_graph Graph; + typedef + typename boost::graph_traits< Graph >::vertex_descriptor vertex_t; + typedef std::vector< std::pair< vertex_t, vertex_t > > edge_vector_t; + edge_vector_t new_edges(first, last); + if (new_edges.empty()) + return; + std::sort(new_edges.begin(), new_edges.end()); + this->add_edges_sorted_internal_global( + new_edges.begin(), new_edges.end(), global_to_local); + } + + template < typename InputIterator > + inline void add_edges_internal(InputIterator first, InputIterator last) + { + this->add_edges_internal( + first, last, typed_identity_property_map< vertices_size_type >()); + } + + // Add edges from a range of (source, target) pairs and edge properties that + // are unsorted + template < typename InputIterator, typename EPIterator, + typename GlobalToLocal > + inline void add_edges_internal(InputIterator first, InputIterator last, + EPIterator ep_iter, EPIterator ep_iter_end, + const GlobalToLocal& global_to_local) + { + typedef compressed_sparse_row_graph Graph; + typedef + typename boost::graph_traits< Graph >::vertex_descriptor vertex_t; + typedef std::pair< vertex_t, vertex_t > vertex_pair; + typedef std::vector< boost::tuple< vertex_pair, edge_bundled > > + edge_vector_t; + edge_vector_t new_edges( + boost::make_zip_iterator(boost::make_tuple(first, ep_iter)), + boost::make_zip_iterator(boost::make_tuple(last, ep_iter_end))); + if (new_edges.empty()) + return; + std::sort(new_edges.begin(), new_edges.end(), + boost::detail::compare_first< std::less< vertex_pair > >()); + m_forward.add_edges_sorted_internal( + boost::make_transform_iterator(new_edges.begin(), + boost::detail::my_tuple_get_class< 0, vertex_pair >()), + boost::make_transform_iterator(new_edges.end(), + boost::detail::my_tuple_get_class< 0, vertex_pair >()), + boost::make_transform_iterator(new_edges.begin(), + boost::detail::my_tuple_get_class< 1, edge_bundled >()), + global_to_local); + } + + // Add edges from a range of (source, target) pairs and edge properties that + // are unsorted + template < typename InputIterator, typename EPIterator > + inline void add_edges_internal(InputIterator first, InputIterator last, + EPIterator ep_iter, EPIterator ep_iter_end) + { + this->add_edges_internal(first, last, ep_iter, ep_iter_end, + typed_identity_property_map< vertices_size_type >()); + } + + using inherited_vertex_properties::operator[]; + + // Directly access a edge or edge bundle + edge_push_back_type& operator[](const edge_descriptor& v) + { + return m_forward.m_edge_properties[get(edge_index, *this, v)]; } - assign(g, get(vertex_index, g), num_vertices(g), numedges); - } - - // From any graph (slow and uses a lot of memory) - // Requires IncidenceGraph and a vertex index map - // Internal helper function - // Note that numedges must be doubled for undirected source graphs - template<typename Graph, typename VertexIndexMap> - void - assign(const Graph& g, const VertexIndexMap& vi, - vertices_size_type numverts, edges_size_type numedges) - { - m_forward.assign(g, vi, numverts, numedges); - inherited_vertex_properties::resize(numverts); - } - - // Requires the above, plus VertexListGraph and EdgeListGraph - template<typename Graph, typename VertexIndexMap> - void assign(const Graph& g, const VertexIndexMap& vi) - { - typename graph_traits<Graph>::edges_size_type numedges = num_edges(g); - if (is_same<typename graph_traits<Graph>::directed_category, undirectedS>::value) { - numedges *= 2; // Double each edge (actual doubling done by out_edges function) + + const edge_push_back_type& operator[](const edge_descriptor& v) const + { + return m_forward.m_edge_properties[get(edge_index, *this, v)]; + } + + // Directly access a graph bundle + graph_bundled& operator[](graph_bundle_t) { return get_property(*this); } + + const graph_bundled& operator[](graph_bundle_t) const + { + return get_property(*this); + } + + // private: non-portable, requires friend templates + inherited_vertex_properties& vertex_properties() { return *this; } + const inherited_vertex_properties& vertex_properties() const + { + return *this; } - vertices_size_type numverts = num_vertices(g); - m_forward.assign(g, vi, numverts, numedges); - inherited_vertex_properties::resize(numverts); - } - - // Requires the above, plus a vertex_index map. - template<typename Graph> - void assign(const Graph& g) - { - typename graph_traits<Graph>::edges_size_type numedges = num_edges(g); - if (is_same<typename graph_traits<Graph>::directed_category, undirectedS>::value) { - numedges *= 2; // Double each edge (actual doubling done by out_edges function) + typename forward_type::inherited_edge_properties& edge_properties() + { + return m_forward; } - vertices_size_type numverts = num_vertices(g); - m_forward.assign(g, get(vertex_index, g), numverts, numedges); - inherited_vertex_properties::resize(numverts); - } - - // Add edges from a sorted (smallest sources first) range of pairs and edge - // properties - template <typename BidirectionalIteratorOrig, typename EPIterOrig, - typename GlobalToLocal> - void - add_edges_sorted_internal( - BidirectionalIteratorOrig first_sorted, - BidirectionalIteratorOrig last_sorted, - EPIterOrig ep_iter_sorted, - const GlobalToLocal& global_to_local) { - m_forward.add_edges_sorted_internal(first_sorted, last_sorted, ep_iter_sorted, global_to_local); - } - - template <typename BidirectionalIteratorOrig, typename EPIterOrig> - void - add_edges_sorted_internal( - BidirectionalIteratorOrig first_sorted, - BidirectionalIteratorOrig last_sorted, - EPIterOrig ep_iter_sorted) { - m_forward.add_edges_sorted_internal(first_sorted, last_sorted, ep_iter_sorted, typed_identity_property_map<vertices_size_type>()); - } - - // Add edges from a sorted (smallest sources first) range of pairs - template <typename BidirectionalIteratorOrig> - void - add_edges_sorted_internal( - BidirectionalIteratorOrig first_sorted, - BidirectionalIteratorOrig last_sorted) { - m_forward.add_edges_sorted_internal(first_sorted, last_sorted, detail::default_construct_iterator<edge_bundled>()); - } - - template <typename BidirectionalIteratorOrig, typename GlobalToLocal> - void - add_edges_sorted_internal_global( - BidirectionalIteratorOrig first_sorted, - BidirectionalIteratorOrig last_sorted, - const GlobalToLocal& global_to_local) { - m_forward.add_edges_sorted_internal(first_sorted, last_sorted, detail::default_construct_iterator<edge_bundled>(), global_to_local); - } - - template <typename BidirectionalIteratorOrig, typename EPIterOrig, - typename GlobalToLocal> - void - add_edges_sorted_internal_global( - BidirectionalIteratorOrig first_sorted, - BidirectionalIteratorOrig last_sorted, - EPIterOrig ep_iter_sorted, - const GlobalToLocal& global_to_local) { - m_forward.add_edges_sorted_internal(first_sorted, last_sorted, ep_iter_sorted, global_to_local); - } - - // Add edges from a range of (source, target) pairs that are unsorted - template <typename InputIterator, typename GlobalToLocal> - inline void - add_edges_internal(InputIterator first, InputIterator last, - const GlobalToLocal& global_to_local) { - typedef compressed_sparse_row_graph Graph; - typedef typename boost::graph_traits<Graph>::vertex_descriptor vertex_t; - typedef std::vector<std::pair<vertex_t, vertex_t> > edge_vector_t; - edge_vector_t new_edges(first, last); - if (new_edges.empty()) return; - std::sort(new_edges.begin(), new_edges.end()); - this->add_edges_sorted_internal_global(new_edges.begin(), new_edges.end(), global_to_local); - } - - template <typename InputIterator> - inline void - add_edges_internal(InputIterator first, InputIterator last) { - this->add_edges_internal(first, last, typed_identity_property_map<vertices_size_type>()); - } - - // Add edges from a range of (source, target) pairs and edge properties that - // are unsorted - template <typename InputIterator, typename EPIterator, typename GlobalToLocal> - inline void - add_edges_internal(InputIterator first, InputIterator last, - EPIterator ep_iter, EPIterator ep_iter_end, - const GlobalToLocal& global_to_local) { - typedef compressed_sparse_row_graph Graph; - typedef typename boost::graph_traits<Graph>::vertex_descriptor vertex_t; - typedef std::pair<vertex_t, vertex_t> vertex_pair; - typedef std::vector< - boost::tuple<vertex_pair, - edge_bundled> > - edge_vector_t; - edge_vector_t new_edges - (boost::make_zip_iterator(boost::make_tuple(first, ep_iter)), - boost::make_zip_iterator(boost::make_tuple(last, ep_iter_end))); - if (new_edges.empty()) return; - std::sort(new_edges.begin(), new_edges.end(), - boost::detail::compare_first< - std::less<vertex_pair> >()); - m_forward.add_edges_sorted_internal - (boost::make_transform_iterator( - new_edges.begin(), - boost::detail::my_tuple_get_class<0, vertex_pair>()), - boost::make_transform_iterator( - new_edges.end(), - boost::detail::my_tuple_get_class<0, vertex_pair>()), - boost::make_transform_iterator( - new_edges.begin(), - boost::detail::my_tuple_get_class - <1, edge_bundled>()), - global_to_local); - } - - // Add edges from a range of (source, target) pairs and edge properties that - // are unsorted - template <typename InputIterator, typename EPIterator> - inline void - add_edges_internal(InputIterator first, InputIterator last, - EPIterator ep_iter, EPIterator ep_iter_end) { - this->add_edges_internal(first, last, ep_iter, ep_iter_end, typed_identity_property_map<vertices_size_type>()); - } - - using inherited_vertex_properties::operator[]; - - // Directly access a edge or edge bundle - edge_push_back_type& operator[](const edge_descriptor& v) - { return m_forward.m_edge_properties[get(edge_index, *this, v)]; } - - const edge_push_back_type& operator[](const edge_descriptor& v) const - { return m_forward.m_edge_properties[get(edge_index, *this, v)]; } - - // Directly access a graph bundle - graph_bundled& operator[](graph_bundle_t) - { return get_property(*this); } - - const graph_bundled& operator[](graph_bundle_t) const - { return get_property(*this); } - - // private: non-portable, requires friend templates - inherited_vertex_properties& vertex_properties() {return *this;} - const inherited_vertex_properties& vertex_properties() const {return *this;} - typename forward_type::inherited_edge_properties& edge_properties() { return m_forward; } - const typename forward_type::inherited_edge_properties& edge_properties() const { return m_forward; } - - forward_type m_forward; - GraphProperty m_property; + const typename forward_type::inherited_edge_properties& + edge_properties() const + { + return m_forward; + } + + forward_type m_forward; + GraphProperty m_property; }; -template<typename VertexProperty, - typename EdgeProperty, - typename GraphProperty, - typename Vertex, - typename EdgeIndex> -class compressed_sparse_row_graph<bidirectionalS, VertexProperty, EdgeProperty, GraphProperty, Vertex, EdgeIndex> - : public detail::indexed_vertex_properties<BOOST_BIDIR_CSR_GRAPH_TYPE, - VertexProperty, Vertex, typed_identity_property_map<Vertex> > -{ - public: - typedef detail::indexed_vertex_properties<compressed_sparse_row_graph, - VertexProperty, Vertex, typed_identity_property_map<Vertex> > - inherited_vertex_properties; - - public: - // For Property Graph - typedef GraphProperty graph_property_type; - typedef typename lookup_one_property<GraphProperty, graph_bundle_t>::type graph_bundled; - // typedef GraphProperty graph_property_type; - - typedef detail::compressed_sparse_row_structure<EdgeProperty, Vertex, EdgeIndex> forward_type; - typedef EdgeIndex /* typename boost::mpl::if_c<boost::is_same<EdgeProperty, boost::no_property>, boost::no_property, EdgeIndex> */ backward_edge_property; - typedef detail::compressed_sparse_row_structure<backward_edge_property, Vertex, EdgeIndex> backward_type; - - public: - // Concept requirements: - // For Graph - typedef Vertex vertex_descriptor; - typedef detail::csr_edge_descriptor<Vertex, EdgeIndex> edge_descriptor; - typedef bidirectional_tag directed_category; - typedef allow_parallel_edge_tag edge_parallel_category; - - class traversal_category: public bidirectional_graph_tag, - public adjacency_graph_tag, - public vertex_list_graph_tag, - public edge_list_graph_tag {}; - - static vertex_descriptor null_vertex() { return vertex_descriptor(-1); } - - // For VertexListGraph - typedef counting_iterator<Vertex> vertex_iterator; - typedef Vertex vertices_size_type; - - // For EdgeListGraph - typedef EdgeIndex edges_size_type; - - // For IncidenceGraph - typedef detail::csr_out_edge_iterator<compressed_sparse_row_graph> out_edge_iterator; - typedef EdgeIndex degree_size_type; - - // For AdjacencyGraph - typedef typename std::vector<Vertex>::const_iterator adjacency_iterator; - - // For EdgeListGraph - typedef detail::csr_edge_iterator<compressed_sparse_row_graph> edge_iterator; - - // For BidirectionalGraph (not implemented) - typedef detail::csr_in_edge_iterator<compressed_sparse_row_graph> in_edge_iterator; - - // For internal use - typedef csr_graph_tag graph_tag; - - typedef typename forward_type::inherited_edge_properties::edge_bundled edge_bundled; - typedef typename forward_type::inherited_edge_properties::edge_push_back_type edge_push_back_type; - typedef typename forward_type::inherited_edge_properties::edge_property_type edge_property_type; - - // Constructors - - // Default constructor: an empty graph. - compressed_sparse_row_graph(): m_property() {} - - // With numverts vertices - compressed_sparse_row_graph(vertices_size_type numverts) - : inherited_vertex_properties(numverts), - m_forward(numverts), m_backward(numverts) {} - - private: - - void set_up_backward_property_links() { - std::pair<edge_iterator, edge_iterator> e = edges(*this); - m_backward.assign_unsorted_multi_pass_edges - (detail::transpose_edges( - detail::make_edge_to_index_pair_iter - (*this, get(vertex_index, *this), e.first)), - detail::transpose_edges( - detail::make_edge_to_index_pair_iter - (*this, get(vertex_index, *this), e.second)), - boost::counting_iterator<EdgeIndex>(0), - m_forward.m_rowstart.size() - 1, - typed_identity_property_map<Vertex>(), - keep_all()); - } - - public: - - // From number of vertices and unsorted list of edges - template <typename MultiPassInputIterator> - compressed_sparse_row_graph(edges_are_unsorted_multi_pass_t, - MultiPassInputIterator edge_begin, - MultiPassInputIterator edge_end, - vertices_size_type numverts, - const GraphProperty& prop = GraphProperty()) +template < typename VertexProperty, typename EdgeProperty, + typename GraphProperty, typename Vertex, typename EdgeIndex > +class compressed_sparse_row_graph< bidirectionalS, VertexProperty, EdgeProperty, + GraphProperty, Vertex, EdgeIndex > +: public detail::indexed_vertex_properties< BOOST_BIDIR_CSR_GRAPH_TYPE, + VertexProperty, Vertex, typed_identity_property_map< Vertex > > +{ +public: + typedef detail::indexed_vertex_properties< compressed_sparse_row_graph, + VertexProperty, Vertex, typed_identity_property_map< Vertex > > + inherited_vertex_properties; + +public: + // For Property Graph + typedef GraphProperty graph_property_type; + typedef typename lookup_one_property< GraphProperty, graph_bundle_t >::type + graph_bundled; + // typedef GraphProperty graph_property_type; + + typedef detail::compressed_sparse_row_structure< EdgeProperty, Vertex, + EdgeIndex > + forward_type; + typedef EdgeIndex /* typename boost::mpl::if_c<boost::is_same<EdgeProperty, + boost::no_property>, boost::no_property, EdgeIndex> */ + backward_edge_property; + typedef detail::compressed_sparse_row_structure< backward_edge_property, + Vertex, EdgeIndex > + backward_type; + +public: + // Concept requirements: + // For Graph + typedef Vertex vertex_descriptor; + typedef detail::csr_edge_descriptor< Vertex, EdgeIndex > edge_descriptor; + typedef bidirectional_tag directed_category; + typedef allow_parallel_edge_tag edge_parallel_category; + + class traversal_category : public bidirectional_graph_tag, + public adjacency_graph_tag, + public vertex_list_graph_tag, + public edge_list_graph_tag + { + }; + + static vertex_descriptor null_vertex() { return vertex_descriptor(-1); } + + // For VertexListGraph + typedef counting_iterator< Vertex > vertex_iterator; + typedef Vertex vertices_size_type; + + // For EdgeListGraph + typedef EdgeIndex edges_size_type; + + // For IncidenceGraph + typedef detail::csr_out_edge_iterator< compressed_sparse_row_graph > + out_edge_iterator; + typedef EdgeIndex degree_size_type; + + // For AdjacencyGraph + typedef typename std::vector< Vertex >::const_iterator adjacency_iterator; + + // For EdgeListGraph + typedef detail::csr_edge_iterator< compressed_sparse_row_graph > + edge_iterator; + + // For BidirectionalGraph (not implemented) + typedef detail::csr_in_edge_iterator< compressed_sparse_row_graph > + in_edge_iterator; + + // For internal use + typedef csr_graph_tag graph_tag; + + typedef typename forward_type::inherited_edge_properties::edge_bundled + edge_bundled; + typedef + typename forward_type::inherited_edge_properties::edge_push_back_type + edge_push_back_type; + typedef typename forward_type::inherited_edge_properties::edge_property_type + edge_property_type; + + // Constructors + + // Default constructor: an empty graph. + compressed_sparse_row_graph() : m_property() {} + + // With numverts vertices + compressed_sparse_row_graph(vertices_size_type numverts) + : inherited_vertex_properties(numverts) + , m_forward(numverts) + , m_backward(numverts) + { + } + +private: + void set_up_backward_property_links() + { + std::pair< edge_iterator, edge_iterator > e = edges(*this); + m_backward.assign_unsorted_multi_pass_edges( + detail::transpose_edges(detail::make_edge_to_index_pair_iter( + *this, get(vertex_index, *this), e.first)), + detail::transpose_edges(detail::make_edge_to_index_pair_iter( + *this, get(vertex_index, *this), e.second)), + boost::counting_iterator< EdgeIndex >(0), + m_forward.m_rowstart.size() - 1, + typed_identity_property_map< Vertex >(), keep_all()); + } + +public: + // From number of vertices and unsorted list of edges + template < typename MultiPassInputIterator > + compressed_sparse_row_graph(edges_are_unsorted_multi_pass_t, + MultiPassInputIterator edge_begin, MultiPassInputIterator edge_end, + vertices_size_type numverts, + const GraphProperty& prop = GraphProperty()) : inherited_vertex_properties(numverts), m_property(prop) - { - m_forward.assign_unsorted_multi_pass_edges(edge_begin, edge_end, numverts, typed_identity_property_map<Vertex>(), keep_all()); - set_up_backward_property_links(); - } - - // From number of vertices and unsorted list of edges, plus edge properties - template <typename MultiPassInputIterator, typename EdgePropertyIterator> - compressed_sparse_row_graph(edges_are_unsorted_multi_pass_t, - MultiPassInputIterator edge_begin, - MultiPassInputIterator edge_end, - EdgePropertyIterator ep_iter, - vertices_size_type numverts, - const GraphProperty& prop = GraphProperty()) + { + m_forward.assign_unsorted_multi_pass_edges(edge_begin, edge_end, + numverts, typed_identity_property_map< Vertex >(), keep_all()); + set_up_backward_property_links(); + } + + // From number of vertices and unsorted list of edges, plus edge properties + template < typename MultiPassInputIterator, typename EdgePropertyIterator > + compressed_sparse_row_graph(edges_are_unsorted_multi_pass_t, + MultiPassInputIterator edge_begin, MultiPassInputIterator edge_end, + EdgePropertyIterator ep_iter, vertices_size_type numverts, + const GraphProperty& prop = GraphProperty()) : inherited_vertex_properties(numverts), m_forward(), m_property(prop) - { - m_forward.assign_unsorted_multi_pass_edges(edge_begin, edge_end, ep_iter, numverts, typed_identity_property_map<Vertex>(), keep_all()); - set_up_backward_property_links(); - } - - // From number of vertices and unsorted list of edges, with filter and - // global-to-local map - template <typename MultiPassInputIterator, typename GlobalToLocal, typename SourcePred> - compressed_sparse_row_graph(edges_are_unsorted_multi_pass_global_t, - MultiPassInputIterator edge_begin, - MultiPassInputIterator edge_end, - vertices_size_type numlocalverts, - const GlobalToLocal& global_to_local, - const SourcePred& source_pred, - const GraphProperty& prop = GraphProperty()) + { + m_forward.assign_unsorted_multi_pass_edges(edge_begin, edge_end, + ep_iter, numverts, typed_identity_property_map< Vertex >(), + keep_all()); + set_up_backward_property_links(); + } + + // From number of vertices and unsorted list of edges, with filter and + // global-to-local map + template < typename MultiPassInputIterator, typename GlobalToLocal, + typename SourcePred > + compressed_sparse_row_graph(edges_are_unsorted_multi_pass_global_t, + MultiPassInputIterator edge_begin, MultiPassInputIterator edge_end, + vertices_size_type numlocalverts, const GlobalToLocal& global_to_local, + const SourcePred& source_pred, + const GraphProperty& prop = GraphProperty()) : inherited_vertex_properties(numlocalverts), m_forward(), m_property(prop) - { - m_forward.assign_unsorted_multi_pass_edges(edge_begin, edge_end, numlocalverts, global_to_local, source_pred); - set_up_backward_property_links(); - } - - // From number of vertices and unsorted list of edges, plus edge properties, - // with filter and global-to-local map - template <typename MultiPassInputIterator, typename EdgePropertyIterator, typename GlobalToLocal, typename SourcePred> - compressed_sparse_row_graph(edges_are_unsorted_multi_pass_global_t, - MultiPassInputIterator edge_begin, - MultiPassInputIterator edge_end, - EdgePropertyIterator ep_iter, - vertices_size_type numlocalverts, - const GlobalToLocal& global_to_local, - const SourcePred& source_pred, - const GraphProperty& prop = GraphProperty()) + { + m_forward.assign_unsorted_multi_pass_edges( + edge_begin, edge_end, numlocalverts, global_to_local, source_pred); + set_up_backward_property_links(); + } + + // From number of vertices and unsorted list of edges, plus edge + // properties, with filter and global-to-local map + template < typename MultiPassInputIterator, typename EdgePropertyIterator, + typename GlobalToLocal, typename SourcePred > + compressed_sparse_row_graph(edges_are_unsorted_multi_pass_global_t, + MultiPassInputIterator edge_begin, MultiPassInputIterator edge_end, + EdgePropertyIterator ep_iter, vertices_size_type numlocalverts, + const GlobalToLocal& global_to_local, const SourcePred& source_pred, + const GraphProperty& prop = GraphProperty()) : inherited_vertex_properties(numlocalverts), m_forward(), m_property(prop) - { - m_forward.assign_unsorted_multi_pass_edges(edge_begin, edge_end, ep_iter, numlocalverts, global_to_local, source_pred); - set_up_backward_property_links(); - } - - // Requires IncidenceGraph and a vertex index map - template<typename Graph, typename VertexIndexMap> - compressed_sparse_row_graph(const Graph& g, const VertexIndexMap& vi, - vertices_size_type numverts, - edges_size_type numedges) - : m_property() - { - assign(g, vi, numverts, numedges); - inherited_vertex_properties::resize(numverts); - } - - // Requires VertexListGraph and EdgeListGraph - template<typename Graph, typename VertexIndexMap> - compressed_sparse_row_graph(const Graph& g, const VertexIndexMap& vi) + { + m_forward.assign_unsorted_multi_pass_edges(edge_begin, edge_end, + ep_iter, numlocalverts, global_to_local, source_pred); + set_up_backward_property_links(); + } + + // Requires IncidenceGraph and a vertex index map + template < typename Graph, typename VertexIndexMap > + compressed_sparse_row_graph(const Graph& g, const VertexIndexMap& vi, + vertices_size_type numverts, edges_size_type numedges) : m_property() - { - typename graph_traits<Graph>::edges_size_type numedges = num_edges(g); - if (is_same<typename graph_traits<Graph>::directed_category, undirectedS>::value) { - numedges *= 2; // Double each edge (actual doubling done by out_edges function) + { + assign(g, vi, numverts, numedges); + inherited_vertex_properties::resize(numverts); } - vertices_size_type numverts = num_vertices(g); - assign(g, vi, numverts, numedges); - inherited_vertex_properties::resize(numverts); - } - - // Requires vertex index map plus requirements of previous constructor - template<typename Graph> - explicit compressed_sparse_row_graph(const Graph& g) + + // Requires VertexListGraph and EdgeListGraph + template < typename Graph, typename VertexIndexMap > + compressed_sparse_row_graph(const Graph& g, const VertexIndexMap& vi) : m_property() - { - typename graph_traits<Graph>::edges_size_type numedges = num_edges(g); - if (is_same<typename graph_traits<Graph>::directed_category, undirectedS>::value) { - numedges *= 2; // Double each edge (actual doubling done by out_edges function) + { + typename graph_traits< Graph >::edges_size_type numedges = num_edges(g); + if (is_same< typename graph_traits< Graph >::directed_category, + undirectedS >::value) + { + numedges *= 2; // Double each edge (actual doubling done by + // out_edges function) + } + vertices_size_type numverts = num_vertices(g); + assign(g, vi, numverts, numedges); + inherited_vertex_properties::resize(numverts); + } + + // Requires vertex index map plus requirements of previous constructor + template < typename Graph > + explicit compressed_sparse_row_graph(const Graph& g) : m_property() + { + typename graph_traits< Graph >::edges_size_type numedges = num_edges(g); + if (is_same< typename graph_traits< Graph >::directed_category, + undirectedS >::value) + { + numedges *= 2; // Double each edge (actual doubling done by + // out_edges function) + } + assign(g, get(vertex_index, g), num_vertices(g), numedges); } - assign(g, get(vertex_index, g), num_vertices(g), numedges); - } - - // From any graph (slow and uses a lot of memory) - // Requires IncidenceGraph and a vertex index map - // Internal helper function - // Note that numedges must be doubled for undirected source graphs - template<typename Graph, typename VertexIndexMap> - void - assign(const Graph& g, const VertexIndexMap& vi, - vertices_size_type numverts, edges_size_type numedges) - { - m_forward.assign(g, vi, numverts, numedges); - inherited_vertex_properties::resize(numverts); - set_up_backward_property_links(); - } - - // Requires the above, plus VertexListGraph and EdgeListGraph - template<typename Graph, typename VertexIndexMap> - void assign(const Graph& g, const VertexIndexMap& vi) - { - typename graph_traits<Graph>::edges_size_type numedges = num_edges(g); - if (is_same<typename graph_traits<Graph>::directed_category, undirectedS>::value) { - numedges *= 2; // Double each edge (actual doubling done by out_edges function) + + // From any graph (slow and uses a lot of memory) + // Requires IncidenceGraph and a vertex index map + // Internal helper function + // Note that numedges must be doubled for undirected source graphs + template < typename Graph, typename VertexIndexMap > + void assign(const Graph& g, const VertexIndexMap& vi, + vertices_size_type numverts, edges_size_type numedges) + { + m_forward.assign(g, vi, numverts, numedges); + inherited_vertex_properties::resize(numverts); + set_up_backward_property_links(); } - vertices_size_type numverts = num_vertices(g); - m_forward.assign(g, vi, numverts, numedges); - inherited_vertex_properties::resize(numverts); - set_up_backward_property_links(); - } - - // Requires the above, plus a vertex_index map. - template<typename Graph> - void assign(const Graph& g) - { - typename graph_traits<Graph>::edges_size_type numedges = num_edges(g); - if (is_same<typename graph_traits<Graph>::directed_category, undirectedS>::value) { - numedges *= 2; // Double each edge (actual doubling done by out_edges function) + + // Requires the above, plus VertexListGraph and EdgeListGraph + template < typename Graph, typename VertexIndexMap > + void assign(const Graph& g, const VertexIndexMap& vi) + { + typename graph_traits< Graph >::edges_size_type numedges = num_edges(g); + if (is_same< typename graph_traits< Graph >::directed_category, + undirectedS >::value) + { + numedges *= 2; // Double each edge (actual doubling done by + // out_edges function) + } + vertices_size_type numverts = num_vertices(g); + m_forward.assign(g, vi, numverts, numedges); + inherited_vertex_properties::resize(numverts); + set_up_backward_property_links(); } - vertices_size_type numverts = num_vertices(g); - m_forward.assign(g, get(vertex_index, g), numverts, numedges); - inherited_vertex_properties::resize(numverts); - set_up_backward_property_links(); - } - - using inherited_vertex_properties::operator[]; - - // Directly access a edge or edge bundle - edge_push_back_type& operator[](const edge_descriptor& v) - { return m_forward.m_edge_properties[get(edge_index, *this, v)]; } - - const edge_push_back_type& operator[](const edge_descriptor& v) const - { return m_forward.m_edge_properties[get(edge_index, *this, v)]; } - - // private: non-portable, requires friend templates - inherited_vertex_properties& vertex_properties() {return *this;} - const inherited_vertex_properties& vertex_properties() const {return *this;} - typename forward_type::inherited_edge_properties& edge_properties() { return m_forward; } - const typename forward_type::inherited_edge_properties& edge_properties() const { return m_forward; } - - forward_type m_forward; - backward_type m_backward; - GraphProperty m_property; + + // Requires the above, plus a vertex_index map. + template < typename Graph > void assign(const Graph& g) + { + typename graph_traits< Graph >::edges_size_type numedges = num_edges(g); + if (is_same< typename graph_traits< Graph >::directed_category, + undirectedS >::value) + { + numedges *= 2; // Double each edge (actual doubling done by + // out_edges function) + } + vertices_size_type numverts = num_vertices(g); + m_forward.assign(g, get(vertex_index, g), numverts, numedges); + inherited_vertex_properties::resize(numverts); + set_up_backward_property_links(); + } + + using inherited_vertex_properties::operator[]; + + // Directly access a edge or edge bundle + edge_push_back_type& operator[](const edge_descriptor& v) + { + return m_forward.m_edge_properties[get(edge_index, *this, v)]; + } + + const edge_push_back_type& operator[](const edge_descriptor& v) const + { + return m_forward.m_edge_properties[get(edge_index, *this, v)]; + } + + // private: non-portable, requires friend templates + inherited_vertex_properties& vertex_properties() { return *this; } + const inherited_vertex_properties& vertex_properties() const + { + return *this; + } + typename forward_type::inherited_edge_properties& edge_properties() + { + return m_forward; + } + const typename forward_type::inherited_edge_properties& + edge_properties() const + { + return m_forward; + } + + forward_type m_forward; + backward_type m_backward; + GraphProperty m_property; }; // Construction functions -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline Vertex -add_vertex(BOOST_CSR_GRAPH_TYPE& g) { - add_vertex(g, typename BOOST_CSR_GRAPH_TYPE::vertex_bundled()); +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline Vertex add_vertex(BOOST_CSR_GRAPH_TYPE& g) +{ + add_vertex(g, typename BOOST_CSR_GRAPH_TYPE::vertex_bundled()); } -template<BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS> -inline Vertex -add_vertex(BOOST_DIR_CSR_GRAPH_TYPE& g, - typename BOOST_DIR_CSR_GRAPH_TYPE::vertex_bundled const& p) { - Vertex old_num_verts_plus_one = g.m_forward.m_rowstart.size(); - g.m_forward.m_rowstart.push_back(g.m_forward.m_rowstart.back()); - g.vertex_properties().push_back(p); - return old_num_verts_plus_one - 1; +template < BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS > +inline Vertex add_vertex(BOOST_DIR_CSR_GRAPH_TYPE& g, + typename BOOST_DIR_CSR_GRAPH_TYPE::vertex_bundled const& p) +{ + Vertex old_num_verts_plus_one = g.m_forward.m_rowstart.size(); + g.m_forward.m_rowstart.push_back(g.m_forward.m_rowstart.back()); + g.vertex_properties().push_back(p); + return old_num_verts_plus_one - 1; } -template<BOOST_BIDIR_CSR_GRAPH_TEMPLATE_PARMS> -inline Vertex -add_vertex(BOOST_BIDIR_CSR_GRAPH_TYPE& g, - typename BOOST_BIDIR_CSR_GRAPH_TYPE::vertex_bundled const& p) { - Vertex old_num_verts_plus_one = g.m_forward.m_rowstart.size(); - g.m_forward.m_rowstart.push_back(g.m_forward.m_rowstart.back()); - g.m_backward.m_rowstart.push_back(g.m_backward.m_rowstart.back()); - g.vertex_properties().push_back(p); - return old_num_verts_plus_one - 1; +template < BOOST_BIDIR_CSR_GRAPH_TEMPLATE_PARMS > +inline Vertex add_vertex(BOOST_BIDIR_CSR_GRAPH_TYPE& g, + typename BOOST_BIDIR_CSR_GRAPH_TYPE::vertex_bundled const& p) +{ + Vertex old_num_verts_plus_one = g.m_forward.m_rowstart.size(); + g.m_forward.m_rowstart.push_back(g.m_forward.m_rowstart.back()); + g.m_backward.m_rowstart.push_back(g.m_backward.m_rowstart.back()); + g.vertex_properties().push_back(p); + return old_num_verts_plus_one - 1; } -template<BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS> -inline Vertex -add_vertices(typename BOOST_DIR_CSR_GRAPH_TYPE::vertices_size_type count, BOOST_DIR_CSR_GRAPH_TYPE& g) { - Vertex old_num_verts_plus_one = g.m_forward.m_rowstart.size(); - EdgeIndex numedges = g.m_forward.m_rowstart.back(); - g.m_forward.m_rowstart.resize(old_num_verts_plus_one + count, numedges); - g.vertex_properties().resize(num_vertices(g)); - return old_num_verts_plus_one - 1; +template < BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS > +inline Vertex add_vertices( + typename BOOST_DIR_CSR_GRAPH_TYPE::vertices_size_type count, + BOOST_DIR_CSR_GRAPH_TYPE& g) +{ + Vertex old_num_verts_plus_one = g.m_forward.m_rowstart.size(); + EdgeIndex numedges = g.m_forward.m_rowstart.back(); + g.m_forward.m_rowstart.resize(old_num_verts_plus_one + count, numedges); + g.vertex_properties().resize(num_vertices(g)); + return old_num_verts_plus_one - 1; } - // Add edges from a sorted (smallest sources first) range of pairs and edge - // properties - template <BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS, typename BidirectionalIteratorOrig, - typename EPIterOrig> - void - add_edges_sorted( - BidirectionalIteratorOrig first_sorted, - BidirectionalIteratorOrig last_sorted, - EPIterOrig ep_iter_sorted, - BOOST_DIR_CSR_GRAPH_TYPE& g) { +// Add edges from a sorted (smallest sources first) range of pairs and edge +// properties +template < BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS, + typename BidirectionalIteratorOrig, typename EPIterOrig > +void add_edges_sorted(BidirectionalIteratorOrig first_sorted, + BidirectionalIteratorOrig last_sorted, EPIterOrig ep_iter_sorted, + BOOST_DIR_CSR_GRAPH_TYPE& g) +{ g.add_edges_sorted_internal(first_sorted, last_sorted, ep_iter_sorted); - } - - // Add edges from a sorted (smallest sources first) range of pairs - template <BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS, typename BidirectionalIteratorOrig> - void - add_edges_sorted( - BidirectionalIteratorOrig first_sorted, - BidirectionalIteratorOrig last_sorted, - BOOST_DIR_CSR_GRAPH_TYPE& g) { +} + +// Add edges from a sorted (smallest sources first) range of pairs +template < BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS, + typename BidirectionalIteratorOrig > +void add_edges_sorted(BidirectionalIteratorOrig first_sorted, + BidirectionalIteratorOrig last_sorted, BOOST_DIR_CSR_GRAPH_TYPE& g) +{ g.add_edges_sorted_internal(first_sorted, last_sorted); - } - - template <BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS, typename BidirectionalIteratorOrig, - typename EPIterOrig, typename GlobalToLocal> - void - add_edges_sorted_global( - BidirectionalIteratorOrig first_sorted, - BidirectionalIteratorOrig last_sorted, - EPIterOrig ep_iter_sorted, - const GlobalToLocal& global_to_local, - BOOST_DIR_CSR_GRAPH_TYPE& g) { - g.add_edges_sorted_internal_global(first_sorted, last_sorted, ep_iter_sorted, - global_to_local); - } - - // Add edges from a sorted (smallest sources first) range of pairs - template <BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS, typename BidirectionalIteratorOrig, - typename GlobalToLocal> - void - add_edges_sorted_global( - BidirectionalIteratorOrig first_sorted, - BidirectionalIteratorOrig last_sorted, - const GlobalToLocal& global_to_local, - BOOST_DIR_CSR_GRAPH_TYPE& g) { - g.add_edges_sorted_internal_global(first_sorted, last_sorted, global_to_local); - } - - // Add edges from a range of (source, target) pairs that are unsorted - template <BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS, typename InputIterator, - typename GlobalToLocal> - inline void - add_edges_global(InputIterator first, InputIterator last, - const GlobalToLocal& global_to_local, BOOST_DIR_CSR_GRAPH_TYPE& g) { +} + +template < BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS, + typename BidirectionalIteratorOrig, typename EPIterOrig, + typename GlobalToLocal > +void add_edges_sorted_global(BidirectionalIteratorOrig first_sorted, + BidirectionalIteratorOrig last_sorted, EPIterOrig ep_iter_sorted, + const GlobalToLocal& global_to_local, BOOST_DIR_CSR_GRAPH_TYPE& g) +{ + g.add_edges_sorted_internal_global( + first_sorted, last_sorted, ep_iter_sorted, global_to_local); +} + +// Add edges from a sorted (smallest sources first) range of pairs +template < BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS, + typename BidirectionalIteratorOrig, typename GlobalToLocal > +void add_edges_sorted_global(BidirectionalIteratorOrig first_sorted, + BidirectionalIteratorOrig last_sorted, const GlobalToLocal& global_to_local, + BOOST_DIR_CSR_GRAPH_TYPE& g) +{ + g.add_edges_sorted_internal_global( + first_sorted, last_sorted, global_to_local); +} + +// Add edges from a range of (source, target) pairs that are unsorted +template < BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS, typename InputIterator, + typename GlobalToLocal > +inline void add_edges_global(InputIterator first, InputIterator last, + const GlobalToLocal& global_to_local, BOOST_DIR_CSR_GRAPH_TYPE& g) +{ g.add_edges_internal(first, last, global_to_local); - } +} - // Add edges from a range of (source, target) pairs that are unsorted - template <BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS, typename InputIterator> - inline void - add_edges(InputIterator first, InputIterator last, BOOST_DIR_CSR_GRAPH_TYPE& g) { +// Add edges from a range of (source, target) pairs that are unsorted +template < BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS, typename InputIterator > +inline void add_edges( + InputIterator first, InputIterator last, BOOST_DIR_CSR_GRAPH_TYPE& g) +{ g.add_edges_internal(first, last); - } - - // Add edges from a range of (source, target) pairs and edge properties that - // are unsorted - template <BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS, - typename InputIterator, typename EPIterator> - inline void - add_edges(InputIterator first, InputIterator last, - EPIterator ep_iter, EPIterator ep_iter_end, - BOOST_DIR_CSR_GRAPH_TYPE& g) { +} + +// Add edges from a range of (source, target) pairs and edge properties that +// are unsorted +template < BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS, typename InputIterator, + typename EPIterator > +inline void add_edges(InputIterator first, InputIterator last, + EPIterator ep_iter, EPIterator ep_iter_end, BOOST_DIR_CSR_GRAPH_TYPE& g) +{ g.add_edges_internal(first, last, ep_iter, ep_iter_end); - } - - template <BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS, - typename InputIterator, typename EPIterator, typename GlobalToLocal> - inline void - add_edges_global(InputIterator first, InputIterator last, - EPIterator ep_iter, EPIterator ep_iter_end, - const GlobalToLocal& global_to_local, - BOOST_DIR_CSR_GRAPH_TYPE& g) { +} + +template < BOOST_DIR_CSR_GRAPH_TEMPLATE_PARMS, typename InputIterator, + typename EPIterator, typename GlobalToLocal > +inline void add_edges_global(InputIterator first, InputIterator last, + EPIterator ep_iter, EPIterator ep_iter_end, + const GlobalToLocal& global_to_local, BOOST_DIR_CSR_GRAPH_TYPE& g) +{ g.add_edges_internal(first, last, ep_iter, ep_iter_end, global_to_local); - } +} // From VertexListGraph -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline Vertex -num_vertices(const BOOST_CSR_GRAPH_TYPE& g) { - return g.m_forward.m_rowstart.size() - 1; +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline Vertex num_vertices(const BOOST_CSR_GRAPH_TYPE& g) +{ + return g.m_forward.m_rowstart.size() - 1; } -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -std::pair<counting_iterator<Vertex>, counting_iterator<Vertex> > -inline vertices(const BOOST_CSR_GRAPH_TYPE& g) { - return std::make_pair(counting_iterator<Vertex>(0), - counting_iterator<Vertex>(num_vertices(g))); +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +std::pair< counting_iterator< Vertex >, + counting_iterator< Vertex > > inline vertices(const BOOST_CSR_GRAPH_TYPE& g) +{ + return std::make_pair(counting_iterator< Vertex >(0), + counting_iterator< Vertex >(num_vertices(g))); } // From IncidenceGraph -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline Vertex -source(typename BOOST_CSR_GRAPH_TYPE::edge_descriptor e, - const BOOST_CSR_GRAPH_TYPE&) +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline Vertex source(typename BOOST_CSR_GRAPH_TYPE::edge_descriptor e, + const BOOST_CSR_GRAPH_TYPE&) { - return e.src; + return e.src; } -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline Vertex -target(typename BOOST_CSR_GRAPH_TYPE::edge_descriptor e, - const BOOST_CSR_GRAPH_TYPE& g) +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline Vertex target(typename BOOST_CSR_GRAPH_TYPE::edge_descriptor e, + const BOOST_CSR_GRAPH_TYPE& g) { - return g.m_forward.m_column[e.idx]; + return g.m_forward.m_column[e.idx]; } -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline std::pair<typename BOOST_CSR_GRAPH_TYPE::out_edge_iterator, - typename BOOST_CSR_GRAPH_TYPE::out_edge_iterator> +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline std::pair< typename BOOST_CSR_GRAPH_TYPE::out_edge_iterator, + typename BOOST_CSR_GRAPH_TYPE::out_edge_iterator > out_edges(Vertex v, const BOOST_CSR_GRAPH_TYPE& g) { - typedef typename BOOST_CSR_GRAPH_TYPE::edge_descriptor ed; - typedef typename BOOST_CSR_GRAPH_TYPE::out_edge_iterator it; - EdgeIndex v_row_start = g.m_forward.m_rowstart[v]; - EdgeIndex next_row_start = g.m_forward.m_rowstart[v + 1]; - return std::make_pair(it(ed(v, v_row_start)), - it(ed(v, next_row_start))); + typedef typename BOOST_CSR_GRAPH_TYPE::edge_descriptor ed; + typedef typename BOOST_CSR_GRAPH_TYPE::out_edge_iterator it; + EdgeIndex v_row_start = g.m_forward.m_rowstart[v]; + EdgeIndex next_row_start = g.m_forward.m_rowstart[v + 1]; + return std::make_pair(it(ed(v, v_row_start)), it(ed(v, next_row_start))); } -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline EdgeIndex -out_degree(Vertex v, const BOOST_CSR_GRAPH_TYPE& g) +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline EdgeIndex out_degree(Vertex v, const BOOST_CSR_GRAPH_TYPE& g) { - EdgeIndex v_row_start = g.m_forward.m_rowstart[v]; - EdgeIndex next_row_start = g.m_forward.m_rowstart[v + 1]; - return next_row_start - v_row_start; + EdgeIndex v_row_start = g.m_forward.m_rowstart[v]; + EdgeIndex next_row_start = g.m_forward.m_rowstart[v + 1]; + return next_row_start - v_row_start; } -template<BOOST_BIDIR_CSR_GRAPH_TEMPLATE_PARMS> -inline std::pair<typename BOOST_BIDIR_CSR_GRAPH_TYPE::in_edge_iterator, - typename BOOST_BIDIR_CSR_GRAPH_TYPE::in_edge_iterator> +template < BOOST_BIDIR_CSR_GRAPH_TEMPLATE_PARMS > +inline std::pair< typename BOOST_BIDIR_CSR_GRAPH_TYPE::in_edge_iterator, + typename BOOST_BIDIR_CSR_GRAPH_TYPE::in_edge_iterator > in_edges(Vertex v, const BOOST_BIDIR_CSR_GRAPH_TYPE& g) { - typedef typename BOOST_BIDIR_CSR_GRAPH_TYPE::in_edge_iterator it; - EdgeIndex v_row_start = g.m_backward.m_rowstart[v]; - EdgeIndex next_row_start = g.m_backward.m_rowstart[v + 1]; - return std::make_pair(it(g, v_row_start), - it(g, next_row_start)); + typedef typename BOOST_BIDIR_CSR_GRAPH_TYPE::in_edge_iterator it; + EdgeIndex v_row_start = g.m_backward.m_rowstart[v]; + EdgeIndex next_row_start = g.m_backward.m_rowstart[v + 1]; + return std::make_pair(it(g, v_row_start), it(g, next_row_start)); } -template<BOOST_BIDIR_CSR_GRAPH_TEMPLATE_PARMS> -inline EdgeIndex -in_degree(Vertex v, const BOOST_BIDIR_CSR_GRAPH_TYPE& g) +template < BOOST_BIDIR_CSR_GRAPH_TEMPLATE_PARMS > +inline EdgeIndex in_degree(Vertex v, const BOOST_BIDIR_CSR_GRAPH_TYPE& g) { - EdgeIndex v_row_start = g.m_backward.m_rowstart[v]; - EdgeIndex next_row_start = g.m_backward.m_rowstart[v + 1]; - return next_row_start - v_row_start; + EdgeIndex v_row_start = g.m_backward.m_rowstart[v]; + EdgeIndex next_row_start = g.m_backward.m_rowstart[v + 1]; + return next_row_start - v_row_start; } // From AdjacencyGraph -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline std::pair<typename BOOST_CSR_GRAPH_TYPE::adjacency_iterator, - typename BOOST_CSR_GRAPH_TYPE::adjacency_iterator> +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline std::pair< typename BOOST_CSR_GRAPH_TYPE::adjacency_iterator, + typename BOOST_CSR_GRAPH_TYPE::adjacency_iterator > adjacent_vertices(Vertex v, const BOOST_CSR_GRAPH_TYPE& g) { - EdgeIndex v_row_start = g.m_forward.m_rowstart[v]; - EdgeIndex next_row_start = g.m_forward.m_rowstart[v + 1]; - return std::make_pair(g.m_forward.m_column.begin() + v_row_start, - g.m_forward.m_column.begin() + next_row_start); + EdgeIndex v_row_start = g.m_forward.m_rowstart[v]; + EdgeIndex next_row_start = g.m_forward.m_rowstart[v + 1]; + return std::make_pair(g.m_forward.m_column.begin() + v_row_start, + g.m_forward.m_column.begin() + next_row_start); } // Extra, common functions -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline typename graph_traits<BOOST_CSR_GRAPH_TYPE>::vertex_descriptor -vertex(typename graph_traits<BOOST_CSR_GRAPH_TYPE>::vertex_descriptor i, - const BOOST_CSR_GRAPH_TYPE&) +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline typename graph_traits< BOOST_CSR_GRAPH_TYPE >::vertex_descriptor vertex( + typename graph_traits< BOOST_CSR_GRAPH_TYPE >::vertex_descriptor i, + const BOOST_CSR_GRAPH_TYPE&) { - return i; + return i; } // edge() can be provided in linear time for the new interface -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline std::pair<typename BOOST_CSR_GRAPH_TYPE::edge_descriptor, bool> -edge(Vertex i, Vertex j, const BOOST_CSR_GRAPH_TYPE& g) -{ - typedef typename BOOST_CSR_GRAPH_TYPE::out_edge_iterator out_edge_iter; - std::pair<out_edge_iter, out_edge_iter> range = out_edges(i, g); - for (; range.first != range.second; ++range.first) { - if (target(*range.first, g) == j) - return std::make_pair(*range.first, true); - } - return std::make_pair(typename BOOST_CSR_GRAPH_TYPE::edge_descriptor(), - false); +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline std::pair< typename BOOST_CSR_GRAPH_TYPE::edge_descriptor, bool > edge( + Vertex i, Vertex j, const BOOST_CSR_GRAPH_TYPE& g) +{ + typedef typename BOOST_CSR_GRAPH_TYPE::out_edge_iterator out_edge_iter; + std::pair< out_edge_iter, out_edge_iter > range = out_edges(i, g); + for (; range.first != range.second; ++range.first) + { + if (target(*range.first, g) == j) + return std::make_pair(*range.first, true); + } + return std::make_pair( + typename BOOST_CSR_GRAPH_TYPE::edge_descriptor(), false); } // Find an edge given its index in the graph -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline typename BOOST_CSR_GRAPH_TYPE::edge_descriptor -edge_from_index(EdgeIndex idx, const BOOST_CSR_GRAPH_TYPE& g) -{ - typedef typename std::vector<EdgeIndex>::const_iterator row_start_iter; - BOOST_ASSERT (idx < num_edges(g)); - row_start_iter src_plus_1 = - std::upper_bound(g.m_forward.m_rowstart.begin(), - g.m_forward.m_rowstart.end(), - idx); +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline typename BOOST_CSR_GRAPH_TYPE::edge_descriptor edge_from_index( + EdgeIndex idx, const BOOST_CSR_GRAPH_TYPE& g) +{ + typedef typename std::vector< EdgeIndex >::const_iterator row_start_iter; + BOOST_ASSERT(idx < num_edges(g)); + row_start_iter src_plus_1 = std::upper_bound( + g.m_forward.m_rowstart.begin(), g.m_forward.m_rowstart.end(), idx); // Get last source whose rowstart is at most idx // upper_bound returns this position plus 1 - Vertex src = (src_plus_1 - g.m_forward.m_rowstart.begin()) - 1; - return typename BOOST_CSR_GRAPH_TYPE::edge_descriptor(src, idx); + Vertex src = (src_plus_1 - g.m_forward.m_rowstart.begin()) - 1; + return typename BOOST_CSR_GRAPH_TYPE::edge_descriptor(src, idx); } -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline EdgeIndex -num_edges(const BOOST_CSR_GRAPH_TYPE& g) +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline EdgeIndex num_edges(const BOOST_CSR_GRAPH_TYPE& g) { - return g.m_forward.m_column.size(); + return g.m_forward.m_column.size(); } -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -std::pair<typename BOOST_CSR_GRAPH_TYPE::edge_iterator, - typename BOOST_CSR_GRAPH_TYPE::edge_iterator> +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +std::pair< typename BOOST_CSR_GRAPH_TYPE::edge_iterator, + typename BOOST_CSR_GRAPH_TYPE::edge_iterator > edges(const BOOST_CSR_GRAPH_TYPE& g) { - typedef typename BOOST_CSR_GRAPH_TYPE::edge_iterator ei; - typedef typename BOOST_CSR_GRAPH_TYPE::edge_descriptor edgedesc; - if (g.m_forward.m_rowstart.size() == 1 || g.m_forward.m_column.empty()) { - return std::make_pair(ei(), ei()); - } else { - // Find the first vertex that has outgoing edges - Vertex src = 0; - while (g.m_forward.m_rowstart[src + 1] == 0) ++src; - return std::make_pair(ei(g, edgedesc(src, 0), g.m_forward.m_rowstart[src + 1]), - ei(g, edgedesc(num_vertices(g), g.m_forward.m_column.size()), 0)); - } + typedef typename BOOST_CSR_GRAPH_TYPE::edge_iterator ei; + typedef typename BOOST_CSR_GRAPH_TYPE::edge_descriptor edgedesc; + if (g.m_forward.m_rowstart.size() == 1 || g.m_forward.m_column.empty()) + { + return std::make_pair(ei(), ei()); + } + else + { + // Find the first vertex that has outgoing edges + Vertex src = 0; + while (g.m_forward.m_rowstart[src + 1] == 0) + ++src; + return std::make_pair( + ei(g, edgedesc(src, 0), g.m_forward.m_rowstart[src + 1]), + ei(g, edgedesc(num_vertices(g), g.m_forward.m_column.size()), 0)); + } } // For Property Graph // Graph properties -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS, class Tag, class Value> -inline void -set_property(BOOST_CSR_GRAPH_TYPE& g, Tag tag, const Value& value) +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS, class Tag, class Value > +inline void set_property(BOOST_CSR_GRAPH_TYPE& g, Tag tag, const Value& value) { - get_property_value(g.m_property, tag) = value; + get_property_value(g.m_property, tag) = value; } -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS, class Tag> -inline -typename graph_property<BOOST_CSR_GRAPH_TYPE, Tag>::type& -get_property(BOOST_CSR_GRAPH_TYPE& g, Tag tag) +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS, class Tag > +inline typename graph_property< BOOST_CSR_GRAPH_TYPE, Tag >::type& get_property( + BOOST_CSR_GRAPH_TYPE& g, Tag tag) { - return get_property_value(g.m_property, tag); + return get_property_value(g.m_property, tag); } -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS, class Tag> -inline -const -typename graph_property<BOOST_CSR_GRAPH_TYPE, Tag>::type& +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS, class Tag > +inline const typename graph_property< BOOST_CSR_GRAPH_TYPE, Tag >::type& get_property(const BOOST_CSR_GRAPH_TYPE& g, Tag tag) { - return get_property_value(g.m_property, tag); + return get_property_value(g.m_property, tag); } -template <typename G, typename Tag, typename Kind> -struct csr_property_map_helper {}; +template < typename G, typename Tag, typename Kind > +struct csr_property_map_helper +{ +}; // Kind == void for invalid property tags, so we can use that to SFINAE out -template <BOOST_CSR_GRAPH_TEMPLATE_PARMS, typename Tag> -struct csr_property_map_helper<BOOST_CSR_GRAPH_TYPE, Tag, vertex_property_tag> { - typedef vertex_all_t all_tag; - typedef typename property_traits<typename property_map<BOOST_CSR_GRAPH_TYPE, vertex_all_t>::type>::key_type key_type; - typedef VertexProperty plist_type; - typedef typename property_map<BOOST_CSR_GRAPH_TYPE, vertex_all_t>::type all_type; - typedef typename property_map<BOOST_CSR_GRAPH_TYPE, vertex_all_t>::const_type all_const_type; - typedef transform_value_property_map<detail::lookup_one_property_f<plist_type, Tag>, all_type> type; - typedef transform_value_property_map<detail::lookup_one_property_f<const plist_type, Tag>, all_const_type> const_type; +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS, typename Tag > +struct csr_property_map_helper< BOOST_CSR_GRAPH_TYPE, Tag, vertex_property_tag > +{ + typedef vertex_all_t all_tag; + typedef + typename property_traits< typename property_map< BOOST_CSR_GRAPH_TYPE, + vertex_all_t >::type >::key_type key_type; + typedef VertexProperty plist_type; + typedef typename property_map< BOOST_CSR_GRAPH_TYPE, vertex_all_t >::type + all_type; + typedef + typename property_map< BOOST_CSR_GRAPH_TYPE, vertex_all_t >::const_type + all_const_type; + typedef transform_value_property_map< + detail::lookup_one_property_f< plist_type, Tag >, all_type > + type; + typedef transform_value_property_map< + detail::lookup_one_property_f< const plist_type, Tag >, all_const_type > + const_type; }; -template <BOOST_CSR_GRAPH_TEMPLATE_PARMS, typename Tag> -struct csr_property_map_helper<BOOST_CSR_GRAPH_TYPE, Tag, edge_property_tag> { - typedef edge_all_t all_tag; - typedef typename property_traits<typename property_map<BOOST_CSR_GRAPH_TYPE, edge_all_t>::type>::key_type key_type; - typedef EdgeProperty plist_type; - typedef typename property_map<BOOST_CSR_GRAPH_TYPE, edge_all_t>::type all_type; - typedef typename property_map<BOOST_CSR_GRAPH_TYPE, edge_all_t>::const_type all_const_type; - typedef transform_value_property_map<detail::lookup_one_property_f<plist_type, Tag>, all_type> type; - typedef transform_value_property_map<detail::lookup_one_property_f<const plist_type, Tag>, all_const_type> const_type; +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS, typename Tag > +struct csr_property_map_helper< BOOST_CSR_GRAPH_TYPE, Tag, edge_property_tag > +{ + typedef edge_all_t all_tag; + typedef + typename property_traits< typename property_map< BOOST_CSR_GRAPH_TYPE, + edge_all_t >::type >::key_type key_type; + typedef EdgeProperty plist_type; + typedef typename property_map< BOOST_CSR_GRAPH_TYPE, edge_all_t >::type + all_type; + typedef + typename property_map< BOOST_CSR_GRAPH_TYPE, edge_all_t >::const_type + all_const_type; + typedef transform_value_property_map< + detail::lookup_one_property_f< plist_type, Tag >, all_type > + type; + typedef transform_value_property_map< + detail::lookup_one_property_f< const plist_type, Tag >, all_const_type > + const_type; }; -template <BOOST_CSR_GRAPH_TEMPLATE_PARMS, typename Tag> -struct csr_property_map_helper<BOOST_CSR_GRAPH_TYPE, Tag, graph_property_tag> { - typedef graph_all_t all_tag; - typedef BOOST_CSR_GRAPH_TYPE* key_type; - typedef GraphProperty plist_type; - typedef typename property_map<BOOST_CSR_GRAPH_TYPE, graph_all_t>::type all_type; - typedef typename property_map<BOOST_CSR_GRAPH_TYPE, graph_all_t>::const_type all_const_type; - typedef transform_value_property_map<detail::lookup_one_property_f<plist_type, Tag>, all_type> type; - typedef transform_value_property_map<detail::lookup_one_property_f<const plist_type, Tag>, all_const_type> const_type; +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS, typename Tag > +struct csr_property_map_helper< BOOST_CSR_GRAPH_TYPE, Tag, graph_property_tag > +{ + typedef graph_all_t all_tag; + typedef BOOST_CSR_GRAPH_TYPE* key_type; + typedef GraphProperty plist_type; + typedef typename property_map< BOOST_CSR_GRAPH_TYPE, graph_all_t >::type + all_type; + typedef + typename property_map< BOOST_CSR_GRAPH_TYPE, graph_all_t >::const_type + all_const_type; + typedef transform_value_property_map< + detail::lookup_one_property_f< plist_type, Tag >, all_type > + type; + typedef transform_value_property_map< + detail::lookup_one_property_f< const plist_type, Tag >, all_const_type > + const_type; +}; + +// disable_if isn't truly necessary but required to avoid ambiguity with +// specializations below +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS, typename Tag > +struct property_map< BOOST_CSR_GRAPH_TYPE, Tag, + typename disable_if< detail::is_distributed_selector< Vertex > >::type > +: csr_property_map_helper< BOOST_CSR_GRAPH_TYPE, Tag, + typename detail::property_kind_from_graph< BOOST_CSR_GRAPH_TYPE, + Tag >::type > +{ }; -// disable_if isn't truly necessary but required to avoid ambiguity with specializations below -template <BOOST_CSR_GRAPH_TEMPLATE_PARMS, typename Tag> -struct property_map<BOOST_CSR_GRAPH_TYPE, Tag, typename disable_if<detail::is_distributed_selector<Vertex> >::type>: - csr_property_map_helper< - BOOST_CSR_GRAPH_TYPE, - Tag, - typename detail::property_kind_from_graph<BOOST_CSR_GRAPH_TYPE, Tag> - ::type> {}; - -template <BOOST_CSR_GRAPH_TEMPLATE_PARMS, typename Tag> -typename property_map<BOOST_CSR_GRAPH_TYPE, Tag>::type -get(Tag tag, BOOST_CSR_GRAPH_TYPE& g) { - return typename property_map<BOOST_CSR_GRAPH_TYPE, Tag>::type(tag, get(typename property_map<BOOST_CSR_GRAPH_TYPE, Tag>::all_tag(), g)); +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS, typename Tag > +typename property_map< BOOST_CSR_GRAPH_TYPE, Tag >::type get( + Tag tag, BOOST_CSR_GRAPH_TYPE& g) +{ + return typename property_map< BOOST_CSR_GRAPH_TYPE, Tag >::type(tag, + get(typename property_map< BOOST_CSR_GRAPH_TYPE, Tag >::all_tag(), g)); } -template <BOOST_CSR_GRAPH_TEMPLATE_PARMS, typename Tag> -typename property_map<BOOST_CSR_GRAPH_TYPE, Tag>::const_type -get(Tag tag, const BOOST_CSR_GRAPH_TYPE& g) { - return typename property_map<BOOST_CSR_GRAPH_TYPE, Tag>::const_type(tag, get(typename property_map<BOOST_CSR_GRAPH_TYPE, Tag>::all_tag(), g)); +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS, typename Tag > +typename property_map< BOOST_CSR_GRAPH_TYPE, Tag >::const_type get( + Tag tag, const BOOST_CSR_GRAPH_TYPE& g) +{ + return typename property_map< BOOST_CSR_GRAPH_TYPE, Tag >::const_type(tag, + get(typename property_map< BOOST_CSR_GRAPH_TYPE, Tag >::all_tag(), g)); } -template <BOOST_CSR_GRAPH_TEMPLATE_PARMS, typename Tag> -typename property_traits<typename property_map<BOOST_CSR_GRAPH_TYPE, Tag>::type>::reference -get(Tag tag, BOOST_CSR_GRAPH_TYPE& g, typename property_map<BOOST_CSR_GRAPH_TYPE, Tag>::key_type k) { - typedef typename property_map<BOOST_CSR_GRAPH_TYPE, Tag>::all_tag all_tag; - typedef typename property_map<BOOST_CSR_GRAPH_TYPE, all_tag>::type outer_pm; - return lookup_one_property<typename property_traits<outer_pm>::value_type, Tag>::lookup(get(all_tag(), g, k), tag); +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS, typename Tag > +typename property_traits< + typename property_map< BOOST_CSR_GRAPH_TYPE, Tag >::type >::reference +get(Tag tag, BOOST_CSR_GRAPH_TYPE& g, + typename property_map< BOOST_CSR_GRAPH_TYPE, Tag >::key_type k) +{ + typedef typename property_map< BOOST_CSR_GRAPH_TYPE, Tag >::all_tag all_tag; + typedef + typename property_map< BOOST_CSR_GRAPH_TYPE, all_tag >::type outer_pm; + return lookup_one_property< + typename property_traits< outer_pm >::value_type, + Tag >::lookup(get(all_tag(), g, k), tag); } -template <BOOST_CSR_GRAPH_TEMPLATE_PARMS, typename Tag> -typename property_traits<typename property_map<BOOST_CSR_GRAPH_TYPE, Tag>::const_type>::reference -get(Tag tag, const BOOST_CSR_GRAPH_TYPE& g, typename property_map<BOOST_CSR_GRAPH_TYPE, Tag>::key_type k) { - typedef typename property_map<BOOST_CSR_GRAPH_TYPE, Tag>::all_tag all_tag; - typedef typename property_map<BOOST_CSR_GRAPH_TYPE, all_tag>::const_type outer_pm; - return lookup_one_property<const typename property_traits<outer_pm>::value_type, Tag>::lookup(get(all_tag(), g, k), tag); +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS, typename Tag > +typename property_traits< + typename property_map< BOOST_CSR_GRAPH_TYPE, Tag >::const_type >::reference +get(Tag tag, const BOOST_CSR_GRAPH_TYPE& g, + typename property_map< BOOST_CSR_GRAPH_TYPE, Tag >::key_type k) +{ + typedef typename property_map< BOOST_CSR_GRAPH_TYPE, Tag >::all_tag all_tag; + typedef typename property_map< BOOST_CSR_GRAPH_TYPE, all_tag >::const_type + outer_pm; + return lookup_one_property< + const typename property_traits< outer_pm >::value_type, + Tag >::lookup(get(all_tag(), g, k), tag); } -template <BOOST_CSR_GRAPH_TEMPLATE_PARMS, typename Tag> -void -put(Tag tag, - BOOST_CSR_GRAPH_TYPE& g, - typename property_map<BOOST_CSR_GRAPH_TYPE, Tag>::key_type k, - typename lookup_one_property<typename property_map<BOOST_CSR_GRAPH_TYPE, Tag>::plist_type, Tag>::type val) { - typedef typename property_map<BOOST_CSR_GRAPH_TYPE, Tag>::all_tag all_tag; - lookup_one_property<typename property_map<BOOST_CSR_GRAPH_TYPE, Tag>::plist_type, Tag>::lookup(get(all_tag(), g, k), tag) = val; +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS, typename Tag > +void put(Tag tag, BOOST_CSR_GRAPH_TYPE& g, + typename property_map< BOOST_CSR_GRAPH_TYPE, Tag >::key_type k, + typename lookup_one_property< + typename property_map< BOOST_CSR_GRAPH_TYPE, Tag >::plist_type, + Tag >::type val) +{ + typedef typename property_map< BOOST_CSR_GRAPH_TYPE, Tag >::all_tag all_tag; + lookup_one_property< + typename property_map< BOOST_CSR_GRAPH_TYPE, Tag >::plist_type, + Tag >::lookup(get(all_tag(), g, k), tag) + = val; } -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -struct property_map<BOOST_CSR_GRAPH_TYPE, vertex_index_t, typename disable_if<detail::is_distributed_selector<Vertex> >::type> +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +struct property_map< BOOST_CSR_GRAPH_TYPE, vertex_index_t, + typename disable_if< detail::is_distributed_selector< Vertex > >::type > { - typedef typed_identity_property_map<Vertex> type; - typedef type const_type; + typedef typed_identity_property_map< Vertex > type; + typedef type const_type; }; -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -struct property_map<BOOST_CSR_GRAPH_TYPE, edge_index_t, typename disable_if<detail::is_distributed_selector<Vertex> >::type> +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +struct property_map< BOOST_CSR_GRAPH_TYPE, edge_index_t, + typename disable_if< detail::is_distributed_selector< Vertex > >::type > { - typedef detail::csr_edge_index_map<Vertex, EdgeIndex> type; - typedef type const_type; + typedef detail::csr_edge_index_map< Vertex, EdgeIndex > type; + typedef type const_type; }; -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -struct property_map<BOOST_CSR_GRAPH_TYPE, vertex_all_t, typename disable_if<detail::is_distributed_selector<Vertex> >::type> +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +struct property_map< BOOST_CSR_GRAPH_TYPE, vertex_all_t, + typename disable_if< detail::is_distributed_selector< Vertex > >::type > { - typedef typename BOOST_CSR_GRAPH_TYPE::inherited_vertex_properties::vertex_map_type type; - typedef typename BOOST_CSR_GRAPH_TYPE::inherited_vertex_properties::const_vertex_map_type const_type; + typedef typename BOOST_CSR_GRAPH_TYPE::inherited_vertex_properties:: + vertex_map_type type; + typedef typename BOOST_CSR_GRAPH_TYPE::inherited_vertex_properties:: + const_vertex_map_type const_type; }; -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -struct property_map<BOOST_CSR_GRAPH_TYPE, edge_all_t, typename disable_if<detail::is_distributed_selector<Vertex> >::type> +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +struct property_map< BOOST_CSR_GRAPH_TYPE, edge_all_t, + typename disable_if< detail::is_distributed_selector< Vertex > >::type > { - typedef typename BOOST_CSR_GRAPH_TYPE::forward_type::inherited_edge_properties::edge_map_type type; - typedef typename BOOST_CSR_GRAPH_TYPE::forward_type::inherited_edge_properties::const_edge_map_type const_type; + typedef typename BOOST_CSR_GRAPH_TYPE::forward_type:: + inherited_edge_properties::edge_map_type type; + typedef typename BOOST_CSR_GRAPH_TYPE::forward_type:: + inherited_edge_properties::const_edge_map_type const_type; }; -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -struct property_map<BOOST_CSR_GRAPH_TYPE, graph_all_t, typename disable_if<detail::is_distributed_selector<Vertex> >::type> +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +struct property_map< BOOST_CSR_GRAPH_TYPE, graph_all_t, + typename disable_if< detail::is_distributed_selector< Vertex > >::type > { - typedef boost::ref_property_map<BOOST_CSR_GRAPH_TYPE*, typename BOOST_CSR_GRAPH_TYPE::graph_property_type> type; - typedef boost::ref_property_map<BOOST_CSR_GRAPH_TYPE*, const typename BOOST_CSR_GRAPH_TYPE::graph_property_type> const_type; + typedef boost::ref_property_map< BOOST_CSR_GRAPH_TYPE*, + typename BOOST_CSR_GRAPH_TYPE::graph_property_type > + type; + typedef boost::ref_property_map< BOOST_CSR_GRAPH_TYPE*, + const typename BOOST_CSR_GRAPH_TYPE::graph_property_type > + const_type; }; -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline typed_identity_property_map<Vertex> -get(vertex_index_t, const BOOST_CSR_GRAPH_TYPE&) +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline typed_identity_property_map< Vertex > get( + vertex_index_t, const BOOST_CSR_GRAPH_TYPE&) { - return typed_identity_property_map<Vertex>(); + return typed_identity_property_map< Vertex >(); } -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline Vertex -get(vertex_index_t, - const BOOST_CSR_GRAPH_TYPE&, Vertex v) +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline Vertex get(vertex_index_t, const BOOST_CSR_GRAPH_TYPE&, Vertex v) { - return v; + return v; } -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline typed_identity_property_map<Vertex> -get(vertex_index_t, BOOST_CSR_GRAPH_TYPE&) +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline typed_identity_property_map< Vertex > get( + vertex_index_t, BOOST_CSR_GRAPH_TYPE&) { - return typed_identity_property_map<Vertex>(); + return typed_identity_property_map< Vertex >(); } -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline Vertex -get(vertex_index_t, - BOOST_CSR_GRAPH_TYPE&, Vertex v) +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline Vertex get(vertex_index_t, BOOST_CSR_GRAPH_TYPE&, Vertex v) { - return v; + return v; } -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline typename property_map<BOOST_CSR_GRAPH_TYPE, edge_index_t>::const_type +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline typename property_map< BOOST_CSR_GRAPH_TYPE, edge_index_t >::const_type get(edge_index_t, const BOOST_CSR_GRAPH_TYPE&) { - typedef typename property_map<BOOST_CSR_GRAPH_TYPE, edge_index_t>::const_type - result_type; - return result_type(); + typedef + typename property_map< BOOST_CSR_GRAPH_TYPE, edge_index_t >::const_type + result_type; + return result_type(); } -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline EdgeIndex -get(edge_index_t, const BOOST_CSR_GRAPH_TYPE&, +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline EdgeIndex get(edge_index_t, const BOOST_CSR_GRAPH_TYPE&, typename BOOST_CSR_GRAPH_TYPE::edge_descriptor e) { - return e.idx; + return e.idx; } -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline typename property_map<BOOST_CSR_GRAPH_TYPE, edge_index_t>::const_type +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline typename property_map< BOOST_CSR_GRAPH_TYPE, edge_index_t >::const_type get(edge_index_t, BOOST_CSR_GRAPH_TYPE&) { - typedef typename property_map<BOOST_CSR_GRAPH_TYPE, edge_index_t>::const_type - result_type; - return result_type(); + typedef + typename property_map< BOOST_CSR_GRAPH_TYPE, edge_index_t >::const_type + result_type; + return result_type(); } -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline EdgeIndex -get(edge_index_t, BOOST_CSR_GRAPH_TYPE&, +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline EdgeIndex get(edge_index_t, BOOST_CSR_GRAPH_TYPE&, typename BOOST_CSR_GRAPH_TYPE::edge_descriptor e) { - return e.idx; + return e.idx; } -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline typename property_map<BOOST_CSR_GRAPH_TYPE, vertex_all_t>::type -get(vertex_all_t, BOOST_CSR_GRAPH_TYPE& g) +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline typename property_map< BOOST_CSR_GRAPH_TYPE, vertex_all_t >::type get( + vertex_all_t, BOOST_CSR_GRAPH_TYPE& g) { - return g.get_vertex_bundle(get(vertex_index, g)); + return g.get_vertex_bundle(get(vertex_index, g)); } -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline typename property_map<BOOST_CSR_GRAPH_TYPE, vertex_all_t>::const_type +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline typename property_map< BOOST_CSR_GRAPH_TYPE, vertex_all_t >::const_type get(vertex_all_t, const BOOST_CSR_GRAPH_TYPE& g) { - return g.get_vertex_bundle(get(vertex_index, g)); + return g.get_vertex_bundle(get(vertex_index, g)); } -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline VertexProperty& -get(vertex_all_t, - BOOST_CSR_GRAPH_TYPE& g, Vertex v) +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline VertexProperty& get(vertex_all_t, BOOST_CSR_GRAPH_TYPE& g, Vertex v) { - return get(vertex_all, g)[v]; + return get(vertex_all, g)[v]; } -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline const VertexProperty& -get(vertex_all_t, - const BOOST_CSR_GRAPH_TYPE& g, Vertex v) +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline const VertexProperty& get( + vertex_all_t, const BOOST_CSR_GRAPH_TYPE& g, Vertex v) { - return get(vertex_all, g)[v]; + return get(vertex_all, g)[v]; } -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline void -put(vertex_all_t, - BOOST_CSR_GRAPH_TYPE& g, - Vertex v, - const VertexProperty& val) +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline void put( + vertex_all_t, BOOST_CSR_GRAPH_TYPE& g, Vertex v, const VertexProperty& val) { - put(get(vertex_all, g), v, val); + put(get(vertex_all, g), v, val); } -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline typename property_map<BOOST_CSR_GRAPH_TYPE, edge_all_t>::type -get(edge_all_t, BOOST_CSR_GRAPH_TYPE& g) +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline typename property_map< BOOST_CSR_GRAPH_TYPE, edge_all_t >::type get( + edge_all_t, BOOST_CSR_GRAPH_TYPE& g) { - return g.m_forward.get_edge_bundle(get(edge_index, g)); + return g.m_forward.get_edge_bundle(get(edge_index, g)); } -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline typename property_map<BOOST_CSR_GRAPH_TYPE, edge_all_t>::const_type +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline typename property_map< BOOST_CSR_GRAPH_TYPE, edge_all_t >::const_type get(edge_all_t, const BOOST_CSR_GRAPH_TYPE& g) { - return g.m_forward.get_edge_bundle(get(edge_index, g)); + return g.m_forward.get_edge_bundle(get(edge_index, g)); } -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline EdgeProperty& -get(edge_all_t, - BOOST_CSR_GRAPH_TYPE& g, +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline EdgeProperty& get(edge_all_t, BOOST_CSR_GRAPH_TYPE& g, const typename BOOST_CSR_GRAPH_TYPE::edge_descriptor& e) { - return get(edge_all, g)[e]; + return get(edge_all, g)[e]; } -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline const EdgeProperty& -get(edge_all_t, - const BOOST_CSR_GRAPH_TYPE& g, +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline const EdgeProperty& get(edge_all_t, const BOOST_CSR_GRAPH_TYPE& g, const typename BOOST_CSR_GRAPH_TYPE::edge_descriptor& e) { - return get(edge_all, g)[e]; + return get(edge_all, g)[e]; } -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline void -put(edge_all_t, - BOOST_CSR_GRAPH_TYPE& g, +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline void put(edge_all_t, BOOST_CSR_GRAPH_TYPE& g, const typename BOOST_CSR_GRAPH_TYPE::edge_descriptor& e, const EdgeProperty& val) { - put(get(edge_all, g), e, val); + put(get(edge_all, g), e, val); } -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline typename property_map<BOOST_CSR_GRAPH_TYPE, graph_all_t>::type -get(graph_all_t, BOOST_CSR_GRAPH_TYPE& g) +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline typename property_map< BOOST_CSR_GRAPH_TYPE, graph_all_t >::type get( + graph_all_t, BOOST_CSR_GRAPH_TYPE& g) { - return typename property_map<BOOST_CSR_GRAPH_TYPE, graph_all_t>::type(g.m_property); + return typename property_map< BOOST_CSR_GRAPH_TYPE, graph_all_t >::type( + g.m_property); } -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline typename property_map<BOOST_CSR_GRAPH_TYPE, graph_all_t>::const_type +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline typename property_map< BOOST_CSR_GRAPH_TYPE, graph_all_t >::const_type get(graph_all_t, const BOOST_CSR_GRAPH_TYPE& g) { - return typename property_map<BOOST_CSR_GRAPH_TYPE, graph_all_t>::const_type(g.m_property); + return + typename property_map< BOOST_CSR_GRAPH_TYPE, graph_all_t >::const_type( + g.m_property); } -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline GraphProperty& -get(graph_all_t, - BOOST_CSR_GRAPH_TYPE& g, - BOOST_CSR_GRAPH_TYPE*) +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline GraphProperty& get( + graph_all_t, BOOST_CSR_GRAPH_TYPE& g, BOOST_CSR_GRAPH_TYPE*) { - return g.m_property; + return g.m_property; } -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline const GraphProperty& -get(graph_all_t, - const BOOST_CSR_GRAPH_TYPE& g, - BOOST_CSR_GRAPH_TYPE*) +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline const GraphProperty& get( + graph_all_t, const BOOST_CSR_GRAPH_TYPE& g, BOOST_CSR_GRAPH_TYPE*) { - return g.m_property; + return g.m_property; } -template<BOOST_CSR_GRAPH_TEMPLATE_PARMS> -inline void -put(graph_all_t, - BOOST_CSR_GRAPH_TYPE& g, - BOOST_CSR_GRAPH_TYPE*, +template < BOOST_CSR_GRAPH_TEMPLATE_PARMS > +inline void put(graph_all_t, BOOST_CSR_GRAPH_TYPE& g, BOOST_CSR_GRAPH_TYPE*, const GraphProperty& val) { - g.m_property = val; + g.m_property = val; } #undef BOOST_CSR_GRAPH_TYPE diff --git a/contrib/restricted/boost/graph/include/boost/graph/connected_components.hpp b/contrib/restricted/boost/graph/include/boost/graph/connected_components.hpp index e8d3466156..75e76a0734 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/connected_components.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/connected_components.hpp @@ -16,92 +16,99 @@ #include <boost/graph/properties.hpp> #include <boost/graph/graph_concepts.hpp> #include <boost/graph/overloading.hpp> +#include <boost/graph/detail/mpi_include.hpp> #include <boost/static_assert.hpp> #include <boost/concept/assert.hpp> -namespace boost { +namespace boost +{ - namespace detail { +namespace detail +{ // This visitor is used both in the connected_components algorithm // and in the kosaraju strong components algorithm during the // second DFS traversal. - template <class ComponentsMap> + template < class ComponentsMap > class components_recorder : public dfs_visitor<> { - typedef typename property_traits<ComponentsMap>::value_type comp_type; + typedef typename property_traits< ComponentsMap >::value_type comp_type; + public: - components_recorder(ComponentsMap c, - comp_type& c_count) - : m_component(c), m_count(c_count) {} - - template <class Vertex, class Graph> - void start_vertex(Vertex, Graph&) { - if (m_count == (std::numeric_limits<comp_type>::max)()) - m_count = 0; // start counting components at zero - else - ++m_count; - } - template <class Vertex, class Graph> - void discover_vertex(Vertex u, Graph&) { - put(m_component, u, m_count); - } + components_recorder(ComponentsMap c, comp_type& c_count) + : m_component(c), m_count(c_count) + { + } + + template < class Vertex, class Graph > void start_vertex(Vertex, Graph&) + { + if (m_count == (std::numeric_limits< comp_type >::max)()) + m_count = 0; // start counting components at zero + else + ++m_count; + } + template < class Vertex, class Graph > + void discover_vertex(Vertex u, Graph&) + { + put(m_component, u, m_count); + } + protected: - ComponentsMap m_component; - comp_type& m_count; + ComponentsMap m_component; + comp_type& m_count; }; - } // namespace detail +} // namespace detail - // This function computes the connected components of an undirected - // graph using a single application of depth first search. +// This function computes the connected components of an undirected +// graph using a single application of depth first search. - template <class Graph, class ComponentMap, class P, class T, class R> - inline typename property_traits<ComponentMap>::value_type - connected_components(const Graph& g, ComponentMap c, - const bgl_named_params<P, T, R>& params - BOOST_GRAPH_ENABLE_IF_MODELS_PARM(Graph, vertex_list_graph_tag)) - { - if (num_vertices(g) == 0) return 0; +template < class Graph, class ComponentMap, class P, class T, class R > +inline typename property_traits< ComponentMap >::value_type +connected_components(const Graph& g, ComponentMap c, + const bgl_named_params< P, T, R >& params BOOST_GRAPH_ENABLE_IF_MODELS_PARM( + Graph, vertex_list_graph_tag)) +{ + if (num_vertices(g) == 0) + return 0; - typedef typename graph_traits<Graph>::vertex_descriptor Vertex; - BOOST_CONCEPT_ASSERT(( WritablePropertyMapConcept<ComponentMap, Vertex> )); - typedef typename boost::graph_traits<Graph>::directed_category directed; - BOOST_STATIC_ASSERT((boost::is_same<directed, undirected_tag>::value)); + typedef typename graph_traits< Graph >::vertex_descriptor Vertex; + BOOST_CONCEPT_ASSERT((WritablePropertyMapConcept< ComponentMap, Vertex >)); + typedef typename boost::graph_traits< Graph >::directed_category directed; + BOOST_STATIC_ASSERT((boost::is_same< directed, undirected_tag >::value)); - typedef typename property_traits<ComponentMap>::value_type comp_type; + typedef typename property_traits< ComponentMap >::value_type comp_type; // c_count initialized to "nil" (with nil represented by (max)()) - comp_type c_count((std::numeric_limits<comp_type>::max)()); - detail::components_recorder<ComponentMap> vis(c, c_count); + comp_type c_count((std::numeric_limits< comp_type >::max)()); + detail::components_recorder< ComponentMap > vis(c, c_count); depth_first_search(g, params.visitor(vis)); return c_count + 1; - } - - template <class Graph, class ComponentMap> - inline typename property_traits<ComponentMap>::value_type - connected_components(const Graph& g, ComponentMap c - BOOST_GRAPH_ENABLE_IF_MODELS_PARM(Graph, vertex_list_graph_tag)) - { - if (num_vertices(g) == 0) return 0; - - typedef typename graph_traits<Graph>::vertex_descriptor Vertex; - BOOST_CONCEPT_ASSERT(( WritablePropertyMapConcept<ComponentMap, Vertex> )); +} + +template < class Graph, class ComponentMap > +inline typename property_traits< ComponentMap >::value_type +connected_components(const Graph& g, + ComponentMap c BOOST_GRAPH_ENABLE_IF_MODELS_PARM( + Graph, vertex_list_graph_tag)) +{ + if (num_vertices(g) == 0) + return 0; + + typedef typename graph_traits< Graph >::vertex_descriptor Vertex; + BOOST_CONCEPT_ASSERT((WritablePropertyMapConcept< ComponentMap, Vertex >)); // typedef typename boost::graph_traits<Graph>::directed_category directed; // BOOST_STATIC_ASSERT((boost::is_same<directed, undirected_tag>::value)); - typedef typename property_traits<ComponentMap>::value_type comp_type; + typedef typename property_traits< ComponentMap >::value_type comp_type; // c_count initialized to "nil" (with nil represented by (max)()) - comp_type c_count((std::numeric_limits<comp_type>::max)()); - detail::components_recorder<ComponentMap> vis(c, c_count); + comp_type c_count((std::numeric_limits< comp_type >::max)()); + detail::components_recorder< ComponentMap > vis(c, c_count); depth_first_search(g, visitor(vis)); return c_count + 1; - } +} - } // namespace boost -#ifdef BOOST_GRAPH_USE_MPI -# error #include <boost/graph/distributed/connected_components.hpp> -#endif +#include BOOST_GRAPH_MPI_INCLUDE(<boost/graph/distributed/connected_components.hpp>) #endif // BOOST_GRAPH_CONNECTED_COMPONENTS_HPP diff --git a/contrib/restricted/boost/graph/include/boost/graph/copy.hpp b/contrib/restricted/boost/graph/include/boost/graph/copy.hpp index 6246ebceb1..7cbbc25c72 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/copy.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/copy.hpp @@ -16,28 +16,27 @@ template <typename VertexListGraph, typename MutableGraph> void copy_graph(const VertexListGraph& g_in, MutableGraph& g_out) - template <typename VertexListGraph, typename MutableGraph, + template <typename VertexListGraph, typename MutableGraph, class P, class T, class R> - void copy_graph(const VertexListGraph& g_in, MutableGraph& g_out, + void copy_graph(const VertexListGraph& g_in, MutableGraph& g_out, const bgl_named_params<P, T, R>& params) template <typename IncidenceGraph, typename MutableGraph> typename graph_traits<MutableGraph>::vertex_descriptor - copy_component(IncidenceGraph& g_in, + copy_component(IncidenceGraph& g_in, typename graph_traits<IncidenceGraph>::vertex_descriptor src, MutableGraph& g_out) - template <typename IncidenceGraph, typename MutableGraph, + template <typename IncidenceGraph, typename MutableGraph, typename P, typename T, typename R> typename graph_traits<MutableGraph>::vertex_descriptor - copy_component(IncidenceGraph& g_in, + copy_component(IncidenceGraph& g_in, typename graph_traits<IncidenceGraph>::vertex_descriptor src, - MutableGraph& g_out, + MutableGraph& g_out, const bgl_named_params<P, T, R>& params) */ - #ifndef BOOST_GRAPH_COPY_HPP #define BOOST_GRAPH_COPY_HPP @@ -50,23 +49,30 @@ #include <boost/graph/breadth_first_search.hpp> #include <boost/type_traits/conversion_traits.hpp> -namespace boost { +namespace boost +{ - namespace detail { +namespace detail +{ // Hack to make transpose_graph work with the same interface as before - template <typename Graph, typename Desc> - struct remove_reverse_edge_descriptor { - typedef Desc type; - static Desc convert(const Desc& d, const Graph&) {return d;} + template < typename Graph, typename Desc > + struct remove_reverse_edge_descriptor + { + typedef Desc type; + static Desc convert(const Desc& d, const Graph&) { return d; } }; - template <typename Graph, typename Desc> - struct remove_reverse_edge_descriptor<Graph, reverse_graph_edge_descriptor<Desc> > { - typedef Desc type; - static Desc convert(const reverse_graph_edge_descriptor<Desc>& d, const Graph& g) { - return get(edge_underlying, g, d); - } + template < typename Graph, typename Desc > + struct remove_reverse_edge_descriptor< Graph, + reverse_graph_edge_descriptor< Desc > > + { + typedef Desc type; + static Desc convert( + const reverse_graph_edge_descriptor< Desc >& d, const Graph& g) + { + return get(edge_underlying, g, d); + } }; // Add a reverse_graph_edge_descriptor wrapper if the Graph is a @@ -74,437 +80,478 @@ namespace boost { // case comes from the fact that transpose_graph uses reverse_graph // internally but doesn't expose the different edge descriptor type to the // user). - template <typename Desc, typename Graph> - struct add_reverse_edge_descriptor { - typedef Desc type; - static Desc convert(const Desc& d) {return d;} + template < typename Desc, typename Graph > + struct add_reverse_edge_descriptor + { + typedef Desc type; + static Desc convert(const Desc& d) { return d; } }; - template <typename Desc, typename G, typename GR> - struct add_reverse_edge_descriptor<Desc, boost::reverse_graph<G, GR> > { - typedef reverse_graph_edge_descriptor<Desc> type; - static reverse_graph_edge_descriptor<Desc> convert(const Desc& d) { - return reverse_graph_edge_descriptor<Desc>(d); - } + template < typename Desc, typename G, typename GR > + struct add_reverse_edge_descriptor< Desc, boost::reverse_graph< G, GR > > + { + typedef reverse_graph_edge_descriptor< Desc > type; + static reverse_graph_edge_descriptor< Desc > convert(const Desc& d) + { + return reverse_graph_edge_descriptor< Desc >(d); + } }; - template <typename Desc, typename G, typename GR> - struct add_reverse_edge_descriptor<reverse_graph_edge_descriptor<Desc>, boost::reverse_graph<G, GR> > { - typedef reverse_graph_edge_descriptor<Desc> type; - static reverse_graph_edge_descriptor<Desc> convert(const reverse_graph_edge_descriptor<Desc>& d) { - return d; - } + template < typename Desc, typename G, typename GR > + struct add_reverse_edge_descriptor< reverse_graph_edge_descriptor< Desc >, + boost::reverse_graph< G, GR > > + { + typedef reverse_graph_edge_descriptor< Desc > type; + static reverse_graph_edge_descriptor< Desc > convert( + const reverse_graph_edge_descriptor< Desc >& d) + { + return d; + } }; // Default edge and vertex property copiers - template <typename Graph1, typename Graph2> - struct edge_copier { - edge_copier(const Graph1& g1, Graph2& g2) - : edge_all_map1(get(edge_all, g1)), - edge_all_map2(get(edge_all, g2)) { } - - template <typename Edge1, typename Edge2> - void operator()(const Edge1& e1, Edge2& e2) const { - put(edge_all_map2, e2, get(edge_all_map1, add_reverse_edge_descriptor<Edge1, Graph1>::convert(e1))); - } - typename property_map<Graph1, edge_all_t>::const_type edge_all_map1; - mutable typename property_map<Graph2, edge_all_t>::type edge_all_map2; + template < typename Graph1, typename Graph2 > struct edge_copier + { + edge_copier(const Graph1& g1, Graph2& g2) + : edge_all_map1(get(edge_all, g1)), edge_all_map2(get(edge_all, g2)) + { + } + + template < typename Edge1, typename Edge2 > + void operator()(const Edge1& e1, Edge2& e2) const + { + put(edge_all_map2, e2, + get(edge_all_map1, + add_reverse_edge_descriptor< Edge1, Graph1 >::convert(e1))); + } + typename property_map< Graph1, edge_all_t >::const_type edge_all_map1; + mutable typename property_map< Graph2, edge_all_t >::type edge_all_map2; }; - template <typename Graph1, typename Graph2> - inline edge_copier<Graph1,Graph2> - make_edge_copier(const Graph1& g1, Graph2& g2) + template < typename Graph1, typename Graph2 > + inline edge_copier< Graph1, Graph2 > make_edge_copier( + const Graph1& g1, Graph2& g2) { - return edge_copier<Graph1,Graph2>(g1, g2); + return edge_copier< Graph1, Graph2 >(g1, g2); } - template <typename Graph1, typename Graph2> - struct vertex_copier { - vertex_copier(const Graph1& g1, Graph2& g2) - : vertex_all_map1(get(vertex_all, g1)), - vertex_all_map2(get(vertex_all, g2)) { } - - template <typename Vertex1, typename Vertex2> - void operator()(const Vertex1& v1, Vertex2& v2) const { - put(vertex_all_map2, v2, get(vertex_all_map1, v1)); - } - typename property_map<Graph1, vertex_all_t>::const_type vertex_all_map1; - mutable typename property_map<Graph2, vertex_all_t>::type - vertex_all_map2; + template < typename Graph1, typename Graph2 > struct vertex_copier + { + vertex_copier(const Graph1& g1, Graph2& g2) + : vertex_all_map1(get(vertex_all, g1)) + , vertex_all_map2(get(vertex_all, g2)) + { + } + + template < typename Vertex1, typename Vertex2 > + void operator()(const Vertex1& v1, Vertex2& v2) const + { + put(vertex_all_map2, v2, get(vertex_all_map1, v1)); + } + typename property_map< Graph1, vertex_all_t >::const_type + vertex_all_map1; + mutable + typename property_map< Graph2, vertex_all_t >::type vertex_all_map2; }; - template <typename Graph1, typename Graph2> - inline vertex_copier<Graph1,Graph2> - make_vertex_copier(const Graph1& g1, Graph2& g2) + template < typename Graph1, typename Graph2 > + inline vertex_copier< Graph1, Graph2 > make_vertex_copier( + const Graph1& g1, Graph2& g2) { - return vertex_copier<Graph1,Graph2>(g1, g2); + return vertex_copier< Graph1, Graph2 >(g1, g2); } // Copy all the vertices and edges of graph g_in into graph g_out. // The copy_vertex and copy_edge function objects control how vertex // and edge properties are copied. - template <int Version> - struct copy_graph_impl { }; + template < int Version > struct copy_graph_impl + { + }; - template <> struct copy_graph_impl<0> + template <> struct copy_graph_impl< 0 > { - template <typename Graph, typename MutableGraph, - typename CopyVertex, typename CopyEdge, typename IndexMap, - typename Orig2CopyVertexIndexMap> - static void apply(const Graph& g_in, MutableGraph& g_out, - CopyVertex copy_vertex, CopyEdge copy_edge, - Orig2CopyVertexIndexMap orig2copy, IndexMap) - { - typedef remove_reverse_edge_descriptor<Graph, typename graph_traits<Graph>::edge_descriptor> cvt; - typename graph_traits<Graph>::vertex_iterator vi, vi_end; - for (boost::tie(vi, vi_end) = vertices(g_in); vi != vi_end; ++vi) { - typename graph_traits<MutableGraph>::vertex_descriptor - new_v = add_vertex(g_out); - put(orig2copy, *vi, new_v); - copy_vertex(*vi, new_v); - } - typename graph_traits<Graph>::edge_iterator ei, ei_end; - for (boost::tie(ei, ei_end) = edges(g_in); ei != ei_end; ++ei) { - typename graph_traits<MutableGraph>::edge_descriptor new_e; - bool inserted; - boost::tie(new_e, inserted) = add_edge(get(orig2copy, source(*ei, g_in)), - get(orig2copy, target(*ei, g_in)), - g_out); - copy_edge(cvt::convert(*ei, g_in), new_e); + template < typename Graph, typename MutableGraph, typename CopyVertex, + typename CopyEdge, typename IndexMap, + typename Orig2CopyVertexIndexMap > + static void apply(const Graph& g_in, MutableGraph& g_out, + CopyVertex copy_vertex, CopyEdge copy_edge, + Orig2CopyVertexIndexMap orig2copy, IndexMap) + { + typedef remove_reverse_edge_descriptor< Graph, + typename graph_traits< Graph >::edge_descriptor > + cvt; + typename graph_traits< Graph >::vertex_iterator vi, vi_end; + for (boost::tie(vi, vi_end) = vertices(g_in); vi != vi_end; ++vi) + { + typename graph_traits< MutableGraph >::vertex_descriptor new_v + = add_vertex(g_out); + put(orig2copy, *vi, new_v); + copy_vertex(*vi, new_v); + } + typename graph_traits< Graph >::edge_iterator ei, ei_end; + for (boost::tie(ei, ei_end) = edges(g_in); ei != ei_end; ++ei) + { + typename graph_traits< MutableGraph >::edge_descriptor new_e; + bool inserted; + boost::tie(new_e, inserted) + = add_edge(get(orig2copy, source(*ei, g_in)), + get(orig2copy, target(*ei, g_in)), g_out); + copy_edge(cvt::convert(*ei, g_in), new_e); + } } - } }; // for directed graphs - template <> struct copy_graph_impl<1> + template <> struct copy_graph_impl< 1 > { - template <typename Graph, typename MutableGraph, - typename CopyVertex, typename CopyEdge, typename IndexMap, - typename Orig2CopyVertexIndexMap> - static void apply(const Graph& g_in, MutableGraph& g_out, - CopyVertex copy_vertex, CopyEdge copy_edge, - Orig2CopyVertexIndexMap orig2copy, IndexMap) - { - typedef remove_reverse_edge_descriptor<Graph, typename graph_traits<Graph>::edge_descriptor> cvt; - typename graph_traits<Graph>::vertex_iterator vi, vi_end; - for (boost::tie(vi, vi_end) = vertices(g_in); vi != vi_end; ++vi) { - typename graph_traits<MutableGraph>::vertex_descriptor - new_v = add_vertex(g_out); - put(orig2copy, *vi, new_v); - copy_vertex(*vi, new_v); - } - for (boost::tie(vi, vi_end) = vertices(g_in); vi != vi_end; ++vi) { - typename graph_traits<Graph>::out_edge_iterator ei, ei_end; - for (boost::tie(ei, ei_end) = out_edges(*vi, g_in); ei != ei_end; ++ei) { - typename graph_traits<MutableGraph>::edge_descriptor new_e; - bool inserted; - boost::tie(new_e, inserted) = add_edge(get(orig2copy, source(*ei, g_in)), - get(orig2copy, target(*ei, g_in)), - g_out); - copy_edge(cvt::convert(*ei, g_in), new_e); - } + template < typename Graph, typename MutableGraph, typename CopyVertex, + typename CopyEdge, typename IndexMap, + typename Orig2CopyVertexIndexMap > + static void apply(const Graph& g_in, MutableGraph& g_out, + CopyVertex copy_vertex, CopyEdge copy_edge, + Orig2CopyVertexIndexMap orig2copy, IndexMap) + { + typedef remove_reverse_edge_descriptor< Graph, + typename graph_traits< Graph >::edge_descriptor > + cvt; + typename graph_traits< Graph >::vertex_iterator vi, vi_end; + for (boost::tie(vi, vi_end) = vertices(g_in); vi != vi_end; ++vi) + { + typename graph_traits< MutableGraph >::vertex_descriptor new_v + = add_vertex(g_out); + put(orig2copy, *vi, new_v); + copy_vertex(*vi, new_v); + } + for (boost::tie(vi, vi_end) = vertices(g_in); vi != vi_end; ++vi) + { + typename graph_traits< Graph >::out_edge_iterator ei, ei_end; + for (boost::tie(ei, ei_end) = out_edges(*vi, g_in); + ei != ei_end; ++ei) + { + typename graph_traits< MutableGraph >::edge_descriptor + new_e; + bool inserted; + boost::tie(new_e, inserted) + = add_edge(get(orig2copy, source(*ei, g_in)), + get(orig2copy, target(*ei, g_in)), g_out); + copy_edge(cvt::convert(*ei, g_in), new_e); + } + } } - } }; // for undirected graphs - template <> struct copy_graph_impl<2> + template <> struct copy_graph_impl< 2 > { - template <typename Graph, typename MutableGraph, - typename CopyVertex, typename CopyEdge, typename IndexMap, - typename Orig2CopyVertexIndexMap> - static void apply(const Graph& g_in, MutableGraph& g_out, - CopyVertex copy_vertex, CopyEdge copy_edge, - Orig2CopyVertexIndexMap orig2copy, - IndexMap index_map) - { - typedef remove_reverse_edge_descriptor<Graph, typename graph_traits<Graph>::edge_descriptor> cvt; - typedef color_traits<default_color_type> Color; - std::vector<default_color_type> - color(num_vertices(g_in), Color::white()); - typename graph_traits<Graph>::vertex_iterator vi, vi_end; - for (boost::tie(vi, vi_end) = vertices(g_in); vi != vi_end; ++vi) { - typename graph_traits<MutableGraph>::vertex_descriptor - new_v = add_vertex(g_out); - put(orig2copy, *vi, new_v); - copy_vertex(*vi, new_v); - } - for (boost::tie(vi, vi_end) = vertices(g_in); vi != vi_end; ++vi) { - typename graph_traits<Graph>::out_edge_iterator ei, ei_end; - for (boost::tie(ei, ei_end) = out_edges(*vi, g_in); ei != ei_end; ++ei) { - typename graph_traits<MutableGraph>::edge_descriptor new_e; - bool inserted; - if (color[get(index_map, target(*ei, g_in))] == Color::white()) { - boost::tie(new_e, inserted) = add_edge(get(orig2copy, source(*ei,g_in)), - get(orig2copy, target(*ei,g_in)), - g_out); - copy_edge(cvt::convert(*ei, g_in), new_e); + template < typename Graph, typename MutableGraph, typename CopyVertex, + typename CopyEdge, typename IndexMap, + typename Orig2CopyVertexIndexMap > + static void apply(const Graph& g_in, MutableGraph& g_out, + CopyVertex copy_vertex, CopyEdge copy_edge, + Orig2CopyVertexIndexMap orig2copy, IndexMap index_map) + { + typedef remove_reverse_edge_descriptor< Graph, + typename graph_traits< Graph >::edge_descriptor > + cvt; + typedef color_traits< default_color_type > Color; + std::vector< default_color_type > color( + num_vertices(g_in), Color::white()); + typename graph_traits< Graph >::vertex_iterator vi, vi_end; + for (boost::tie(vi, vi_end) = vertices(g_in); vi != vi_end; ++vi) + { + typename graph_traits< MutableGraph >::vertex_descriptor new_v + = add_vertex(g_out); + put(orig2copy, *vi, new_v); + copy_vertex(*vi, new_v); + } + for (boost::tie(vi, vi_end) = vertices(g_in); vi != vi_end; ++vi) + { + typename graph_traits< Graph >::out_edge_iterator ei, ei_end; + for (boost::tie(ei, ei_end) = out_edges(*vi, g_in); + ei != ei_end; ++ei) + { + typename graph_traits< MutableGraph >::edge_descriptor + new_e; + bool inserted; + if (color[get(index_map, target(*ei, g_in))] + == Color::white()) + { + boost::tie(new_e, inserted) + = add_edge(get(orig2copy, source(*ei, g_in)), + get(orig2copy, target(*ei, g_in)), g_out); + copy_edge(cvt::convert(*ei, g_in), new_e); + } + } + color[get(index_map, *vi)] = Color::black(); } - } - color[get(index_map, *vi)] = Color::black(); } - } }; - template <class Graph> - struct choose_graph_copy { - typedef typename graph_traits<Graph>::traversal_category Trv; - typedef typename graph_traits<Graph>::directed_category Dr; - enum { algo = - (is_convertible<Trv, vertex_list_graph_tag>::value - && is_convertible<Trv, edge_list_graph_tag>::value) - ? 0 : is_convertible<Dr, directed_tag>::value ? 1 : 2 }; - typedef copy_graph_impl<algo> type; + template < class Graph > struct choose_graph_copy + { + typedef typename graph_traits< Graph >::traversal_category Trv; + typedef typename graph_traits< Graph >::directed_category Dr; + enum + { + algo = (is_convertible< Trv, vertex_list_graph_tag >::value + && is_convertible< Trv, edge_list_graph_tag >::value) + ? 0 + : is_convertible< Dr, directed_tag >::value ? 1 : 2 + }; + typedef copy_graph_impl< algo > type; }; //------------------------------------------------------------------------- - struct choose_copier_parameter { - template <class P, class G1, class G2> - struct bind_ { - typedef const P& result_type; - static result_type apply(const P& p, const G1&, G2&) - { return p; } - }; + struct choose_copier_parameter + { + template < class P, class G1, class G2 > struct bind_ + { + typedef const P& result_type; + static result_type apply(const P& p, const G1&, G2&) { return p; } + }; }; - struct choose_default_edge_copier { - template <class P, class G1, class G2> - struct bind_ { - typedef edge_copier<G1, G2> result_type; - static result_type apply(const P&, const G1& g1, G2& g2) { - return result_type(g1, g2); - } - }; + struct choose_default_edge_copier + { + template < class P, class G1, class G2 > struct bind_ + { + typedef edge_copier< G1, G2 > result_type; + static result_type apply(const P&, const G1& g1, G2& g2) + { + return result_type(g1, g2); + } + }; }; - template <class Param> - struct choose_edge_copy { - typedef choose_copier_parameter type; + template < class Param > struct choose_edge_copy + { + typedef choose_copier_parameter type; }; - template <> - struct choose_edge_copy<param_not_found> { - typedef choose_default_edge_copier type; + template <> struct choose_edge_copy< param_not_found > + { + typedef choose_default_edge_copier type; }; - template <class Param, class G1, class G2> - struct choose_edge_copier_helper { - typedef typename choose_edge_copy<Param>::type Selector; - typedef typename Selector:: template bind_<Param, G1, G2> Bind; - typedef Bind type; - typedef typename Bind::result_type result_type; + template < class Param, class G1, class G2 > + struct choose_edge_copier_helper + { + typedef typename choose_edge_copy< Param >::type Selector; + typedef typename Selector::template bind_< Param, G1, G2 > Bind; + typedef Bind type; + typedef typename Bind::result_type result_type; }; - template <typename Param, typename G1, typename G2> - typename detail::choose_edge_copier_helper<Param,G1,G2>::result_type + template < typename Param, typename G1, typename G2 > + typename detail::choose_edge_copier_helper< Param, G1, G2 >::result_type choose_edge_copier(const Param& params, const G1& g_in, G2& g_out) { - typedef typename - detail::choose_edge_copier_helper<Param,G1,G2>::type Choice; - return Choice::apply(params, g_in, g_out); + typedef + typename detail::choose_edge_copier_helper< Param, G1, G2 >::type + Choice; + return Choice::apply(params, g_in, g_out); } - - struct choose_default_vertex_copier { - template <class P, class G1, class G2> - struct bind_ { - typedef vertex_copier<G1, G2> result_type; - static result_type apply(const P&, const G1& g1, G2& g2) { - return result_type(g1, g2); - } - }; + struct choose_default_vertex_copier + { + template < class P, class G1, class G2 > struct bind_ + { + typedef vertex_copier< G1, G2 > result_type; + static result_type apply(const P&, const G1& g1, G2& g2) + { + return result_type(g1, g2); + } + }; }; - template <class Param> - struct choose_vertex_copy { - typedef choose_copier_parameter type; + template < class Param > struct choose_vertex_copy + { + typedef choose_copier_parameter type; }; - template <> - struct choose_vertex_copy<param_not_found> { - typedef choose_default_vertex_copier type; + template <> struct choose_vertex_copy< param_not_found > + { + typedef choose_default_vertex_copier type; }; - template <class Param, class G1, class G2> - struct choose_vertex_copier_helper { - typedef typename choose_vertex_copy<Param>::type Selector; - typedef typename Selector:: template bind_<Param, G1, G2> Bind; - typedef Bind type; - typedef typename Bind::result_type result_type; + template < class Param, class G1, class G2 > + struct choose_vertex_copier_helper + { + typedef typename choose_vertex_copy< Param >::type Selector; + typedef typename Selector::template bind_< Param, G1, G2 > Bind; + typedef Bind type; + typedef typename Bind::result_type result_type; }; - template <typename Param, typename G1, typename G2> - typename detail::choose_vertex_copier_helper<Param,G1,G2>::result_type + template < typename Param, typename G1, typename G2 > + typename detail::choose_vertex_copier_helper< Param, G1, G2 >::result_type choose_vertex_copier(const Param& params, const G1& g_in, G2& g_out) { - typedef typename - detail::choose_vertex_copier_helper<Param,G1,G2>::type Choice; - return Choice::apply(params, g_in, g_out); + typedef + typename detail::choose_vertex_copier_helper< Param, G1, G2 >::type + Choice; + return Choice::apply(params, g_in, g_out); } - } // namespace detail - +} // namespace detail - template <typename VertexListGraph, typename MutableGraph> - void copy_graph(const VertexListGraph& g_in, MutableGraph& g_out) - { +template < typename VertexListGraph, typename MutableGraph > +void copy_graph(const VertexListGraph& g_in, MutableGraph& g_out) +{ if (num_vertices(g_in) == 0) - return; - typedef typename graph_traits<MutableGraph>::vertex_descriptor vertex_t; - std::vector<vertex_t> orig2copy(num_vertices(g_in)); - typedef typename detail::choose_graph_copy<VertexListGraph>::type - copy_impl; - copy_impl::apply - (g_in, g_out, - detail::make_vertex_copier(g_in, g_out), - detail::make_edge_copier(g_in, g_out), - make_iterator_property_map(orig2copy.begin(), - get(vertex_index, g_in), orig2copy[0]), - get(vertex_index, g_in) - ); - } - - template <typename VertexListGraph, typename MutableGraph, - class P, class T, class R> - void copy_graph(const VertexListGraph& g_in, MutableGraph& g_out, - const bgl_named_params<P, T, R>& params) - { - typename std::vector<T>::size_type n; - n = is_default_param(get_param(params, orig_to_copy_t())) - ? num_vertices(g_in) : 1; + return; + typedef typename graph_traits< MutableGraph >::vertex_descriptor vertex_t; + std::vector< vertex_t > orig2copy(num_vertices(g_in)); + typedef + typename detail::choose_graph_copy< VertexListGraph >::type copy_impl; + copy_impl::apply(g_in, g_out, detail::make_vertex_copier(g_in, g_out), + detail::make_edge_copier(g_in, g_out), + make_iterator_property_map( + orig2copy.begin(), get(vertex_index, g_in), orig2copy[0]), + get(vertex_index, g_in)); +} + +template < typename VertexListGraph, typename MutableGraph, class P, class T, + class R > +void copy_graph(const VertexListGraph& g_in, MutableGraph& g_out, + const bgl_named_params< P, T, R >& params) +{ + typename std::vector< T >::size_type n; + n = is_default_param(get_param(params, orig_to_copy_t())) + ? num_vertices(g_in) + : 1; if (n == 0) - return; - std::vector<BOOST_DEDUCED_TYPENAME graph_traits<MutableGraph>::vertex_descriptor> - orig2copy(n); - - typedef typename detail::choose_graph_copy<VertexListGraph>::type - copy_impl; - copy_impl::apply - (g_in, g_out, - detail::choose_vertex_copier(get_param(params, vertex_copy_t()), - g_in, g_out), - detail::choose_edge_copier(get_param(params, edge_copy_t()), - g_in, g_out), - choose_param(get_param(params, orig_to_copy_t()), - make_iterator_property_map - (orig2copy.begin(), - choose_const_pmap(get_param(params, vertex_index), - g_in, vertex_index), orig2copy[0])), - choose_const_pmap(get_param(params, vertex_index), g_in, vertex_index) - ); - } - - namespace detail { - - template <class NewGraph, class Copy2OrigIndexMap, - class CopyVertex, class CopyEdge> + return; + std::vector< + BOOST_DEDUCED_TYPENAME graph_traits< MutableGraph >::vertex_descriptor > + orig2copy(n); + + typedef + typename detail::choose_graph_copy< VertexListGraph >::type copy_impl; + copy_impl::apply(g_in, g_out, + detail::choose_vertex_copier( + get_param(params, vertex_copy_t()), g_in, g_out), + detail::choose_edge_copier( + get_param(params, edge_copy_t()), g_in, g_out), + choose_param(get_param(params, orig_to_copy_t()), + make_iterator_property_map(orig2copy.begin(), + choose_const_pmap( + get_param(params, vertex_index), g_in, vertex_index), + orig2copy[0])), + choose_const_pmap(get_param(params, vertex_index), g_in, vertex_index)); +} + +namespace detail +{ + + template < class NewGraph, class Copy2OrigIndexMap, class CopyVertex, + class CopyEdge > struct graph_copy_visitor : public bfs_visitor<> { - graph_copy_visitor(NewGraph& graph, Copy2OrigIndexMap c, - CopyVertex cv, CopyEdge ce) - : g_out(graph), orig2copy(c), copy_vertex(cv), copy_edge(ce) { } - - template <class Vertex, class Graph> - typename graph_traits<NewGraph>::vertex_descriptor copy_one_vertex(Vertex u) const { - typename graph_traits<NewGraph>::vertex_descriptor - new_u = add_vertex(g_out); - put(orig2copy, u, new_u); - copy_vertex(u, new_u); - return new_u; - } - - template <class Edge, class Graph> - void tree_edge(Edge e, const Graph& g_in) const { - // For a tree edge, the target vertex has not been copied yet. - typename graph_traits<NewGraph>::edge_descriptor new_e; - bool inserted; - boost::tie(new_e, inserted) = add_edge(get(orig2copy, source(e, g_in)), - this->copy_one_vertex(target(e, g_in)), - g_out); - copy_edge(e, new_e); - } - - template <class Edge, class Graph> - void non_tree_edge(Edge e, const Graph& g_in) const { - // For a non-tree edge, the target vertex has already been copied. - typename graph_traits<NewGraph>::edge_descriptor new_e; - bool inserted; - boost::tie(new_e, inserted) = add_edge(get(orig2copy, source(e, g_in)), - get(orig2copy, target(e, g_in)), - g_out); - copy_edge(e, new_e); - } + graph_copy_visitor( + NewGraph& graph, Copy2OrigIndexMap c, CopyVertex cv, CopyEdge ce) + : g_out(graph), orig2copy(c), copy_vertex(cv), copy_edge(ce) + { + } + + template < class Vertex > + typename graph_traits< NewGraph >::vertex_descriptor copy_one_vertex( + Vertex u) const + { + typename graph_traits< NewGraph >::vertex_descriptor new_u + = add_vertex(g_out); + put(orig2copy, u, new_u); + copy_vertex(u, new_u); + return new_u; + } + + template < class Edge, class Graph > + void tree_edge(Edge e, const Graph& g_in) const + { + // For a tree edge, the target vertex has not been copied yet. + typename graph_traits< NewGraph >::edge_descriptor new_e; + bool inserted; + boost::tie(new_e, inserted) + = add_edge(get(orig2copy, source(e, g_in)), + this->copy_one_vertex(target(e, g_in)), g_out); + copy_edge(e, new_e); + } + + template < class Edge, class Graph > + void non_tree_edge(Edge e, const Graph& g_in) const + { + // For a non-tree edge, the target vertex has already been copied. + typename graph_traits< NewGraph >::edge_descriptor new_e; + bool inserted; + boost::tie(new_e, inserted) + = add_edge(get(orig2copy, source(e, g_in)), + get(orig2copy, target(e, g_in)), g_out); + copy_edge(e, new_e); + } + private: - NewGraph& g_out; - Copy2OrigIndexMap orig2copy; - CopyVertex copy_vertex; - CopyEdge copy_edge; + NewGraph& g_out; + Copy2OrigIndexMap orig2copy; + CopyVertex copy_vertex; + CopyEdge copy_edge; }; - template <typename Graph, typename MutableGraph, - typename CopyVertex, typename CopyEdge, - typename Orig2CopyVertexIndexMap, typename Params> - typename graph_traits<MutableGraph>::vertex_descriptor - copy_component_impl - (const Graph& g_in, - typename graph_traits<Graph>::vertex_descriptor src, - MutableGraph& g_out, - CopyVertex copy_vertex, CopyEdge copy_edge, - Orig2CopyVertexIndexMap orig2copy, - const Params& params) + template < typename Graph, typename MutableGraph, typename CopyVertex, + typename CopyEdge, typename Orig2CopyVertexIndexMap, typename Params > + typename graph_traits< MutableGraph >::vertex_descriptor + copy_component_impl(const Graph& g_in, + typename graph_traits< Graph >::vertex_descriptor src, + MutableGraph& g_out, CopyVertex copy_vertex, CopyEdge copy_edge, + Orig2CopyVertexIndexMap orig2copy, const Params& params) { - graph_copy_visitor<MutableGraph, Orig2CopyVertexIndexMap, - CopyVertex, CopyEdge> vis(g_out, orig2copy, copy_vertex, copy_edge); - typename graph_traits<MutableGraph>::vertex_descriptor src_copy - = vis.copy_one_vertex(src); - breadth_first_search(g_in, src, params.visitor(vis)); - return src_copy; + graph_copy_visitor< MutableGraph, Orig2CopyVertexIndexMap, CopyVertex, + CopyEdge > + vis(g_out, orig2copy, copy_vertex, copy_edge); + typename graph_traits< MutableGraph >::vertex_descriptor src_copy + = vis.copy_one_vertex(src); + breadth_first_search(g_in, src, params.visitor(vis)); + return src_copy; } - } // namespace detail - - - // Copy all the vertices and edges of graph g_in that are reachable - // from the source vertex into graph g_out. Return the vertex - // in g_out that matches the source vertex of g_in. - template <typename IncidenceGraph, typename MutableGraph, - typename P, typename T, typename R> - typename graph_traits<MutableGraph>::vertex_descriptor - copy_component(IncidenceGraph& g_in, - typename graph_traits<IncidenceGraph>::vertex_descriptor src, - MutableGraph& g_out, - const bgl_named_params<P, T, R>& params) - { - typename std::vector<T>::size_type n; - n = is_default_param(get_param(params, orig_to_copy_t())) - ? num_vertices(g_in) : 1; - std::vector<typename graph_traits<IncidenceGraph>::vertex_descriptor> - orig2copy(n); - - return detail::copy_component_impl - (g_in, src, g_out, - detail::choose_vertex_copier(get_param(params, vertex_copy_t()), - g_in, g_out), - detail::choose_edge_copier(get_param(params, edge_copy_t()), - g_in, g_out), - choose_param(get_param(params, orig_to_copy_t()), - make_iterator_property_map - (orig2copy.begin(), - choose_pmap(get_param(params, vertex_index), - g_in, vertex_index), orig2copy[0])), - params - ); - } - - template <typename IncidenceGraph, typename MutableGraph> - typename graph_traits<MutableGraph>::vertex_descriptor - copy_component(IncidenceGraph& g_in, - typename graph_traits<IncidenceGraph>::vertex_descriptor src, - MutableGraph& g_out) - { - std::vector<typename graph_traits<IncidenceGraph>::vertex_descriptor> - orig2copy(num_vertices(g_in)); - - return detail::copy_component_impl - (g_in, src, g_out, - make_vertex_copier(g_in, g_out), - make_edge_copier(g_in, g_out), - make_iterator_property_map(orig2copy.begin(), - get(vertex_index, g_in), orig2copy[0]), - bgl_named_params<char,char>('x') // dummy param object - ); - } +} // namespace detail + +// Copy all the vertices and edges of graph g_in that are reachable +// from the source vertex into graph g_out. Return the vertex +// in g_out that matches the source vertex of g_in. +template < typename IncidenceGraph, typename MutableGraph, typename P, + typename T, typename R > +typename graph_traits< MutableGraph >::vertex_descriptor copy_component( + IncidenceGraph& g_in, + typename graph_traits< IncidenceGraph >::vertex_descriptor src, + MutableGraph& g_out, const bgl_named_params< P, T, R >& params) +{ + typename std::vector< T >::size_type n; + n = is_default_param(get_param(params, orig_to_copy_t())) + ? num_vertices(g_in) + : 1; + std::vector< typename graph_traits< IncidenceGraph >::vertex_descriptor > + orig2copy(n); + + return detail::copy_component_impl(g_in, src, g_out, + detail::choose_vertex_copier( + get_param(params, vertex_copy_t()), g_in, g_out), + detail::choose_edge_copier( + get_param(params, edge_copy_t()), g_in, g_out), + choose_param(get_param(params, orig_to_copy_t()), + make_iterator_property_map(orig2copy.begin(), + choose_pmap( + get_param(params, vertex_index), g_in, vertex_index), + orig2copy[0])), + params); +} + +template < typename IncidenceGraph, typename MutableGraph > +typename graph_traits< MutableGraph >::vertex_descriptor copy_component( + IncidenceGraph& g_in, + typename graph_traits< IncidenceGraph >::vertex_descriptor src, + MutableGraph& g_out) +{ + std::vector< typename graph_traits< IncidenceGraph >::vertex_descriptor > + orig2copy(num_vertices(g_in)); + + return detail::copy_component_impl(g_in, src, g_out, + make_vertex_copier(g_in, g_out), make_edge_copier(g_in, g_out), + make_iterator_property_map( + orig2copy.begin(), get(vertex_index, g_in), orig2copy[0]), + bgl_named_params< char, char >('x') // dummy param object + ); +} } // namespace boost diff --git a/contrib/restricted/boost/graph/include/boost/graph/dag_shortest_paths.hpp b/contrib/restricted/boost/graph/include/boost/graph/dag_shortest_paths.hpp index 325d1516c3..a0aecc169f 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/dag_shortest_paths.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/dag_shortest_paths.hpp @@ -15,25 +15,21 @@ // single-source shortest paths for a Directed Acyclic Graph (DAG) -namespace boost { - - // Initalize distances and call depth first search - template <class VertexListGraph, class DijkstraVisitor, - class DistanceMap, class WeightMap, class ColorMap, - class PredecessorMap, - class Compare, class Combine, - class DistInf, class DistZero> - inline void - dag_shortest_paths - (const VertexListGraph& g, - typename graph_traits<VertexListGraph>::vertex_descriptor s, - DistanceMap distance, WeightMap weight, ColorMap color, - PredecessorMap pred, - DijkstraVisitor vis, Compare compare, Combine combine, - DistInf inf, DistZero zero) - { - typedef typename graph_traits<VertexListGraph>::vertex_descriptor Vertex; - std::vector<Vertex> rev_topo_order; +namespace boost +{ + +// Initalize distances and call depth first search +template < class VertexListGraph, class DijkstraVisitor, class DistanceMap, + class WeightMap, class ColorMap, class PredecessorMap, class Compare, + class Combine, class DistInf, class DistZero > +inline void dag_shortest_paths(const VertexListGraph& g, + typename graph_traits< VertexListGraph >::vertex_descriptor s, + DistanceMap distance, WeightMap weight, ColorMap color, PredecessorMap pred, + DijkstraVisitor vis, Compare compare, Combine combine, DistInf inf, + DistZero zero) +{ + typedef typename graph_traits< VertexListGraph >::vertex_descriptor Vertex; + std::vector< Vertex > rev_topo_order; rev_topo_order.reserve(num_vertices(g)); // Call 'depth_first_visit', not 'topological_sort', because we don't @@ -41,119 +37,109 @@ namespace boost { // and 'topological_sort' will traverse everything. The logic below // is the same as for 'topological_sort', only we call 'depth_first_visit' // and 'topological_sort' calls 'depth_first_search'. - topo_sort_visitor<std::back_insert_iterator<std::vector<Vertex> > > + topo_sort_visitor< std::back_insert_iterator< std::vector< Vertex > > > topo_visitor(std::back_inserter(rev_topo_order)); depth_first_visit(g, s, topo_visitor, color); - typename graph_traits<VertexListGraph>::vertex_iterator ui, ui_end; - for (boost::tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui) { - put(distance, *ui, inf); - put(pred, *ui, *ui); + typename graph_traits< VertexListGraph >::vertex_iterator ui, ui_end; + for (boost::tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui) + { + put(distance, *ui, inf); + put(pred, *ui, *ui); } put(distance, s, zero); vis.discover_vertex(s, g); - typename std::vector<Vertex>::reverse_iterator i; - for (i = rev_topo_order.rbegin(); i != rev_topo_order.rend(); ++i) { - Vertex u = *i; - vis.examine_vertex(u, g); - typename graph_traits<VertexListGraph>::out_edge_iterator e, e_end; - for (boost::tie(e, e_end) = out_edges(u, g); e != e_end; ++e) { - vis.discover_vertex(target(*e, g), g); - bool decreased = relax(*e, g, weight, pred, distance, - combine, compare); - if (decreased) - vis.edge_relaxed(*e, g); - else - vis.edge_not_relaxed(*e, g); - } - vis.finish_vertex(u, g); + typename std::vector< Vertex >::reverse_iterator i; + for (i = rev_topo_order.rbegin(); i != rev_topo_order.rend(); ++i) + { + Vertex u = *i; + vis.examine_vertex(u, g); + typename graph_traits< VertexListGraph >::out_edge_iterator e, e_end; + for (boost::tie(e, e_end) = out_edges(u, g); e != e_end; ++e) + { + vis.discover_vertex(target(*e, g), g); + bool decreased + = relax(*e, g, weight, pred, distance, combine, compare); + if (decreased) + vis.edge_relaxed(*e, g); + else + vis.edge_not_relaxed(*e, g); + } + vis.finish_vertex(u, g); } - } +} - namespace detail { +namespace detail +{ // Defaults are the same as Dijkstra's algorithm // Handle Distance Compare, Combine, Inf and Zero defaults - template <class VertexListGraph, class DijkstraVisitor, - class DistanceMap, class WeightMap, class ColorMap, - class IndexMap, class Params> - inline void - dag_sp_dispatch2 - (const VertexListGraph& g, - typename graph_traits<VertexListGraph>::vertex_descriptor s, - DistanceMap distance, WeightMap weight, ColorMap color, IndexMap /*id*/, - DijkstraVisitor vis, const Params& params) + template < class VertexListGraph, class DijkstraVisitor, class DistanceMap, + class WeightMap, class ColorMap, class IndexMap, class Params > + inline void dag_sp_dispatch2(const VertexListGraph& g, + typename graph_traits< VertexListGraph >::vertex_descriptor s, + DistanceMap distance, WeightMap weight, ColorMap color, IndexMap /*id*/, + DijkstraVisitor vis, const Params& params) { - typedef typename property_traits<DistanceMap>::value_type D; - dummy_property_map p_map; - D inf = - choose_param(get_param(params, distance_inf_t()), - (std::numeric_limits<D>::max)()); - dag_shortest_paths - (g, s, distance, weight, color, - choose_param(get_param(params, vertex_predecessor), p_map), - vis, - choose_param(get_param(params, distance_compare_t()), std::less<D>()), - choose_param(get_param(params, distance_combine_t()), closed_plus<D>(inf)), - inf, - choose_param(get_param(params, distance_zero_t()), - D())); + typedef typename property_traits< DistanceMap >::value_type D; + dummy_property_map p_map; + D inf = choose_param(get_param(params, distance_inf_t()), + (std::numeric_limits< D >::max)()); + dag_shortest_paths(g, s, distance, weight, color, + choose_param(get_param(params, vertex_predecessor), p_map), vis, + choose_param( + get_param(params, distance_compare_t()), std::less< D >()), + choose_param( + get_param(params, distance_combine_t()), closed_plus< D >(inf)), + inf, choose_param(get_param(params, distance_zero_t()), D())); } // Handle DistanceMap and ColorMap defaults - template <class VertexListGraph, class DijkstraVisitor, - class DistanceMap, class WeightMap, class ColorMap, - class IndexMap, class Params> - inline void - dag_sp_dispatch1 - (const VertexListGraph& g, - typename graph_traits<VertexListGraph>::vertex_descriptor s, - DistanceMap distance, WeightMap weight, ColorMap color, IndexMap id, - DijkstraVisitor vis, const Params& params) + template < class VertexListGraph, class DijkstraVisitor, class DistanceMap, + class WeightMap, class ColorMap, class IndexMap, class Params > + inline void dag_sp_dispatch1(const VertexListGraph& g, + typename graph_traits< VertexListGraph >::vertex_descriptor s, + DistanceMap distance, WeightMap weight, ColorMap color, IndexMap id, + DijkstraVisitor vis, const Params& params) { - typedef typename property_traits<WeightMap>::value_type T; - typename std::vector<T>::size_type n; - n = is_default_param(distance) ? num_vertices(g) : 1; - std::vector<T> distance_map(n); - n = is_default_param(color) ? num_vertices(g) : 1; - std::vector<default_color_type> color_map(n); - - dag_sp_dispatch2 - (g, s, - choose_param(distance, - make_iterator_property_map(distance_map.begin(), id, - distance_map[0])), - weight, - choose_param(color, - make_iterator_property_map(color_map.begin(), id, - color_map[0])), - id, vis, params); + typedef typename property_traits< WeightMap >::value_type T; + typename std::vector< T >::size_type n; + n = is_default_param(distance) ? num_vertices(g) : 1; + std::vector< T > distance_map(n); + n = is_default_param(color) ? num_vertices(g) : 1; + std::vector< default_color_type > color_map(n); + + dag_sp_dispatch2(g, s, + choose_param(distance, + make_iterator_property_map( + distance_map.begin(), id, distance_map[0])), + weight, + choose_param(color, + make_iterator_property_map( + color_map.begin(), id, color_map[0])), + id, vis, params); } - - } // namespace detail - - template <class VertexListGraph, class Param, class Tag, class Rest> - inline void - dag_shortest_paths - (const VertexListGraph& g, - typename graph_traits<VertexListGraph>::vertex_descriptor s, - const bgl_named_params<Param,Tag,Rest>& params) - { + +} // namespace detail + +template < class VertexListGraph, class Param, class Tag, class Rest > +inline void dag_shortest_paths(const VertexListGraph& g, + typename graph_traits< VertexListGraph >::vertex_descriptor s, + const bgl_named_params< Param, Tag, Rest >& params) +{ // assert that the graph is directed... null_visitor null_vis; - detail::dag_sp_dispatch1 - (g, s, - get_param(params, vertex_distance), - choose_const_pmap(get_param(params, edge_weight), g, edge_weight), - get_param(params, vertex_color), - choose_const_pmap(get_param(params, vertex_index), g, vertex_index), - choose_param(get_param(params, graph_visitor), - make_dijkstra_visitor(null_vis)), - params); - } - + detail::dag_sp_dispatch1(g, s, get_param(params, vertex_distance), + choose_const_pmap(get_param(params, edge_weight), g, edge_weight), + get_param(params, vertex_color), + choose_const_pmap(get_param(params, vertex_index), g, vertex_index), + choose_param( + get_param(params, graph_visitor), make_dijkstra_visitor(null_vis)), + params); +} + } // namespace boost #endif // BOOST_GRAPH_DAG_SHORTEST_PATHS_HPP diff --git a/contrib/restricted/boost/graph/include/boost/graph/depth_first_search.hpp b/contrib/restricted/boost/graph/include/boost/graph/depth_first_search.hpp index 277e976858..17d25e89c3 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/depth_first_search.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/depth_first_search.hpp @@ -19,6 +19,7 @@ #include <boost/graph/properties.hpp> #include <boost/graph/visitors.hpp> #include <boost/graph/named_function_params.hpp> +#include <boost/graph/detail/mpi_include.hpp> #include <boost/ref.hpp> #include <boost/implicit_cast.hpp> #include <boost/optional.hpp> @@ -29,65 +30,80 @@ #include <vector> #include <utility> -namespace boost { - - template <class Visitor, class Graph> - class DFSVisitorConcept { - public: - void constraints() { - BOOST_CONCEPT_ASSERT(( CopyConstructibleConcept<Visitor> )); - vis.initialize_vertex(u, g); - vis.start_vertex(u, g); - vis.discover_vertex(u, g); - vis.examine_edge(e, g); - vis.tree_edge(e, g); - vis.back_edge(e, g); - vis.forward_or_cross_edge(e, g); - // vis.finish_edge(e, g); // Optional for user - vis.finish_vertex(u, g); +namespace boost +{ + +template < class Visitor, class Graph > class DFSVisitorConcept +{ +public: + void constraints() + { + BOOST_CONCEPT_ASSERT((CopyConstructibleConcept< Visitor >)); + vis.initialize_vertex(u, g); + vis.start_vertex(u, g); + vis.discover_vertex(u, g); + vis.examine_edge(e, g); + vis.tree_edge(e, g); + vis.back_edge(e, g); + vis.forward_or_cross_edge(e, g); + // vis.finish_edge(e, g); // Optional for user + vis.finish_vertex(u, g); } - private: + +private: Visitor vis; Graph g; - typename graph_traits<Graph>::vertex_descriptor u; - typename graph_traits<Graph>::edge_descriptor e; - }; + typename graph_traits< Graph >::vertex_descriptor u; + typename graph_traits< Graph >::edge_descriptor e; +}; - namespace detail { +namespace detail +{ - struct nontruth2 { - template<class T, class T2> - bool operator()(const T&, const T2&) const { return false; } + struct nontruth2 + { + template < class T, class T2 > + bool operator()(const T&, const T2&) const + { + return false; + } }; BOOST_TTI_HAS_MEMBER_FUNCTION(finish_edge) - template <bool IsCallable> struct do_call_finish_edge { - template <typename E, typename G, typename Vis> - static void call_finish_edge(Vis& vis, E e, const G& g) { - vis.finish_edge(e, g); - } + template < bool IsCallable > struct do_call_finish_edge + { + template < typename E, typename G, typename Vis > + static void call_finish_edge(Vis& vis, E e, const G& g) + { + vis.finish_edge(e, g); + } }; - template <> struct do_call_finish_edge<false> { - template <typename E, typename G, typename Vis> - static void call_finish_edge(Vis&, E, const G&) {} + template <> struct do_call_finish_edge< false > + { + template < typename E, typename G, typename Vis > + static void call_finish_edge(Vis&, E, const G&) + { + } }; - template <typename E, typename G, typename Vis> - void call_finish_edge(Vis& vis, E e, const G& g) { // Only call if method exists -#if ((defined(__GNUC__) && (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 9))) || \ - defined(__clang__) || \ - (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1200))) - do_call_finish_edge< - has_member_function_finish_edge<Vis, void, - boost::mpl::vector<E, const G&> >::value>::call_finish_edge(vis, e, g); + template < typename E, typename G, typename Vis > + void call_finish_edge(Vis& vis, E e, const G& g) + { // Only call if method exists +#if ((defined(__GNUC__) && (__GNUC__ > 4) \ + || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 9))) \ + || defined(__clang__) \ + || (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1200))) + do_call_finish_edge< has_member_function_finish_edge< Vis, void, + boost::mpl::vector< E, const G& > >::value >::call_finish_edge(vis, + e, g); #else - do_call_finish_edge<has_member_function_finish_edge<Vis, void>::value>::call_finish_edge(vis, e, g); + do_call_finish_edge< has_member_function_finish_edge< Vis, + void >::value >::call_finish_edge(vis, e, g); #endif } - // Define BOOST_RECURSIVE_DFS to use older, recursive version. // It is retained for a while in order to perform performance // comparison. @@ -102,272 +118,316 @@ namespace boost { // The corresponding context shift back from the adjacent vertex occurs // after all of its out-edges have been examined. // - // See http://lists.boost.org/MailArchives/boost/msg48752.php for FAQ. - - template <class IncidenceGraph, class DFSVisitor, class ColorMap, - class TerminatorFunc> - void depth_first_visit_impl - (const IncidenceGraph& g, - typename graph_traits<IncidenceGraph>::vertex_descriptor u, - DFSVisitor& vis, - ColorMap color, TerminatorFunc func = TerminatorFunc()) + // See https://lists.boost.org/Archives/boost/2003/06/49265.php for FAQ. + + template < class IncidenceGraph, class DFSVisitor, class ColorMap, + class TerminatorFunc > + void depth_first_visit_impl(const IncidenceGraph& g, + typename graph_traits< IncidenceGraph >::vertex_descriptor u, + DFSVisitor& vis, ColorMap color, TerminatorFunc func = TerminatorFunc()) { - BOOST_CONCEPT_ASSERT(( IncidenceGraphConcept<IncidenceGraph> )); - BOOST_CONCEPT_ASSERT(( DFSVisitorConcept<DFSVisitor, IncidenceGraph> )); - typedef typename graph_traits<IncidenceGraph>::vertex_descriptor Vertex; - typedef typename graph_traits<IncidenceGraph>::edge_descriptor Edge; - BOOST_CONCEPT_ASSERT(( ReadWritePropertyMapConcept<ColorMap, Vertex> )); - typedef typename property_traits<ColorMap>::value_type ColorValue; - BOOST_CONCEPT_ASSERT(( ColorValueConcept<ColorValue> )); - typedef color_traits<ColorValue> Color; - typedef typename graph_traits<IncidenceGraph>::out_edge_iterator Iter; - typedef std::pair<Vertex, std::pair<boost::optional<Edge>, std::pair<Iter, Iter> > > VertexInfo; - - boost::optional<Edge> src_e; - Iter ei, ei_end; - std::vector<VertexInfo> stack; - - // Possible optimization for vector - //stack.reserve(num_vertices(g)); - - put(color, u, Color::gray()); - vis.discover_vertex(u, g); - boost::tie(ei, ei_end) = out_edges(u, g); - if (func(u, g)) { - // If this vertex terminates the search, we push empty range - stack.push_back(std::make_pair(u, std::make_pair(boost::optional<Edge>(), std::make_pair(ei_end, ei_end)))); - } else { - stack.push_back(std::make_pair(u, std::make_pair(boost::optional<Edge>(), std::make_pair(ei, ei_end)))); - } - while (!stack.empty()) { - VertexInfo& back = stack.back(); - u = back.first; - src_e = back.second.first; - boost::tie(ei, ei_end) = back.second.second; - stack.pop_back(); - // finish_edge has to be called here, not after the - // loop. Think of the pop as the return from a recursive call. - if (src_e) { - call_finish_edge(vis, src_e.get(), g); - } - while (ei != ei_end) { - Vertex v = target(*ei, g); - vis.examine_edge(*ei, g); - ColorValue v_color = get(color, v); - if (v_color == Color::white()) { - vis.tree_edge(*ei, g); - src_e = *ei; - stack.push_back(std::make_pair(u, std::make_pair(src_e, std::make_pair(++ei, ei_end)))); - u = v; - put(color, u, Color::gray()); - vis.discover_vertex(u, g); - boost::tie(ei, ei_end) = out_edges(u, g); - if (func(u, g)) { - ei = ei_end; + BOOST_CONCEPT_ASSERT((IncidenceGraphConcept< IncidenceGraph >)); + BOOST_CONCEPT_ASSERT((DFSVisitorConcept< DFSVisitor, IncidenceGraph >)); + typedef + typename graph_traits< IncidenceGraph >::vertex_descriptor Vertex; + typedef typename graph_traits< IncidenceGraph >::edge_descriptor Edge; + BOOST_CONCEPT_ASSERT((ReadWritePropertyMapConcept< ColorMap, Vertex >)); + typedef typename property_traits< ColorMap >::value_type ColorValue; + BOOST_CONCEPT_ASSERT((ColorValueConcept< ColorValue >)); + typedef color_traits< ColorValue > Color; + typedef typename graph_traits< IncidenceGraph >::out_edge_iterator Iter; + typedef std::pair< Vertex, + std::pair< boost::optional< Edge >, std::pair< Iter, Iter > > > + VertexInfo; + + boost::optional< Edge > src_e; + Iter ei, ei_end; + std::vector< VertexInfo > stack; + + // Possible optimization for vector + // stack.reserve(num_vertices(g)); + + put(color, u, Color::gray()); + vis.discover_vertex(u, g); + boost::tie(ei, ei_end) = out_edges(u, g); + if (func(u, g)) + { + // If this vertex terminates the search, we push empty range + stack.push_back(std::make_pair(u, + std::make_pair(boost::optional< Edge >(), + std::make_pair(ei_end, ei_end)))); + } + else + { + stack.push_back(std::make_pair(u, + std::make_pair( + boost::optional< Edge >(), std::make_pair(ei, ei_end)))); + } + while (!stack.empty()) + { + VertexInfo& back = stack.back(); + u = back.first; + src_e = back.second.first; + boost::tie(ei, ei_end) = back.second.second; + stack.pop_back(); + // finish_edge has to be called here, not after the + // loop. Think of the pop as the return from a recursive call. + if (src_e) + { + call_finish_edge(vis, src_e.get(), g); } - } else { - if (v_color == Color::gray()) { - vis.back_edge(*ei, g); - } else { - vis.forward_or_cross_edge(*ei, g); + while (ei != ei_end) + { + Vertex v = target(*ei, g); + vis.examine_edge(*ei, g); + ColorValue v_color = get(color, v); + if (v_color == Color::white()) + { + vis.tree_edge(*ei, g); + src_e = *ei; + stack.push_back(std::make_pair(u, + std::make_pair(src_e, std::make_pair(++ei, ei_end)))); + u = v; + put(color, u, Color::gray()); + vis.discover_vertex(u, g); + boost::tie(ei, ei_end) = out_edges(u, g); + if (func(u, g)) + { + ei = ei_end; + } + } + else + { + if (v_color == Color::gray()) + { + vis.back_edge(*ei, g); + } + else + { + vis.forward_or_cross_edge(*ei, g); + } + call_finish_edge(vis, *ei, g); + ++ei; + } } - call_finish_edge(vis, *ei, g); - ++ei; - } + put(color, u, Color::black()); + vis.finish_vertex(u, g); } - put(color, u, Color::black()); - vis.finish_vertex(u, g); - } } #else // BOOST_RECURSIVE_DFS is defined - template <class IncidenceGraph, class DFSVisitor, class ColorMap, - class TerminatorFunc> - void depth_first_visit_impl - (const IncidenceGraph& g, - typename graph_traits<IncidenceGraph>::vertex_descriptor u, - DFSVisitor& vis, // pass-by-reference here, important! - ColorMap color, TerminatorFunc func) + template < class IncidenceGraph, class DFSVisitor, class ColorMap, + class TerminatorFunc > + void depth_first_visit_impl(const IncidenceGraph& g, + typename graph_traits< IncidenceGraph >::vertex_descriptor u, + DFSVisitor& vis, // pass-by-reference here, important! + ColorMap color, TerminatorFunc func) { - BOOST_CONCEPT_ASSERT(( IncidenceGraphConcept<IncidenceGraph> )); - BOOST_CONCEPT_ASSERT(( DFSVisitorConcept<DFSVisitor, IncidenceGraph> )); - typedef typename graph_traits<IncidenceGraph>::vertex_descriptor Vertex; - BOOST_CONCEPT_ASSERT(( ReadWritePropertyMapConcept<ColorMap, Vertex> )); - typedef typename property_traits<ColorMap>::value_type ColorValue; - BOOST_CONCEPT_ASSERT(( ColorValueConcept<ColorValue> )); - typedef color_traits<ColorValue> Color; - typename graph_traits<IncidenceGraph>::out_edge_iterator ei, ei_end; - - put(color, u, Color::gray()); vis.discover_vertex(u, g); - - if (!func(u, g)) - for (boost::tie(ei, ei_end) = out_edges(u, g); ei != ei_end; ++ei) { - Vertex v = target(*ei, g); vis.examine_edge(*ei, g); - ColorValue v_color = get(color, v); - if (v_color == Color::white()) { vis.tree_edge(*ei, g); - depth_first_visit_impl(g, v, vis, color, func); - } else if (v_color == Color::gray()) vis.back_edge(*ei, g); - else vis.forward_or_cross_edge(*ei, g); - call_finish_edge(vis, *ei, g); - } - put(color, u, Color::black()); vis.finish_vertex(u, g); + BOOST_CONCEPT_ASSERT((IncidenceGraphConcept< IncidenceGraph >)); + BOOST_CONCEPT_ASSERT((DFSVisitorConcept< DFSVisitor, IncidenceGraph >)); + typedef + typename graph_traits< IncidenceGraph >::vertex_descriptor Vertex; + BOOST_CONCEPT_ASSERT((ReadWritePropertyMapConcept< ColorMap, Vertex >)); + typedef typename property_traits< ColorMap >::value_type ColorValue; + BOOST_CONCEPT_ASSERT((ColorValueConcept< ColorValue >)); + typedef color_traits< ColorValue > Color; + typename graph_traits< IncidenceGraph >::out_edge_iterator ei, ei_end; + + put(color, u, Color::gray()); + vis.discover_vertex(u, g); + + if (!func(u, g)) + for (boost::tie(ei, ei_end) = out_edges(u, g); ei != ei_end; ++ei) + { + Vertex v = target(*ei, g); + vis.examine_edge(*ei, g); + ColorValue v_color = get(color, v); + if (v_color == Color::white()) + { + vis.tree_edge(*ei, g); + depth_first_visit_impl(g, v, vis, color, func); + } + else if (v_color == Color::gray()) + vis.back_edge(*ei, g); + else + vis.forward_or_cross_edge(*ei, g); + call_finish_edge(vis, *ei, g); + } + put(color, u, Color::black()); + vis.finish_vertex(u, g); } #endif - } // namespace detail - - template <class VertexListGraph, class DFSVisitor, class ColorMap> - void - depth_first_search(const VertexListGraph& g, DFSVisitor vis, ColorMap color, - typename graph_traits<VertexListGraph>::vertex_descriptor start_vertex) - { - typedef typename graph_traits<VertexListGraph>::vertex_descriptor Vertex; - BOOST_CONCEPT_ASSERT(( DFSVisitorConcept<DFSVisitor, VertexListGraph> )); - typedef typename property_traits<ColorMap>::value_type ColorValue; - typedef color_traits<ColorValue> Color; - - typename graph_traits<VertexListGraph>::vertex_iterator ui, ui_end; - for (boost::tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui) { - Vertex u = implicit_cast<Vertex>(*ui); - put(color, u, Color::white()); vis.initialize_vertex(u, g); +} // namespace detail + +template < class VertexListGraph, class DFSVisitor, class ColorMap > +void depth_first_search(const VertexListGraph& g, DFSVisitor vis, + ColorMap color, + typename graph_traits< VertexListGraph >::vertex_descriptor start_vertex) +{ + typedef typename graph_traits< VertexListGraph >::vertex_descriptor Vertex; + BOOST_CONCEPT_ASSERT((DFSVisitorConcept< DFSVisitor, VertexListGraph >)); + typedef typename property_traits< ColorMap >::value_type ColorValue; + typedef color_traits< ColorValue > Color; + + typename graph_traits< VertexListGraph >::vertex_iterator ui, ui_end; + for (boost::tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui) + { + Vertex u = implicit_cast< Vertex >(*ui); + put(color, u, Color::white()); + vis.initialize_vertex(u, g); } - if (start_vertex != detail::get_default_starting_vertex(g)){ vis.start_vertex(start_vertex, g); - detail::depth_first_visit_impl(g, start_vertex, vis, color, - detail::nontruth2()); + if (start_vertex != detail::get_default_starting_vertex(g)) + { + vis.start_vertex(start_vertex, g); + detail::depth_first_visit_impl( + g, start_vertex, vis, color, detail::nontruth2()); } - for (boost::tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui) { - Vertex u = implicit_cast<Vertex>(*ui); - ColorValue u_color = get(color, u); - if (u_color == Color::white()) { vis.start_vertex(u, g); - detail::depth_first_visit_impl(g, u, vis, color, detail::nontruth2()); - } + for (boost::tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui) + { + Vertex u = implicit_cast< Vertex >(*ui); + ColorValue u_color = get(color, u); + if (u_color == Color::white()) + { + vis.start_vertex(u, g); + detail::depth_first_visit_impl( + g, u, vis, color, detail::nontruth2()); + } } - } - - template <class VertexListGraph, class DFSVisitor, class ColorMap> - void - depth_first_search(const VertexListGraph& g, DFSVisitor vis, ColorMap color) - { - typedef typename boost::graph_traits<VertexListGraph>::vertex_iterator vi; - std::pair<vi, vi> verts = vertices(g); +} + +template < class VertexListGraph, class DFSVisitor, class ColorMap > +void depth_first_search( + const VertexListGraph& g, DFSVisitor vis, ColorMap color) +{ + typedef typename boost::graph_traits< VertexListGraph >::vertex_iterator vi; + std::pair< vi, vi > verts = vertices(g); if (verts.first == verts.second) - return; + return; depth_first_search(g, vis, color, detail::get_default_starting_vertex(g)); - } +} - template <class Visitors = null_visitor> - class dfs_visitor { - public: - dfs_visitor() { } - dfs_visitor(Visitors vis) : m_vis(vis) { } +template < class Visitors = null_visitor > class dfs_visitor +{ +public: + dfs_visitor() {} + dfs_visitor(Visitors vis) : m_vis(vis) {} - template <class Vertex, class Graph> - void initialize_vertex(Vertex u, const Graph& g) { - invoke_visitors(m_vis, u, g, ::boost::on_initialize_vertex()); + template < class Vertex, class Graph > + void initialize_vertex(Vertex u, const Graph& g) + { + invoke_visitors(m_vis, u, g, ::boost::on_initialize_vertex()); } - template <class Vertex, class Graph> - void start_vertex(Vertex u, const Graph& g) { - invoke_visitors(m_vis, u, g, ::boost::on_start_vertex()); + template < class Vertex, class Graph > + void start_vertex(Vertex u, const Graph& g) + { + invoke_visitors(m_vis, u, g, ::boost::on_start_vertex()); } - template <class Vertex, class Graph> - void discover_vertex(Vertex u, const Graph& g) { - invoke_visitors(m_vis, u, g, ::boost::on_discover_vertex()); + template < class Vertex, class Graph > + void discover_vertex(Vertex u, const Graph& g) + { + invoke_visitors(m_vis, u, g, ::boost::on_discover_vertex()); } - template <class Edge, class Graph> - void examine_edge(Edge u, const Graph& g) { - invoke_visitors(m_vis, u, g, ::boost::on_examine_edge()); + template < class Edge, class Graph > + void examine_edge(Edge u, const Graph& g) + { + invoke_visitors(m_vis, u, g, ::boost::on_examine_edge()); } - template <class Edge, class Graph> - void tree_edge(Edge u, const Graph& g) { - invoke_visitors(m_vis, u, g, ::boost::on_tree_edge()); + template < class Edge, class Graph > void tree_edge(Edge u, const Graph& g) + { + invoke_visitors(m_vis, u, g, ::boost::on_tree_edge()); } - template <class Edge, class Graph> - void back_edge(Edge u, const Graph& g) { - invoke_visitors(m_vis, u, g, ::boost::on_back_edge()); + template < class Edge, class Graph > void back_edge(Edge u, const Graph& g) + { + invoke_visitors(m_vis, u, g, ::boost::on_back_edge()); } - template <class Edge, class Graph> - void forward_or_cross_edge(Edge u, const Graph& g) { - invoke_visitors(m_vis, u, g, ::boost::on_forward_or_cross_edge()); + template < class Edge, class Graph > + void forward_or_cross_edge(Edge u, const Graph& g) + { + invoke_visitors(m_vis, u, g, ::boost::on_forward_or_cross_edge()); } - template <class Edge, class Graph> - void finish_edge(Edge u, const Graph& g) { - invoke_visitors(m_vis, u, g, ::boost::on_finish_edge()); + template < class Edge, class Graph > + void finish_edge(Edge u, const Graph& g) + { + invoke_visitors(m_vis, u, g, ::boost::on_finish_edge()); } - template <class Vertex, class Graph> - void finish_vertex(Vertex u, const Graph& g) { - invoke_visitors(m_vis, u, g, ::boost::on_finish_vertex()); + template < class Vertex, class Graph > + void finish_vertex(Vertex u, const Graph& g) + { + invoke_visitors(m_vis, u, g, ::boost::on_finish_vertex()); } - BOOST_GRAPH_EVENT_STUB(on_initialize_vertex,dfs) - BOOST_GRAPH_EVENT_STUB(on_start_vertex,dfs) - BOOST_GRAPH_EVENT_STUB(on_discover_vertex,dfs) - BOOST_GRAPH_EVENT_STUB(on_examine_edge,dfs) - BOOST_GRAPH_EVENT_STUB(on_tree_edge,dfs) - BOOST_GRAPH_EVENT_STUB(on_back_edge,dfs) - BOOST_GRAPH_EVENT_STUB(on_forward_or_cross_edge,dfs) - BOOST_GRAPH_EVENT_STUB(on_finish_edge,dfs) - BOOST_GRAPH_EVENT_STUB(on_finish_vertex,dfs) - - protected: + BOOST_GRAPH_EVENT_STUB(on_initialize_vertex, dfs) + BOOST_GRAPH_EVENT_STUB(on_start_vertex, dfs) + BOOST_GRAPH_EVENT_STUB(on_discover_vertex, dfs) + BOOST_GRAPH_EVENT_STUB(on_examine_edge, dfs) + BOOST_GRAPH_EVENT_STUB(on_tree_edge, dfs) + BOOST_GRAPH_EVENT_STUB(on_back_edge, dfs) + BOOST_GRAPH_EVENT_STUB(on_forward_or_cross_edge, dfs) + BOOST_GRAPH_EVENT_STUB(on_finish_edge, dfs) + BOOST_GRAPH_EVENT_STUB(on_finish_vertex, dfs) + +protected: Visitors m_vis; - }; - template <class Visitors> - dfs_visitor<Visitors> - make_dfs_visitor(Visitors vis) { - return dfs_visitor<Visitors>(vis); - } - typedef dfs_visitor<> default_dfs_visitor; - - // Boost.Parameter named parameter variant - namespace graph { - namespace detail { - template <typename Graph> - struct depth_first_search_impl { - typedef void result_type; - template <typename ArgPack> - void operator()(const Graph& g, const ArgPack& arg_pack) const { - using namespace boost::graph::keywords; - boost::depth_first_search(g, - arg_pack[_visitor | make_dfs_visitor(null_visitor())], - boost::detail::make_color_map_from_arg_pack(g, arg_pack), - arg_pack[_root_vertex || boost::detail::get_default_starting_vertex_t<Graph>(g)]); - } - }; +}; +template < class Visitors > +dfs_visitor< Visitors > make_dfs_visitor(Visitors vis) +{ + return dfs_visitor< Visitors >(vis); +} +typedef dfs_visitor<> default_dfs_visitor; + +// Boost.Parameter named parameter variant +namespace graph +{ + namespace detail + { + template < typename Graph > struct depth_first_search_impl + { + typedef void result_type; + template < typename ArgPack > + void operator()(const Graph& g, const ArgPack& arg_pack) const + { + using namespace boost::graph::keywords; + boost::depth_first_search(g, + arg_pack[_visitor | make_dfs_visitor(null_visitor())], + boost::detail::make_color_map_from_arg_pack(g, arg_pack), + arg_pack[_root_vertex + || boost::detail::get_default_starting_vertex_t< + Graph >(g)]); + } + }; } BOOST_GRAPH_MAKE_FORWARDING_FUNCTION(depth_first_search, 1, 4) - } +} - BOOST_GRAPH_MAKE_OLD_STYLE_PARAMETER_FUNCTION(depth_first_search, 1) +BOOST_GRAPH_MAKE_OLD_STYLE_PARAMETER_FUNCTION(depth_first_search, 1) - template <class IncidenceGraph, class DFSVisitor, class ColorMap> - void depth_first_visit - (const IncidenceGraph& g, - typename graph_traits<IncidenceGraph>::vertex_descriptor u, - DFSVisitor vis, ColorMap color) - { +template < class IncidenceGraph, class DFSVisitor, class ColorMap > +void depth_first_visit(const IncidenceGraph& g, + typename graph_traits< IncidenceGraph >::vertex_descriptor u, + DFSVisitor vis, ColorMap color) +{ vis.start_vertex(u, g); detail::depth_first_visit_impl(g, u, vis, color, detail::nontruth2()); - } - - template <class IncidenceGraph, class DFSVisitor, class ColorMap, - class TerminatorFunc> - void depth_first_visit - (const IncidenceGraph& g, - typename graph_traits<IncidenceGraph>::vertex_descriptor u, - DFSVisitor vis, ColorMap color, TerminatorFunc func = TerminatorFunc()) - { +} + +template < class IncidenceGraph, class DFSVisitor, class ColorMap, + class TerminatorFunc > +void depth_first_visit(const IncidenceGraph& g, + typename graph_traits< IncidenceGraph >::vertex_descriptor u, + DFSVisitor vis, ColorMap color, TerminatorFunc func = TerminatorFunc()) +{ vis.start_vertex(u, g); detail::depth_first_visit_impl(g, u, vis, color, func); - } +} } // namespace boost -#ifdef BOOST_GRAPH_USE_MPI -# error #include <boost/graph/distributed/depth_first_search.hpp> -#endif +#include BOOST_GRAPH_MPI_INCLUDE(<boost/graph/distributed/depth_first_search.hpp>) #endif diff --git a/contrib/restricted/boost/graph/include/boost/graph/detail/adj_list_edge_iterator.hpp b/contrib/restricted/boost/graph/include/boost/graph/detail/adj_list_edge_iterator.hpp index 4f43e1c12b..3a13f86180 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/detail/adj_list_edge_iterator.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/detail/adj_list_edge_iterator.hpp @@ -15,102 +15,120 @@ #include <utility> #include <boost/detail/workaround.hpp> -#if BOOST_WORKAROUND( __IBMCPP__, <= 600 ) -# define BOOST_GRAPH_NO_OPTIONAL +#if BOOST_WORKAROUND(__IBMCPP__, <= 600) +#define BOOST_GRAPH_NO_OPTIONAL #endif #ifdef BOOST_GRAPH_NO_OPTIONAL -# define BOOST_GRAPH_MEMBER . -#else -# define BOOST_GRAPH_MEMBER -> -# include <boost/optional.hpp> +#define BOOST_GRAPH_MEMBER . +#else +#define BOOST_GRAPH_MEMBER -> +#include <boost/optional.hpp> #endif // ndef BOOST_GRAPH_NO_OPTIONAL -namespace boost { +namespace boost +{ + +namespace detail +{ - namespace detail { + template < class VertexIterator, class OutEdgeIterator, class Graph > + class adj_list_edge_iterator + { + typedef adj_list_edge_iterator self; - template <class VertexIterator, class OutEdgeIterator, class Graph> - class adj_list_edge_iterator { - typedef adj_list_edge_iterator self; public: - typedef std::forward_iterator_tag iterator_category; - typedef typename OutEdgeIterator::value_type value_type; - typedef typename OutEdgeIterator::reference reference; - typedef typename OutEdgeIterator::pointer pointer; - typedef typename OutEdgeIterator::difference_type difference_type; - typedef difference_type distance_type; - - inline adj_list_edge_iterator() {} - - inline adj_list_edge_iterator& operator=(const self& x) = default; - - inline adj_list_edge_iterator(const self& x) - : vBegin(x.vBegin), vCurr(x.vCurr), vEnd(x.vEnd), - edges(x.edges), m_g(x.m_g) { } - - template <class G> - inline adj_list_edge_iterator(VertexIterator b, - VertexIterator c, - VertexIterator e, - const G& g) - : vBegin(b), vCurr(c), vEnd(e), m_g(&g) { - if ( vCurr != vEnd ) { - while ( vCurr != vEnd && out_degree(*vCurr, *m_g) == 0 ) - ++vCurr; - if ( vCurr != vEnd ) - edges = out_edges(*vCurr, *m_g); + typedef std::forward_iterator_tag iterator_category; + typedef typename OutEdgeIterator::value_type value_type; + typedef typename OutEdgeIterator::reference reference; + typedef typename OutEdgeIterator::pointer pointer; + typedef typename OutEdgeIterator::difference_type difference_type; + typedef difference_type distance_type; + + inline adj_list_edge_iterator() {} + + inline adj_list_edge_iterator& operator=(const self& x) = default; + + inline adj_list_edge_iterator(const self& x) + : vBegin(x.vBegin) + , vCurr(x.vCurr) + , vEnd(x.vEnd) + , edges(x.edges) + , m_g(x.m_g) + { + } + + template < class G > + inline adj_list_edge_iterator( + VertexIterator b, VertexIterator c, VertexIterator e, const G& g) + : vBegin(b), vCurr(c), vEnd(e), m_g(&g) + { + if (vCurr != vEnd) + { + while (vCurr != vEnd && out_degree(*vCurr, *m_g) == 0) + ++vCurr; + if (vCurr != vEnd) + edges = out_edges(*vCurr, *m_g); + } + } + + /*Note: + In the directed graph cases, it is fine. + For undirected graphs, one edge go through twice. + */ + inline self& operator++() + { + ++edges BOOST_GRAPH_MEMBER first; + if (edges BOOST_GRAPH_MEMBER first + == edges BOOST_GRAPH_MEMBER second) + { + ++vCurr; + while (vCurr != vEnd && out_degree(*vCurr, *m_g) == 0) + ++vCurr; + if (vCurr != vEnd) + edges = out_edges(*vCurr, *m_g); + } + return *this; + } + inline self operator++(int) + { + self tmp = *this; + ++(*this); + return tmp; + } + inline value_type operator*() const + { + return *edges BOOST_GRAPH_MEMBER first; + } + inline bool operator==(const self& x) const + { + return vCurr == x.vCurr + && (vCurr == vEnd + || edges BOOST_GRAPH_MEMBER first + == x.edges BOOST_GRAPH_MEMBER first); } - } - - /*Note: - In the directed graph cases, it is fine. - For undirected graphs, one edge go through twice. - */ - inline self& operator++() { - ++edges BOOST_GRAPH_MEMBER first; - if (edges BOOST_GRAPH_MEMBER first == edges BOOST_GRAPH_MEMBER second) + inline bool operator!=(const self& x) const { - ++vCurr; - while ( vCurr != vEnd && out_degree(*vCurr, *m_g) == 0 ) - ++vCurr; - if ( vCurr != vEnd ) - edges = out_edges(*vCurr, *m_g); + return vCurr != x.vCurr + || (vCurr != vEnd + && edges BOOST_GRAPH_MEMBER first + != x.edges BOOST_GRAPH_MEMBER first); } - return *this; - } - inline self operator++(int) { - self tmp = *this; - ++(*this); - return tmp; - } - inline value_type operator*() const - { return *edges BOOST_GRAPH_MEMBER first; } - inline bool operator==(const self& x) const { - return vCurr == x.vCurr - && (vCurr == vEnd - || edges BOOST_GRAPH_MEMBER first == x.edges BOOST_GRAPH_MEMBER first); - } - inline bool operator!=(const self& x) const { - return vCurr != x.vCurr - || (vCurr != vEnd - && edges BOOST_GRAPH_MEMBER first != x.edges BOOST_GRAPH_MEMBER first); - } + protected: - VertexIterator vBegin; - VertexIterator vCurr; - VertexIterator vEnd; + VertexIterator vBegin; + VertexIterator vCurr; + VertexIterator vEnd; #ifdef BOOST_GRAPH_NO_OPTIONAL - std::pair<OutEdgeIterator, OutEdgeIterator> edges; + std::pair< OutEdgeIterator, OutEdgeIterator > edges; #else - boost::optional<std::pair<OutEdgeIterator, OutEdgeIterator> > - edges; + boost::optional< std::pair< OutEdgeIterator, OutEdgeIterator > > edges; #endif // ndef BOOST_GRAPH_NO_OPTIONAL - const Graph* m_g; + const Graph* m_g; }; - } // namespace detail +} // namespace detail } diff --git a/contrib/restricted/boost/graph/include/boost/graph/detail/adjacency_list.hpp b/contrib/restricted/boost/graph/include/boost/graph/detail/adjacency_list.hpp index d8ea24d123..7fb2c49361 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/detail/adjacency_list.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/detail/adjacency_list.hpp @@ -21,6 +21,7 @@ #include <boost/range/irange.hpp> #include <boost/graph/graph_traits.hpp> #include <memory> +#include <iterator> #include <algorithm> #include <boost/limits.hpp> @@ -38,8 +39,6 @@ #include <boost/static_assert.hpp> #include <boost/assert.hpp> -#include <util/system/compiler.h> - #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES #define BOOST_GRAPH_MOVE_IF_POSSIBLE(x) (x) #else @@ -71,1198 +70,1209 @@ bidirectional code... it is awful similar. */ +namespace boost +{ -namespace boost { - - namespace detail { +namespace detail +{ - template <typename DirectedS> - struct directed_category_traits { - typedef directed_tag directed_category; + template < typename DirectedS > struct directed_category_traits + { + typedef directed_tag directed_category; }; - template <> - struct directed_category_traits<directedS> { - typedef directed_tag directed_category; + template <> struct directed_category_traits< directedS > + { + typedef directed_tag directed_category; }; - template <> - struct directed_category_traits<undirectedS> { - typedef undirected_tag directed_category; + template <> struct directed_category_traits< undirectedS > + { + typedef undirected_tag directed_category; }; - template <> - struct directed_category_traits<bidirectionalS> { - typedef bidirectional_tag directed_category; + template <> struct directed_category_traits< bidirectionalS > + { + typedef bidirectional_tag directed_category; }; - template <class Vertex> - struct target_is { - target_is(const Vertex& v) : m_target(v) { } - template <class StoredEdge> - bool operator()(const StoredEdge& e) const { - return e.get_target() == m_target; - } - Vertex m_target; + template < class Vertex > struct target_is + { + target_is(const Vertex& v) : m_target(v) {} + template < class StoredEdge > bool operator()(const StoredEdge& e) const + { + return e.get_target() == m_target; + } + Vertex m_target; }; // O(E/V) - template <class EdgeList, class vertex_descriptor> - void erase_from_incidence_list(EdgeList& el, vertex_descriptor v, - allow_parallel_edge_tag) + template < class EdgeList, class vertex_descriptor > + void erase_from_incidence_list( + EdgeList& el, vertex_descriptor v, allow_parallel_edge_tag) { - boost::graph_detail::erase_if(el, detail::target_is<vertex_descriptor>(v)); + boost::graph_detail::erase_if( + el, detail::target_is< vertex_descriptor >(v)); } // O(log(E/V)) - template <class EdgeList, class vertex_descriptor> - void erase_from_incidence_list(EdgeList& el, vertex_descriptor v, - disallow_parallel_edge_tag) + template < class EdgeList, class vertex_descriptor > + void erase_from_incidence_list( + EdgeList& el, vertex_descriptor v, disallow_parallel_edge_tag) { - typedef typename EdgeList::value_type StoredEdge; - el.erase(StoredEdge(v)); + typedef typename EdgeList::value_type StoredEdge; + el.erase(StoredEdge(v)); } //========================================================================= // Out-Edge and In-Edge Iterator Implementation - template <class BaseIter, class VertexDescriptor, class EdgeDescriptor, class Difference> + template < class BaseIter, class VertexDescriptor, class EdgeDescriptor, + class Difference > struct out_edge_iter - : iterator_adaptor< - out_edge_iter<BaseIter, VertexDescriptor, EdgeDescriptor, Difference> - , BaseIter - , EdgeDescriptor - , use_default - , EdgeDescriptor - , Difference - > - { - typedef iterator_adaptor< - out_edge_iter<BaseIter, VertexDescriptor, EdgeDescriptor, Difference> - , BaseIter - , EdgeDescriptor - , use_default - , EdgeDescriptor - , Difference - > super_t; - - inline out_edge_iter() { } + : iterator_adaptor< out_edge_iter< BaseIter, VertexDescriptor, + EdgeDescriptor, Difference >, + BaseIter, EdgeDescriptor, use_default, EdgeDescriptor, Difference > + { + typedef iterator_adaptor< out_edge_iter< BaseIter, VertexDescriptor, + EdgeDescriptor, Difference >, + BaseIter, EdgeDescriptor, use_default, EdgeDescriptor, Difference > + super_t; + + inline out_edge_iter() {} inline out_edge_iter(const BaseIter& i, const VertexDescriptor& src) - : super_t(i), m_src(src) { } - - inline EdgeDescriptor - dereference() const - { - return EdgeDescriptor(m_src, (*this->base()).get_target(), - &(*this->base()).get_property()); - } - VertexDescriptor m_src; + : super_t(i), m_src(src) + { + } + + inline EdgeDescriptor dereference() const + { + return EdgeDescriptor(m_src, (*this->base()).get_target(), + &(*this->base()).get_property()); + } + VertexDescriptor m_src; }; - template <class BaseIter, class VertexDescriptor, class EdgeDescriptor, class Difference> + template < class BaseIter, class VertexDescriptor, class EdgeDescriptor, + class Difference > struct in_edge_iter - : iterator_adaptor< - in_edge_iter<BaseIter, VertexDescriptor, EdgeDescriptor, Difference> - , BaseIter - , EdgeDescriptor - , use_default - , EdgeDescriptor - , Difference - > - { - typedef iterator_adaptor< - in_edge_iter<BaseIter, VertexDescriptor, EdgeDescriptor, Difference> - , BaseIter - , EdgeDescriptor - , use_default - , EdgeDescriptor - , Difference - > super_t; - - inline in_edge_iter() { } - inline in_edge_iter(const BaseIter& i, const VertexDescriptor& src) - : super_t(i), m_src(src) { } - - inline EdgeDescriptor - dereference() const - { - return EdgeDescriptor((*this->base()).get_target(), m_src, - &this->base()->get_property()); - } - VertexDescriptor m_src; + : iterator_adaptor< in_edge_iter< BaseIter, VertexDescriptor, + EdgeDescriptor, Difference >, + BaseIter, EdgeDescriptor, use_default, EdgeDescriptor, Difference > + { + typedef iterator_adaptor< in_edge_iter< BaseIter, VertexDescriptor, + EdgeDescriptor, Difference >, + BaseIter, EdgeDescriptor, use_default, EdgeDescriptor, Difference > + super_t; + + inline in_edge_iter() {} + inline in_edge_iter(const BaseIter& i, const VertexDescriptor& src) + : super_t(i), m_src(src) + { + } + + inline EdgeDescriptor dereference() const + { + return EdgeDescriptor((*this->base()).get_target(), m_src, + &this->base()->get_property()); + } + VertexDescriptor m_src; }; //========================================================================= // Undirected Edge Iterator Implementation - template <class EdgeIter, class EdgeDescriptor, class Difference> + template < class EdgeIter, class EdgeDescriptor, class Difference > struct undirected_edge_iter - : iterator_adaptor< - undirected_edge_iter<EdgeIter, EdgeDescriptor, Difference> - , EdgeIter - , EdgeDescriptor - , use_default - , EdgeDescriptor - , Difference - > - { - typedef iterator_adaptor< - undirected_edge_iter<EdgeIter, EdgeDescriptor, Difference> - , EdgeIter - , EdgeDescriptor - , use_default - , EdgeDescriptor - , Difference - > super_t; - - undirected_edge_iter() {} - - explicit undirected_edge_iter(EdgeIter i) - : super_t(i) {} - - inline EdgeDescriptor - dereference() const { - return EdgeDescriptor( - (*this->base()).m_source - , (*this->base()).m_target - , &this->base()->get_property()); - } + : iterator_adaptor< + undirected_edge_iter< EdgeIter, EdgeDescriptor, Difference >, + EdgeIter, EdgeDescriptor, use_default, EdgeDescriptor, Difference > + { + typedef iterator_adaptor< + undirected_edge_iter< EdgeIter, EdgeDescriptor, Difference >, + EdgeIter, EdgeDescriptor, use_default, EdgeDescriptor, Difference > + super_t; + + undirected_edge_iter() {} + + explicit undirected_edge_iter(EdgeIter i) : super_t(i) {} + + inline EdgeDescriptor dereference() const + { + return EdgeDescriptor((*this->base()).m_source, + (*this->base()).m_target, &this->base()->get_property()); + } }; //========================================================================= // Edge Storage Types (stored in the out-edge/in-edge lists) - template <class Vertex> + template < class Vertex > class stored_edge - : public boost::equality_comparable1< stored_edge<Vertex>, - boost::less_than_comparable1< stored_edge<Vertex> > > + : public boost::equality_comparable1< stored_edge< Vertex >, + boost::less_than_comparable1< stored_edge< Vertex > > > { public: - typedef no_property property_type; - inline stored_edge() { } - inline stored_edge(Vertex target, const no_property& = no_property()) - : m_target(target) { } - inline Vertex& get_target() const { return m_target; } - inline const no_property& get_property() const { return s_prop; } - inline bool operator==(const stored_edge& x) const - { return m_target == x.get_target(); } - inline bool operator<(const stored_edge& x) const - { return m_target < x.get_target(); } - //protected: need to add hash<> as a friend - static no_property s_prop; - // Sometimes target not used as key in the set, and in that case - // it is ok to change the target. - mutable Vertex m_target; + typedef no_property property_type; + inline stored_edge() {} + inline stored_edge(Vertex target, const no_property& = no_property()) + : m_target(target) + { + } + inline Vertex& get_target() const { return m_target; } + inline const no_property& get_property() const { return s_prop; } + inline bool operator==(const stored_edge& x) const + { + return m_target == x.get_target(); + } + inline bool operator<(const stored_edge& x) const + { + return m_target < x.get_target(); + } + // protected: need to add hash<> as a friend + static no_property s_prop; + // Sometimes target not used as key in the set, and in that case + // it is ok to change the target. + mutable Vertex m_target; }; - template <class Vertex> - no_property stored_edge<Vertex>::s_prop; - -#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) || defined(BOOST_NO_CXX11_SMART_PTR) - template <class Vertex, class Property> - class stored_edge_property : public stored_edge<Vertex> { - typedef stored_edge_property self; - typedef stored_edge<Vertex> Base; + template < class Vertex > no_property stored_edge< Vertex >::s_prop; + +#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) \ + || defined(BOOST_NO_CXX11_SMART_PTR) + template < class Vertex, class Property > + class stored_edge_property : public stored_edge< Vertex > + { + typedef stored_edge_property self; + typedef stored_edge< Vertex > Base; + public: - typedef Property property_type; - inline stored_edge_property() { } - inline stored_edge_property(Vertex target, - const Property& p = Property()) - : stored_edge<Vertex>(target), m_property(new Property(p)) { } - stored_edge_property(const self& x) - : Base(static_cast< Base const& >(x)), m_property(const_cast<self&>(x).m_property) { } - self& operator=(const self& x) { - // NOTE: avoid 'Base::operator=(x);' broken on SGI MIPSpro (bug 55771 of Mozilla). - static_cast<Base&>(*this) = static_cast< Base const& >(x); - m_property = const_cast<self&>(x).m_property; - return *this; - } + typedef Property property_type; + inline stored_edge_property() {} + inline stored_edge_property( + Vertex target, const Property& p = Property()) + : stored_edge< Vertex >(target), m_property(new Property(p)) + { + } + stored_edge_property(const self& x) + : Base(static_cast< Base const& >(x)) + , m_property(const_cast< self& >(x).m_property) + { + } + self& operator=(const self& x) + { + // NOTE: avoid 'Base::operator=(x);' broken on SGI MIPSpro (bug + // 55771 of Mozilla). + static_cast< Base& >(*this) = static_cast< Base const& >(x); + m_property = const_cast< self& >(x).m_property; + return *this; + } #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) - // NOTE Don't rely on default operators, their behavior is broken on several compilers (GCC 4.6). - stored_edge_property(self&& x) - : Base(static_cast< Base&& >(x)), m_property(std::move(x.m_property)) { } - self& operator=(self&& x) { - // NOTE: avoid 'Base::operator=(x);' broken on SGI MIPSpro (bug 55771 of Mozilla). - static_cast<Base&>(*this) = static_cast< Base&& >(x); - m_property = std::move(x.m_property); - return *this; - } + // NOTE Don't rely on default operators, their behavior is broken on + // several compilers (GCC 4.6). + stored_edge_property(self&& x) + : Base(static_cast< Base&& >(x)), m_property(std::move(x.m_property)) + { + } + self& operator=(self&& x) + { + // NOTE: avoid 'Base::operator=(x);' broken on SGI MIPSpro (bug + // 55771 of Mozilla). + static_cast< Base& >(*this) = static_cast< Base&& >(x); + m_property = std::move(x.m_property); + return *this; + } #endif - inline Property& get_property() { return *m_property; } - inline const Property& get_property() const { return *m_property; } + inline Property& get_property() { return *m_property; } + inline const Property& get_property() const { return *m_property; } + protected: - // Holding the property by-value causes edge-descriptor - // invalidation for add_edge() with EdgeList=vecS. Instead we - // hold a pointer to the property. std::auto_ptr is not - // a perfect fit for the job, but it is darn close. - std::auto_ptr<Property> m_property; + // Holding the property by-value causes edge-descriptor + // invalidation for add_edge() with EdgeList=vecS. Instead we + // hold a pointer to the property. std::auto_ptr is not + // a perfect fit for the job, but it is darn close. +#ifdef BOOST_NO_AUTO_PTR + std::unique_ptr< Property > m_property; +#else + std::auto_ptr< Property > m_property; +#endif }; #else - template <class Vertex, class Property> - class stored_edge_property : public stored_edge<Vertex> { - typedef stored_edge_property self; - typedef stored_edge<Vertex> Base; + template < class Vertex, class Property > + class stored_edge_property : public stored_edge< Vertex > + { + typedef stored_edge_property self; + typedef stored_edge< Vertex > Base; + public: - typedef Property property_type; - inline stored_edge_property() { } - inline stored_edge_property(Vertex target, - const Property& p = Property()) - : stored_edge<Vertex>(target), m_property(new Property(p)) { } - stored_edge_property(self&& x) : Base(static_cast< Base&& >(x)), - m_property(std::move(x.m_property)) { } - stored_edge_property(self const& x) : Base(static_cast< Base const& >(x)), - m_property(std::move(const_cast<self&>(x).m_property)) { } - self& operator=(self&& x) { - // NOTE: avoid 'Base::operator=(x);' broken on SGI MIPSpro (bug 55771 of Mozilla). - static_cast<Base&>(*this) = static_cast< Base&& >(x); - m_property = std::move(x.m_property); - return *this; - } - self& operator=(self const& x) { - // NOTE: avoid 'Base::operator=(x);' broken on SGI MIPSpro (bug 55771 of Mozilla). - static_cast<Base&>(*this) = static_cast< Base const& >(x); - m_property = std::move(const_cast<self&>(x).m_property); - return *this; - } - inline Property& get_property() { return *m_property; } - inline const Property& get_property() const { return *m_property; } + typedef Property property_type; + inline stored_edge_property() {} + inline stored_edge_property( + Vertex target, const Property& p = Property()) + : stored_edge< Vertex >(target), m_property(new Property(p)) + { + } + stored_edge_property(self&& x) + : Base(static_cast< Base&& >(x)), m_property(std::move(x.m_property)) + { + } + stored_edge_property(self const& x) + : Base(static_cast< Base const& >(x)) + , m_property(std::move(const_cast< self& >(x).m_property)) + { + } + self& operator=(self&& x) + { + // NOTE: avoid 'Base::operator=(x);' broken on SGI MIPSpro (bug + // 55771 of Mozilla). + static_cast< Base& >(*this) = static_cast< Base&& >(x); + m_property = std::move(x.m_property); + return *this; + } + self& operator=(self const& x) + { + // NOTE: avoid 'Base::operator=(x);' broken on SGI MIPSpro (bug + // 55771 of Mozilla). + static_cast< Base& >(*this) = static_cast< Base const& >(x); + m_property = std::move(const_cast< self& >(x).m_property); + return *this; + } + inline Property& get_property() { return *m_property; } + inline const Property& get_property() const { return *m_property; } + protected: - std::unique_ptr<Property> m_property; + std::unique_ptr< Property > m_property; }; #endif - - template <class Vertex, class Iter, class Property> - class stored_edge_iter - : public stored_edge<Vertex> + template < class Vertex, class Iter, class Property > + class stored_edge_iter : public stored_edge< Vertex > { public: - typedef Property property_type; - inline stored_edge_iter() { } - inline stored_edge_iter(Vertex v) - : stored_edge<Vertex>(v) { } - inline stored_edge_iter(Vertex v, Iter i, void* = 0) - : stored_edge<Vertex>(v), m_iter(i) { } - inline Property& get_property() { return m_iter->get_property(); } - inline const Property& get_property() const { - return m_iter->get_property(); - } - inline Iter get_iter() const { return m_iter; } + typedef Property property_type; + inline stored_edge_iter() {} + inline stored_edge_iter(Vertex v) : stored_edge< Vertex >(v) {} + inline stored_edge_iter(Vertex v, Iter i, void* = 0) + : stored_edge< Vertex >(v), m_iter(i) + { + } + inline Property& get_property() { return m_iter->get_property(); } + inline const Property& get_property() const + { + return m_iter->get_property(); + } + inline Iter get_iter() const { return m_iter; } + protected: - Iter m_iter; + Iter m_iter; }; // For when the EdgeList is a std::vector. // Want to make the iterator stable, so use an offset // instead of an iterator into a std::vector - template <class Vertex, class EdgeVec, class Property> - class stored_ra_edge_iter - : public stored_edge<Vertex> + template < class Vertex, class EdgeVec, class Property > + class stored_ra_edge_iter : public stored_edge< Vertex > { - typedef typename EdgeVec::iterator Iter; + typedef typename EdgeVec::iterator Iter; + public: - typedef Property property_type; - inline stored_ra_edge_iter() { } - inline explicit stored_ra_edge_iter(Vertex v) // Only used for comparisons - : stored_edge<Vertex>(v), m_i(0), m_vec(0){ } - inline stored_ra_edge_iter(Vertex v, Iter i, EdgeVec* edge_vec) - : stored_edge<Vertex>(v), m_i(i - edge_vec->begin()), m_vec(edge_vec){ } - inline Property& get_property() { BOOST_ASSERT ((m_vec != 0)); return (*m_vec)[m_i].get_property(); } - inline const Property& get_property() const { - BOOST_ASSERT ((m_vec != 0)); - return (*m_vec)[m_i].get_property(); - } - inline Iter get_iter() const { BOOST_ASSERT ((m_vec != 0)); return m_vec->begin() + m_i; } + typedef Property property_type; + inline stored_ra_edge_iter() {} + inline explicit stored_ra_edge_iter( + Vertex v) // Only used for comparisons + : stored_edge< Vertex >(v), m_i(0), m_vec(0) + { + } + inline stored_ra_edge_iter(Vertex v, Iter i, EdgeVec* edge_vec) + : stored_edge< Vertex >(v), m_i(i - edge_vec->begin()), m_vec(edge_vec) + { + } + inline Property& get_property() + { + BOOST_ASSERT((m_vec != 0)); + return (*m_vec)[m_i].get_property(); + } + inline const Property& get_property() const + { + BOOST_ASSERT((m_vec != 0)); + return (*m_vec)[m_i].get_property(); + } + inline Iter get_iter() const + { + BOOST_ASSERT((m_vec != 0)); + return m_vec->begin() + m_i; + } + protected: - std::size_t m_i; - EdgeVec* m_vec; + std::size_t m_i; + EdgeVec* m_vec; }; - } // namespace detail +} // namespace detail - template <class Tag, class Vertex, class Property> - const typename property_value<Property,Tag>::type& - get(Tag property_tag, - const detail::stored_edge_property<Vertex, Property>& e) - { +template < class Tag, class Vertex, class Property > +const typename property_value< Property, Tag >::type& get( + Tag property_tag, const detail::stored_edge_property< Vertex, Property >& e) +{ return get_property_value(e.get_property(), property_tag); - } +} - template <class Tag, class Vertex, class Iter, class Property> - const typename property_value<Property,Tag>::type& - get(Tag property_tag, - const detail::stored_edge_iter<Vertex, Iter, Property>& e) - { +template < class Tag, class Vertex, class Iter, class Property > +const typename property_value< Property, Tag >::type& get(Tag property_tag, + const detail::stored_edge_iter< Vertex, Iter, Property >& e) +{ return get_property_value(e.get_property(), property_tag); - } +} - template <class Tag, class Vertex, class EdgeVec, class Property> - const typename property_value<Property,Tag>::type& - get(Tag property_tag, - const detail::stored_ra_edge_iter<Vertex, EdgeVec, Property>& e) - { +template < class Tag, class Vertex, class EdgeVec, class Property > +const typename property_value< Property, Tag >::type& get(Tag property_tag, + const detail::stored_ra_edge_iter< Vertex, EdgeVec, Property >& e) +{ return get_property_value(e.get_property(), property_tag); - } +} - //========================================================================= - // Directed Edges Helper Class - - namespace detail { - - // O(E/V) - template <class edge_descriptor, class EdgeList, class StoredProperty> - inline void - remove_directed_edge_dispatch(edge_descriptor, EdgeList& el, - StoredProperty& p) - { - for (typename EdgeList::iterator i = el.begin(); - i != el.end(); ++i) - if (&(*i).get_property() == &p) { - el.erase(i); - return; - } - } - - template <class incidence_iterator, class EdgeList, class Predicate> - inline void - remove_directed_edge_if_dispatch(incidence_iterator first, - incidence_iterator last, - EdgeList& el, Predicate pred, - boost::allow_parallel_edge_tag) - { +//========================================================================= +// Directed Edges Helper Class + +namespace detail +{ + + // O(E/V) + template < class edge_descriptor, class EdgeList, class StoredProperty > + inline void remove_directed_edge_dispatch( + edge_descriptor, EdgeList& el, StoredProperty& p) + { + for (typename EdgeList::iterator i = el.begin(); i != el.end(); ++i) + if (&(*i).get_property() == &p) + { + el.erase(i); + return; + } + } + + template < class incidence_iterator, class EdgeList, class Predicate > + inline void remove_directed_edge_if_dispatch(incidence_iterator first, + incidence_iterator last, EdgeList& el, Predicate pred, + boost::allow_parallel_edge_tag) + { // remove_if while (first != last && !pred(*first)) - ++first; + ++first; incidence_iterator i = first; if (first != last) - for (++i; i != last; ++i) - if (!pred(*i)) { - *first.base() = BOOST_GRAPH_MOVE_IF_POSSIBLE(*i.base()); - ++first; - } + for (++i; i != last; ++i) + if (!pred(*i)) + { + *first.base() = BOOST_GRAPH_MOVE_IF_POSSIBLE(*i.base()); + ++first; + } el.erase(first.base(), el.end()); - } - template <class incidence_iterator, class EdgeList, class Predicate> - inline void - remove_directed_edge_if_dispatch(incidence_iterator first, - incidence_iterator last, - EdgeList& el, - Predicate pred, - boost::disallow_parallel_edge_tag) - { - for (incidence_iterator next = first; - first != last; first = next) { - ++next; - if (pred(*first)) - el.erase( first.base() ); + } + template < class incidence_iterator, class EdgeList, class Predicate > + inline void remove_directed_edge_if_dispatch(incidence_iterator first, + incidence_iterator last, EdgeList& el, Predicate pred, + boost::disallow_parallel_edge_tag) + { + for (incidence_iterator next = first; first != last; first = next) + { + ++next; + if (pred(*first)) + el.erase(first.base()); } - } - - template <class PropT, class Graph, class incidence_iterator, - class EdgeList, class Predicate> - inline void - undirected_remove_out_edge_if_dispatch(Graph& g, - incidence_iterator first, - incidence_iterator last, - EdgeList& el, Predicate pred, - boost::allow_parallel_edge_tag) - { + } + + template < class PropT, class Graph, class incidence_iterator, + class EdgeList, class Predicate > + inline void undirected_remove_out_edge_if_dispatch(Graph& g, + incidence_iterator first, incidence_iterator last, EdgeList& el, + Predicate pred, boost::allow_parallel_edge_tag) + { typedef typename Graph::global_edgelist_selector EdgeListS; - BOOST_STATIC_ASSERT((!is_same<EdgeListS, vecS>::value)); + BOOST_STATIC_ASSERT((!is_same< EdgeListS, vecS >::value)); // remove_if while (first != last && !pred(*first)) - ++first; + ++first; incidence_iterator i = first; bool self_loop_removed = false; if (first != last) - for (; i != last; ++i) { - if (self_loop_removed) { - /* With self loops, the descriptor will show up - * twice. The first time it will be removed, and now it - * will be skipped. - */ - self_loop_removed = false; + for (; i != last; ++i) + { + if (self_loop_removed) + { + /* With self loops, the descriptor will show up + * twice. The first time it will be removed, and now it + * will be skipped. + */ + self_loop_removed = false; + } + else if (!pred(*i)) + { + *first.base() = BOOST_GRAPH_MOVE_IF_POSSIBLE(*i.base()); + ++first; + } + else + { + if (source(*i, g) == target(*i, g)) + self_loop_removed = true; + else + { + // Remove the edge from the target + detail::remove_directed_edge_dispatch(*i, + g.out_edge_list(target(*i, g)), + *(PropT*)(*i).get_property()); + } + + // Erase the edge property + g.m_edges.erase((*i.base()).get_iter()); + } } - else if (!pred(*i)) { - *first.base() = BOOST_GRAPH_MOVE_IF_POSSIBLE(*i.base()); - ++first; - } else { - if (source(*i, g) == target(*i, g)) self_loop_removed = true; - else { - // Remove the edge from the target - detail::remove_directed_edge_dispatch - (*i, - g.out_edge_list(target(*i, g)), - *(PropT*)(*i).get_property()); - } - - // Erase the edge property - g.m_edges.erase( (*i.base()).get_iter() ); - } - } el.erase(first.base(), el.end()); - } - template <class PropT, class Graph, class incidence_iterator, - class EdgeList, class Predicate> - inline void - undirected_remove_out_edge_if_dispatch(Graph& g, - incidence_iterator first, - incidence_iterator last, - EdgeList& el, - Predicate pred, - boost::disallow_parallel_edge_tag) - { + } + template < class PropT, class Graph, class incidence_iterator, + class EdgeList, class Predicate > + inline void undirected_remove_out_edge_if_dispatch(Graph& g, + incidence_iterator first, incidence_iterator last, EdgeList& el, + Predicate pred, boost::disallow_parallel_edge_tag) + { typedef typename Graph::global_edgelist_selector EdgeListS; - BOOST_STATIC_ASSERT((!is_same<EdgeListS, vecS>::value)); - - for (incidence_iterator next = first; - first != last; first = next) { - ++next; - if (pred(*first)) { - if (source(*first, g) != target(*first, g)) { - // Remove the edge from the target - detail::remove_directed_edge_dispatch - (*first, - g.out_edge_list(target(*first, g)), - *(PropT*)(*first).get_property()); - } - - // Erase the edge property - g.m_edges.erase( (*first.base()).get_iter() ); + BOOST_STATIC_ASSERT((!is_same< EdgeListS, vecS >::value)); - // Erase the edge in the source - el.erase( first.base() ); - } + for (incidence_iterator next = first; first != last; first = next) + { + ++next; + if (pred(*first)) + { + if (source(*first, g) != target(*first, g)) + { + // Remove the edge from the target + detail::remove_directed_edge_dispatch(*first, + g.out_edge_list(target(*first, g)), + *(PropT*)(*first).get_property()); + } + + // Erase the edge property + g.m_edges.erase((*first.base()).get_iter()); + + // Erase the edge in the source + el.erase(first.base()); + } } - } - - // O(E/V) - template <class edge_descriptor, class EdgeList, class StoredProperty> - inline void - remove_directed_edge_dispatch(edge_descriptor e, EdgeList& el, - no_property&) - { - for (typename EdgeList::iterator i = el.begin(); - i != el.end(); ++i) - if ((*i).get_target() == e.m_target) { - el.erase(i); - return; - } - } + } - } // namespace detail + // O(E/V) + template < class edge_descriptor, class EdgeList, class StoredProperty > + inline void remove_directed_edge_dispatch( + edge_descriptor e, EdgeList& el, no_property&) + { + for (typename EdgeList::iterator i = el.begin(); i != el.end(); ++i) + if ((*i).get_target() == e.m_target) + { + el.erase(i); + return; + } + } + +} // namespace detail - template <class Config> - struct directed_edges_helper { +template < class Config > struct directed_edges_helper +{ - // Placement of these overloaded remove_edge() functions - // inside the class avoids a VC++ bug. + // Placement of these overloaded remove_edge() functions + // inside the class avoids a VC++ bug. - // O(E/V) - inline void - remove_edge(typename Config::edge_descriptor e) - { + // O(E/V) + inline void remove_edge(typename Config::edge_descriptor e) + { typedef typename Config::graph_type graph_type; - graph_type& g = static_cast<graph_type&>(*this); + graph_type& g = static_cast< graph_type& >(*this); typename Config::OutEdgeList& el = g.out_edge_list(source(e, g)); typedef typename Config::OutEdgeList::value_type::property_type PType; - detail::remove_directed_edge_dispatch(e, el, - *(PType*)e.get_property()); - } - - // O(1) - inline void - remove_edge(typename Config::out_edge_iterator iter) - { + detail::remove_directed_edge_dispatch(e, el, *(PType*)e.get_property()); + } + + // O(1) + inline void remove_edge(typename Config::out_edge_iterator iter) + { typedef typename Config::graph_type graph_type; - graph_type& g = static_cast<graph_type&>(*this); + graph_type& g = static_cast< graph_type& >(*this); typename Config::edge_descriptor e = *iter; typename Config::OutEdgeList& el = g.out_edge_list(source(e, g)); el.erase(iter.base()); - } - - }; - - // O(1) - template <class Config> - inline std::pair<typename Config::edge_iterator, - typename Config::edge_iterator> - edges(const directed_edges_helper<Config>& g_) - { - typedef typename Config::graph_type graph_type; - typedef typename Config::edge_iterator edge_iterator; - const graph_type& cg = static_cast<const graph_type&>(g_); - graph_type& g = const_cast<graph_type&>(cg); - return std::make_pair( edge_iterator(g.vertex_set().begin(), - g.vertex_set().begin(), - g.vertex_set().end(), g), - edge_iterator(g.vertex_set().begin(), - g.vertex_set().end(), - g.vertex_set().end(), g) ); } +}; + +// O(1) +template < class Config > +inline std::pair< typename Config::edge_iterator, + typename Config::edge_iterator > +edges(const directed_edges_helper< Config >& g_) +{ + typedef typename Config::graph_type graph_type; + typedef typename Config::edge_iterator edge_iterator; + const graph_type& cg = static_cast< const graph_type& >(g_); + graph_type& g = const_cast< graph_type& >(cg); + return std::make_pair(edge_iterator(g.vertex_set().begin(), + g.vertex_set().begin(), g.vertex_set().end(), g), + edge_iterator(g.vertex_set().begin(), g.vertex_set().end(), + g.vertex_set().end(), g)); +} - //========================================================================= - // Directed Graph Helper Class - - struct adj_list_dir_traversal_tag : - public virtual vertex_list_graph_tag, - public virtual incidence_graph_tag, - public virtual adjacency_graph_tag, - public virtual edge_list_graph_tag { }; - - template <class Config> - struct directed_graph_helper - : public directed_edges_helper<Config> { - typedef typename Config::edge_descriptor edge_descriptor; - typedef adj_list_dir_traversal_tag traversal_category; - }; +//========================================================================= +// Directed Graph Helper Class + +struct adj_list_dir_traversal_tag : public virtual vertex_list_graph_tag, + public virtual incidence_graph_tag, + public virtual adjacency_graph_tag, + public virtual edge_list_graph_tag +{ +}; + +template < class Config > +struct directed_graph_helper : public directed_edges_helper< Config > +{ + typedef typename Config::edge_descriptor edge_descriptor; + typedef adj_list_dir_traversal_tag traversal_category; +}; + +// O(E/V) +template < class Config > +inline void remove_edge(typename Config::vertex_descriptor u, + typename Config::vertex_descriptor v, directed_graph_helper< Config >& g_) +{ + typedef typename Config::graph_type graph_type; + typedef typename Config::edge_parallel_category Cat; + graph_type& g = static_cast< graph_type& >(g_); + detail::erase_from_incidence_list(g.out_edge_list(u), v, Cat()); +} - // O(E/V) - template <class Config> - inline void - remove_edge(typename Config::vertex_descriptor u, - typename Config::vertex_descriptor v, - directed_graph_helper<Config>& g_) - { - typedef typename Config::graph_type graph_type; - typedef typename Config::edge_parallel_category Cat; - graph_type& g = static_cast<graph_type&>(g_); - detail::erase_from_incidence_list(g.out_edge_list(u), v, Cat()); - } +template < class Config, class Predicate > +inline void remove_out_edge_if(typename Config::vertex_descriptor u, + Predicate pred, directed_graph_helper< Config >& g_) +{ + typedef typename Config::graph_type graph_type; + graph_type& g = static_cast< graph_type& >(g_); + typename Config::out_edge_iterator first, last; + boost::tie(first, last) = out_edges(u, g); + typedef typename Config::edge_parallel_category edge_parallel_category; + detail::remove_directed_edge_if_dispatch( + first, last, g.out_edge_list(u), pred, edge_parallel_category()); +} - template <class Config, class Predicate> - inline void - remove_out_edge_if(typename Config::vertex_descriptor u, Predicate pred, - directed_graph_helper<Config>& g_) - { - typedef typename Config::graph_type graph_type; - graph_type& g = static_cast<graph_type&>(g_); - typename Config::out_edge_iterator first, last; - boost::tie(first, last) = out_edges(u, g); - typedef typename Config::edge_parallel_category edge_parallel_category; - detail::remove_directed_edge_if_dispatch - (first, last, g.out_edge_list(u), pred, edge_parallel_category()); - } +template < class Config, class Predicate > +inline void remove_edge_if(Predicate pred, directed_graph_helper< Config >& g_) +{ + typedef typename Config::graph_type graph_type; + graph_type& g = static_cast< graph_type& >(g_); - template <class Config, class Predicate> - inline void - remove_edge_if(Predicate pred, directed_graph_helper<Config>& g_) - { - typedef typename Config::graph_type graph_type; - graph_type& g = static_cast<graph_type&>(g_); - - typename Config::vertex_iterator vi, vi_end; - for (boost::tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi) + typename Config::vertex_iterator vi, vi_end; + for (boost::tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi) remove_out_edge_if(*vi, pred, g); - } +} - template <class EdgeOrIter, class Config> - inline void - remove_edge(EdgeOrIter e_or_iter, directed_graph_helper<Config>& g_) - { - g_.remove_edge(e_or_iter); - } +template < class EdgeOrIter, class Config > +inline void remove_edge( + EdgeOrIter e_or_iter, directed_graph_helper< Config >& g_) +{ + g_.remove_edge(e_or_iter); +} - // O(V + E) for allow_parallel_edges - // O(V * log(E/V)) for disallow_parallel_edges - template <class Config> - inline void - clear_vertex(typename Config::vertex_descriptor u, - directed_graph_helper<Config>& g_) - { - typedef typename Config::graph_type graph_type; - typedef typename Config::edge_parallel_category Cat; - graph_type& g = static_cast<graph_type&>(g_); - typename Config::vertex_iterator vi, viend; - for (boost::tie(vi, viend) = vertices(g); vi != viend; ++vi) +// O(V + E) for allow_parallel_edges +// O(V * log(E/V)) for disallow_parallel_edges +template < class Config > +inline void clear_vertex( + typename Config::vertex_descriptor u, directed_graph_helper< Config >& g_) +{ + typedef typename Config::graph_type graph_type; + typedef typename Config::edge_parallel_category Cat; + graph_type& g = static_cast< graph_type& >(g_); + typename Config::vertex_iterator vi, viend; + for (boost::tie(vi, viend) = vertices(g); vi != viend; ++vi) detail::erase_from_incidence_list(g.out_edge_list(*vi), u, Cat()); - g.out_edge_list(u).clear(); - // clear() should be a req of Sequence and AssociativeContainer, - // or maybe just Container - } + g.out_edge_list(u).clear(); + // clear() should be a req of Sequence and AssociativeContainer, + // or maybe just Container +} - template <class Config> - inline void - clear_out_edges(typename Config::vertex_descriptor u, - directed_graph_helper<Config>& g_) - { - typedef typename Config::graph_type graph_type; - graph_type& g = static_cast<graph_type&>(g_); - g.out_edge_list(u).clear(); - // clear() should be a req of Sequence and AssociativeContainer, - // or maybe just Container - } +template < class Config > +inline void clear_out_edges( + typename Config::vertex_descriptor u, directed_graph_helper< Config >& g_) +{ + typedef typename Config::graph_type graph_type; + graph_type& g = static_cast< graph_type& >(g_); + g.out_edge_list(u).clear(); + // clear() should be a req of Sequence and AssociativeContainer, + // or maybe just Container +} - // O(V), could do better... - template <class Config> - inline typename Config::edges_size_type - num_edges(const directed_graph_helper<Config>& g_) - { - typedef typename Config::graph_type graph_type; - const graph_type& g = static_cast<const graph_type&>(g_); - typename Config::edges_size_type num_e = 0; - typename Config::vertex_iterator vi, vi_end; - for (boost::tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi) +// O(V), could do better... +template < class Config > +inline typename Config::edges_size_type num_edges( + const directed_graph_helper< Config >& g_) +{ + typedef typename Config::graph_type graph_type; + const graph_type& g = static_cast< const graph_type& >(g_); + typename Config::edges_size_type num_e = 0; + typename Config::vertex_iterator vi, vi_end; + for (boost::tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi) num_e += out_degree(*vi, g); - return num_e; - } - // O(1) for allow_parallel_edge_tag - // O(log(E/V)) for disallow_parallel_edge_tag - template <class Config> - inline std::pair<typename directed_graph_helper<Config>::edge_descriptor, bool> - add_edge(typename Config::vertex_descriptor u, - typename Config::vertex_descriptor v, - const typename Config::edge_property_type& p, - directed_graph_helper<Config>& g_) - { - typedef typename Config::edge_descriptor edge_descriptor; - typedef typename Config::graph_type graph_type; - typedef typename Config::StoredEdge StoredEdge; - graph_type& g = static_cast<graph_type&>(g_); - typename Config::OutEdgeList::iterator i; - bool inserted; - boost::tie(i, inserted) = boost::graph_detail::push(g.out_edge_list(u), - StoredEdge(v, p)); - return std::make_pair(edge_descriptor(u, v, &(*i).get_property()), - inserted); - } - // Did not use default argument here because that - // causes Visual C++ to get confused. - template <class Config> - inline std::pair<typename Config::edge_descriptor, bool> - add_edge(typename Config::vertex_descriptor u, - typename Config::vertex_descriptor v, - directed_graph_helper<Config>& g_) - { - typename Config::edge_property_type p; - return add_edge(u, v, p, g_); - } - //========================================================================= - // Undirected Graph Helper Class + return num_e; +} +// O(1) for allow_parallel_edge_tag +// O(log(E/V)) for disallow_parallel_edge_tag +template < class Config > +inline std::pair< typename directed_graph_helper< Config >::edge_descriptor, + bool > +add_edge(typename Config::vertex_descriptor u, + typename Config::vertex_descriptor v, + const typename Config::edge_property_type& p, + directed_graph_helper< Config >& g_) +{ + typedef typename Config::edge_descriptor edge_descriptor; + typedef typename Config::graph_type graph_type; + typedef typename Config::StoredEdge StoredEdge; + graph_type& g = static_cast< graph_type& >(g_); + typename Config::OutEdgeList::iterator i; + bool inserted; + boost::tie(i, inserted) + = boost::graph_detail::push(g.out_edge_list(u), StoredEdge(v, p)); + return std::make_pair( + edge_descriptor(u, v, &(*i).get_property()), inserted); +} +// Did not use default argument here because that +// causes Visual C++ to get confused. +template < class Config > +inline std::pair< typename Config::edge_descriptor, bool > add_edge( + typename Config::vertex_descriptor u, typename Config::vertex_descriptor v, + directed_graph_helper< Config >& g_) +{ + typename Config::edge_property_type p; + return add_edge(u, v, p, g_); +} +//========================================================================= +// Undirected Graph Helper Class - template <class Config> - struct undirected_graph_helper; +template < class Config > struct undirected_graph_helper; - struct undir_adj_list_traversal_tag : - public virtual vertex_list_graph_tag, - public virtual incidence_graph_tag, - public virtual adjacency_graph_tag, - public virtual edge_list_graph_tag, - public virtual bidirectional_graph_tag { }; +struct undir_adj_list_traversal_tag : public virtual vertex_list_graph_tag, + public virtual incidence_graph_tag, + public virtual adjacency_graph_tag, + public virtual edge_list_graph_tag, + public virtual bidirectional_graph_tag +{ +}; - namespace detail { +namespace detail +{ - // using class with specialization for dispatch is a VC++ workaround. - template <class StoredProperty> - struct remove_undirected_edge_dispatch { + // using class with specialization for dispatch is a VC++ workaround. + template < class StoredProperty > struct remove_undirected_edge_dispatch + { // O(E/V) - template <class edge_descriptor, class Config> - static void - apply(edge_descriptor e, - undirected_graph_helper<Config>& g_, - StoredProperty& p) + template < class edge_descriptor, class Config > + static void apply(edge_descriptor e, + undirected_graph_helper< Config >& g_, StoredProperty& p) { - typedef typename Config::global_edgelist_selector EdgeListS; - BOOST_STATIC_ASSERT((!is_same<EdgeListS, vecS>::value)); - - typedef typename Config::graph_type graph_type; - graph_type& g = static_cast<graph_type&>(g_); - - typename Config::OutEdgeList& out_el = g.out_edge_list(source(e, g)); - typename Config::OutEdgeList::iterator out_i = out_el.begin(); - typename Config::EdgeIter edge_iter_to_erase; - for (; out_i != out_el.end(); ++out_i) - if (&(*out_i).get_property() == &p) { - edge_iter_to_erase = (*out_i).get_iter(); - out_el.erase(out_i); - break; - } - typename Config::OutEdgeList& in_el = g.out_edge_list(target(e, g)); - typename Config::OutEdgeList::iterator in_i = in_el.begin(); - for (; in_i != in_el.end(); ++in_i) - if (&(*in_i).get_property() == &p) { - in_el.erase(in_i); - break; - } - g.m_edges.erase(edge_iter_to_erase); + typedef typename Config::global_edgelist_selector EdgeListS; + BOOST_STATIC_ASSERT((!is_same< EdgeListS, vecS >::value)); + + typedef typename Config::graph_type graph_type; + graph_type& g = static_cast< graph_type& >(g_); + + typename Config::OutEdgeList& out_el + = g.out_edge_list(source(e, g)); + typename Config::OutEdgeList::iterator out_i = out_el.begin(); + typename Config::EdgeIter edge_iter_to_erase; + for (; out_i != out_el.end(); ++out_i) + if (&(*out_i).get_property() == &p) + { + edge_iter_to_erase = (*out_i).get_iter(); + out_el.erase(out_i); + break; + } + typename Config::OutEdgeList& in_el = g.out_edge_list(target(e, g)); + typename Config::OutEdgeList::iterator in_i = in_el.begin(); + for (; in_i != in_el.end(); ++in_i) + if (&(*in_i).get_property() == &p) + { + in_el.erase(in_i); + break; + } + g.m_edges.erase(edge_iter_to_erase); } - }; + }; - template <> - struct remove_undirected_edge_dispatch<no_property> { + template <> struct remove_undirected_edge_dispatch< no_property > + { // O(E/V) - template <class edge_descriptor, class Config> - static void - apply(edge_descriptor e, - undirected_graph_helper<Config>& g_, - no_property&) + template < class edge_descriptor, class Config > + static void apply(edge_descriptor e, + undirected_graph_helper< Config >& g_, no_property&) { - typedef typename Config::global_edgelist_selector EdgeListS; - BOOST_STATIC_ASSERT((!is_same<EdgeListS, vecS>::value)); - - typedef typename Config::graph_type graph_type; - graph_type& g = static_cast<graph_type&>(g_); - no_property* p = (no_property*)e.get_property(); - typename Config::OutEdgeList& out_el = g.out_edge_list(source(e, g)); - typename Config::OutEdgeList::iterator out_i = out_el.begin(); - typename Config::EdgeIter edge_iter_to_erase; - for (; out_i != out_el.end(); ++out_i) - if (&(*out_i).get_property() == p) { - edge_iter_to_erase = (*out_i).get_iter(); - out_el.erase(out_i); - break; - } - typename Config::OutEdgeList& in_el = g.out_edge_list(target(e, g)); - typename Config::OutEdgeList::iterator in_i = in_el.begin(); - for (; in_i != in_el.end(); ++in_i) - if (&(*in_i).get_property() == p) { - in_el.erase(in_i); - break; - } - g.m_edges.erase(edge_iter_to_erase); + typedef typename Config::global_edgelist_selector EdgeListS; + BOOST_STATIC_ASSERT((!is_same< EdgeListS, vecS >::value)); + + typedef typename Config::graph_type graph_type; + graph_type& g = static_cast< graph_type& >(g_); + no_property* p = (no_property*)e.get_property(); + typename Config::OutEdgeList& out_el + = g.out_edge_list(source(e, g)); + typename Config::OutEdgeList::iterator out_i = out_el.begin(); + typename Config::EdgeIter edge_iter_to_erase; + for (; out_i != out_el.end(); ++out_i) + if (&(*out_i).get_property() == p) + { + edge_iter_to_erase = (*out_i).get_iter(); + out_el.erase(out_i); + break; + } + typename Config::OutEdgeList& in_el = g.out_edge_list(target(e, g)); + typename Config::OutEdgeList::iterator in_i = in_el.begin(); + for (; in_i != in_el.end(); ++in_i) + if (&(*in_i).get_property() == p) + { + in_el.erase(in_i); + break; + } + g.m_edges.erase(edge_iter_to_erase); } - }; - - // O(E/V) - template <class Graph, class EdgeList, class Vertex> - inline void - remove_edge_and_property(Graph& g, EdgeList& el, Vertex v, - boost::allow_parallel_edge_tag cat) - { + }; + + // O(E/V) + template < class Graph, class EdgeList, class Vertex > + inline void remove_edge_and_property( + Graph& g, EdgeList& el, Vertex v, boost::allow_parallel_edge_tag cat) + { typedef typename Graph::global_edgelist_selector EdgeListS; - BOOST_STATIC_ASSERT((!is_same<EdgeListS, vecS>::value)); + BOOST_STATIC_ASSERT((!is_same< EdgeListS, vecS >::value)); typename EdgeList::iterator i = el.begin(), end = el.end(); - for (; i != end; ++i) { - if ((*i).get_target() == v) { - // NOTE: Wihtout this skip, this loop will double-delete properties - // of loop edges. This solution is based on the observation that - // the incidence edges of a vertex with a loop are adjacent in the - // out edge list. This *may* actually hold for multisets also. - bool skip = (boost::next(i) != end && i->get_iter() == boost::next(i)->get_iter()); - g.m_edges.erase((*i).get_iter()); - if (skip) ++i; - } + for (; i != end; ++i) + { + if ((*i).get_target() == v) + { + // NOTE: Wihtout this skip, this loop will double-delete + // properties of loop edges. This solution is based on the + // observation that the incidence edges of a vertex with a loop + // are adjacent in the out edge list. This *may* actually hold + // for multisets also. + bool skip = (boost::next(i) != end + && i->get_iter() == boost::next(i)->get_iter()); + g.m_edges.erase((*i).get_iter()); + if (skip) + ++i; + } } detail::erase_from_incidence_list(el, v, cat); - } - // O(log(E/V)) - template <class Graph, class EdgeList, class Vertex> - inline void - remove_edge_and_property(Graph& g, EdgeList& el, Vertex v, - boost::disallow_parallel_edge_tag) - { + } + // O(log(E/V)) + template < class Graph, class EdgeList, class Vertex > + inline void remove_edge_and_property( + Graph& g, EdgeList& el, Vertex v, boost::disallow_parallel_edge_tag) + { typedef typename Graph::global_edgelist_selector EdgeListS; - BOOST_STATIC_ASSERT((!is_same<EdgeListS, vecS>::value)); + BOOST_STATIC_ASSERT((!is_same< EdgeListS, vecS >::value)); typedef typename EdgeList::value_type StoredEdge; typename EdgeList::iterator i = el.find(StoredEdge(v)), end = el.end(); - if (i != end) { - g.m_edges.erase((*i).get_iter()); - el.erase(i); + if (i != end) + { + g.m_edges.erase((*i).get_iter()); + el.erase(i); } - } - - } // namespace detail - - template <class Vertex, class EdgeProperty> - struct list_edge // short name due to VC++ truncation and linker problems - : public boost::detail::edge_base<boost::undirected_tag, Vertex> - { - typedef EdgeProperty property_type; - typedef boost::detail::edge_base<boost::undirected_tag, Vertex> Base; - list_edge(Vertex u, Vertex v, const EdgeProperty& p = EdgeProperty()) - : Base(u, v), m_property(p) { } - EdgeProperty& get_property() { return m_property; } - const EdgeProperty& get_property() const { return m_property; } - // the following methods should never be used, but are needed - // to make SGI MIPSpro C++ happy - list_edge() { } - bool operator==(const list_edge&) const { return false; } - bool operator<(const list_edge&) const { return false; } - EdgeProperty m_property; - }; + } - template <class Config> - struct undirected_graph_helper { +} // namespace detail - typedef undir_adj_list_traversal_tag traversal_category; +template < class Vertex, class EdgeProperty > +struct list_edge // short name due to VC++ truncation and linker problems +: public boost::detail::edge_base< boost::undirected_tag, Vertex > +{ + typedef EdgeProperty property_type; + typedef boost::detail::edge_base< boost::undirected_tag, Vertex > Base; + list_edge(Vertex u, Vertex v, const EdgeProperty& p = EdgeProperty()) + : Base(u, v), m_property(p) + { + } + EdgeProperty& get_property() { return m_property; } + const EdgeProperty& get_property() const { return m_property; } + // the following methods should never be used, but are needed + // to make SGI MIPSpro C++ happy + list_edge() {} + bool operator==(const list_edge&) const { return false; } + bool operator<(const list_edge&) const { return false; } + EdgeProperty m_property; +}; - // Placement of these overloaded remove_edge() functions - // inside the class avoids a VC++ bug. +template < class Config > struct undirected_graph_helper +{ - // O(E/V) - inline void - remove_edge(typename Config::edge_descriptor e) - { - typedef typename Config::global_edgelist_selector EdgeListS; - BOOST_STATIC_ASSERT((!is_same<EdgeListS, vecS>::value)); + typedef undir_adj_list_traversal_tag traversal_category; - typedef typename Config::OutEdgeList::value_type::property_type PType; - detail::remove_undirected_edge_dispatch<PType>::apply - (e, *this, *(PType*)e.get_property()); - } - // O(E/V) - inline void - remove_edge(typename Config::out_edge_iterator iter) - { - this->remove_edge(*iter); - } - }; + // Placement of these overloaded remove_edge() functions + // inside the class avoids a VC++ bug. - // Had to make these non-members to avoid accidental instantiation - // on SGI MIPSpro C++ - template <class C> - inline typename C::InEdgeList& - in_edge_list(undirected_graph_helper<C>&, - typename C::vertex_descriptor v) + // O(E/V) + inline void remove_edge(typename Config::edge_descriptor e) { - typename C::stored_vertex* sv = (typename C::stored_vertex*)v; - return sv->m_out_edges; - } - template <class C> - inline const typename C::InEdgeList& - in_edge_list(const undirected_graph_helper<C>&, - typename C::vertex_descriptor v) { - typename C::stored_vertex* sv = (typename C::stored_vertex*)v; - return sv->m_out_edges; - } + typedef typename Config::global_edgelist_selector EdgeListS; + BOOST_STATIC_ASSERT((!is_same< EdgeListS, vecS >::value)); + typedef typename Config::OutEdgeList::value_type::property_type PType; + detail::remove_undirected_edge_dispatch< PType >::apply( + e, *this, *(PType*)e.get_property()); + } // O(E/V) - template <class EdgeOrIter, class Config> - inline void - remove_edge(EdgeOrIter e, undirected_graph_helper<Config>& g_) + inline void remove_edge(typename Config::out_edge_iterator iter) { - typedef typename Config::global_edgelist_selector EdgeListS; - BOOST_STATIC_ASSERT((!is_same<EdgeListS, vecS>::value)); - - g_.remove_edge(e); + this->remove_edge(*iter); } +}; - // O(E/V) or O(log(E/V)) - template <class Config> - void - remove_edge(typename Config::vertex_descriptor u, - typename Config::vertex_descriptor v, - undirected_graph_helper<Config>& g_) - { - typedef typename Config::global_edgelist_selector EdgeListS; - BOOST_STATIC_ASSERT((!is_same<EdgeListS, vecS>::value)); - - typedef typename Config::graph_type graph_type; - graph_type& g = static_cast<graph_type&>(g_); - typedef typename Config::edge_parallel_category Cat; - detail::remove_edge_and_property(g, g.out_edge_list(u), v, Cat()); - detail::erase_from_incidence_list(g.out_edge_list(v), u, Cat()); - } - - template <class Config, class Predicate> - void - remove_out_edge_if(typename Config::vertex_descriptor u, Predicate pred, - undirected_graph_helper<Config>& g_) - { - typedef typename Config::global_edgelist_selector EdgeListS; - BOOST_STATIC_ASSERT((!is_same<EdgeListS, vecS>::value)); - - typedef typename Config::graph_type graph_type; - typedef typename Config::OutEdgeList::value_type::property_type PropT; - graph_type& g = static_cast<graph_type&>(g_); - typename Config::out_edge_iterator first, last; - boost::tie(first, last) = out_edges(u, g); - typedef typename Config::edge_parallel_category Cat; - detail::undirected_remove_out_edge_if_dispatch<PropT> - (g, first, last, g.out_edge_list(u), pred, Cat()); - } - template <class Config, class Predicate> - void - remove_in_edge_if(typename Config::vertex_descriptor u, Predicate pred, - undirected_graph_helper<Config>& g_) - { - typedef typename Config::global_edgelist_selector EdgeListS; - BOOST_STATIC_ASSERT((!is_same<EdgeListS, vecS>::value)); - - remove_out_edge_if(u, pred, g_); - } - - // O(E/V * E) or O(log(E/V) * E) - template <class Predicate, class Config> - void - remove_edge_if(Predicate pred, undirected_graph_helper<Config>& g_) - { - typedef typename Config::global_edgelist_selector EdgeListS; - BOOST_STATIC_ASSERT((!is_same<EdgeListS, vecS>::value)); - - typedef typename Config::graph_type graph_type; - graph_type& g = static_cast<graph_type&>(g_); - typename Config::edge_iterator ei, ei_end, next; - boost::tie(ei, ei_end) = edges(g); - for (next = ei; ei != ei_end; ei = next) { +// Had to make these non-members to avoid accidental instantiation +// on SGI MIPSpro C++ +template < class C > +inline typename C::InEdgeList& in_edge_list( + undirected_graph_helper< C >&, typename C::vertex_descriptor v) +{ + typename C::stored_vertex* sv = (typename C::stored_vertex*)v; + return sv->m_out_edges; +} +template < class C > +inline const typename C::InEdgeList& in_edge_list( + const undirected_graph_helper< C >&, typename C::vertex_descriptor v) +{ + typename C::stored_vertex* sv = (typename C::stored_vertex*)v; + return sv->m_out_edges; +} + +// O(E/V) +template < class EdgeOrIter, class Config > +inline void remove_edge(EdgeOrIter e, undirected_graph_helper< Config >& g_) +{ + typedef typename Config::global_edgelist_selector EdgeListS; + BOOST_STATIC_ASSERT((!is_same< EdgeListS, vecS >::value)); + + g_.remove_edge(e); +} + +// O(E/V) or O(log(E/V)) +template < class Config > +void remove_edge(typename Config::vertex_descriptor u, + typename Config::vertex_descriptor v, undirected_graph_helper< Config >& g_) +{ + typedef typename Config::global_edgelist_selector EdgeListS; + BOOST_STATIC_ASSERT((!is_same< EdgeListS, vecS >::value)); + + typedef typename Config::graph_type graph_type; + graph_type& g = static_cast< graph_type& >(g_); + typedef typename Config::edge_parallel_category Cat; + detail::remove_edge_and_property(g, g.out_edge_list(u), v, Cat()); + detail::erase_from_incidence_list(g.out_edge_list(v), u, Cat()); +} + +template < class Config, class Predicate > +void remove_out_edge_if(typename Config::vertex_descriptor u, Predicate pred, + undirected_graph_helper< Config >& g_) +{ + typedef typename Config::global_edgelist_selector EdgeListS; + BOOST_STATIC_ASSERT((!is_same< EdgeListS, vecS >::value)); + + typedef typename Config::graph_type graph_type; + typedef typename Config::OutEdgeList::value_type::property_type PropT; + graph_type& g = static_cast< graph_type& >(g_); + typename Config::out_edge_iterator first, last; + boost::tie(first, last) = out_edges(u, g); + typedef typename Config::edge_parallel_category Cat; + detail::undirected_remove_out_edge_if_dispatch< PropT >( + g, first, last, g.out_edge_list(u), pred, Cat()); +} +template < class Config, class Predicate > +void remove_in_edge_if(typename Config::vertex_descriptor u, Predicate pred, + undirected_graph_helper< Config >& g_) +{ + typedef typename Config::global_edgelist_selector EdgeListS; + BOOST_STATIC_ASSERT((!is_same< EdgeListS, vecS >::value)); + + remove_out_edge_if(u, pred, g_); +} + +// O(E/V * E) or O(log(E/V) * E) +template < class Predicate, class Config > +void remove_edge_if(Predicate pred, undirected_graph_helper< Config >& g_) +{ + typedef typename Config::global_edgelist_selector EdgeListS; + BOOST_STATIC_ASSERT((!is_same< EdgeListS, vecS >::value)); + + typedef typename Config::graph_type graph_type; + graph_type& g = static_cast< graph_type& >(g_); + typename Config::edge_iterator ei, ei_end, next; + boost::tie(ei, ei_end) = edges(g); + for (next = ei; ei != ei_end; ei = next) + { ++next; if (pred(*ei)) - remove_edge(*ei, g); - } + remove_edge(*ei, g); } +} - // O(1) - template <class Config> - inline std::pair<typename Config::edge_iterator, - typename Config::edge_iterator> - edges(const undirected_graph_helper<Config>& g_) - { - typedef typename Config::graph_type graph_type; - typedef typename Config::edge_iterator edge_iterator; - const graph_type& cg = static_cast<const graph_type&>(g_); - graph_type& g = const_cast<graph_type&>(cg); - return std::make_pair( edge_iterator(g.m_edges.begin()), - edge_iterator(g.m_edges.end()) ); - } - // O(1) - template <class Config> - inline typename Config::edges_size_type - num_edges(const undirected_graph_helper<Config>& g_) - { - typedef typename Config::graph_type graph_type; - const graph_type& g = static_cast<const graph_type&>(g_); - return g.m_edges.size(); - } - // O(E/V * E/V) - template <class Config> - inline void - clear_vertex(typename Config::vertex_descriptor u, - undirected_graph_helper<Config>& g_) - { - typedef typename Config::global_edgelist_selector EdgeListS; - BOOST_STATIC_ASSERT((!is_same<EdgeListS, vecS>::value)); - - typedef typename Config::graph_type graph_type; - graph_type& g = static_cast<graph_type&>(g_); - while (true) { +// O(1) +template < class Config > +inline std::pair< typename Config::edge_iterator, + typename Config::edge_iterator > +edges(const undirected_graph_helper< Config >& g_) +{ + typedef typename Config::graph_type graph_type; + typedef typename Config::edge_iterator edge_iterator; + const graph_type& cg = static_cast< const graph_type& >(g_); + graph_type& g = const_cast< graph_type& >(cg); + return std::make_pair( + edge_iterator(g.m_edges.begin()), edge_iterator(g.m_edges.end())); +} +// O(1) +template < class Config > +inline typename Config::edges_size_type num_edges( + const undirected_graph_helper< Config >& g_) +{ + typedef typename Config::graph_type graph_type; + const graph_type& g = static_cast< const graph_type& >(g_); + return g.m_edges.size(); +} +// O(E/V * E/V) +template < class Config > +inline void clear_vertex( + typename Config::vertex_descriptor u, undirected_graph_helper< Config >& g_) +{ + typedef typename Config::global_edgelist_selector EdgeListS; + BOOST_STATIC_ASSERT((!is_same< EdgeListS, vecS >::value)); + + typedef typename Config::graph_type graph_type; + graph_type& g = static_cast< graph_type& >(g_); + while (true) + { typename Config::out_edge_iterator ei, ei_end; boost::tie(ei, ei_end) = out_edges(u, g); - if (ei == ei_end) break; + if (ei == ei_end) + break; remove_edge(*ei, g); - } - } - // O(1) for allow_parallel_edge_tag - // O(log(E/V)) for disallow_parallel_edge_tag - template <class Config> - inline std::pair<typename Config::edge_descriptor, bool> - add_edge(typename Config::vertex_descriptor u, - typename Config::vertex_descriptor v, - const typename Config::edge_property_type& p, - undirected_graph_helper<Config>& g_) - { - typedef typename Config::StoredEdge StoredEdge; - typedef typename Config::edge_descriptor edge_descriptor; - typedef typename Config::graph_type graph_type; - graph_type& g = static_cast<graph_type&>(g_); - - bool inserted; - typename Config::EdgeContainer::value_type e(u, v, p); - typename Config::EdgeContainer::iterator p_iter + } +} +// O(1) for allow_parallel_edge_tag +// O(log(E/V)) for disallow_parallel_edge_tag +template < class Config > +inline std::pair< typename Config::edge_descriptor, bool > add_edge( + typename Config::vertex_descriptor u, typename Config::vertex_descriptor v, + const typename Config::edge_property_type& p, + undirected_graph_helper< Config >& g_) +{ + typedef typename Config::StoredEdge StoredEdge; + typedef typename Config::edge_descriptor edge_descriptor; + typedef typename Config::graph_type graph_type; + graph_type& g = static_cast< graph_type& >(g_); + + bool inserted; + typename Config::EdgeContainer::value_type e(u, v, p); + typename Config::EdgeContainer::iterator p_iter = graph_detail::push(g.m_edges, e).first; - typename Config::OutEdgeList::iterator i; - boost::tie(i, inserted) = boost::graph_detail::push(g.out_edge_list(u), - StoredEdge(v, p_iter, &g.m_edges)); - if (inserted) { - boost::graph_detail::push(g.out_edge_list(v), StoredEdge(u, p_iter, &g.m_edges)); - return std::make_pair(edge_descriptor(u, v, &p_iter->get_property()), - true); - } else { - g.m_edges.erase(p_iter); - return std::make_pair - (edge_descriptor(u, v, &i->get_iter()->get_property()), false); - } - } - template <class Config> - inline std::pair<typename Config::edge_descriptor, bool> - add_edge(typename Config::vertex_descriptor u, - typename Config::vertex_descriptor v, - undirected_graph_helper<Config>& g_) + typename Config::OutEdgeList::iterator i; + boost::tie(i, inserted) = boost::graph_detail::push( + g.out_edge_list(u), StoredEdge(v, p_iter, &g.m_edges)); + if (inserted) { - typename Config::edge_property_type p; - return add_edge(u, v, p, g_); + boost::graph_detail::push( + g.out_edge_list(v), StoredEdge(u, p_iter, &g.m_edges)); + return std::make_pair( + edge_descriptor(u, v, &p_iter->get_property()), true); } - - // O(1) - template <class Config> - inline typename Config::degree_size_type - degree(typename Config::vertex_descriptor u, - const undirected_graph_helper<Config>& g_) + else { - typedef typename Config::graph_type Graph; - const Graph& g = static_cast<const Graph&>(g_); - return out_degree(u, g); + g.m_edges.erase(p_iter); + return std::make_pair( + edge_descriptor(u, v, &i->get_iter()->get_property()), false); } +} +template < class Config > +inline std::pair< typename Config::edge_descriptor, bool > add_edge( + typename Config::vertex_descriptor u, typename Config::vertex_descriptor v, + undirected_graph_helper< Config >& g_) +{ + typename Config::edge_property_type p; + return add_edge(u, v, p, g_); +} + +// O(1) +template < class Config > +inline typename Config::degree_size_type degree( + typename Config::vertex_descriptor u, + const undirected_graph_helper< Config >& g_) +{ + typedef typename Config::graph_type Graph; + const Graph& g = static_cast< const Graph& >(g_); + return out_degree(u, g); +} - template <class Config> - inline std::pair<typename Config::in_edge_iterator, - typename Config::in_edge_iterator> - in_edges(typename Config::vertex_descriptor u, - const undirected_graph_helper<Config>& g_) +template < class Config > +inline std::pair< typename Config::in_edge_iterator, + typename Config::in_edge_iterator > +in_edges(typename Config::vertex_descriptor u, + const undirected_graph_helper< Config >& g_) +{ + typedef typename Config::graph_type Graph; + const Graph& cg = static_cast< const Graph& >(g_); + Graph& g = const_cast< Graph& >(cg); + typedef typename Config::in_edge_iterator in_edge_iterator; + return std::make_pair(in_edge_iterator(g.out_edge_list(u).begin(), u), + in_edge_iterator(g.out_edge_list(u).end(), u)); +} + +template < class Config > +inline typename Config::degree_size_type in_degree( + typename Config::vertex_descriptor u, + const undirected_graph_helper< Config >& g_) +{ + return degree(u, g_); +} + +//========================================================================= +// Bidirectional Graph Helper Class + +struct bidir_adj_list_traversal_tag : public virtual vertex_list_graph_tag, + public virtual incidence_graph_tag, + public virtual adjacency_graph_tag, + public virtual edge_list_graph_tag, + public virtual bidirectional_graph_tag +{ +}; + +template < class Config > +struct bidirectional_graph_helper : public directed_edges_helper< Config > +{ + typedef bidir_adj_list_traversal_tag traversal_category; +}; + +// Had to make these non-members to avoid accidental instantiation +// on SGI MIPSpro C++ +template < class C > +inline typename C::InEdgeList& in_edge_list( + bidirectional_graph_helper< C >&, typename C::vertex_descriptor v) +{ + typename C::stored_vertex* sv = (typename C::stored_vertex*)v; + return sv->m_in_edges; +} +template < class C > +inline const typename C::InEdgeList& in_edge_list( + const bidirectional_graph_helper< C >&, typename C::vertex_descriptor v) +{ + typename C::stored_vertex* sv = (typename C::stored_vertex*)v; + return sv->m_in_edges; +} + +template < class Predicate, class Config > +inline void remove_edge_if( + Predicate pred, bidirectional_graph_helper< Config >& g_) +{ + typedef typename Config::global_edgelist_selector EdgeListS; + BOOST_STATIC_ASSERT((!is_same< EdgeListS, vecS >::value)); + + typedef typename Config::graph_type graph_type; + graph_type& g = static_cast< graph_type& >(g_); + typename Config::edge_iterator ei, ei_end, next; + boost::tie(ei, ei_end) = edges(g); + for (next = ei; ei != ei_end; ei = next) { - typedef typename Config::graph_type Graph; - const Graph& cg = static_cast<const Graph&>(g_); - Graph& g = const_cast<Graph&>(cg); - typedef typename Config::in_edge_iterator in_edge_iterator; - return - std::make_pair(in_edge_iterator(g.out_edge_list(u).begin(), u), - in_edge_iterator(g.out_edge_list(u).end(), u)); + ++next; + if (pred(*ei)) + remove_edge(*ei, g); } +} - template <class Config> - inline typename Config::degree_size_type - in_degree(typename Config::vertex_descriptor u, - const undirected_graph_helper<Config>& g_) - { return degree(u, g_); } +template < class Config > +inline std::pair< typename Config::in_edge_iterator, + typename Config::in_edge_iterator > +in_edges(typename Config::vertex_descriptor u, + const bidirectional_graph_helper< Config >& g_) +{ + typedef typename Config::graph_type graph_type; + const graph_type& cg = static_cast< const graph_type& >(g_); + graph_type& g = const_cast< graph_type& >(cg); + typedef typename Config::in_edge_iterator in_edge_iterator; + return std::make_pair(in_edge_iterator(in_edge_list(g, u).begin(), u), + in_edge_iterator(in_edge_list(g, u).end(), u)); +} - //========================================================================= - // Bidirectional Graph Helper Class - - struct bidir_adj_list_traversal_tag : - public virtual vertex_list_graph_tag, - public virtual incidence_graph_tag, - public virtual adjacency_graph_tag, - public virtual edge_list_graph_tag, - public virtual bidirectional_graph_tag { }; - - template <class Config> - struct bidirectional_graph_helper - : public directed_edges_helper<Config> { - typedef bidir_adj_list_traversal_tag traversal_category; - }; +// O(1) +template < class Config > +inline std::pair< typename Config::edge_iterator, + typename Config::edge_iterator > +edges(const bidirectional_graph_helper< Config >& g_) +{ + typedef typename Config::graph_type graph_type; + typedef typename Config::edge_iterator edge_iterator; + const graph_type& cg = static_cast< const graph_type& >(g_); + graph_type& g = const_cast< graph_type& >(cg); + return std::make_pair( + edge_iterator(g.m_edges.begin()), edge_iterator(g.m_edges.end())); +} + +//========================================================================= +// Bidirectional Graph Helper Class (with edge properties) + +template < class Config > +struct bidirectional_graph_helper_with_property +: public bidirectional_graph_helper< Config > +{ + typedef typename Config::graph_type graph_type; + typedef typename Config::out_edge_iterator out_edge_iterator; - // Had to make these non-members to avoid accidental instantiation - // on SGI MIPSpro C++ - template <class C> - inline typename C::InEdgeList& - in_edge_list(bidirectional_graph_helper<C>&, - typename C::vertex_descriptor v) + std::pair< out_edge_iterator, out_edge_iterator > get_parallel_edge_sublist( + typename Config::edge_descriptor e, const graph_type& g, void*) { - typename C::stored_vertex* sv = (typename C::stored_vertex*)v; - return sv->m_in_edges; - } - template <class C> - inline const typename C::InEdgeList& - in_edge_list(const bidirectional_graph_helper<C>&, - typename C::vertex_descriptor v) { - typename C::stored_vertex* sv = (typename C::stored_vertex*)v; - return sv->m_in_edges; + return out_edges(source(e, g), g); } - template <class Predicate, class Config> - inline void - remove_edge_if(Predicate pred, bidirectional_graph_helper<Config>& g_) + std::pair< out_edge_iterator, out_edge_iterator > get_parallel_edge_sublist( + typename Config::edge_descriptor e, const graph_type& g, setS*) { - typedef typename Config::global_edgelist_selector EdgeListS; - BOOST_STATIC_ASSERT((!is_same<EdgeListS, vecS>::value)); - - typedef typename Config::graph_type graph_type; - graph_type& g = static_cast<graph_type&>(g_); - typename Config::edge_iterator ei, ei_end, next; - boost::tie(ei, ei_end) = edges(g); - for (next = ei; ei != ei_end; ei = next) { - ++next; - if (pred(*ei)) - remove_edge(*ei, g); - } + return edge_range(source(e, g), target(e, g), g); } - template <class Config> - inline std::pair<typename Config::in_edge_iterator, - typename Config::in_edge_iterator> - in_edges(typename Config::vertex_descriptor u, - const bidirectional_graph_helper<Config>& g_) + std::pair< out_edge_iterator, out_edge_iterator > get_parallel_edge_sublist( + typename Config::edge_descriptor e, const graph_type& g, multisetS*) { - typedef typename Config::graph_type graph_type; - const graph_type& cg = static_cast<const graph_type&>(g_); - graph_type& g = const_cast<graph_type&>(cg); - typedef typename Config::in_edge_iterator in_edge_iterator; - return - std::make_pair(in_edge_iterator(in_edge_list(g, u).begin(), u), - in_edge_iterator(in_edge_list(g, u).end(), u)); + return edge_range(source(e, g), target(e, g), g); } - // O(1) - template <class Config> - inline std::pair<typename Config::edge_iterator, - typename Config::edge_iterator> - edges(const bidirectional_graph_helper<Config>& g_) + std::pair< out_edge_iterator, out_edge_iterator > get_parallel_edge_sublist( + typename Config::edge_descriptor e, const graph_type& g, hash_setS*) { - typedef typename Config::graph_type graph_type; - typedef typename Config::edge_iterator edge_iterator; - const graph_type& cg = static_cast<const graph_type&>(g_); - graph_type& g = const_cast<graph_type&>(cg); - return std::make_pair( edge_iterator(g.m_edges.begin()), - edge_iterator(g.m_edges.end()) ); + return edge_range(source(e, g), target(e, g), g); } - //========================================================================= - // Bidirectional Graph Helper Class (with edge properties) - - - template <class Config> - struct bidirectional_graph_helper_with_property - : public bidirectional_graph_helper<Config> - { - typedef typename Config::graph_type graph_type; - typedef typename Config::out_edge_iterator out_edge_iterator; - - std::pair<out_edge_iterator, out_edge_iterator> - get_parallel_edge_sublist(typename Config::edge_descriptor e, - const graph_type& g, - void*) - { return out_edges(source(e, g), g); } - - std::pair<out_edge_iterator, out_edge_iterator> - get_parallel_edge_sublist(typename Config::edge_descriptor e, - const graph_type& g, - setS*) - { return edge_range(source(e, g), target(e, g), g); } - - std::pair<out_edge_iterator, out_edge_iterator> - get_parallel_edge_sublist(typename Config::edge_descriptor e, - const graph_type& g, - multisetS*) - { return edge_range(source(e, g), target(e, g), g); } - - std::pair<out_edge_iterator, out_edge_iterator> - get_parallel_edge_sublist(typename Config::edge_descriptor e, - const graph_type& g, - hash_setS*) - { return edge_range(source(e, g), target(e, g), g); } - - // Placement of these overloaded remove_edge() functions - // inside the class avoids a VC++ bug. - - // O(E/V) or O(log(E/V)) - void - remove_edge(typename Config::edge_descriptor e) - { + // Placement of these overloaded remove_edge() functions + // inside the class avoids a VC++ bug. + + // O(E/V) or O(log(E/V)) + void remove_edge(typename Config::edge_descriptor e) + { typedef typename Config::global_edgelist_selector EdgeListS; - BOOST_STATIC_ASSERT((!is_same<EdgeListS, vecS>::value)); + BOOST_STATIC_ASSERT((!is_same< EdgeListS, vecS >::value)); - graph_type& g = static_cast<graph_type&>(*this); + graph_type& g = static_cast< graph_type& >(*this); typedef typename Config::edgelist_selector OutEdgeListS; - std::pair<out_edge_iterator, out_edge_iterator> rng = - get_parallel_edge_sublist(e, g, (OutEdgeListS*)(0)); + std::pair< out_edge_iterator, out_edge_iterator > rng + = get_parallel_edge_sublist(e, g, (OutEdgeListS*)(0)); rng.first = std::find(rng.first, rng.second, e); BOOST_ASSERT(rng.first != rng.second); remove_edge(rng.first); - } + } - inline void - remove_edge(typename Config::out_edge_iterator iter) - { + inline void remove_edge(typename Config::out_edge_iterator iter) + { typedef typename Config::global_edgelist_selector EdgeListS; - BOOST_STATIC_ASSERT((!is_same<EdgeListS, vecS>::value)); - - Y_PRAGMA_DIAGNOSTIC_PUSH - Y_PRAGMA_NO_WSHADOW + BOOST_STATIC_ASSERT((!is_same< EdgeListS, vecS >::value)); typedef typename Config::graph_type graph_type; - graph_type& g = static_cast<graph_type&>(*this); + graph_type& g = static_cast< graph_type& >(*this); typename Config::edge_descriptor e = *iter; typename Config::OutEdgeList& oel = g.out_edge_list(source(e, g)); typename Config::InEdgeList& iel = in_edge_list(g, target(e, g)); @@ -1271,1545 +1281,1607 @@ namespace boost { detail::remove_directed_edge_dispatch(*iter, iel, p); g.m_edges.erase(iter.base()->get_iter()); oel.erase(iter.base()); + } +}; + +// O(E/V) for allow_parallel_edge_tag +// O(log(E/V)) for disallow_parallel_edge_tag +template < class Config > +inline void remove_edge(typename Config::vertex_descriptor u, + typename Config::vertex_descriptor v, + bidirectional_graph_helper_with_property< Config >& g_) +{ + typedef typename Config::global_edgelist_selector EdgeListS; + BOOST_STATIC_ASSERT((!is_same< EdgeListS, vecS >::value)); + + typedef typename Config::graph_type graph_type; + graph_type& g = static_cast< graph_type& >(g_); + typedef typename Config::edge_parallel_category Cat; + detail::remove_edge_and_property(g, g.out_edge_list(u), v, Cat()); + detail::erase_from_incidence_list(in_edge_list(g, v), u, Cat()); +} - Y_PRAGMA_DIAGNOSTIC_POP - } - }; - - // O(E/V) for allow_parallel_edge_tag - // O(log(E/V)) for disallow_parallel_edge_tag - template <class Config> - inline void - remove_edge(typename Config::vertex_descriptor u, - typename Config::vertex_descriptor v, - bidirectional_graph_helper_with_property<Config>& g_) - { - typedef typename Config::global_edgelist_selector EdgeListS; - BOOST_STATIC_ASSERT((!is_same<EdgeListS, vecS>::value)); +// O(E/V) or O(log(E/V)) +template < class EdgeOrIter, class Config > +inline void remove_edge( + EdgeOrIter e, bidirectional_graph_helper_with_property< Config >& g_) +{ + typedef typename Config::global_edgelist_selector EdgeListS; + BOOST_STATIC_ASSERT((!is_same< EdgeListS, vecS >::value)); - typedef typename Config::graph_type graph_type; - graph_type& g = static_cast<graph_type&>(g_); - typedef typename Config::edge_parallel_category Cat; - detail::remove_edge_and_property(g, g.out_edge_list(u), v, Cat()); - detail::erase_from_incidence_list(in_edge_list(g, v), u, Cat()); - } + g_.remove_edge(e); +} - // O(E/V) or O(log(E/V)) - template <class EdgeOrIter, class Config> - inline void - remove_edge(EdgeOrIter e, - bidirectional_graph_helper_with_property<Config>& g_) - { - typedef typename Config::global_edgelist_selector EdgeListS; - BOOST_STATIC_ASSERT((!is_same<EdgeListS, vecS>::value)); - - g_.remove_edge(e); - } - - template <class Config, class Predicate> - inline void - remove_out_edge_if(typename Config::vertex_descriptor u, Predicate pred, - bidirectional_graph_helper_with_property<Config>& g_) - { - typedef typename Config::global_edgelist_selector EdgeListS; - BOOST_STATIC_ASSERT((!is_same<EdgeListS, vecS>::value)); - - typedef typename Config::graph_type graph_type; - typedef typename Config::OutEdgeList::value_type::property_type PropT; - graph_type& g = static_cast<graph_type&>(g_); - - typedef typename Config::EdgeIter EdgeIter; - typedef std::vector<EdgeIter> Garbage; - Garbage garbage; - - // First remove the edges from the targets' in-edge lists and - // from the graph's edge set list. - typename Config::out_edge_iterator out_i, out_end; - for (boost::tie(out_i, out_end) = out_edges(u, g); out_i != out_end; ++out_i) - if (pred(*out_i)) { - detail::remove_directed_edge_dispatch - (*out_i, in_edge_list(g, target(*out_i, g)), - *(PropT*)(*out_i).get_property()); - // Put in garbage to delete later. Will need the properties - // for the remove_if of the out-edges. - garbage.push_back((*out_i.base()).get_iter()); +template < class Config, class Predicate > +inline void remove_out_edge_if(typename Config::vertex_descriptor u, + Predicate pred, bidirectional_graph_helper_with_property< Config >& g_) +{ + typedef typename Config::global_edgelist_selector EdgeListS; + BOOST_STATIC_ASSERT((!is_same< EdgeListS, vecS >::value)); + + typedef typename Config::graph_type graph_type; + typedef typename Config::OutEdgeList::value_type::property_type PropT; + graph_type& g = static_cast< graph_type& >(g_); + + typedef typename Config::EdgeIter EdgeIter; + typedef std::vector< EdgeIter > Garbage; + Garbage garbage; + + // First remove the edges from the targets' in-edge lists and + // from the graph's edge set list. + typename Config::out_edge_iterator out_i, out_end; + for (boost::tie(out_i, out_end) = out_edges(u, g); out_i != out_end; + ++out_i) + if (pred(*out_i)) + { + detail::remove_directed_edge_dispatch(*out_i, + in_edge_list(g, target(*out_i, g)), + *(PropT*)(*out_i).get_property()); + // Put in garbage to delete later. Will need the properties + // for the remove_if of the out-edges. + garbage.push_back((*out_i.base()).get_iter()); } - // Now remove the edges from this out-edge list. - typename Config::out_edge_iterator first, last; - boost::tie(first, last) = out_edges(u, g); - typedef typename Config::edge_parallel_category Cat; - detail::remove_directed_edge_if_dispatch - (first, last, g.out_edge_list(u), pred, Cat()); + // Now remove the edges from this out-edge list. + typename Config::out_edge_iterator first, last; + boost::tie(first, last) = out_edges(u, g); + typedef typename Config::edge_parallel_category Cat; + detail::remove_directed_edge_if_dispatch( + first, last, g.out_edge_list(u), pred, Cat()); - // Now delete the edge properties from the g.m_edges list - for (typename Garbage::iterator i = garbage.begin(); - i != garbage.end(); ++i) + // Now delete the edge properties from the g.m_edges list + for (typename Garbage::iterator i = garbage.begin(); i != garbage.end(); + ++i) g.m_edges.erase(*i); - } - template <class Config, class Predicate> - inline void - remove_in_edge_if(typename Config::vertex_descriptor v, Predicate pred, - bidirectional_graph_helper_with_property<Config>& g_) - { - typedef typename Config::global_edgelist_selector EdgeListS; - BOOST_STATIC_ASSERT((!is_same<EdgeListS, vecS>::value)); - - typedef typename Config::graph_type graph_type; - typedef typename Config::OutEdgeList::value_type::property_type PropT; - graph_type& g = static_cast<graph_type&>(g_); - - typedef typename Config::EdgeIter EdgeIter; - typedef std::vector<EdgeIter> Garbage; - Garbage garbage; - - // First remove the edges from the sources' out-edge lists and - // from the graph's edge set list. - typename Config::in_edge_iterator in_i, in_end; - for (boost::tie(in_i, in_end) = in_edges(v, g); in_i != in_end; ++in_i) - if (pred(*in_i)) { - typename Config::vertex_descriptor u = source(*in_i, g); - detail::remove_directed_edge_dispatch - (*in_i, g.out_edge_list(u), *(PropT*)(*in_i).get_property()); - // Put in garbage to delete later. Will need the properties - // for the remove_if of the out-edges. - garbage.push_back((*in_i.base()).get_iter()); +} +template < class Config, class Predicate > +inline void remove_in_edge_if(typename Config::vertex_descriptor v, + Predicate pred, bidirectional_graph_helper_with_property< Config >& g_) +{ + typedef typename Config::global_edgelist_selector EdgeListS; + BOOST_STATIC_ASSERT((!is_same< EdgeListS, vecS >::value)); + + typedef typename Config::graph_type graph_type; + typedef typename Config::OutEdgeList::value_type::property_type PropT; + graph_type& g = static_cast< graph_type& >(g_); + + typedef typename Config::EdgeIter EdgeIter; + typedef std::vector< EdgeIter > Garbage; + Garbage garbage; + + // First remove the edges from the sources' out-edge lists and + // from the graph's edge set list. + typename Config::in_edge_iterator in_i, in_end; + for (boost::tie(in_i, in_end) = in_edges(v, g); in_i != in_end; ++in_i) + if (pred(*in_i)) + { + typename Config::vertex_descriptor u = source(*in_i, g); + detail::remove_directed_edge_dispatch( + *in_i, g.out_edge_list(u), *(PropT*)(*in_i).get_property()); + // Put in garbage to delete later. Will need the properties + // for the remove_if of the out-edges. + garbage.push_back((*in_i.base()).get_iter()); } - // Now remove the edges from this in-edge list. - typename Config::in_edge_iterator first, last; - boost::tie(first, last) = in_edges(v, g); - typedef typename Config::edge_parallel_category Cat; - detail::remove_directed_edge_if_dispatch - (first, last, in_edge_list(g, v), pred, Cat()); - - // Now delete the edge properties from the g.m_edges list - for (typename Garbage::iterator i = garbage.begin(); - i != garbage.end(); ++i) + // Now remove the edges from this in-edge list. + typename Config::in_edge_iterator first, last; + boost::tie(first, last) = in_edges(v, g); + typedef typename Config::edge_parallel_category Cat; + detail::remove_directed_edge_if_dispatch( + first, last, in_edge_list(g, v), pred, Cat()); + + // Now delete the edge properties from the g.m_edges list + for (typename Garbage::iterator i = garbage.begin(); i != garbage.end(); + ++i) g.m_edges.erase(*i); - } +} - // O(1) - template <class Config> - inline typename Config::edges_size_type - num_edges(const bidirectional_graph_helper_with_property<Config>& g_) - { - typedef typename Config::graph_type graph_type; - const graph_type& g = static_cast<const graph_type&>(g_); - return g.m_edges.size(); - } - // O(E/V * E/V) for allow_parallel_edge_tag - // O(E/V * log(E/V)) for disallow_parallel_edge_tag - template <class Config> - inline void - clear_vertex(typename Config::vertex_descriptor u, - bidirectional_graph_helper_with_property<Config>& g_) - { - typedef typename Config::global_edgelist_selector EdgeListS; - BOOST_STATIC_ASSERT((!is_same<EdgeListS, vecS>::value)); - - typedef typename Config::graph_type graph_type; - typedef typename Config::edge_parallel_category Cat; - graph_type& g = static_cast<graph_type&>(g_); - typename Config::OutEdgeList& el = g.out_edge_list(u); - typename Config::OutEdgeList::iterator - ei = el.begin(), ei_end = el.end(); - for (; ei != ei_end; ++ei) { - detail::erase_from_incidence_list - (in_edge_list(g, (*ei).get_target()), u, Cat()); +// O(1) +template < class Config > +inline typename Config::edges_size_type num_edges( + const bidirectional_graph_helper_with_property< Config >& g_) +{ + typedef typename Config::graph_type graph_type; + const graph_type& g = static_cast< const graph_type& >(g_); + return g.m_edges.size(); +} +// O(E/V * E/V) for allow_parallel_edge_tag +// O(E/V * log(E/V)) for disallow_parallel_edge_tag +template < class Config > +inline void clear_vertex(typename Config::vertex_descriptor u, + bidirectional_graph_helper_with_property< Config >& g_) +{ + typedef typename Config::global_edgelist_selector EdgeListS; + BOOST_STATIC_ASSERT((!is_same< EdgeListS, vecS >::value)); + + typedef typename Config::graph_type graph_type; + typedef typename Config::edge_parallel_category Cat; + graph_type& g = static_cast< graph_type& >(g_); + typename Config::OutEdgeList& el = g.out_edge_list(u); + typename Config::OutEdgeList::iterator ei = el.begin(), ei_end = el.end(); + for (; ei != ei_end; ++ei) + { + detail::erase_from_incidence_list( + in_edge_list(g, (*ei).get_target()), u, Cat()); g.m_edges.erase((*ei).get_iter()); - } - typename Config::InEdgeList& in_el = in_edge_list(g, u); - typename Config::InEdgeList::iterator - in_ei = in_el.begin(), in_ei_end = in_el.end(); - for (; in_ei != in_ei_end; ++in_ei) { - detail::erase_from_incidence_list - (g.out_edge_list((*in_ei).get_target()), u, Cat()); + } + typename Config::InEdgeList& in_el = in_edge_list(g, u); + typename Config::InEdgeList::iterator in_ei = in_el.begin(), + in_ei_end = in_el.end(); + for (; in_ei != in_ei_end; ++in_ei) + { + detail::erase_from_incidence_list( + g.out_edge_list((*in_ei).get_target()), u, Cat()); g.m_edges.erase((*in_ei).get_iter()); - } - g.out_edge_list(u).clear(); - in_edge_list(g, u).clear(); - } - - template <class Config> - inline void - clear_out_edges(typename Config::vertex_descriptor u, - bidirectional_graph_helper_with_property<Config>& g_) - { - typedef typename Config::global_edgelist_selector EdgeListS; - BOOST_STATIC_ASSERT((!is_same<EdgeListS, vecS>::value)); - - typedef typename Config::graph_type graph_type; - typedef typename Config::edge_parallel_category Cat; - graph_type& g = static_cast<graph_type&>(g_); - typename Config::OutEdgeList& el = g.out_edge_list(u); - typename Config::OutEdgeList::iterator - ei = el.begin(), ei_end = el.end(); - for (; ei != ei_end; ++ei) { - detail::erase_from_incidence_list - (in_edge_list(g, (*ei).get_target()), u, Cat()); + } + g.out_edge_list(u).clear(); + in_edge_list(g, u).clear(); +} + +template < class Config > +inline void clear_out_edges(typename Config::vertex_descriptor u, + bidirectional_graph_helper_with_property< Config >& g_) +{ + typedef typename Config::global_edgelist_selector EdgeListS; + BOOST_STATIC_ASSERT((!is_same< EdgeListS, vecS >::value)); + + typedef typename Config::graph_type graph_type; + typedef typename Config::edge_parallel_category Cat; + graph_type& g = static_cast< graph_type& >(g_); + typename Config::OutEdgeList& el = g.out_edge_list(u); + typename Config::OutEdgeList::iterator ei = el.begin(), ei_end = el.end(); + for (; ei != ei_end; ++ei) + { + detail::erase_from_incidence_list( + in_edge_list(g, (*ei).get_target()), u, Cat()); g.m_edges.erase((*ei).get_iter()); - } - g.out_edge_list(u).clear(); - } - - template <class Config> - inline void - clear_in_edges(typename Config::vertex_descriptor u, - bidirectional_graph_helper_with_property<Config>& g_) - { - typedef typename Config::global_edgelist_selector EdgeListS; - BOOST_STATIC_ASSERT((!is_same<EdgeListS, vecS>::value)); - - typedef typename Config::graph_type graph_type; - typedef typename Config::edge_parallel_category Cat; - graph_type& g = static_cast<graph_type&>(g_); - typename Config::InEdgeList& in_el = in_edge_list(g, u); - typename Config::InEdgeList::iterator - in_ei = in_el.begin(), in_ei_end = in_el.end(); - for (; in_ei != in_ei_end; ++in_ei) { - detail::erase_from_incidence_list - (g.out_edge_list((*in_ei).get_target()), u, Cat()); + } + g.out_edge_list(u).clear(); +} + +template < class Config > +inline void clear_in_edges(typename Config::vertex_descriptor u, + bidirectional_graph_helper_with_property< Config >& g_) +{ + typedef typename Config::global_edgelist_selector EdgeListS; + BOOST_STATIC_ASSERT((!is_same< EdgeListS, vecS >::value)); + + typedef typename Config::graph_type graph_type; + typedef typename Config::edge_parallel_category Cat; + graph_type& g = static_cast< graph_type& >(g_); + typename Config::InEdgeList& in_el = in_edge_list(g, u); + typename Config::InEdgeList::iterator in_ei = in_el.begin(), + in_ei_end = in_el.end(); + for (; in_ei != in_ei_end; ++in_ei) + { + detail::erase_from_incidence_list( + g.out_edge_list((*in_ei).get_target()), u, Cat()); g.m_edges.erase((*in_ei).get_iter()); - } - in_edge_list(g, u).clear(); - } - - // O(1) for allow_parallel_edge_tag - // O(log(E/V)) for disallow_parallel_edge_tag - template <class Config> - inline std::pair<typename Config::edge_descriptor, bool> - add_edge(typename Config::vertex_descriptor u, - typename Config::vertex_descriptor v, - const typename Config::edge_property_type& p, - bidirectional_graph_helper_with_property<Config>& g_) - { - typedef typename Config::graph_type graph_type; - graph_type& g = static_cast<graph_type&>(g_); - typedef typename Config::edge_descriptor edge_descriptor; - typedef typename Config::StoredEdge StoredEdge; - bool inserted; - typename Config::EdgeContainer::value_type e(u, v, p); - typename Config::EdgeContainer::iterator p_iter - = graph_detail::push(g.m_edges, e).first; - typename Config::OutEdgeList::iterator i; - boost::tie(i, inserted) = boost::graph_detail::push(g.out_edge_list(u), - StoredEdge(v, p_iter, &g.m_edges)); - if (inserted) { - boost::graph_detail::push(in_edge_list(g, v), StoredEdge(u, p_iter, &g.m_edges)); - return std::make_pair(edge_descriptor(u, v, &p_iter->m_property), - true); - } else { - g.m_edges.erase(p_iter); - return std::make_pair(edge_descriptor(u, v, - &i->get_iter()->get_property()), - false); - } } + in_edge_list(g, u).clear(); +} - template <class Config> - inline std::pair<typename Config::edge_descriptor, bool> - add_edge(typename Config::vertex_descriptor u, - typename Config::vertex_descriptor v, - bidirectional_graph_helper_with_property<Config>& g_) +// O(1) for allow_parallel_edge_tag +// O(log(E/V)) for disallow_parallel_edge_tag +template < class Config > +inline std::pair< typename Config::edge_descriptor, bool > add_edge( + typename Config::vertex_descriptor u, typename Config::vertex_descriptor v, + const typename Config::edge_property_type& p, + bidirectional_graph_helper_with_property< Config >& g_) +{ + typedef typename Config::graph_type graph_type; + graph_type& g = static_cast< graph_type& >(g_); + typedef typename Config::edge_descriptor edge_descriptor; + typedef typename Config::StoredEdge StoredEdge; + bool inserted; + typename Config::EdgeContainer::value_type e(u, v, p); + typename Config::EdgeContainer::iterator p_iter + = graph_detail::push(g.m_edges, e).first; + typename Config::OutEdgeList::iterator i; + boost::tie(i, inserted) = boost::graph_detail::push( + g.out_edge_list(u), StoredEdge(v, p_iter, &g.m_edges)); + if (inserted) { - typename Config::edge_property_type p; - return add_edge(u, v, p, g_); + boost::graph_detail::push( + in_edge_list(g, v), StoredEdge(u, p_iter, &g.m_edges)); + return std::make_pair(edge_descriptor(u, v, &p_iter->m_property), true); } - // O(1) - template <class Config> - inline typename Config::degree_size_type - degree(typename Config::vertex_descriptor u, - const bidirectional_graph_helper_with_property<Config>& g_) + else { - typedef typename Config::graph_type graph_type; - const graph_type& g = static_cast<const graph_type&>(g_); - return in_degree(u, g) + out_degree(u, g); + g.m_edges.erase(p_iter); + return std::make_pair( + edge_descriptor(u, v, &i->get_iter()->get_property()), false); } +} - //========================================================================= - // Adjacency List Helper Class - - template <class Config, class Base> - struct adj_list_helper : public Base - { - typedef typename Config::graph_type AdjList; - typedef typename Config::vertex_descriptor vertex_descriptor; - typedef typename Config::edge_descriptor edge_descriptor; - typedef typename Config::out_edge_iterator out_edge_iterator; - typedef typename Config::in_edge_iterator in_edge_iterator; - typedef typename Config::adjacency_iterator adjacency_iterator; - typedef typename Config::inv_adjacency_iterator inv_adjacency_iterator; - typedef typename Config::vertex_iterator vertex_iterator; - typedef typename Config::edge_iterator edge_iterator; - typedef typename Config::directed_category directed_category; - typedef typename Config::edge_parallel_category edge_parallel_category; - typedef typename Config::vertices_size_type vertices_size_type; - typedef typename Config::edges_size_type edges_size_type; - typedef typename Config::degree_size_type degree_size_type; - typedef typename Config::StoredEdge StoredEdge; - typedef typename Config::vertex_property_type vertex_property_type; - typedef typename Config::edge_property_type edge_property_type; - typedef typename Config::graph_property_type graph_property_type; - - typedef typename Config::global_edgelist_selector - global_edgelist_selector; - - typedef typename lookup_one_property<vertex_property_type, vertex_bundle_t>::type vertex_bundled; - typedef typename lookup_one_property<edge_property_type, edge_bundle_t>::type edge_bundled; - typedef typename lookup_one_property<graph_property_type, graph_bundle_t>::type graph_bundled; - }; +template < class Config > +inline std::pair< typename Config::edge_descriptor, bool > add_edge( + typename Config::vertex_descriptor u, typename Config::vertex_descriptor v, + bidirectional_graph_helper_with_property< Config >& g_) +{ + typename Config::edge_property_type p; + return add_edge(u, v, p, g_); +} +// O(1) +template < class Config > +inline typename Config::degree_size_type degree( + typename Config::vertex_descriptor u, + const bidirectional_graph_helper_with_property< Config >& g_) +{ + typedef typename Config::graph_type graph_type; + const graph_type& g = static_cast< const graph_type& >(g_); + return in_degree(u, g) + out_degree(u, g); +} - template <class Config, class Base> - inline std::pair<typename Config::adjacency_iterator, - typename Config::adjacency_iterator> - adjacent_vertices(typename Config::vertex_descriptor u, - const adj_list_helper<Config, Base>& g_) - { - typedef typename Config::graph_type AdjList; - const AdjList& cg = static_cast<const AdjList&>(g_); - AdjList& g = const_cast<AdjList&>(cg); - typedef typename Config::adjacency_iterator adjacency_iterator; - typename Config::out_edge_iterator first, last; - boost::tie(first, last) = out_edges(u, g); - return std::make_pair(adjacency_iterator(first, &g), - adjacency_iterator(last, &g)); - } - template <class Config, class Base> - inline std::pair<typename Config::inv_adjacency_iterator, - typename Config::inv_adjacency_iterator> - inv_adjacent_vertices(typename Config::vertex_descriptor u, - const adj_list_helper<Config, Base>& g_) - { - typedef typename Config::graph_type AdjList; - const AdjList& cg = static_cast<const AdjList&>(g_); - AdjList& g = const_cast<AdjList&>(cg); - typedef typename Config::inv_adjacency_iterator inv_adjacency_iterator; - typename Config::in_edge_iterator first, last; - boost::tie(first, last) = in_edges(u, g); - return std::make_pair(inv_adjacency_iterator(first, &g), - inv_adjacency_iterator(last, &g)); - } - template <class Config, class Base> - inline std::pair<typename Config::out_edge_iterator, - typename Config::out_edge_iterator> - out_edges(typename Config::vertex_descriptor u, - const adj_list_helper<Config, Base>& g_) - { - typedef typename Config::graph_type AdjList; - typedef typename Config::out_edge_iterator out_edge_iterator; - const AdjList& cg = static_cast<const AdjList&>(g_); - AdjList& g = const_cast<AdjList&>(cg); - return - std::make_pair(out_edge_iterator(g.out_edge_list(u).begin(), u), - out_edge_iterator(g.out_edge_list(u).end(), u)); - } - template <class Config, class Base> - inline std::pair<typename Config::vertex_iterator, - typename Config::vertex_iterator> - vertices(const adj_list_helper<Config, Base>& g_) - { - typedef typename Config::graph_type AdjList; - const AdjList& cg = static_cast<const AdjList&>(g_); - AdjList& g = const_cast<AdjList&>(cg); - return std::make_pair( g.vertex_set().begin(), g.vertex_set().end() ); - } - template <class Config, class Base> - inline typename Config::vertices_size_type - num_vertices(const adj_list_helper<Config, Base>& g_) - { - typedef typename Config::graph_type AdjList; - const AdjList& g = static_cast<const AdjList&>(g_); - return g.vertex_set().size(); - } - template <class Config, class Base> - inline typename Config::degree_size_type - out_degree(typename Config::vertex_descriptor u, - const adj_list_helper<Config, Base>& g_) - { - typedef typename Config::graph_type AdjList; - const AdjList& g = static_cast<const AdjList&>(g_); - return g.out_edge_list(u).size(); - } - template <class Config, class Base> - inline std::pair<typename Config::edge_descriptor, bool> - edge(typename Config::vertex_descriptor u, - typename Config::vertex_descriptor v, - const adj_list_helper<Config, Base>& g_) - { - typedef typename Config::graph_type Graph; - typedef typename Config::StoredEdge StoredEdge; - const Graph& cg = static_cast<const Graph&>(g_); - const typename Config::OutEdgeList& el = cg.out_edge_list(u); - typename Config::OutEdgeList::const_iterator it = graph_detail:: - find(el, StoredEdge(v)); - return std::make_pair( - typename Config::edge_descriptor - (u, v, (it == el.end() ? 0 : &(*it).get_property())), - (it != el.end())); - } - - template <class Config, class Base> - inline std::pair<typename Config::out_edge_iterator, - typename Config::out_edge_iterator> - edge_range(typename Config::vertex_descriptor u, - typename Config::vertex_descriptor v, - const adj_list_helper<Config, Base>& g_) - { - typedef typename Config::graph_type Graph; - typedef typename Config::StoredEdge StoredEdge; - const Graph& cg = static_cast<const Graph&>(g_); - Graph& g = const_cast<Graph&>(cg); - typedef typename Config::out_edge_iterator out_edge_iterator; - typename Config::OutEdgeList& el = g.out_edge_list(u); - typename Config::OutEdgeList::iterator first, last; - typename Config::EdgeContainer fake_edge_container; - boost::tie(first, last) = graph_detail:: - equal_range(el, StoredEdge(v)); - return std::make_pair(out_edge_iterator(first, u), - out_edge_iterator(last, u)); - } - - template <class Config> - inline typename Config::degree_size_type - in_degree(typename Config::vertex_descriptor u, - const directed_edges_helper<Config>& g_) - { - typedef typename Config::graph_type Graph; - const Graph& cg = static_cast<const Graph&>(g_); - Graph& g = const_cast<Graph&>(cg); - return in_edge_list(g, u).size(); - } - - namespace detail { - template <class Config, class Base, class Property> - inline - typename boost::property_map<typename Config::graph_type, - Property>::type - get_dispatch(adj_list_helper<Config,Base>&, Property p, - boost::edge_property_tag) { +//========================================================================= +// Adjacency List Helper Class + +template < class Config, class Base > struct adj_list_helper : public Base +{ + typedef typename Config::graph_type AdjList; + typedef typename Config::vertex_descriptor vertex_descriptor; + typedef typename Config::edge_descriptor edge_descriptor; + typedef typename Config::out_edge_iterator out_edge_iterator; + typedef typename Config::in_edge_iterator in_edge_iterator; + typedef typename Config::adjacency_iterator adjacency_iterator; + typedef typename Config::inv_adjacency_iterator inv_adjacency_iterator; + typedef typename Config::vertex_iterator vertex_iterator; + typedef typename Config::edge_iterator edge_iterator; + typedef typename Config::directed_category directed_category; + typedef typename Config::edge_parallel_category edge_parallel_category; + typedef typename Config::vertices_size_type vertices_size_type; + typedef typename Config::edges_size_type edges_size_type; + typedef typename Config::degree_size_type degree_size_type; + typedef typename Config::StoredEdge StoredEdge; + typedef typename Config::vertex_property_type vertex_property_type; + typedef typename Config::edge_property_type edge_property_type; + typedef typename Config::graph_property_type graph_property_type; + + typedef typename Config::global_edgelist_selector global_edgelist_selector; + + typedef typename lookup_one_property< vertex_property_type, + vertex_bundle_t >::type vertex_bundled; + typedef + typename lookup_one_property< edge_property_type, edge_bundle_t >::type + edge_bundled; + typedef typename lookup_one_property< graph_property_type, + graph_bundle_t >::type graph_bundled; +}; + +template < class Config, class Base > +inline std::pair< typename Config::adjacency_iterator, + typename Config::adjacency_iterator > +adjacent_vertices(typename Config::vertex_descriptor u, + const adj_list_helper< Config, Base >& g_) +{ + typedef typename Config::graph_type AdjList; + const AdjList& cg = static_cast< const AdjList& >(g_); + AdjList& g = const_cast< AdjList& >(cg); + typedef typename Config::adjacency_iterator adjacency_iterator; + typename Config::out_edge_iterator first, last; + boost::tie(first, last) = out_edges(u, g); + return std::make_pair( + adjacency_iterator(first, &g), adjacency_iterator(last, &g)); +} +template < class Config, class Base > +inline std::pair< typename Config::inv_adjacency_iterator, + typename Config::inv_adjacency_iterator > +inv_adjacent_vertices(typename Config::vertex_descriptor u, + const adj_list_helper< Config, Base >& g_) +{ + typedef typename Config::graph_type AdjList; + const AdjList& cg = static_cast< const AdjList& >(g_); + AdjList& g = const_cast< AdjList& >(cg); + typedef typename Config::inv_adjacency_iterator inv_adjacency_iterator; + typename Config::in_edge_iterator first, last; + boost::tie(first, last) = in_edges(u, g); + return std::make_pair( + inv_adjacency_iterator(first, &g), inv_adjacency_iterator(last, &g)); +} +template < class Config, class Base > +inline std::pair< typename Config::out_edge_iterator, + typename Config::out_edge_iterator > +out_edges(typename Config::vertex_descriptor u, + const adj_list_helper< Config, Base >& g_) +{ + typedef typename Config::graph_type AdjList; + typedef typename Config::out_edge_iterator out_edge_iterator; + const AdjList& cg = static_cast< const AdjList& >(g_); + AdjList& g = const_cast< AdjList& >(cg); + return std::make_pair(out_edge_iterator(g.out_edge_list(u).begin(), u), + out_edge_iterator(g.out_edge_list(u).end(), u)); +} +template < class Config, class Base > +inline std::pair< typename Config::vertex_iterator, + typename Config::vertex_iterator > +vertices(const adj_list_helper< Config, Base >& g_) +{ + typedef typename Config::graph_type AdjList; + const AdjList& cg = static_cast< const AdjList& >(g_); + AdjList& g = const_cast< AdjList& >(cg); + return std::make_pair(g.vertex_set().begin(), g.vertex_set().end()); +} +template < class Config, class Base > +inline typename Config::vertices_size_type num_vertices( + const adj_list_helper< Config, Base >& g_) +{ + typedef typename Config::graph_type AdjList; + const AdjList& g = static_cast< const AdjList& >(g_); + return g.vertex_set().size(); +} +template < class Config, class Base > +inline typename Config::degree_size_type out_degree( + typename Config::vertex_descriptor u, + const adj_list_helper< Config, Base >& g_) +{ + typedef typename Config::graph_type AdjList; + const AdjList& g = static_cast< const AdjList& >(g_); + return g.out_edge_list(u).size(); +} +template < class Config, class Base > +inline std::pair< typename Config::edge_descriptor, bool > edge( + typename Config::vertex_descriptor u, typename Config::vertex_descriptor v, + const adj_list_helper< Config, Base >& g_) +{ + typedef typename Config::graph_type Graph; + typedef typename Config::StoredEdge StoredEdge; + const Graph& cg = static_cast< const Graph& >(g_); + const typename Config::OutEdgeList& el = cg.out_edge_list(u); + typename Config::OutEdgeList::const_iterator it + = graph_detail::find(el, StoredEdge(v)); + return std::make_pair(typename Config::edge_descriptor(u, v, + (it == el.end() ? 0 : &(*it).get_property())), + (it != el.end())); +} + +template < class Config, class Base > +inline std::pair< typename Config::out_edge_iterator, + typename Config::out_edge_iterator > +edge_range(typename Config::vertex_descriptor u, + typename Config::vertex_descriptor v, + const adj_list_helper< Config, Base >& g_) +{ + typedef typename Config::graph_type Graph; + typedef typename Config::StoredEdge StoredEdge; + const Graph& cg = static_cast< const Graph& >(g_); + Graph& g = const_cast< Graph& >(cg); + typedef typename Config::out_edge_iterator out_edge_iterator; + typename Config::OutEdgeList& el = g.out_edge_list(u); + typename Config::OutEdgeList::iterator first, last; + typename Config::EdgeContainer fake_edge_container; + boost::tie(first, last) = graph_detail::equal_range(el, StoredEdge(v)); + return std::make_pair( + out_edge_iterator(first, u), out_edge_iterator(last, u)); +} + +template < class Config > +inline typename Config::degree_size_type in_degree( + typename Config::vertex_descriptor u, + const directed_edges_helper< Config >& g_) +{ + typedef typename Config::graph_type Graph; + const Graph& cg = static_cast< const Graph& >(g_); + Graph& g = const_cast< Graph& >(cg); + return in_edge_list(g, u).size(); +} + +namespace detail +{ + template < class Config, class Base, class Property > + inline typename boost::property_map< typename Config::graph_type, + Property >::type + get_dispatch( + adj_list_helper< Config, Base >&, Property p, boost::edge_property_tag) + { typedef typename Config::graph_type Graph; - typedef typename boost::property_map<Graph, Property>::type PA; + typedef typename boost::property_map< Graph, Property >::type PA; return PA(p); - } - template <class Config, class Base, class Property> - inline - typename boost::property_map<typename Config::graph_type, - Property>::const_type - get_dispatch(const adj_list_helper<Config,Base>&, Property p, - boost::edge_property_tag) { + } + template < class Config, class Base, class Property > + inline typename boost::property_map< typename Config::graph_type, + Property >::const_type + get_dispatch(const adj_list_helper< Config, Base >&, Property p, + boost::edge_property_tag) + { typedef typename Config::graph_type Graph; - typedef typename boost::property_map<Graph, Property>::const_type PA; + typedef typename boost::property_map< Graph, Property >::const_type PA; return PA(p); - } - - template <class Config, class Base, class Property> - inline - typename boost::property_map<typename Config::graph_type, - Property>::type - get_dispatch(adj_list_helper<Config,Base>& g, Property p, - boost::vertex_property_tag) { + } + + template < class Config, class Base, class Property > + inline typename boost::property_map< typename Config::graph_type, + Property >::type + get_dispatch(adj_list_helper< Config, Base >& g, Property p, + boost::vertex_property_tag) + { typedef typename Config::graph_type Graph; - typedef typename boost::property_map<Graph, Property>::type PA; - return PA(&static_cast<Graph&>(g), p); - } - template <class Config, class Base, class Property> - inline - typename boost::property_map<typename Config::graph_type, - Property>::const_type - get_dispatch(const adj_list_helper<Config, Base>& g, Property p, - boost::vertex_property_tag) { + typedef typename boost::property_map< Graph, Property >::type PA; + return PA(&static_cast< Graph& >(g), p); + } + template < class Config, class Base, class Property > + inline typename boost::property_map< typename Config::graph_type, + Property >::const_type + get_dispatch(const adj_list_helper< Config, Base >& g, Property p, + boost::vertex_property_tag) + { typedef typename Config::graph_type Graph; - typedef typename boost::property_map<Graph, Property>::const_type PA; - const Graph& cg = static_cast<const Graph&>(g); + typedef typename boost::property_map< Graph, Property >::const_type PA; + const Graph& cg = static_cast< const Graph& >(g); return PA(&cg, p); - } - - } // namespace detail - - // Implementation of the PropertyGraph interface - template <class Config, class Base, class Property> - inline - typename boost::property_map<typename Config::graph_type, Property>::type - get(Property p, adj_list_helper<Config, Base>& g) { - typedef typename detail::property_kind_from_graph<adj_list_helper<Config, Base>, Property>::type Kind; - return detail::get_dispatch(g, p, Kind()); - } - template <class Config, class Base, class Property> - inline - typename boost::property_map<typename Config::graph_type, - Property>::const_type - get(Property p, const adj_list_helper<Config, Base>& g) { - typedef typename detail::property_kind_from_graph<adj_list_helper<Config, Base>, Property>::type Kind; - return detail::get_dispatch(g, p, Kind()); } - template <class Config, class Base, class Property, class Key> - inline - typename boost::property_traits< - typename boost::property_map<typename Config::graph_type, - Property>::type - >::reference - get(Property p, adj_list_helper<Config, Base>& g, const Key& key) { - return get(get(p, g), key); - } +} // namespace detail - template <class Config, class Base, class Property, class Key> - inline - typename boost::property_traits< - typename boost::property_map<typename Config::graph_type, - Property>::const_type - >::reference - get(Property p, const adj_list_helper<Config, Base>& g, const Key& key) { - return get(get(p, g), key); - } - - template <class Config, class Base, class Property, class Key,class Value> - inline void - put(Property p, adj_list_helper<Config, Base>& g, - const Key& key, const Value& value) - { - typedef typename Config::graph_type Graph; - typedef typename boost::property_map<Graph, Property>::type Map; - Map pmap = get(p, static_cast<Graph&>(g)); - put(pmap, key, value); - } +// Implementation of the PropertyGraph interface +template < class Config, class Base, class Property > +inline + typename boost::property_map< typename Config::graph_type, Property >::type + get(Property p, adj_list_helper< Config, Base >& g) +{ + typedef typename detail::property_kind_from_graph< + adj_list_helper< Config, Base >, Property >::type Kind; + return detail::get_dispatch(g, p, Kind()); +} +template < class Config, class Base, class Property > +inline typename boost::property_map< typename Config::graph_type, + Property >::const_type +get(Property p, const adj_list_helper< Config, Base >& g) +{ + typedef typename detail::property_kind_from_graph< + adj_list_helper< Config, Base >, Property >::type Kind; + return detail::get_dispatch(g, p, Kind()); +} +template < class Config, class Base, class Property, class Key > +inline typename boost::property_traits< typename boost::property_map< + typename Config::graph_type, Property >::type >::reference +get(Property p, adj_list_helper< Config, Base >& g, const Key& key) +{ + return get(get(p, g), key); +} - //========================================================================= - // Generalize Adjacency List Implementation +template < class Config, class Base, class Property, class Key > +inline typename boost::property_traits< typename boost::property_map< + typename Config::graph_type, Property >::const_type >::reference +get(Property p, const adj_list_helper< Config, Base >& g, const Key& key) +{ + return get(get(p, g), key); +} - struct adj_list_tag { }; +template < class Config, class Base, class Property, class Key, class Value > +inline void put(Property p, adj_list_helper< Config, Base >& g, const Key& key, + const Value& value) +{ + typedef typename Config::graph_type Graph; + typedef typename boost::property_map< Graph, Property >::type Map; + Map pmap = get(p, static_cast< Graph& >(g)); + put(pmap, key, value); +} - template <class Derived, class Config, class Base> - class adj_list_impl - : public adj_list_helper<Config, Base> +//========================================================================= +// Generalize Adjacency List Implementation + +struct adj_list_tag +{ +}; + +template < class Derived, class Config, class Base > +class adj_list_impl : public adj_list_helper< Config, Base > +{ + typedef typename Config::OutEdgeList OutEdgeList; + typedef typename Config::InEdgeList InEdgeList; + typedef typename Config::StoredVertexList StoredVertexList; + +public: + typedef typename Config::stored_vertex stored_vertex; + typedef typename Config::EdgeContainer EdgeContainer; + typedef typename Config::vertex_descriptor vertex_descriptor; + typedef typename Config::edge_descriptor edge_descriptor; + typedef typename Config::vertex_iterator vertex_iterator; + typedef typename Config::edge_iterator edge_iterator; + typedef typename Config::edge_parallel_category edge_parallel_category; + typedef typename Config::vertices_size_type vertices_size_type; + typedef typename Config::edges_size_type edges_size_type; + typedef typename Config::degree_size_type degree_size_type; + typedef typename Config::edge_property_type edge_property_type; + typedef adj_list_tag graph_tag; + + static vertex_descriptor null_vertex() { return 0; } + + inline adj_list_impl() {} + + inline adj_list_impl(const adj_list_impl& x) { copy_impl(x); } + inline adj_list_impl& operator=(const adj_list_impl& x) { - typedef typename Config::OutEdgeList OutEdgeList; - typedef typename Config::InEdgeList InEdgeList; - typedef typename Config::StoredVertexList StoredVertexList; - public: - typedef typename Config::stored_vertex stored_vertex; - typedef typename Config::EdgeContainer EdgeContainer; - typedef typename Config::vertex_descriptor vertex_descriptor; - typedef typename Config::edge_descriptor edge_descriptor; - typedef typename Config::vertex_iterator vertex_iterator; - typedef typename Config::edge_iterator edge_iterator; - typedef typename Config::edge_parallel_category edge_parallel_category; - typedef typename Config::vertices_size_type vertices_size_type; - typedef typename Config::edges_size_type edges_size_type; - typedef typename Config::degree_size_type degree_size_type; - typedef typename Config::edge_property_type edge_property_type; - typedef adj_list_tag graph_tag; - - static vertex_descriptor null_vertex() - { - return 0; - } - - inline adj_list_impl() { } - - inline adj_list_impl(const adj_list_impl& x) { - copy_impl(x); - } - inline adj_list_impl& operator=(const adj_list_impl& x) { this->clear(); copy_impl(x); return *this; - } - inline void clear() { + } + inline void clear() + { for (typename StoredVertexList::iterator i = m_vertices.begin(); i != m_vertices.end(); ++i) - delete (stored_vertex*)*i; + delete (stored_vertex*)*i; m_vertices.clear(); m_edges.clear(); - } - inline adj_list_impl(vertices_size_type num_vertices) { + } + inline adj_list_impl(vertices_size_type num_vertices) + { for (vertices_size_type i = 0; i < num_vertices; ++i) - add_vertex(static_cast<Derived&>(*this)); - } - template <class EdgeIterator> - inline adj_list_impl(vertices_size_type num_vertices, - EdgeIterator first, EdgeIterator last) - { + add_vertex(static_cast< Derived& >(*this)); + } + template < class EdgeIterator > + inline adj_list_impl( + vertices_size_type num_vertices, EdgeIterator first, EdgeIterator last) + { vertex_descriptor* v = new vertex_descriptor[num_vertices]; for (vertices_size_type i = 0; i < num_vertices; ++i) - v[i] = add_vertex(static_cast<Derived&>(*this)); + v[i] = add_vertex(static_cast< Derived& >(*this)); - while (first != last) { - add_edge(v[(*first).first], v[(*first).second], *this); - ++first; + while (first != last) + { + add_edge(v[(*first).first], v[(*first).second], *this); + ++first; } - delete [] v; - } - template <class EdgeIterator, class EdgePropertyIterator> - inline adj_list_impl(vertices_size_type num_vertices, - EdgeIterator first, EdgeIterator last, - EdgePropertyIterator ep_iter) - { + delete[] v; + } + template < class EdgeIterator, class EdgePropertyIterator > + inline adj_list_impl(vertices_size_type num_vertices, EdgeIterator first, + EdgeIterator last, EdgePropertyIterator ep_iter) + { vertex_descriptor* v = new vertex_descriptor[num_vertices]; for (vertices_size_type i = 0; i < num_vertices; ++i) - v[i] = add_vertex(static_cast<Derived&>(*this)); + v[i] = add_vertex(static_cast< Derived& >(*this)); - while (first != last) { - add_edge(v[(*first).first], v[(*first).second], *ep_iter, *this); - ++first; - ++ep_iter; + while (first != last) + { + add_edge(v[(*first).first], v[(*first).second], *ep_iter, *this); + ++first; + ++ep_iter; } - delete [] v; - } - ~adj_list_impl() { + delete[] v; + } + ~adj_list_impl() + { for (typename StoredVertexList::iterator i = m_vertices.begin(); i != m_vertices.end(); ++i) - delete (stored_vertex*)*i; - } - // protected: - inline OutEdgeList& out_edge_list(vertex_descriptor v) { + delete (stored_vertex*)*i; + } + // protected: + inline OutEdgeList& out_edge_list(vertex_descriptor v) + { stored_vertex* sv = (stored_vertex*)v; return sv->m_out_edges; - } - inline const OutEdgeList& out_edge_list(vertex_descriptor v) const { + } + inline const OutEdgeList& out_edge_list(vertex_descriptor v) const + { stored_vertex* sv = (stored_vertex*)v; return sv->m_out_edges; - } - inline StoredVertexList& vertex_set() { return m_vertices; } - inline const StoredVertexList& vertex_set() const { return m_vertices; } + } + inline StoredVertexList& vertex_set() { return m_vertices; } + inline const StoredVertexList& vertex_set() const { return m_vertices; } - inline void copy_impl(const adj_list_impl& x_) - { - const Derived& x = static_cast<const Derived&>(x_); + inline void copy_impl(const adj_list_impl& x_) + { + const Derived& x = static_cast< const Derived& >(x_); // Would be better to have a constant time way to get from // vertices in x to the corresponding vertices in *this. - std::map<stored_vertex*,stored_vertex*> vertex_map; + std::map< stored_vertex*, stored_vertex* > vertex_map; // Copy the stored vertex objects by adding each vertex // and copying its property object. vertex_iterator vi, vi_end; - for (boost::tie(vi, vi_end) = vertices(x); vi != vi_end; ++vi) { - stored_vertex* v = (stored_vertex*)add_vertex(*this); - v->m_property = ((stored_vertex*)*vi)->m_property; - vertex_map[(stored_vertex*)*vi] = v; + for (boost::tie(vi, vi_end) = vertices(x); vi != vi_end; ++vi) + { + stored_vertex* v = (stored_vertex*)add_vertex(*this); + v->m_property = ((stored_vertex*)*vi)->m_property; + vertex_map[(stored_vertex*)*vi] = v; } // Copy the edges by adding each edge and copying its // property object. edge_iterator ei, ei_end; - for (boost::tie(ei, ei_end) = edges(x); ei != ei_end; ++ei) { - edge_descriptor e; - bool inserted; - vertex_descriptor s = source(*ei,x), t = target(*ei,x); - boost::tie(e, inserted) = add_edge(vertex_map[(stored_vertex*)s], - vertex_map[(stored_vertex*)t], *this); - *((edge_property_type*)e.m_eproperty) - = *((edge_property_type*)(*ei).m_eproperty); + for (boost::tie(ei, ei_end) = edges(x); ei != ei_end; ++ei) + { + edge_descriptor e; + bool inserted; + vertex_descriptor s = source(*ei, x), t = target(*ei, x); + boost::tie(e, inserted) = add_edge(vertex_map[(stored_vertex*)s], + vertex_map[(stored_vertex*)t], *this); + *((edge_property_type*)e.m_eproperty) + = *((edge_property_type*)(*ei).m_eproperty); } - } - - - typename Config::EdgeContainer m_edges; - StoredVertexList m_vertices; - }; - - // O(1) - template <class Derived, class Config, class Base> - inline typename Config::vertex_descriptor - add_vertex(adj_list_impl<Derived, Config, Base>& g_) - { - Derived& g = static_cast<Derived&>(g_); - typedef typename Config::stored_vertex stored_vertex; - stored_vertex* v = new stored_vertex; - typename Config::StoredVertexList::iterator pos; - bool inserted; - boost::tie(pos,inserted) = boost::graph_detail::push(g.m_vertices, v); - v->m_position = pos; - g.added_vertex(v); - return v; } - // O(1) - template <class Derived, class Config, class Base> - inline typename Config::vertex_descriptor - add_vertex(const typename Config::vertex_property_type& p, - adj_list_impl<Derived, Config, Base>& g_) - { - typedef typename Config::vertex_descriptor vertex_descriptor; - Derived& g = static_cast<Derived&>(g_); - if (optional<vertex_descriptor> v - = g.vertex_by_property(get_property_value(p, vertex_bundle))) + + typename Config::EdgeContainer m_edges; + StoredVertexList m_vertices; +}; + +// O(1) +template < class Derived, class Config, class Base > +inline typename Config::vertex_descriptor add_vertex( + adj_list_impl< Derived, Config, Base >& g_) +{ + Derived& g = static_cast< Derived& >(g_); + typedef typename Config::stored_vertex stored_vertex; + stored_vertex* v = new stored_vertex; + typename Config::StoredVertexList::iterator pos; + bool inserted; + boost::tie(pos, inserted) = boost::graph_detail::push(g.m_vertices, v); + v->m_position = pos; + g.added_vertex(v); + return v; +} +// O(1) +template < class Derived, class Config, class Base > +inline typename Config::vertex_descriptor add_vertex( + const typename Config::vertex_property_type& p, + adj_list_impl< Derived, Config, Base >& g_) +{ + typedef typename Config::vertex_descriptor vertex_descriptor; + Derived& g = static_cast< Derived& >(g_); + if (optional< vertex_descriptor > v + = g.vertex_by_property(get_property_value(p, vertex_bundle))) return *v; - typedef typename Config::stored_vertex stored_vertex; - stored_vertex* v = new stored_vertex(p); - typename Config::StoredVertexList::iterator pos; - bool inserted; - boost::tie(pos,inserted) = boost::graph_detail::push(g.m_vertices, v); - v->m_position = pos; - g.added_vertex(v); - return v; - } - // O(1) - template <class Derived, class Config, class Base> - inline void remove_vertex(typename Config::vertex_descriptor u, - adj_list_impl<Derived, Config, Base>& g_) - { - typedef typename Config::stored_vertex stored_vertex; - Derived& g = static_cast<Derived&>(g_); - g.removing_vertex(u, boost::graph_detail::iterator_stability(g_.m_vertices)); - stored_vertex* su = (stored_vertex*)u; - g.m_vertices.erase(su->m_position); - delete su; - } - // O(V) - template <class Derived, class Config, class Base> - inline typename Config::vertex_descriptor - vertex(typename Config::vertices_size_type n, - const adj_list_impl<Derived, Config, Base>& g_) - { - const Derived& g = static_cast<const Derived&>(g_); - typename Config::vertex_iterator i = vertices(g).first; - while (n--) ++i; // std::advance(i, n); (not VC++ portable) - return *i; - } + typedef typename Config::stored_vertex stored_vertex; + stored_vertex* v = new stored_vertex(p); + typename Config::StoredVertexList::iterator pos; + bool inserted; + boost::tie(pos, inserted) = boost::graph_detail::push(g.m_vertices, v); + v->m_position = pos; + g.added_vertex(v); + return v; +} +// O(1) +template < class Derived, class Config, class Base > +inline void remove_vertex(typename Config::vertex_descriptor u, + adj_list_impl< Derived, Config, Base >& g_) +{ + typedef typename Config::stored_vertex stored_vertex; + Derived& g = static_cast< Derived& >(g_); + g.removing_vertex( + u, boost::graph_detail::iterator_stability(g_.m_vertices)); + stored_vertex* su = (stored_vertex*)u; + g.m_vertices.erase(su->m_position); + delete su; +} +// O(V) +template < class Derived, class Config, class Base > +inline typename Config::vertex_descriptor vertex( + typename Config::vertices_size_type n, + const adj_list_impl< Derived, Config, Base >& g_) +{ + const Derived& g = static_cast< const Derived& >(g_); + typename Config::vertex_iterator i = vertices(g).first; + while (n--) + ++i; // std::advance(i, n); (not VC++ portable) + return *i; +} - //========================================================================= - // Vector-Backbone Adjacency List Implementation +//========================================================================= +// Vector-Backbone Adjacency List Implementation - namespace detail { +namespace detail +{ - template <class Graph, class vertex_descriptor> - inline void - remove_vertex_dispatch(Graph& g, vertex_descriptor u, - boost::directed_tag) - { + template < class Graph, class vertex_descriptor > + inline void remove_vertex_dispatch( + Graph& g, vertex_descriptor u, boost::directed_tag) + { typedef typename Graph::edge_parallel_category edge_parallel_category; g.m_vertices.erase(g.m_vertices.begin() + u); vertex_descriptor V = num_vertices(g); - if (u != V) { - for (vertex_descriptor v = 0; v < V; ++v) - reindex_edge_list(g.out_edge_list(v), u, edge_parallel_category()); + if (u != V) + { + for (vertex_descriptor v = 0; v < V; ++v) + reindex_edge_list( + g.out_edge_list(v), u, edge_parallel_category()); } - } + } - template <class Graph, class vertex_descriptor> - inline void - remove_vertex_dispatch(Graph& g, vertex_descriptor u, - boost::undirected_tag) - { + template < class Graph, class vertex_descriptor > + inline void remove_vertex_dispatch( + Graph& g, vertex_descriptor u, boost::undirected_tag) + { typedef typename Graph::global_edgelist_selector EdgeListS; - BOOST_STATIC_ASSERT((!is_same<EdgeListS, vecS>::value)); + BOOST_STATIC_ASSERT((!is_same< EdgeListS, vecS >::value)); typedef typename Graph::edge_parallel_category edge_parallel_category; g.m_vertices.erase(g.m_vertices.begin() + u); vertex_descriptor V = num_vertices(g); for (vertex_descriptor v = 0; v < V; ++v) - reindex_edge_list(g.out_edge_list(v), u, - edge_parallel_category()); + reindex_edge_list(g.out_edge_list(v), u, edge_parallel_category()); typedef typename Graph::EdgeContainer Container; typedef typename Container::iterator Iter; Iter ei = g.m_edges.begin(), ei_end = g.m_edges.end(); - for (; ei != ei_end; ++ei) { - if (ei->m_source > u) - --ei->m_source; - if (ei->m_target > u) - --ei->m_target; + for (; ei != ei_end; ++ei) + { + if (ei->m_source > u) + --ei->m_source; + if (ei->m_target > u) + --ei->m_target; } - } - template <class Graph, class vertex_descriptor> - inline void - remove_vertex_dispatch(Graph& g, vertex_descriptor u, - boost::bidirectional_tag) - { + } + template < class Graph, class vertex_descriptor > + inline void remove_vertex_dispatch( + Graph& g, vertex_descriptor u, boost::bidirectional_tag) + { typedef typename Graph::global_edgelist_selector EdgeListS; - BOOST_STATIC_ASSERT((!is_same<EdgeListS, vecS>::value)); + BOOST_STATIC_ASSERT((!is_same< EdgeListS, vecS >::value)); typedef typename Graph::edge_parallel_category edge_parallel_category; g.m_vertices.erase(g.m_vertices.begin() + u); vertex_descriptor V = num_vertices(g); vertex_descriptor v; - if (u != V) { - for (v = 0; v < V; ++v) - reindex_edge_list(g.out_edge_list(v), u, - edge_parallel_category()); - for (v = 0; v < V; ++v) - reindex_edge_list(in_edge_list(g, v), u, - edge_parallel_category()); - - typedef typename Graph::EdgeContainer Container; - typedef typename Container::iterator Iter; - Iter ei = g.m_edges.begin(), ei_end = g.m_edges.end(); - for (; ei != ei_end; ++ei) { - if (ei->m_source > u) - --ei->m_source; - if (ei->m_target > u) - --ei->m_target; - } + if (u != V) + { + for (v = 0; v < V; ++v) + reindex_edge_list( + g.out_edge_list(v), u, edge_parallel_category()); + for (v = 0; v < V; ++v) + reindex_edge_list( + in_edge_list(g, v), u, edge_parallel_category()); + + typedef typename Graph::EdgeContainer Container; + typedef typename Container::iterator Iter; + Iter ei = g.m_edges.begin(), ei_end = g.m_edges.end(); + for (; ei != ei_end; ++ei) + { + if (ei->m_source > u) + --ei->m_source; + if (ei->m_target > u) + --ei->m_target; + } } - } + } - template <class EdgeList, class vertex_descriptor> - inline void - reindex_edge_list(EdgeList& el, vertex_descriptor u, - boost::allow_parallel_edge_tag) - { + template < class EdgeList, class vertex_descriptor > + inline void reindex_edge_list( + EdgeList& el, vertex_descriptor u, boost::allow_parallel_edge_tag) + { typename EdgeList::iterator ei = el.begin(), e_end = el.end(); for (; ei != e_end; ++ei) - if ((*ei).get_target() > u) - --(*ei).get_target(); - } - template <class EdgeList, class vertex_descriptor> - inline void - reindex_edge_list(EdgeList& el, vertex_descriptor u, - boost::disallow_parallel_edge_tag) - { + if ((*ei).get_target() > u) + --(*ei).get_target(); + } + + template < class EdgeList, class vertex_descriptor > + inline void reindex_edge_list( + EdgeList& el, vertex_descriptor u, boost::disallow_parallel_edge_tag) + { typename EdgeList::iterator ei = el.begin(), e_end = el.end(); - while (ei != e_end) { - typename EdgeList::value_type ce = *ei; - ++ei; - if (ce.get_target() > u) { - el.erase(ce); - --ce.get_target(); - el.insert(ce); - } + while (ei != e_end) + { + if (ei->get_target() > u) + { + typename EdgeList::value_type ce = *ei; + ++ei; + el.erase(ce); + --ce.get_target(); + el.insert(ce); + } + else { + ++ei; + } } - } - } // namespace detail + } +} // namespace detail + +struct vec_adj_list_tag +{ +}; - struct vec_adj_list_tag { }; +template < class Graph, class Config, class Base > +class vec_adj_list_impl : public adj_list_helper< Config, Base > +{ + typedef typename Config::OutEdgeList OutEdgeList; + typedef typename Config::InEdgeList InEdgeList; + typedef typename Config::StoredVertexList StoredVertexList; - template <class Graph, class Config, class Base> - class vec_adj_list_impl - : public adj_list_helper<Config, Base> +public: + typedef typename Config::vertex_descriptor vertex_descriptor; + typedef typename Config::edge_descriptor edge_descriptor; + typedef typename Config::out_edge_iterator out_edge_iterator; + typedef typename Config::edge_iterator edge_iterator; + typedef typename Config::directed_category directed_category; + typedef typename Config::vertices_size_type vertices_size_type; + typedef typename Config::edges_size_type edges_size_type; + typedef typename Config::degree_size_type degree_size_type; + typedef typename Config::StoredEdge StoredEdge; + typedef typename Config::stored_vertex stored_vertex; + typedef typename Config::EdgeContainer EdgeContainer; + typedef typename Config::edge_property_type edge_property_type; + typedef vec_adj_list_tag graph_tag; + + static vertex_descriptor null_vertex() + { + return (std::numeric_limits< vertex_descriptor >::max)(); + } + + inline vec_adj_list_impl() {} + + inline vec_adj_list_impl(const vec_adj_list_impl& x) { copy_impl(x); } + inline vec_adj_list_impl& operator=(const vec_adj_list_impl& x) { - typedef typename Config::OutEdgeList OutEdgeList; - typedef typename Config::InEdgeList InEdgeList; - typedef typename Config::StoredVertexList StoredVertexList; - public: - typedef typename Config::vertex_descriptor vertex_descriptor; - typedef typename Config::edge_descriptor edge_descriptor; - typedef typename Config::out_edge_iterator out_edge_iterator; - typedef typename Config::edge_iterator edge_iterator; - typedef typename Config::directed_category directed_category; - typedef typename Config::vertices_size_type vertices_size_type; - typedef typename Config::edges_size_type edges_size_type; - typedef typename Config::degree_size_type degree_size_type; - typedef typename Config::StoredEdge StoredEdge; - typedef typename Config::stored_vertex stored_vertex; - typedef typename Config::EdgeContainer EdgeContainer; - typedef typename Config::edge_property_type edge_property_type; - typedef vec_adj_list_tag graph_tag; - - static vertex_descriptor null_vertex() - { - return (std::numeric_limits<vertex_descriptor>::max)(); - } - - inline vec_adj_list_impl() { } - - inline vec_adj_list_impl(const vec_adj_list_impl& x) { - copy_impl(x); - } - inline vec_adj_list_impl& operator=(const vec_adj_list_impl& x) { this->clear(); copy_impl(x); return *this; - } - inline void clear() { + } + inline void clear() + { m_vertices.clear(); m_edges.clear(); - } - - inline vec_adj_list_impl(vertices_size_type _num_vertices) - : m_vertices(_num_vertices) { } - - template <class EdgeIterator> - inline vec_adj_list_impl(vertices_size_type num_vertices, - EdgeIterator first, EdgeIterator last) - : m_vertices(num_vertices) - { - while (first != last) { - add_edge((*first).first, (*first).second, - static_cast<Graph&>(*this)); - ++first; + } + + inline vec_adj_list_impl(vertices_size_type _num_vertices) + : m_vertices(_num_vertices) + { + } + + template < class EdgeIterator > + inline vec_adj_list_impl( + vertices_size_type num_vertices, EdgeIterator first, EdgeIterator last) + : m_vertices(num_vertices) + { + while (first != last) + { + add_edge( + (*first).first, (*first).second, static_cast< Graph& >(*this)); + ++first; } - } - template <class EdgeIterator, class EdgePropertyIterator> - inline vec_adj_list_impl(vertices_size_type num_vertices, - EdgeIterator first, EdgeIterator last, - EdgePropertyIterator ep_iter) - : m_vertices(num_vertices) - { - while (first != last) { - add_edge((*first).first, (*first).second, *ep_iter, - static_cast<Graph&>(*this)); - ++first; - ++ep_iter; + } + template < class EdgeIterator, class EdgePropertyIterator > + inline vec_adj_list_impl(vertices_size_type num_vertices, + EdgeIterator first, EdgeIterator last, EdgePropertyIterator ep_iter) + : m_vertices(num_vertices) + { + while (first != last) + { + add_edge((*first).first, (*first).second, *ep_iter, + static_cast< Graph& >(*this)); + ++first; + ++ep_iter; } - } + } - // protected: - inline boost::integer_range<vertex_descriptor> vertex_set() const { - return boost::integer_range<vertex_descriptor>(0, m_vertices.size()); - } - inline OutEdgeList& out_edge_list(vertex_descriptor v) { + // protected: + inline boost::integer_range< vertex_descriptor > vertex_set() const + { + return boost::integer_range< vertex_descriptor >(0, m_vertices.size()); + } + inline OutEdgeList& out_edge_list(vertex_descriptor v) + { return m_vertices[v].m_out_edges; - } - inline const OutEdgeList& out_edge_list(vertex_descriptor v) const { + } + inline const OutEdgeList& out_edge_list(vertex_descriptor v) const + { return m_vertices[v].m_out_edges; - } - inline void copy_impl(const vec_adj_list_impl& x_) - { - const Graph& x = static_cast<const Graph&>(x_); + } + inline void copy_impl(const vec_adj_list_impl& x_) + { + const Graph& x = static_cast< const Graph& >(x_); // Copy the stored vertex objects by adding each vertex // and copying its property object. - for (vertices_size_type i = 0; i < num_vertices(x); ++i) { - vertex_descriptor v = add_vertex(*this); - m_vertices[v].m_property = x.m_vertices[i].m_property; + for (vertices_size_type i = 0; i < num_vertices(x); ++i) + { + vertex_descriptor v = add_vertex(*this); + m_vertices[v].m_property = x.m_vertices[i].m_property; } // Copy the edges by adding each edge and copying its // property object. edge_iterator ei, ei_end; - for (boost::tie(ei, ei_end) = edges(x); ei != ei_end; ++ei) { - edge_descriptor e; - bool inserted; - boost::tie(e, inserted) = add_edge(source(*ei,x), target(*ei,x) , *this); - *((edge_property_type*)e.m_eproperty) - = *((edge_property_type*)(*ei).m_eproperty); + for (boost::tie(ei, ei_end) = edges(x); ei != ei_end; ++ei) + { + edge_descriptor e; + bool inserted; + boost::tie(e, inserted) + = add_edge(source(*ei, x), target(*ei, x), *this); + *((edge_property_type*)e.m_eproperty) + = *((edge_property_type*)(*ei).m_eproperty); } - } - typename Config::EdgeContainer m_edges; - StoredVertexList m_vertices; - }; - // Had to make these non-members to avoid accidental instantiation - // on SGI MIPSpro C++ - template <class G, class C, class B> - inline typename C::InEdgeList& - in_edge_list(vec_adj_list_impl<G,C,B>& g, - typename C::vertex_descriptor v) { - return g.m_vertices[v].m_in_edges; - } - template <class G, class C, class B> - inline const typename C::InEdgeList& - in_edge_list(const vec_adj_list_impl<G,C,B>& g, - typename C::vertex_descriptor v) { - return g.m_vertices[v].m_in_edges; - } - - // O(1) - template <class Graph, class Config, class Base> - inline typename Config::vertex_descriptor - add_vertex(vec_adj_list_impl<Graph, Config, Base>& g_) { - Graph& g = static_cast<Graph&>(g_); - g.m_vertices.resize(g.m_vertices.size() + 1); - g.added_vertex(g.m_vertices.size() - 1); - return g.m_vertices.size() - 1; - } - - template <class Graph, class Config, class Base> - inline typename Config::vertex_descriptor - add_vertex(const typename Config::vertex_property_type& p, - vec_adj_list_impl<Graph, Config, Base>& g_) { - typedef typename Config::vertex_descriptor vertex_descriptor; - Graph& g = static_cast<Graph&>(g_); - if (optional<vertex_descriptor> v - = g.vertex_by_property(get_property_value(p, vertex_bundle))) - return *v; - typedef typename Config::stored_vertex stored_vertex; - g.m_vertices.push_back(stored_vertex(p)); - g.added_vertex(g.m_vertices.size() - 1); - return g.m_vertices.size() - 1; - } - - // Here we override the directed_graph_helper add_edge() function - // so that the number of vertices is automatically changed if - // either u or v is greater than the number of vertices. - template <class Graph, class Config, class Base> - inline std::pair<typename Config::edge_descriptor, bool> - add_edge(typename Config::vertex_descriptor u, - typename Config::vertex_descriptor v, - const typename Config::edge_property_type& p, - vec_adj_list_impl<Graph, Config, Base>& g_) - { - BOOST_USING_STD_MAX(); - typename Config::vertex_descriptor x = max BOOST_PREVENT_MACRO_SUBSTITUTION(u, v); - if (x >= num_vertices(g_)) - g_.m_vertices.resize(x + 1); - adj_list_helper<Config, Base>& g = g_; - return add_edge(u, v, p, g); - } - template <class Graph, class Config, class Base> - inline std::pair<typename Config::edge_descriptor, bool> - add_edge(typename Config::vertex_descriptor u, - typename Config::vertex_descriptor v, - vec_adj_list_impl<Graph, Config, Base>& g_) - { - typename Config::edge_property_type p; - return add_edge(u, v, p, g_); } + typename Config::EdgeContainer m_edges; + StoredVertexList m_vertices; +}; +// Had to make these non-members to avoid accidental instantiation +// on SGI MIPSpro C++ +template < class G, class C, class B > +inline typename C::InEdgeList& in_edge_list( + vec_adj_list_impl< G, C, B >& g, typename C::vertex_descriptor v) +{ + return g.m_vertices[v].m_in_edges; +} +template < class G, class C, class B > +inline const typename C::InEdgeList& in_edge_list( + const vec_adj_list_impl< G, C, B >& g, typename C::vertex_descriptor v) +{ + return g.m_vertices[v].m_in_edges; +} +// O(1) +template < class Graph, class Config, class Base > +inline typename Config::vertex_descriptor add_vertex( + vec_adj_list_impl< Graph, Config, Base >& g_) +{ + Graph& g = static_cast< Graph& >(g_); + g.m_vertices.resize(g.m_vertices.size() + 1); + g.added_vertex(g.m_vertices.size() - 1); + return g.m_vertices.size() - 1; +} - // O(V + E) - template <class Graph, class Config, class Base> - inline void remove_vertex(typename Config::vertex_descriptor v, - vec_adj_list_impl<Graph, Config, Base>& g_) - { - typedef typename Config::directed_category Cat; - Graph& g = static_cast<Graph&>(g_); - g.removing_vertex(v, boost::graph_detail::iterator_stability(g_.m_vertices)); - detail::remove_vertex_dispatch(g, v, Cat()); - } - // O(1) - template <class Graph, class Config, class Base> - inline typename Config::vertex_descriptor - vertex(typename Config::vertices_size_type n, - const vec_adj_list_impl<Graph, Config, Base>&) - { - return n; - } +template < class Graph, class Config, class Base > +inline typename Config::vertex_descriptor add_vertex( + const typename Config::vertex_property_type& p, + vec_adj_list_impl< Graph, Config, Base >& g_) +{ + typedef typename Config::vertex_descriptor vertex_descriptor; + Graph& g = static_cast< Graph& >(g_); + if (optional< vertex_descriptor > v + = g.vertex_by_property(get_property_value(p, vertex_bundle))) + return *v; + typedef typename Config::stored_vertex stored_vertex; + g.m_vertices.push_back(stored_vertex(p)); + g.added_vertex(g.m_vertices.size() - 1); + return g.m_vertices.size() - 1; +} +// Here we override the directed_graph_helper add_edge() function +// so that the number of vertices is automatically changed if +// either u or v is greater than the number of vertices. +template < class Graph, class Config, class Base > +inline std::pair< typename Config::edge_descriptor, bool > add_edge( + typename Config::vertex_descriptor u, typename Config::vertex_descriptor v, + const typename Config::edge_property_type& p, + vec_adj_list_impl< Graph, Config, Base >& g_) +{ + BOOST_USING_STD_MAX(); + typename Config::vertex_descriptor x + = max BOOST_PREVENT_MACRO_SUBSTITUTION(u, v); + if (x >= num_vertices(g_)) + g_.m_vertices.resize(x + 1); + adj_list_helper< Config, Base >& g = g_; + return add_edge(u, v, p, g); +} +template < class Graph, class Config, class Base > +inline std::pair< typename Config::edge_descriptor, bool > add_edge( + typename Config::vertex_descriptor u, typename Config::vertex_descriptor v, + vec_adj_list_impl< Graph, Config, Base >& g_) +{ + typename Config::edge_property_type p; + return add_edge(u, v, p, g_); +} - namespace detail { +// O(V + E) +template < class Graph, class Config, class Base > +inline void remove_vertex(typename Config::vertex_descriptor v, + vec_adj_list_impl< Graph, Config, Base >& g_) +{ + typedef typename Config::directed_category Cat; + Graph& g = static_cast< Graph& >(g_); + g.removing_vertex( + v, boost::graph_detail::iterator_stability(g_.m_vertices)); + detail::remove_vertex_dispatch(g, v, Cat()); +} +// O(1) +template < class Graph, class Config, class Base > +inline typename Config::vertex_descriptor vertex( + typename Config::vertices_size_type n, + const vec_adj_list_impl< Graph, Config, Base >&) +{ + return n; +} + +namespace detail +{ //========================================================================= // Adjacency List Generator - template <class Graph, class VertexListS, class OutEdgeListS, - class DirectedS, class VertexProperty, class EdgeProperty, - class GraphProperty, class EdgeListS> + template < class Graph, class VertexListS, class OutEdgeListS, + class DirectedS, class VertexProperty, class EdgeProperty, + class GraphProperty, class EdgeListS > struct adj_list_gen { - typedef typename detail::is_random_access<VertexListS>::type - is_rand_access; - typedef typename has_property<EdgeProperty>::type has_edge_property; - typedef typename DirectedS::is_directed_t DirectedT; - typedef typename DirectedS::is_bidir_t BidirectionalT; - - struct config - { - typedef OutEdgeListS edgelist_selector; - typedef EdgeListS global_edgelist_selector; - - typedef Graph graph_type; - typedef EdgeProperty edge_property_type; - typedef VertexProperty vertex_property_type; - typedef GraphProperty graph_property_type; - typedef std::size_t vertices_size_type; - - typedef adjacency_list_traits<OutEdgeListS, VertexListS, DirectedS> - Traits; - - typedef typename Traits::directed_category directed_category; - typedef typename Traits::edge_parallel_category edge_parallel_category; - typedef typename Traits::vertex_descriptor vertex_descriptor; - typedef typename Traits::edge_descriptor edge_descriptor; - - typedef void* vertex_ptr; - - // need to reorganize this to avoid instantiating stuff - // that doesn't get used -JGS - - // VertexList and vertex_iterator - typedef typename container_gen<VertexListS, - vertex_ptr>::type SeqVertexList; - typedef boost::integer_range<vertex_descriptor> RandVertexList; - typedef typename mpl::if_<is_rand_access, - RandVertexList, SeqVertexList>::type VertexList; - - typedef typename VertexList::iterator vertex_iterator; - - // EdgeContainer and StoredEdge - - typedef typename container_gen<EdgeListS, - list_edge<vertex_descriptor, EdgeProperty> >::type EdgeContainer; + typedef typename detail::is_random_access< VertexListS >::type + is_rand_access; + typedef typename has_property< EdgeProperty >::type has_edge_property; + typedef typename DirectedS::is_directed_t DirectedT; + typedef typename DirectedS::is_bidir_t BidirectionalT; - typedef typename mpl::and_<DirectedT, - typename mpl::not_<BidirectionalT>::type >::type on_edge_storage; - - typedef typename mpl::if_<on_edge_storage, - std::size_t, typename EdgeContainer::size_type - >::type edges_size_type; - - typedef typename EdgeContainer::iterator EdgeIter; - - typedef typename detail::is_random_access<EdgeListS>::type is_edge_ra; - - typedef typename mpl::if_<on_edge_storage, - stored_edge_property<vertex_descriptor, EdgeProperty>, - typename mpl::if_<is_edge_ra, - stored_ra_edge_iter<vertex_descriptor, EdgeContainer, EdgeProperty>, - stored_edge_iter<vertex_descriptor, EdgeIter, EdgeProperty> - >::type - >::type StoredEdge; - - // Adjacency Types - - typedef typename container_gen<OutEdgeListS, StoredEdge>::type - OutEdgeList; - typedef typename OutEdgeList::size_type degree_size_type; - typedef typename OutEdgeList::iterator OutEdgeIter; - - typedef boost::detail::iterator_traits<OutEdgeIter> OutEdgeIterTraits; - typedef typename OutEdgeIterTraits::iterator_category OutEdgeIterCat; - typedef typename OutEdgeIterTraits::difference_type OutEdgeIterDiff; - - typedef out_edge_iter< - OutEdgeIter, vertex_descriptor, edge_descriptor, OutEdgeIterDiff - > out_edge_iterator; - - typedef typename adjacency_iterator_generator<graph_type, - vertex_descriptor, out_edge_iterator>::type adjacency_iterator; - - typedef OutEdgeList InEdgeList; - typedef OutEdgeIter InEdgeIter; - typedef OutEdgeIterCat InEdgeIterCat; - typedef OutEdgeIterDiff InEdgeIterDiff; - - typedef in_edge_iter< - InEdgeIter, vertex_descriptor, edge_descriptor, InEdgeIterDiff - > in_edge_iterator; - - typedef typename inv_adjacency_iterator_generator<graph_type, - vertex_descriptor, in_edge_iterator>::type inv_adjacency_iterator; - - // Edge Iterator - - typedef boost::detail::iterator_traits<EdgeIter> EdgeIterTraits; - typedef typename EdgeIterTraits::iterator_category EdgeIterCat; - typedef typename EdgeIterTraits::difference_type EdgeIterDiff; - - typedef undirected_edge_iter< - EdgeIter - , edge_descriptor - , EdgeIterDiff - > UndirectedEdgeIter; // also used for bidirectional + struct config + { + typedef OutEdgeListS edgelist_selector; + typedef EdgeListS global_edgelist_selector; - typedef adj_list_edge_iterator<vertex_iterator, out_edge_iterator, - graph_type> DirectedEdgeIter; + typedef Graph graph_type; + typedef EdgeProperty edge_property_type; + typedef VertexProperty vertex_property_type; + typedef GraphProperty graph_property_type; + typedef std::size_t vertices_size_type; - typedef typename mpl::if_<on_edge_storage, - DirectedEdgeIter, UndirectedEdgeIter>::type edge_iterator; + typedef adjacency_list_traits< OutEdgeListS, VertexListS, + DirectedS > + Traits; - // stored_vertex and StoredVertexList - typedef typename container_gen<VertexListS, vertex_ptr>::type - SeqStoredVertexList; - struct seq_stored_vertex { - seq_stored_vertex() { } - seq_stored_vertex(const VertexProperty& p) : m_property(p) { } - OutEdgeList m_out_edges; - VertexProperty m_property; - typename SeqStoredVertexList::iterator m_position; - }; - struct bidir_seq_stored_vertex { - bidir_seq_stored_vertex() { } - bidir_seq_stored_vertex(const VertexProperty& p) : m_property(p) { } - OutEdgeList m_out_edges; - InEdgeList m_in_edges; - VertexProperty m_property; - typename SeqStoredVertexList::iterator m_position; - }; - struct rand_stored_vertex { - rand_stored_vertex() { } - rand_stored_vertex(const VertexProperty& p) : m_property(p) { } - OutEdgeList m_out_edges; - VertexProperty m_property; - }; - struct bidir_rand_stored_vertex { - bidir_rand_stored_vertex() { } - bidir_rand_stored_vertex(const VertexProperty& p) : m_property(p) { } - OutEdgeList m_out_edges; - InEdgeList m_in_edges; - VertexProperty m_property; - }; - typedef typename mpl::if_<is_rand_access, - typename mpl::if_<BidirectionalT, - bidir_rand_stored_vertex, rand_stored_vertex>::type, - typename mpl::if_<BidirectionalT, - bidir_seq_stored_vertex, seq_stored_vertex>::type - >::type StoredVertex; - struct stored_vertex : public StoredVertex { - stored_vertex() { } - stored_vertex(const VertexProperty& p) : StoredVertex(p) { } - }; + typedef typename Traits::directed_category directed_category; + typedef + typename Traits::edge_parallel_category edge_parallel_category; + typedef typename Traits::vertex_descriptor vertex_descriptor; + typedef typename Traits::edge_descriptor edge_descriptor; + + typedef void* vertex_ptr; + + // need to reorganize this to avoid instantiating stuff + // that doesn't get used -JGS + + // VertexList and vertex_iterator + typedef typename container_gen< VertexListS, vertex_ptr >::type + SeqVertexList; + typedef boost::integer_range< vertex_descriptor > RandVertexList; + typedef typename mpl::if_< is_rand_access, RandVertexList, + SeqVertexList >::type VertexList; + + typedef typename VertexList::iterator vertex_iterator; + + // EdgeContainer and StoredEdge + + typedef typename container_gen< EdgeListS, + list_edge< vertex_descriptor, EdgeProperty > >::type + EdgeContainer; + + typedef typename mpl::and_< DirectedT, + typename mpl::not_< BidirectionalT >::type >::type + on_edge_storage; + + typedef typename mpl::if_< on_edge_storage, std::size_t, + typename EdgeContainer::size_type >::type edges_size_type; + + typedef typename EdgeContainer::iterator EdgeIter; + + typedef + typename detail::is_random_access< EdgeListS >::type is_edge_ra; + + typedef typename mpl::if_< on_edge_storage, + stored_edge_property< vertex_descriptor, EdgeProperty >, + typename mpl::if_< is_edge_ra, + stored_ra_edge_iter< vertex_descriptor, EdgeContainer, + EdgeProperty >, + stored_edge_iter< vertex_descriptor, EdgeIter, + EdgeProperty > >::type >::type StoredEdge; + + // Adjacency Types + + typedef typename container_gen< OutEdgeListS, StoredEdge >::type + OutEdgeList; + typedef typename OutEdgeList::size_type degree_size_type; + typedef typename OutEdgeList::iterator OutEdgeIter; + + typedef std::iterator_traits< OutEdgeIter > + OutEdgeIterTraits; + typedef + typename OutEdgeIterTraits::iterator_category OutEdgeIterCat; + typedef typename OutEdgeIterTraits::difference_type OutEdgeIterDiff; + + typedef out_edge_iter< OutEdgeIter, vertex_descriptor, + edge_descriptor, OutEdgeIterDiff > + out_edge_iterator; + + typedef typename adjacency_iterator_generator< graph_type, + vertex_descriptor, out_edge_iterator >::type adjacency_iterator; + + typedef OutEdgeList InEdgeList; + typedef OutEdgeIter InEdgeIter; + typedef OutEdgeIterCat InEdgeIterCat; + typedef OutEdgeIterDiff InEdgeIterDiff; + + typedef in_edge_iter< InEdgeIter, vertex_descriptor, + edge_descriptor, InEdgeIterDiff > + in_edge_iterator; + + typedef typename inv_adjacency_iterator_generator< graph_type, + vertex_descriptor, in_edge_iterator >::type + inv_adjacency_iterator; + + // Edge Iterator + + typedef std::iterator_traits< EdgeIter > EdgeIterTraits; + typedef typename EdgeIterTraits::iterator_category EdgeIterCat; + typedef typename EdgeIterTraits::difference_type EdgeIterDiff; + + typedef undirected_edge_iter< EdgeIter, edge_descriptor, + EdgeIterDiff > + UndirectedEdgeIter; // also used for bidirectional + + typedef adj_list_edge_iterator< vertex_iterator, out_edge_iterator, + graph_type > + DirectedEdgeIter; + + typedef typename mpl::if_< on_edge_storage, DirectedEdgeIter, + UndirectedEdgeIter >::type edge_iterator; + + // stored_vertex and StoredVertexList + typedef typename container_gen< VertexListS, vertex_ptr >::type + SeqStoredVertexList; + struct seq_stored_vertex + { + seq_stored_vertex() {} + seq_stored_vertex(const VertexProperty& p) : m_property(p) {} + OutEdgeList m_out_edges; + VertexProperty m_property; + typename SeqStoredVertexList::iterator m_position; + }; + struct bidir_seq_stored_vertex + { + bidir_seq_stored_vertex() {} + bidir_seq_stored_vertex(const VertexProperty& p) : m_property(p) + { + } + OutEdgeList m_out_edges; + InEdgeList m_in_edges; + VertexProperty m_property; + typename SeqStoredVertexList::iterator m_position; + }; + struct rand_stored_vertex + { + rand_stored_vertex() {} + rand_stored_vertex(const VertexProperty& p) : m_property(p) {} + OutEdgeList m_out_edges; + VertexProperty m_property; + }; + struct bidir_rand_stored_vertex + { + bidir_rand_stored_vertex() {} + bidir_rand_stored_vertex(const VertexProperty& p) + : m_property(p) + { + } + OutEdgeList m_out_edges; + InEdgeList m_in_edges; + VertexProperty m_property; + }; + typedef typename mpl::if_< is_rand_access, + typename mpl::if_< BidirectionalT, bidir_rand_stored_vertex, + rand_stored_vertex >::type, + typename mpl::if_< BidirectionalT, bidir_seq_stored_vertex, + seq_stored_vertex >::type >::type StoredVertex; + struct stored_vertex : public StoredVertex + { + stored_vertex() {} + stored_vertex(const VertexProperty& p) : StoredVertex(p) {} + }; + + typedef typename container_gen< VertexListS, stored_vertex >::type + RandStoredVertexList; + typedef typename mpl::if_< is_rand_access, RandStoredVertexList, + SeqStoredVertexList >::type StoredVertexList; + }; // end of config + + typedef typename mpl::if_< BidirectionalT, + bidirectional_graph_helper_with_property< config >, + typename mpl::if_< DirectedT, directed_graph_helper< config >, + undirected_graph_helper< config > >::type >::type + DirectedHelper; - typedef typename container_gen<VertexListS, stored_vertex>::type - RandStoredVertexList; typedef typename mpl::if_< is_rand_access, - RandStoredVertexList, SeqStoredVertexList>::type StoredVertexList; - }; // end of config - - - typedef typename mpl::if_<BidirectionalT, - bidirectional_graph_helper_with_property<config>, - typename mpl::if_<DirectedT, - directed_graph_helper<config>, - undirected_graph_helper<config> - >::type - >::type DirectedHelper; - - typedef typename mpl::if_<is_rand_access, - vec_adj_list_impl<Graph, config, DirectedHelper>, - adj_list_impl<Graph, config, DirectedHelper> - >::type type; - + vec_adj_list_impl< Graph, config, DirectedHelper >, + adj_list_impl< Graph, config, DirectedHelper > >::type type; }; - } // namespace detail +} // namespace detail - //========================================================================= - // Vertex Property Maps - - template <class Graph, class ValueType, class Reference, class Tag> - struct adj_list_vertex_property_map - : public boost::put_get_helper< - Reference, - adj_list_vertex_property_map<Graph, ValueType, Reference, Tag> - > - { - typedef typename Graph::stored_vertex StoredVertex; - typedef ValueType value_type; - typedef Reference reference; - typedef typename Graph::vertex_descriptor key_type; - typedef boost::lvalue_property_map_tag category; - inline adj_list_vertex_property_map(const Graph* = 0, Tag tag = Tag()): m_tag(tag) { } - inline Reference operator[](key_type v) const { +//========================================================================= +// Vertex Property Maps + +template < class Graph, class ValueType, class Reference, class Tag > +struct adj_list_vertex_property_map +: public boost::put_get_helper< Reference, + adj_list_vertex_property_map< Graph, ValueType, Reference, Tag > > +{ + typedef typename Graph::stored_vertex StoredVertex; + typedef ValueType value_type; + typedef Reference reference; + typedef typename Graph::vertex_descriptor key_type; + typedef boost::lvalue_property_map_tag category; + inline adj_list_vertex_property_map(const Graph* = 0, Tag tag = Tag()) + : m_tag(tag) + { + } + inline Reference operator[](key_type v) const + { StoredVertex* sv = (StoredVertex*)v; return get_property_value(sv->m_property, m_tag); - } - inline Reference operator()(key_type v) const { + } + inline Reference operator()(key_type v) const + { return this->operator[](v); - } - Tag m_tag; - }; + } + Tag m_tag; +}; - template <class Graph, class Property, class PropRef> - struct adj_list_vertex_all_properties_map - : public boost::put_get_helper<PropRef, - adj_list_vertex_all_properties_map<Graph, Property, PropRef> - > - { - typedef typename Graph::stored_vertex StoredVertex; - typedef Property value_type; - typedef PropRef reference; - typedef typename Graph::vertex_descriptor key_type; - typedef boost::lvalue_property_map_tag category; - inline adj_list_vertex_all_properties_map(const Graph* = 0, vertex_all_t = vertex_all_t()) { } - inline PropRef operator[](key_type v) const { +template < class Graph, class Property, class PropRef > +struct adj_list_vertex_all_properties_map +: public boost::put_get_helper< PropRef, + adj_list_vertex_all_properties_map< Graph, Property, PropRef > > +{ + typedef typename Graph::stored_vertex StoredVertex; + typedef Property value_type; + typedef PropRef reference; + typedef typename Graph::vertex_descriptor key_type; + typedef boost::lvalue_property_map_tag category; + inline adj_list_vertex_all_properties_map( + const Graph* = 0, vertex_all_t = vertex_all_t()) + { + } + inline PropRef operator[](key_type v) const + { StoredVertex* sv = (StoredVertex*)v; return sv->m_property; - } - inline PropRef operator()(key_type v) const { - return this->operator[](v); - } - }; + } + inline PropRef operator()(key_type v) const { return this->operator[](v); } +}; - template <class Graph, class GraphPtr, class ValueType, class Reference, - class Tag> - struct vec_adj_list_vertex_property_map - : public boost::put_get_helper< - Reference, - vec_adj_list_vertex_property_map<Graph,GraphPtr,ValueType,Reference, - Tag> - > - { - typedef ValueType value_type; - typedef Reference reference; - typedef typename boost::graph_traits<Graph>::vertex_descriptor key_type; - typedef boost::lvalue_property_map_tag category; - vec_adj_list_vertex_property_map(GraphPtr g = 0, Tag tag = Tag()) : m_g(g), m_tag(tag) { } - inline Reference operator[](key_type v) const { +template < class Graph, class GraphPtr, class ValueType, class Reference, + class Tag > +struct vec_adj_list_vertex_property_map +: public boost::put_get_helper< Reference, + vec_adj_list_vertex_property_map< Graph, GraphPtr, ValueType, Reference, + Tag > > +{ + typedef ValueType value_type; + typedef Reference reference; + typedef typename boost::graph_traits< Graph >::vertex_descriptor key_type; + typedef boost::lvalue_property_map_tag category; + vec_adj_list_vertex_property_map(GraphPtr g = 0, Tag tag = Tag()) + : m_g(g), m_tag(tag) + { + } + inline Reference operator[](key_type v) const + { return get_property_value(m_g->m_vertices[v].m_property, m_tag); - } - inline Reference operator()(key_type v) const { + } + inline Reference operator()(key_type v) const + { return this->operator[](v); - } - GraphPtr m_g; - Tag m_tag; - }; + } + GraphPtr m_g; + Tag m_tag; +}; - template <class Graph, class GraphPtr, class Property, class PropertyRef> - struct vec_adj_list_vertex_all_properties_map - : public boost::put_get_helper<PropertyRef, - vec_adj_list_vertex_all_properties_map<Graph,GraphPtr,Property, - PropertyRef> - > - { - typedef Property value_type; - typedef PropertyRef reference; - typedef typename boost::graph_traits<Graph>::vertex_descriptor key_type; - typedef boost::lvalue_property_map_tag category; - vec_adj_list_vertex_all_properties_map(GraphPtr g = 0, vertex_all_t = vertex_all_t()) : m_g(g) { } - inline PropertyRef operator[](key_type v) const { +template < class Graph, class GraphPtr, class Property, class PropertyRef > +struct vec_adj_list_vertex_all_properties_map +: public boost::put_get_helper< PropertyRef, + vec_adj_list_vertex_all_properties_map< Graph, GraphPtr, Property, + PropertyRef > > +{ + typedef Property value_type; + typedef PropertyRef reference; + typedef typename boost::graph_traits< Graph >::vertex_descriptor key_type; + typedef boost::lvalue_property_map_tag category; + vec_adj_list_vertex_all_properties_map( + GraphPtr g = 0, vertex_all_t = vertex_all_t()) + : m_g(g) + { + } + inline PropertyRef operator[](key_type v) const + { return m_g->m_vertices[v].m_property; - } - inline PropertyRef operator()(key_type v) const { + } + inline PropertyRef operator()(key_type v) const + { return this->operator[](v); - } - GraphPtr m_g; - }; + } + GraphPtr m_g; +}; - struct adj_list_any_vertex_pa { - template <class Tag, class Graph, class Property> - struct bind_ { - typedef typename property_value<Property, Tag>::type value_type; +struct adj_list_any_vertex_pa +{ + template < class Tag, class Graph, class Property > struct bind_ + { + typedef typename property_value< Property, Tag >::type value_type; typedef value_type& reference; typedef const value_type& const_reference; - typedef adj_list_vertex_property_map - <Graph, value_type, reference, Tag> type; - typedef adj_list_vertex_property_map - <Graph, value_type, const_reference, Tag> const_type; - }; + typedef adj_list_vertex_property_map< Graph, value_type, reference, + Tag > + type; + typedef adj_list_vertex_property_map< Graph, value_type, + const_reference, Tag > + const_type; }; - struct adj_list_all_vertex_pa { - template <class Tag, class Graph, class Property> - struct bind_ { +}; +struct adj_list_all_vertex_pa +{ + template < class Tag, class Graph, class Property > struct bind_ + { typedef typename Graph::vertex_descriptor Vertex; - typedef adj_list_vertex_all_properties_map<Graph,Property, - Property&> type; - typedef adj_list_vertex_all_properties_map<Graph,Property, - const Property&> const_type; - }; + typedef adj_list_vertex_all_properties_map< Graph, Property, Property& > + type; + typedef adj_list_vertex_all_properties_map< Graph, Property, + const Property& > + const_type; }; - - template <class Property, class Vertex> - struct vec_adj_list_vertex_id_map - : public boost::put_get_helper< - Vertex, vec_adj_list_vertex_id_map<Property, Vertex> - > - { - typedef Vertex value_type; - typedef Vertex key_type; - typedef Vertex reference; - typedef boost::readable_property_map_tag category; - inline vec_adj_list_vertex_id_map() { } - template <class Graph> - inline vec_adj_list_vertex_id_map(const Graph&, vertex_index_t) { } - inline value_type operator[](key_type v) const { return v; } - inline value_type operator()(key_type v) const { return v; } - }; - - struct vec_adj_list_any_vertex_pa { - template <class Tag, class Graph, class Property> - struct bind_ { - typedef typename property_value<Property, Tag>::type value_type; +}; + +template < class Property, class Vertex > +struct vec_adj_list_vertex_id_map +: public boost::put_get_helper< Vertex, + vec_adj_list_vertex_id_map< Property, Vertex > > +{ + typedef Vertex value_type; + typedef Vertex key_type; + typedef Vertex reference; + typedef boost::readable_property_map_tag category; + inline vec_adj_list_vertex_id_map() {} + template < class Graph > + inline vec_adj_list_vertex_id_map(const Graph&, vertex_index_t) + { + } + inline value_type operator[](key_type v) const { return v; } + inline value_type operator()(key_type v) const { return v; } +}; + +struct vec_adj_list_any_vertex_pa +{ + template < class Tag, class Graph, class Property > struct bind_ + { + typedef typename property_value< Property, Tag >::type value_type; typedef value_type& reference; typedef const value_type& const_reference; - typedef vec_adj_list_vertex_property_map - <Graph, Graph*, value_type, reference, Tag> type; - typedef vec_adj_list_vertex_property_map - <Graph, const Graph*, value_type, const_reference, Tag> const_type; - }; + typedef vec_adj_list_vertex_property_map< Graph, Graph*, value_type, + reference, Tag > + type; + typedef vec_adj_list_vertex_property_map< Graph, const Graph*, + value_type, const_reference, Tag > + const_type; }; - struct vec_adj_list_id_vertex_pa { - template <class Tag, class Graph, class Property> - struct bind_ { +}; +struct vec_adj_list_id_vertex_pa +{ + template < class Tag, class Graph, class Property > struct bind_ + { typedef typename Graph::vertex_descriptor Vertex; - typedef vec_adj_list_vertex_id_map<Property, Vertex> type; - typedef vec_adj_list_vertex_id_map<Property, Vertex> const_type; - }; + typedef vec_adj_list_vertex_id_map< Property, Vertex > type; + typedef vec_adj_list_vertex_id_map< Property, Vertex > const_type; }; - struct vec_adj_list_all_vertex_pa { - template <class Tag, class Graph, class Property> - struct bind_ { +}; +struct vec_adj_list_all_vertex_pa +{ + template < class Tag, class Graph, class Property > struct bind_ + { typedef typename Graph::vertex_descriptor Vertex; - typedef vec_adj_list_vertex_all_properties_map - <Graph, Graph*, Property, Property&> type; - typedef vec_adj_list_vertex_all_properties_map - <Graph, const Graph*, Property, const Property&> const_type; - }; + typedef vec_adj_list_vertex_all_properties_map< Graph, Graph*, Property, + Property& > + type; + typedef vec_adj_list_vertex_all_properties_map< Graph, const Graph*, + Property, const Property& > + const_type; }; - namespace detail { - template <class Tag, class Graph, class Property> +}; +namespace detail +{ + template < class Tag, class Graph, class Property > struct adj_list_choose_vertex_pa - : boost::mpl::if_< - boost::is_same<Tag, vertex_all_t>, - adj_list_all_vertex_pa, - adj_list_any_vertex_pa>::type - ::template bind_<Tag, Graph, Property> - {}; - + : boost::mpl::if_< boost::is_same< Tag, vertex_all_t >, + adj_list_all_vertex_pa, adj_list_any_vertex_pa >::type :: + template bind_< Tag, Graph, Property > + { + }; - template <class Tag> - struct vec_adj_list_choose_vertex_pa_helper { - typedef vec_adj_list_any_vertex_pa type; + template < class Tag > struct vec_adj_list_choose_vertex_pa_helper + { + typedef vec_adj_list_any_vertex_pa type; }; - template <> - struct vec_adj_list_choose_vertex_pa_helper<vertex_index_t> { - typedef vec_adj_list_id_vertex_pa type; + template <> struct vec_adj_list_choose_vertex_pa_helper< vertex_index_t > + { + typedef vec_adj_list_id_vertex_pa type; }; - template <> - struct vec_adj_list_choose_vertex_pa_helper<vertex_all_t> { - typedef vec_adj_list_all_vertex_pa type; + template <> struct vec_adj_list_choose_vertex_pa_helper< vertex_all_t > + { + typedef vec_adj_list_all_vertex_pa type; }; - template <class Tag, class Graph, class Property> + template < class Tag, class Graph, class Property > struct vec_adj_list_choose_vertex_pa - : vec_adj_list_choose_vertex_pa_helper<Tag>::type::template bind_<Tag,Graph,Property> - {}; - } // namespace detail - - //========================================================================= - // Edge Property Map - - template <class Directed, class Value, class Ref, class Vertex, - class Property, class Tag> - struct adj_list_edge_property_map - : public put_get_helper< - Ref, - adj_list_edge_property_map<Directed, Value, Ref, Vertex, Property, - Tag> - > - { - Tag tag; - explicit adj_list_edge_property_map(Tag tag = Tag()): tag(tag) {} - - typedef Value value_type; - typedef Ref reference; - typedef detail::edge_desc_impl<Directed, Vertex> key_type; - typedef boost::lvalue_property_map_tag category; - inline Ref operator[](key_type e) const { + : vec_adj_list_choose_vertex_pa_helper< Tag >::type::template bind_< Tag, + Graph, Property > + { + }; +} // namespace detail + +//========================================================================= +// Edge Property Map + +template < class Directed, class Value, class Ref, class Vertex, class Property, + class Tag > +struct adj_list_edge_property_map +: public put_get_helper< Ref, + adj_list_edge_property_map< Directed, Value, Ref, Vertex, Property, + Tag > > +{ + Tag tag; + explicit adj_list_edge_property_map(Tag tag = Tag()) : tag(tag) {} + + typedef Value value_type; + typedef Ref reference; + typedef detail::edge_desc_impl< Directed, Vertex > key_type; + typedef boost::lvalue_property_map_tag category; + inline Ref operator[](key_type e) const + { Property& p = *(Property*)e.get_property(); return get_property_value(p, tag); - } - inline Ref operator()(key_type e) const { - return this->operator[](e); - } - }; - - template <class Directed, class Property, class PropRef, class PropPtr, - class Vertex> - struct adj_list_edge_all_properties_map - : public put_get_helper<PropRef, - adj_list_edge_all_properties_map<Directed, Property, PropRef, - PropPtr, Vertex> - > - { - explicit adj_list_edge_all_properties_map(edge_all_t = edge_all_t()) {} - typedef Property value_type; - typedef PropRef reference; - typedef detail::edge_desc_impl<Directed, Vertex> key_type; - typedef boost::lvalue_property_map_tag category; - inline PropRef operator[](key_type e) const { + } + inline Ref operator()(key_type e) const { return this->operator[](e); } +}; + +template < class Directed, class Property, class PropRef, class PropPtr, + class Vertex > +struct adj_list_edge_all_properties_map +: public put_get_helper< PropRef, + adj_list_edge_all_properties_map< Directed, Property, PropRef, PropPtr, + Vertex > > +{ + explicit adj_list_edge_all_properties_map(edge_all_t = edge_all_t()) {} + typedef Property value_type; + typedef PropRef reference; + typedef detail::edge_desc_impl< Directed, Vertex > key_type; + typedef boost::lvalue_property_map_tag category; + inline PropRef operator[](key_type e) const + { return *(PropPtr)e.get_property(); - } - inline PropRef operator()(key_type e) const { - return this->operator[](e); - } - }; - - // Edge Property Maps + } + inline PropRef operator()(key_type e) const { return this->operator[](e); } +}; - namespace detail { - struct adj_list_any_edge_pmap { - template <class Graph, class Property, class Tag> - struct bind_ { - typedef typename property_value<Property,Tag>::type value_type; - typedef value_type& reference; - typedef const value_type& const_reference; +// Edge Property Maps - typedef adj_list_edge_property_map - <typename Graph::directed_category, value_type, reference, - typename Graph::vertex_descriptor,Property,Tag> type; - typedef adj_list_edge_property_map - <typename Graph::directed_category, value_type, const_reference, - typename Graph::vertex_descriptor,const Property, Tag> const_type; - }; +namespace detail +{ + struct adj_list_any_edge_pmap + { + template < class Graph, class Property, class Tag > struct bind_ + { + typedef typename property_value< Property, Tag >::type value_type; + typedef value_type& reference; + typedef const value_type& const_reference; + + typedef adj_list_edge_property_map< + typename Graph::directed_category, value_type, reference, + typename Graph::vertex_descriptor, Property, Tag > + type; + typedef adj_list_edge_property_map< + typename Graph::directed_category, value_type, const_reference, + typename Graph::vertex_descriptor, const Property, Tag > + const_type; + }; }; - struct adj_list_all_edge_pmap { - template <class Graph, class Property, class Tag> - struct bind_ { - typedef adj_list_edge_all_properties_map - <typename Graph::directed_category, Property, Property&, Property*, - typename Graph::vertex_descriptor> type; - typedef adj_list_edge_all_properties_map - <typename Graph::directed_category, Property, const Property&, - const Property*, typename Graph::vertex_descriptor> const_type; - }; + struct adj_list_all_edge_pmap + { + template < class Graph, class Property, class Tag > struct bind_ + { + typedef adj_list_edge_all_properties_map< + typename Graph::directed_category, Property, Property&, + Property*, typename Graph::vertex_descriptor > + type; + typedef adj_list_edge_all_properties_map< + typename Graph::directed_category, Property, const Property&, + const Property*, typename Graph::vertex_descriptor > + const_type; + }; }; - template <class Tag> - struct adj_list_choose_edge_pmap_helper { - typedef adj_list_any_edge_pmap type; + template < class Tag > struct adj_list_choose_edge_pmap_helper + { + typedef adj_list_any_edge_pmap type; }; - template <> - struct adj_list_choose_edge_pmap_helper<edge_all_t> { - typedef adj_list_all_edge_pmap type; + template <> struct adj_list_choose_edge_pmap_helper< edge_all_t > + { + typedef adj_list_all_edge_pmap type; }; - template <class Tag, class Graph, class Property> + template < class Tag, class Graph, class Property > struct adj_list_choose_edge_pmap - : adj_list_choose_edge_pmap_helper<Tag>::type::template bind_<Graph, Property, Tag> - {}; - struct adj_list_edge_property_selector { - template <class Graph, class Property, class Tag> - struct bind_: adj_list_choose_edge_pmap<Tag, Graph, Property> {}; + : adj_list_choose_edge_pmap_helper< Tag >::type::template bind_< Graph, + Property, Tag > + { + }; + struct adj_list_edge_property_selector + { + template < class Graph, class Property, class Tag > + struct bind_ : adj_list_choose_edge_pmap< Tag, Graph, Property > + { + }; }; - } // namespace detail +} // namespace detail - template <> - struct edge_property_selector<adj_list_tag> { +template <> struct edge_property_selector< adj_list_tag > +{ typedef detail::adj_list_edge_property_selector type; - }; - template <> - struct edge_property_selector<vec_adj_list_tag> { +}; +template <> struct edge_property_selector< vec_adj_list_tag > +{ typedef detail::adj_list_edge_property_selector type; - }; - - // Vertex Property Maps - - struct adj_list_vertex_property_selector { - template <class Graph, class Property, class Tag> - struct bind_ - : detail::adj_list_choose_vertex_pa<Tag,Graph,Property> - {}; - }; - template <> - struct vertex_property_selector<adj_list_tag> { +}; + +// Vertex Property Maps + +struct adj_list_vertex_property_selector +{ + template < class Graph, class Property, class Tag > + struct bind_ : detail::adj_list_choose_vertex_pa< Tag, Graph, Property > + { + }; +}; +template <> struct vertex_property_selector< adj_list_tag > +{ typedef adj_list_vertex_property_selector type; - }; - - struct vec_adj_list_vertex_property_selector { - template <class Graph, class Property, class Tag> - struct bind_: detail::vec_adj_list_choose_vertex_pa<Tag,Graph,Property> {}; - }; - template <> - struct vertex_property_selector<vec_adj_list_tag> { +}; + +struct vec_adj_list_vertex_property_selector +{ + template < class Graph, class Property, class Tag > + struct bind_ : detail::vec_adj_list_choose_vertex_pa< Tag, Graph, Property > + { + }; +}; +template <> struct vertex_property_selector< vec_adj_list_tag > +{ typedef vec_adj_list_vertex_property_selector type; - }; +}; } // namespace boost -namespace boost { +namespace boost +{ - template <typename V> - struct hash< boost::detail::stored_edge<V> > - { - std::size_t - operator()(const boost::detail::stored_edge<V>& e) const +template < typename V > struct hash< boost::detail::stored_edge< V > > +{ + std::size_t operator()(const boost::detail::stored_edge< V >& e) const { - return hash<V>()(e.m_target); + return hash< V >()(e.m_target); } - }; +}; - template <typename V, typename P> - struct hash< boost::detail::stored_edge_property <V,P> > - { - std::size_t - operator()(const boost::detail::stored_edge_property<V,P>& e) const +template < typename V, typename P > +struct hash< boost::detail::stored_edge_property< V, P > > +{ + std::size_t operator()( + const boost::detail::stored_edge_property< V, P >& e) const { - return hash<V>()(e.m_target); + return hash< V >()(e.m_target); } - }; +}; - template <typename V, typename I, typename P> - struct hash< boost::detail::stored_edge_iter<V,I, P> > - { - std::size_t - operator()(const boost::detail::stored_edge_iter<V,I,P>& e) const +template < typename V, typename I, typename P > +struct hash< boost::detail::stored_edge_iter< V, I, P > > +{ + std::size_t operator()( + const boost::detail::stored_edge_iter< V, I, P >& e) const { - return hash<V>()(e.m_target); + return hash< V >()(e.m_target); } - }; +}; } - #endif // BOOST_GRAPH_DETAIL_DETAIL_ADJACENCY_LIST_CCT /* diff --git a/contrib/restricted/boost/graph/include/boost/graph/detail/array_binary_tree.hpp b/contrib/restricted/boost/graph/include/boost/graph/detail/array_binary_tree.hpp index fd403d1f30..7d2c4e22c1 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/detail/array_binary_tree.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/detail/array_binary_tree.hpp @@ -14,170 +14,224 @@ #include <iterator> #include <functional> #include <boost/config.hpp> -#include <boost/iterator.hpp> -namespace boost { +namespace boost +{ /* * Note: array_binary_tree is a completey balanced binary tree. */ #if !defined BOOST_NO_STD_ITERATOR_TRAITS - template <class RandomAccessIterator, class ID> +template < class RandomAccessIterator, class ID > #else - template <class RandomAccessIterator, class ValueType, class ID> +template < class RandomAccessIterator, class ValueType, class ID > #endif -class array_binary_tree_node { +class array_binary_tree_node +{ public: - typedef array_binary_tree_node ArrayBinaryTreeNode; - typedef RandomAccessIterator rep_iterator; + typedef array_binary_tree_node ArrayBinaryTreeNode; + typedef RandomAccessIterator rep_iterator; #if !defined BOOST_NO_STD_ITERATOR_TRAITS - typedef typename std::iterator_traits<RandomAccessIterator>::difference_type - difference_type; - typedef typename std::iterator_traits<RandomAccessIterator>::value_type - value_type; + typedef + typename std::iterator_traits< RandomAccessIterator >::difference_type + difference_type; + typedef typename std::iterator_traits< RandomAccessIterator >::value_type + value_type; #else - typedef int difference_type; - typedef ValueType value_type; + typedef int difference_type; + typedef ValueType value_type; #endif - typedef difference_type size_type; + typedef difference_type size_type; - struct children_type { - struct iterator - : boost::iterator<std::bidirectional_iterator_tag, ArrayBinaryTreeNode, - difference_type, array_binary_tree_node*, ArrayBinaryTreeNode&> - { // replace with iterator_adaptor implementation -JGS + struct children_type + { + struct iterator + { // replace with iterator_adaptor implementation -JGS + typedef std::bidirectional_iterator_tag iterator_category; + typedef ArrayBinaryTreeNode value_type; + typedef size_type difference_type; + typedef array_binary_tree_node* pointer; + typedef ArrayBinaryTreeNode& reference; - inline iterator() : i(0), n(0) { } - inline iterator(const iterator& x) : r(x.r), i(x.i), n(x.n), id(x.id) { } - inline iterator& operator=(const iterator& x) { - r = x.r; i = x.i; n = x.n; + inline iterator() : i(0), n(0) {} + inline iterator(const iterator& x) + : r(x.r), i(x.i), n(x.n), id(x.id) + { + } + inline iterator& operator=(const iterator& x) + { + r = x.r; + i = x.i; + n = x.n; + /*egcs generate a warning*/ + id = x.id; + return *this; + } + inline iterator( + rep_iterator rr, size_type ii, size_type nn, const ID& _id) + : r(rr), i(ii), n(nn), id(_id) + { + } + inline array_binary_tree_node operator*() + { + return ArrayBinaryTreeNode(r, i, n, id); + } + inline iterator& operator++() + { + ++i; + return *this; + } + inline iterator operator++(int) + { + iterator t = *this; + ++(*this); + return t; + } + inline iterator& operator--() + { + --i; + return *this; + } + inline iterator operator--(int) + { + iterator t = *this; + --(*this); + return t; + } + inline bool operator==(const iterator& x) const { return i == x.i; } + inline bool operator!=(const iterator& x) const + { + return !(*this == x); + } + rep_iterator r; + size_type i; + size_type n; + ID id; + }; + inline children_type() : i(0), n(0) {} + inline children_type(const children_type& x) + : r(x.r), i(x.i), n(x.n), id(x.id) + { + } + inline children_type& operator=(const children_type& x) + { + r = x.r; + i = x.i; + n = x.n; + /*egcs generate a warning*/ + id = x.id; + return *this; + } + inline children_type( + rep_iterator rr, size_type ii, size_type nn, const ID& _id) + : r(rr), i(ii), n(nn), id(_id) + { + } + inline iterator begin() { return iterator(r, 2 * i + 1, n, id); } + inline iterator end() { return iterator(r, 2 * i + 1 + size(), n, id); } + inline size_type size() const + { + size_type c = 2 * i + 1; + size_type s; + if (c + 1 < n) + s = 2; + else if (c < n) + s = 1; + else + s = 0; + return s; + } + rep_iterator r; + size_type i; + size_type n; + ID id; + }; + inline array_binary_tree_node() : i(0), n(0) {} + inline array_binary_tree_node(const array_binary_tree_node& x) + : r(x.r), i(x.i), n(x.n), id(x.id) + { + } + inline ArrayBinaryTreeNode& operator=(const ArrayBinaryTreeNode& x) + { + r = x.r; + i = x.i; + n = x.n; /*egcs generate a warning*/ id = x.id; return *this; - } - inline iterator(rep_iterator rr, - size_type ii, - size_type nn, - const ID& _id) : r(rr), i(ii), n(nn), id(_id) { } - inline array_binary_tree_node operator*() { - return ArrayBinaryTreeNode(r, i, n, id); } - inline iterator& operator++() { ++i; return *this; } - inline iterator operator++(int) - { iterator t = *this; ++(*this); return t; } - inline iterator& operator--() { --i; return *this; } - inline iterator operator--(int) - { iterator t = *this; --(*this); return t; } - inline bool operator==(const iterator& x) const { return i == x.i; } - inline bool operator!=(const iterator& x) const - { return !(*this == x); } - rep_iterator r; - size_type i; - size_type n; - ID id; - }; - inline children_type() : i(0), n(0) { } - inline children_type(const children_type& x) - : r(x.r), i(x.i), n(x.n), id(x.id) { } - inline children_type& operator=(const children_type& x) { - r = x.r; i = x.i; n = x.n; - /*egcs generate a warning*/ - id = x.id; - return *this; } - inline children_type(rep_iterator rr, - size_type ii, - size_type nn, - const ID& _id) : r(rr), i(ii), n(nn), id(_id) { } - inline iterator begin() { return iterator(r, 2 * i + 1, n, id); } - inline iterator end() { return iterator(r, 2 * i + 1 + size(), n, id); } - inline size_type size() const { - size_type c = 2 * i + 1; - size_type s; - if (c + 1 < n) s = 2; - else if (c < n) s = 1; - else s = 0; - return s; + inline array_binary_tree_node( + rep_iterator start, rep_iterator end, rep_iterator pos, const ID& _id) + : r(start), i(pos - start), n(end - start), id(_id) + { + } + inline array_binary_tree_node( + rep_iterator rr, size_type ii, size_type nn, const ID& _id) + : r(rr), i(ii), n(nn), id(_id) + { + } + inline value_type& value() { return *(r + i); } + inline const value_type& value() const { return *(r + i); } + inline ArrayBinaryTreeNode parent() const + { + return ArrayBinaryTreeNode(r, (i - 1) / 2, n, id); + } + inline bool has_parent() const { return i != 0; } + inline children_type children() { return children_type(r, i, n, id); } + /* + inline void swap(array_binary_tree_node x) { + value_type tmp = x.value(); + x.value() = value(); + value() = tmp; + i = x.i; + } + */ + template < class ExternalData > + inline void swap(ArrayBinaryTreeNode x, ExternalData& edata) + { + using boost::get; + + value_type tmp = x.value(); + + /*swap external data*/ + edata[get(id, tmp)] = i; + edata[get(id, value())] = x.i; + + x.value() = value(); + value() = tmp; + i = x.i; + } + inline const children_type children() const + { + return children_type(r, i, n); } + inline size_type index() const { return i; } rep_iterator r; size_type i; size_type n; ID id; - }; - inline array_binary_tree_node() : i(0), n(0) { } - inline array_binary_tree_node(const array_binary_tree_node& x) - : r(x.r), i(x.i), n(x.n), id(x.id) { } - inline ArrayBinaryTreeNode& operator=(const ArrayBinaryTreeNode& x) { - r = x.r; - i = x.i; - n = x.n; - /*egcs generate a warning*/ - id = x.id; - return *this; - } - inline array_binary_tree_node(rep_iterator start, - rep_iterator end, - rep_iterator pos, const ID& _id) - : r(start), i(pos - start), n(end - start), id(_id) { } - inline array_binary_tree_node(rep_iterator rr, - size_type ii, - size_type nn, const ID& _id) - : r(rr), i(ii), n(nn), id(_id) { } - inline value_type& value() { return *(r + i); } - inline const value_type& value() const { return *(r + i); } - inline ArrayBinaryTreeNode parent() const { - return ArrayBinaryTreeNode(r, (i - 1) / 2, n, id); - } - inline bool has_parent() const { return i != 0; } - inline children_type children() { return children_type(r, i, n, id); } - /* - inline void swap(array_binary_tree_node x) { - value_type tmp = x.value(); - x.value() = value(); - value() = tmp; - i = x.i; - } - */ - template <class ExternalData> - inline void swap(ArrayBinaryTreeNode x, ExternalData& edata ) { - using boost::get; - - value_type tmp = x.value(); - - /*swap external data*/ - edata[ get(id, tmp) ] = i; - edata[ get(id, value()) ] = x.i; - - x.value() = value(); - value() = tmp; - i = x.i; - } - inline const children_type children() const { - return children_type(r, i, n); - } - inline size_type index() const { return i; } - rep_iterator r; - size_type i; - size_type n; - ID id; }; -template <class RandomAccessContainer, - class Compare = std::less<typename RandomAccessContainer::value_type> > -struct compare_array_node { - typedef typename RandomAccessContainer::value_type value_type; - compare_array_node(const Compare& x) : comp(x) {} - compare_array_node(const compare_array_node& x) : comp(x.comp) {} +template < class RandomAccessContainer, + class Compare = std::less< typename RandomAccessContainer::value_type > > +struct compare_array_node +{ + typedef typename RandomAccessContainer::value_type value_type; + compare_array_node(const Compare& x) : comp(x) {} + compare_array_node(const compare_array_node& x) : comp(x.comp) {} - template< class node_type > - inline bool operator()(const node_type& x, const node_type& y) { - return comp(x.value(), y.value()); - } + template < class node_type > + inline bool operator()(const node_type& x, const node_type& y) + { + return comp(x.value(), y.value()); + } - template< class node_type > - inline bool operator()(const node_type& x, const node_type& y) const { - return comp(x.value(), y.value()); - } - Compare comp; + template < class node_type > + inline bool operator()(const node_type& x, const node_type& y) const + { + return comp(x.value(), y.value()); + } + Compare comp; }; } // namespace boost diff --git a/contrib/restricted/boost/graph/include/boost/graph/detail/compressed_sparse_row_struct.hpp b/contrib/restricted/boost/graph/include/boost/graph/detail/compressed_sparse_row_struct.hpp index 6e7b60d74b..a6be13e511 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/detail/compressed_sparse_row_struct.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/detail/compressed_sparse_row_struct.hpp @@ -45,602 +45,695 @@ #include <boost/static_assert.hpp> #include <boost/functional/hash.hpp> -namespace boost { - -namespace detail { - // Forward declaration of CSR edge descriptor type, needed to pass to - // indexed_edge_properties. - template<typename Vertex, typename EdgeIndex> - class csr_edge_descriptor; - - // Add edge_index property map - template<typename Vertex, typename EdgeIndex> - struct csr_edge_index_map - { - typedef EdgeIndex value_type; - typedef EdgeIndex reference; - typedef csr_edge_descriptor<Vertex, EdgeIndex> key_type; - typedef readable_property_map_tag category; - }; - - template<typename Vertex, typename EdgeIndex> - inline EdgeIndex - get(const csr_edge_index_map<Vertex, EdgeIndex>&, - const csr_edge_descriptor<Vertex, EdgeIndex>& key) - { - return key.idx; - } - - /** Compressed sparse row graph internal structure. - * - * Vertex and EdgeIndex should be unsigned integral types and should - * specialize numeric_limits. - */ - template <typename EdgeProperty, - typename Vertex = std::size_t, typename EdgeIndex = Vertex> - class compressed_sparse_row_structure : - public detail::indexed_edge_properties< - compressed_sparse_row_structure<EdgeProperty, Vertex, EdgeIndex>, - EdgeProperty, - csr_edge_descriptor<Vertex, EdgeIndex>, - csr_edge_index_map<Vertex, EdgeIndex> > { - public: - typedef detail::indexed_edge_properties< - compressed_sparse_row_structure<EdgeProperty, Vertex, EdgeIndex>, - EdgeProperty, - csr_edge_descriptor<Vertex, EdgeIndex>, - csr_edge_index_map<Vertex, EdgeIndex> > - inherited_edge_properties; - - typedef Vertex vertices_size_type; - typedef Vertex vertex_descriptor; - typedef EdgeIndex edges_size_type; - - static vertex_descriptor null_vertex() { return vertex_descriptor(-1); } - - std::vector<EdgeIndex> m_rowstart; - std::vector<Vertex> m_column; - - compressed_sparse_row_structure(Vertex numverts = 0) - : m_rowstart(numverts + 1, EdgeIndex(0)), m_column() - {} - - // Rebuild graph from number of vertices and multi-pass unsorted list of - // edges (filtered using source_pred and mapped using global_to_local) - template <typename MultiPassInputIterator, typename GlobalToLocal, typename SourcePred> - void - assign_unsorted_multi_pass_edges(MultiPassInputIterator edge_begin, - MultiPassInputIterator edge_end, - vertices_size_type numlocalverts, - const GlobalToLocal& global_to_local, - const SourcePred& source_pred) { - m_rowstart.clear(); - m_rowstart.resize(numlocalverts + 1, 0); - typedef std::pair<vertices_size_type, vertices_size_type> edge_type; - typedef boost::transform_iterator<boost::graph::detail::project1st<edge_type>, MultiPassInputIterator> source_iterator; - typedef boost::transform_iterator<boost::graph::detail::project2nd<edge_type>, MultiPassInputIterator> target_iterator; - source_iterator sources_begin(edge_begin, boost::graph::detail::project1st<edge_type>()); - source_iterator sources_end(edge_end, boost::graph::detail::project1st<edge_type>()); - target_iterator targets_begin(edge_begin, boost::graph::detail::project2nd<edge_type>()); - target_iterator targets_end(edge_end, boost::graph::detail::project2nd<edge_type>()); - - boost::graph::detail::count_starts - (sources_begin, sources_end, m_rowstart.begin(), numlocalverts, - source_pred, boost::make_property_map_function(global_to_local)); - - m_column.resize(m_rowstart.back()); - inherited_edge_properties::resize(m_rowstart.back()); - - boost::graph::detail::histogram_sort - (sources_begin, sources_end, m_rowstart.begin(), numlocalverts, - targets_begin, m_column.begin(), - source_pred, boost::make_property_map_function(global_to_local)); - } +namespace boost +{ - // Rebuild graph from number of vertices and multi-pass unsorted list of - // edges and their properties (filtered using source_pred and mapped using - // global_to_local) - template <typename MultiPassInputIterator, typename EdgePropertyIterator, typename GlobalToLocal, typename SourcePred> - void - assign_unsorted_multi_pass_edges(MultiPassInputIterator edge_begin, - MultiPassInputIterator edge_end, - EdgePropertyIterator ep_iter, - vertices_size_type numlocalverts, - const GlobalToLocal& global_to_local, - const SourcePred& source_pred) { - m_rowstart.clear(); - m_rowstart.resize(numlocalverts + 1, 0); - typedef std::pair<vertices_size_type, vertices_size_type> edge_type; - typedef boost::transform_iterator<boost::graph::detail::project1st<edge_type>, MultiPassInputIterator> source_iterator; - typedef boost::transform_iterator<boost::graph::detail::project2nd<edge_type>, MultiPassInputIterator> target_iterator; - source_iterator sources_begin(edge_begin, boost::graph::detail::project1st<edge_type>()); - source_iterator sources_end(edge_end, boost::graph::detail::project1st<edge_type>()); - target_iterator targets_begin(edge_begin, boost::graph::detail::project2nd<edge_type>()); - target_iterator targets_end(edge_end, boost::graph::detail::project2nd<edge_type>()); - - boost::graph::detail::count_starts - (sources_begin, sources_end, m_rowstart.begin(), numlocalverts, - source_pred, boost::make_property_map_function(global_to_local)); - - m_column.resize(m_rowstart.back()); - inherited_edge_properties::resize(m_rowstart.back()); - - boost::graph::detail::histogram_sort - (sources_begin, sources_end, m_rowstart.begin(), numlocalverts, - targets_begin, m_column.begin(), - ep_iter, inherited_edge_properties::begin(), - source_pred, boost::make_property_map_function(global_to_local)); - } +namespace detail +{ + // Forward declaration of CSR edge descriptor type, needed to pass to + // indexed_edge_properties. + template < typename Vertex, typename EdgeIndex > class csr_edge_descriptor; - // Assign from number of vertices and sorted list of edges - template<typename InputIterator, typename GlobalToLocal, typename SourcePred> - void assign_from_sorted_edges( - InputIterator edge_begin, InputIterator edge_end, - const GlobalToLocal& global_to_local, - const SourcePred& source_pred, - vertices_size_type numlocalverts, - edges_size_type numedges_or_zero) { - m_column.clear(); - m_column.reserve(numedges_or_zero); - m_rowstart.resize(numlocalverts + 1); - EdgeIndex current_edge = 0; - Vertex current_vertex_plus_one = 1; - m_rowstart[0] = 0; - for (InputIterator ei = edge_begin; ei != edge_end; ++ei) { - if (!source_pred(ei->first)) continue; - Vertex src = get(global_to_local, ei->first); - Vertex tgt = ei->second; - for (; current_vertex_plus_one != src + 1; ++current_vertex_plus_one) - m_rowstart[current_vertex_plus_one] = current_edge; - m_column.push_back(tgt); - ++current_edge; - } - - // The remaining vertices have no edges - for (; current_vertex_plus_one != numlocalverts + 1; ++current_vertex_plus_one) - m_rowstart[current_vertex_plus_one] = current_edge; - - // Default-construct properties for edges - inherited_edge_properties::resize(m_column.size()); + // Add edge_index property map + template < typename Vertex, typename EdgeIndex > struct csr_edge_index_map + { + typedef EdgeIndex value_type; + typedef EdgeIndex reference; + typedef csr_edge_descriptor< Vertex, EdgeIndex > key_type; + typedef readable_property_map_tag category; + }; + + template < typename Vertex, typename EdgeIndex > + inline EdgeIndex get(const csr_edge_index_map< Vertex, EdgeIndex >&, + const csr_edge_descriptor< Vertex, EdgeIndex >& key) + { + return key.idx; } - // Assign from number of vertices and sorted list of edges - template<typename InputIterator, typename EdgePropertyIterator, typename GlobalToLocal, typename SourcePred> - void assign_from_sorted_edges( - InputIterator edge_begin, InputIterator edge_end, - EdgePropertyIterator ep_iter, - const GlobalToLocal& global_to_local, - const SourcePred& source_pred, - vertices_size_type numlocalverts, - edges_size_type numedges_or_zero) { - // Reserving storage in advance can save us lots of time and - // memory, but it can only be done if we have forward iterators or - // the user has supplied the number of edges. - edges_size_type numedges = numedges_or_zero; - if (numedges == 0) { - numedges = boost::graph::detail::reserve_count_for_single_pass(edge_begin, edge_end); - } - m_column.clear(); - m_column.reserve(numedges_or_zero); - inherited_edge_properties::clear(); - inherited_edge_properties::reserve(numedges_or_zero); - m_rowstart.resize(numlocalverts + 1); - EdgeIndex current_edge = 0; - Vertex current_vertex_plus_one = 1; - m_rowstart[0] = 0; - for (InputIterator ei = edge_begin; ei != edge_end; ++ei, ++ep_iter) { - if (!source_pred(ei->first)) continue; - Vertex src = get(global_to_local, ei->first); - Vertex tgt = ei->second; - for (; current_vertex_plus_one != src + 1; ++current_vertex_plus_one) - m_rowstart[current_vertex_plus_one] = current_edge; - m_column.push_back(tgt); - inherited_edge_properties::push_back(*ep_iter); - ++current_edge; - } - - // The remaining vertices have no edges - for (; current_vertex_plus_one != numlocalverts + 1; ++current_vertex_plus_one) - m_rowstart[current_vertex_plus_one] = current_edge; - } + /** Compressed sparse row graph internal structure. + * + * Vertex and EdgeIndex should be unsigned integral types and should + * specialize numeric_limits. + */ + template < typename EdgeProperty, typename Vertex = std::size_t, + typename EdgeIndex = Vertex > + class compressed_sparse_row_structure + : public detail::indexed_edge_properties< + compressed_sparse_row_structure< EdgeProperty, Vertex, EdgeIndex >, + EdgeProperty, csr_edge_descriptor< Vertex, EdgeIndex >, + csr_edge_index_map< Vertex, EdgeIndex > > + { + public: + typedef detail::indexed_edge_properties< + compressed_sparse_row_structure< EdgeProperty, Vertex, EdgeIndex >, + EdgeProperty, csr_edge_descriptor< Vertex, EdgeIndex >, + csr_edge_index_map< Vertex, EdgeIndex > > + inherited_edge_properties; - // Replace graph with sources and targets given, sorting them in-place, and - // using the given global-to-local property map to get local indices from - // global ones in the two arrays. - template <typename GlobalToLocal> - void assign_sources_and_targets_global(std::vector<vertex_descriptor>& sources, - std::vector<vertex_descriptor>& targets, - vertices_size_type numverts, - GlobalToLocal global_to_local) { - BOOST_ASSERT (sources.size() == targets.size()); - // Do an in-place histogram sort (at least that's what I think it is) to - // sort sources and targets - m_rowstart.clear(); - m_rowstart.resize(numverts + 1); - boost::graph::detail::count_starts - (sources.begin(), sources.end(), m_rowstart.begin(), numverts, - keep_all(), boost::make_property_map_function(global_to_local)); - boost::graph::detail::histogram_sort_inplace - (sources.begin(), m_rowstart.begin(), numverts, - targets.begin(), boost::make_property_map_function(global_to_local)); - // Now targets is the correct vector (properly sorted by source) for - // m_column - m_column.swap(targets); - inherited_edge_properties::resize(m_rowstart.back()); - } + typedef Vertex vertices_size_type; + typedef Vertex vertex_descriptor; + typedef EdgeIndex edges_size_type; - // Replace graph with sources and targets and edge properties given, sorting - // them in-place, and using the given global-to-local property map to get - // local indices from global ones in the two arrays. - template <typename GlobalToLocal> - void assign_sources_and_targets_global(std::vector<vertex_descriptor>& sources, - std::vector<vertex_descriptor>& targets, - std::vector<typename inherited_edge_properties::edge_bundled>& edge_props, - vertices_size_type numverts, - GlobalToLocal global_to_local) { - BOOST_ASSERT (sources.size() == targets.size()); - BOOST_ASSERT (sources.size() == edge_props.size()); - // Do an in-place histogram sort (at least that's what I think it is) to - // sort sources and targets - m_rowstart.clear(); - m_rowstart.resize(numverts + 1); - boost::graph::detail::count_starts - (sources.begin(), sources.end(), m_rowstart.begin(), numverts, - keep_all(), boost::make_property_map_function(global_to_local)); - boost::graph::detail::histogram_sort_inplace - (sources.begin(), m_rowstart.begin(), numverts, - targets.begin(), edge_props.begin(), - boost::make_property_map_function(global_to_local)); - // Now targets is the correct vector (properly sorted by source) for - // m_column, and edge_props for m_edge_properties - m_column.swap(targets); - this->m_edge_properties.swap(edge_props); - } + static vertex_descriptor null_vertex() { return vertex_descriptor(-1); } - // From any graph (slow and uses a lot of memory) - // Requires IncidenceGraph and a vertex index map - // Internal helper function - // Note that numedges must be doubled for undirected source graphs - template<typename Graph, typename VertexIndexMap> - void - assign(const Graph& g, const VertexIndexMap& vi, - vertices_size_type numverts, edges_size_type numedges) + std::vector< EdgeIndex > m_rowstart; + std::vector< Vertex > m_column; + + compressed_sparse_row_structure(Vertex numverts = 0) + : m_rowstart(numverts + 1, EdgeIndex(0)), m_column() + { + } + + // Rebuild graph from number of vertices and multi-pass unsorted list + // of edges (filtered using source_pred and mapped using + // global_to_local) + template < typename MultiPassInputIterator, typename GlobalToLocal, + typename SourcePred > + void assign_unsorted_multi_pass_edges(MultiPassInputIterator edge_begin, + MultiPassInputIterator edge_end, vertices_size_type numlocalverts, + const GlobalToLocal& global_to_local, const SourcePred& source_pred) + { + m_rowstart.clear(); + m_rowstart.resize(numlocalverts + 1, 0); + typedef std::pair< vertices_size_type, vertices_size_type > + edge_type; + typedef boost::transform_iterator< + boost::graph::detail::project1st< edge_type >, + MultiPassInputIterator > + source_iterator; + typedef boost::transform_iterator< + boost::graph::detail::project2nd< edge_type >, + MultiPassInputIterator > + target_iterator; + source_iterator sources_begin( + edge_begin, boost::graph::detail::project1st< edge_type >()); + source_iterator sources_end( + edge_end, boost::graph::detail::project1st< edge_type >()); + target_iterator targets_begin( + edge_begin, boost::graph::detail::project2nd< edge_type >()); + target_iterator targets_end( + edge_end, boost::graph::detail::project2nd< edge_type >()); + + boost::graph::detail::count_starts(sources_begin, sources_end, + m_rowstart.begin(), numlocalverts, source_pred, + boost::make_property_map_function(global_to_local)); + + m_column.resize(m_rowstart.back()); + inherited_edge_properties::resize(m_rowstart.back()); + + boost::graph::detail::histogram_sort(sources_begin, sources_end, + m_rowstart.begin(), numlocalverts, targets_begin, + m_column.begin(), source_pred, + boost::make_property_map_function(global_to_local)); + } + + // Rebuild graph from number of vertices and multi-pass unsorted list + // of edges and their properties (filtered using source_pred and mapped + // using global_to_local) + template < typename MultiPassInputIterator, + typename EdgePropertyIterator, typename GlobalToLocal, + typename SourcePred > + void assign_unsorted_multi_pass_edges(MultiPassInputIterator edge_begin, + MultiPassInputIterator edge_end, EdgePropertyIterator ep_iter, + vertices_size_type numlocalverts, + const GlobalToLocal& global_to_local, const SourcePred& source_pred) + { + m_rowstart.clear(); + m_rowstart.resize(numlocalverts + 1, 0); + typedef std::pair< vertices_size_type, vertices_size_type > + edge_type; + typedef boost::transform_iterator< + boost::graph::detail::project1st< edge_type >, + MultiPassInputIterator > + source_iterator; + typedef boost::transform_iterator< + boost::graph::detail::project2nd< edge_type >, + MultiPassInputIterator > + target_iterator; + source_iterator sources_begin( + edge_begin, boost::graph::detail::project1st< edge_type >()); + source_iterator sources_end( + edge_end, boost::graph::detail::project1st< edge_type >()); + target_iterator targets_begin( + edge_begin, boost::graph::detail::project2nd< edge_type >()); + target_iterator targets_end( + edge_end, boost::graph::detail::project2nd< edge_type >()); + + boost::graph::detail::count_starts(sources_begin, sources_end, + m_rowstart.begin(), numlocalverts, source_pred, + boost::make_property_map_function(global_to_local)); + + m_column.resize(m_rowstart.back()); + inherited_edge_properties::resize(m_rowstart.back()); + + boost::graph::detail::histogram_sort(sources_begin, sources_end, + m_rowstart.begin(), numlocalverts, targets_begin, + m_column.begin(), ep_iter, inherited_edge_properties::begin(), + source_pred, + boost::make_property_map_function(global_to_local)); + } + + // Assign from number of vertices and sorted list of edges + template < typename InputIterator, typename GlobalToLocal, + typename SourcePred > + void assign_from_sorted_edges(InputIterator edge_begin, + InputIterator edge_end, const GlobalToLocal& global_to_local, + const SourcePred& source_pred, vertices_size_type numlocalverts, + edges_size_type numedges_or_zero) + { + m_column.clear(); + m_column.reserve(numedges_or_zero); + m_rowstart.resize(numlocalverts + 1); + EdgeIndex current_edge = 0; + Vertex current_vertex_plus_one = 1; + m_rowstart[0] = 0; + for (InputIterator ei = edge_begin; ei != edge_end; ++ei) + { + if (!source_pred(ei->first)) + continue; + Vertex src = get(global_to_local, ei->first); + Vertex tgt = ei->second; + for (; current_vertex_plus_one != src + 1; + ++current_vertex_plus_one) + m_rowstart[current_vertex_plus_one] = current_edge; + m_column.push_back(tgt); + ++current_edge; + } + + // The remaining vertices have no edges + for (; current_vertex_plus_one != numlocalverts + 1; + ++current_vertex_plus_one) + m_rowstart[current_vertex_plus_one] = current_edge; + + // Default-construct properties for edges + inherited_edge_properties::resize(m_column.size()); + } + + // Assign from number of vertices and sorted list of edges + template < typename InputIterator, typename EdgePropertyIterator, + typename GlobalToLocal, typename SourcePred > + void assign_from_sorted_edges(InputIterator edge_begin, + InputIterator edge_end, EdgePropertyIterator ep_iter, + const GlobalToLocal& global_to_local, const SourcePred& source_pred, + vertices_size_type numlocalverts, edges_size_type numedges_or_zero) + { + // Reserving storage in advance can save us lots of time and + // memory, but it can only be done if we have forward iterators or + // the user has supplied the number of edges. + edges_size_type numedges = numedges_or_zero; + if (numedges == 0) + { + numedges = boost::graph::detail::reserve_count_for_single_pass( + edge_begin, edge_end); + } + m_column.clear(); + m_column.reserve(numedges_or_zero); + inherited_edge_properties::clear(); + inherited_edge_properties::reserve(numedges_or_zero); + m_rowstart.resize(numlocalverts + 1); + EdgeIndex current_edge = 0; + Vertex current_vertex_plus_one = 1; + m_rowstart[0] = 0; + for (InputIterator ei = edge_begin; ei != edge_end; ++ei, ++ep_iter) + { + if (!source_pred(ei->first)) + continue; + Vertex src = get(global_to_local, ei->first); + Vertex tgt = ei->second; + for (; current_vertex_plus_one != src + 1; + ++current_vertex_plus_one) + m_rowstart[current_vertex_plus_one] = current_edge; + m_column.push_back(tgt); + inherited_edge_properties::push_back(*ep_iter); + ++current_edge; + } + + // The remaining vertices have no edges + for (; current_vertex_plus_one != numlocalverts + 1; + ++current_vertex_plus_one) + m_rowstart[current_vertex_plus_one] = current_edge; + } + + // Replace graph with sources and targets given, sorting them in-place, + // and using the given global-to-local property map to get local indices + // from global ones in the two arrays. + template < typename GlobalToLocal > + void assign_sources_and_targets_global( + std::vector< vertex_descriptor >& sources, + std::vector< vertex_descriptor >& targets, + vertices_size_type numverts, GlobalToLocal global_to_local) + { + BOOST_ASSERT(sources.size() == targets.size()); + // Do an in-place histogram sort (at least that's what I think it + // is) to sort sources and targets + m_rowstart.clear(); + m_rowstart.resize(numverts + 1); + boost::graph::detail::count_starts(sources.begin(), sources.end(), + m_rowstart.begin(), numverts, keep_all(), + boost::make_property_map_function(global_to_local)); + boost::graph::detail::histogram_sort_inplace(sources.begin(), + m_rowstart.begin(), numverts, targets.begin(), + boost::make_property_map_function(global_to_local)); + // Now targets is the correct vector (properly sorted by source) for + // m_column + m_column.swap(targets); + inherited_edge_properties::resize(m_rowstart.back()); + } + + // Replace graph with sources and targets and edge properties given, + // sorting them in-place, and using the given global-to-local property + // map to get local indices from global ones in the two arrays. + template < typename GlobalToLocal > + void assign_sources_and_targets_global( + std::vector< vertex_descriptor >& sources, + std::vector< vertex_descriptor >& targets, + std::vector< typename inherited_edge_properties::edge_bundled >& + edge_props, + vertices_size_type numverts, GlobalToLocal global_to_local) + { + BOOST_ASSERT(sources.size() == targets.size()); + BOOST_ASSERT(sources.size() == edge_props.size()); + // Do an in-place histogram sort (at least that's what I think it + // is) to sort sources and targets + m_rowstart.clear(); + m_rowstart.resize(numverts + 1); + boost::graph::detail::count_starts(sources.begin(), sources.end(), + m_rowstart.begin(), numverts, keep_all(), + boost::make_property_map_function(global_to_local)); + boost::graph::detail::histogram_sort_inplace(sources.begin(), + m_rowstart.begin(), numverts, targets.begin(), + edge_props.begin(), + boost::make_property_map_function(global_to_local)); + // Now targets is the correct vector (properly sorted by source) for + // m_column, and edge_props for m_edge_properties + m_column.swap(targets); + this->m_edge_properties.swap(edge_props); + } + + // From any graph (slow and uses a lot of memory) + // Requires IncidenceGraph and a vertex index map + // Internal helper function + // Note that numedges must be doubled for undirected source graphs + template < typename Graph, typename VertexIndexMap > + void assign(const Graph& g, const VertexIndexMap& vi, + vertices_size_type numverts, edges_size_type numedges) + { + m_rowstart.resize(numverts + 1); + m_column.resize(numedges); + inherited_edge_properties::resize(numedges); + EdgeIndex current_edge = 0; + typedef typename boost::graph_traits< Graph >::vertex_descriptor + g_vertex; + typedef typename boost::graph_traits< Graph >::out_edge_iterator + g_out_edge_iter; + + std::vector< g_vertex > ordered_verts_of_g(numverts); + BGL_FORALL_VERTICES_T(v, g, Graph) + { + ordered_verts_of_g[get(vertex_index, g, v)] = v; + } + for (Vertex i = 0; i != numverts; ++i) + { + m_rowstart[i] = current_edge; + g_vertex v = ordered_verts_of_g[i]; + g_out_edge_iter ei, ei_end; + for (boost::tie(ei, ei_end) = out_edges(v, g); ei != ei_end; + ++ei) + { + m_column[current_edge++] = get(vi, target(*ei, g)); + } + } + m_rowstart[numverts] = current_edge; + } + + // Add edges from a sorted (smallest sources first) range of pairs and + // edge properties + template < typename BidirectionalIteratorOrig, typename EPIterOrig, + typename GlobalToLocal > + void add_edges_sorted_internal(BidirectionalIteratorOrig first_sorted, + BidirectionalIteratorOrig last_sorted, EPIterOrig ep_iter_sorted, + const GlobalToLocal& global_to_local) + { + typedef boost::reverse_iterator< BidirectionalIteratorOrig > + BidirectionalIterator; + typedef boost::reverse_iterator< EPIterOrig > EPIter; + // Flip sequence + BidirectionalIterator first(last_sorted); + BidirectionalIterator last(first_sorted); + typedef Vertex vertex_num; + typedef EdgeIndex edge_num; + edge_num new_edge_count = std::distance(first, last); + + EPIter ep_iter(ep_iter_sorted); + std::advance(ep_iter, -(std::ptrdiff_t)new_edge_count); + edge_num edges_added_before_i + = new_edge_count; // Count increment to add to rowstarts + m_column.resize(m_column.size() + new_edge_count); + inherited_edge_properties::resize( + inherited_edge_properties::size() + new_edge_count); + BidirectionalIterator current_new_edge = first, + prev_new_edge = first; + EPIter current_new_edge_prop = ep_iter; + for (vertex_num i_plus_1 = m_rowstart.size() - 1; i_plus_1 > 0; + --i_plus_1) + { + vertex_num i = i_plus_1 - 1; + prev_new_edge = current_new_edge; + // edges_added_to_this_vertex = #mbrs of new_edges with first == + // i + edge_num edges_added_to_this_vertex = 0; + while (current_new_edge != last) + { + if (get(global_to_local, current_new_edge->first) != i) + break; + ++current_new_edge; + ++current_new_edge_prop; + ++edges_added_to_this_vertex; + } + edges_added_before_i -= edges_added_to_this_vertex; + // Invariant: edges_added_before_i = #mbrs of new_edges with + // first < i + edge_num old_rowstart = m_rowstart[i]; + edge_num new_rowstart = m_rowstart[i] + edges_added_before_i; + edge_num old_degree = m_rowstart[i + 1] - m_rowstart[i]; + edge_num new_degree = old_degree + edges_added_to_this_vertex; + // Move old edges forward (by #new_edges before this i) to make + // room new_rowstart > old_rowstart, so use copy_backwards + if (old_rowstart != new_rowstart) + { + std::copy_backward(m_column.begin() + old_rowstart, + m_column.begin() + old_rowstart + old_degree, + m_column.begin() + new_rowstart + old_degree); + inherited_edge_properties::move_range( + old_rowstart, old_rowstart + old_degree, new_rowstart); + } + // Add new edges (reversed because current_new_edge is a + // const_reverse_iterator) + BidirectionalIterator temp = current_new_edge; + EPIter temp_prop = current_new_edge_prop; + for (; temp != prev_new_edge; ++old_degree) + { + --temp; + --temp_prop; + m_column[new_rowstart + old_degree] = temp->second; + inherited_edge_properties::write_by_index( + new_rowstart + old_degree, *temp_prop); + } + m_rowstart[i + 1] = new_rowstart + new_degree; + if (edges_added_before_i == 0) + break; // No more edges inserted before this point + // m_rowstart[i] will be fixed up on the next iteration (to + // avoid changing the degree of vertex i - 1); the last + // iteration never changes it (either because of the condition + // of the break or because m_rowstart[0] is always 0) + } + } + }; + + template < typename Vertex, typename EdgeIndex > class csr_edge_descriptor { - m_rowstart.resize(numverts + 1); - m_column.resize(numedges); - inherited_edge_properties::resize(numedges); - EdgeIndex current_edge = 0; - typedef typename boost::graph_traits<Graph>::vertex_descriptor g_vertex; - typedef typename boost::graph_traits<Graph>::out_edge_iterator - g_out_edge_iter; - - std::vector<g_vertex> ordered_verts_of_g(numverts); - BGL_FORALL_VERTICES_T(v, g, Graph) { - ordered_verts_of_g[get(vertex_index, g, v)] = v; - } - for (Vertex i = 0; i != numverts; ++i) { - m_rowstart[i] = current_edge; - g_vertex v = ordered_verts_of_g[i]; - g_out_edge_iter ei, ei_end; - for (boost::tie(ei, ei_end) = out_edges(v, g); ei != ei_end; ++ei) { - m_column[current_edge++] = get(vi, target(*ei, g)); + public: + Vertex src; + EdgeIndex idx; + + csr_edge_descriptor(Vertex src, EdgeIndex idx) : src(src), idx(idx) {} + csr_edge_descriptor() : src(0), idx(0) {} + + bool operator==(const csr_edge_descriptor& e) const + { + return idx == e.idx; } - } - m_rowstart[numverts] = current_edge; - } + bool operator!=(const csr_edge_descriptor& e) const + { + return idx != e.idx; + } + bool operator<(const csr_edge_descriptor& e) const + { + return idx < e.idx; + } + bool operator>(const csr_edge_descriptor& e) const + { + return idx > e.idx; + } + bool operator<=(const csr_edge_descriptor& e) const + { + return idx <= e.idx; + } + bool operator>=(const csr_edge_descriptor& e) const + { + return idx >= e.idx; + } + + template < typename Archiver > + void serialize(Archiver& ar, const unsigned int /*version*/) + { + ar& src& idx; + } + }; + + // Common out edge and edge iterators + template < typename CSRGraph > + class csr_out_edge_iterator + : public iterator_facade< csr_out_edge_iterator< CSRGraph >, + typename CSRGraph::edge_descriptor, std::random_access_iterator_tag, + const typename CSRGraph::edge_descriptor&, + typename int_t< CHAR_BIT + * sizeof(typename CSRGraph::edges_size_type) >::fast > + { + public: + typedef typename CSRGraph::edges_size_type EdgeIndex; + typedef typename CSRGraph::edge_descriptor edge_descriptor; + typedef typename int_t< CHAR_BIT * sizeof(EdgeIndex) >::fast + difference_type; + + csr_out_edge_iterator() {} + // Implicit copy constructor OK + explicit csr_out_edge_iterator(edge_descriptor edge) : m_edge(edge) {} + + public: // GCC 4.2.1 doesn't like the private-and-friend thing + // iterator_facade requirements + const edge_descriptor& dereference() const { return m_edge; } + + bool equal(const csr_out_edge_iterator& other) const + { + return m_edge == other.m_edge; + } + + void increment() { ++m_edge.idx; } + void decrement() { --m_edge.idx; } + void advance(difference_type n) { m_edge.idx += n; } - // Add edges from a sorted (smallest sources first) range of pairs and edge - // properties - template <typename BidirectionalIteratorOrig, typename EPIterOrig, - typename GlobalToLocal> - void - add_edges_sorted_internal( - BidirectionalIteratorOrig first_sorted, - BidirectionalIteratorOrig last_sorted, - EPIterOrig ep_iter_sorted, - const GlobalToLocal& global_to_local) { - typedef boost::reverse_iterator<BidirectionalIteratorOrig> BidirectionalIterator; - typedef boost::reverse_iterator<EPIterOrig> EPIter; - // Flip sequence - BidirectionalIterator first(last_sorted); - BidirectionalIterator last(first_sorted); - typedef Vertex vertex_num; - typedef EdgeIndex edge_num; - edge_num new_edge_count = std::distance(first, last); - - EPIter ep_iter(ep_iter_sorted); - std::advance(ep_iter, -(std::ptrdiff_t)new_edge_count); - edge_num edges_added_before_i = new_edge_count; // Count increment to add to rowstarts - m_column.resize(m_column.size() + new_edge_count); - inherited_edge_properties::resize(inherited_edge_properties::size() + new_edge_count); - BidirectionalIterator current_new_edge = first, prev_new_edge = first; - EPIter current_new_edge_prop = ep_iter; - for (vertex_num i_plus_1 = m_rowstart.size() - 1; i_plus_1 > 0; --i_plus_1) { - vertex_num i = i_plus_1 - 1; - prev_new_edge = current_new_edge; - // edges_added_to_this_vertex = #mbrs of new_edges with first == i - edge_num edges_added_to_this_vertex = 0; - while (current_new_edge != last) { - if (get(global_to_local, current_new_edge->first) != i) break; - ++current_new_edge; - ++current_new_edge_prop; - ++edges_added_to_this_vertex; + difference_type distance_to(const csr_out_edge_iterator& other) const + { + return other.m_edge.idx - m_edge.idx; } - edges_added_before_i -= edges_added_to_this_vertex; - // Invariant: edges_added_before_i = #mbrs of new_edges with first < i - edge_num old_rowstart = m_rowstart[i]; - edge_num new_rowstart = m_rowstart[i] + edges_added_before_i; - edge_num old_degree = m_rowstart[i + 1] - m_rowstart[i]; - edge_num new_degree = old_degree + edges_added_to_this_vertex; - // Move old edges forward (by #new_edges before this i) to make room - // new_rowstart > old_rowstart, so use copy_backwards - if (old_rowstart != new_rowstart) { - std::copy_backward(m_column.begin() + old_rowstart, - m_column.begin() + old_rowstart + old_degree, - m_column.begin() + new_rowstart + old_degree); - inherited_edge_properties::move_range(old_rowstart, old_rowstart + old_degree, new_rowstart); + + edge_descriptor m_edge; + + friend class boost::iterator_core_access; + }; + + template < typename CSRGraph > + class csr_edge_iterator + : public iterator_facade< csr_edge_iterator< CSRGraph >, + typename CSRGraph::edge_descriptor, boost::forward_traversal_tag, + typename CSRGraph::edge_descriptor > + { + private: + typedef typename CSRGraph::edge_descriptor edge_descriptor; + typedef typename CSRGraph::edges_size_type EdgeIndex; + + public: + csr_edge_iterator() + : rowstart_array(0) + , current_edge() + , end_of_this_vertex(0) + , total_num_edges(0) + { } - // Add new edges (reversed because current_new_edge is a - // const_reverse_iterator) - BidirectionalIterator temp = current_new_edge; - EPIter temp_prop = current_new_edge_prop; - for (; temp != prev_new_edge; ++old_degree) { - --temp; - --temp_prop; - m_column[new_rowstart + old_degree] = temp->second; - inherited_edge_properties::write_by_index(new_rowstart + old_degree, *temp_prop); + + csr_edge_iterator(const CSRGraph& graph, edge_descriptor current_edge, + EdgeIndex end_of_this_vertex) + : rowstart_array(&graph.m_forward.m_rowstart[0]) + , current_edge(current_edge) + , end_of_this_vertex(end_of_this_vertex) + , total_num_edges(num_edges(graph)) + { } - m_rowstart[i + 1] = new_rowstart + new_degree; - if (edges_added_before_i == 0) break; // No more edges inserted before this point - // m_rowstart[i] will be fixed up on the next iteration (to avoid - // changing the degree of vertex i - 1); the last iteration never changes - // it (either because of the condition of the break or because - // m_rowstart[0] is always 0) - } - } - }; + public: // See above + friend class boost::iterator_core_access; - template<typename Vertex, typename EdgeIndex> - class csr_edge_descriptor - { - public: - Vertex src; - EdgeIndex idx; + edge_descriptor dereference() const { return current_edge; } - csr_edge_descriptor(Vertex src, EdgeIndex idx): src(src), idx(idx) {} - csr_edge_descriptor(): src(0), idx(0) {} + bool equal(const csr_edge_iterator& o) const + { + return current_edge == o.current_edge; + } - bool operator==(const csr_edge_descriptor& e) const {return idx == e.idx;} - bool operator!=(const csr_edge_descriptor& e) const {return idx != e.idx;} - bool operator<(const csr_edge_descriptor& e) const {return idx < e.idx;} - bool operator>(const csr_edge_descriptor& e) const {return idx > e.idx;} - bool operator<=(const csr_edge_descriptor& e) const {return idx <= e.idx;} - bool operator>=(const csr_edge_descriptor& e) const {return idx >= e.idx;} + void increment() + { + ++current_edge.idx; + if (current_edge.idx == total_num_edges) + return; + while (current_edge.idx == end_of_this_vertex) + { + ++current_edge.src; + end_of_this_vertex = rowstart_array[current_edge.src + 1]; + } + } - template<typename Archiver> - void serialize(Archiver& ar, const unsigned int /*version*/) + const EdgeIndex* rowstart_array; + edge_descriptor current_edge; + EdgeIndex end_of_this_vertex; + EdgeIndex total_num_edges; + }; + + // Only for bidirectional graphs + template < typename CSRGraph > + class csr_in_edge_iterator + : public iterator_facade< csr_in_edge_iterator< CSRGraph >, + typename CSRGraph::edge_descriptor, boost::forward_traversal_tag, + typename CSRGraph::edge_descriptor > { - ar & src & idx; - } - }; - - // Common out edge and edge iterators - template<typename CSRGraph> - class csr_out_edge_iterator - : public iterator_facade<csr_out_edge_iterator<CSRGraph>, - typename CSRGraph::edge_descriptor, - std::random_access_iterator_tag, - const typename CSRGraph::edge_descriptor&, - typename int_t<CHAR_BIT * sizeof(typename CSRGraph::edges_size_type)>::fast> - { - public: - typedef typename CSRGraph::edges_size_type EdgeIndex; - typedef typename CSRGraph::edge_descriptor edge_descriptor; - typedef typename int_t<CHAR_BIT * sizeof(EdgeIndex)>::fast difference_type; - - csr_out_edge_iterator() {} - // Implicit copy constructor OK - explicit csr_out_edge_iterator(edge_descriptor edge) : m_edge(edge) { } - - public: // GCC 4.2.1 doesn't like the private-and-friend thing - // iterator_facade requirements - const edge_descriptor& dereference() const { return m_edge; } - - bool equal(const csr_out_edge_iterator& other) const - { return m_edge == other.m_edge; } - - void increment() { ++m_edge.idx; } - void decrement() { --m_edge.idx; } - void advance(difference_type n) { m_edge.idx += n; } - - difference_type distance_to(const csr_out_edge_iterator& other) const - { return other.m_edge.idx - m_edge.idx; } - - edge_descriptor m_edge; - - friend class iterator_core_access; - }; - - template<typename CSRGraph> - class csr_edge_iterator - : public iterator_facade<csr_edge_iterator<CSRGraph>, - typename CSRGraph::edge_descriptor, - boost::forward_traversal_tag, - typename CSRGraph::edge_descriptor> - { - private: - typedef typename CSRGraph::edge_descriptor edge_descriptor; - typedef typename CSRGraph::edges_size_type EdgeIndex; - - public: - csr_edge_iterator() : rowstart_array(0), current_edge(), end_of_this_vertex(0), total_num_edges(0) {} - - csr_edge_iterator(const CSRGraph& graph, - edge_descriptor current_edge, - EdgeIndex end_of_this_vertex) - : rowstart_array(&graph.m_forward.m_rowstart[0]), - current_edge(current_edge), - end_of_this_vertex(end_of_this_vertex), - total_num_edges(num_edges(graph)) {} - - public: // See above - friend class boost::iterator_core_access; - - edge_descriptor dereference() const {return current_edge;} - - bool equal(const csr_edge_iterator& o) const { - return current_edge == o.current_edge; - } + public: + typedef typename CSRGraph::edges_size_type EdgeIndex; + typedef typename CSRGraph::edge_descriptor edge_descriptor; + + csr_in_edge_iterator() : m_graph(0) {} + // Implicit copy constructor OK + csr_in_edge_iterator( + const CSRGraph& graph, EdgeIndex index_in_backward_graph) + : m_index_in_backward_graph(index_in_backward_graph), m_graph(&graph) + { + } - void increment() { - ++current_edge.idx; - if (current_edge.idx == total_num_edges) return; - while (current_edge.idx == end_of_this_vertex) { - ++current_edge.src; - end_of_this_vertex = rowstart_array[current_edge.src + 1]; - } - } + public: // See above + // iterator_facade requirements + edge_descriptor dereference() const + { + return edge_descriptor( + m_graph->m_backward.m_column[m_index_in_backward_graph], + m_graph->m_backward + .m_edge_properties[m_index_in_backward_graph]); + } - const EdgeIndex* rowstart_array; - edge_descriptor current_edge; - EdgeIndex end_of_this_vertex; - EdgeIndex total_num_edges; - }; - - // Only for bidirectional graphs - template<typename CSRGraph> - class csr_in_edge_iterator - : public iterator_facade<csr_in_edge_iterator<CSRGraph>, - typename CSRGraph::edge_descriptor, - boost::forward_traversal_tag, - typename CSRGraph::edge_descriptor> - { - public: - typedef typename CSRGraph::edges_size_type EdgeIndex; - typedef typename CSRGraph::edge_descriptor edge_descriptor; - - csr_in_edge_iterator(): m_graph(0) {} - // Implicit copy constructor OK - csr_in_edge_iterator(const CSRGraph& graph, - EdgeIndex index_in_backward_graph) - : m_index_in_backward_graph(index_in_backward_graph), m_graph(&graph) {} - - public: // See above - // iterator_facade requirements - edge_descriptor dereference() const { - return edge_descriptor( - m_graph->m_backward.m_column[m_index_in_backward_graph], - m_graph->m_backward.m_edge_properties[m_index_in_backward_graph]); - } + bool equal(const csr_in_edge_iterator& other) const + { + return m_index_in_backward_graph == other.m_index_in_backward_graph; + } - bool equal(const csr_in_edge_iterator& other) const - { return m_index_in_backward_graph == other.m_index_in_backward_graph; } + void increment() { ++m_index_in_backward_graph; } + void decrement() { --m_index_in_backward_graph; } + void advance(std::ptrdiff_t n) { m_index_in_backward_graph += n; } - void increment() { ++m_index_in_backward_graph; } - void decrement() { --m_index_in_backward_graph; } - void advance(std::ptrdiff_t n) { m_index_in_backward_graph += n; } + std::ptrdiff_t distance_to(const csr_in_edge_iterator& other) const + { + return other.m_index_in_backward_graph - m_index_in_backward_graph; + } - std::ptrdiff_t distance_to(const csr_in_edge_iterator& other) const - { return other.m_index_in_backward_graph - m_index_in_backward_graph; } + EdgeIndex m_index_in_backward_graph; + const CSRGraph* m_graph; - EdgeIndex m_index_in_backward_graph; - const CSRGraph* m_graph; + friend class boost::iterator_core_access; + }; - friend class iterator_core_access; - }; + template < typename A, typename B > struct transpose_pair + { + typedef std::pair< B, A > result_type; + result_type operator()(const std::pair< A, B >& p) const + { + return result_type(p.second, p.first); + } + }; - template <typename A, typename B> - struct transpose_pair { - typedef std::pair<B, A> result_type; - result_type operator()(const std::pair<A, B>& p) const { - return result_type(p.second, p.first); - } - }; - - template <typename Iter> - struct transpose_iterator_gen { - typedef typename std::iterator_traits<Iter>::value_type vt; - typedef typename vt::first_type first_type; - typedef typename vt::second_type second_type; - typedef transpose_pair<first_type, second_type> transpose; - typedef boost::transform_iterator<transpose, Iter> type; - static type make(Iter it) { - return type(it, transpose()); + template < typename Iter > struct transpose_iterator_gen + { + typedef typename std::iterator_traits< Iter >::value_type vt; + typedef typename vt::first_type first_type; + typedef typename vt::second_type second_type; + typedef transpose_pair< first_type, second_type > transpose; + typedef boost::transform_iterator< transpose, Iter > type; + static type make(Iter it) { return type(it, transpose()); } + }; + + template < typename Iter > + typename transpose_iterator_gen< Iter >::type transpose_edges(Iter i) + { + return transpose_iterator_gen< Iter >::make(i); } - }; - template <typename Iter> - typename transpose_iterator_gen<Iter>::type transpose_edges(Iter i) { - return transpose_iterator_gen<Iter>::make(i); - } + template < typename GraphT, typename VertexIndexMap > + class edge_to_index_pair + { + typedef typename boost::graph_traits< GraphT >::vertices_size_type + vertices_size_type; + typedef typename boost::graph_traits< GraphT >::edge_descriptor + edge_descriptor; - template<typename GraphT, typename VertexIndexMap> - class edge_to_index_pair - { - typedef typename boost::graph_traits<GraphT>::vertices_size_type - vertices_size_type; - typedef typename boost::graph_traits<GraphT>::edge_descriptor edge_descriptor; + public: + typedef std::pair< vertices_size_type, vertices_size_type > result_type; - public: - typedef std::pair<vertices_size_type, vertices_size_type> result_type; + edge_to_index_pair() : g(0), index() {} + edge_to_index_pair(const GraphT& g, const VertexIndexMap& index) + : g(&g), index(index) + { + } - edge_to_index_pair() : g(0), index() { } - edge_to_index_pair(const GraphT& g, const VertexIndexMap& index) - : g(&g), index(index) - { } + result_type operator()(edge_descriptor e) const + { + return result_type( + get(index, source(e, *g)), get(index, target(e, *g))); + } - result_type operator()(edge_descriptor e) const + private: + const GraphT* g; + VertexIndexMap index; + }; + + template < typename GraphT, typename VertexIndexMap > + edge_to_index_pair< GraphT, VertexIndexMap > make_edge_to_index_pair( + const GraphT& g, const VertexIndexMap& index) { - return result_type(get(index, source(e, *g)), get(index, target(e, *g))); + return edge_to_index_pair< GraphT, VertexIndexMap >(g, index); } - private: - const GraphT* g; - VertexIndexMap index; - }; - - template<typename GraphT, typename VertexIndexMap> - edge_to_index_pair<GraphT, VertexIndexMap> - make_edge_to_index_pair(const GraphT& g, const VertexIndexMap& index) - { - return edge_to_index_pair<GraphT, VertexIndexMap>(g, index); - } - - template<typename GraphT> - edge_to_index_pair - <GraphT, - typename boost::property_map<GraphT,boost::vertex_index_t>::const_type> - make_edge_to_index_pair(const GraphT& g) - { - typedef typename boost::property_map<GraphT, - boost::vertex_index_t>::const_type - VertexIndexMap; - return edge_to_index_pair<GraphT, VertexIndexMap>(g, - get(boost::vertex_index, - g)); - } - - template<typename GraphT, typename VertexIndexMap, typename Iter> - boost::transform_iterator<edge_to_index_pair<GraphT, VertexIndexMap>, Iter> - make_edge_to_index_pair_iter(const GraphT& g, const VertexIndexMap& index, - Iter it) { - return boost::transform_iterator<edge_to_index_pair<GraphT, VertexIndexMap>, Iter>(it, edge_to_index_pair<GraphT, VertexIndexMap>(g, index)); - } + template < typename GraphT > + edge_to_index_pair< GraphT, + typename boost::property_map< GraphT, + boost::vertex_index_t >::const_type > + make_edge_to_index_pair(const GraphT& g) + { + typedef typename boost::property_map< GraphT, + boost::vertex_index_t >::const_type VertexIndexMap; + return edge_to_index_pair< GraphT, VertexIndexMap >( + g, get(boost::vertex_index, g)); + } + + template < typename GraphT, typename VertexIndexMap, typename Iter > + boost::transform_iterator< edge_to_index_pair< GraphT, VertexIndexMap >, + Iter > + make_edge_to_index_pair_iter( + const GraphT& g, const VertexIndexMap& index, Iter it) + { + return boost::transform_iterator< + edge_to_index_pair< GraphT, VertexIndexMap >, Iter >( + it, edge_to_index_pair< GraphT, VertexIndexMap >(g, index)); + } } // namespace detail - template<typename Vertex, typename EdgeIndex> - struct hash<detail::csr_edge_descriptor<Vertex, EdgeIndex> > - { - std::size_t operator() - (detail::csr_edge_descriptor<Vertex, EdgeIndex> const& x) const +template < typename Vertex, typename EdgeIndex > +struct hash< detail::csr_edge_descriptor< Vertex, EdgeIndex > > +{ + std::size_t operator()( + detail::csr_edge_descriptor< Vertex, EdgeIndex > const& x) const { - std::size_t hash = hash_value(x.src); - hash_combine(hash, x.idx); - return hash; + std::size_t hash = hash_value(x.src); + hash_combine(hash, x.idx); + return hash; } - }; +}; } // namespace boost diff --git a/contrib/restricted/boost/graph/include/boost/graph/detail/d_ary_heap.hpp b/contrib/restricted/boost/graph/include/boost/graph/detail/d_ary_heap.hpp index cf930fc187..7c423dcac2 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/detail/d_ary_heap.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/detail/d_ary_heap.hpp @@ -25,160 +25,172 @@ // (without move support from C++11), but it deep-copies the heap contents yet // shallow-copies the index_in_heap_map. -namespace boost { +namespace boost +{ - // Swap two elements in a property map without assuming they model - // LvaluePropertyMap -- currently not used - template <typename PropMap> - inline void property_map_swap( - PropMap prop_map, - const typename boost::property_traits<PropMap>::key_type& ka, - const typename boost::property_traits<PropMap>::key_type& kb) { - typename boost::property_traits<PropMap>::value_type va = get(prop_map, ka); +// Swap two elements in a property map without assuming they model +// LvaluePropertyMap -- currently not used +template < typename PropMap > +inline void property_map_swap(PropMap prop_map, + const typename boost::property_traits< PropMap >::key_type& ka, + const typename boost::property_traits< PropMap >::key_type& kb) +{ + typename boost::property_traits< PropMap >::value_type va + = get(prop_map, ka); put(prop_map, ka, get(prop_map, kb)); put(prop_map, kb, va); - } +} - namespace detail { - template <typename Value> - class fixed_max_size_vector { - boost::shared_array<Value> m_data; - std::size_t m_size; +namespace detail +{ + template < typename Value > class fixed_max_size_vector + { + boost::shared_array< Value > m_data; + std::size_t m_size; - public: - typedef std::size_t size_type; - fixed_max_size_vector(std::size_t max_size) - : m_data(new Value[max_size]), m_size(0) {} - std::size_t size() const {return m_size;} - bool empty() const {return m_size == 0;} - Value& operator[](std::size_t i) {return m_data[i];} - const Value& operator[](std::size_t i) const {return m_data[i];} - void push_back(Value v) {m_data[m_size++] = v;} - void pop_back() {--m_size;} - Value& back() {return m_data[m_size - 1];} - const Value& back() const {return m_data[m_size - 1];} + public: + typedef std::size_t size_type; + fixed_max_size_vector(std::size_t max_size) + : m_data(new Value[max_size]), m_size(0) + { + } + std::size_t size() const { return m_size; } + bool empty() const { return m_size == 0; } + Value& operator[](std::size_t i) { return m_data[i]; } + const Value& operator[](std::size_t i) const { return m_data[i]; } + void push_back(Value v) { m_data[m_size++] = v; } + void pop_back() { --m_size; } + Value& back() { return m_data[m_size - 1]; } + const Value& back() const { return m_data[m_size - 1]; } }; - } +} - // D-ary heap using an indirect compare operator (use identity_property_map - // as DistanceMap to get a direct compare operator). This heap appears to be - // commonly used for Dijkstra's algorithm for its good practical performance - // on some platforms; asymptotically, it has an O(lg N) decrease-key - // operation while that can be done in constant time on a relaxed heap. The - // implementation is mostly based on the binary heap page on Wikipedia and - // online sources that state that the operations are the same for d-ary - // heaps. This code is not based on the old Boost d-ary heap code. - // - // - d_ary_heap_indirect is a model of UpdatableQueue as is needed for - // dijkstra_shortest_paths. - // - // - Value must model Assignable. - // - Arity must be at least 2 (optimal value appears to be 4, both in my and - // third-party experiments). - // - IndexInHeapMap must be a ReadWritePropertyMap from Value to - // Container::size_type (to store the index of each stored value within the - // heap for decrease-key aka update). - // - DistanceMap must be a ReadablePropertyMap from Value to something - // (typedef'ed as distance_type). - // - Compare must be a BinaryPredicate used as a less-than operator on - // distance_type. - // - Container must be a random-access, contiguous container (in practice, - // the operations used probably require that it is std::vector<Value>). - // - template <typename Value, - std::size_t Arity, - typename IndexInHeapPropertyMap, - typename DistanceMap, - typename Compare = std::less<Value>, - typename Container = std::vector<Value> > - class d_ary_heap_indirect { - BOOST_STATIC_ASSERT (Arity >= 2); +// D-ary heap using an indirect compare operator (use identity_property_map +// as DistanceMap to get a direct compare operator). This heap appears to be +// commonly used for Dijkstra's algorithm for its good practical performance +// on some platforms; asymptotically, it has an O(lg N) decrease-key +// operation while that can be done in constant time on a relaxed heap. The +// implementation is mostly based on the binary heap page on Wikipedia and +// online sources that state that the operations are the same for d-ary +// heaps. This code is not based on the old Boost d-ary heap code. +// +// - d_ary_heap_indirect is a model of UpdatableQueue as is needed for +// dijkstra_shortest_paths. +// +// - Value must model Assignable. +// - Arity must be at least 2 (optimal value appears to be 4, both in my and +// third-party experiments). +// - IndexInHeapMap must be a ReadWritePropertyMap from Value to +// Container::size_type (to store the index of each stored value within the +// heap for decrease-key aka update). +// - DistanceMap must be a ReadablePropertyMap from Value to something +// (typedef'ed as distance_type). +// - Compare must be a BinaryPredicate used as a less-than operator on +// distance_type. +// - Container must be a random-access, contiguous container (in practice, +// the operations used probably require that it is std::vector<Value>). +// +template < typename Value, std::size_t Arity, typename IndexInHeapPropertyMap, + typename DistanceMap, typename Compare = std::less< Value >, + typename Container = std::vector< Value > > +class d_ary_heap_indirect +{ + BOOST_STATIC_ASSERT(Arity >= 2); - public: +public: typedef typename Container::size_type size_type; typedef Value value_type; - typedef typename boost::property_traits<DistanceMap>::value_type key_type; + typedef typename boost::property_traits< DistanceMap >::value_type key_type; typedef DistanceMap key_map; d_ary_heap_indirect(DistanceMap distance, - IndexInHeapPropertyMap index_in_heap, - const Compare& compare = Compare(), - const Container& data = Container()) - : compare(compare), data(data), distance(distance), - index_in_heap(index_in_heap) {} + IndexInHeapPropertyMap index_in_heap, + const Compare& compare = Compare(), const Container& data = Container()) + : compare(compare) + , data(data) + , distance(distance) + , index_in_heap(index_in_heap) + { + } /* Implicit copy constructor */ /* Implicit assignment operator */ - size_type size() const { - return data.size(); - } + size_type size() const { return data.size(); } - bool empty() const { - return data.empty(); - } + bool empty() const { return data.empty(); } - void push(const Value& v) { - size_type index = data.size(); - data.push_back(v); - put(index_in_heap, v, index); - preserve_heap_property_up(index); - verify_heap(); + void push(const Value& v) + { + size_type index = data.size(); + data.push_back(v); + put(index_in_heap, v, index); + preserve_heap_property_up(index); + verify_heap(); } - Value& top() { - BOOST_ASSERT (!this->empty()); - return data[0]; + Value& top() + { + BOOST_ASSERT(!this->empty()); + return data[0]; } - const Value& top() const { - BOOST_ASSERT (!this->empty()); - return data[0]; + const Value& top() const + { + BOOST_ASSERT(!this->empty()); + return data[0]; } - void pop() { - BOOST_ASSERT (!this->empty()); - put(index_in_heap, data[0], (size_type)(-1)); - if (data.size() != 1) { - data[0] = data.back(); - put(index_in_heap, data[0], (size_type)(0)); - data.pop_back(); - preserve_heap_property_down(); - verify_heap(); - } else { - data.pop_back(); - } + void pop() + { + BOOST_ASSERT(!this->empty()); + put(index_in_heap, data[0], (size_type)(-1)); + if (data.size() != 1) + { + data[0] = data.back(); + put(index_in_heap, data[0], (size_type)(0)); + data.pop_back(); + preserve_heap_property_down(); + verify_heap(); + } + else + { + data.pop_back(); + } } // This function assumes the key has been updated (using an external write // to the distance map or such) - // See http://coding.derkeiler.com/Archive/General/comp.theory/2007-05/msg00043.html - void update(const Value& v) { /* decrease-key */ - size_type index = get(index_in_heap, v); - preserve_heap_property_up(index); - verify_heap(); + // See + // http://coding.derkeiler.com/Archive/General/comp.theory/2007-05/msg00043.html + void update(const Value& v) + { /* decrease-key */ + size_type index = get(index_in_heap, v); + preserve_heap_property_up(index); + verify_heap(); } - bool contains(const Value& v) const { - size_type index = get(index_in_heap, v); - return (index != (size_type)(-1)); + bool contains(const Value& v) const + { + size_type index = get(index_in_heap, v); + return (index != (size_type)(-1)); } - void push_or_update(const Value& v) { /* insert if not present, else update */ - size_type index = get(index_in_heap, v); - if (index == (size_type)(-1)) { - index = data.size(); - data.push_back(v); - put(index_in_heap, v, index); - } - preserve_heap_property_up(index); - verify_heap(); + void push_or_update(const Value& v) + { /* insert if not present, else update */ + size_type index = get(index_in_heap, v); + if (index == (size_type)(-1)) + { + index = data.size(); + data.push_back(v); + put(index_in_heap, v, index); + } + preserve_heap_property_up(index); + verify_heap(); } - DistanceMap keys() const { - return distance; - } + DistanceMap keys() const { return distance; } - private: +private: Compare compare; Container data; DistanceMap distance; @@ -186,38 +198,41 @@ namespace boost { // The distances being compared using compare and that are stored in the // distance map - typedef typename boost::property_traits<DistanceMap>::value_type distance_type; + typedef typename boost::property_traits< DistanceMap >::value_type + distance_type; // Get the parent of a given node in the heap - static size_type parent(size_type index) { - return (index - 1) / Arity; - } + static size_type parent(size_type index) { return (index - 1) / Arity; } - // Get the child_idx'th child of a given node; 0 <= child_idx < Arity - static size_type child(size_type index, std::size_t child_idx) { - return index * Arity + child_idx + 1; + // Get the first child of a given node + static size_type first_child(size_type index) + { + return index * Arity + 1; } // Swap two elements in the heap by index, updating index_in_heap - void swap_heap_elements(size_type index_a, size_type index_b) { - using std::swap; - Value value_a = data[index_a]; - Value value_b = data[index_b]; - data[index_a] = value_b; - data[index_b] = value_a; - put(index_in_heap, value_a, index_b); - put(index_in_heap, value_b, index_a); + void swap_heap_elements(size_type index_a, size_type index_b) + { + using std::swap; + Value value_a = data[index_a]; + Value value_b = data[index_b]; + data[index_a] = value_b; + data[index_b] = value_a; + put(index_in_heap, value_a, index_b); + put(index_in_heap, value_b, index_a); } // Emulate the indirect_cmp that is now folded into this heap class - bool compare_indirect(const Value& a, const Value& b) const { - return compare(get(distance, a), get(distance, b)); + bool compare_indirect(const Value& a, const Value& b) const + { + return compare(get(distance, a), get(distance, b)); } // Verify that the array forms a heap; commented out by default - void verify_heap() const { - // This is a very expensive test so it should be disabled even when - // NDEBUG is not defined + void verify_heap() const + { + // This is a very expensive test so it should be disabled even when + // NDEBUG is not defined #if 0 for (size_t i = 1; i < data.size(); ++i) { if (compare_indirect(data[i], data[parent(i)])) { @@ -229,90 +244,114 @@ namespace boost { // Starting at a node, move up the tree swapping elements to preserve the // heap property - void preserve_heap_property_up(size_type index) { - size_type orig_index = index; - size_type num_levels_moved = 0; - // The first loop just saves swaps that need to be done in order to avoid - // aliasing issues in its search; there is a second loop that does the - // necessary swap operations - if (index == 0) return; // Do nothing on root - Value currently_being_moved = data[index]; - distance_type currently_being_moved_dist = - get(distance, currently_being_moved); - for (;;) { - if (index == 0) break; // Stop at root - size_type parent_index = parent(index); - Value parent_value = data[parent_index]; - if (compare(currently_being_moved_dist, get(distance, parent_value))) { - ++num_levels_moved; - index = parent_index; - continue; - } else { - break; // Heap property satisfied + void preserve_heap_property_up(size_type index) + { + size_type orig_index = index; + size_type num_levels_moved = 0; + // The first loop just saves swaps that need to be done in order to + // avoid aliasing issues in its search; there is a second loop that does + // the necessary swap operations + if (index == 0) + return; // Do nothing on root + Value currently_being_moved = data[index]; + distance_type currently_being_moved_dist + = get(distance, currently_being_moved); + for (;;) + { + if (index == 0) + break; // Stop at root + size_type parent_index = parent(index); + Value parent_value = data[parent_index]; + if (compare( + currently_being_moved_dist, get(distance, parent_value))) + { + ++num_levels_moved; + index = parent_index; + continue; + } + else + { + break; // Heap property satisfied + } } - } - // Actually do the moves -- move num_levels_moved elements down in the - // tree, then put currently_being_moved at the top - index = orig_index; - for (size_type i = 0; i < num_levels_moved; ++i) { - size_type parent_index = parent(index); - Value parent_value = data[parent_index]; - put(index_in_heap, parent_value, index); - data[index] = parent_value; - index = parent_index; - } - data[index] = currently_being_moved; - put(index_in_heap, currently_being_moved, index); - verify_heap(); + // Actually do the moves -- move num_levels_moved elements down in the + // tree, then put currently_being_moved at the top + index = orig_index; + for (size_type i = 0; i < num_levels_moved; ++i) + { + size_type parent_index = parent(index); + Value parent_value = data[parent_index]; + put(index_in_heap, parent_value, index); + data[index] = parent_value; + index = parent_index; + } + data[index] = currently_being_moved; + put(index_in_heap, currently_being_moved, index); + verify_heap(); } // From the root, swap elements (each one with its smallest child) if there // are any parent-child pairs that violate the heap property - void preserve_heap_property_down() { - if (data.empty()) return; - size_type index = 0; - Value currently_being_moved = data[0]; - distance_type currently_being_moved_dist = - get(distance, currently_being_moved); - size_type heap_size = data.size(); - Value* data_ptr = &data[0]; - for (;;) { - size_type first_child_index = child(index, 0); - if (first_child_index >= heap_size) break; /* No children */ - Value* child_base_ptr = data_ptr + first_child_index; - size_type smallest_child_index = 0; - distance_type smallest_child_dist = get(distance, child_base_ptr[smallest_child_index]); - if (first_child_index + Arity <= heap_size) { - // Special case for a statically known loop count (common case) - for (size_t i = 1; i < Arity; ++i) { - Value i_value = child_base_ptr[i]; - distance_type i_dist = get(distance, i_value); - if (compare(i_dist, smallest_child_dist)) { - smallest_child_index = i; - smallest_child_dist = i_dist; + void preserve_heap_property_down() + { + if (data.empty()) + return; + size_type index = 0; + Value currently_being_moved = data[0]; + distance_type currently_being_moved_dist + = get(distance, currently_being_moved); + size_type heap_size = data.size(); + Value* data_ptr = &data[0]; + for (;;) + { + size_type first_child_index = first_child(index); + if (first_child_index >= heap_size) + break; /* No children */ + Value* child_base_ptr = data_ptr + first_child_index; + size_type smallest_child_index = 0; + distance_type smallest_child_dist + = get(distance, child_base_ptr[smallest_child_index]); + if (first_child_index + Arity <= heap_size) + { + // Special case for a statically known loop count (common case) + for (size_t i = 1; i < Arity; ++i) + { + Value i_value = child_base_ptr[i]; + distance_type i_dist = get(distance, i_value); + if (compare(i_dist, smallest_child_dist)) + { + smallest_child_index = i; + smallest_child_dist = i_dist; + } + } } - } - } else { - for (size_t i = 1; i < heap_size - first_child_index; ++i) { - distance_type i_dist = get(distance, child_base_ptr[i]); - if (compare(i_dist, smallest_child_dist)) { - smallest_child_index = i; - smallest_child_dist = i_dist; + else + { + for (size_t i = 1; i < heap_size - first_child_index; ++i) + { + distance_type i_dist = get(distance, child_base_ptr[i]); + if (compare(i_dist, smallest_child_dist)) + { + smallest_child_index = i; + smallest_child_dist = i_dist; + } + } + } + if (compare(smallest_child_dist, currently_being_moved_dist)) + { + swap_heap_elements( + smallest_child_index + first_child_index, index); + index = smallest_child_index + first_child_index; + continue; + } + else + { + break; // Heap property satisfied } - } - } - if (compare(smallest_child_dist, currently_being_moved_dist)) { - swap_heap_elements(smallest_child_index + first_child_index, index); - index = smallest_child_index + first_child_index; - continue; - } else { - break; // Heap property satisfied } - } - verify_heap(); + verify_heap(); } - - }; +}; } // namespace boost diff --git a/contrib/restricted/boost/graph/include/boost/graph/detail/edge.hpp b/contrib/restricted/boost/graph/include/boost/graph/detail/edge.hpp index 3aba9f8d96..33cb305ec2 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/detail/edge.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/detail/edge.hpp @@ -15,107 +15,108 @@ #include <boost/functional/hash.hpp> -namespace boost { +namespace boost +{ - namespace detail { +namespace detail +{ - template <typename Directed, typename Vertex> - struct edge_base + template < typename Directed, typename Vertex > struct edge_base { - inline edge_base() {} - inline edge_base(Vertex s, Vertex d) - : m_source(s), m_target(d) { } - Vertex m_source; - Vertex m_target; + inline edge_base() {} + inline edge_base(Vertex s, Vertex d) : m_source(s), m_target(d) {} + Vertex m_source; + Vertex m_target; }; - template <typename Directed, typename Vertex> - class edge_desc_impl : public edge_base<Directed,Vertex> { - typedef edge_desc_impl self; - typedef edge_base<Directed,Vertex> Base; - public: - typedef void property_type; - - inline edge_desc_impl() : m_eproperty(0) {} - - inline edge_desc_impl(Vertex s, Vertex d, const property_type* eplug) - : Base(s,d), m_eproperty(const_cast<property_type*>(eplug)) { } - - property_type* get_property() { return m_eproperty; } - const property_type* get_property() const { return m_eproperty; } - - // protected: - property_type* m_eproperty; + template < typename Directed, typename Vertex > + class edge_desc_impl : public edge_base< Directed, Vertex > + { + typedef edge_desc_impl self; + typedef edge_base< Directed, Vertex > Base; + + public: + typedef void property_type; + + inline edge_desc_impl() : m_eproperty(0) {} + + inline edge_desc_impl(Vertex s, Vertex d, const property_type* eplug) + : Base(s, d), m_eproperty(const_cast< property_type* >(eplug)) + { + } + + property_type* get_property() { return m_eproperty; } + const property_type* get_property() const { return m_eproperty; } + + // protected: + property_type* m_eproperty; }; - template <class D, class V> - inline bool - operator==(const detail::edge_desc_impl<D,V>& a, - const detail::edge_desc_impl<D,V>& b) + template < class D, class V > + inline bool operator==(const detail::edge_desc_impl< D, V >& a, + const detail::edge_desc_impl< D, V >& b) { - return a.get_property() == b.get_property(); + return a.get_property() == b.get_property(); } - template <class D, class V> - inline bool - operator!=(const detail::edge_desc_impl<D,V>& a, - const detail::edge_desc_impl<D,V>& b) + template < class D, class V > + inline bool operator!=(const detail::edge_desc_impl< D, V >& a, + const detail::edge_desc_impl< D, V >& b) { - return ! (a.get_property() == b.get_property()); + return !(a.get_property() == b.get_property()); } // Order edges according to the address of their property object - template <class D, class V> - inline bool - operator<(const detail::edge_desc_impl<D,V>& a, - const detail::edge_desc_impl<D,V>& b) + template < class D, class V > + inline bool operator<(const detail::edge_desc_impl< D, V >& a, + const detail::edge_desc_impl< D, V >& b) { - return a.get_property() < b.get_property(); + return a.get_property() < b.get_property(); } - template <class D, class V> - inline bool - operator<=(const detail::edge_desc_impl<D,V>& a, - const detail::edge_desc_impl<D,V>& b) + template < class D, class V > + inline bool operator<=(const detail::edge_desc_impl< D, V >& a, + const detail::edge_desc_impl< D, V >& b) { - return a.get_property() <= b.get_property(); + return a.get_property() <= b.get_property(); } - template <class D, class V> - inline bool - operator>(const detail::edge_desc_impl<D,V>& a, - const detail::edge_desc_impl<D,V>& b) + template < class D, class V > + inline bool operator>(const detail::edge_desc_impl< D, V >& a, + const detail::edge_desc_impl< D, V >& b) { - return a.get_property() > b.get_property(); + return a.get_property() > b.get_property(); } - template <class D, class V> - inline bool - operator>=(const detail::edge_desc_impl<D,V>& a, - const detail::edge_desc_impl<D,V>& b) + template < class D, class V > + inline bool operator>=(const detail::edge_desc_impl< D, V >& a, + const detail::edge_desc_impl< D, V >& b) { - return a.get_property() >= b.get_property(); + return a.get_property() >= b.get_property(); } - } //namespace detail - +} // namespace detail + } // namespace boost -namespace std { - template <class Char, class Traits, class D, class V> - std::basic_ostream<Char, Traits>& - operator<<(std::basic_ostream<Char, Traits>& os, - const boost::detail::edge_desc_impl<D,V>& e) - { +namespace std +{ +template < class Char, class Traits, class D, class V > +std::basic_ostream< Char, Traits >& operator<<( + std::basic_ostream< Char, Traits >& os, + const boost::detail::edge_desc_impl< D, V >& e) +{ return os << "(" << e.m_source << "," << e.m_target << ")"; - } +} } // Boost's functional/hash -namespace boost { - template<typename D, typename V> - struct hash<boost::detail::edge_desc_impl<D, V> > - { - std::size_t operator()(const boost::detail::edge_desc_impl<D, V> & x) const - { return hash_value(x.get_property()); } - }; +namespace boost +{ +template < typename D, typename V > +struct hash< boost::detail::edge_desc_impl< D, V > > +{ + std::size_t operator()(const boost::detail::edge_desc_impl< D, V >& x) const + { + return hash_value(x.get_property()); + } +}; } - #endif // BOOST_GRAPH_DETAIL_DETAIL_EDGE_HPP diff --git a/contrib/restricted/boost/graph/include/boost/graph/detail/histogram_sort.hpp b/contrib/restricted/boost/graph/include/boost/graph/detail/histogram_sort.hpp index ef03635638..40025f5a70 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/detail/histogram_sort.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/detail/histogram_sort.hpp @@ -12,282 +12,308 @@ #include <boost/assert.hpp> -namespace boost { - namespace graph { - namespace detail { - -template<typename InputIterator> -size_t -reserve_count_for_single_pass_helper(InputIterator, InputIterator, - std::input_iterator_tag) +namespace boost { - // Do nothing: we have no idea how much storage to reserve. - return 0; -} - -template<typename InputIterator> -size_t -reserve_count_for_single_pass_helper(InputIterator first, InputIterator last, - std::random_access_iterator_tag) +namespace graph { - using std::distance; - typename std::iterator_traits<InputIterator>::difference_type n = - distance(first, last); - return (size_t)n; -} - -template<typename InputIterator> -size_t -reserve_count_for_single_pass(InputIterator first, InputIterator last) { - typedef typename std::iterator_traits<InputIterator>::iterator_category - category; - return reserve_count_for_single_pass_helper(first, last, category()); -} - -template <typename KeyIterator, typename RowstartIterator, - typename VerticesSize, typename KeyFilter, typename KeyTransform> -void -count_starts - (KeyIterator begin, KeyIterator end, - RowstartIterator starts, // Must support numverts + 1 elements - VerticesSize numkeys, - KeyFilter key_filter, - KeyTransform key_transform) { - - typedef typename std::iterator_traits<RowstartIterator>::value_type EdgeIndex; - - // Put the degree of each vertex v into m_rowstart[v + 1] - for (KeyIterator i = begin; i != end; ++i) { - if (key_filter(*i)) { - BOOST_ASSERT (key_transform(*i) < numkeys); - ++starts[key_transform(*i) + 1]; - } - } - - // Compute the partial sum of the degrees to get the actual values of - // m_rowstart - EdgeIndex start_of_this_row = 0; - starts[0] = start_of_this_row; - for (VerticesSize i = 1; i < numkeys + 1; ++i) { - start_of_this_row += starts[i]; - starts[i] = start_of_this_row; - } -} - -template <typename KeyIterator, typename RowstartIterator, - typename NumKeys, - typename Value1InputIter, - typename Value1OutputIter, typename KeyFilter, typename KeyTransform> -void -histogram_sort(KeyIterator key_begin, KeyIterator key_end, - RowstartIterator rowstart, // Must support numkeys + 1 elements and be precomputed - NumKeys numkeys, - Value1InputIter values1_begin, - Value1OutputIter values1_out, - KeyFilter key_filter, - KeyTransform key_transform) { - - typedef typename std::iterator_traits<RowstartIterator>::value_type EdgeIndex; - - // Histogram sort the edges by their source vertices, putting the targets - // into m_column. The index current_insert_positions[v] contains the next - // location to insert out edges for vertex v. - std::vector<EdgeIndex> - current_insert_positions(rowstart, rowstart + numkeys); - Value1InputIter v1i = values1_begin; - for (KeyIterator i = key_begin; i != key_end; ++i, ++v1i) { - if (key_filter(*i)) { - NumKeys source = key_transform(*i); - BOOST_ASSERT (source < numkeys); - EdgeIndex insert_pos = current_insert_positions[source]; - ++current_insert_positions[source]; - values1_out[insert_pos] = *v1i; - } - } -} - -template <typename KeyIterator, typename RowstartIterator, - typename NumKeys, - typename Value1InputIter, - typename Value1OutputIter, - typename Value2InputIter, - typename Value2OutputIter, - typename KeyFilter, typename KeyTransform> -void -histogram_sort(KeyIterator key_begin, KeyIterator key_end, - RowstartIterator rowstart, // Must support numkeys + 1 elements and be precomputed - NumKeys numkeys, - Value1InputIter values1_begin, - Value1OutputIter values1_out, - Value2InputIter values2_begin, - Value2OutputIter values2_out, - KeyFilter key_filter, - KeyTransform key_transform) { - - typedef typename std::iterator_traits<RowstartIterator>::value_type EdgeIndex; - - // Histogram sort the edges by their source vertices, putting the targets - // into m_column. The index current_insert_positions[v] contains the next - // location to insert out edges for vertex v. - std::vector<EdgeIndex> - current_insert_positions(rowstart, rowstart + numkeys); - Value1InputIter v1i = values1_begin; - Value2InputIter v2i = values2_begin; - for (KeyIterator i = key_begin; i != key_end; ++i, ++v1i, ++v2i) { - if (key_filter(*i)) { - NumKeys source = key_transform(*i); - BOOST_ASSERT (source < numkeys); - EdgeIndex insert_pos = current_insert_positions[source]; - ++current_insert_positions[source]; - values1_out[insert_pos] = *v1i; - values2_out[insert_pos] = *v2i; - } - } -} - -template <typename KeyIterator, typename RowstartIterator, - typename NumKeys, - typename Value1Iter, - typename KeyTransform> -void -histogram_sort_inplace(KeyIterator key_begin, - RowstartIterator rowstart, // Must support numkeys + 1 elements and be precomputed - NumKeys numkeys, - Value1Iter values1, - KeyTransform key_transform) { - - typedef typename std::iterator_traits<RowstartIterator>::value_type EdgeIndex; - - // 1. Copy m_rowstart (except last element) to get insert positions - std::vector<EdgeIndex> insert_positions(rowstart, rowstart + numkeys); - // 2. Swap the sources and targets into place - for (size_t i = 0; i < rowstart[numkeys]; ++i) { - BOOST_ASSERT (key_transform(key_begin[i]) < numkeys); - // While edge i is not in the right bucket: - while (!(i >= rowstart[key_transform(key_begin[i])] && i < insert_positions[key_transform(key_begin[i])])) { - // Add a slot in the right bucket - size_t target_pos = insert_positions[key_transform(key_begin[i])]++; - BOOST_ASSERT (target_pos < rowstart[key_transform(key_begin[i]) + 1]); - if (target_pos == i) continue; - // Swap this edge into place - using std::swap; - swap(key_begin[i], key_begin[target_pos]); - swap(values1[i], values1[target_pos]); - } - } -} - -template <typename KeyIterator, typename RowstartIterator, - typename NumKeys, - typename Value1Iter, - typename Value2Iter, - typename KeyTransform> -void -histogram_sort_inplace(KeyIterator key_begin, - RowstartIterator rowstart, // Must support numkeys + 1 elements and be precomputed - NumKeys numkeys, - Value1Iter values1, - Value2Iter values2, - KeyTransform key_transform) { - - typedef typename std::iterator_traits<RowstartIterator>::value_type EdgeIndex; - - // 1. Copy m_rowstart (except last element) to get insert positions - std::vector<EdgeIndex> insert_positions(rowstart, rowstart + numkeys); - // 2. Swap the sources and targets into place - for (size_t i = 0; i < rowstart[numkeys]; ++i) { - BOOST_ASSERT (key_transform(key_begin[i]) < numkeys); - // While edge i is not in the right bucket: - while (!(i >= rowstart[key_transform(key_begin[i])] && i < insert_positions[key_transform(key_begin[i])])) { - // Add a slot in the right bucket - size_t target_pos = insert_positions[key_transform(key_begin[i])]++; - BOOST_ASSERT (target_pos < rowstart[key_transform(key_begin[i]) + 1]); - if (target_pos == i) continue; - // Swap this edge into place - using std::swap; - swap(key_begin[i], key_begin[target_pos]); - swap(values1[i], values1[target_pos]); - swap(values2[i], values2[target_pos]); - } - } -} - -template <typename InputIterator, typename VerticesSize> -void split_into_separate_coords(InputIterator begin, InputIterator end, - std::vector<VerticesSize>& firsts, - std::vector<VerticesSize>& seconds) { - firsts.clear(); - seconds.clear(); - size_t reserve_size - = detail::reserve_count_for_single_pass(begin, end); - firsts.reserve(reserve_size); - seconds.reserve(reserve_size); - for (; begin != end; ++begin) { - std::pair<VerticesSize, VerticesSize> edge = *begin; - firsts.push_back(edge.first); - seconds.push_back(edge.second); - } -} + namespace detail + { + + template < typename InputIterator > + size_t reserve_count_for_single_pass_helper( + InputIterator, InputIterator, std::input_iterator_tag) + { + // Do nothing: we have no idea how much storage to reserve. + return 0; + } + + template < typename InputIterator > + size_t reserve_count_for_single_pass_helper(InputIterator first, + InputIterator last, std::random_access_iterator_tag) + { + using std::distance; + typename std::iterator_traits< InputIterator >::difference_type n + = distance(first, last); + return (size_t)n; + } + + template < typename InputIterator > + size_t reserve_count_for_single_pass( + InputIterator first, InputIterator last) + { + typedef typename std::iterator_traits< + InputIterator >::iterator_category category; + return reserve_count_for_single_pass_helper( + first, last, category()); + } + + template < typename KeyIterator, typename RowstartIterator, + typename VerticesSize, typename KeyFilter, typename KeyTransform > + void count_starts(KeyIterator begin, KeyIterator end, + RowstartIterator starts, // Must support numverts + 1 elements + VerticesSize numkeys, KeyFilter key_filter, + KeyTransform key_transform) + { + + typedef + typename std::iterator_traits< RowstartIterator >::value_type + EdgeIndex; + + // Put the degree of each vertex v into m_rowstart[v + 1] + for (KeyIterator i = begin; i != end; ++i) + { + if (key_filter(*i)) + { + BOOST_ASSERT(key_transform(*i) < numkeys); + ++starts[key_transform(*i) + 1]; + } + } + + // Compute the partial sum of the degrees to get the actual values + // of m_rowstart + EdgeIndex start_of_this_row = 0; + starts[0] = start_of_this_row; + for (VerticesSize i = 1; i < numkeys + 1; ++i) + { + start_of_this_row += starts[i]; + starts[i] = start_of_this_row; + } + } + + template < typename KeyIterator, typename RowstartIterator, + typename NumKeys, typename Value1InputIter, + typename Value1OutputIter, typename KeyFilter, + typename KeyTransform > + void histogram_sort(KeyIterator key_begin, KeyIterator key_end, + RowstartIterator rowstart, // Must support numkeys + 1 elements and + // be precomputed + NumKeys numkeys, Value1InputIter values1_begin, + Value1OutputIter values1_out, KeyFilter key_filter, + KeyTransform key_transform) + { + + typedef + typename std::iterator_traits< RowstartIterator >::value_type + EdgeIndex; + + // Histogram sort the edges by their source vertices, putting the + // targets into m_column. The index current_insert_positions[v] + // contains the next location to insert out edges for vertex v. + std::vector< EdgeIndex > current_insert_positions( + rowstart, rowstart + numkeys); + Value1InputIter v1i = values1_begin; + for (KeyIterator i = key_begin; i != key_end; ++i, ++v1i) + { + if (key_filter(*i)) + { + NumKeys source = key_transform(*i); + BOOST_ASSERT(source < numkeys); + EdgeIndex insert_pos = current_insert_positions[source]; + ++current_insert_positions[source]; + values1_out[insert_pos] = *v1i; + } + } + } + + template < typename KeyIterator, typename RowstartIterator, + typename NumKeys, typename Value1InputIter, + typename Value1OutputIter, typename Value2InputIter, + typename Value2OutputIter, typename KeyFilter, + typename KeyTransform > + void histogram_sort(KeyIterator key_begin, KeyIterator key_end, + RowstartIterator rowstart, // Must support numkeys + 1 elements and + // be precomputed + NumKeys numkeys, Value1InputIter values1_begin, + Value1OutputIter values1_out, Value2InputIter values2_begin, + Value2OutputIter values2_out, KeyFilter key_filter, + KeyTransform key_transform) + { + + typedef + typename std::iterator_traits< RowstartIterator >::value_type + EdgeIndex; + + // Histogram sort the edges by their source vertices, putting the + // targets into m_column. The index current_insert_positions[v] + // contains the next location to insert out edges for vertex v. + std::vector< EdgeIndex > current_insert_positions( + rowstart, rowstart + numkeys); + Value1InputIter v1i = values1_begin; + Value2InputIter v2i = values2_begin; + for (KeyIterator i = key_begin; i != key_end; ++i, ++v1i, ++v2i) + { + if (key_filter(*i)) + { + NumKeys source = key_transform(*i); + BOOST_ASSERT(source < numkeys); + EdgeIndex insert_pos = current_insert_positions[source]; + ++current_insert_positions[source]; + values1_out[insert_pos] = *v1i; + values2_out[insert_pos] = *v2i; + } + } + } + + template < typename KeyIterator, typename RowstartIterator, + typename NumKeys, typename Value1Iter, typename KeyTransform > + void histogram_sort_inplace(KeyIterator key_begin, + RowstartIterator rowstart, // Must support numkeys + 1 elements and + // be precomputed + NumKeys numkeys, Value1Iter values1, KeyTransform key_transform) + { + + typedef + typename std::iterator_traits< RowstartIterator >::value_type + EdgeIndex; + + // 1. Copy m_rowstart (except last element) to get insert positions + std::vector< EdgeIndex > insert_positions( + rowstart, rowstart + numkeys); + // 2. Swap the sources and targets into place + for (size_t i = 0; i < rowstart[numkeys]; ++i) + { + BOOST_ASSERT(key_transform(key_begin[i]) < numkeys); + // While edge i is not in the right bucket: + while (!(i >= rowstart[key_transform(key_begin[i])] + && i < insert_positions[key_transform(key_begin[i])])) + { + // Add a slot in the right bucket + size_t target_pos + = insert_positions[key_transform(key_begin[i])]++; + BOOST_ASSERT( + target_pos < rowstart[key_transform(key_begin[i]) + 1]); + if (target_pos == i) + continue; + // Swap this edge into place + using std::swap; + swap(key_begin[i], key_begin[target_pos]); + swap(values1[i], values1[target_pos]); + } + } + } + + template < typename KeyIterator, typename RowstartIterator, + typename NumKeys, typename Value1Iter, typename Value2Iter, + typename KeyTransform > + void histogram_sort_inplace(KeyIterator key_begin, + RowstartIterator rowstart, // Must support numkeys + 1 elements and + // be precomputed + NumKeys numkeys, Value1Iter values1, Value2Iter values2, + KeyTransform key_transform) + { + + typedef + typename std::iterator_traits< RowstartIterator >::value_type + EdgeIndex; + + // 1. Copy m_rowstart (except last element) to get insert positions + std::vector< EdgeIndex > insert_positions( + rowstart, rowstart + numkeys); + // 2. Swap the sources and targets into place + for (size_t i = 0; i < rowstart[numkeys]; ++i) + { + BOOST_ASSERT(key_transform(key_begin[i]) < numkeys); + // While edge i is not in the right bucket: + while (!(i >= rowstart[key_transform(key_begin[i])] + && i < insert_positions[key_transform(key_begin[i])])) + { + // Add a slot in the right bucket + size_t target_pos + = insert_positions[key_transform(key_begin[i])]++; + BOOST_ASSERT( + target_pos < rowstart[key_transform(key_begin[i]) + 1]); + if (target_pos == i) + continue; + // Swap this edge into place + using std::swap; + swap(key_begin[i], key_begin[target_pos]); + swap(values1[i], values1[target_pos]); + swap(values2[i], values2[target_pos]); + } + } + } + + template < typename InputIterator, typename VerticesSize > + void split_into_separate_coords(InputIterator begin, InputIterator end, + std::vector< VerticesSize >& firsts, + std::vector< VerticesSize >& seconds) + { + firsts.clear(); + seconds.clear(); + size_t reserve_size + = detail::reserve_count_for_single_pass(begin, end); + firsts.reserve(reserve_size); + seconds.reserve(reserve_size); + for (; begin != end; ++begin) + { + std::pair< VerticesSize, VerticesSize > edge = *begin; + firsts.push_back(edge.first); + seconds.push_back(edge.second); + } + } + + template < typename InputIterator, typename VerticesSize, + typename SourceFilter > + void split_into_separate_coords_filtered(InputIterator begin, + InputIterator end, std::vector< VerticesSize >& firsts, + std::vector< VerticesSize >& seconds, const SourceFilter& filter) + { + firsts.clear(); + seconds.clear(); + for (; begin != end; ++begin) + { + std::pair< VerticesSize, VerticesSize > edge = *begin; + if (filter(edge.first)) + { + firsts.push_back(edge.first); + seconds.push_back(edge.second); + } + } + } + + template < typename InputIterator, typename PropInputIterator, + typename VerticesSize, typename PropType, typename SourceFilter > + void split_into_separate_coords_filtered(InputIterator begin, + InputIterator end, PropInputIterator props, + std::vector< VerticesSize >& firsts, + std::vector< VerticesSize >& seconds, + std::vector< PropType >& props_out, const SourceFilter& filter) + { + firsts.clear(); + seconds.clear(); + props_out.clear(); + for (; begin != end; ++begin) + { + std::pair< VerticesSize, VerticesSize > edge = *begin; + if (filter(edge.first)) + { + firsts.push_back(edge.first); + seconds.push_back(edge.second); + props_out.push_back(*props); + } + ++props; + } + } + + // The versions of operator()() here can't return by reference because + // the actual type passed in may not match Pair, in which case the + // reference parameter is bound to a temporary that could end up + // dangling after the operator returns. + + template < typename Pair > struct project1st + { + typedef typename Pair::first_type result_type; + result_type operator()(const Pair& p) const { return p.first; } + }; + + template < typename Pair > struct project2nd + { + typedef typename Pair::second_type result_type; + result_type operator()(const Pair& p) const { return p.second; } + }; -template <typename InputIterator, typename VerticesSize, typename SourceFilter> -void split_into_separate_coords_filtered - (InputIterator begin, InputIterator end, - std::vector<VerticesSize>& firsts, - std::vector<VerticesSize>& seconds, - const SourceFilter& filter) { - firsts.clear(); - seconds.clear(); - for (; begin != end; ++begin) { - std::pair<VerticesSize, VerticesSize> edge = *begin; - if (filter(edge.first)) { - firsts.push_back(edge.first); - seconds.push_back(edge.second); } - } } - -template <typename InputIterator, typename PropInputIterator, - typename VerticesSize, typename PropType, typename SourceFilter> -void split_into_separate_coords_filtered - (InputIterator begin, InputIterator end, - PropInputIterator props, - std::vector<VerticesSize>& firsts, - std::vector<VerticesSize>& seconds, - std::vector<PropType>& props_out, - const SourceFilter& filter) { - firsts.clear(); - seconds.clear(); - props_out.clear(); - for (; begin != end; ++begin) { - std::pair<VerticesSize, VerticesSize> edge = *begin; - if (filter(edge.first)) { - firsts.push_back(edge.first); - seconds.push_back(edge.second); - props_out.push_back(*props); - } - ++props; - } -} - -// The versions of operator()() here can't return by reference because the -// actual type passed in may not match Pair, in which case the reference -// parameter is bound to a temporary that could end up dangling after the -// operator returns. - -template <typename Pair> -struct project1st { - typedef typename Pair::first_type result_type; - result_type operator()(const Pair& p) const {return p.first;} -}; - -template <typename Pair> -struct project2nd { - typedef typename Pair::second_type result_type; - result_type operator()(const Pair& p) const {return p.second;} -}; - - } - } } #endif // BOOST_GRAPH_DETAIL_HISTOGRAM_SORT_HPP diff --git a/contrib/restricted/boost/graph/include/boost/graph/detail/indexed_properties.hpp b/contrib/restricted/boost/graph/include/boost/graph/detail/indexed_properties.hpp index 4494625c65..b86cf31a73 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/detail/indexed_properties.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/detail/indexed_properties.hpp @@ -26,257 +26,271 @@ #include <boost/property_map/property_map.hpp> #include <boost/mpl/if.hpp> -namespace boost { -namespace detail { - -template<typename Derived, typename Property, typename Descriptor, typename IndexMap> -class indexed_vertex_properties +namespace boost { -public: - typedef no_property vertex_property_type; - typedef Property vertex_bundled; - typedef iterator_property_map< - typename std::vector<Property>::iterator, - IndexMap> vertex_map_type; - typedef iterator_property_map< - typename std::vector<Property>::const_iterator, - IndexMap> const_vertex_map_type; - - // Directly access a vertex or edge bundle - Property& operator[](Descriptor v) - { return m_vertex_properties[get(vertex_index, derived(), v)]; } - - const Property& operator[](Descriptor v) const - { return m_vertex_properties[get(vertex_index, derived(), v)]; } - - vertex_map_type get_vertex_bundle(const IndexMap& index_map = IndexMap()) { - return vertex_map_type(m_vertex_properties.begin(), index_map); - } - - const_vertex_map_type get_vertex_bundle(const IndexMap& index_map = IndexMap()) const { - return const_vertex_map_type(m_vertex_properties.begin(), index_map); - } - -protected: - // Default-construct with no property values - indexed_vertex_properties() {} - - // Initialize with n default-constructed property values - indexed_vertex_properties(std::size_t n) : m_vertex_properties(n) { } - -public: - // Clear the properties vector - void clear() - { - m_vertex_properties.clear(); - } - - // Resize the properties vector - void resize(std::size_t n) - { - m_vertex_properties.resize(n); - } - - // Reserve space in the vector of properties - void reserve(std::size_t n) - { - m_vertex_properties.reserve(n); - } - - // Add a new property value to the back - void push_back(const Property& prop) - { - m_vertex_properties.push_back(prop); - } - - // Write an element by raw index - void write_by_index(std::size_t idx, const Property& prop) - { - m_vertex_properties[idx] = prop; - } - - // Access to the derived object - Derived& derived() { return *static_cast<Derived*>(this); } - - const Derived& derived() const - { return *static_cast<const Derived*>(this); } - -public: // should be private, but friend templates not portable - std::vector<Property> m_vertex_properties; -}; - -template<typename Derived, typename Descriptor, typename IndexMap> -class indexed_vertex_properties<Derived, void, Descriptor, IndexMap> +namespace detail { - struct secret {}; - - public: - typedef no_property vertex_property_type; - typedef void vertex_bundled; - typedef secret vertex_map_type; - typedef secret const_vertex_map_type; - - secret operator[](secret) { return secret(); } - - vertex_map_type get_vertex_bundle() const { - return vertex_map_type(); - } - protected: - // All operations do nothing. - indexed_vertex_properties() { } - indexed_vertex_properties(std::size_t) { } - -public: - void clear() { } - void resize(std::size_t) { } - void reserve(std::size_t) { } -}; - -template<typename Derived, typename Property, typename Descriptor, typename IndexMap> -class indexed_edge_properties -{ -public: - typedef no_property edge_property_type; - typedef Property edge_bundled; - typedef Property edge_push_back_type; - typedef iterator_property_map< - typename std::vector<Property>::iterator, - IndexMap> edge_map_type; - typedef iterator_property_map< - typename std::vector<Property>::const_iterator, - IndexMap> const_edge_map_type; - - // Directly access a edge or edge bundle - Property& operator[](Descriptor v) - { return m_edge_properties[get(edge_index, derived(), v)]; } - - const Property& operator[](Descriptor v) const - { return m_edge_properties[get(edge_index, derived(), v)]; } - - edge_map_type get_edge_bundle(const IndexMap& index_map = IndexMap()) { - return edge_map_type(m_edge_properties.begin(), index_map); - } - - const_edge_map_type get_edge_bundle(const IndexMap& index_map = IndexMap()) const { - return const_edge_map_type(m_edge_properties.begin(), index_map); - } - -protected: - // Default-construct with no property values - indexed_edge_properties() {} - - // Initialize with n default-constructed property values - indexed_edge_properties(std::size_t n) : m_edge_properties(n) { } - - // Get the size of the properties vector - std::size_t size() const - { - return m_edge_properties.size(); - } - - // Clear the properties vector - void clear() - { - m_edge_properties.clear(); - } - - // Resize the properties vector - void resize(std::size_t n) - { - m_edge_properties.resize(n); - } - - // Reserve space in the vector of properties - void reserve(std::size_t n) - { - m_edge_properties.reserve(n); - } - - // Write an element by raw index - void write_by_index(std::size_t idx, const Property& prop) - { - m_edge_properties[idx] = prop; - } - - public: - // Add a new property value to the back - void push_back(const Property& prop) - { - m_edge_properties.push_back(prop); - } - - // Move range of properties backwards - void move_range(std::size_t src_begin, std::size_t src_end, std::size_t dest_begin) { - std::copy_backward( - m_edge_properties.begin() + src_begin, - m_edge_properties.begin() + src_end, - m_edge_properties.begin() + dest_begin + (src_end - src_begin)); - } - - typedef typename std::vector<Property>::iterator iterator; - iterator begin() {return m_edge_properties.begin();} - iterator end() {return m_edge_properties.end();} - - private: - // Access to the derived object - Derived& derived() { return *static_cast<Derived*>(this); } - - const Derived& derived() const - { return *static_cast<const Derived*>(this); } - -public: // should be private, but friend templates not portable - std::vector<Property> m_edge_properties; -}; - -struct dummy_no_property_iterator -: public boost::iterator_facade<dummy_no_property_iterator, no_property, std::random_access_iterator_tag> { - mutable no_property prop; - no_property& dereference() const {return prop;} - bool equal(const dummy_no_property_iterator&) const {return true;} - void increment() {} - void decrement() {} - void advance(std::ptrdiff_t) {} - std::ptrdiff_t distance_to(const dummy_no_property_iterator) const {return 0;} -}; - -template<typename Derived, typename Descriptor, typename IndexMap> -class indexed_edge_properties<Derived, void, Descriptor, IndexMap> -{ - struct secret {}; - - public: - typedef no_property edge_property_type; - typedef void edge_bundled; - typedef void* edge_push_back_type; - typedef secret edge_map_type; - typedef secret const_edge_map_type; - - secret operator[](secret) { return secret(); } - void write_by_index(std::size_t /*idx*/, const no_property& /*prop*/) {} - - edge_map_type get_edge_bundle(const IndexMap& = IndexMap()) const { - return edge_map_type(); - } - - protected: - // All operations do nothing. - indexed_edge_properties() { } - indexed_edge_properties(std::size_t) { } - std::size_t size() const {return 0;} - void clear() { } - void resize(std::size_t) { } - void reserve(std::size_t) { } - - public: - void push_back(const edge_push_back_type&) { } - void move_range(std::size_t /*src_begin*/, std::size_t /*src_end*/, std::size_t /*dest_begin*/) {} - - typedef dummy_no_property_iterator iterator; - iterator begin() {return dummy_no_property_iterator();} - iterator end() {return dummy_no_property_iterator();} - -}; + template < typename Derived, typename Property, typename Descriptor, + typename IndexMap > + class indexed_vertex_properties + { + public: + typedef no_property vertex_property_type; + typedef Property vertex_bundled; + typedef iterator_property_map< + typename std::vector< Property >::iterator, IndexMap > + vertex_map_type; + typedef iterator_property_map< + typename std::vector< Property >::const_iterator, IndexMap > + const_vertex_map_type; + + // Directly access a vertex or edge bundle + Property& operator[](Descriptor v) + { + return m_vertex_properties[get(vertex_index, derived(), v)]; + } + + const Property& operator[](Descriptor v) const + { + return m_vertex_properties[get(vertex_index, derived(), v)]; + } + + vertex_map_type get_vertex_bundle( + const IndexMap& index_map = IndexMap()) + { + return vertex_map_type(m_vertex_properties.begin(), index_map); + } + + const_vertex_map_type get_vertex_bundle( + const IndexMap& index_map = IndexMap()) const + { + return const_vertex_map_type( + m_vertex_properties.begin(), index_map); + } + + protected: + // Default-construct with no property values + indexed_vertex_properties() {} + + // Initialize with n default-constructed property values + indexed_vertex_properties(std::size_t n) : m_vertex_properties(n) {} + + public: + // Clear the properties vector + void clear() { m_vertex_properties.clear(); } + + // Resize the properties vector + void resize(std::size_t n) { m_vertex_properties.resize(n); } + + // Reserve space in the vector of properties + void reserve(std::size_t n) { m_vertex_properties.reserve(n); } + + // Add a new property value to the back + void push_back(const Property& prop) + { + m_vertex_properties.push_back(prop); + } + + // Write an element by raw index + void write_by_index(std::size_t idx, const Property& prop) + { + m_vertex_properties[idx] = prop; + } + + // Access to the derived object + Derived& derived() { return *static_cast< Derived* >(this); } + + const Derived& derived() const + { + return *static_cast< const Derived* >(this); + } + + public: // should be private, but friend templates not portable + std::vector< Property > m_vertex_properties; + }; + + template < typename Derived, typename Descriptor, typename IndexMap > + class indexed_vertex_properties< Derived, void, Descriptor, IndexMap > + { + struct secret + { + }; + + public: + typedef no_property vertex_property_type; + typedef void vertex_bundled; + typedef secret vertex_map_type; + typedef secret const_vertex_map_type; + + secret operator[](secret) { return secret(); } + + vertex_map_type get_vertex_bundle() const { return vertex_map_type(); } + + protected: + // All operations do nothing. + indexed_vertex_properties() {} + indexed_vertex_properties(std::size_t) {} + + public: + void clear() {} + void resize(std::size_t) {} + void reserve(std::size_t) {} + }; + + template < typename Derived, typename Property, typename Descriptor, + typename IndexMap > + class indexed_edge_properties + { + public: + typedef no_property edge_property_type; + typedef Property edge_bundled; + typedef Property edge_push_back_type; + typedef iterator_property_map< + typename std::vector< Property >::iterator, IndexMap > + edge_map_type; + typedef iterator_property_map< + typename std::vector< Property >::const_iterator, IndexMap > + const_edge_map_type; + + // Directly access a edge or edge bundle + Property& operator[](Descriptor v) + { + return m_edge_properties[get(edge_index, derived(), v)]; + } + + const Property& operator[](Descriptor v) const + { + return m_edge_properties[get(edge_index, derived(), v)]; + } + + edge_map_type get_edge_bundle(const IndexMap& index_map = IndexMap()) + { + return edge_map_type(m_edge_properties.begin(), index_map); + } + + const_edge_map_type get_edge_bundle( + const IndexMap& index_map = IndexMap()) const + { + return const_edge_map_type(m_edge_properties.begin(), index_map); + } + + protected: + // Default-construct with no property values + indexed_edge_properties() {} + + // Initialize with n default-constructed property values + indexed_edge_properties(std::size_t n) : m_edge_properties(n) {} + + // Get the size of the properties vector + std::size_t size() const { return m_edge_properties.size(); } + + // Clear the properties vector + void clear() { m_edge_properties.clear(); } + + // Resize the properties vector + void resize(std::size_t n) { m_edge_properties.resize(n); } + + // Reserve space in the vector of properties + void reserve(std::size_t n) { m_edge_properties.reserve(n); } + + // Write an element by raw index + void write_by_index(std::size_t idx, const Property& prop) + { + m_edge_properties[idx] = prop; + } + + public: + // Add a new property value to the back + void push_back(const Property& prop) + { + m_edge_properties.push_back(prop); + } + + // Move range of properties backwards + void move_range( + std::size_t src_begin, std::size_t src_end, std::size_t dest_begin) + { + std::copy_backward(m_edge_properties.begin() + src_begin, + m_edge_properties.begin() + src_end, + m_edge_properties.begin() + dest_begin + (src_end - src_begin)); + } + + typedef typename std::vector< Property >::iterator iterator; + iterator begin() { return m_edge_properties.begin(); } + iterator end() { return m_edge_properties.end(); } + + private: + // Access to the derived object + Derived& derived() { return *static_cast< Derived* >(this); } + + const Derived& derived() const + { + return *static_cast< const Derived* >(this); + } + + public: // should be private, but friend templates not portable + std::vector< Property > m_edge_properties; + }; + + struct dummy_no_property_iterator + : public boost::iterator_facade< dummy_no_property_iterator, no_property, + std::random_access_iterator_tag > + { + mutable no_property prop; + no_property& dereference() const { return prop; } + bool equal(const dummy_no_property_iterator&) const { return true; } + void increment() {} + void decrement() {} + void advance(std::ptrdiff_t) {} + std::ptrdiff_t distance_to(const dummy_no_property_iterator) const + { + return 0; + } + }; + + template < typename Derived, typename Descriptor, typename IndexMap > + class indexed_edge_properties< Derived, void, Descriptor, IndexMap > + { + struct secret + { + }; + + public: + typedef no_property edge_property_type; + typedef void edge_bundled; + typedef void* edge_push_back_type; + typedef secret edge_map_type; + typedef secret const_edge_map_type; + + secret operator[](secret) { return secret(); } + void write_by_index(std::size_t /*idx*/, const no_property& /*prop*/) {} + + edge_map_type get_edge_bundle(const IndexMap& = IndexMap()) const + { + return edge_map_type(); + } + + protected: + // All operations do nothing. + indexed_edge_properties() {} + indexed_edge_properties(std::size_t) {} + std::size_t size() const { return 0; } + void clear() {} + void resize(std::size_t) {} + void reserve(std::size_t) {} + + public: + void push_back(const edge_push_back_type&) {} + void move_range(std::size_t /*src_begin*/, std::size_t /*src_end*/, + std::size_t /*dest_begin*/) + { + } + + typedef dummy_no_property_iterator iterator; + iterator begin() { return dummy_no_property_iterator(); } + iterator end() { return dummy_no_property_iterator(); } + }; } } diff --git a/contrib/restricted/boost/graph/include/boost/graph/detail/is_distributed_selector.hpp b/contrib/restricted/boost/graph/include/boost/graph/detail/is_distributed_selector.hpp index 4319d9d895..0a25a6852a 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/detail/is_distributed_selector.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/detail/is_distributed_selector.hpp @@ -17,10 +17,14 @@ #include <boost/mpl/bool.hpp> -namespace boost { - namespace detail { - template <typename> struct is_distributed_selector: boost::mpl::false_ {}; - } +namespace boost +{ +namespace detail +{ + template < typename > struct is_distributed_selector : boost::mpl::false_ + { + }; +} } #endif // BOOST_GRAPH_DETAIL_IS_DISTRIBUTED_SELECTOR_HPP diff --git a/contrib/restricted/boost/graph/include/boost/graph/detail/mpi_include.hpp b/contrib/restricted/boost/graph/include/boost/graph/detail/mpi_include.hpp new file mode 100644 index 0000000000..f64592daba --- /dev/null +++ b/contrib/restricted/boost/graph/include/boost/graph/detail/mpi_include.hpp @@ -0,0 +1,16 @@ +#ifndef BOOST_GRAPH_DETAIL_MPI_INCLUDE_HPP_INCLUDED +#define BOOST_GRAPH_DETAIL_MPI_INCLUDE_HPP_INCLUDED + +// Copyright 2018 Peter Dimov +// +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0 (See accompanying file +// LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) + +#if defined BOOST_GRAPH_USE_MPI +#define BOOST_GRAPH_MPI_INCLUDE(x) x +#else +#define BOOST_GRAPH_MPI_INCLUDE(x) <boost/graph/detail/empty_header.hpp> +#endif + +#endif // #ifndef BOOST_GRAPH_DETAIL_MPI_INCLUDE_HPP_INCLUDED diff --git a/contrib/restricted/boost/graph/include/boost/graph/detail/read_graphviz_new.hpp b/contrib/restricted/boost/graph/include/boost/graph/detail/read_graphviz_new.hpp index 81221c0b25..1e7ca7ca51 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/detail/read_graphviz_new.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/detail/read_graphviz_new.hpp @@ -5,19 +5,19 @@ // http://www.boost.org/LICENSE_1_0.txt) // -// read_graphviz_new.hpp - +// read_graphviz_new.hpp - // Initialize a model of the BGL's MutableGraph concept and an associated // collection of property maps using a graph expressed in the GraphViz -// DOT Language. +// DOT Language. // // Based on the grammar found at: -// http://www.graphviz.org/cvs/doc/info/lang.html +// https://web.archive.org/web/20041213234742/http://www.graphviz.org/cvs/doc/info/lang.html // // Jeremiah rewrite used grammar found at: // http://www.graphviz.org/doc/info/lang.html // and page 34 or http://www.graphviz.org/pdf/dotguide.pdf // -// See documentation for this code at: +// See documentation for this code at: // http://www.boost.org/libs/graph/doc/read_graphviz.html // @@ -41,66 +41,82 @@ #include <iostream> #include <cstdlib> -namespace boost { - -namespace read_graphviz_detail { - typedef std::string node_name; - typedef std::string subgraph_name; - - typedef std::map<std::string, std::string> properties; - - struct node_and_port { - node_name name; - std::string angle; // Or empty if no angle - std::vector<std::string> location; // Up to two identifiers - - friend inline bool operator==(const node_and_port& a, const node_and_port& b) { - return a.name == b.name && - a.angle == b.angle && - a.location == b.location; - } - - friend inline bool operator<(const node_and_port& a, const node_and_port& b) { - if (a.name != b.name) return a.name < b.name; - if (a.angle != b.angle) return a.angle < b.angle; - return a.location < b.location; - } - }; - - struct edge_info { - node_and_port source; - node_and_port target; - properties props; - }; - - struct parser_result { - bool graph_is_directed; - bool graph_is_strict; - std::map<node_name, properties> nodes; // Global set - std::vector<edge_info> edges; - std::map<subgraph_name, properties> graph_props; // Root and subgraphs - }; - - // The actual parser, from libs/graph/src/read_graphviz_new.cpp - void parse_graphviz_from_string(const std::string& str, parser_result& result, bool want_directed); - - // Translate from those results to a graph - void translate_results_to_graph(const parser_result& r, ::boost::detail::graph::mutate_graph* mg); +namespace boost +{ + +namespace read_graphviz_detail +{ + typedef std::string node_name; + typedef std::string subgraph_name; + + typedef std::map< std::string, std::string > properties; + + struct node_and_port + { + node_name name; + std::string angle; // Or empty if no angle + std::vector< std::string > location; // Up to two identifiers + + friend inline bool operator==( + const node_and_port& a, const node_and_port& b) + { + return a.name == b.name && a.angle == b.angle + && a.location == b.location; + } + + friend inline bool operator<( + const node_and_port& a, const node_and_port& b) + { + if (a.name != b.name) + return a.name < b.name; + if (a.angle != b.angle) + return a.angle < b.angle; + return a.location < b.location; + } + }; + + struct edge_info + { + node_and_port source; + node_and_port target; + properties props; + }; + + struct parser_result + { + bool graph_is_directed; + bool graph_is_strict; + std::map< node_name, properties > nodes; // Global set + std::vector< edge_info > edges; + std::map< subgraph_name, properties > graph_props; // Root and subgraphs + }; + + // The actual parser, from libs/graph/src/read_graphviz_new.cpp + void parse_graphviz_from_string( + const std::string& str, parser_result& result, bool want_directed); + + // Translate from those results to a graph + void translate_results_to_graph( + const parser_result& r, ::boost::detail::graph::mutate_graph* mg); } // namespace read_graphviz_detail -namespace detail { - namespace graph { - BOOST_GRAPH_DECL bool read_graphviz_new(const std::string& str, boost::detail::graph::mutate_graph* mg); - } // end namespace graph +namespace detail +{ + namespace graph + { + BOOST_GRAPH_DECL bool read_graphviz_new( + const std::string& str, boost::detail::graph::mutate_graph* mg); + } // end namespace graph } // end namespace detail -template <typename MutableGraph> -bool read_graphviz_new(const std::string& str, - MutableGraph& graph, boost::dynamic_properties& dp, - std::string const& node_id = "node_id") { - boost::detail::graph::mutate_graph_impl<MutableGraph> mg(graph, dp, node_id); - return detail::graph::read_graphviz_new(str, &mg); +template < typename MutableGraph > +bool read_graphviz_new(const std::string& str, MutableGraph& graph, + boost::dynamic_properties& dp, std::string const& node_id = "node_id") +{ + boost::detail::graph::mutate_graph_impl< MutableGraph > mg( + graph, dp, node_id); + return detail::graph::read_graphviz_new(str, &mg); } } // namespace boost diff --git a/contrib/restricted/boost/graph/include/boost/graph/detail/read_graphviz_spirit.hpp b/contrib/restricted/boost/graph/include/boost/graph/detail/read_graphviz_spirit.hpp index 2ba09cc0a4..b39ad7d631 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/detail/read_graphviz_spirit.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/detail/read_graphviz_spirit.hpp @@ -5,15 +5,15 @@ // http://www.boost.org/LICENSE_1_0.txt) // -// read_graphviz_spirit.hpp - +// read_graphviz_spirit.hpp - // Initialize a model of the BGL's MutableGraph concept and an associated // collection of property maps using a graph expressed in the GraphViz -// DOT Language. +// DOT Language. // // Based on the grammar found at: -// http://www.graphviz.org/cvs/doc/info/lang.html +// https://web.archive.org/web/20041213234742/http://www.graphviz.org/cvs/doc/info/lang.html // -// See documentation for this code at: +// See documentation for this code at: // http://www.boost.org/libs/graph/doc/read_graphviz.html // @@ -27,7 +27,6 @@ #define PHOENIX_LIMIT 6 #define BOOST_SPIRIT_CLOSURE_LIMIT 6 - #include <boost/spirit/include/classic_multi_pass.hpp> #include <boost/spirit/include/classic_core.hpp> #include <boost/spirit/include/classic_confix.hpp> @@ -56,557 +55,617 @@ #include <boost/graph/graphviz.hpp> #include <boost/throw_exception.hpp> -namespace phoenix { +namespace phoenix +{ // Workaround: std::map::operator[] uses a different return type than all // other standard containers. Phoenix doesn't account for that. -template <typename TK, typename T0, typename T1> -struct binary_operator<index_op, std::map<TK,T0>, T1> +template < typename TK, typename T0, typename T1 > +struct binary_operator< index_op, std::map< TK, T0 >, T1 > { - typedef typename std::map<TK,T0>::mapped_type& result_type; - static result_type eval(std::map<TK,T0>& container, T1 const& index) - { return container[index]; } + typedef typename std::map< TK, T0 >::mapped_type& result_type; + static result_type eval(std::map< TK, T0 >& container, T1 const& index) + { + return container[index]; + } }; } // namespace phoenix -namespace boost { -namespace detail { -namespace graph { - - -///////////////////////////////////////////////////////////////////////////// -// Application-specific type definitions -///////////////////////////////////////////////////////////////////////////// - -typedef std::set<edge_t> edges_t; -typedef std::set<node_t> nodes_t; -typedef std::set<id_t> ids_t; -typedef std::map<edge_t,ids_t> edge_map_t; -typedef std::map<node_t,ids_t> node_map_t; -typedef std::map<id_t,id_t> props_t; -typedef std::map<id_t,props_t> subgraph_props_t; -typedef boost::function2<void, id_t const&, id_t const&> actor_t; -typedef std::vector<edge_t> edge_stack_t; -typedef std::map<id_t,nodes_t> subgraph_nodes_t; -typedef std::map<id_t,edges_t> subgraph_edges_t; - - - -///////////////////////////////////////////////////////////////////////////// -// Stack frames used by semantic actions -///////////////////////////////////////////////////////////////////////////// -struct id_closure : boost::spirit::classic::closure<id_closure, node_t> { - member1 name; -}; - - -struct node_id_closure : boost::spirit::classic::closure<node_id_closure, node_t> { - member1 name; -}; - -struct attr_list_closure : boost::spirit::classic::closure<attr_list_closure, actor_t> { - member1 prop_actor; -}; - -struct property_closure : boost::spirit::classic::closure<property_closure, id_t, id_t> { - member1 key; - member2 value; -}; - -struct data_stmt_closure : boost::spirit::classic::closure<data_stmt_closure, - nodes_t,nodes_t,edge_stack_t,bool,node_t> { - member1 sources; - member2 dests; - member3 edge_stack; - member4 saw_node; - member5 active_node; -}; - -struct subgraph_closure : boost::spirit::classic::closure<subgraph_closure, - nodes_t, edges_t, node_t> { - member1 nodes; - member2 edges; - member3 name; -}; +namespace boost +{ +namespace detail +{ + namespace graph + { -///////////////////////////////////////////////////////////////////////////// -// Grammar and Actions for the DOT Language -///////////////////////////////////////////////////////////////////////////// - -// Grammar for a dot file. -struct dot_grammar : public boost::spirit::classic::grammar<dot_grammar> { - mutate_graph& graph_; - explicit dot_grammar(mutate_graph& graph) : graph_(graph) { } - - template <class ScannerT> - struct definition { - - definition(dot_grammar const& self) : self(self), subgraph_depth(0), - keyword_p("0-9a-zA-Z_") { - using namespace boost::spirit::classic; - using namespace phoenix; - - // RG - Future Work - // - Handle multi-line strings using \ line continuation - // - Make keywords case insensitive - ID - = ( lexeme_d[((alpha_p | ch_p('_')) >> *(alnum_p | ch_p('_')))] - | real_p - | lexeme_d[confix_p('"', *c_escape_ch_p, '"')] - | comment_nest_p('<', '>') - )[ID.name = construct_<std::string>(arg1,arg2)] - ; - - a_list - = list_p( ID[(a_list.key = arg1), - (a_list.value = "true") - ] - >> !( ch_p('=') - >> ID[a_list.value = arg1]) - [phoenix::bind(&definition::call_prop_actor) - (var(*this),a_list.key,a_list.value)],!ch_p(',')); - - attr_list = +(ch_p('[') >> !a_list >> ch_p(']')); - - // RG - disregard port id's for now. - port_location - = (ch_p(':') >> ID) - | (ch_p(':') >> ch_p('(') >> ID >> ch_p(',') >> ID >> ch_p(')')) - ; - - port_angle = ch_p('@') >> ID; - - port - = port_location >> (!port_angle) - | port_angle >> (!port_location); - - - node_id - = ( ID[node_id.name = arg1] >> (!port) ) - [phoenix::bind(&definition::memoize_node)(var(*this))]; - - graph_stmt - = (ID[graph_stmt.key = arg1] >> - ch_p('=') >> - ID[graph_stmt.value = arg1]) - [phoenix::bind(&definition::call_graph_prop) - (var(*this),graph_stmt.key,graph_stmt.value)] - ; // Graph property. - - attr_stmt - = (as_lower_d[keyword_p("graph")] - >> attr_list(actor_t(phoenix::bind(&definition::default_graph_prop) - (var(*this),arg1,arg2)))) - | (as_lower_d[keyword_p("node")] - >> attr_list(actor_t(phoenix::bind(&definition::default_node_prop) - (var(*this),arg1,arg2)))) - | (as_lower_d[keyword_p("edge")] - >> attr_list(actor_t(phoenix::bind(&definition::default_edge_prop) - (var(*this),arg1,arg2)))) - ; - - // edge_head is set depending on the graph type (directed/undirected) - edgeop = ch_p('-') >> ch_p(boost::ref(edge_head)); - - edgeRHS - = +( edgeop[(data_stmt.sources = data_stmt.dests), - (data_stmt.dests = construct_<nodes_t>())] - >> ( subgraph[data_stmt.dests = arg1] - | node_id[phoenix::bind(&definition::insert_node) - (var(*this),data_stmt.dests,arg1)] - ) - [phoenix::bind(&definition::activate_edge) - (var(*this),data_stmt.sources,data_stmt.dests, - var(edges), var(default_edge_props))] - ); - - - // To avoid backtracking, edge, node, and subgraph statements are - // processed as one nonterminal. - data_stmt - = ( subgraph[(data_stmt.dests = arg1),// will get moved in rhs - (data_stmt.saw_node = false)] - | node_id[(phoenix::bind(&definition::insert_node) - (var(*this),data_stmt.dests,arg1)), - (data_stmt.saw_node = true), + ///////////////////////////////////////////////////////////////////////////// + // Application-specific type definitions + ///////////////////////////////////////////////////////////////////////////// + + typedef std::set< edge_t > edges_t; + typedef std::set< node_t > nodes_t; + typedef std::set< id_t > ids_t; + typedef std::map< edge_t, ids_t > edge_map_t; + typedef std::map< node_t, ids_t > node_map_t; + typedef std::map< id_t, id_t > props_t; + typedef std::map< id_t, props_t > subgraph_props_t; + typedef boost::function2< void, id_t const&, id_t const& > actor_t; + typedef std::vector< edge_t > edge_stack_t; + typedef std::map< id_t, nodes_t > subgraph_nodes_t; + typedef std::map< id_t, edges_t > subgraph_edges_t; + + ///////////////////////////////////////////////////////////////////////////// + // Stack frames used by semantic actions + ///////////////////////////////////////////////////////////////////////////// + struct id_closure + : boost::spirit::classic::closure< id_closure, node_t > + { + member1 name; + }; + + struct node_id_closure + : boost::spirit::classic::closure< node_id_closure, node_t > + { + member1 name; + }; + + struct attr_list_closure + : boost::spirit::classic::closure< attr_list_closure, actor_t > + { + member1 prop_actor; + }; + + struct property_closure + : boost::spirit::classic::closure< property_closure, id_t, id_t > + { + member1 key; + member2 value; + }; + + struct data_stmt_closure + : boost::spirit::classic::closure< data_stmt_closure, nodes_t, nodes_t, + edge_stack_t, bool, node_t > + { + member1 sources; + member2 dests; + member3 edge_stack; + member4 saw_node; + member5 active_node; + }; + + struct subgraph_closure + : boost::spirit::classic::closure< subgraph_closure, nodes_t, edges_t, + node_t > + { + member1 nodes; + member2 edges; + member3 name; + }; + + ///////////////////////////////////////////////////////////////////////////// + // Grammar and Actions for the DOT Language + ///////////////////////////////////////////////////////////////////////////// + + // Grammar for a dot file. + struct dot_grammar + : public boost::spirit::classic::grammar< dot_grammar > + { + mutate_graph& graph_; + explicit dot_grammar(mutate_graph& graph) : graph_(graph) {} + + template < class ScannerT > struct definition + { + + definition(dot_grammar const& self) + : self(self), subgraph_depth(0), keyword_p("0-9a-zA-Z_") + { + using namespace boost::spirit::classic; + using namespace phoenix; + + // RG - Future Work + // - Handle multi-line strings using \ line continuation + // - Make keywords case insensitive + ID = (lexeme_d[( + (alpha_p | ch_p('_')) >> *(alnum_p | ch_p('_')))] + | real_p | lexeme_d[confix_p('"', *c_escape_ch_p, '"')] + | comment_nest_p('<', '>'))[ID.name + = construct_< std::string >(arg1, arg2)]; + + a_list = list_p( + ID[(a_list.key = arg1), (a_list.value = "true")] >> !( + ch_p('=') >> ID[a_list.value = arg1])[phoenix::bind( + &definition::call_prop_actor)( + var(*this), a_list.key, a_list.value)], + !ch_p(',')); + + attr_list = +(ch_p('[') >> !a_list >> ch_p(']')); + + // RG - disregard port id's for now. + port_location = (ch_p(':') >> ID) + | (ch_p(':') >> ch_p('(') >> ID >> ch_p(',') >> ID + >> ch_p(')')); + + port_angle = ch_p('@') >> ID; + + port = port_location >> (!port_angle) + | port_angle >> (!port_location); + + node_id + = (ID[node_id.name = arg1] >> (!port))[phoenix::bind( + &definition::memoize_node)(var(*this))]; + + graph_stmt = (ID[graph_stmt.key = arg1] >> ch_p('=') + >> ID[graph_stmt.value = arg1])[phoenix::bind( + &definition::call_graph_prop)(var(*this), + graph_stmt.key, graph_stmt.value)]; // Graph property. + + attr_stmt + = (as_lower_d[keyword_p("graph")] >> attr_list(actor_t( + phoenix::bind(&definition::default_graph_prop)( + var(*this), arg1, arg2)))) + | (as_lower_d[keyword_p("node")] >> attr_list(actor_t( + phoenix::bind(&definition::default_node_prop)( + var(*this), arg1, arg2)))) + | (as_lower_d[keyword_p("edge")] >> attr_list(actor_t( + phoenix::bind(&definition::default_edge_prop)( + var(*this), arg1, arg2)))); + + // edge_head is set depending on the graph type + // (directed/undirected) + edgeop = ch_p('-') >> ch_p(boost::ref(edge_head)); + + edgeRHS = +(edgeop[(data_stmt.sources = data_stmt.dests), + (data_stmt.dests = construct_< nodes_t >())] + >> (subgraph[data_stmt.dests = arg1] + | node_id[phoenix::bind(&definition::insert_node)( + var(*this), data_stmt.dests, arg1)]) + [phoenix::bind(&definition::activate_edge)( + var(*this), data_stmt.sources, data_stmt.dests, + var(edges), var(default_edge_props))]); + + // To avoid backtracking, edge, node, and subgraph + // statements are processed as one nonterminal. + data_stmt + = (subgraph[(data_stmt.dests + = arg1), // will get moved in rhs + (data_stmt.saw_node = false)] + | node_id[(phoenix::bind( + &definition::insert_node)( + var(*this), data_stmt.dests, arg1)), + (data_stmt.saw_node = true), #ifdef BOOST_GRAPH_DEBUG - (std::cout << val("AcTive Node: ") << arg1 << "\n"), + (std::cout << val("AcTive Node: ") << arg1 + << "\n"), #endif // BOOST_GRAPH_DEBUG - (data_stmt.active_node = arg1)] - ) >> if_p(edgeRHS)[ - !attr_list( - actor_t(phoenix::bind(&definition::edge_prop) - (var(*this),arg1,arg2))) - ].else_p[ - if_p(data_stmt.saw_node)[ - !attr_list( - actor_t(phoenix::bind(&definition::node_prop) - (var(*this),arg1,arg2))) - ] // otherwise it's a subgraph, nothing more to do. - ]; - - - stmt - = graph_stmt - | attr_stmt - | data_stmt - ; - - stmt_list = *( stmt >> !ch_p(';') ); - - subgraph - = !( as_lower_d[keyword_p("subgraph")] - >> (!ID[(subgraph.name = arg1), - (subgraph.nodes = (var(subgraph_nodes))[arg1]), - (subgraph.edges = (var(subgraph_edges))[arg1])]) - ) - >> ch_p('{')[++var(subgraph_depth)] - >> stmt_list - >> ch_p('}')[--var(subgraph_depth)] - [(var(subgraph_nodes))[subgraph.name] = subgraph.nodes] - [(var(subgraph_edges))[subgraph.name] = subgraph.edges] - - | as_lower_d[keyword_p("subgraph")] - >> ID[(subgraph.nodes = (var(subgraph_nodes))[arg1]), - (subgraph.edges = (var(subgraph_edges))[arg1])] - ; - - the_grammar - = (!as_lower_d[keyword_p("strict")]) - >> ( as_lower_d[keyword_p("graph")][ - (var(edge_head) = '-'), - (phoenix::bind(&definition::check_undirected)(var(*this)))] - | as_lower_d[keyword_p("digraph")][ - (var(edge_head) = '>'), - (phoenix::bind(&definition::check_directed)(var(*this)))] - ) - >> (!ID) >> ch_p('{') >> stmt_list >> ch_p('}'); - - } // definition() - - typedef boost::spirit::classic::rule<ScannerT> rule_t; - - rule_t const& start() const { return the_grammar; } - - - // - // Semantic actions - // - - void check_undirected() { - if(self.graph_.is_directed()) - boost::throw_exception(boost::undirected_graph_error()); - } - - void check_directed() { - if(!self.graph_.is_directed()) - boost::throw_exception(boost::directed_graph_error()); - } - - void memoize_node() { - id_t const& node = node_id.name(); - props_t& node_props = default_node_props; - - if(nodes.find(node) == nodes.end()) { - nodes.insert(node); - self.graph_.do_add_vertex(node); - - node_map.insert(std::make_pair(node,ids_t())); + (data_stmt.active_node = arg1)]) + >> if_p(edgeRHS)[!attr_list(actor_t(phoenix::bind( + &definition::edge_prop)( + var(*this), arg1, arg2)))] + .else_p[if_p(data_stmt.saw_node)[!attr_list( + actor_t(phoenix::bind( + &definition::node_prop)(var(*this), arg1, + arg2)))] // otherwise it's a subgraph, + // nothing more to do. + ]; + + stmt = graph_stmt | attr_stmt | data_stmt; + + stmt_list = *(stmt >> !ch_p(';')); + + subgraph = !(as_lower_d[keyword_p("subgraph")] + >> (!ID[(subgraph.name = arg1), + (subgraph.nodes + = (var(subgraph_nodes))[arg1]), + (subgraph.edges + = (var(subgraph_edges))[arg1])])) + >> ch_p('{')[++var(subgraph_depth)] >> stmt_list + >> ch_p('}')[--var(subgraph_depth)] + [(var(subgraph_nodes))[subgraph.name] + = subgraph.nodes] + [(var(subgraph_edges))[subgraph.name] + = subgraph.edges] + + | as_lower_d[keyword_p("subgraph")] + >> ID[(subgraph.nodes + = (var(subgraph_nodes))[arg1]), + (subgraph.edges = (var(subgraph_edges))[arg1])]; + + the_grammar = (!as_lower_d[keyword_p("strict")]) + >> (as_lower_d[keyword_p( + "graph")][(var(edge_head) = '-'), + (phoenix::bind(&definition::check_undirected)( + var(*this)))] + | as_lower_d[keyword_p( + "digraph")][(var(edge_head) = '>'), + (phoenix::bind(&definition::check_directed)( + var(*this)))]) + >> (!ID) >> ch_p('{') >> stmt_list >> ch_p('}'); + + } // definition() + + typedef boost::spirit::classic::rule< ScannerT > rule_t; + + rule_t const& start() const { return the_grammar; } + + // + // Semantic actions + // + + void check_undirected() + { + if (self.graph_.is_directed()) + boost::throw_exception(boost::undirected_graph_error()); + } + + void check_directed() + { + if (!self.graph_.is_directed()) + boost::throw_exception(boost::directed_graph_error()); + } + + void memoize_node() + { + id_t const& node = node_id.name(); + props_t& node_props = default_node_props; + + if (nodes.find(node) == nodes.end()) + { + nodes.insert(node); + self.graph_.do_add_vertex(node); + + node_map.insert(std::make_pair(node, ids_t())); #ifdef BOOST_GRAPH_DEBUG - std::cout << "Add new node " << node << std::endl; + std::cout << "Add new node " << node << std::endl; #endif // BOOST_GRAPH_DEBUG - // Set the default properties for this edge - // RG: Here I would actually set the properties - for(props_t::iterator i = node_props.begin(); - i != node_props.end(); ++i) { - set_node_property(node,i->first,i->second); - } - if(subgraph_depth > 0) { - subgraph.nodes().insert(node); - // Set the subgraph's default properties as well - props_t& props = subgraph_node_props[subgraph.name()]; - for(props_t::iterator i = props.begin(); i != props.end(); ++i) { - set_node_property(node,i->first,i->second); - } - } - } else { + // Set the default properties for this edge + // RG: Here I would actually set the properties + for (props_t::iterator i = node_props.begin(); + i != node_props.end(); ++i) + { + set_node_property(node, i->first, i->second); + } + if (subgraph_depth > 0) + { + subgraph.nodes().insert(node); + // Set the subgraph's default properties as well + props_t& props + = subgraph_node_props[subgraph.name()]; + for (props_t::iterator i = props.begin(); + i != props.end(); ++i) + { + set_node_property(node, i->first, i->second); + } + } + } + else + { #ifdef BOOST_GRAPH_DEBUG - std::cout << "See node " << node << std::endl; + std::cout << "See node " << node << std::endl; #endif // BOOST_GRAPH_DEBUG - } - } - - void activate_edge(nodes_t& sources, nodes_t& dests, edges_t& edges, - props_t& edge_props) { - edge_stack_t& edge_stack = data_stmt.edge_stack(); - for(nodes_t::iterator i = sources.begin(); i != sources.end(); ++i) { - for(nodes_t::iterator j = dests.begin(); j != dests.end(); ++j) { - // Create the edge and push onto the edge stack. + } + } + + void activate_edge(nodes_t& sources, nodes_t& dests, + edges_t& edges, props_t& edge_props) + { + edge_stack_t& edge_stack = data_stmt.edge_stack(); + for (nodes_t::iterator i = sources.begin(); + i != sources.end(); ++i) + { + for (nodes_t::iterator j = dests.begin(); + j != dests.end(); ++j) + { + // Create the edge and push onto the edge stack. #ifdef BOOST_GRAPH_DEBUG - std::cout << "Edge " << *i << " to " << *j << std::endl; + std::cout << "Edge " << *i << " to " << *j + << std::endl; #endif // BOOST_GRAPH_DEBUG - edge_t edge = edge_t::new_edge(); - edge_stack.push_back(edge); - edges.insert(edge); - edge_map.insert(std::make_pair(edge,ids_t())); - - // Add the real edge. - self.graph_.do_add_edge(edge, *i, *j); - - // Set the default properties for this edge - for(props_t::iterator k = edge_props.begin(); - k != edge_props.end(); ++k) { - set_edge_property(edge,k->first,k->second); - } - if(subgraph_depth > 0) { - subgraph.edges().insert(edge); - // Set the subgraph's default properties as well - props_t& props = subgraph_edge_props[subgraph.name()]; - for(props_t::iterator k = props.begin(); k != props.end(); ++k) { - set_edge_property(edge,k->first,k->second); - } - } - } - } - } - - // node_prop - Assign the property for the current active node. - void node_prop(id_t const& key, id_t const& value) { - node_t& active_object = data_stmt.active_node(); - set_node_property(active_object, key, value); - } - - // edge_prop - Assign the property for the current active edges. - void edge_prop(id_t const& key, id_t const& value) { - edge_stack_t const& active_edges_ = data_stmt.edge_stack(); - for (edge_stack_t::const_iterator i = active_edges_.begin(); - i != active_edges_.end(); ++i) { - set_edge_property(*i,key,value); - } - } - - // default_graph_prop - Store as a graph property. - void default_graph_prop(id_t const& key, id_t const& value) { + edge_t edge = edge_t::new_edge(); + edge_stack.push_back(edge); + edges.insert(edge); + edge_map.insert(std::make_pair(edge, ids_t())); + + // Add the real edge. + self.graph_.do_add_edge(edge, *i, *j); + + // Set the default properties for this edge + for (props_t::iterator k = edge_props.begin(); + k != edge_props.end(); ++k) + { + set_edge_property(edge, k->first, k->second); + } + if (subgraph_depth > 0) + { + subgraph.edges().insert(edge); + // Set the subgraph's default properties as well + props_t& props + = subgraph_edge_props[subgraph.name()]; + for (props_t::iterator k = props.begin(); + k != props.end(); ++k) + { + set_edge_property( + edge, k->first, k->second); + } + } + } + } + } + + // node_prop - Assign the property for the current active node. + void node_prop(id_t const& key, id_t const& value) + { + node_t& active_object = data_stmt.active_node(); + set_node_property(active_object, key, value); + } + + // edge_prop - Assign the property for the current active edges. + void edge_prop(id_t const& key, id_t const& value) + { + edge_stack_t const& active_edges_ = data_stmt.edge_stack(); + for (edge_stack_t::const_iterator i = active_edges_.begin(); + i != active_edges_.end(); ++i) + { + set_edge_property(*i, key, value); + } + } + + // default_graph_prop - Store as a graph property. + void default_graph_prop(id_t const& key, id_t const& value) + { #ifdef BOOST_GRAPH_DEBUG - std::cout << key << " = " << value << std::endl; + std::cout << key << " = " << value << std::endl; #endif // BOOST_GRAPH_DEBUG - self.graph_.set_graph_property(key, value); - } - - // default_node_prop - declare default properties for any future new nodes - void default_node_prop(id_t const& key, id_t const& value) { - nodes_t& nodes_ = - subgraph_depth == 0 ? nodes : subgraph.nodes(); - props_t& node_props_ = - subgraph_depth == 0 ? - default_node_props : - subgraph_node_props[subgraph.name()]; - - // add this to the selected list of default node properties. - node_props_[key] = value; - // for each node, set its property to default-constructed value - // if it hasn't been set already. - // set the dynamic property map value - for(nodes_t::iterator i = nodes_.begin(); i != nodes_.end(); ++i) - if(node_map[*i].find(key) == node_map[*i].end()) { - set_node_property(*i,key,id_t()); - } - } - - // default_edge_prop - declare default properties for any future new edges - void default_edge_prop(id_t const& key, id_t const& value) { - edges_t& edges_ = - subgraph_depth == 0 ? edges : subgraph.edges(); - props_t& edge_props_ = - subgraph_depth == 0 ? - default_edge_props : - subgraph_edge_props[subgraph.name()]; - - // add this to the list of default edge properties. - edge_props_[key] = value; - // for each edge, set its property to be empty string - // set the dynamic property map value - for(edges_t::iterator i = edges_.begin(); i != edges_.end(); ++i) - if(edge_map[*i].find(key) == edge_map[*i].end()) - set_edge_property(*i,key,id_t()); - } - - // helper function - void insert_node(nodes_t& nodes, id_t const& name) { - nodes.insert(name); - } - - void call_prop_actor(std::string const& lhs, std::string const& rhs) { - actor_t& actor = attr_list.prop_actor(); - // If first and last characters of the rhs are double-quotes, - // remove them. - if (!rhs.empty() && rhs[0] == '"' && rhs[rhs.size() - 1] == '"') - actor(lhs, rhs.substr(1, rhs.size()-2)); - else - actor(lhs,rhs); - } - - void call_graph_prop(std::string const& lhs, std::string const& rhs) { - // If first and last characters of the rhs are double-quotes, - // remove them. - if (!rhs.empty() && rhs[0] == '"' && rhs[rhs.size() - 1] == '"') - this->default_graph_prop(lhs, rhs.substr(1, rhs.size()-2)); - else - this->default_graph_prop(lhs,rhs); - } - - void set_node_property(node_t const& node, id_t const& key, - id_t const& value) { - - // Add the property key to the "set" table to avoid default overwrite - node_map[node].insert(key); - // Set the user's property map - self.graph_.set_node_property(key, node, value); + self.graph_.set_graph_property(key, value); + } + + // default_node_prop - declare default properties for any future + // new nodes + void default_node_prop(id_t const& key, id_t const& value) + { + nodes_t& nodes_ + = subgraph_depth == 0 ? nodes : subgraph.nodes(); + props_t& node_props_ = subgraph_depth == 0 + ? default_node_props + : subgraph_node_props[subgraph.name()]; + + // add this to the selected list of default node properties. + node_props_[key] = value; + // for each node, set its property to default-constructed + // value + // if it hasn't been set already. + // set the dynamic property map value + for (nodes_t::iterator i = nodes_.begin(); + i != nodes_.end(); ++i) + if (node_map[*i].find(key) == node_map[*i].end()) + { + set_node_property(*i, key, id_t()); + } + } + + // default_edge_prop - declare default properties for any future + // new edges + void default_edge_prop(id_t const& key, id_t const& value) + { + edges_t& edges_ + = subgraph_depth == 0 ? edges : subgraph.edges(); + props_t& edge_props_ = subgraph_depth == 0 + ? default_edge_props + : subgraph_edge_props[subgraph.name()]; + + // add this to the list of default edge properties. + edge_props_[key] = value; + // for each edge, set its property to be empty string + // set the dynamic property map value + for (edges_t::iterator i = edges_.begin(); + i != edges_.end(); ++i) + if (edge_map[*i].find(key) == edge_map[*i].end()) + set_edge_property(*i, key, id_t()); + } + + // helper function + void insert_node(nodes_t& nodes, id_t const& name) + { + nodes.insert(name); + } + + void call_prop_actor( + std::string const& lhs, std::string const& rhs) + { + actor_t& actor = attr_list.prop_actor(); + // If first and last characters of the rhs are + // double-quotes, remove them. + if (!rhs.empty() && rhs[0] == '"' + && rhs[rhs.size() - 1] == '"') + actor(lhs, rhs.substr(1, rhs.size() - 2)); + else + actor(lhs, rhs); + } + + void call_graph_prop( + std::string const& lhs, std::string const& rhs) + { + // If first and last characters of the rhs are + // double-quotes, remove them. + if (!rhs.empty() && rhs[0] == '"' + && rhs[rhs.size() - 1] == '"') + this->default_graph_prop( + lhs, rhs.substr(1, rhs.size() - 2)); + else + this->default_graph_prop(lhs, rhs); + } + + void set_node_property( + node_t const& node, id_t const& key, id_t const& value) + { + + // Add the property key to the "set" table to avoid default + // overwrite + node_map[node].insert(key); + // Set the user's property map + self.graph_.set_node_property(key, node, value); #ifdef BOOST_GRAPH_DEBUG - // Tell the world - std::cout << node << ": " << key << " = " << value << std::endl; + // Tell the world + std::cout << node << ": " << key << " = " << value + << std::endl; #endif // BOOST_GRAPH_DEBUG - } + } - void set_edge_property(edge_t const& edge, id_t const& key, - id_t const& value) { + void set_edge_property( + edge_t const& edge, id_t const& key, id_t const& value) + { - // Add the property key to the "set" table to avoid default overwrite - edge_map[edge].insert(key); - // Set the user's property map - self.graph_.set_edge_property(key, edge, value); + // Add the property key to the "set" table to avoid default + // overwrite + edge_map[edge].insert(key); + // Set the user's property map + self.graph_.set_edge_property(key, edge, value); #ifdef BOOST_GRAPH_DEBUG - // Tell the world -#if 0 // RG - edge representation changed, + // Tell the world +#if 0 // RG - edge representation changed, std::cout << "(" << edge.first << "," << edge.second << "): " #else - std::cout << "an edge: " + std::cout << "an edge: " #endif // 0 - << key << " = " << value << std::endl; + << key << " = " << value << std::endl; #endif // BOOST_GRAPH_DEBUG - } - - // Variables explicitly initialized - dot_grammar const& self; - // if subgraph_depth > 0, then we're processing a subgraph. - int subgraph_depth; - - // Keywords; - const boost::spirit::classic::distinct_parser<> keyword_p; - // - // rules that make up the grammar - // - boost::spirit::classic::rule<ScannerT,id_closure::context_t> ID; - boost::spirit::classic::rule<ScannerT,property_closure::context_t> a_list; - boost::spirit::classic::rule<ScannerT,attr_list_closure::context_t> attr_list; - rule_t port_location; - rule_t port_angle; - rule_t port; - boost::spirit::classic::rule<ScannerT,node_id_closure::context_t> node_id; - boost::spirit::classic::rule<ScannerT,property_closure::context_t> graph_stmt; - rule_t attr_stmt; - boost::spirit::classic::rule<ScannerT,data_stmt_closure::context_t> data_stmt; - boost::spirit::classic::rule<ScannerT,subgraph_closure::context_t> subgraph; - rule_t edgeop; - rule_t edgeRHS; - rule_t stmt; - rule_t stmt_list; - rule_t the_grammar; - - - // The grammar uses edge_head to dynamically set the syntax for edges - // directed graphs: edge_head = '>', and so edgeop = "->" - // undirected graphs: edge_head = '-', and so edgeop = "--" - char edge_head; - - - // - // Support data structures - // - - nodes_t nodes; // list of node names seen - edges_t edges; // list of edges seen - node_map_t node_map; // remember the properties set for each node - edge_map_t edge_map; // remember the properties set for each edge - - subgraph_nodes_t subgraph_nodes; // per-subgraph lists of nodes - subgraph_edges_t subgraph_edges; // per-subgraph lists of edges - - props_t default_node_props; // global default node properties - props_t default_edge_props; // global default edge properties - subgraph_props_t subgraph_node_props; // per-subgraph default node properties - subgraph_props_t subgraph_edge_props; // per-subgraph default edge properties - }; // struct definition -}; // struct dot_grammar - - - -// -// dot_skipper - GraphViz whitespace and comment skipper -// -struct dot_skipper : public boost::spirit::classic::grammar<dot_skipper> -{ - dot_skipper() {} - - template <typename ScannerT> - struct definition - { - definition(dot_skipper const& /*self*/) { - using namespace boost::spirit::classic; - using namespace phoenix; - // comment forms - skip = eol_p >> comment_p("#") - | space_p - | comment_p("//") + } + + // Variables explicitly initialized + dot_grammar const& self; + // if subgraph_depth > 0, then we're processing a subgraph. + int subgraph_depth; + + // Keywords; + const boost::spirit::classic::distinct_parser<> keyword_p; + // + // rules that make up the grammar + // + boost::spirit::classic::rule< ScannerT, id_closure::context_t > + ID; + boost::spirit::classic::rule< ScannerT, + property_closure::context_t > + a_list; + boost::spirit::classic::rule< ScannerT, + attr_list_closure::context_t > + attr_list; + rule_t port_location; + rule_t port_angle; + rule_t port; + boost::spirit::classic::rule< ScannerT, + node_id_closure::context_t > + node_id; + boost::spirit::classic::rule< ScannerT, + property_closure::context_t > + graph_stmt; + rule_t attr_stmt; + boost::spirit::classic::rule< ScannerT, + data_stmt_closure::context_t > + data_stmt; + boost::spirit::classic::rule< ScannerT, + subgraph_closure::context_t > + subgraph; + rule_t edgeop; + rule_t edgeRHS; + rule_t stmt; + rule_t stmt_list; + rule_t the_grammar; + + // The grammar uses edge_head to dynamically set the syntax for + // edges directed graphs: edge_head = '>', and so edgeop = "->" + // undirected graphs: edge_head = '-', and so edgeop = "--" + char edge_head; + + // + // Support data structures + // + + nodes_t nodes; // list of node names seen + edges_t edges; // list of edges seen + node_map_t + node_map; // remember the properties set for each node + edge_map_t + edge_map; // remember the properties set for each edge + + subgraph_nodes_t subgraph_nodes; // per-subgraph lists of nodes + subgraph_edges_t subgraph_edges; // per-subgraph lists of edges + + props_t default_node_props; // global default node properties + props_t default_edge_props; // global default edge properties + subgraph_props_t + subgraph_node_props; // per-subgraph default node properties + subgraph_props_t + subgraph_edge_props; // per-subgraph default edge properties + }; // struct definition + }; // struct dot_grammar + + // + // dot_skipper - GraphViz whitespace and comment skipper + // + struct dot_skipper + : public boost::spirit::classic::grammar< dot_skipper > + { + dot_skipper() {} + + template < typename ScannerT > struct definition + { + definition(dot_skipper const& /*self*/) + { + using namespace boost::spirit::classic; + using namespace phoenix; + // comment forms + skip = eol_p >> comment_p("#") | space_p | comment_p("//") #if BOOST_WORKAROUND(BOOST_MSVC, <= 1400) - | confix_p(str_p("/*") ,*anychar_p, str_p("*/")) + | confix_p(str_p("/*"), *anychar_p, str_p("*/")) #else - | confix_p("/*" ,*anychar_p, "*/") + | confix_p("/*", *anychar_p, "*/") #endif - ; + ; #ifdef BOOST_SPIRIT_DEBUG - BOOST_SPIRIT_DEBUG_RULE(skip); + BOOST_SPIRIT_DEBUG_RULE(skip); #endif - } + } - boost::spirit::classic::rule<ScannerT> skip; - boost::spirit::classic::rule<ScannerT> const& - start() const { return skip; } - }; // definition -}; // dot_skipper + boost::spirit::classic::rule< ScannerT > skip; + boost::spirit::classic::rule< ScannerT > const& start() const + { + return skip; + } + }; // definition + }; // dot_skipper -} // namespace graph + } // namespace graph } // namespace detail -template <typename MultiPassIterator, typename MutableGraph> +template < typename MultiPassIterator, typename MutableGraph > bool read_graphviz_spirit(MultiPassIterator begin, MultiPassIterator end, - MutableGraph& graph, dynamic_properties& dp, - std::string const& node_id = "node_id") { - using namespace boost; - using namespace boost::spirit::classic; + MutableGraph& graph, dynamic_properties& dp, + std::string const& node_id = "node_id") +{ + using namespace boost; + using namespace boost::spirit::classic; - typedef MultiPassIterator iterator_t; - typedef skip_parser_iteration_policy< boost::detail::graph::dot_skipper> - iter_policy_t; - typedef scanner_policies<iter_policy_t> scanner_policies_t; - typedef scanner<iterator_t, scanner_policies_t> scanner_t; + typedef MultiPassIterator iterator_t; + typedef skip_parser_iteration_policy< boost::detail::graph::dot_skipper > + iter_policy_t; + typedef scanner_policies< iter_policy_t > scanner_policies_t; + typedef scanner< iterator_t, scanner_policies_t > scanner_t; - ::boost::detail::graph::mutate_graph_impl<MutableGraph> - m_graph(graph, dp, node_id); + ::boost::detail::graph::mutate_graph_impl< MutableGraph > m_graph( + graph, dp, node_id); - ::boost::detail::graph::dot_grammar p(m_graph); - ::boost::detail::graph::dot_skipper skip_p; + ::boost::detail::graph::dot_grammar p(m_graph); + ::boost::detail::graph::dot_skipper skip_p; - iter_policy_t iter_policy(skip_p); - scanner_policies_t policies(iter_policy); + iter_policy_t iter_policy(skip_p); + scanner_policies_t policies(iter_policy); - scanner_t scan(begin, end, policies); + scanner_t scan(begin, end, policies); - bool ok = p.parse(scan); - m_graph.finish_building_graph(); - return ok; + bool ok = p.parse(scan); + m_graph.finish_building_graph(); + return ok; } } // namespace boost diff --git a/contrib/restricted/boost/graph/include/boost/graph/detail/set_adaptor.hpp b/contrib/restricted/boost/graph/include/boost/graph/detail/set_adaptor.hpp index 33acc07e3a..487d3be2fb 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/detail/set_adaptor.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/detail/set_adaptor.hpp @@ -9,115 +9,110 @@ #include <set> #include <boost/unordered_set.hpp> -namespace boost { +namespace boost +{ - template <class K, class C, class A, class T> - bool set_contains(const std::set<K,C,A>& s, const T& x) { - return s.find(x) != s.end(); - } - - template <class K, class H, class C, class A, class T> - bool set_contains(const boost::unordered_set<K,H,C,A>& s, const T& x) { - return s.find(x) != s.end(); - } - - template <class K, class C, class A> - bool set_equal(const std::set<K,C,A>& x, - const std::set<K,C,A>& y) - { - return x == y; - } +template < class K, class C, class A, class T > +bool set_contains(const std::set< K, C, A >& s, const T& x) +{ + return s.find(x) != s.end(); +} + +template < class K, class H, class C, class A, class T > +bool set_contains(const boost::unordered_set< K, H, C, A >& s, const T& x) +{ + return s.find(x) != s.end(); +} + +template < class K, class C, class A > +bool set_equal(const std::set< K, C, A >& x, const std::set< K, C, A >& y) +{ + return x == y; +} - // Not the same as lexicographical_compare_3way applied to std::set. - // this is equivalent semantically to bitset::operator<() - template <class K, class C, class A> - int set_lex_order(const std::set<K,C,A>& x, - const std::set<K,C,A>& y) +// Not the same as lexicographical_compare_3way applied to std::set. +// this is equivalent semantically to bitset::operator<() +template < class K, class C, class A > +int set_lex_order(const std::set< K, C, A >& x, const std::set< K, C, A >& y) +{ + typename std::set< K, C, A >::iterator xi = x.begin(), yi = y.begin(), + xend = x.end(), yend = y.end(); + for (; xi != xend && yi != yend; ++xi, ++yi) { - typename std::set<K,C,A>::iterator - xi = x.begin(), yi = y.begin(), xend = x.end(), yend = y.end(); - for (; xi != xend && yi != yend; ++xi, ++yi) { if (*xi < *yi) - return 1; + return 1; else if (*yi < *xi) - return -1; - } - if (xi == xend) + return -1; + } + if (xi == xend) return (yi == yend) ? 0 : -1; - else + else return 1; - } +} - template <class K, class C, class A> - void set_clear(std::set<K,C,A>& x) { - x.clear(); - } +template < class K, class C, class A > void set_clear(std::set< K, C, A >& x) +{ + x.clear(); +} - template <class K, class C, class A> - bool set_empty(const std::set<K,C,A>& x) { - return x.empty(); - } +template < class K, class C, class A > +bool set_empty(const std::set< K, C, A >& x) +{ + return x.empty(); +} - template <class K, class C, class A, class T> - void set_insert(std::set<K,C,A>& x, const T& a) { - x.insert(a); - } +template < class K, class C, class A, class T > +void set_insert(std::set< K, C, A >& x, const T& a) +{ + x.insert(a); +} - template <class K, class C, class A, class T> - void set_remove(std::set<K,C,A>& x, const T& a) { - x.erase(a); - } - - template <class K, class C, class A> - void set_intersect(const std::set<K,C,A>& x, - const std::set<K,C,A>& y, - std::set<K,C,A>& z) - { - z.clear(); - std::set_intersection(x.begin(), x.end(), - y.begin(), y.end(), - std::inserter(z)); - } +template < class K, class C, class A, class T > +void set_remove(std::set< K, C, A >& x, const T& a) +{ + x.erase(a); +} - template <class K, class C, class A> - void set_union(const std::set<K,C,A>& x, - const std::set<K,C,A>& y, - std::set<K,C,A>& z) - { - z.clear(); - std::set_union(x.begin(), x.end(), - y.begin(), y.end(), - std::inserter(z)); - } +template < class K, class C, class A > +void set_intersect(const std::set< K, C, A >& x, const std::set< K, C, A >& y, + std::set< K, C, A >& z) +{ + z.clear(); + std::set_intersection( + x.begin(), x.end(), y.begin(), y.end(), std::inserter(z)); +} - template <class K, class C, class A> - void set_difference(const std::set<K,C,A>& x, - const std::set<K,C,A>& y, - std::set<K,C,A>& z) - { - z.clear(); - std::set_difference(x.begin(), x.end(), - y.begin(), y.end(), - std::inserter(z, z.begin())); - } +template < class K, class C, class A > +void set_union(const std::set< K, C, A >& x, const std::set< K, C, A >& y, + std::set< K, C, A >& z) +{ + z.clear(); + std::set_union(x.begin(), x.end(), y.begin(), y.end(), std::inserter(z)); +} - template <class K, class C, class A> - bool set_subset(const std::set<K,C,A>& x, - const std::set<K,C,A>& y) - { - return std::includes(x.begin(), x.end(), y.begin(), y.end()); - } +template < class K, class C, class A > +void set_difference(const std::set< K, C, A >& x, const std::set< K, C, A >& y, + std::set< K, C, A >& z) +{ + z.clear(); + std::set_difference( + x.begin(), x.end(), y.begin(), y.end(), std::inserter(z, z.begin())); +} - // Shit, can't implement this without knowing the size of the - // universe. - template <class K, class C, class A> - void set_compliment(const std::set<K,C,A>& /*x*/, - std::set<K,C,A>& z) - { - z.clear(); - - } - -} // namespace boost +template < class K, class C, class A > +bool set_subset(const std::set< K, C, A >& x, const std::set< K, C, A >& y) +{ + return std::includes(x.begin(), x.end(), y.begin(), y.end()); +} + +// Shit, can't implement this without knowing the size of the +// universe. +template < class K, class C, class A > +void set_compliment(const std::set< K, C, A >& /*x*/, std::set< K, C, A >& z) +{ + z.clear(); +} + +} // namespace boost #endif // BOOST_SET_ADAPTOR_HPP diff --git a/contrib/restricted/boost/graph/include/boost/graph/dijkstra_shortest_paths.hpp b/contrib/restricted/boost/graph/include/boost/graph/dijkstra_shortest_paths.hpp index 0d9de1f4d6..8d3c0705ca 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/dijkstra_shortest_paths.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/dijkstra_shortest_paths.hpp @@ -22,602 +22,559 @@ #include <boost/graph/relax.hpp> #include <boost/pending/indirect_cmp.hpp> #include <boost/graph/exception.hpp> -#include <boost/pending/relaxed_heap.hpp> #include <boost/graph/overloading.hpp> #include <boost/smart_ptr.hpp> #include <boost/graph/detail/d_ary_heap.hpp> #include <boost/graph/two_bit_color_map.hpp> +#include <boost/graph/detail/mpi_include.hpp> #include <boost/property_map/property_map.hpp> #include <boost/property_map/vector_property_map.hpp> #include <boost/type_traits.hpp> #include <boost/concept/assert.hpp> #ifdef BOOST_GRAPH_DIJKSTRA_TESTING -# include <boost/pending/mutable_queue.hpp> +#include <boost/pending/mutable_queue.hpp> #endif // BOOST_GRAPH_DIJKSTRA_TESTING -namespace boost { - - /** - * @brief Updates a particular value in a queue used by Dijkstra's - * algorithm. - * - * This routine is called by Dijkstra's algorithm after it has - * decreased the distance from the source vertex to the given @p - * vertex. By default, this routine will just call @c - * Q.update(vertex). However, other queues may provide more - * specialized versions of this routine. - * - * @param Q the queue that will be updated. - * @param vertex the vertex whose distance has been updated - * @param old_distance the previous distance to @p vertex - */ - template<typename Buffer, typename Vertex, typename DistanceType> - inline void - dijkstra_queue_update(Buffer& Q, Vertex vertex, DistanceType old_distance) - { +namespace boost +{ + +/** + * @brief Updates a particular value in a queue used by Dijkstra's + * algorithm. + * + * This routine is called by Dijkstra's algorithm after it has + * decreased the distance from the source vertex to the given @p + * vertex. By default, this routine will just call @c + * Q.update(vertex). However, other queues may provide more + * specialized versions of this routine. + * + * @param Q the queue that will be updated. + * @param vertex the vertex whose distance has been updated + * @param old_distance the previous distance to @p vertex + */ +template < typename Buffer, typename Vertex, typename DistanceType > +inline void dijkstra_queue_update( + Buffer& Q, Vertex vertex, DistanceType old_distance) +{ (void)old_distance; Q.update(vertex); - } +} -#ifdef BOOST_GRAPH_DIJKSTRA_TESTING - // This is a misnomer now: it now just refers to the "default heap", which is - // currently d-ary (d=4) but can be changed by a #define. - static bool dijkstra_relaxed_heap = true; -#endif - - template <class Visitor, class Graph> - struct DijkstraVisitorConcept { - void constraints() { - BOOST_CONCEPT_ASSERT(( CopyConstructibleConcept<Visitor> )); - vis.initialize_vertex(u, g); - vis.discover_vertex(u, g); - vis.examine_vertex(u, g); - vis.examine_edge(e, g); - vis.edge_relaxed(e, g); - vis.edge_not_relaxed(e, g); - vis.finish_vertex(u, g); +template < class Visitor, class Graph > struct DijkstraVisitorConcept +{ + void constraints() + { + BOOST_CONCEPT_ASSERT((CopyConstructibleConcept< Visitor >)); + vis.initialize_vertex(u, g); + vis.discover_vertex(u, g); + vis.examine_vertex(u, g); + vis.examine_edge(e, g); + vis.edge_relaxed(e, g); + vis.edge_not_relaxed(e, g); + vis.finish_vertex(u, g); } Visitor vis; Graph g; - typename graph_traits<Graph>::vertex_descriptor u; - typename graph_traits<Graph>::edge_descriptor e; - }; - - template <class Visitors = null_visitor> - class dijkstra_visitor : public bfs_visitor<Visitors> { - public: - dijkstra_visitor() { } - dijkstra_visitor(Visitors vis) - : bfs_visitor<Visitors>(vis) { } - - template <class Edge, class Graph> - void edge_relaxed(Edge e, Graph& g) { - invoke_visitors(this->m_vis, e, g, on_edge_relaxed()); + typename graph_traits< Graph >::vertex_descriptor u; + typename graph_traits< Graph >::edge_descriptor e; +}; + +template < class Visitors = null_visitor > +class dijkstra_visitor : public bfs_visitor< Visitors > +{ +public: + dijkstra_visitor() {} + dijkstra_visitor(Visitors vis) : bfs_visitor< Visitors >(vis) {} + + template < class Edge, class Graph > void edge_relaxed(Edge e, Graph& g) + { + invoke_visitors(this->m_vis, e, g, on_edge_relaxed()); } - template <class Edge, class Graph> - void edge_not_relaxed(Edge e, Graph& g) { - invoke_visitors(this->m_vis, e, g, on_edge_not_relaxed()); + template < class Edge, class Graph > void edge_not_relaxed(Edge e, Graph& g) + { + invoke_visitors(this->m_vis, e, g, on_edge_not_relaxed()); } - private: - template <class Edge, class Graph> - void tree_edge(Edge /* u */, Graph& /* g */) { } - }; - template <class Visitors> - dijkstra_visitor<Visitors> - make_dijkstra_visitor(Visitors vis) { - return dijkstra_visitor<Visitors>(vis); - } - typedef dijkstra_visitor<> default_dijkstra_visitor; - - namespace detail { - - template <class UniformCostVisitor, class UpdatableQueue, - class WeightMap, class PredecessorMap, class DistanceMap, - class BinaryFunction, class BinaryPredicate> + +private: + template < class Edge, class Graph > void tree_edge(Edge /* u */, Graph& /* g */) {} +}; +template < class Visitors > +dijkstra_visitor< Visitors > make_dijkstra_visitor(Visitors vis) +{ + return dijkstra_visitor< Visitors >(vis); +} +typedef dijkstra_visitor<> default_dijkstra_visitor; + +namespace detail +{ + + template < class UniformCostVisitor, class UpdatableQueue, class WeightMap, + class PredecessorMap, class DistanceMap, class BinaryFunction, + class BinaryPredicate > struct dijkstra_bfs_visitor { - typedef typename property_traits<DistanceMap>::value_type D; - typedef typename property_traits<WeightMap>::value_type W; - - dijkstra_bfs_visitor(UniformCostVisitor vis, UpdatableQueue& Q, - WeightMap w, PredecessorMap p, DistanceMap d, - BinaryFunction combine, BinaryPredicate compare, - D zero) - : m_vis(vis), m_Q(Q), m_weight(w), m_predecessor(p), m_distance(d), - m_combine(combine), m_compare(compare), m_zero(zero) { } - - template <class Edge, class Graph> - void tree_edge(Edge e, Graph& g) { - bool decreased = relax(e, g, m_weight, m_predecessor, m_distance, - m_combine, m_compare); - if (decreased) - m_vis.edge_relaxed(e, g); - else - m_vis.edge_not_relaxed(e, g); - } - template <class Edge, class Graph> - void gray_target(Edge e, Graph& g) { - D old_distance = get(m_distance, target(e, g)); - - bool decreased = relax(e, g, m_weight, m_predecessor, m_distance, - m_combine, m_compare); - if (decreased) { - dijkstra_queue_update(m_Q, target(e, g), old_distance); - m_vis.edge_relaxed(e, g); - } else - m_vis.edge_not_relaxed(e, g); - } - - template <class Vertex, class Graph> - void initialize_vertex(Vertex u, Graph& g) - { m_vis.initialize_vertex(u, g); } - template <class Edge, class Graph> - void non_tree_edge(Edge, Graph&) { } - template <class Vertex, class Graph> - void discover_vertex(Vertex u, Graph& g) { m_vis.discover_vertex(u, g); } - template <class Vertex, class Graph> - void examine_vertex(Vertex u, Graph& g) { m_vis.examine_vertex(u, g); } - template <class Edge, class Graph> - void examine_edge(Edge e, Graph& g) { - // Test for negative-weight edges: - // - // Reasons that other comparisons do not work: - // - // m_compare(e_weight, D(0)): - // m_compare only needs to work on distances, not weights, and those - // types do not need to be the same (bug 8398, - // https://svn.boost.org/trac/boost/ticket/8398). - // m_compare(m_combine(source_dist, e_weight), source_dist): - // if m_combine is project2nd (as in prim_minimum_spanning_tree), - // this test will claim that the edge weight is negative whenever - // the edge weight is less than source_dist, even if both of those - // are positive (bug 9012, - // https://svn.boost.org/trac/boost/ticket/9012). - // m_compare(m_combine(e_weight, source_dist), source_dist): - // would fix project2nd issue, but documentation only requires that - // m_combine be able to take a distance and a weight (in that order) - // and return a distance. - - // W e_weight = get(m_weight, e); - // sd_plus_ew = source_dist + e_weight. - // D sd_plus_ew = m_combine(source_dist, e_weight); - // sd_plus_2ew = source_dist + 2 * e_weight. - // D sd_plus_2ew = m_combine(sd_plus_ew, e_weight); - // The test here is equivalent to e_weight < 0 if m_combine has a - // cancellation law, but always returns false when m_combine is a - // projection operator. - if (m_compare(m_combine(m_zero, get(m_weight, e)), m_zero)) - boost::throw_exception(negative_edge()); - // End of test for negative-weight edges. - - m_vis.examine_edge(e, g); - - } - template <class Edge, class Graph> - void black_target(Edge, Graph&) { } - template <class Vertex, class Graph> - void finish_vertex(Vertex u, Graph& g) { m_vis.finish_vertex(u, g); } - - UniformCostVisitor m_vis; - UpdatableQueue& m_Q; - WeightMap m_weight; - PredecessorMap m_predecessor; - DistanceMap m_distance; - BinaryFunction m_combine; - BinaryPredicate m_compare; - D m_zero; + typedef typename property_traits< DistanceMap >::value_type D; + typedef typename property_traits< WeightMap >::value_type W; + + dijkstra_bfs_visitor(UniformCostVisitor vis, UpdatableQueue& Q, + WeightMap w, PredecessorMap p, DistanceMap d, + BinaryFunction combine, BinaryPredicate compare, D zero) + : m_vis(vis) + , m_Q(Q) + , m_weight(w) + , m_predecessor(p) + , m_distance(d) + , m_combine(combine) + , m_compare(compare) + , m_zero(zero) + { + } + + template < class Edge, class Graph > void tree_edge(Edge e, Graph& g) + { + bool decreased = relax_target(e, g, m_weight, m_predecessor, + m_distance, m_combine, m_compare); + if (decreased) + m_vis.edge_relaxed(e, g); + else + m_vis.edge_not_relaxed(e, g); + } + template < class Edge, class Graph > void gray_target(Edge e, Graph& g) + { + D old_distance = get(m_distance, target(e, g)); + + bool decreased = relax_target(e, g, m_weight, m_predecessor, + m_distance, m_combine, m_compare); + if (decreased) + { + dijkstra_queue_update(m_Q, target(e, g), old_distance); + m_vis.edge_relaxed(e, g); + } + else + m_vis.edge_not_relaxed(e, g); + } + + template < class Vertex, class Graph > + void initialize_vertex(Vertex u, Graph& g) + { + m_vis.initialize_vertex(u, g); + } + template < class Edge, class Graph > void non_tree_edge(Edge, Graph&) {} + template < class Vertex, class Graph > + void discover_vertex(Vertex u, Graph& g) + { + m_vis.discover_vertex(u, g); + } + template < class Vertex, class Graph > + void examine_vertex(Vertex u, Graph& g) + { + m_vis.examine_vertex(u, g); + } + template < class Edge, class Graph > void examine_edge(Edge e, Graph& g) + { + // Test for negative-weight edges: + // + // Reasons that other comparisons do not work: + // + // m_compare(e_weight, D(0)): + // m_compare only needs to work on distances, not weights, and + // those types do not need to be the same (bug 8398, + // https://svn.boost.org/trac/boost/ticket/8398). + // m_compare(m_combine(source_dist, e_weight), source_dist): + // if m_combine is project2nd (as in prim_minimum_spanning_tree), + // this test will claim that the edge weight is negative whenever + // the edge weight is less than source_dist, even if both of + // those are positive (bug 9012, + // https://svn.boost.org/trac/boost/ticket/9012). + // m_compare(m_combine(e_weight, source_dist), source_dist): + // would fix project2nd issue, but documentation only requires + // that m_combine be able to take a distance and a weight (in + // that order) and return a distance. + + // W e_weight = get(m_weight, e); + // sd_plus_ew = source_dist + e_weight. + // D sd_plus_ew = m_combine(source_dist, e_weight); + // sd_plus_2ew = source_dist + 2 * e_weight. + // D sd_plus_2ew = m_combine(sd_plus_ew, e_weight); + // The test here is equivalent to e_weight < 0 if m_combine has a + // cancellation law, but always returns false when m_combine is a + // projection operator. + if (m_compare(m_combine(m_zero, get(m_weight, e)), m_zero)) + boost::throw_exception(negative_edge()); + // End of test for negative-weight edges. + + m_vis.examine_edge(e, g); + } + template < class Edge, class Graph > void black_target(Edge, Graph&) {} + template < class Vertex, class Graph > + void finish_vertex(Vertex u, Graph& g) + { + m_vis.finish_vertex(u, g); + } + + UniformCostVisitor m_vis; + UpdatableQueue& m_Q; + WeightMap m_weight; + PredecessorMap m_predecessor; + DistanceMap m_distance; + BinaryFunction m_combine; + BinaryPredicate m_compare; + D m_zero; }; - } // namespace detail +} // namespace detail - namespace detail { - template <class Graph, class IndexMap, class Value, bool KnownNumVertices> - struct vertex_property_map_generator_helper {}; +namespace detail +{ + template < class Graph, class IndexMap, class Value, bool KnownNumVertices > + struct vertex_property_map_generator_helper + { + }; - template <class Graph, class IndexMap, class Value> - struct vertex_property_map_generator_helper<Graph, IndexMap, Value, true> { - typedef boost::iterator_property_map<Value*, IndexMap> type; - static type build(const Graph& g, const IndexMap& index, boost::scoped_array<Value>& array_holder) { - array_holder.reset(new Value[num_vertices(g)]); - std::fill(array_holder.get(), array_holder.get() + num_vertices(g), Value()); - return make_iterator_property_map(array_holder.get(), index); - } + template < class Graph, class IndexMap, class Value > + struct vertex_property_map_generator_helper< Graph, IndexMap, Value, true > + { + typedef boost::iterator_property_map< Value*, IndexMap > type; + static type build(const Graph& g, const IndexMap& index, + boost::scoped_array< Value >& array_holder) + { + array_holder.reset(new Value[num_vertices(g)]); + std::fill(array_holder.get(), array_holder.get() + num_vertices(g), + Value()); + return make_iterator_property_map(array_holder.get(), index); + } }; - template <class Graph, class IndexMap, class Value> - struct vertex_property_map_generator_helper<Graph, IndexMap, Value, false> { - typedef boost::vector_property_map<Value, IndexMap> type; - static type build(const Graph& /* g */, const IndexMap& index, boost::scoped_array<Value>& /* array_holder */) { - return boost::make_vector_property_map<Value>(index); - } + template < class Graph, class IndexMap, class Value > + struct vertex_property_map_generator_helper< Graph, IndexMap, Value, false > + { + typedef boost::vector_property_map< Value, IndexMap > type; + static type build(const Graph& /* g */, const IndexMap& index, + boost::scoped_array< Value >& /* array_holder */) + { + return boost::make_vector_property_map< Value >(index); + } }; - template <class Graph, class IndexMap, class Value> - struct vertex_property_map_generator { - typedef boost::is_base_and_derived< - boost::vertex_list_graph_tag, - typename boost::graph_traits<Graph>::traversal_category> - known_num_vertices; - typedef vertex_property_map_generator_helper<Graph, IndexMap, Value, known_num_vertices::value> helper; - typedef typename helper::type type; - static type build(const Graph& g, const IndexMap& index, boost::scoped_array<Value>& array_holder) { - return helper::build(g, index, array_holder); - } + template < class Graph, class IndexMap, class Value > + struct vertex_property_map_generator + { + typedef boost::is_base_and_derived< boost::vertex_list_graph_tag, + typename boost::graph_traits< Graph >::traversal_category > + known_num_vertices; + typedef vertex_property_map_generator_helper< Graph, IndexMap, Value, + known_num_vertices::value > + helper; + typedef typename helper::type type; + static type build(const Graph& g, const IndexMap& index, + boost::scoped_array< Value >& array_holder) + { + return helper::build(g, index, array_holder); + } }; - } - - namespace detail { - template <class Graph, class IndexMap, bool KnownNumVertices> - struct default_color_map_generator_helper {}; - - template <class Graph, class IndexMap> - struct default_color_map_generator_helper<Graph, IndexMap, true> { - typedef boost::two_bit_color_map<IndexMap> type; - static type build(const Graph& g, const IndexMap& index) { - size_t nv = num_vertices(g); - return boost::two_bit_color_map<IndexMap>(nv, index); - } +} + +namespace detail +{ + template < class Graph, class IndexMap, bool KnownNumVertices > + struct default_color_map_generator_helper + { + }; + + template < class Graph, class IndexMap > + struct default_color_map_generator_helper< Graph, IndexMap, true > + { + typedef boost::two_bit_color_map< IndexMap > type; + static type build(const Graph& g, const IndexMap& index) + { + size_t nv = num_vertices(g); + return boost::two_bit_color_map< IndexMap >(nv, index); + } }; - template <class Graph, class IndexMap> - struct default_color_map_generator_helper<Graph, IndexMap, false> { - typedef boost::vector_property_map<boost::two_bit_color_type, IndexMap> type; - static type build(const Graph& /* g */, const IndexMap& index) { - return boost::make_vector_property_map<boost::two_bit_color_type>(index); - } + template < class Graph, class IndexMap > + struct default_color_map_generator_helper< Graph, IndexMap, false > + { + typedef boost::vector_property_map< boost::two_bit_color_type, + IndexMap > + type; + static type build(const Graph& /* g */, const IndexMap& index) + { + return boost::make_vector_property_map< boost::two_bit_color_type >( + index); + } }; - template <class Graph, class IndexMap> - struct default_color_map_generator { - typedef boost::is_base_and_derived< - boost::vertex_list_graph_tag, - typename boost::graph_traits<Graph>::traversal_category> - known_num_vertices; - typedef default_color_map_generator_helper<Graph, IndexMap, known_num_vertices::value> helper; - typedef typename helper::type type; - static type build(const Graph& g, const IndexMap& index) { - return helper::build(g, index); - } + template < class Graph, class IndexMap > struct default_color_map_generator + { + typedef boost::is_base_and_derived< boost::vertex_list_graph_tag, + typename boost::graph_traits< Graph >::traversal_category > + known_num_vertices; + typedef default_color_map_generator_helper< Graph, IndexMap, + known_num_vertices::value > + helper; + typedef typename helper::type type; + static type build(const Graph& g, const IndexMap& index) + { + return helper::build(g, index); + } }; - } - - // Call breadth first search with default color map. - template <class Graph, class SourceInputIter, class DijkstraVisitor, - class PredecessorMap, class DistanceMap, - class WeightMap, class IndexMap, class Compare, class Combine, - class DistZero> - inline void - dijkstra_shortest_paths_no_init - (const Graph& g, - SourceInputIter s_begin, SourceInputIter s_end, - PredecessorMap predecessor, DistanceMap distance, WeightMap weight, - IndexMap index_map, - Compare compare, Combine combine, DistZero zero, - DijkstraVisitor vis) - { - typedef - detail::default_color_map_generator<Graph, IndexMap> - ColorMapHelper; +} + +// Call breadth first search with default color map. +template < class Graph, class SourceInputIter, class DijkstraVisitor, + class PredecessorMap, class DistanceMap, class WeightMap, class IndexMap, + class Compare, class Combine, class DistZero > +inline void dijkstra_shortest_paths_no_init(const Graph& g, + SourceInputIter s_begin, SourceInputIter s_end, PredecessorMap predecessor, + DistanceMap distance, WeightMap weight, IndexMap index_map, Compare compare, + Combine combine, DistZero zero, DijkstraVisitor vis) +{ + typedef detail::default_color_map_generator< Graph, IndexMap > + ColorMapHelper; typedef typename ColorMapHelper::type ColorMap; - ColorMap color = - ColorMapHelper::build(g, index_map); - dijkstra_shortest_paths_no_init( g, s_begin, s_end, predecessor, distance, weight, - index_map, compare, combine, zero, vis, - color); - } - - // Call breadth first search with default color map. - template <class Graph, class DijkstraVisitor, - class PredecessorMap, class DistanceMap, - class WeightMap, class IndexMap, class Compare, class Combine, - class DistZero> - inline void - dijkstra_shortest_paths_no_init - (const Graph& g, - typename graph_traits<Graph>::vertex_descriptor s, - PredecessorMap predecessor, DistanceMap distance, WeightMap weight, - IndexMap index_map, - Compare compare, Combine combine, DistZero zero, - DijkstraVisitor vis) - { + ColorMap color = ColorMapHelper::build(g, index_map); + dijkstra_shortest_paths_no_init(g, s_begin, s_end, predecessor, distance, + weight, index_map, compare, combine, zero, vis, color); +} + +// Call breadth first search with default color map. +template < class Graph, class DijkstraVisitor, class PredecessorMap, + class DistanceMap, class WeightMap, class IndexMap, class Compare, + class Combine, class DistZero > +inline void dijkstra_shortest_paths_no_init(const Graph& g, + typename graph_traits< Graph >::vertex_descriptor s, + PredecessorMap predecessor, DistanceMap distance, WeightMap weight, + IndexMap index_map, Compare compare, Combine combine, DistZero zero, + DijkstraVisitor vis) +{ dijkstra_shortest_paths_no_init(g, &s, &s + 1, predecessor, distance, - weight, index_map, compare, combine, zero, - vis); - } - - // Call breadth first search - template <class Graph, class SourceInputIter, class DijkstraVisitor, - class PredecessorMap, class DistanceMap, - class WeightMap, class IndexMap, class Compare, class Combine, - class DistZero, class ColorMap> - inline void - dijkstra_shortest_paths_no_init - (const Graph& g, - SourceInputIter s_begin, SourceInputIter s_end, - PredecessorMap predecessor, DistanceMap distance, WeightMap weight, - IndexMap index_map, - Compare compare, Combine combine, DistZero zero, - DijkstraVisitor vis, ColorMap color) - { - typedef indirect_cmp<DistanceMap, Compare> IndirectCmp; + weight, index_map, compare, combine, zero, vis); +} + +// Call breadth first search +template < class Graph, class SourceInputIter, class DijkstraVisitor, + class PredecessorMap, class DistanceMap, class WeightMap, class IndexMap, + class Compare, class Combine, class DistZero, class ColorMap > +inline void dijkstra_shortest_paths_no_init(const Graph& g, + SourceInputIter s_begin, SourceInputIter s_end, PredecessorMap predecessor, + DistanceMap distance, WeightMap weight, IndexMap index_map, Compare compare, + Combine combine, DistZero zero, DijkstraVisitor vis, ColorMap color) +{ + typedef indirect_cmp< DistanceMap, Compare > IndirectCmp; IndirectCmp icmp(distance, compare); - typedef typename graph_traits<Graph>::vertex_descriptor Vertex; - -#ifdef BOOST_GRAPH_DIJKSTRA_TESTING - if (!dijkstra_relaxed_heap) { - typedef mutable_queue<Vertex, std::vector<Vertex>, IndirectCmp, IndexMap> - MutableQueue; + typedef typename graph_traits< Graph >::vertex_descriptor Vertex; - MutableQueue Q(num_vertices(g), icmp, index_map); - detail::dijkstra_bfs_visitor<DijkstraVisitor, MutableQueue, WeightMap, - PredecessorMap, DistanceMap, Combine, Compare> - bfs_vis(vis, Q, weight, predecessor, distance, combine, compare, zero); - - breadth_first_visit(g, s_begin, s_end, Q, bfs_vis, color); - return; - } -#endif // BOOST_GRAPH_DIJKSTRA_TESTING - -#ifdef BOOST_GRAPH_DIJKSTRA_USE_RELAXED_HEAP - typedef relaxed_heap<Vertex, IndirectCmp, IndexMap> MutableQueue; - MutableQueue Q(num_vertices(g), icmp, index_map); -#else // Now the default: use a d-ary heap - boost::scoped_array<std::size_t> index_in_heap_map_holder; - typedef - detail::vertex_property_map_generator<Graph, IndexMap, std::size_t> + // Now the default: use a d-ary heap + boost::scoped_array< std::size_t > index_in_heap_map_holder; + typedef detail::vertex_property_map_generator< Graph, IndexMap, + std::size_t > IndexInHeapMapHelper; - typedef typename IndexInHeapMapHelper::type IndexInHeapMap; - IndexInHeapMap index_in_heap = - IndexInHeapMapHelper::build(g, index_map, index_in_heap_map_holder); - typedef d_ary_heap_indirect<Vertex, 4, IndexInHeapMap, DistanceMap, Compare> + typedef typename IndexInHeapMapHelper::type IndexInHeapMap; + IndexInHeapMap index_in_heap + = IndexInHeapMapHelper::build(g, index_map, index_in_heap_map_holder); + typedef d_ary_heap_indirect< Vertex, 4, IndexInHeapMap, DistanceMap, + Compare > MutableQueue; - MutableQueue Q(distance, index_in_heap, compare); -#endif // Relaxed heap + MutableQueue Q(distance, index_in_heap, compare); - detail::dijkstra_bfs_visitor<DijkstraVisitor, MutableQueue, WeightMap, - PredecessorMap, DistanceMap, Combine, Compare> + detail::dijkstra_bfs_visitor< DijkstraVisitor, MutableQueue, WeightMap, + PredecessorMap, DistanceMap, Combine, Compare > bfs_vis(vis, Q, weight, predecessor, distance, combine, compare, zero); breadth_first_visit(g, s_begin, s_end, Q, bfs_vis, color); - } - - // Call breadth first search - template <class Graph, class DijkstraVisitor, - class PredecessorMap, class DistanceMap, - class WeightMap, class IndexMap, class Compare, class Combine, - class DistZero, class ColorMap> - inline void - dijkstra_shortest_paths_no_init - (const Graph& g, - typename graph_traits<Graph>::vertex_descriptor s, - PredecessorMap predecessor, DistanceMap distance, WeightMap weight, - IndexMap index_map, - Compare compare, Combine combine, DistZero zero, - DijkstraVisitor vis, ColorMap color) - { +} + +// Call breadth first search +template < class Graph, class DijkstraVisitor, class PredecessorMap, + class DistanceMap, class WeightMap, class IndexMap, class Compare, + class Combine, class DistZero, class ColorMap > +inline void dijkstra_shortest_paths_no_init(const Graph& g, + typename graph_traits< Graph >::vertex_descriptor s, + PredecessorMap predecessor, DistanceMap distance, WeightMap weight, + IndexMap index_map, Compare compare, Combine combine, DistZero zero, + DijkstraVisitor vis, ColorMap color) +{ dijkstra_shortest_paths_no_init(g, &s, &s + 1, predecessor, distance, - weight, index_map, compare, combine, - zero, vis, color); - } - - // Initialize distances and call breadth first search with default color map - template <class VertexListGraph, class SourceInputIter, class DijkstraVisitor, - class PredecessorMap, class DistanceMap, - class WeightMap, class IndexMap, class Compare, class Combine, - class DistInf, class DistZero, typename T, typename Tag, - typename Base> - inline void - dijkstra_shortest_paths - (const VertexListGraph& g, - SourceInputIter s_begin, SourceInputIter s_end, - PredecessorMap predecessor, DistanceMap distance, WeightMap weight, - IndexMap index_map, - Compare compare, Combine combine, DistInf inf, DistZero zero, - DijkstraVisitor vis, - const bgl_named_params<T, Tag, Base>& - BOOST_GRAPH_ENABLE_IF_MODELS_PARM(VertexListGraph,vertex_list_graph_tag)) - { - boost::two_bit_color_map<IndexMap> color(num_vertices(g), index_map); + weight, index_map, compare, combine, zero, vis, color); +} + +// Initialize distances and call breadth first search with default color map +template < class VertexListGraph, class SourceInputIter, class DijkstraVisitor, + class PredecessorMap, class DistanceMap, class WeightMap, class IndexMap, + class Compare, class Combine, class DistInf, class DistZero, typename T, + typename Tag, typename Base > +inline void dijkstra_shortest_paths(const VertexListGraph& g, + SourceInputIter s_begin, SourceInputIter s_end, PredecessorMap predecessor, + DistanceMap distance, WeightMap weight, IndexMap index_map, Compare compare, + Combine combine, DistInf inf, DistZero zero, DijkstraVisitor vis, + const bgl_named_params< T, Tag, Base >& BOOST_GRAPH_ENABLE_IF_MODELS_PARM( + VertexListGraph, vertex_list_graph_tag)) +{ + boost::two_bit_color_map< IndexMap > color(num_vertices(g), index_map); dijkstra_shortest_paths(g, s_begin, s_end, predecessor, distance, weight, - index_map, compare, combine, inf, zero, vis, - color); - } - - // Initialize distances and call breadth first search with default color map - template <class VertexListGraph, class DijkstraVisitor, - class PredecessorMap, class DistanceMap, - class WeightMap, class IndexMap, class Compare, class Combine, - class DistInf, class DistZero, typename T, typename Tag, - typename Base> - inline void - dijkstra_shortest_paths - (const VertexListGraph& g, - typename graph_traits<VertexListGraph>::vertex_descriptor s, - PredecessorMap predecessor, DistanceMap distance, WeightMap weight, - IndexMap index_map, - Compare compare, Combine combine, DistInf inf, DistZero zero, - DijkstraVisitor vis, - const bgl_named_params<T, Tag, Base>& - BOOST_GRAPH_ENABLE_IF_MODELS_PARM(VertexListGraph,vertex_list_graph_tag)) - { + index_map, compare, combine, inf, zero, vis, color); +} + +// Initialize distances and call breadth first search with default color map +template < class VertexListGraph, class DijkstraVisitor, class PredecessorMap, + class DistanceMap, class WeightMap, class IndexMap, class Compare, + class Combine, class DistInf, class DistZero, typename T, typename Tag, + typename Base > +inline void dijkstra_shortest_paths(const VertexListGraph& g, + typename graph_traits< VertexListGraph >::vertex_descriptor s, + PredecessorMap predecessor, DistanceMap distance, WeightMap weight, + IndexMap index_map, Compare compare, Combine combine, DistInf inf, + DistZero zero, DijkstraVisitor vis, + const bgl_named_params< T, Tag, Base >& BOOST_GRAPH_ENABLE_IF_MODELS_PARM( + VertexListGraph, vertex_list_graph_tag)) +{ dijkstra_shortest_paths(g, &s, &s + 1, predecessor, distance, weight, - index_map, compare, combine, inf, zero, vis); - } - - // Initialize distances and call breadth first search - template <class VertexListGraph, class SourceInputIter, class DijkstraVisitor, - class PredecessorMap, class DistanceMap, - class WeightMap, class IndexMap, class Compare, class Combine, - class DistInf, class DistZero, class ColorMap> - inline void - dijkstra_shortest_paths - (const VertexListGraph& g, - SourceInputIter s_begin, SourceInputIter s_end, - PredecessorMap predecessor, DistanceMap distance, WeightMap weight, - IndexMap index_map, - Compare compare, Combine combine, DistInf inf, DistZero zero, - DijkstraVisitor vis, ColorMap color) - { - typedef typename property_traits<ColorMap>::value_type ColorValue; - typedef color_traits<ColorValue> Color; - typename graph_traits<VertexListGraph>::vertex_iterator ui, ui_end; - for (boost::tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui) { - vis.initialize_vertex(*ui, g); - put(distance, *ui, inf); - put(predecessor, *ui, *ui); - put(color, *ui, Color::white()); + index_map, compare, combine, inf, zero, vis); +} + +// Initialize distances and call breadth first search +template < class VertexListGraph, class SourceInputIter, class DijkstraVisitor, + class PredecessorMap, class DistanceMap, class WeightMap, class IndexMap, + class Compare, class Combine, class DistInf, class DistZero, + class ColorMap > +inline void dijkstra_shortest_paths(const VertexListGraph& g, + SourceInputIter s_begin, SourceInputIter s_end, PredecessorMap predecessor, + DistanceMap distance, WeightMap weight, IndexMap index_map, Compare compare, + Combine combine, DistInf inf, DistZero zero, DijkstraVisitor vis, + ColorMap color) +{ + typedef typename property_traits< ColorMap >::value_type ColorValue; + typedef color_traits< ColorValue > Color; + typename graph_traits< VertexListGraph >::vertex_iterator ui, ui_end; + for (boost::tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui) + { + vis.initialize_vertex(*ui, g); + put(distance, *ui, inf); + put(predecessor, *ui, *ui); + put(color, *ui, Color::white()); } - for (SourceInputIter it = s_begin; it != s_end; ++it) { - put(distance, *it, zero); + for (SourceInputIter it = s_begin; it != s_end; ++it) + { + put(distance, *it, zero); } dijkstra_shortest_paths_no_init(g, s_begin, s_end, predecessor, distance, - weight, index_map, compare, combine, zero, vis, - color); - } - - // Initialize distances and call breadth first search - template <class VertexListGraph, class DijkstraVisitor, - class PredecessorMap, class DistanceMap, - class WeightMap, class IndexMap, class Compare, class Combine, - class DistInf, class DistZero, class ColorMap> - inline void - dijkstra_shortest_paths - (const VertexListGraph& g, - typename graph_traits<VertexListGraph>::vertex_descriptor s, - PredecessorMap predecessor, DistanceMap distance, WeightMap weight, - IndexMap index_map, - Compare compare, Combine combine, DistInf inf, DistZero zero, - DijkstraVisitor vis, ColorMap color) - { + weight, index_map, compare, combine, zero, vis, color); +} + +// Initialize distances and call breadth first search +template < class VertexListGraph, class DijkstraVisitor, class PredecessorMap, + class DistanceMap, class WeightMap, class IndexMap, class Compare, + class Combine, class DistInf, class DistZero, class ColorMap > +inline void dijkstra_shortest_paths(const VertexListGraph& g, + typename graph_traits< VertexListGraph >::vertex_descriptor s, + PredecessorMap predecessor, DistanceMap distance, WeightMap weight, + IndexMap index_map, Compare compare, Combine combine, DistInf inf, + DistZero zero, DijkstraVisitor vis, ColorMap color) +{ dijkstra_shortest_paths(g, &s, &s + 1, predecessor, distance, weight, - index_map, compare, combine, inf, zero, - vis, color); - } - - // Initialize distances and call breadth first search - template <class VertexListGraph, class SourceInputIter, - class DijkstraVisitor, - class PredecessorMap, class DistanceMap, - class WeightMap, class IndexMap, class Compare, class Combine, - class DistInf, class DistZero> - inline void - dijkstra_shortest_paths - (const VertexListGraph& g, - SourceInputIter s_begin, SourceInputIter s_end, - PredecessorMap predecessor, DistanceMap distance, WeightMap weight, - IndexMap index_map, - Compare compare, Combine combine, DistInf inf, DistZero zero, - DijkstraVisitor vis) - { - dijkstra_shortest_paths(g, s_begin, s_end, predecessor, distance, - weight, index_map, - compare, combine, inf, zero, vis, - no_named_parameters()); - } - - // Initialize distances and call breadth first search - template <class VertexListGraph, class DijkstraVisitor, - class PredecessorMap, class DistanceMap, - class WeightMap, class IndexMap, class Compare, class Combine, - class DistInf, class DistZero> - inline void - dijkstra_shortest_paths - (const VertexListGraph& g, - typename graph_traits<VertexListGraph>::vertex_descriptor s, - PredecessorMap predecessor, DistanceMap distance, WeightMap weight, - IndexMap index_map, - Compare compare, Combine combine, DistInf inf, DistZero zero, - DijkstraVisitor vis) - { - dijkstra_shortest_paths(g, &s, &s + 1, predecessor, distance, - weight, index_map, - compare, combine, inf, zero, vis); - } - - namespace detail { + index_map, compare, combine, inf, zero, vis, color); +} + +// Initialize distances and call breadth first search +template < class VertexListGraph, class SourceInputIter, class DijkstraVisitor, + class PredecessorMap, class DistanceMap, class WeightMap, class IndexMap, + class Compare, class Combine, class DistInf, class DistZero > +inline void dijkstra_shortest_paths(const VertexListGraph& g, + SourceInputIter s_begin, SourceInputIter s_end, PredecessorMap predecessor, + DistanceMap distance, WeightMap weight, IndexMap index_map, Compare compare, + Combine combine, DistInf inf, DistZero zero, DijkstraVisitor vis) +{ + dijkstra_shortest_paths(g, s_begin, s_end, predecessor, distance, weight, + index_map, compare, combine, inf, zero, vis, no_named_parameters()); +} + +// Initialize distances and call breadth first search +template < class VertexListGraph, class DijkstraVisitor, class PredecessorMap, + class DistanceMap, class WeightMap, class IndexMap, class Compare, + class Combine, class DistInf, class DistZero > +inline void dijkstra_shortest_paths(const VertexListGraph& g, + typename graph_traits< VertexListGraph >::vertex_descriptor s, + PredecessorMap predecessor, DistanceMap distance, WeightMap weight, + IndexMap index_map, Compare compare, Combine combine, DistInf inf, + DistZero zero, DijkstraVisitor vis) +{ + dijkstra_shortest_paths(g, &s, &s + 1, predecessor, distance, weight, + index_map, compare, combine, inf, zero, vis); +} + +namespace detail +{ // Handle defaults for PredecessorMap and // Distance Compare, Combine, Inf and Zero - template <class VertexListGraph, class DistanceMap, class WeightMap, - class IndexMap, class Params> - inline void - dijkstra_dispatch2 - (const VertexListGraph& g, - typename graph_traits<VertexListGraph>::vertex_descriptor s, - DistanceMap distance, WeightMap weight, IndexMap index_map, - const Params& params) + template < class VertexListGraph, class DistanceMap, class WeightMap, + class IndexMap, class Params > + inline void dijkstra_dispatch2(const VertexListGraph& g, + typename graph_traits< VertexListGraph >::vertex_descriptor s, + DistanceMap distance, WeightMap weight, IndexMap index_map, + const Params& params) { - // Default for predecessor map - dummy_property_map p_map; - - typedef typename property_traits<DistanceMap>::value_type D; - D inf = choose_param(get_param(params, distance_inf_t()), - (std::numeric_limits<D>::max)()); - - dijkstra_shortest_paths - (g, s, - choose_param(get_param(params, vertex_predecessor), p_map), - distance, weight, index_map, - choose_param(get_param(params, distance_compare_t()), - std::less<D>()), - choose_param(get_param(params, distance_combine_t()), - closed_plus<D>(inf)), - inf, - choose_param(get_param(params, distance_zero_t()), - D()), - choose_param(get_param(params, graph_visitor), - make_dijkstra_visitor(null_visitor())), - params); + // Default for predecessor map + dummy_property_map p_map; + + typedef typename property_traits< DistanceMap >::value_type D; + D inf = choose_param(get_param(params, distance_inf_t()), + (std::numeric_limits< D >::max)()); + + dijkstra_shortest_paths(g, s, + choose_param(get_param(params, vertex_predecessor), p_map), + distance, weight, index_map, + choose_param( + get_param(params, distance_compare_t()), std::less< D >()), + choose_param( + get_param(params, distance_combine_t()), std::plus< D >()), + inf, choose_param(get_param(params, distance_zero_t()), D()), + choose_param(get_param(params, graph_visitor), + make_dijkstra_visitor(null_visitor())), + params); } - template <class VertexListGraph, class DistanceMap, class WeightMap, - class IndexMap, class Params> - inline void - dijkstra_dispatch1 - (const VertexListGraph& g, - typename graph_traits<VertexListGraph>::vertex_descriptor s, - DistanceMap distance, WeightMap weight, IndexMap index_map, - const Params& params) + template < class VertexListGraph, class DistanceMap, class WeightMap, + class IndexMap, class Params > + inline void dijkstra_dispatch1(const VertexListGraph& g, + typename graph_traits< VertexListGraph >::vertex_descriptor s, + DistanceMap distance, WeightMap weight, IndexMap index_map, + const Params& params) { - // Default for distance map - typedef typename property_traits<WeightMap>::value_type D; - typename std::vector<D>::size_type - n = is_default_param(distance) ? num_vertices(g) : 1; - std::vector<D> distance_map(n); - - detail::dijkstra_dispatch2 - (g, s, choose_param(distance, make_iterator_property_map - (distance_map.begin(), index_map, - distance_map[0])), - weight, index_map, params); + // Default for distance map + typedef typename property_traits< WeightMap >::value_type D; + typename std::vector< D >::size_type n + = is_default_param(distance) ? num_vertices(g) : 1; + std::vector< D > distance_map(n); + + detail::dijkstra_dispatch2(g, s, + choose_param(distance, + make_iterator_property_map( + distance_map.begin(), index_map, distance_map[0])), + weight, index_map, params); } - } // namespace detail - - // Named Parameter Variant - template <class VertexListGraph, class Param, class Tag, class Rest> - inline void - dijkstra_shortest_paths - (const VertexListGraph& g, - typename graph_traits<VertexListGraph>::vertex_descriptor s, - const bgl_named_params<Param,Tag,Rest>& params) - { +} // namespace detail + +// Named Parameter Variant +template < class VertexListGraph, class Param, class Tag, class Rest > +inline void dijkstra_shortest_paths(const VertexListGraph& g, + typename graph_traits< VertexListGraph >::vertex_descriptor s, + const bgl_named_params< Param, Tag, Rest >& params) +{ // Default for edge weight and vertex index map is to ask for them // from the graph. Default for the visitor is null_visitor. - detail::dijkstra_dispatch1 - (g, s, - get_param(params, vertex_distance), - choose_const_pmap(get_param(params, edge_weight), g, edge_weight), - choose_const_pmap(get_param(params, vertex_index), g, vertex_index), - params); - } + detail::dijkstra_dispatch1(g, s, get_param(params, vertex_distance), + choose_const_pmap(get_param(params, edge_weight), g, edge_weight), + choose_const_pmap(get_param(params, vertex_index), g, vertex_index), + params); +} } // namespace boost -#ifdef BOOST_GRAPH_USE_MPI -# error #include <boost/graph/distributed/dijkstra_shortest_paths.hpp> -#endif +#include BOOST_GRAPH_MPI_INCLUDE(<boost/graph/distributed/dijkstra_shortest_paths.hpp>) #endif // BOOST_GRAPH_DIJKSTRA_HPP diff --git a/contrib/restricted/boost/graph/include/boost/graph/dll_import_export.hpp b/contrib/restricted/boost/graph/include/boost/graph/dll_import_export.hpp index d03fcd3f2e..7f042373bd 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/dll_import_export.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/dll_import_export.hpp @@ -14,15 +14,15 @@ #include <boost/config.hpp> #if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_GRAPH_DYN_LINK) -# ifdef BOOST_GRAPH_SOURCE -# define BOOST_GRAPH_DECL BOOST_SYMBOL_EXPORT -# else -# define BOOST_GRAPH_DECL BOOST_SYMBOL_IMPORT -# endif // BOOST_GRAPH_SOURCE -#endif // DYN_LINK +#ifdef BOOST_GRAPH_SOURCE +#define BOOST_GRAPH_DECL BOOST_SYMBOL_EXPORT +#else +#define BOOST_GRAPH_DECL BOOST_SYMBOL_IMPORT +#endif // BOOST_GRAPH_SOURCE +#endif // DYN_LINK #ifndef BOOST_GRAPH_DECL -# define BOOST_GRAPH_DECL +#define BOOST_GRAPH_DECL #endif #endif // BOOST_GRAPH_DLL_IMPORT_EXPORT_HPP diff --git a/contrib/restricted/boost/graph/include/boost/graph/exception.hpp b/contrib/restricted/boost/graph/include/boost/graph/exception.hpp index 382d671928..81323a3616 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/exception.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/exception.hpp @@ -13,42 +13,43 @@ #include <stdexcept> #include <string> -namespace boost { - - struct bad_graph : public std::invalid_argument { - bad_graph(const std::string& what_arg) - : std::invalid_argument(what_arg) { } - }; - - struct not_a_dag : public bad_graph { - not_a_dag() - : bad_graph("The graph must be a DAG.") - { } - }; - - struct negative_edge : public bad_graph { - negative_edge() - : bad_graph("The graph may not contain an edge with negative weight.") - { } - }; - - struct negative_cycle : public bad_graph { - negative_cycle() - : bad_graph("The graph may not contain negative cycles.") - { } - }; - - struct not_connected : public bad_graph { - not_connected() - : bad_graph("The graph must be connected.") - { } - }; - - struct not_complete : public bad_graph { - not_complete() - : bad_graph("The graph must be complete.") - { } - }; +namespace boost +{ + +struct BOOST_SYMBOL_VISIBLE bad_graph : public std::invalid_argument +{ + bad_graph(const std::string& what_arg) : std::invalid_argument(what_arg) {} +}; + +struct BOOST_SYMBOL_VISIBLE not_a_dag : public bad_graph +{ + not_a_dag() : bad_graph("The graph must be a DAG.") {} +}; + +struct BOOST_SYMBOL_VISIBLE negative_edge : public bad_graph +{ + negative_edge() + : bad_graph("The graph may not contain an edge with negative weight.") + { + } +}; + +struct BOOST_SYMBOL_VISIBLE negative_cycle : public bad_graph +{ + negative_cycle() : bad_graph("The graph may not contain negative cycles.") + { + } +}; + +struct BOOST_SYMBOL_VISIBLE not_connected : public bad_graph +{ + not_connected() : bad_graph("The graph must be connected.") {} +}; + +struct BOOST_SYMBOL_VISIBLE not_complete : public bad_graph +{ + not_complete() : bad_graph("The graph must be complete.") {} +}; } // namespace boost diff --git a/contrib/restricted/boost/graph/include/boost/graph/filtered_graph.hpp b/contrib/restricted/boost/graph/include/boost/graph/filtered_graph.hpp index 5426eac6f6..05d65b8068 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/filtered_graph.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/filtered_graph.hpp @@ -16,545 +16,576 @@ #include <boost/graph/detail/set_adaptor.hpp> #include <boost/iterator/filter_iterator.hpp> -namespace boost { - - //========================================================================= - // Some predicate classes. - - struct keep_all { - template <typename T> - bool operator()(const T&) const { return true; } - }; - - // Keep residual edges (used in maximum-flow algorithms). - template <typename ResidualCapacityEdgeMap> - struct is_residual_edge { - is_residual_edge() { } - is_residual_edge(ResidualCapacityEdgeMap rcap) : m_rcap(rcap) { } - template <typename Edge> - bool operator()(const Edge& e) const { - return 0 < get(m_rcap, e); +namespace boost +{ + +//========================================================================= +// Some predicate classes. + +struct keep_all +{ + template < typename T > bool operator()(const T&) const { return true; } +}; + +// Keep residual edges (used in maximum-flow algorithms). +template < typename ResidualCapacityEdgeMap > struct is_residual_edge +{ + is_residual_edge() {} + is_residual_edge(ResidualCapacityEdgeMap rcap) : m_rcap(rcap) {} + template < typename Edge > bool operator()(const Edge& e) const + { + return 0 < get(m_rcap, e); } ResidualCapacityEdgeMap m_rcap; - }; +}; - template <typename Set> - struct is_in_subset { - is_in_subset() : m_s(0) { } - is_in_subset(const Set& s) : m_s(&s) { } +template < typename Set > struct is_in_subset +{ + is_in_subset() : m_s(0) {} + is_in_subset(const Set& s) : m_s(&s) {} - template <typename Elt> - bool operator()(const Elt& x) const { - return set_contains(*m_s, x); + template < typename Elt > bool operator()(const Elt& x) const + { + return set_contains(*m_s, x); } const Set* m_s; - }; +}; - template <typename Set> - struct is_not_in_subset { - is_not_in_subset() : m_s(0) { } - is_not_in_subset(const Set& s) : m_s(&s) { } +template < typename Set > struct is_not_in_subset +{ + is_not_in_subset() : m_s(0) {} + is_not_in_subset(const Set& s) : m_s(&s) {} - template <typename Elt> - bool operator()(const Elt& x) const { - return !set_contains(*m_s, x); + template < typename Elt > bool operator()(const Elt& x) const + { + return !set_contains(*m_s, x); } const Set* m_s; - }; - - namespace detail { - - template <typename EdgePredicate, typename VertexPredicate, typename Graph> - struct out_edge_predicate { - out_edge_predicate() { } - out_edge_predicate(EdgePredicate ep, VertexPredicate vp, - const Graph& g) - : m_edge_pred(ep), m_vertex_pred(vp), m_g(&g) { } - - template <typename Edge> - bool operator()(const Edge& e) const { - return m_edge_pred(e) && m_vertex_pred(target(e, *m_g)); - } - EdgePredicate m_edge_pred; - VertexPredicate m_vertex_pred; - const Graph* m_g; - }; +}; - template <typename EdgePredicate, typename VertexPredicate, typename Graph> - struct in_edge_predicate { - in_edge_predicate() { } - in_edge_predicate(EdgePredicate ep, VertexPredicate vp, - const Graph& g) - : m_edge_pred(ep), m_vertex_pred(vp), m_g(&g) { } - - template <typename Edge> - bool operator()(const Edge& e) const { - return m_edge_pred(e) && m_vertex_pred(source(e, *m_g)); - } - EdgePredicate m_edge_pred; - VertexPredicate m_vertex_pred; - const Graph* m_g; - }; +namespace detail +{ - template <typename EdgePredicate, typename VertexPredicate, typename Graph> - struct edge_predicate { - edge_predicate() { } - edge_predicate(EdgePredicate ep, VertexPredicate vp, - const Graph& g) - : m_edge_pred(ep), m_vertex_pred(vp), m_g(&g) { } - - template <typename Edge> - bool operator()(const Edge& e) const { - return m_edge_pred(e) - && m_vertex_pred(source(e, *m_g)) && m_vertex_pred(target(e, *m_g)); - } - EdgePredicate m_edge_pred; - VertexPredicate m_vertex_pred; - const Graph* m_g; + template < typename EdgePredicate, typename VertexPredicate, + typename Graph > + struct out_edge_predicate + { + out_edge_predicate() {} + out_edge_predicate(EdgePredicate ep, VertexPredicate vp, const Graph& g) + : m_edge_pred(ep), m_vertex_pred(vp), m_g(&g) + { + } + + template < typename Edge > bool operator()(const Edge& e) const + { + return m_edge_pred(e) && m_vertex_pred(target(e, *m_g)); + } + EdgePredicate m_edge_pred; + VertexPredicate m_vertex_pred; + const Graph* m_g; }; - } // namespace detail - - - //=========================================================================== - // Filtered Graph + template < typename EdgePredicate, typename VertexPredicate, + typename Graph > + struct in_edge_predicate + { + in_edge_predicate() {} + in_edge_predicate(EdgePredicate ep, VertexPredicate vp, const Graph& g) + : m_edge_pred(ep), m_vertex_pred(vp), m_g(&g) + { + } + + template < typename Edge > bool operator()(const Edge& e) const + { + return m_edge_pred(e) && m_vertex_pred(source(e, *m_g)); + } + EdgePredicate m_edge_pred; + VertexPredicate m_vertex_pred; + const Graph* m_g; + }; - struct filtered_graph_tag { }; + template < typename EdgePredicate, typename VertexPredicate, + typename Graph > + struct edge_predicate + { + edge_predicate() {} + edge_predicate(EdgePredicate ep, VertexPredicate vp, const Graph& g) + : m_edge_pred(ep), m_vertex_pred(vp), m_g(&g) + { + } + + template < typename Edge > bool operator()(const Edge& e) const + { + return m_edge_pred(e) && m_vertex_pred(source(e, *m_g)) + && m_vertex_pred(target(e, *m_g)); + } + EdgePredicate m_edge_pred; + VertexPredicate m_vertex_pred; + const Graph* m_g; + }; - // This base class is a stupid hack to change overload resolution - // rules for the source and target functions so that they are a - // worse match than the source and target functions defined for - // pairs in graph_traits.hpp. I feel dirty. -JGS - template <class G> - struct filtered_graph_base { - typedef graph_traits<G> Traits; - typedef typename Traits::vertex_descriptor vertex_descriptor; - typedef typename Traits::edge_descriptor edge_descriptor; - filtered_graph_base(const G& g) : m_g(g) { } - //protected: +} // namespace detail + +//=========================================================================== +// Filtered Graph + +struct filtered_graph_tag +{ +}; + +// This base class is a stupid hack to change overload resolution +// rules for the source and target functions so that they are a +// worse match than the source and target functions defined for +// pairs in graph_traits.hpp. I feel dirty. -JGS +template < class G > struct filtered_graph_base +{ + typedef graph_traits< G > Traits; + typedef typename Traits::vertex_descriptor vertex_descriptor; + typedef typename Traits::edge_descriptor edge_descriptor; + filtered_graph_base(const G& g) : m_g(g) {} + // protected: const G& m_g; - }; - - template <typename Graph, - typename EdgePredicate, - typename VertexPredicate = keep_all> - class filtered_graph : public filtered_graph_base<Graph> { - typedef filtered_graph_base<Graph> Base; - typedef graph_traits<Graph> Traits; +}; + +template < typename Graph, typename EdgePredicate, + typename VertexPredicate = keep_all > +class filtered_graph : public filtered_graph_base< Graph > +{ + typedef filtered_graph_base< Graph > Base; + typedef graph_traits< Graph > Traits; typedef filtered_graph self; - public: + +public: typedef Graph graph_type; - typedef detail::out_edge_predicate<EdgePredicate, - VertexPredicate, self> OutEdgePred; - typedef detail::in_edge_predicate<EdgePredicate, - VertexPredicate, self> InEdgePred; - typedef detail::edge_predicate<EdgePredicate, - VertexPredicate, self> EdgePred; + typedef detail::out_edge_predicate< EdgePredicate, VertexPredicate, self > + OutEdgePred; + typedef detail::in_edge_predicate< EdgePredicate, VertexPredicate, self > + InEdgePred; + typedef detail::edge_predicate< EdgePredicate, VertexPredicate, self > + EdgePred; // Constructors - filtered_graph(const Graph& g, EdgePredicate ep) - : Base(g), m_edge_pred(ep) { } + filtered_graph(const Graph& g, EdgePredicate ep) : Base(g), m_edge_pred(ep) + { + } filtered_graph(const Graph& g, EdgePredicate ep, VertexPredicate vp) - : Base(g), m_edge_pred(ep), m_vertex_pred(vp) { } + : Base(g), m_edge_pred(ep), m_vertex_pred(vp) + { + } // Graph requirements - typedef typename Traits::vertex_descriptor vertex_descriptor; - typedef typename Traits::edge_descriptor edge_descriptor; - typedef typename Traits::directed_category directed_category; - typedef typename Traits::edge_parallel_category edge_parallel_category; - typedef typename Traits::traversal_category traversal_category; + typedef typename Traits::vertex_descriptor vertex_descriptor; + typedef typename Traits::edge_descriptor edge_descriptor; + typedef typename Traits::directed_category directed_category; + typedef typename Traits::edge_parallel_category edge_parallel_category; + typedef typename Traits::traversal_category traversal_category; // IncidenceGraph requirements - typedef filter_iterator< - OutEdgePred, typename Traits::out_edge_iterator - > out_edge_iterator; - - typedef typename Traits::degree_size_type degree_size_type; + typedef filter_iterator< OutEdgePred, typename Traits::out_edge_iterator > + out_edge_iterator; + + typedef typename Traits::degree_size_type degree_size_type; // AdjacencyGraph requirements - typedef typename adjacency_iterator_generator<self, - vertex_descriptor, out_edge_iterator>::type adjacency_iterator; + typedef typename adjacency_iterator_generator< self, vertex_descriptor, + out_edge_iterator >::type adjacency_iterator; // BidirectionalGraph requirements - typedef filter_iterator< - InEdgePred, typename Traits::in_edge_iterator - > in_edge_iterator; + typedef filter_iterator< InEdgePred, typename Traits::in_edge_iterator > + in_edge_iterator; // VertexListGraph requirements - typedef filter_iterator< - VertexPredicate, typename Traits::vertex_iterator - > vertex_iterator; - typedef typename Traits::vertices_size_type vertices_size_type; + typedef filter_iterator< VertexPredicate, typename Traits::vertex_iterator > + vertex_iterator; + typedef typename Traits::vertices_size_type vertices_size_type; // EdgeListGraph requirements - typedef filter_iterator< - EdgePred, typename Traits::edge_iterator - > edge_iterator; - typedef typename Traits::edges_size_type edges_size_type; + typedef filter_iterator< EdgePred, typename Traits::edge_iterator > + edge_iterator; + typedef typename Traits::edges_size_type edges_size_type; typedef filtered_graph_tag graph_tag; // Bundled properties support - template<typename Descriptor> - typename graph::detail::bundled_result<Graph, Descriptor>::type& + template < typename Descriptor > + typename graph::detail::bundled_result< Graph, Descriptor >::type& operator[](Descriptor x) - { return const_cast<Graph&>(this->m_g)[x]; } + { + return const_cast< Graph& >(this->m_g)[x]; + } - template<typename Descriptor> - typename graph::detail::bundled_result<Graph, Descriptor>::type const& + template < typename Descriptor > + typename graph::detail::bundled_result< Graph, Descriptor >::type const& operator[](Descriptor x) const - { return this->m_g[x]; } - - static vertex_descriptor null_vertex() { - return Traits::null_vertex(); + return this->m_g[x]; } - //private: + static vertex_descriptor null_vertex() { return Traits::null_vertex(); } + + // private: EdgePredicate m_edge_pred; VertexPredicate m_vertex_pred; - }; - - // Do not instantiate these unless needed - template <typename Graph, - typename EdgePredicate, - typename VertexPredicate> - struct vertex_property_type<filtered_graph<Graph, EdgePredicate, VertexPredicate> >: - vertex_property_type<Graph> {}; - - template <typename Graph, - typename EdgePredicate, - typename VertexPredicate> - struct edge_property_type<filtered_graph<Graph, EdgePredicate, VertexPredicate> >: - edge_property_type<Graph> {}; - - template <typename Graph, - typename EdgePredicate, - typename VertexPredicate> - struct graph_property_type<filtered_graph<Graph, EdgePredicate, VertexPredicate> >: - graph_property_type<Graph> {}; - - template<typename Graph, typename EdgePredicate, typename VertexPredicate> - struct vertex_bundle_type<filtered_graph<Graph, EdgePredicate, - VertexPredicate> > - : vertex_bundle_type<Graph> { }; - - template<typename Graph, typename EdgePredicate, typename VertexPredicate> - struct edge_bundle_type<filtered_graph<Graph, EdgePredicate, - VertexPredicate> > - : edge_bundle_type<Graph> { }; - - template<typename Graph, typename EdgePredicate, typename VertexPredicate> - struct graph_bundle_type<filtered_graph<Graph, EdgePredicate, - VertexPredicate> > - : graph_bundle_type<Graph> { }; - - //=========================================================================== - // Non-member functions for the Filtered Edge Graph - - // Helper functions - template <typename Graph, typename EdgePredicate> - inline filtered_graph<Graph, EdgePredicate> - make_filtered_graph(Graph& g, EdgePredicate ep) { - return filtered_graph<Graph, EdgePredicate>(g, ep); - } - template <typename Graph, typename EdgePredicate, typename VertexPredicate> - inline filtered_graph<Graph, EdgePredicate, VertexPredicate> - make_filtered_graph(Graph& g, EdgePredicate ep, VertexPredicate vp) { - return filtered_graph<Graph, EdgePredicate, VertexPredicate>(g, ep, vp); - } - - template <typename Graph, typename EdgePredicate> - inline filtered_graph<const Graph, EdgePredicate> - make_filtered_graph(const Graph& g, EdgePredicate ep) { - return filtered_graph<const Graph, EdgePredicate>(g, ep); - } - template <typename Graph, typename EdgePredicate, typename VertexPredicate> - inline filtered_graph<const Graph, EdgePredicate, VertexPredicate> - make_filtered_graph(const Graph& g, EdgePredicate ep, VertexPredicate vp) { - return filtered_graph<const Graph, EdgePredicate, VertexPredicate>(g, ep, vp); - } - - template <typename G, typename EP, typename VP> - std::pair<typename filtered_graph<G, EP, VP>::vertex_iterator, - typename filtered_graph<G, EP, VP>::vertex_iterator> - vertices(const filtered_graph<G, EP, VP>& g) - { - typedef filtered_graph<G, EP, VP> Graph; - typename graph_traits<G>::vertex_iterator f, l; +}; + +// Do not instantiate these unless needed +template < typename Graph, typename EdgePredicate, typename VertexPredicate > +struct vertex_property_type< + filtered_graph< Graph, EdgePredicate, VertexPredicate > > +: vertex_property_type< Graph > +{ +}; + +template < typename Graph, typename EdgePredicate, typename VertexPredicate > +struct edge_property_type< + filtered_graph< Graph, EdgePredicate, VertexPredicate > > +: edge_property_type< Graph > +{ +}; + +template < typename Graph, typename EdgePredicate, typename VertexPredicate > +struct graph_property_type< + filtered_graph< Graph, EdgePredicate, VertexPredicate > > +: graph_property_type< Graph > +{ +}; + +template < typename Graph, typename EdgePredicate, typename VertexPredicate > +struct vertex_bundle_type< + filtered_graph< Graph, EdgePredicate, VertexPredicate > > +: vertex_bundle_type< Graph > +{ +}; + +template < typename Graph, typename EdgePredicate, typename VertexPredicate > +struct edge_bundle_type< + filtered_graph< Graph, EdgePredicate, VertexPredicate > > +: edge_bundle_type< Graph > +{ +}; + +template < typename Graph, typename EdgePredicate, typename VertexPredicate > +struct graph_bundle_type< + filtered_graph< Graph, EdgePredicate, VertexPredicate > > +: graph_bundle_type< Graph > +{ +}; + +//=========================================================================== +// Non-member functions for the Filtered Edge Graph + +// Helper functions +template < typename Graph, typename EdgePredicate > +inline filtered_graph< Graph, EdgePredicate > make_filtered_graph( + Graph& g, EdgePredicate ep) +{ + return filtered_graph< Graph, EdgePredicate >(g, ep); +} +template < typename Graph, typename EdgePredicate, typename VertexPredicate > +inline filtered_graph< Graph, EdgePredicate, VertexPredicate > +make_filtered_graph(Graph& g, EdgePredicate ep, VertexPredicate vp) +{ + return filtered_graph< Graph, EdgePredicate, VertexPredicate >(g, ep, vp); +} + +template < typename Graph, typename EdgePredicate > +inline filtered_graph< const Graph, EdgePredicate > make_filtered_graph( + const Graph& g, EdgePredicate ep) +{ + return filtered_graph< const Graph, EdgePredicate >(g, ep); +} +template < typename Graph, typename EdgePredicate, typename VertexPredicate > +inline filtered_graph< const Graph, EdgePredicate, VertexPredicate > +make_filtered_graph(const Graph& g, EdgePredicate ep, VertexPredicate vp) +{ + return filtered_graph< const Graph, EdgePredicate, VertexPredicate >( + g, ep, vp); +} + +template < typename G, typename EP, typename VP > +std::pair< typename filtered_graph< G, EP, VP >::vertex_iterator, + typename filtered_graph< G, EP, VP >::vertex_iterator > +vertices(const filtered_graph< G, EP, VP >& g) +{ + typedef filtered_graph< G, EP, VP > Graph; + typename graph_traits< G >::vertex_iterator f, l; boost::tie(f, l) = vertices(g.m_g); typedef typename Graph::vertex_iterator iter; - return std::make_pair(iter(g.m_vertex_pred, f, l), - iter(g.m_vertex_pred, l, l)); - } - - template <typename G, typename EP, typename VP> - std::pair<typename filtered_graph<G, EP, VP>::edge_iterator, - typename filtered_graph<G, EP, VP>::edge_iterator> - edges(const filtered_graph<G, EP, VP>& g) - { - typedef filtered_graph<G, EP, VP> Graph; + return std::make_pair( + iter(g.m_vertex_pred, f, l), iter(g.m_vertex_pred, l, l)); +} + +template < typename G, typename EP, typename VP > +std::pair< typename filtered_graph< G, EP, VP >::edge_iterator, + typename filtered_graph< G, EP, VP >::edge_iterator > +edges(const filtered_graph< G, EP, VP >& g) +{ + typedef filtered_graph< G, EP, VP > Graph; typename Graph::EdgePred pred(g.m_edge_pred, g.m_vertex_pred, g); - typename graph_traits<G>::edge_iterator f, l; + typename graph_traits< G >::edge_iterator f, l; boost::tie(f, l) = edges(g.m_g); typedef typename Graph::edge_iterator iter; return std::make_pair(iter(pred, f, l), iter(pred, l, l)); - } - - // An alternative for num_vertices() and num_edges() would be to - // count the number in the filtered graph. This is problematic - // because of the interaction with the vertex indices... they would - // no longer go from 0 to num_vertices(), which would cause trouble - // for algorithms allocating property storage in an array. We could - // try to create a mapping to new recalibrated indices, but I don't - // see an efficient way to do this. - // - // However, the current solution is still unsatisfactory because - // the following semantic constraints no longer hold: - // boost::tie(vi, viend) = vertices(g); - // assert(std::distance(vi, viend) == num_vertices(g)); - - template <typename G, typename EP, typename VP> - typename filtered_graph<G, EP, VP>::vertices_size_type - num_vertices(const filtered_graph<G, EP, VP>& g) { +} + +// An alternative for num_vertices() and num_edges() would be to +// count the number in the filtered graph. This is problematic +// because of the interaction with the vertex indices... they would +// no longer go from 0 to num_vertices(), which would cause trouble +// for algorithms allocating property storage in an array. We could +// try to create a mapping to new recalibrated indices, but I don't +// see an efficient way to do this. +// +// However, the current solution is still unsatisfactory because +// the following semantic constraints no longer hold: +// boost::tie(vi, viend) = vertices(g); +// assert(std::distance(vi, viend) == num_vertices(g)); + +template < typename G, typename EP, typename VP > +typename filtered_graph< G, EP, VP >::vertices_size_type num_vertices( + const filtered_graph< G, EP, VP >& g) +{ return num_vertices(g.m_g); - } +} - template <typename G, typename EP, typename VP> - typename filtered_graph<G, EP, VP>::edges_size_type - num_edges(const filtered_graph<G, EP, VP>& g) { +template < typename G, typename EP, typename VP > +typename filtered_graph< G, EP, VP >::edges_size_type num_edges( + const filtered_graph< G, EP, VP >& g) +{ return num_edges(g.m_g); - } - - template <typename G> - typename filtered_graph_base<G>::vertex_descriptor - source(typename filtered_graph_base<G>::edge_descriptor e, - const filtered_graph_base<G>& g) - { +} + +template < typename G > +typename filtered_graph_base< G >::vertex_descriptor source( + typename filtered_graph_base< G >::edge_descriptor e, + const filtered_graph_base< G >& g) +{ return source(e, g.m_g); - } +} - template <typename G> - typename filtered_graph_base<G>::vertex_descriptor - target(typename filtered_graph_base<G>::edge_descriptor e, - const filtered_graph_base<G>& g) - { +template < typename G > +typename filtered_graph_base< G >::vertex_descriptor target( + typename filtered_graph_base< G >::edge_descriptor e, + const filtered_graph_base< G >& g) +{ return target(e, g.m_g); - } - - template <typename G, typename EP, typename VP> - std::pair<typename filtered_graph<G, EP, VP>::out_edge_iterator, - typename filtered_graph<G, EP, VP>::out_edge_iterator> - out_edges(typename filtered_graph<G, EP, VP>::vertex_descriptor u, - const filtered_graph<G, EP, VP>& g) - { - typedef filtered_graph<G, EP, VP> Graph; +} + +template < typename G, typename EP, typename VP > +std::pair< typename filtered_graph< G, EP, VP >::out_edge_iterator, + typename filtered_graph< G, EP, VP >::out_edge_iterator > +out_edges(typename filtered_graph< G, EP, VP >::vertex_descriptor u, + const filtered_graph< G, EP, VP >& g) +{ + typedef filtered_graph< G, EP, VP > Graph; typename Graph::OutEdgePred pred(g.m_edge_pred, g.m_vertex_pred, g); typedef typename Graph::out_edge_iterator iter; - typename graph_traits<G>::out_edge_iterator f, l; + typename graph_traits< G >::out_edge_iterator f, l; boost::tie(f, l) = out_edges(u, g.m_g); return std::make_pair(iter(pred, f, l), iter(pred, l, l)); - } - - template <typename G, typename EP, typename VP> - typename filtered_graph<G, EP, VP>::degree_size_type - out_degree(typename filtered_graph<G, EP, VP>::vertex_descriptor u, - const filtered_graph<G, EP, VP>& g) - { - typename filtered_graph<G, EP, VP>::degree_size_type n = 0; - typename filtered_graph<G, EP, VP>::out_edge_iterator f, l; +} + +template < typename G, typename EP, typename VP > +typename filtered_graph< G, EP, VP >::degree_size_type out_degree( + typename filtered_graph< G, EP, VP >::vertex_descriptor u, + const filtered_graph< G, EP, VP >& g) +{ + typename filtered_graph< G, EP, VP >::degree_size_type n = 0; + typename filtered_graph< G, EP, VP >::out_edge_iterator f, l; for (boost::tie(f, l) = out_edges(u, g); f != l; ++f) - ++n; + ++n; return n; - } - - template <typename G, typename EP, typename VP> - std::pair<typename filtered_graph<G, EP, VP>::adjacency_iterator, - typename filtered_graph<G, EP, VP>::adjacency_iterator> - adjacent_vertices(typename filtered_graph<G, EP, VP>::vertex_descriptor u, - const filtered_graph<G, EP, VP>& g) - { - typedef filtered_graph<G, EP, VP> Graph; +} + +template < typename G, typename EP, typename VP > +std::pair< typename filtered_graph< G, EP, VP >::adjacency_iterator, + typename filtered_graph< G, EP, VP >::adjacency_iterator > +adjacent_vertices(typename filtered_graph< G, EP, VP >::vertex_descriptor u, + const filtered_graph< G, EP, VP >& g) +{ + typedef filtered_graph< G, EP, VP > Graph; typedef typename Graph::adjacency_iterator adjacency_iterator; typename Graph::out_edge_iterator f, l; boost::tie(f, l) = out_edges(u, g); - return std::make_pair(adjacency_iterator(f, const_cast<Graph*>(&g)), - adjacency_iterator(l, const_cast<Graph*>(&g))); - } - - template <typename G, typename EP, typename VP> - std::pair<typename filtered_graph<G, EP, VP>::in_edge_iterator, - typename filtered_graph<G, EP, VP>::in_edge_iterator> - in_edges(typename filtered_graph<G, EP, VP>::vertex_descriptor u, - const filtered_graph<G, EP, VP>& g) - { - typedef filtered_graph<G, EP, VP> Graph; + return std::make_pair(adjacency_iterator(f, const_cast< Graph* >(&g)), + adjacency_iterator(l, const_cast< Graph* >(&g))); +} + +template < typename G, typename EP, typename VP > +std::pair< typename filtered_graph< G, EP, VP >::in_edge_iterator, + typename filtered_graph< G, EP, VP >::in_edge_iterator > +in_edges(typename filtered_graph< G, EP, VP >::vertex_descriptor u, + const filtered_graph< G, EP, VP >& g) +{ + typedef filtered_graph< G, EP, VP > Graph; typename Graph::InEdgePred pred(g.m_edge_pred, g.m_vertex_pred, g); typedef typename Graph::in_edge_iterator iter; - typename graph_traits<G>::in_edge_iterator f, l; + typename graph_traits< G >::in_edge_iterator f, l; boost::tie(f, l) = in_edges(u, g.m_g); return std::make_pair(iter(pred, f, l), iter(pred, l, l)); - } - - template <typename G, typename EP, typename VP> - typename filtered_graph<G, EP, VP>::degree_size_type - in_degree(typename filtered_graph<G, EP, VP>::vertex_descriptor u, - const filtered_graph<G, EP, VP>& g) - { - typename filtered_graph<G, EP, VP>::degree_size_type n = 0; - typename filtered_graph<G, EP, VP>::in_edge_iterator f, l; +} + +template < typename G, typename EP, typename VP > +typename filtered_graph< G, EP, VP >::degree_size_type in_degree( + typename filtered_graph< G, EP, VP >::vertex_descriptor u, + const filtered_graph< G, EP, VP >& g) +{ + typename filtered_graph< G, EP, VP >::degree_size_type n = 0; + typename filtered_graph< G, EP, VP >::in_edge_iterator f, l; for (boost::tie(f, l) = in_edges(u, g); f != l; ++f) - ++n; + ++n; return n; - } - - template <typename G, typename EP, typename VP> - typename enable_if<typename is_directed_graph<G>::type, - typename filtered_graph<G, EP, VP>::degree_size_type - >::type - degree(typename filtered_graph<G, EP, VP>::vertex_descriptor u, - const filtered_graph<G, EP, VP>& g) - { +} + +template < typename G, typename EP, typename VP > +typename enable_if< typename is_directed_graph< G >::type, + typename filtered_graph< G, EP, VP >::degree_size_type >::type +degree(typename filtered_graph< G, EP, VP >::vertex_descriptor u, + const filtered_graph< G, EP, VP >& g) +{ return out_degree(u, g) + in_degree(u, g); - } - - template <typename G, typename EP, typename VP> - typename disable_if<typename is_directed_graph<G>::type, - typename filtered_graph<G, EP, VP>::degree_size_type - >::type - degree(typename filtered_graph<G, EP, VP>::vertex_descriptor u, - const filtered_graph<G, EP, VP>& g) - { +} + +template < typename G, typename EP, typename VP > +typename disable_if< typename is_directed_graph< G >::type, + typename filtered_graph< G, EP, VP >::degree_size_type >::type +degree(typename filtered_graph< G, EP, VP >::vertex_descriptor u, + const filtered_graph< G, EP, VP >& g) +{ return out_degree(u, g); - } - - template <typename G, typename EP, typename VP> - std::pair<typename filtered_graph<G, EP, VP>::edge_descriptor, bool> - edge(typename filtered_graph<G, EP, VP>::vertex_descriptor u, - typename filtered_graph<G, EP, VP>::vertex_descriptor v, - const filtered_graph<G, EP, VP>& g) - { - typename graph_traits<G>::edge_descriptor e; +} + +template < typename G, typename EP, typename VP > +std::pair< typename filtered_graph< G, EP, VP >::edge_descriptor, bool > edge( + typename filtered_graph< G, EP, VP >::vertex_descriptor u, + typename filtered_graph< G, EP, VP >::vertex_descriptor v, + const filtered_graph< G, EP, VP >& g) +{ + typename graph_traits< G >::edge_descriptor e; bool exists; boost::tie(e, exists) = edge(u, v, g.m_g); return std::make_pair(e, exists && g.m_edge_pred(e)); - } - - template <typename G, typename EP, typename VP> - std::pair<typename filtered_graph<G, EP, VP>::out_edge_iterator, - typename filtered_graph<G, EP, VP>::out_edge_iterator> - edge_range(typename filtered_graph<G, EP, VP>::vertex_descriptor u, - typename filtered_graph<G, EP, VP>::vertex_descriptor v, - const filtered_graph<G, EP, VP>& g) - { - typedef filtered_graph<G, EP, VP> Graph; +} + +template < typename G, typename EP, typename VP > +std::pair< typename filtered_graph< G, EP, VP >::out_edge_iterator, + typename filtered_graph< G, EP, VP >::out_edge_iterator > +edge_range(typename filtered_graph< G, EP, VP >::vertex_descriptor u, + typename filtered_graph< G, EP, VP >::vertex_descriptor v, + const filtered_graph< G, EP, VP >& g) +{ + typedef filtered_graph< G, EP, VP > Graph; typename Graph::OutEdgePred pred(g.m_edge_pred, g.m_vertex_pred, g); typedef typename Graph::out_edge_iterator iter; - typename graph_traits<G>::out_edge_iterator f, l; + typename graph_traits< G >::out_edge_iterator f, l; boost::tie(f, l) = edge_range(u, v, g.m_g); return std::make_pair(iter(pred, f, l), iter(pred, l, l)); - } - - - //=========================================================================== - // Property map - - template <typename G, typename EP, typename VP, typename Property> - struct property_map<filtered_graph<G, EP, VP>, Property> - : property_map<G, Property> {}; - - template <typename G, typename EP, typename VP, typename Property> - typename property_map<G, Property>::type - get(Property p, filtered_graph<G, EP, VP>& g) - { - return get(p, const_cast<G&>(g.m_g)); - } - - template <typename G, typename EP, typename VP,typename Property> - typename property_map<G, Property>::const_type - get(Property p, const filtered_graph<G, EP, VP>& g) - { +} + +//=========================================================================== +// Property map + +template < typename G, typename EP, typename VP, typename Property > +struct property_map< filtered_graph< G, EP, VP >, Property > +: property_map< G, Property > +{ +}; + +template < typename G, typename EP, typename VP, typename Property > +typename property_map< G, Property >::type get( + Property p, filtered_graph< G, EP, VP >& g) +{ + return get(p, const_cast< G& >(g.m_g)); +} + +template < typename G, typename EP, typename VP, typename Property > +typename property_map< G, Property >::const_type get( + Property p, const filtered_graph< G, EP, VP >& g) +{ return get(p, (const G&)g.m_g); - } +} - template <typename G, typename EP, typename VP, typename Property, - typename Key> - typename property_map_value<G, Property>::type - get(Property p, const filtered_graph<G, EP, VP>& g, const Key& k) - { +template < typename G, typename EP, typename VP, typename Property, + typename Key > +typename property_map_value< G, Property >::type get( + Property p, const filtered_graph< G, EP, VP >& g, const Key& k) +{ return get(p, (const G&)g.m_g, k); - } - - template <typename G, typename EP, typename VP, typename Property, - typename Key, typename Value> - void - put(Property p, const filtered_graph<G, EP, VP>& g, const Key& k, - const Value& val) - { - put(p, const_cast<G&>(g.m_g), k, val); - } - - //=========================================================================== - // Some filtered subgraph specializations - - template <typename Graph, typename Set> - struct vertex_subset_filter { - typedef filtered_graph<Graph, keep_all, is_in_subset<Set> > type; - }; - template <typename Graph, typename Set> - inline typename vertex_subset_filter<Graph, Set>::type - make_vertex_subset_filter(Graph& g, const Set& s) { - typedef typename vertex_subset_filter<Graph, Set>::type Filter; - is_in_subset<Set> p(s); +} + +template < typename G, typename EP, typename VP, typename Property, + typename Key, typename Value > +void put(Property p, const filtered_graph< G, EP, VP >& g, const Key& k, + const Value& val) +{ + put(p, const_cast< G& >(g.m_g), k, val); +} + +//=========================================================================== +// Some filtered subgraph specializations + +template < typename Graph, typename Set > struct vertex_subset_filter +{ + typedef filtered_graph< Graph, keep_all, is_in_subset< Set > > type; +}; +template < typename Graph, typename Set > +inline typename vertex_subset_filter< Graph, Set >::type +make_vertex_subset_filter(Graph& g, const Set& s) +{ + typedef typename vertex_subset_filter< Graph, Set >::type Filter; + is_in_subset< Set > p(s); return Filter(g, keep_all(), p); - } - - // This is misspelled, but present for backwards compatibility; new code - // should use the version below that has the correct spelling. - template <typename Graph, typename Set> - struct vertex_subset_compliment_filter { - typedef filtered_graph<Graph, keep_all, is_not_in_subset<Set> > type; - }; - template <typename Graph, typename Set> - inline typename vertex_subset_compliment_filter<Graph, Set>::type - make_vertex_subset_compliment_filter(Graph& g, const Set& s) { - typedef typename vertex_subset_compliment_filter<Graph, Set>::type Filter; - is_not_in_subset<Set> p(s); +} + +// This is misspelled, but present for backwards compatibility; new code +// should use the version below that has the correct spelling. +template < typename Graph, typename Set > struct vertex_subset_compliment_filter +{ + typedef filtered_graph< Graph, keep_all, is_not_in_subset< Set > > type; +}; +template < typename Graph, typename Set > +inline typename vertex_subset_compliment_filter< Graph, Set >::type +make_vertex_subset_compliment_filter(Graph& g, const Set& s) +{ + typedef typename vertex_subset_compliment_filter< Graph, Set >::type Filter; + is_not_in_subset< Set > p(s); return Filter(g, keep_all(), p); - } - - template <typename Graph, typename Set> - struct vertex_subset_complement_filter { - typedef filtered_graph<Graph, keep_all, is_not_in_subset<Set> > type; - }; - template <typename Graph, typename Set> - inline typename vertex_subset_complement_filter<Graph, Set>::type - make_vertex_subset_complement_filter(Graph& g, const Set& s) { - typedef typename vertex_subset_complement_filter<Graph, Set>::type Filter; - is_not_in_subset<Set> p(s); +} + +template < typename Graph, typename Set > struct vertex_subset_complement_filter +{ + typedef filtered_graph< Graph, keep_all, is_not_in_subset< Set > > type; +}; +template < typename Graph, typename Set > +inline typename vertex_subset_complement_filter< Graph, Set >::type +make_vertex_subset_complement_filter(Graph& g, const Set& s) +{ + typedef typename vertex_subset_complement_filter< Graph, Set >::type Filter; + is_not_in_subset< Set > p(s); return Filter(g, keep_all(), p); - } - - // Filter that uses a property map whose value_type is a boolean - template <typename PropertyMap> - struct property_map_filter { - - property_map_filter() { } - - property_map_filter(const PropertyMap& property_map) : - m_property_map(property_map) { } - - template <typename Key> - bool operator()(const Key& key) const { - return (get(m_property_map, key)); +} + +// Filter that uses a property map whose value_type is a boolean +template < typename PropertyMap > struct property_map_filter +{ + + property_map_filter() {} + + property_map_filter(const PropertyMap& property_map) + : m_property_map(property_map) + { + } + + template < typename Key > bool operator()(const Key& key) const + { + return (get(m_property_map, key)); } - - private : + +private: PropertyMap m_property_map; - }; +}; } // namespace boost - #endif // BOOST_FILTERED_GRAPH_HPP diff --git a/contrib/restricted/boost/graph/include/boost/graph/graph_concepts.hpp b/contrib/restricted/boost/graph/include/boost/graph/graph_concepts.hpp index 3b873a8233..c013ccd4cb 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/graph_concepts.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/graph_concepts.hpp @@ -37,156 +37,158 @@ namespace boost // // It is needed in order to allow us to write using boost::vertices as // needed for ADL when using vector_as_graph below. -#if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) \ - && !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) -# define BOOST_VECTOR_AS_GRAPH_GRAPH_ADL_HACK +#if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) \ + && !BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564)) +#define BOOST_VECTOR_AS_GRAPH_GRAPH_ADL_HACK #endif #ifdef BOOST_VECTOR_AS_GRAPH_GRAPH_ADL_HACK -template <class T> +template < class T > typename T::ThereReallyIsNoMemberByThisNameInT vertices(T const&); #endif - namespace concepts { - BOOST_concept(MultiPassInputIterator,(T)) { - BOOST_CONCEPT_USAGE(MultiPassInputIterator) { - BOOST_CONCEPT_ASSERT((InputIterator<T>)); - } - }; +namespace concepts +{ + BOOST_concept(MultiPassInputIterator, (T)) { BOOST_CONCEPT_USAGE( + MultiPassInputIterator) { BOOST_CONCEPT_ASSERT((InputIterator< T >)); +} +}; - BOOST_concept(Graph,(G)) +BOOST_concept(Graph, (G)) +{ + typedef typename graph_traits< G >::vertex_descriptor vertex_descriptor; + typedef typename graph_traits< G >::edge_descriptor edge_descriptor; + typedef typename graph_traits< G >::directed_category directed_category; + typedef typename graph_traits< G >::edge_parallel_category + edge_parallel_category; + typedef typename graph_traits< G >::traversal_category traversal_category; + + BOOST_CONCEPT_USAGE(Graph) { - typedef typename graph_traits<G>::vertex_descriptor vertex_descriptor; - typedef typename graph_traits<G>::edge_descriptor edge_descriptor; - typedef typename graph_traits<G>::directed_category directed_category; - typedef typename graph_traits<G>::edge_parallel_category edge_parallel_category; - typedef typename graph_traits<G>::traversal_category traversal_category; - - BOOST_CONCEPT_USAGE(Graph) - { - BOOST_CONCEPT_ASSERT((DefaultConstructible<vertex_descriptor>)); - BOOST_CONCEPT_ASSERT((EqualityComparable<vertex_descriptor>)); - BOOST_CONCEPT_ASSERT((Assignable<vertex_descriptor>)); - } - G g; - }; - - BOOST_concept(IncidenceGraph,(G)) - : Graph<G> + BOOST_CONCEPT_ASSERT((DefaultConstructible< vertex_descriptor >)); + BOOST_CONCEPT_ASSERT((EqualityComparable< vertex_descriptor >)); + BOOST_CONCEPT_ASSERT((Assignable< vertex_descriptor >)); + } + G g; +}; + +BOOST_concept(IncidenceGraph, (G)) : Graph< G > +{ + typedef typename graph_traits< G >::edge_descriptor edge_descriptor; + typedef typename graph_traits< G >::out_edge_iterator out_edge_iterator; + typedef typename graph_traits< G >::degree_size_type degree_size_type; + typedef typename graph_traits< G >::traversal_category traversal_category; + + BOOST_STATIC_ASSERT( + (boost::mpl::not_< boost::is_same< out_edge_iterator, void > >::value)); + BOOST_STATIC_ASSERT( + (boost::mpl::not_< boost::is_same< degree_size_type, void > >::value)); + + BOOST_CONCEPT_USAGE(IncidenceGraph) { - typedef typename graph_traits<G>::edge_descriptor edge_descriptor; - typedef typename graph_traits<G>::out_edge_iterator out_edge_iterator; - typedef typename graph_traits<G>::degree_size_type degree_size_type; - typedef typename graph_traits<G>::traversal_category traversal_category; - - BOOST_STATIC_ASSERT((boost::mpl::not_<boost::is_same<out_edge_iterator, void> >::value)); - BOOST_STATIC_ASSERT((boost::mpl::not_<boost::is_same<degree_size_type, void> >::value)); - - BOOST_CONCEPT_USAGE(IncidenceGraph) { - BOOST_CONCEPT_ASSERT((MultiPassInputIterator<out_edge_iterator>)); - BOOST_CONCEPT_ASSERT((DefaultConstructible<edge_descriptor>)); - BOOST_CONCEPT_ASSERT((EqualityComparable<edge_descriptor>)); - BOOST_CONCEPT_ASSERT((Assignable<edge_descriptor>)); - BOOST_CONCEPT_ASSERT((Convertible<traversal_category, - incidence_graph_tag>)); - - p = out_edges(u, g); - n = out_degree(u, g); - e = *p.first; - u = source(e, g); - v = target(e, g); - const_constraints(g); - } - void const_constraints(const G& cg) { - p = out_edges(u, cg); - n = out_degree(u, cg); - e = *p.first; - u = source(e, cg); - v = target(e, cg); - } - std::pair<out_edge_iterator, out_edge_iterator> p; - typename graph_traits<G>::vertex_descriptor u, v; - typename graph_traits<G>::edge_descriptor e; - typename graph_traits<G>::degree_size_type n; - G g; - }; - - BOOST_concept(BidirectionalGraph,(G)) - : IncidenceGraph<G> + BOOST_CONCEPT_ASSERT((MultiPassInputIterator< out_edge_iterator >)); + BOOST_CONCEPT_ASSERT((DefaultConstructible< edge_descriptor >)); + BOOST_CONCEPT_ASSERT((EqualityComparable< edge_descriptor >)); + BOOST_CONCEPT_ASSERT((Assignable< edge_descriptor >)); + BOOST_CONCEPT_ASSERT( + (Convertible< traversal_category, incidence_graph_tag >)); + + p = out_edges(u, g); + n = out_degree(u, g); + e = *p.first; + u = source(e, g); + v = target(e, g); + const_constraints(g); + } + void const_constraints(const G& cg) { - typedef typename graph_traits<G>::in_edge_iterator - in_edge_iterator; - typedef typename graph_traits<G>::traversal_category - traversal_category; + p = out_edges(u, cg); + n = out_degree(u, cg); + e = *p.first; + u = source(e, cg); + v = target(e, cg); + } + std::pair< out_edge_iterator, out_edge_iterator > p; + typename graph_traits< G >::vertex_descriptor u, v; + typename graph_traits< G >::edge_descriptor e; + typename graph_traits< G >::degree_size_type n; + G g; +}; + +BOOST_concept(BidirectionalGraph, (G)) : IncidenceGraph< G > +{ + typedef typename graph_traits< G >::in_edge_iterator in_edge_iterator; + typedef typename graph_traits< G >::traversal_category traversal_category; - BOOST_CONCEPT_USAGE(BidirectionalGraph) { - BOOST_CONCEPT_ASSERT((MultiPassInputIterator<in_edge_iterator>)); - BOOST_CONCEPT_ASSERT((Convertible<traversal_category, - bidirectional_graph_tag>)); + BOOST_CONCEPT_USAGE(BidirectionalGraph) + { + BOOST_CONCEPT_ASSERT((MultiPassInputIterator< in_edge_iterator >)); + BOOST_CONCEPT_ASSERT( + (Convertible< traversal_category, bidirectional_graph_tag >)); - BOOST_STATIC_ASSERT((boost::mpl::not_<boost::is_same<in_edge_iterator, void> >::value)); + BOOST_STATIC_ASSERT((boost::mpl::not_< + boost::is_same< in_edge_iterator, void > >::value)); p = in_edges(v, g); n = in_degree(v, g); n = degree(v, g); e = *p.first; const_constraints(g); - } - void const_constraints(const G& cg) { + } + void const_constraints(const G& cg) + { p = in_edges(v, cg); n = in_degree(v, cg); n = degree(v, cg); e = *p.first; - } - std::pair<in_edge_iterator, in_edge_iterator> p; - typename graph_traits<G>::vertex_descriptor v; - typename graph_traits<G>::edge_descriptor e; - typename graph_traits<G>::degree_size_type n; - G g; - }; - - BOOST_concept(AdjacencyGraph,(G)) - : Graph<G> - { - typedef typename graph_traits<G>::adjacency_iterator - adjacency_iterator; - typedef typename graph_traits<G>::traversal_category - traversal_category; + } + std::pair< in_edge_iterator, in_edge_iterator > p; + typename graph_traits< G >::vertex_descriptor v; + typename graph_traits< G >::edge_descriptor e; + typename graph_traits< G >::degree_size_type n; + G g; +}; + +BOOST_concept(AdjacencyGraph, (G)) : Graph< G > +{ + typedef typename graph_traits< G >::adjacency_iterator adjacency_iterator; + typedef typename graph_traits< G >::traversal_category traversal_category; - BOOST_CONCEPT_USAGE(AdjacencyGraph) { - BOOST_CONCEPT_ASSERT((MultiPassInputIterator<adjacency_iterator>)); - BOOST_CONCEPT_ASSERT((Convertible<traversal_category, - adjacency_graph_tag>)); + BOOST_CONCEPT_USAGE(AdjacencyGraph) + { + BOOST_CONCEPT_ASSERT((MultiPassInputIterator< adjacency_iterator >)); + BOOST_CONCEPT_ASSERT( + (Convertible< traversal_category, adjacency_graph_tag >)); - BOOST_STATIC_ASSERT((boost::mpl::not_<boost::is_same<adjacency_iterator, void> >::value)); + BOOST_STATIC_ASSERT((boost::mpl::not_< + boost::is_same< adjacency_iterator, void > >::value)); p = adjacent_vertices(v, g); v = *p.first; const_constraints(g); - } - void const_constraints(const G& cg) { - p = adjacent_vertices(v, cg); - } - std::pair<adjacency_iterator,adjacency_iterator> p; - typename graph_traits<G>::vertex_descriptor v; - G g; - }; - - BOOST_concept(VertexListGraph,(G)) - : Graph<G> - { - typedef typename graph_traits<G>::vertex_iterator vertex_iterator; - typedef typename graph_traits<G>::vertices_size_type vertices_size_type; - typedef typename graph_traits<G>::traversal_category - traversal_category; + } + void const_constraints(const G& cg) { p = adjacent_vertices(v, cg); } + std::pair< adjacency_iterator, adjacency_iterator > p; + typename graph_traits< G >::vertex_descriptor v; + G g; +}; + +BOOST_concept(VertexListGraph, (G)) : Graph< G > +{ + typedef typename graph_traits< G >::vertex_iterator vertex_iterator; + typedef typename graph_traits< G >::vertices_size_type vertices_size_type; + typedef typename graph_traits< G >::traversal_category traversal_category; - BOOST_CONCEPT_USAGE(VertexListGraph) { - BOOST_CONCEPT_ASSERT((MultiPassInputIterator<vertex_iterator>)); - BOOST_CONCEPT_ASSERT((Convertible<traversal_category, - vertex_list_graph_tag>)); + BOOST_CONCEPT_USAGE(VertexListGraph) + { + BOOST_CONCEPT_ASSERT((MultiPassInputIterator< vertex_iterator >)); + BOOST_CONCEPT_ASSERT( + (Convertible< traversal_category, vertex_list_graph_tag >)); - BOOST_STATIC_ASSERT((boost::mpl::not_<boost::is_same<vertex_iterator, void> >::value)); - BOOST_STATIC_ASSERT((boost::mpl::not_<boost::is_same<vertices_size_type, void> >::value)); + BOOST_STATIC_ASSERT((boost::mpl::not_< + boost::is_same< vertex_iterator, void > >::value)); + BOOST_STATIC_ASSERT((boost::mpl::not_< + boost::is_same< vertices_size_type, void > >::value)); #ifdef BOOST_VECTOR_AS_GRAPH_GRAPH_ADL_HACK // dwa 2003/7/11 -- This clearly shouldn't be necessary, but if @@ -199,8 +201,9 @@ typename T::ThereReallyIsNoMemberByThisNameInT vertices(T const&); p = vertices(g); v = *p.first; const_constraints(g); - } - void const_constraints(const G& cg) { + } + void const_constraints(const G& cg) + { #ifdef BOOST_VECTOR_AS_GRAPH_GRAPH_ADL_HACK // dwa 2003/7/11 -- This clearly shouldn't be necessary, but if // you want to use vector_as_graph, it is! I'm sure the graph @@ -213,406 +216,395 @@ typename T::ThereReallyIsNoMemberByThisNameInT vertices(T const&); p = vertices(cg); v = *p.first; V = num_vertices(cg); - } - std::pair<vertex_iterator,vertex_iterator> p; - typename graph_traits<G>::vertex_descriptor v; - G g; - vertices_size_type V; - }; - - BOOST_concept(EdgeListGraph,(G)) - : Graph<G> + } + std::pair< vertex_iterator, vertex_iterator > p; + typename graph_traits< G >::vertex_descriptor v; + G g; + vertices_size_type V; +}; + +BOOST_concept(EdgeListGraph, (G)) : Graph< G > +{ + typedef typename graph_traits< G >::edge_descriptor edge_descriptor; + typedef typename graph_traits< G >::edge_iterator edge_iterator; + typedef typename graph_traits< G >::edges_size_type edges_size_type; + typedef typename graph_traits< G >::traversal_category traversal_category; + + BOOST_CONCEPT_USAGE(EdgeListGraph) { - typedef typename graph_traits<G>::edge_descriptor edge_descriptor; - typedef typename graph_traits<G>::edge_iterator edge_iterator; - typedef typename graph_traits<G>::edges_size_type edges_size_type; - typedef typename graph_traits<G>::traversal_category - traversal_category; - - BOOST_CONCEPT_USAGE(EdgeListGraph) { - BOOST_CONCEPT_ASSERT((MultiPassInputIterator<edge_iterator>)); - BOOST_CONCEPT_ASSERT((DefaultConstructible<edge_descriptor>)); - BOOST_CONCEPT_ASSERT((EqualityComparable<edge_descriptor>)); - BOOST_CONCEPT_ASSERT((Assignable<edge_descriptor>)); - BOOST_CONCEPT_ASSERT((Convertible<traversal_category, - edge_list_graph_tag>)); - - BOOST_STATIC_ASSERT((boost::mpl::not_<boost::is_same<edge_iterator, void> >::value)); - BOOST_STATIC_ASSERT((boost::mpl::not_<boost::is_same<edges_size_type, void> >::value)); + BOOST_CONCEPT_ASSERT((MultiPassInputIterator< edge_iterator >)); + BOOST_CONCEPT_ASSERT((DefaultConstructible< edge_descriptor >)); + BOOST_CONCEPT_ASSERT((EqualityComparable< edge_descriptor >)); + BOOST_CONCEPT_ASSERT((Assignable< edge_descriptor >)); + BOOST_CONCEPT_ASSERT( + (Convertible< traversal_category, edge_list_graph_tag >)); + + BOOST_STATIC_ASSERT( + (boost::mpl::not_< boost::is_same< edge_iterator, void > >::value)); + BOOST_STATIC_ASSERT((boost::mpl::not_< + boost::is_same< edges_size_type, void > >::value)); p = edges(g); e = *p.first; u = source(e, g); v = target(e, g); const_constraints(g); - } - void const_constraints(const G& cg) { + } + void const_constraints(const G& cg) + { p = edges(cg); E = num_edges(cg); e = *p.first; u = source(e, cg); v = target(e, cg); - } - std::pair<edge_iterator,edge_iterator> p; - typename graph_traits<G>::vertex_descriptor u, v; - typename graph_traits<G>::edge_descriptor e; - edges_size_type E; - G g; - }; - - BOOST_concept(VertexAndEdgeListGraph,(G)) - : VertexListGraph<G> - , EdgeListGraph<G> - { - }; + } + std::pair< edge_iterator, edge_iterator > p; + typename graph_traits< G >::vertex_descriptor u, v; + typename graph_traits< G >::edge_descriptor e; + edges_size_type E; + G g; +}; + +BOOST_concept(VertexAndEdgeListGraph, (G)) +: VertexListGraph< G >, EdgeListGraph< G > {}; + +// Where to put the requirement for this constructor? +// G g(n_vertices); +// Not in mutable graph, then LEDA graph's can't be models of +// MutableGraph. +BOOST_concept(EdgeMutableGraph, (G)) +{ + typedef typename graph_traits< G >::edge_descriptor edge_descriptor; - // Where to put the requirement for this constructor? - // G g(n_vertices); - // Not in mutable graph, then LEDA graph's can't be models of - // MutableGraph. - BOOST_concept(EdgeMutableGraph,(G)) + BOOST_CONCEPT_USAGE(EdgeMutableGraph) { - typedef typename graph_traits<G>::edge_descriptor edge_descriptor; - - BOOST_CONCEPT_USAGE(EdgeMutableGraph) { p = add_edge(u, v, g); remove_edge(u, v, g); remove_edge(e, g); clear_vertex(v, g); - } - G g; - edge_descriptor e; - std::pair<edge_descriptor, bool> p; - typename graph_traits<G>::vertex_descriptor u, v; - }; - - BOOST_concept(VertexMutableGraph,(G)) - { + } + G g; + edge_descriptor e; + std::pair< edge_descriptor, bool > p; + typename graph_traits< G >::vertex_descriptor u, v; +}; + +BOOST_concept(VertexMutableGraph, (G)) +{ - BOOST_CONCEPT_USAGE(VertexMutableGraph) { + BOOST_CONCEPT_USAGE(VertexMutableGraph) + { v = add_vertex(g); remove_vertex(v, g); - } - G g; - typename graph_traits<G>::vertex_descriptor u, v; - }; - - BOOST_concept(MutableGraph,(G)) - : EdgeMutableGraph<G> - , VertexMutableGraph<G> - { - }; + } + G g; + typename graph_traits< G >::vertex_descriptor u, v; +}; - template <class edge_descriptor> - struct dummy_edge_predicate { - bool operator()(const edge_descriptor&) const { - return false; - } - }; +BOOST_concept(MutableGraph, (G)) +: EdgeMutableGraph< G >, VertexMutableGraph< G > {}; + +template < class edge_descriptor > struct dummy_edge_predicate +{ + bool operator()(const edge_descriptor&) const { return false; } +}; - BOOST_concept(MutableIncidenceGraph,(G)) - : MutableGraph<G> +BOOST_concept(MutableIncidenceGraph, (G)) : MutableGraph< G > +{ + BOOST_CONCEPT_USAGE(MutableIncidenceGraph) { - BOOST_CONCEPT_USAGE(MutableIncidenceGraph) { remove_edge(iter, g); remove_out_edge_if(u, p, g); - } - G g; - typedef typename graph_traits<G>::edge_descriptor edge_descriptor; - dummy_edge_predicate<edge_descriptor> p; - typename boost::graph_traits<G>::vertex_descriptor u; - typename boost::graph_traits<G>::out_edge_iterator iter; - }; - - BOOST_concept(MutableBidirectionalGraph,(G)) - : MutableIncidenceGraph<G> - { - BOOST_CONCEPT_USAGE(MutableBidirectionalGraph) - { - remove_in_edge_if(u, p, g); - } - G g; - typedef typename graph_traits<G>::edge_descriptor edge_descriptor; - dummy_edge_predicate<edge_descriptor> p; - typename boost::graph_traits<G>::vertex_descriptor u; - }; - - BOOST_concept(MutableEdgeListGraph,(G)) - : EdgeMutableGraph<G> - { - BOOST_CONCEPT_USAGE(MutableEdgeListGraph) { - remove_edge_if(p, g); - } - G g; - typedef typename graph_traits<G>::edge_descriptor edge_descriptor; - dummy_edge_predicate<edge_descriptor> p; - }; - - BOOST_concept(VertexMutablePropertyGraph,(G)) - : VertexMutableGraph<G> - { - BOOST_CONCEPT_USAGE(VertexMutablePropertyGraph) { - v = add_vertex(vp, g); - } - G g; - typename graph_traits<G>::vertex_descriptor v; - typename vertex_property_type<G>::type vp; - }; - - BOOST_concept(EdgeMutablePropertyGraph,(G)) - : EdgeMutableGraph<G> - { - typedef typename graph_traits<G>::edge_descriptor edge_descriptor; - - BOOST_CONCEPT_USAGE(EdgeMutablePropertyGraph) { - p = add_edge(u, v, ep, g); - } - G g; - std::pair<edge_descriptor, bool> p; - typename graph_traits<G>::vertex_descriptor u, v; - typename edge_property_type<G>::type ep; - }; - - BOOST_concept(AdjacencyMatrix,(G)) - : Graph<G> + } + G g; + typedef typename graph_traits< G >::edge_descriptor edge_descriptor; + dummy_edge_predicate< edge_descriptor > p; + typename boost::graph_traits< G >::vertex_descriptor u; + typename boost::graph_traits< G >::out_edge_iterator iter; +}; + +BOOST_concept(MutableBidirectionalGraph, (G)) : MutableIncidenceGraph< G > +{ + BOOST_CONCEPT_USAGE(MutableBidirectionalGraph) { - typedef typename graph_traits<G>::edge_descriptor edge_descriptor; + remove_in_edge_if(u, p, g); + } + G g; + typedef typename graph_traits< G >::edge_descriptor edge_descriptor; + dummy_edge_predicate< edge_descriptor > p; + typename boost::graph_traits< G >::vertex_descriptor u; +}; + +BOOST_concept(MutableEdgeListGraph, (G)) : EdgeMutableGraph< G > +{ + BOOST_CONCEPT_USAGE(MutableEdgeListGraph) { remove_edge_if(p, g); } + G g; + typedef typename graph_traits< G >::edge_descriptor edge_descriptor; + dummy_edge_predicate< edge_descriptor > p; +}; + +BOOST_concept(VertexMutablePropertyGraph, (G)) : VertexMutableGraph< G > +{ + BOOST_CONCEPT_USAGE(VertexMutablePropertyGraph) { v = add_vertex(vp, g); } + G g; + typename graph_traits< G >::vertex_descriptor v; + typename vertex_property_type< G >::type vp; +}; + +BOOST_concept(EdgeMutablePropertyGraph, (G)) : EdgeMutableGraph< G > +{ + typedef typename graph_traits< G >::edge_descriptor edge_descriptor; - BOOST_CONCEPT_USAGE(AdjacencyMatrix) { + BOOST_CONCEPT_USAGE(EdgeMutablePropertyGraph) { p = add_edge(u, v, ep, g); } + G g; + std::pair< edge_descriptor, bool > p; + typename graph_traits< G >::vertex_descriptor u, v; + typename edge_property_type< G >::type ep; +}; + +BOOST_concept(AdjacencyMatrix, (G)) : Graph< G > +{ + typedef typename graph_traits< G >::edge_descriptor edge_descriptor; + + BOOST_CONCEPT_USAGE(AdjacencyMatrix) + { p = edge(u, v, g); const_constraints(g); - } - void const_constraints(const G& cg) { - p = edge(u, v, cg); - } - typename graph_traits<G>::vertex_descriptor u, v; - std::pair<edge_descriptor, bool> p; - G g; - }; - - BOOST_concept(ReadablePropertyGraph,(G)(X)(Property)) - : Graph<G> - { - typedef typename property_map<G, Property>::const_type const_Map; + } + void const_constraints(const G& cg) { p = edge(u, v, cg); } + typename graph_traits< G >::vertex_descriptor u, v; + std::pair< edge_descriptor, bool > p; + G g; +}; + +BOOST_concept(ReadablePropertyGraph, (G)(X)(Property)) : Graph< G > +{ + typedef typename property_map< G, Property >::const_type const_Map; - BOOST_CONCEPT_USAGE(ReadablePropertyGraph) - { - BOOST_CONCEPT_ASSERT((ReadablePropertyMapConcept<const_Map, X>)); + BOOST_CONCEPT_USAGE(ReadablePropertyGraph) + { + BOOST_CONCEPT_ASSERT((ReadablePropertyMapConcept< const_Map, X >)); const_constraints(g); - } - void const_constraints(const G& cg) { + } + void const_constraints(const G& cg) + { const_Map pmap = get(Property(), cg); pval = get(Property(), cg, x); ignore_unused_variable_warning(pmap); - } - G g; - X x; - typename property_traits<const_Map>::value_type pval; - }; - - BOOST_concept(PropertyGraph,(G)(X)(Property)) - : ReadablePropertyGraph<G, X, Property> + } + G g; + X x; + typename property_traits< const_Map >::value_type pval; +}; + +BOOST_concept(PropertyGraph, (G)(X)(Property)) +: ReadablePropertyGraph< G, X, Property > +{ + typedef typename property_map< G, Property >::type Map; + BOOST_CONCEPT_USAGE(PropertyGraph) { - typedef typename property_map<G, Property>::type Map; - BOOST_CONCEPT_USAGE(PropertyGraph) { - BOOST_CONCEPT_ASSERT((ReadWritePropertyMapConcept<Map, X>)); + BOOST_CONCEPT_ASSERT((ReadWritePropertyMapConcept< Map, X >)); Map pmap = get(Property(), g); pval = get(Property(), g, x); put(Property(), g, x, pval); ignore_unused_variable_warning(pmap); - } - G g; - X x; - typename property_traits<Map>::value_type pval; - }; - - BOOST_concept(LvaluePropertyGraph,(G)(X)(Property)) - : ReadablePropertyGraph<G, X, Property> - { - typedef typename property_map<G, Property>::type Map; - typedef typename property_map<G, Property>::const_type const_Map; + } + G g; + X x; + typename property_traits< Map >::value_type pval; +}; + +BOOST_concept(LvaluePropertyGraph, (G)(X)(Property)) +: ReadablePropertyGraph< G, X, Property > +{ + typedef typename property_map< G, Property >::type Map; + typedef typename property_map< G, Property >::const_type const_Map; - BOOST_CONCEPT_USAGE(LvaluePropertyGraph) { - BOOST_CONCEPT_ASSERT((LvaluePropertyMapConcept<const_Map, X>)); + BOOST_CONCEPT_USAGE(LvaluePropertyGraph) + { + BOOST_CONCEPT_ASSERT((LvaluePropertyMapConcept< const_Map, X >)); pval = get(Property(), g, x); put(Property(), g, x, pval); - } - G g; - X x; - typename property_traits<Map>::value_type pval; - }; - - // The *IndexGraph concepts are "semantic" graph concpepts. These can be - // applied to describe any graph that has an index map that can be accessed - // using the get(*_index, g) method. For example, adjacency lists with - // VertexSet == vecS are implicitly models of this concept. - // - // NOTE: We could require an associated type vertex_index_type, but that - // would mean propagating that type name into graph_traits and all of the - // other graph implementations. Much easier to simply call it unsigned. - - BOOST_concept(VertexIndexGraph,(Graph)) + } + G g; + X x; + typename property_traits< Map >::value_type pval; +}; + +// The *IndexGraph concepts are "semantic" graph concpepts. These can be +// applied to describe any graph that has an index map that can be accessed +// using the get(*_index, g) method. For example, adjacency lists with +// VertexSet == vecS are implicitly models of this concept. +// +// NOTE: We could require an associated type vertex_index_type, but that +// would mean propagating that type name into graph_traits and all of the +// other graph implementations. Much easier to simply call it unsigned. + +BOOST_concept(VertexIndexGraph, (Graph)) +{ + BOOST_CONCEPT_USAGE(VertexIndexGraph) + { + typedef typename graph_traits< Graph >::vertex_descriptor Vertex; + typedef typename property_map< Graph, vertex_index_t >::type Map; + typedef unsigned Index; // This could be Graph::vertex_index_type + Map m = get(vertex_index, g); + Index x = get(vertex_index, g, Vertex()); + ignore_unused_variable_warning(m); + ignore_unused_variable_warning(x); + + // This is relaxed + renumber_vertex_indices(g); + + const_constraints(g); + } + void const_constraints(const Graph& g_) { - BOOST_CONCEPT_USAGE(VertexIndexGraph) - { - typedef typename graph_traits<Graph>::vertex_descriptor Vertex; - typedef typename property_map<Graph, vertex_index_t>::type Map; - typedef unsigned Index; // This could be Graph::vertex_index_type - Map m = get(vertex_index, g); - Index x = get(vertex_index, g, Vertex()); - ignore_unused_variable_warning(m); - ignore_unused_variable_warning(x); - - // This is relaxed - renumber_vertex_indices(g); - - const_constraints(g); - } - void const_constraints(const Graph& g_) - { - typedef typename property_map<Graph, vertex_index_t>::const_type Map; - Map m = get(vertex_index, g_); - ignore_unused_variable_warning(m); - } - private: - Graph g; - }; - - BOOST_concept(EdgeIndexGraph,(Graph)) + typedef typename property_map< Graph, vertex_index_t >::const_type Map; + Map m = get(vertex_index, g_); + ignore_unused_variable_warning(m); + } + +private: + Graph g; +}; + +BOOST_concept(EdgeIndexGraph, (Graph)) +{ + BOOST_CONCEPT_USAGE(EdgeIndexGraph) { - BOOST_CONCEPT_USAGE(EdgeIndexGraph) - { - typedef typename graph_traits<Graph>::edge_descriptor Edge; - typedef typename property_map<Graph, edge_index_t>::type Map; - typedef unsigned Index; // This could be Graph::vertex_index_type - Map m = get(edge_index, g); - Index x = get(edge_index, g, Edge()); - ignore_unused_variable_warning(m); - ignore_unused_variable_warning(x); - - // This is relaxed - renumber_edge_indices(g); - - const_constraints(g); - } - void const_constraints(const Graph& g_) - { - typedef typename property_map<Graph, edge_index_t>::const_type Map; - Map m = get(edge_index, g_); - ignore_unused_variable_warning(m); - } - private: - Graph g; - }; - - BOOST_concept(ColorValue,(C)) - : EqualityComparable<C> - , DefaultConstructible<C> + typedef typename graph_traits< Graph >::edge_descriptor Edge; + typedef typename property_map< Graph, edge_index_t >::type Map; + typedef unsigned Index; // This could be Graph::vertex_index_type + Map m = get(edge_index, g); + Index x = get(edge_index, g, Edge()); + ignore_unused_variable_warning(m); + ignore_unused_variable_warning(x); + + // This is relaxed + renumber_edge_indices(g); + + const_constraints(g); + } + void const_constraints(const Graph& g_) + { + typedef typename property_map< Graph, edge_index_t >::const_type Map; + Map m = get(edge_index, g_); + ignore_unused_variable_warning(m); + } + +private: + Graph g; +}; + +BOOST_concept(ColorValue, (C)) +: EqualityComparable< C >, DefaultConstructible< C > +{ + BOOST_CONCEPT_USAGE(ColorValue) { - BOOST_CONCEPT_USAGE(ColorValue) { - c = color_traits<C>::white(); - c = color_traits<C>::gray(); - c = color_traits<C>::black(); - } - C c; - }; - - BOOST_concept(BasicMatrix,(M)(I)(V)) + c = color_traits< C >::white(); + c = color_traits< C >::gray(); + c = color_traits< C >::black(); + } + C c; +}; + +BOOST_concept(BasicMatrix, (M)(I)(V)) +{ + BOOST_CONCEPT_USAGE(BasicMatrix) { - BOOST_CONCEPT_USAGE(BasicMatrix) { V& elt = A[i][j]; const_constraints(A); ignore_unused_variable_warning(elt); - } - void const_constraints(const M& cA) { + } + void const_constraints(const M& cA) + { const V& elt = cA[i][j]; ignore_unused_variable_warning(elt); - } - M A; - I i, j; - }; + } + M A; + I i, j; +}; + +// The following concepts describe aspects of numberic values and measure +// functions. We're extending the notion of numeric values to include +// emulation for zero and infinity. + +BOOST_concept(NumericValue, (Numeric)) { BOOST_CONCEPT_USAGE(NumericValue) { + BOOST_CONCEPT_ASSERT((DefaultConstructible< Numeric >)); +BOOST_CONCEPT_ASSERT((CopyConstructible< Numeric >)); +numeric_values< Numeric >::zero(); +numeric_values< Numeric >::infinity(); +} +} +; + +BOOST_concept(DegreeMeasure, (Measure)(Graph)) +{ + BOOST_CONCEPT_USAGE(DegreeMeasure) + { + typedef typename Measure::degree_type Degree; + typedef typename Measure::vertex_type Vertex; - // The following concepts describe aspects of numberic values and measure - // functions. We're extending the notion of numeric values to include - // emulation for zero and infinity. + Degree d = m(Vertex(), g); + ignore_unused_variable_warning(d); + } - BOOST_concept(NumericValue,(Numeric)) - { - BOOST_CONCEPT_USAGE(NumericValue) - { - BOOST_CONCEPT_ASSERT(( DefaultConstructible<Numeric> )); - BOOST_CONCEPT_ASSERT(( CopyConstructible<Numeric> )); - numeric_values<Numeric>::zero(); - numeric_values<Numeric>::infinity(); - } - }; - - BOOST_concept(DegreeMeasure,(Measure)(Graph)) - { - BOOST_CONCEPT_USAGE(DegreeMeasure) - { - typedef typename Measure::degree_type Degree; - typedef typename Measure::vertex_type Vertex; - - Degree d = m(Vertex(), g); - ignore_unused_variable_warning(d); - } - private: - Measure m; - Graph g; - }; - - BOOST_concept(DistanceMeasure,(Measure)(Graph)) +private: + Measure m; + Graph g; +}; + +BOOST_concept(DistanceMeasure, (Measure)(Graph)) +{ + BOOST_CONCEPT_USAGE(DistanceMeasure) { - BOOST_CONCEPT_USAGE(DistanceMeasure) - { - typedef typename Measure::distance_type Distance; - typedef typename Measure::result_type Result; - Result r = m(Distance(), g); - ignore_unused_variable_warning(r); - } - private: - Measure m; - Graph g; - }; + typedef typename Measure::distance_type Distance; + typedef typename Measure::result_type Result; + Result r = m(Distance(), g); + ignore_unused_variable_warning(r); + } + +private: + Measure m; + Graph g; +}; } /* namespace concepts */ using boost::concepts::MultiPassInputIteratorConcept; // Graph concepts -using boost::concepts::GraphConcept; -using boost::concepts::IncidenceGraphConcept; -using boost::concepts::BidirectionalGraphConcept; using boost::concepts::AdjacencyGraphConcept; -using boost::concepts::VertexListGraphConcept; +using boost::concepts::AdjacencyMatrixConcept; +using boost::concepts::BidirectionalGraphConcept; +using boost::concepts::EdgeIndexGraphConcept; using boost::concepts::EdgeListGraphConcept; -using boost::concepts::VertexAndEdgeListGraphConcept; using boost::concepts::EdgeMutableGraphConcept; -using boost::concepts::VertexMutableGraphConcept; -using boost::concepts::MutableGraphConcept; -using boost::concepts::MutableIncidenceGraphConcept; +using boost::concepts::EdgeMutablePropertyGraphConcept; +using boost::concepts::GraphConcept; +using boost::concepts::IncidenceGraphConcept; +using boost::concepts::LvaluePropertyGraphConcept; using boost::concepts::MutableBidirectionalGraphConcept; using boost::concepts::MutableEdgeListGraphConcept; -using boost::concepts::VertexMutablePropertyGraphConcept; -using boost::concepts::EdgeMutablePropertyGraphConcept; -using boost::concepts::AdjacencyMatrixConcept; -using boost::concepts::ReadablePropertyGraphConcept; +using boost::concepts::MutableGraphConcept; +using boost::concepts::MutableIncidenceGraphConcept; using boost::concepts::PropertyGraphConcept; -using boost::concepts::LvaluePropertyGraphConcept; +using boost::concepts::ReadablePropertyGraphConcept; +using boost::concepts::VertexAndEdgeListGraphConcept; using boost::concepts::VertexIndexGraphConcept; -using boost::concepts::EdgeIndexGraphConcept; +using boost::concepts::VertexListGraphConcept; +using boost::concepts::VertexMutableGraphConcept; +using boost::concepts::VertexMutablePropertyGraphConcept; // Utility concepts -using boost::concepts::ColorValueConcept; using boost::concepts::BasicMatrixConcept; -using boost::concepts::NumericValueConcept; -using boost::concepts::DistanceMeasureConcept; +using boost::concepts::ColorValueConcept; using boost::concepts::DegreeMeasureConcept; - +using boost::concepts::DistanceMeasureConcept; +using boost::concepts::NumericValueConcept; } /* namespace boost */ #include <boost/concept/detail/concept_undef.hpp> diff --git a/contrib/restricted/boost/graph/include/boost/graph/graph_mutability_traits.hpp b/contrib/restricted/boost/graph/include/boost/graph/graph_mutability_traits.hpp index 726d8d1411..333a026d2f 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/graph_mutability_traits.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/graph_mutability_traits.hpp @@ -13,7 +13,8 @@ #include <boost/mpl/bool.hpp> #include <boost/type_traits/is_same.hpp> -namespace boost { +namespace boost +{ // The mutabiltiy categories classify graphs by their mutating operations // on the edge and vertex sets. This is a substantially more refined @@ -23,176 +24,163 @@ namespace boost { // constructive or destructive algorithms (i.e., graph generators) that // may use these to describe requirements on graph inputs. -struct add_vertex_tag { }; -struct add_vertex_property_tag : virtual add_vertex_tag { }; -struct add_edge_tag { }; -struct add_edge_property_tag : virtual add_edge_tag { }; -struct remove_vertex_tag { }; -struct remove_edge_tag { }; - -struct mutable_vertex_graph_tag - : virtual add_vertex_tag, virtual remove_vertex_tag -{ }; -struct mutable_vertex_property_graph_tag - : virtual add_vertex_property_tag, virtual remove_vertex_tag -{ }; - -struct mutable_edge_graph_tag - : virtual add_edge_tag, virtual remove_edge_tag -{ }; -struct mutable_edge_property_graph_tag - : virtual add_edge_property_tag, virtual remove_edge_tag -{ }; - -struct mutable_graph_tag - : virtual mutable_vertex_graph_tag - , virtual mutable_edge_graph_tag -{ }; -struct mutable_property_graph_tag - : virtual mutable_vertex_property_graph_tag - , virtual mutable_edge_property_graph_tag -{ }; +struct add_vertex_tag +{ +}; +struct add_vertex_property_tag : virtual add_vertex_tag +{ +}; +struct add_edge_tag +{ +}; +struct add_edge_property_tag : virtual add_edge_tag +{ +}; +struct remove_vertex_tag +{ +}; +struct remove_edge_tag +{ +}; + +struct mutable_vertex_graph_tag : virtual add_vertex_tag, + virtual remove_vertex_tag +{ +}; +struct mutable_vertex_property_graph_tag : virtual add_vertex_property_tag, + virtual remove_vertex_tag +{ +}; + +struct mutable_edge_graph_tag : virtual add_edge_tag, virtual remove_edge_tag +{ +}; +struct mutable_edge_property_graph_tag : virtual add_edge_property_tag, + virtual remove_edge_tag +{ +}; + +struct mutable_graph_tag : virtual mutable_vertex_graph_tag, + virtual mutable_edge_graph_tag +{ +}; +struct mutable_property_graph_tag : virtual mutable_vertex_property_graph_tag, + virtual mutable_edge_property_graph_tag +{ +}; // Some graphs just don't like to be torn down. Note this only restricts // teardown to the set of vertices, not the vertex set. // TODO: Find a better name for this tag. -struct add_only_property_graph_tag - : virtual add_vertex_property_tag - , virtual mutable_edge_property_graph_tag -{ }; +struct add_only_property_graph_tag : virtual add_vertex_property_tag, + virtual mutable_edge_property_graph_tag +{ +}; /** * The graph_mutability_traits provide methods for determining the * interfaces supported by graph classes for adding and removing vertices * and edges. */ -template <typename Graph> -struct graph_mutability_traits { +template < typename Graph > struct graph_mutability_traits +{ typedef typename Graph::mutability_category category; }; -template <typename Graph> +template < typename Graph > struct graph_has_add_vertex - : mpl::bool_< - is_convertible< - typename graph_mutability_traits<Graph>::category, - add_vertex_tag - >::value - > -{ }; - -template <typename Graph> -struct graph_has_add_vertex_with_property - : mpl::bool_< - is_convertible< - typename graph_mutability_traits<Graph>::category, - add_vertex_property_tag - >::value - > -{ }; +: mpl::bool_< + is_convertible< typename graph_mutability_traits< Graph >::category, + add_vertex_tag >::value > +{ +}; +template < typename Graph > +struct graph_has_add_vertex_with_property +: mpl::bool_< + is_convertible< typename graph_mutability_traits< Graph >::category, + add_vertex_property_tag >::value > +{ +}; -template <typename Graph> +template < typename Graph > struct graph_has_remove_vertex - : mpl::bool_< - is_convertible< - typename graph_mutability_traits<Graph>::category, - remove_vertex_tag - >::value - > -{ }; - -template <typename Graph> +: mpl::bool_< + is_convertible< typename graph_mutability_traits< Graph >::category, + remove_vertex_tag >::value > +{ +}; + +template < typename Graph > struct graph_has_add_edge - : mpl::bool_< - is_convertible< - typename graph_mutability_traits<Graph>::category, - add_edge_tag - >::value - > -{ }; - -template <typename Graph> -struct graph_has_add_edge_with_property - : mpl::bool_< - is_convertible< - typename graph_mutability_traits<Graph>::category, - add_edge_property_tag - >::value - > -{ }; +: mpl::bool_< + is_convertible< typename graph_mutability_traits< Graph >::category, + add_edge_tag >::value > +{ +}; +template < typename Graph > +struct graph_has_add_edge_with_property +: mpl::bool_< + is_convertible< typename graph_mutability_traits< Graph >::category, + add_edge_property_tag >::value > +{ +}; -template <typename Graph> +template < typename Graph > struct graph_has_remove_edge - : mpl::bool_< - is_convertible< - typename graph_mutability_traits<Graph>::category, - remove_edge_tag - >::value - > -{ }; - +: mpl::bool_< + is_convertible< typename graph_mutability_traits< Graph >::category, + remove_edge_tag >::value > +{ +}; -template <typename Graph> +template < typename Graph > struct is_mutable_vertex_graph - : mpl::and_< - graph_has_add_vertex<Graph>, - graph_has_remove_vertex<Graph> - > -{ }; +: mpl::and_< graph_has_add_vertex< Graph >, graph_has_remove_vertex< Graph > > +{ +}; -template <typename Graph> +template < typename Graph > struct is_mutable_vertex_property_graph - : mpl::and_< - graph_has_add_vertex_with_property<Graph>, - graph_has_remove_vertex<Graph> - > -{ }; - +: mpl::and_< graph_has_add_vertex_with_property< Graph >, + graph_has_remove_vertex< Graph > > +{ +}; -template <typename Graph> +template < typename Graph > struct is_mutable_edge_graph - : mpl::and_< - graph_has_add_edge<Graph>, - graph_has_remove_edge<Graph> - > -{ }; +: mpl::and_< graph_has_add_edge< Graph >, graph_has_remove_edge< Graph > > +{ +}; -template <typename Graph> +template < typename Graph > struct is_mutable_edge_property_graph - : mpl::and_< - graph_has_add_edge_with_property<Graph>, - graph_has_remove_edge<Graph> - > -{ }; - +: mpl::and_< graph_has_add_edge_with_property< Graph >, + graph_has_remove_edge< Graph > > +{ +}; -template <typename Graph> +template < typename Graph > struct is_mutable_graph - : mpl::and_< - is_mutable_vertex_graph<Graph>, - is_mutable_edge_graph<Graph> - > -{ }; +: mpl::and_< is_mutable_vertex_graph< Graph >, is_mutable_edge_graph< Graph > > +{ +}; -template <typename Graph> +template < typename Graph > struct is_mutable_property_graph - : mpl::and_< - is_mutable_vertex_property_graph<Graph>, - is_mutable_edge_property_graph<Graph> - > -{ }; +: mpl::and_< is_mutable_vertex_property_graph< Graph >, + is_mutable_edge_property_graph< Graph > > +{ +}; -template <typename Graph> +template < typename Graph > struct is_add_only_property_graph - : mpl::bool_< - is_convertible< - typename graph_mutability_traits<Graph>::category, - add_only_property_graph_tag - >::value - > -{ }; +: mpl::bool_< + is_convertible< typename graph_mutability_traits< Graph >::category, + add_only_property_graph_tag >::value > +{ +}; /** @name Mutability Traits Specializations */ //@{ diff --git a/contrib/restricted/boost/graph/include/boost/graph/graph_selectors.hpp b/contrib/restricted/boost/graph/include/boost/graph/graph_selectors.hpp index 777ebefc94..e37210d09b 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/graph_selectors.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/graph_selectors.hpp @@ -12,26 +12,43 @@ #include <boost/mpl/bool.hpp> -namespace boost { +namespace boost +{ - //=========================================================================== - // Selectors for the Directed template parameter of adjacency_list - // and adjacency_matrix. +//=========================================================================== +// Selectors for the Directed template parameter of adjacency_list +// and adjacency_matrix. - struct directedS { enum { is_directed = true, is_bidir = false }; - typedef mpl::true_ is_directed_t; +struct directedS +{ + enum + { + is_directed = true, + is_bidir = false + }; + typedef mpl::true_ is_directed_t; typedef mpl::false_ is_bidir_t; - }; - struct undirectedS { - enum { is_directed = false, is_bidir = false }; +}; +struct undirectedS +{ + enum + { + is_directed = false, + is_bidir = false + }; typedef mpl::false_ is_directed_t; typedef mpl::false_ is_bidir_t; - }; - struct bidirectionalS { - enum { is_directed = true, is_bidir = true }; +}; +struct bidirectionalS +{ + enum + { + is_directed = true, + is_bidir = true + }; typedef mpl::true_ is_directed_t; typedef mpl::true_ is_bidir_t; - }; +}; } // namespace boost diff --git a/contrib/restricted/boost/graph/include/boost/graph/graph_traits.hpp b/contrib/restricted/boost/graph/include/boost/graph/graph_traits.hpp index a1c27483a1..208cef1fb9 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/graph_traits.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/graph_traits.hpp @@ -27,351 +27,398 @@ #include <boost/pending/property.hpp> #include <boost/detail/workaround.hpp> -namespace boost { - - namespace detail { -#define BOOST_GRAPH_MEMBER_OR_VOID(name) \ - BOOST_MPL_HAS_XXX_TRAIT_DEF(name) \ - template <typename T> struct BOOST_JOIN(get_member_, name) {typedef typename T::name type;}; \ - template <typename T> struct BOOST_JOIN(get_opt_member_, name): \ - boost::mpl::eval_if_c< \ - BOOST_JOIN(has_, name)<T>::value, \ - BOOST_JOIN(get_member_, name)<T>, \ - boost::mpl::identity<void> > \ - {}; - BOOST_GRAPH_MEMBER_OR_VOID(adjacency_iterator) - BOOST_GRAPH_MEMBER_OR_VOID(out_edge_iterator) - BOOST_GRAPH_MEMBER_OR_VOID(in_edge_iterator) - BOOST_GRAPH_MEMBER_OR_VOID(vertex_iterator) - BOOST_GRAPH_MEMBER_OR_VOID(edge_iterator) - BOOST_GRAPH_MEMBER_OR_VOID(vertices_size_type) - BOOST_GRAPH_MEMBER_OR_VOID(edges_size_type) - BOOST_GRAPH_MEMBER_OR_VOID(degree_size_type) - } +namespace boost +{ + +namespace detail +{ +#define BOOST_GRAPH_MEMBER_OR_VOID(name) \ + BOOST_MPL_HAS_XXX_TRAIT_DEF(name) \ + template < typename T > struct BOOST_JOIN(get_member_, name) \ + { \ + typedef typename T::name type; \ + }; \ + template < typename T > \ + struct BOOST_JOIN(get_opt_member_, name) \ + : boost::mpl::eval_if_c< BOOST_JOIN(has_, name) < T >::value, BOOST_JOIN(get_member_, name)< T >, boost::mpl::identity< void > >\ + { \ + }; + BOOST_GRAPH_MEMBER_OR_VOID(adjacency_iterator) + BOOST_GRAPH_MEMBER_OR_VOID(out_edge_iterator) + BOOST_GRAPH_MEMBER_OR_VOID(in_edge_iterator) + BOOST_GRAPH_MEMBER_OR_VOID(vertex_iterator) + BOOST_GRAPH_MEMBER_OR_VOID(edge_iterator) + BOOST_GRAPH_MEMBER_OR_VOID(vertices_size_type) + BOOST_GRAPH_MEMBER_OR_VOID(edges_size_type) + BOOST_GRAPH_MEMBER_OR_VOID(degree_size_type) +} - template <typename G> - struct graph_traits { +template < typename G > struct graph_traits +{ #define BOOST_GRAPH_PULL_OPT_MEMBER(name) \ - typedef typename detail::BOOST_JOIN(get_opt_member_, name)<G>::type name; - - typedef typename G::vertex_descriptor vertex_descriptor; - typedef typename G::edge_descriptor edge_descriptor; - BOOST_GRAPH_PULL_OPT_MEMBER(adjacency_iterator) - BOOST_GRAPH_PULL_OPT_MEMBER(out_edge_iterator) - BOOST_GRAPH_PULL_OPT_MEMBER(in_edge_iterator) - BOOST_GRAPH_PULL_OPT_MEMBER(vertex_iterator) - BOOST_GRAPH_PULL_OPT_MEMBER(edge_iterator) - - typedef typename G::directed_category directed_category; - typedef typename G::edge_parallel_category edge_parallel_category; - typedef typename G::traversal_category traversal_category; - - BOOST_GRAPH_PULL_OPT_MEMBER(vertices_size_type) - BOOST_GRAPH_PULL_OPT_MEMBER(edges_size_type) - BOOST_GRAPH_PULL_OPT_MEMBER(degree_size_type) + typedef typename detail::BOOST_JOIN(get_opt_member_, name)< G >::type name; + + typedef typename G::vertex_descriptor vertex_descriptor; + typedef typename G::edge_descriptor edge_descriptor; + BOOST_GRAPH_PULL_OPT_MEMBER(adjacency_iterator) + BOOST_GRAPH_PULL_OPT_MEMBER(out_edge_iterator) + BOOST_GRAPH_PULL_OPT_MEMBER(in_edge_iterator) + BOOST_GRAPH_PULL_OPT_MEMBER(vertex_iterator) + BOOST_GRAPH_PULL_OPT_MEMBER(edge_iterator) + + typedef typename G::directed_category directed_category; + typedef typename G::edge_parallel_category edge_parallel_category; + typedef typename G::traversal_category traversal_category; + + BOOST_GRAPH_PULL_OPT_MEMBER(vertices_size_type) + BOOST_GRAPH_PULL_OPT_MEMBER(edges_size_type) + BOOST_GRAPH_PULL_OPT_MEMBER(degree_size_type) #undef BOOST_GRAPH_PULL_OPT_MEMBER - static inline vertex_descriptor null_vertex(); - }; + static inline vertex_descriptor null_vertex(); +}; - template <typename G> - inline typename graph_traits<G>::vertex_descriptor - graph_traits<G>::null_vertex() - { return G::null_vertex(); } - - // directed_category tags - struct directed_tag { }; - struct undirected_tag { }; - struct bidirectional_tag : public directed_tag { }; - - namespace detail { - inline bool is_directed(directed_tag) { return true; } - inline bool is_directed(undirected_tag) { return false; } - } +template < typename G > +inline typename graph_traits< G >::vertex_descriptor +graph_traits< G >::null_vertex() +{ + return G::null_vertex(); +} - /** Return true if the given graph is directed. */ - template <typename Graph> - bool is_directed(const Graph&) { - typedef typename graph_traits<Graph>::directed_category Cat; - return detail::is_directed(Cat()); - } +// directed_category tags +struct directed_tag +{ +}; +struct undirected_tag +{ +}; +struct bidirectional_tag : public directed_tag +{ +}; + +namespace detail +{ + inline bool is_directed(directed_tag) { return true; } + inline bool is_directed(undirected_tag) { return false; } +} - /** Return true if the given graph is undirected. */ - template <typename Graph> - bool is_undirected(const Graph& g) { - return !is_directed(g); - } +/** Return true if the given graph is directed. */ +template < typename Graph > bool is_directed(const Graph&) +{ + typedef typename graph_traits< Graph >::directed_category Cat; + return detail::is_directed(Cat()); +} - /** @name Directed/Undirected Graph Traits */ - //@{ - namespace graph_detail { - template <typename Tag> - struct is_directed_tag - : mpl::bool_<is_convertible<Tag, directed_tag>::value> - { }; - } // namespace graph_detail - - template <typename Graph> - struct is_directed_graph - : graph_detail::is_directed_tag< - typename graph_traits<Graph>::directed_category - > - { }; - - template <typename Graph> - struct is_undirected_graph - : mpl::not_< is_directed_graph<Graph> > - { }; - //@} - - // edge_parallel_category tags - struct allow_parallel_edge_tag { }; - struct disallow_parallel_edge_tag { }; - - namespace detail { - inline bool allows_parallel(allow_parallel_edge_tag) { return true; } - inline bool allows_parallel(disallow_parallel_edge_tag) { return false; } - } +/** Return true if the given graph is undirected. */ +template < typename Graph > bool is_undirected(const Graph& g) +{ + return !is_directed(g); +} - template <typename Graph> - bool allows_parallel_edges(const Graph&) { - typedef typename graph_traits<Graph>::edge_parallel_category Cat; - return detail::allows_parallel(Cat()); - } +/** @name Directed/Undirected Graph Traits */ +//@{ +namespace graph_detail +{ + template < typename Tag > + struct is_directed_tag + : mpl::bool_< is_convertible< Tag, directed_tag >::value > + { + }; +} // namespace graph_detail + +template < typename Graph > +struct is_directed_graph +: graph_detail::is_directed_tag< + typename graph_traits< Graph >::directed_category > +{ +}; + +template < typename Graph > +struct is_undirected_graph : mpl::not_< is_directed_graph< Graph > > +{ +}; +//@} + +// edge_parallel_category tags +struct allow_parallel_edge_tag +{ +}; +struct disallow_parallel_edge_tag +{ +}; + +namespace detail +{ + inline bool allows_parallel(allow_parallel_edge_tag) { return true; } + inline bool allows_parallel(disallow_parallel_edge_tag) { return false; } +} - /** @name Parallel Edges Traits */ - //@{ - /** - * The is_multigraph metafunction returns true if the graph allows - * parallel edges. Technically, a multigraph is a simple graph that - * allows parallel edges, but since there are no traits for the allowance - * or disallowance of loops, this is a moot point. - */ - template <typename Graph> - struct is_multigraph - : mpl::bool_< - is_same< - typename graph_traits<Graph>::edge_parallel_category, - allow_parallel_edge_tag - >::value - > - { }; - //@} - - // traversal_category tags - struct incidence_graph_tag { }; - struct adjacency_graph_tag { }; - struct bidirectional_graph_tag : virtual incidence_graph_tag { }; - struct vertex_list_graph_tag { }; - struct edge_list_graph_tag { }; - struct adjacency_matrix_tag { }; - - // Parallel traversal_category tags - struct distributed_graph_tag { }; - struct distributed_vertex_list_graph_tag { }; - struct distributed_edge_list_graph_tag { }; -#define BOOST_GRAPH_SEQUENTIAL_TRAITS_DEFINES_DISTRIBUTED_TAGS // Disable these from external versions of PBGL - - /** @name Traversal Category Traits - * These traits classify graph types by their supported methods of - * vertex and edge traversal. - */ - //@{ - template <typename Graph> - struct is_incidence_graph - : mpl::bool_< - is_convertible< - typename graph_traits<Graph>::traversal_category, - incidence_graph_tag - >::value - > - { }; - - template <typename Graph> - struct is_bidirectional_graph - : mpl::bool_< - is_convertible< - typename graph_traits<Graph>::traversal_category, - bidirectional_graph_tag - >::value - > - { }; - - template <typename Graph> - struct is_vertex_list_graph - : mpl::bool_< - is_convertible< - typename graph_traits<Graph>::traversal_category, - vertex_list_graph_tag - >::value - > - { }; - - template <typename Graph> - struct is_edge_list_graph - : mpl::bool_< - is_convertible< - typename graph_traits<Graph>::traversal_category, - edge_list_graph_tag - >::value - > - { }; - - template <typename Graph> - struct is_adjacency_matrix - : mpl::bool_< - is_convertible< - typename graph_traits<Graph>::traversal_category, - adjacency_matrix_tag - >::value - > - { }; - //@} - - /** @name Directed Graph Traits - * These metafunctions are used to fully classify directed vs. undirected - * graphs. Recall that an undirected graph is also bidirectional, but it - * cannot be both undirected and directed at the same time. - */ - //@{ - template <typename Graph> - struct is_directed_unidirectional_graph - : mpl::and_< - is_directed_graph<Graph>, mpl::not_< is_bidirectional_graph<Graph> > - > - { }; - - template <typename Graph> - struct is_directed_bidirectional_graph - : mpl::and_< - is_directed_graph<Graph>, is_bidirectional_graph<Graph> - > - { }; - //@} - - //?? not the right place ?? Lee - typedef boost::forward_traversal_tag multi_pass_input_iterator_tag; - - namespace detail { - BOOST_MPL_HAS_XXX_TRAIT_DEF(graph_property_type) - BOOST_MPL_HAS_XXX_TRAIT_DEF(edge_property_type) - BOOST_MPL_HAS_XXX_TRAIT_DEF(vertex_property_type) - - template <typename G> struct get_graph_property_type {typedef typename G::graph_property_type type;}; - template <typename G> struct get_edge_property_type {typedef typename G::edge_property_type type;}; - template <typename G> struct get_vertex_property_type {typedef typename G::vertex_property_type type;}; - } +template < typename Graph > bool allows_parallel_edges(const Graph&) +{ + typedef typename graph_traits< Graph >::edge_parallel_category Cat; + return detail::allows_parallel(Cat()); +} - template <typename G> - struct graph_property_type - : boost::mpl::eval_if<detail::has_graph_property_type<G>, - detail::get_graph_property_type<G>, - no_property> {}; - template <typename G> - struct edge_property_type - : boost::mpl::eval_if<detail::has_edge_property_type<G>, - detail::get_edge_property_type<G>, - no_property> {}; - template <typename G> - struct vertex_property_type - : boost::mpl::eval_if<detail::has_vertex_property_type<G>, - detail::get_vertex_property_type<G>, - no_property> {}; - - template<typename G> - struct graph_bundle_type { - typedef typename G::graph_bundled type; +/** @name Parallel Edges Traits */ +//@{ +/** + * The is_multigraph metafunction returns true if the graph allows + * parallel edges. Technically, a multigraph is a simple graph that + * allows parallel edges, but since there are no traits for the allowance + * or disallowance of loops, this is a moot point. + */ +template < typename Graph > +struct is_multigraph +: mpl::bool_< is_same< typename graph_traits< Graph >::edge_parallel_category, + allow_parallel_edge_tag >::value > +{ +}; +//@} + +// traversal_category tags +struct incidence_graph_tag +{ +}; +struct adjacency_graph_tag +{ +}; +struct bidirectional_graph_tag : virtual incidence_graph_tag +{ +}; +struct vertex_list_graph_tag +{ +}; +struct edge_list_graph_tag +{ +}; +struct adjacency_matrix_tag +{ +}; + +// Parallel traversal_category tags +struct distributed_graph_tag +{ +}; +struct distributed_vertex_list_graph_tag +{ +}; +struct distributed_edge_list_graph_tag +{ +}; +#define BOOST_GRAPH_SEQUENTIAL_TRAITS_DEFINES_DISTRIBUTED_TAGS // Disable these + // from external + // versions of + // PBGL + +/** @name Traversal Category Traits + * These traits classify graph types by their supported methods of + * vertex and edge traversal. + */ +//@{ +template < typename Graph > +struct is_incidence_graph +: mpl::bool_< + is_convertible< typename graph_traits< Graph >::traversal_category, + incidence_graph_tag >::value > +{ +}; + +template < typename Graph > +struct is_bidirectional_graph +: mpl::bool_< + is_convertible< typename graph_traits< Graph >::traversal_category, + bidirectional_graph_tag >::value > +{ +}; + +template < typename Graph > +struct is_vertex_list_graph +: mpl::bool_< + is_convertible< typename graph_traits< Graph >::traversal_category, + vertex_list_graph_tag >::value > +{ +}; + +template < typename Graph > +struct is_edge_list_graph +: mpl::bool_< + is_convertible< typename graph_traits< Graph >::traversal_category, + edge_list_graph_tag >::value > +{ +}; + +template < typename Graph > +struct is_adjacency_matrix +: mpl::bool_< + is_convertible< typename graph_traits< Graph >::traversal_category, + adjacency_matrix_tag >::value > +{ +}; +//@} + +/** @name Directed Graph Traits + * These metafunctions are used to fully classify directed vs. undirected + * graphs. Recall that an undirected graph is also bidirectional, but it + * cannot be both undirected and directed at the same time. + */ +//@{ +template < typename Graph > +struct is_directed_unidirectional_graph +: mpl::and_< is_directed_graph< Graph >, + mpl::not_< is_bidirectional_graph< Graph > > > +{ +}; + +template < typename Graph > +struct is_directed_bidirectional_graph +: mpl::and_< is_directed_graph< Graph >, is_bidirectional_graph< Graph > > +{ +}; +//@} + +//?? not the right place ?? Lee +typedef boost::forward_traversal_tag multi_pass_input_iterator_tag; + +namespace detail +{ + BOOST_MPL_HAS_XXX_TRAIT_DEF(graph_property_type) + BOOST_MPL_HAS_XXX_TRAIT_DEF(edge_property_type) + BOOST_MPL_HAS_XXX_TRAIT_DEF(vertex_property_type) + + template < typename G > struct get_graph_property_type + { + typedef typename G::graph_property_type type; }; - - template<typename G> - struct vertex_bundle_type { - typedef typename G::vertex_bundled type; + template < typename G > struct get_edge_property_type + { + typedef typename G::edge_property_type type; }; - - template<typename G> - struct edge_bundle_type { - typedef typename G::edge_bundled type; + template < typename G > struct get_vertex_property_type + { + typedef typename G::vertex_property_type type; }; +} + +template < typename G > +struct graph_property_type +: boost::mpl::eval_if< detail::has_graph_property_type< G >, + detail::get_graph_property_type< G >, no_property > +{ +}; +template < typename G > +struct edge_property_type +: boost::mpl::eval_if< detail::has_edge_property_type< G >, + detail::get_edge_property_type< G >, no_property > +{ +}; +template < typename G > +struct vertex_property_type +: boost::mpl::eval_if< detail::has_vertex_property_type< G >, + detail::get_vertex_property_type< G >, no_property > +{ +}; + +template < typename G > struct graph_bundle_type +{ + typedef typename G::graph_bundled type; +}; + +template < typename G > struct vertex_bundle_type +{ + typedef typename G::vertex_bundled type; +}; + +template < typename G > struct edge_bundle_type +{ + typedef typename G::edge_bundled type; +}; + +namespace graph +{ + namespace detail + { + template < typename Graph, typename Descriptor > class bundled_result + { + typedef typename graph_traits< Graph >::vertex_descriptor Vertex; + typedef typename mpl::if_c< (is_same< Descriptor, Vertex >::value), + vertex_bundle_type< Graph >, edge_bundle_type< Graph > >::type + bundler; - namespace graph { namespace detail { - template<typename Graph, typename Descriptor> - class bundled_result { - typedef typename graph_traits<Graph>::vertex_descriptor Vertex; - typedef typename mpl::if_c<(is_same<Descriptor, Vertex>::value), - vertex_bundle_type<Graph>, - edge_bundle_type<Graph> >::type bundler; public: typedef typename bundler::type type; }; - template<typename Graph> - class bundled_result<Graph, graph_bundle_t> { - typedef typename graph_traits<Graph>::vertex_descriptor Vertex; - typedef graph_bundle_type<Graph> bundler; + template < typename Graph > + class bundled_result< Graph, graph_bundle_t > + { + typedef typename graph_traits< Graph >::vertex_descriptor Vertex; + typedef graph_bundle_type< Graph > bundler; + public: typedef typename bundler::type type; }; - } } // namespace graph::detail - - namespace graph_detail { - // A helper metafunction for determining whether or not a type is - // bundled. - template <typename T> - struct is_no_bundle : mpl::bool_<is_same<T, no_property>::value> - { }; - } // namespace graph_detail - - /** @name Graph Property Traits - * These metafunctions (along with those above), can be used to access the - * vertex and edge properties (bundled or otherwise) of vertices and - * edges. - */ - //@{ - template<typename Graph> - struct has_graph_property - : mpl::not_< - typename detail::is_no_property< - typename graph_property_type<Graph>::type - >::type - >::type - { }; - - template<typename Graph> - struct has_bundled_graph_property - : mpl::not_< - graph_detail::is_no_bundle<typename graph_bundle_type<Graph>::type> - > - { }; - - template <typename Graph> - struct has_vertex_property - : mpl::not_< - typename detail::is_no_property<typename vertex_property_type<Graph>::type> - >::type - { }; - - template <typename Graph> - struct has_bundled_vertex_property - : mpl::not_< - graph_detail::is_no_bundle<typename vertex_bundle_type<Graph>::type> - > - { }; - - template <typename Graph> - struct has_edge_property - : mpl::not_< - typename detail::is_no_property<typename edge_property_type<Graph>::type> - >::type - { }; - - template <typename Graph> - struct has_bundled_edge_property - : mpl::not_< - graph_detail::is_no_bundle<typename edge_bundle_type<Graph>::type> - > - { }; - //@} + } +} // namespace graph::detail + +namespace graph_detail +{ + // A helper metafunction for determining whether or not a type is + // bundled. + template < typename T > + struct is_no_bundle : mpl::bool_< is_same< T, no_property >::value > + { + }; +} // namespace graph_detail + +/** @name Graph Property Traits + * These metafunctions (along with those above), can be used to access the + * vertex and edge properties (bundled or otherwise) of vertices and + * edges. + */ +//@{ +template < typename Graph > +struct has_graph_property +: mpl::not_< typename detail::is_no_property< + typename graph_property_type< Graph >::type >::type >::type +{ +}; + +template < typename Graph > +struct has_bundled_graph_property +: mpl::not_< + graph_detail::is_no_bundle< typename graph_bundle_type< Graph >::type > > +{ +}; + +template < typename Graph > +struct has_vertex_property +: mpl::not_< typename detail::is_no_property< + typename vertex_property_type< Graph >::type > >::type +{ +}; + +template < typename Graph > +struct has_bundled_vertex_property +: mpl::not_< + graph_detail::is_no_bundle< typename vertex_bundle_type< Graph >::type > > +{ +}; + +template < typename Graph > +struct has_edge_property +: mpl::not_< typename detail::is_no_property< + typename edge_property_type< Graph >::type > >::type +{ +}; + +template < typename Graph > +struct has_bundled_edge_property +: mpl::not_< + graph_detail::is_no_bundle< typename edge_bundle_type< Graph >::type > > +{ +}; +//@} } // namespace boost @@ -380,14 +427,19 @@ namespace boost { // but the alternative is to put source and target in the global // namespace which causes name conflicts with other libraries (like // SUIF). -namespace std { +namespace std +{ - /* Some helper functions for dealing with pairs as edges */ - template <class T, class G> - T source(pair<T,T> p, const G&) { return p.first; } +/* Some helper functions for dealing with pairs as edges */ +template < class T, class G > T source(pair< T, T > p, const G&) +{ + return p.first; +} - template <class T, class G> - T target(pair<T,T> p, const G&) { return p.second; } +template < class T, class G > T target(pair< T, T > p, const G&) +{ + return p.second; +} } @@ -395,9 +447,10 @@ namespace std { // For some reason g++ with STLport does not see the above definition // of source() and target() unless we bring them into the boost // namespace. -namespace boost { - using std::source; - using std::target; +namespace boost +{ +using std::source; +using std::target; } #endif diff --git a/contrib/restricted/boost/graph/include/boost/graph/graphml.hpp b/contrib/restricted/boost/graph/include/boost/graph/graphml.hpp index 77505c29ac..de7630ec3d 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/graphml.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/graphml.hpp @@ -18,7 +18,6 @@ #include <boost/type_traits/is_convertible.hpp> #include <boost/graph/dll_import_export.hpp> #include <boost/graph/graphviz.hpp> // for exceptions -#include <typeinfo> #include <boost/mpl/bool.hpp> #include <boost/mpl/vector.hpp> #include <boost/mpl/find.hpp> @@ -27,6 +26,7 @@ #include <boost/throw_exception.hpp> #include <exception> #include <sstream> +#include <typeinfo> namespace boost { @@ -34,16 +34,19 @@ namespace boost ///////////////////////////////////////////////////////////////////////////// // Graph reader exceptions ///////////////////////////////////////////////////////////////////////////// -struct parse_error: public graph_exception +struct BOOST_SYMBOL_VISIBLE parse_error : public graph_exception { - parse_error(const std::string& err) {error = err; statement = "parse error: " + error;} - virtual ~parse_error() {} - virtual const char* what() const noexcept {return statement.c_str();} + parse_error(const std::string& err) + { + error = err; + statement = "parse error: " + error; + } + ~parse_error() BOOST_OVERRIDE {} + const char* what() const noexcept BOOST_OVERRIDE { return statement.c_str(); } std::string statement; std::string error; }; - class mutate_graph { public: @@ -51,138 +54,148 @@ public: virtual bool is_directed() const = 0; virtual boost::any do_add_vertex() = 0; - virtual std::pair<boost::any,bool> do_add_edge(boost::any source, boost::any target) = 0; + virtual std::pair< boost::any, bool > do_add_edge( + boost::any source, boost::any target) + = 0; - virtual void - set_graph_property(const std::string& name, const std::string& value, const std::string& value_type) = 0; + virtual void set_graph_property(const std::string& name, + const std::string& value, const std::string& value_type) + = 0; - virtual void - set_vertex_property(const std::string& name, boost::any vertex, const std::string& value, const std::string& value_type) = 0; + virtual void set_vertex_property(const std::string& name, boost::any vertex, + const std::string& value, const std::string& value_type) + = 0; - virtual void - set_edge_property(const std::string& name, boost::any edge, const std::string& value, const std::string& value_type) = 0; + virtual void set_edge_property(const std::string& name, boost::any edge, + const std::string& value, const std::string& value_type) + = 0; }; -template<typename MutableGraph> -class mutate_graph_impl : public mutate_graph +template < typename MutableGraph > class mutate_graph_impl : public mutate_graph { - typedef typename graph_traits<MutableGraph>::vertex_descriptor vertex_descriptor; - typedef typename graph_traits<MutableGraph>::edge_descriptor edge_descriptor; + typedef typename graph_traits< MutableGraph >::vertex_descriptor + vertex_descriptor; + typedef + typename graph_traits< MutableGraph >::edge_descriptor edge_descriptor; - public: +public: mutate_graph_impl(MutableGraph& g, dynamic_properties& dp) - : m_g(g), m_dp(dp) { } - - bool is_directed() const + : m_g(g), m_dp(dp) { - return is_convertible<typename graph_traits<MutableGraph>::directed_category, - directed_tag>::value; } - virtual any do_add_vertex() + bool is_directed() const BOOST_OVERRIDE { - return any(add_vertex(m_g)); + return is_convertible< + typename graph_traits< MutableGraph >::directed_category, + directed_tag >::value; } - virtual std::pair<any,bool> do_add_edge(any source, any target) + any do_add_vertex() BOOST_OVERRIDE { return any(add_vertex(m_g)); } + + std::pair< any, bool > do_add_edge(any source, any target) BOOST_OVERRIDE { - std::pair<edge_descriptor,bool> retval = add_edge(any_cast<vertex_descriptor>(source), - any_cast<vertex_descriptor>(target), m_g); + std::pair< edge_descriptor, bool > retval + = add_edge(any_cast< vertex_descriptor >(source), + any_cast< vertex_descriptor >(target), m_g); return std::make_pair(any(retval.first), retval.second); } - virtual void - set_graph_property(const std::string& name, const std::string& value, const std::string& value_type) + void set_graph_property(const std::string& name, + const std::string& value, const std::string& value_type) BOOST_OVERRIDE { bool type_found = false; try { - mpl::for_each<value_types>(put_property<MutableGraph *,value_types> - (name, m_dp, &m_g, value, value_type, m_type_names, type_found)); + mpl::for_each< value_types >( + put_property< MutableGraph*, value_types >(name, m_dp, &m_g, + value, value_type, m_type_names, type_found)); } - catch (bad_lexical_cast) + catch (const bad_lexical_cast&) { - BOOST_THROW_EXCEPTION( - parse_error("invalid value \"" + value + "\" for key " + - name + " of type " + value_type)); + BOOST_THROW_EXCEPTION(parse_error("invalid value \"" + value + + "\" for key " + name + " of type " + value_type)); } if (!type_found) { - BOOST_THROW_EXCEPTION( - parse_error("unrecognized type \"" + value_type + - "\" for key " + name)); + BOOST_THROW_EXCEPTION(parse_error( + "unrecognized type \"" + value_type + "\" for key " + name)); } - } - virtual void - set_vertex_property(const std::string& name, any vertex, const std::string& value, const std::string& value_type) + void set_vertex_property(const std::string& name, any vertex, + const std::string& value, const std::string& value_type) BOOST_OVERRIDE { bool type_found = false; try { - mpl::for_each<value_types>(put_property<vertex_descriptor,value_types> - (name, m_dp, any_cast<vertex_descriptor>(vertex), - value, value_type, m_type_names, type_found)); + mpl::for_each< value_types >( + put_property< vertex_descriptor, value_types >(name, m_dp, + any_cast< vertex_descriptor >(vertex), value, value_type, + m_type_names, type_found)); } - catch (bad_lexical_cast) + catch (const bad_lexical_cast&) { - BOOST_THROW_EXCEPTION( - parse_error("invalid value \"" + value + "\" for key " + - name + " of type " + value_type)); + BOOST_THROW_EXCEPTION(parse_error("invalid value \"" + value + + "\" for key " + name + " of type " + value_type)); } if (!type_found) { - BOOST_THROW_EXCEPTION( - parse_error("unrecognized type \"" + value_type + - "\" for key " + name)); + BOOST_THROW_EXCEPTION(parse_error( + "unrecognized type \"" + value_type + "\" for key " + name)); } - } - virtual void - set_edge_property(const std::string& name, any edge, const std::string& value, const std::string& value_type) + void set_edge_property(const std::string& name, any edge, + const std::string& value, const std::string& value_type) BOOST_OVERRIDE { bool type_found = false; try { - mpl::for_each<value_types>(put_property<edge_descriptor,value_types> - (name, m_dp, any_cast<edge_descriptor>(edge), - value, value_type, m_type_names, type_found)); + mpl::for_each< value_types >( + put_property< edge_descriptor, value_types >(name, m_dp, + any_cast< edge_descriptor >(edge), value, value_type, + m_type_names, type_found)); } - catch (bad_lexical_cast) + catch (const bad_lexical_cast&) { - BOOST_THROW_EXCEPTION( - parse_error("invalid value \"" + value + "\" for key " + - name + " of type " + value_type)); + BOOST_THROW_EXCEPTION(parse_error("invalid value \"" + value + + "\" for key " + name + " of type " + value_type)); } if (!type_found) { - BOOST_THROW_EXCEPTION( - parse_error("unrecognized type \"" + value_type + - "\" for key " + name)); + BOOST_THROW_EXCEPTION(parse_error( + "unrecognized type \"" + value_type + "\" for key " + name)); } } - template <typename Key, typename ValueVector> - class put_property + template < typename Key, typename ValueVector > class put_property { public: - put_property(const std::string& name, dynamic_properties& dp, const Key& key, - const std::string& value, const std::string& value_type, - const char** type_names, bool& type_found) - : m_name(name), m_dp(dp), m_key(key), m_value(value), - m_value_type(value_type), m_type_names(type_names), - m_type_found(type_found) {} - template <class Value> - void operator()(Value) + put_property(const std::string& name, dynamic_properties& dp, + const Key& key, const std::string& value, + const std::string& value_type, const char** type_names, + bool& type_found) + : m_name(name) + , m_dp(dp) + , m_key(key) + , m_value(value) + , m_value_type(value_type) + , m_type_names(type_names) + , m_type_found(type_found) { - if (m_value_type == m_type_names[mpl::find<ValueVector,Value>::type::pos::value]) + } + template < class Value > void operator()(Value) + { + if (m_value_type + == m_type_names[mpl::find< ValueVector, + Value >::type::pos::value]) { - put(m_name, m_dp, m_key, lexical_cast<Value>(m_value)); + put(m_name, m_dp, m_key, lexical_cast< Value >(m_value)); m_type_found = true; } } + private: const std::string& m_name; dynamic_properties& m_dp; @@ -196,72 +209,83 @@ class mutate_graph_impl : public mutate_graph protected: MutableGraph& m_g; dynamic_properties& m_dp; - typedef mpl::vector<bool, int, long, float, double, std::string> value_types; + typedef mpl::vector< bool, int, long, float, double, std::string > + value_types; static const char* m_type_names[]; }; -template<typename MutableGraph> -const char* mutate_graph_impl<MutableGraph>::m_type_names[] = {"boolean", "int", "long", "float", "double", "string"}; +template < typename MutableGraph > +const char* mutate_graph_impl< MutableGraph >::m_type_names[] + = { "boolean", "int", "long", "float", "double", "string" }; -void BOOST_GRAPH_DECL -read_graphml(std::istream& in, mutate_graph& g, size_t desired_idx); +void BOOST_GRAPH_DECL read_graphml( + std::istream& in, mutate_graph& g, size_t desired_idx); -template<typename MutableGraph> -void -read_graphml(std::istream& in, MutableGraph& g, dynamic_properties& dp, size_t desired_idx = 0) +template < typename MutableGraph > +void read_graphml(std::istream& in, MutableGraph& g, dynamic_properties& dp, + size_t desired_idx = 0) { - mutate_graph_impl<MutableGraph> mg(g,dp); + mutate_graph_impl< MutableGraph > mg(g, dp); read_graphml(in, mg, desired_idx); } -template <typename Types> -class get_type_name +template < typename Types > class get_type_name { public: - get_type_name(const std::type_info& type, const char** type_names, std::string& type_name) - : m_type(type), m_type_names(type_names), m_type_name(type_name) {} - template <typename Type> - void operator()(Type) + get_type_name(const std::type_info& type, const char** type_names, + std::string& type_name) + : m_type(type), m_type_names(type_names), m_type_name(type_name) + { + } + template < typename Type > void operator()(Type) { if (typeid(Type) == m_type) - m_type_name = m_type_names[mpl::find<Types,Type>::type::pos::value]; + m_type_name + = m_type_names[mpl::find< Types, Type >::type::pos::value]; } + private: - const std::type_info &m_type; + const std::type_info& m_type; const char** m_type_names; - std::string &m_type_name; + std::string& m_type_name; }; - -template <typename Graph, typename VertexIndexMap> -void -write_graphml(std::ostream& out, const Graph& g, VertexIndexMap vertex_index, - const dynamic_properties& dp, bool ordered_vertices=false) +template < typename Graph, typename VertexIndexMap > +void write_graphml(std::ostream& out, const Graph& g, + VertexIndexMap vertex_index, const dynamic_properties& dp, + bool ordered_vertices = false) { - typedef typename graph_traits<Graph>::directed_category directed_category; - typedef typename graph_traits<Graph>::edge_descriptor edge_descriptor; - typedef typename graph_traits<Graph>::vertex_descriptor vertex_descriptor; + typedef typename graph_traits< Graph >::directed_category directed_category; + typedef typename graph_traits< Graph >::edge_descriptor edge_descriptor; + typedef typename graph_traits< Graph >::vertex_descriptor vertex_descriptor; using boost::property_tree::xml_parser::encode_char_entities; BOOST_STATIC_CONSTANT(bool, - graph_is_directed = - (is_convertible<directed_category*, directed_tag*>::value)); + graph_is_directed + = (is_convertible< directed_category*, directed_tag* >::value)); out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" - << "<graphml xmlns=\"http://graphml.graphdrawing.org/xmlns\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd\">\n"; - - typedef mpl::vector<bool, short, unsigned short, int, unsigned int, long, unsigned long, long long, unsigned long long, float, double, long double, std::string> value_types; - const char* type_names[] = {"boolean", "int", "int", "int", "int", "long", "long", "long", "long", "float", "double", "double", "string"}; - std::map<std::string, std::string> graph_key_ids; - std::map<std::string, std::string> vertex_key_ids; - std::map<std::string, std::string> edge_key_ids; + << "<graphml xmlns=\"http://graphml.graphdrawing.org/xmlns\" " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + "xsi:schemaLocation=\"http://graphml.graphdrawing.org/xmlns " + "http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd\">\n"; + + typedef mpl::vector< bool, short, unsigned short, int, unsigned int, long, + unsigned long, long long, unsigned long long, float, double, + long double, std::string > + value_types; + const char* type_names[] = { "boolean", "int", "int", "int", "int", "long", + "long", "long", "long", "float", "double", "double", "string" }; + std::map< std::string, std::string > graph_key_ids; + std::map< std::string, std::string > vertex_key_ids; + std::map< std::string, std::string > edge_key_ids; int key_count = 0; // Output keys for (dynamic_properties::const_iterator i = dp.begin(); i != dp.end(); ++i) { - std::string key_id = "key" + lexical_cast<std::string>(key_count++); + std::string key_id = "key" + lexical_cast< std::string >(key_count++); if (i->second->key() == typeid(Graph*)) graph_key_ids[i->first] = key_id; else if (i->second->key() == typeid(vertex_descriptor)) @@ -271,9 +295,15 @@ write_graphml(std::ostream& out, const Graph& g, VertexIndexMap vertex_index, else continue; std::string type_name = "string"; - mpl::for_each<value_types>(get_type_name<value_types>(i->second->value(), type_names, type_name)); + mpl::for_each< value_types >(get_type_name< value_types >( + i->second->value(), type_names, type_name)); out << " <key id=\"" << encode_char_entities(key_id) << "\" for=\"" - << (i->second->key() == typeid(Graph*) ? "graph" : (i->second->key() == typeid(vertex_descriptor) ? "node" : "edge")) << "\"" + << (i->second->key() == typeid(Graph*) + ? "graph" + : (i->second->key() == typeid(vertex_descriptor) + ? "node" + : "edge")) + << "\"" << " attr.name=\"" << i->first << "\"" << " attr.type=\"" << type_name << "\"" << " />\n"; @@ -281,7 +311,8 @@ write_graphml(std::ostream& out, const Graph& g, VertexIndexMap vertex_index, out << " <graph id=\"G\" edgedefault=\"" << (graph_is_directed ? "directed" : "undirected") << "\"" - << " parse.nodeids=\"" << (ordered_vertices ? "canonical" : "free") << "\"" + << " parse.nodeids=\"" << (ordered_vertices ? "canonical" : "free") + << "\"" << " parse.edgeids=\"canonical\" parse.order=\"nodesfirst\">\n"; // Output graph data @@ -292,30 +323,34 @@ write_graphml(std::ostream& out, const Graph& g, VertexIndexMap vertex_index, // The const_cast here is just to get typeid correct for property // map key; the graph should not be mutated using it. out << " <data key=\"" << graph_key_ids[i->first] << "\">" - << encode_char_entities(i->second->get_string(const_cast<Graph*>(&g))) << "</data>\n"; + << encode_char_entities( + i->second->get_string(const_cast< Graph* >(&g))) + << "</data>\n"; } } - typedef typename graph_traits<Graph>::vertex_iterator vertex_iterator; + typedef typename graph_traits< Graph >::vertex_iterator vertex_iterator; vertex_iterator v, v_end; for (boost::tie(v, v_end) = vertices(g); v != v_end; ++v) { out << " <node id=\"n" << get(vertex_index, *v) << "\">\n"; // Output data - for (dynamic_properties::const_iterator i = dp.begin(); i != dp.end(); ++i) + for (dynamic_properties::const_iterator i = dp.begin(); i != dp.end(); + ++i) { if (i->second->key() == typeid(vertex_descriptor)) { out << " <data key=\"" << vertex_key_ids[i->first] << "\">" - << encode_char_entities(i->second->get_string(*v)) << "</data>\n"; + << encode_char_entities(i->second->get_string(*v)) + << "</data>\n"; } } out << " </node>\n"; } - typedef typename graph_traits<Graph>::edge_iterator edge_iterator; + typedef typename graph_traits< Graph >::edge_iterator edge_iterator; edge_iterator e, e_end; - typename graph_traits<Graph>::edges_size_type edge_count = 0; + typename graph_traits< Graph >::edges_size_type edge_count = 0; for (boost::tie(e, e_end) = edges(g); e != e_end; ++e) { out << " <edge id=\"e" << edge_count++ << "\" source=\"n" @@ -323,12 +358,14 @@ write_graphml(std::ostream& out, const Graph& g, VertexIndexMap vertex_index, << get(vertex_index, target(*e, g)) << "\">\n"; // Output data - for (dynamic_properties::const_iterator i = dp.begin(); i != dp.end(); ++i) + for (dynamic_properties::const_iterator i = dp.begin(); i != dp.end(); + ++i) { if (i->second->key() == typeid(edge_descriptor)) { out << " <data key=\"" << edge_key_ids[i->first] << "\">" - << encode_char_entities(i->second->get_string(*e)) << "</data>\n"; + << encode_char_entities(i->second->get_string(*e)) + << "</data>\n"; } } out << " </edge>\n"; @@ -338,11 +375,9 @@ write_graphml(std::ostream& out, const Graph& g, VertexIndexMap vertex_index, << "</graphml>\n"; } - -template <typename Graph> -void -write_graphml(std::ostream& out, const Graph& g, const dynamic_properties& dp, - bool ordered_vertices=false) +template < typename Graph > +void write_graphml(std::ostream& out, const Graph& g, + const dynamic_properties& dp, bool ordered_vertices = false) { write_graphml(out, g, get(vertex_index, g), dp, ordered_vertices); } diff --git a/contrib/restricted/boost/graph/include/boost/graph/graphviz.hpp b/contrib/restricted/boost/graph/include/boost/graph/graphviz.hpp index 36bc63435c..cdfee5d0bb 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/graphviz.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/graphviz.hpp @@ -11,11 +11,11 @@ #define BOOST_GRAPHVIZ_HPP #include <boost/config.hpp> -#include <string> -#include <map> -#include <iostream> +#include <cstdio> // for FILE #include <fstream> -#include <stdio.h> // for FILE +#include <iostream> +#include <map> +#include <string> #include <boost/property_map/property_map.hpp> #include <boost/tuple/tuple.hpp> #include <boost/graph/graph_traits.hpp> @@ -27,6 +27,7 @@ #include <boost/graph/dll_import_export.hpp> #include <boost/graph/compressed_sparse_row_graph.hpp> #include <boost/graph/iteration_macros.hpp> +#include <boost/graph/detail/mpi_include.hpp> #include <boost/spirit/include/classic_multi_pass.hpp> #include <boost/lexical_cast.hpp> #include <boost/static_assert.hpp> @@ -34,408 +35,418 @@ #include <boost/xpressive/xpressive_static.hpp> #include <boost/foreach.hpp> -namespace boost { +namespace boost +{ - template <typename directed_category> - struct graphviz_io_traits { - static std::string name() { - return "digraph"; - } - static std::string delimiter() { - return "->"; - } }; - - template <> - struct graphviz_io_traits <undirected_tag> { - static std::string name() { - return "graph"; - } - static std::string delimiter() { - return "--"; - } - }; +template < typename directed_category > struct graphviz_io_traits +{ + static std::string name() { return "digraph"; } + static std::string delimiter() { return "->"; } +}; - struct default_writer { - void operator()(std::ostream&) const { - } - template <class VorE> - void operator()(std::ostream&, const VorE&) const { - } - }; +template <> struct graphviz_io_traits< undirected_tag > +{ + static std::string name() { return "graph"; } + static std::string delimiter() { return "--"; } +}; - template <typename T> - inline std::string escape_dot_string(const T& obj) { +struct default_writer +{ + void operator()(std::ostream&) const {} + template < class VorE > void operator()(std::ostream&, const VorE&) const {} +}; + +template < typename T > inline std::string escape_dot_string(const T& obj) +{ using namespace boost::xpressive; - static sregex valid_unquoted_id = (((alpha | '_') >> *_w) | (!as_xpr('-') >> (('.' >> *_d) | (+_d >> !('.' >> *_d))))); - std::string s(boost::lexical_cast<std::string>(obj)); - if (regex_match(s, valid_unquoted_id)) { - return s; - } else { - boost::algorithm::replace_all(s, "\"", "\\\""); - return "\"" + s + "\""; + static sregex valid_unquoted_id = (((alpha | '_') >> *_w) + | (!as_xpr('-') >> (('.' >> *_d) | (+_d >> !('.' >> *_d))))); + std::string s(boost::lexical_cast< std::string >(obj)); + if (regex_match(s, valid_unquoted_id)) + { + return s; + } + else + { + boost::algorithm::replace_all(s, "\"", "\\\""); + return "\"" + s + "\""; } - } +} - template <class Name> - class label_writer { - public: +template < class Name > class label_writer +{ +public: label_writer(Name _name) : name(_name) {} - template <class VertexOrEdge> - void operator()(std::ostream& out, const VertexOrEdge& v) const { - out << "[label=" << escape_dot_string(get(name, v)) << "]"; + template < class VertexOrEdge > + void operator()(std::ostream& out, const VertexOrEdge& v) const + { + out << "[label=" << escape_dot_string(get(name, v)) << "]"; } - private: + +private: Name name; - }; - template <class Name> - inline label_writer<Name> - make_label_writer(Name n) { - return label_writer<Name>(n); - } - - enum edge_attribute_t { edge_attribute = 1111 }; - enum vertex_attribute_t { vertex_attribute = 2222 }; - enum graph_graph_attribute_t { graph_graph_attribute = 3333 }; - enum graph_vertex_attribute_t { graph_vertex_attribute = 4444 }; - enum graph_edge_attribute_t { graph_edge_attribute = 5555 }; - - BOOST_INSTALL_PROPERTY(edge, attribute); - BOOST_INSTALL_PROPERTY(vertex, attribute); - BOOST_INSTALL_PROPERTY(graph, graph_attribute); - BOOST_INSTALL_PROPERTY(graph, vertex_attribute); - BOOST_INSTALL_PROPERTY(graph, edge_attribute); - - - template <class Attribute> - inline void write_attributes(const Attribute& attr, std::ostream& out) { +}; +template < class Name > inline label_writer< Name > make_label_writer(Name n) +{ + return label_writer< Name >(n); +} + +enum edge_attribute_t +{ + edge_attribute = 1111 +}; +enum vertex_attribute_t +{ + vertex_attribute = 2222 +}; +enum graph_graph_attribute_t +{ + graph_graph_attribute = 3333 +}; +enum graph_vertex_attribute_t +{ + graph_vertex_attribute = 4444 +}; +enum graph_edge_attribute_t +{ + graph_edge_attribute = 5555 +}; + +BOOST_INSTALL_PROPERTY(edge, attribute); +BOOST_INSTALL_PROPERTY(vertex, attribute); +BOOST_INSTALL_PROPERTY(graph, graph_attribute); +BOOST_INSTALL_PROPERTY(graph, vertex_attribute); +BOOST_INSTALL_PROPERTY(graph, edge_attribute); + +template < class Attribute > +inline void write_attributes(const Attribute& attr, std::ostream& out) +{ typename Attribute::const_iterator i, iend; - i = attr.begin(); + i = attr.begin(); iend = attr.end(); - while ( i != iend ) { - out << i->first << "=" << escape_dot_string(i->second); - ++i; - if ( i != iend ) - out << ", "; + while (i != iend) + { + out << i->first << "=" << escape_dot_string(i->second); + ++i; + if (i != iend) + out << ", "; } - } +} - template<typename Attributes> - inline void write_all_attributes(Attributes attributes, - const std::string& name, - std::ostream& out) - { +template < typename Attributes > +inline void write_all_attributes( + Attributes attributes, const std::string& name, std::ostream& out) +{ typename Attributes::const_iterator i = attributes.begin(), end = attributes.end(); - if (i != end) { - out << name << " [\n"; - write_attributes(attributes, out); - out << "];\n"; + if (i != end) + { + out << name << " [\n"; + write_attributes(attributes, out); + out << "];\n"; } - } +} - inline void write_all_attributes(detail::error_property_not_found, - const std::string&, - std::ostream&) - { +inline void write_all_attributes( + detail::error_property_not_found, const std::string&, std::ostream&) +{ // Do nothing - no attributes exist - } - - - +} - template <typename GraphGraphAttributes, - typename GraphNodeAttributes, - typename GraphEdgeAttributes> - struct graph_attributes_writer - { - graph_attributes_writer(GraphGraphAttributes gg, - GraphNodeAttributes gn, - GraphEdgeAttributes ge) - : g_attributes(gg), n_attributes(gn), e_attributes(ge) { } +template < typename GraphGraphAttributes, typename GraphNodeAttributes, + typename GraphEdgeAttributes > +struct graph_attributes_writer +{ + graph_attributes_writer( + GraphGraphAttributes gg, GraphNodeAttributes gn, GraphEdgeAttributes ge) + : g_attributes(gg), n_attributes(gn), e_attributes(ge) + { + } - void operator()(std::ostream& out) const { - write_all_attributes(g_attributes, "graph", out); - write_all_attributes(n_attributes, "node", out); - write_all_attributes(e_attributes, "edge", out); + void operator()(std::ostream& out) const + { + write_all_attributes(g_attributes, "graph", out); + write_all_attributes(n_attributes, "node", out); + write_all_attributes(e_attributes, "edge", out); } GraphGraphAttributes g_attributes; GraphNodeAttributes n_attributes; GraphEdgeAttributes e_attributes; - }; - - template <typename GAttrMap, typename NAttrMap, typename EAttrMap> - graph_attributes_writer<GAttrMap, NAttrMap, EAttrMap> - make_graph_attributes_writer(const GAttrMap& g_attr, const NAttrMap& n_attr, - const EAttrMap& e_attr) { - return graph_attributes_writer<GAttrMap, NAttrMap, EAttrMap> - (g_attr, n_attr, e_attr); - } - - - template <typename Graph> - graph_attributes_writer - <typename graph_property<Graph, graph_graph_attribute_t>::type, - typename graph_property<Graph, graph_vertex_attribute_t>::type, - typename graph_property<Graph, graph_edge_attribute_t>::type> - make_graph_attributes_writer(const Graph& g) - { - typedef typename graph_property<Graph, graph_graph_attribute_t>::type - GAttrMap; - typedef typename graph_property<Graph, graph_vertex_attribute_t>::type - NAttrMap; - typedef typename graph_property<Graph, graph_edge_attribute_t>::type - EAttrMap; +}; + +template < typename GAttrMap, typename NAttrMap, typename EAttrMap > +graph_attributes_writer< GAttrMap, NAttrMap, EAttrMap > +make_graph_attributes_writer( + const GAttrMap& g_attr, const NAttrMap& n_attr, const EAttrMap& e_attr) +{ + return graph_attributes_writer< GAttrMap, NAttrMap, EAttrMap >( + g_attr, n_attr, e_attr); +} + +template < typename Graph > +graph_attributes_writer< + typename graph_property< Graph, graph_graph_attribute_t >::type, + typename graph_property< Graph, graph_vertex_attribute_t >::type, + typename graph_property< Graph, graph_edge_attribute_t >::type > +make_graph_attributes_writer(const Graph& g) +{ + typedef typename graph_property< Graph, graph_graph_attribute_t >::type + GAttrMap; + typedef typename graph_property< Graph, graph_vertex_attribute_t >::type + NAttrMap; + typedef + typename graph_property< Graph, graph_edge_attribute_t >::type EAttrMap; GAttrMap gam = get_property(g, graph_graph_attribute); NAttrMap nam = get_property(g, graph_vertex_attribute); EAttrMap eam = get_property(g, graph_edge_attribute); - graph_attributes_writer<GAttrMap, NAttrMap, EAttrMap> writer(gam, nam, eam); + graph_attributes_writer< GAttrMap, NAttrMap, EAttrMap > writer( + gam, nam, eam); return writer; - } +} - template <typename AttributeMap> - struct attributes_writer { - attributes_writer(AttributeMap attr) - : attributes(attr) { } +template < typename AttributeMap > struct attributes_writer +{ + attributes_writer(AttributeMap attr) : attributes(attr) {} - template <class VorE> - void operator()(std::ostream& out, const VorE& e) const { - this->write_attribute(out, attributes[e]); + template < class VorE > + void operator()(std::ostream& out, const VorE& e) const + { + this->write_attribute(out, attributes[e]); } - private: - template<typename AttributeSequence> - void write_attribute(std::ostream& out, - const AttributeSequence& seq) const - { - if (!seq.empty()) { - out << "["; - write_attributes(seq, out); - out << "]"; +private: + template < typename AttributeSequence > + void write_attribute(std::ostream& out, const AttributeSequence& seq) const + { + if (!seq.empty()) + { + out << "["; + write_attributes(seq, out); + out << "]"; } - } + } - void write_attribute(std::ostream&, - detail::error_property_not_found) const - { - } + void write_attribute(std::ostream&, detail::error_property_not_found) const + { + } AttributeMap attributes; - }; - - template <typename Graph> - attributes_writer - <typename property_map<Graph, edge_attribute_t>::const_type> - make_edge_attributes_writer(const Graph& g) - { - typedef typename property_map<Graph, edge_attribute_t>::const_type - EdgeAttributeMap; - return attributes_writer<EdgeAttributeMap>(get(edge_attribute, g)); - } - - template <typename Graph> - attributes_writer - <typename property_map<Graph, vertex_attribute_t>::const_type> - make_vertex_attributes_writer(const Graph& g) - { - typedef typename property_map<Graph, vertex_attribute_t>::const_type - VertexAttributeMap; - return attributes_writer<VertexAttributeMap>(get(vertex_attribute, g)); - } - - template <typename Graph, typename VertexPropertiesWriter, - typename EdgePropertiesWriter, typename GraphPropertiesWriter, - typename VertexID> - inline void - write_graphviz - (std::ostream& out, const Graph& g, - VertexPropertiesWriter vpw, - EdgePropertiesWriter epw, - GraphPropertiesWriter gpw, - VertexID vertex_id - BOOST_GRAPH_ENABLE_IF_MODELS_PARM(Graph,vertex_list_graph_tag)) - { - BOOST_CONCEPT_ASSERT((EdgeListGraphConcept<Graph>)); - - typedef typename graph_traits<Graph>::directed_category cat_type; - typedef graphviz_io_traits<cat_type> Traits; +}; + +template < typename Graph > +attributes_writer< + typename property_map< Graph, edge_attribute_t >::const_type > +make_edge_attributes_writer(const Graph& g) +{ + typedef typename property_map< Graph, edge_attribute_t >::const_type + EdgeAttributeMap; + return attributes_writer< EdgeAttributeMap >(get(edge_attribute, g)); +} + +template < typename Graph > +attributes_writer< + typename property_map< Graph, vertex_attribute_t >::const_type > +make_vertex_attributes_writer(const Graph& g) +{ + typedef typename property_map< Graph, vertex_attribute_t >::const_type + VertexAttributeMap; + return attributes_writer< VertexAttributeMap >(get(vertex_attribute, g)); +} + +template < typename Graph, typename VertexPropertiesWriter, + typename EdgePropertiesWriter, typename GraphPropertiesWriter, + typename VertexID > +inline void write_graphviz(std::ostream& out, const Graph& g, + VertexPropertiesWriter vpw, EdgePropertiesWriter epw, + GraphPropertiesWriter gpw, + VertexID vertex_id BOOST_GRAPH_ENABLE_IF_MODELS_PARM( + Graph, vertex_list_graph_tag)) +{ + BOOST_CONCEPT_ASSERT((EdgeListGraphConcept< Graph >)); + + typedef typename graph_traits< Graph >::directed_category cat_type; + typedef graphviz_io_traits< cat_type > Traits; std::string name = "G"; - out << Traits::name() << " " << escape_dot_string(name) << " {" << std::endl; + out << Traits::name() << " " << escape_dot_string(name) << " {" + << std::endl; - gpw(out); //print graph properties + gpw(out); // print graph properties - typename graph_traits<Graph>::vertex_iterator i, end; + typename graph_traits< Graph >::vertex_iterator i, end; - for(boost::tie(i,end) = vertices(g); i != end; ++i) { - out << escape_dot_string(get(vertex_id, *i)); - vpw(out, *i); //print vertex attributes - out << ";" << std::endl; + for (boost::tie(i, end) = vertices(g); i != end; ++i) + { + out << escape_dot_string(get(vertex_id, *i)); + vpw(out, *i); // print vertex attributes + out << ";" << std::endl; } - typename graph_traits<Graph>::edge_iterator ei, edge_end; - for(boost::tie(ei, edge_end) = edges(g); ei != edge_end; ++ei) { - out << escape_dot_string(get(vertex_id, source(*ei, g))) << Traits::delimiter() << escape_dot_string(get(vertex_id, target(*ei, g))) << " "; - epw(out, *ei); //print edge attributes - out << ";" << std::endl; + typename graph_traits< Graph >::edge_iterator ei, edge_end; + for (boost::tie(ei, edge_end) = edges(g); ei != edge_end; ++ei) + { + out << escape_dot_string(get(vertex_id, source(*ei, g))) + << Traits::delimiter() + << escape_dot_string(get(vertex_id, target(*ei, g))) << " "; + epw(out, *ei); // print edge attributes + out << ";" << std::endl; } out << "}" << std::endl; - } - - template <typename Graph, typename VertexPropertiesWriter, - typename EdgePropertiesWriter, typename GraphPropertiesWriter> - inline void - write_graphviz(std::ostream& out, const Graph& g, - VertexPropertiesWriter vpw, - EdgePropertiesWriter epw, - GraphPropertiesWriter gpw - BOOST_GRAPH_ENABLE_IF_MODELS_PARM(Graph,vertex_list_graph_tag)) - { write_graphviz(out, g, vpw, epw, gpw, get(vertex_index, g)); } - - template <typename Graph> - inline void - write_graphviz(std::ostream& out, const Graph& g - BOOST_GRAPH_ENABLE_IF_MODELS_PARM(Graph,vertex_list_graph_tag)) - { +} + +template < typename Graph, typename VertexPropertiesWriter, + typename EdgePropertiesWriter, typename GraphPropertiesWriter > +inline void write_graphviz(std::ostream& out, const Graph& g, + VertexPropertiesWriter vpw, EdgePropertiesWriter epw, + GraphPropertiesWriter gpw BOOST_GRAPH_ENABLE_IF_MODELS_PARM( + Graph, vertex_list_graph_tag)) +{ + write_graphviz(out, g, vpw, epw, gpw, get(vertex_index, g)); +} + +template < typename Graph > +inline void write_graphviz(std::ostream& out, + const Graph& g BOOST_GRAPH_ENABLE_IF_MODELS_PARM( + Graph, vertex_list_graph_tag)) +{ default_writer dw; default_writer gw; write_graphviz(out, g, dw, dw, gw); - } +} - template <typename Graph, typename VertexWriter> - inline void - write_graphviz(std::ostream& out, const Graph& g, VertexWriter vw - BOOST_GRAPH_ENABLE_IF_MODELS_PARM(Graph,vertex_list_graph_tag)) - { +template < typename Graph, typename VertexWriter > +inline void write_graphviz(std::ostream& out, const Graph& g, + VertexWriter vw BOOST_GRAPH_ENABLE_IF_MODELS_PARM( + Graph, vertex_list_graph_tag)) +{ default_writer dw; default_writer gw; write_graphviz(out, g, vw, dw, gw); - } - - template <typename Graph, typename VertexWriter, typename EdgeWriter> - inline void - write_graphviz(std::ostream& out, const Graph& g, - VertexWriter vw, EdgeWriter ew - BOOST_GRAPH_ENABLE_IF_MODELS_PARM(Graph,vertex_list_graph_tag)) - { +} + +template < typename Graph, typename VertexWriter, typename EdgeWriter > +inline void write_graphviz(std::ostream& out, const Graph& g, VertexWriter vw, + EdgeWriter ew BOOST_GRAPH_ENABLE_IF_MODELS_PARM( + Graph, vertex_list_graph_tag)) +{ default_writer gw; write_graphviz(out, g, vw, ew, gw); - } +} - namespace detail { +namespace detail +{ - template <class Graph_, class RandomAccessIterator, class VertexID> - void write_graphviz_subgraph (std::ostream& out, - const subgraph<Graph_>& g, - RandomAccessIterator vertex_marker, - RandomAccessIterator edge_marker, - VertexID vertex_id) + template < class Graph_, class RandomAccessIterator, class VertexID > + void write_graphviz_subgraph(std::ostream& out, const subgraph< Graph_ >& g, + RandomAccessIterator vertex_marker, RandomAccessIterator edge_marker, + VertexID vertex_id) { - typedef subgraph<Graph_> Graph; - typedef typename graph_traits<Graph>::vertex_descriptor Vertex; - typedef typename graph_traits<Graph>::directed_category cat_type; - typedef graphviz_io_traits<cat_type> Traits; - - typedef typename graph_property<Graph, graph_name_t>::type NameType; - const NameType& g_name = get_property(g, graph_name); + typedef subgraph< Graph_ > Graph; + typedef typename graph_traits< Graph >::vertex_descriptor Vertex; + typedef typename graph_traits< Graph >::directed_category cat_type; + typedef graphviz_io_traits< cat_type > Traits; + + typedef typename graph_property< Graph, graph_name_t >::type NameType; + const NameType& g_name = get_property(g, graph_name); + + if (g.is_root()) + out << Traits::name(); + else + out << "subgraph"; + + out << " " << escape_dot_string(g_name) << " {" << std::endl; + + typename Graph::const_children_iterator i_child, j_child; + + // print graph/node/edge attributes + make_graph_attributes_writer(g)(out); + + // print subgraph + for (boost::tie(i_child, j_child) = g.children(); i_child != j_child; + ++i_child) + write_graphviz_subgraph( + out, *i_child, vertex_marker, edge_marker, vertex_id); + + // Print out vertices and edges not in the subgraphs. + + typename graph_traits< Graph >::vertex_iterator i, end; + typename graph_traits< Graph >::edge_iterator ei, edge_end; + + for (boost::tie(i, end) = vertices(g); i != end; ++i) + { + Vertex v = g.local_to_global(*i); + int pos = get(vertex_id, v); + if (vertex_marker[pos]) + { + vertex_marker[pos] = false; + out << escape_dot_string(pos); + make_vertex_attributes_writer(g.root())(out, v); + out << ";" << std::endl; + } + } - if ( g.is_root() ) - out << Traits::name() ; - else - out << "subgraph"; + for (boost::tie(ei, edge_end) = edges(g); ei != edge_end; ++ei) + { + Vertex u = g.local_to_global(source(*ei, g)), + v = g.local_to_global(target(*ei, g)); + int pos = get(get(edge_index, g.root()), g.local_to_global(*ei)); + if (edge_marker[pos]) + { + edge_marker[pos] = false; + out << escape_dot_string(get(vertex_id, u)) << " " + << Traits::delimiter() << " " + << escape_dot_string(get(vertex_id, v)); + make_edge_attributes_writer(g)( + out, *ei); // print edge properties + out << ";" << std::endl; + } + } + out << "}" << std::endl; + } +} // namespace detail - out << " " << escape_dot_string(g_name) << " {" << std::endl; +// requires graph_name graph property +template < typename Graph > +void write_graphviz(std::ostream& out, const subgraph< Graph >& g) +{ + std::vector< bool > edge_marker(num_edges(g), true); + std::vector< bool > vertex_marker(num_vertices(g), true); - typename Graph::const_children_iterator i_child, j_child; + detail::write_graphviz_subgraph(out, g, vertex_marker.begin(), + edge_marker.begin(), get(vertex_index, g)); +} - //print graph/node/edge attributes - make_graph_attributes_writer(g)(out); +template < typename Graph > +void write_graphviz(const std::string& filename, const subgraph< Graph >& g) +{ + std::ofstream out(filename.c_str()); + std::vector< bool > edge_marker(num_edges(g), true); + std::vector< bool > vertex_marker(num_vertices(g), true); - //print subgraph - for ( boost::tie(i_child,j_child) = g.children(); - i_child != j_child; ++i_child ) - write_graphviz_subgraph(out, *i_child, vertex_marker, edge_marker, - vertex_id); + detail::write_graphviz_subgraph(out, g, vertex_marker.begin(), + edge_marker.begin(), get(vertex_index, g)); +} - // Print out vertices and edges not in the subgraphs. +template < typename Graph, typename VertexID > +void write_graphviz( + std::ostream& out, const subgraph< Graph >& g, VertexID vertex_id) +{ + std::vector< bool > edge_marker(num_edges(g), true); + std::vector< bool > vertex_marker(num_vertices(g), true); - typename graph_traits<Graph>::vertex_iterator i, end; - typename graph_traits<Graph>::edge_iterator ei, edge_end; + detail::write_graphviz_subgraph( + out, g, vertex_marker.begin(), edge_marker.begin(), vertex_id); +} - for(boost::tie(i,end) = vertices(g); i != end; ++i) { - Vertex v = g.local_to_global(*i); - int pos = get(vertex_id, v); - if ( vertex_marker[pos] ) { - vertex_marker[pos] = false; - out << escape_dot_string(pos); - make_vertex_attributes_writer(g.root())(out, v); - out << ";" << std::endl; - } - } - - for (boost::tie(ei, edge_end) = edges(g); ei != edge_end; ++ei) { - Vertex u = g.local_to_global(source(*ei,g)), - v = g.local_to_global(target(*ei, g)); - int pos = get(get(edge_index, g.root()), g.local_to_global(*ei)); - if ( edge_marker[pos] ) { - edge_marker[pos] = false; - out << escape_dot_string(get(vertex_id, u)) << " " << Traits::delimiter() - << " " << escape_dot_string(get(vertex_id, v)); - make_edge_attributes_writer(g)(out, *ei); //print edge properties - out << ";" << std::endl; - } - } - out << "}" << std::endl; - } - } // namespace detail - - // requires graph_name graph property - template <typename Graph> - void write_graphviz(std::ostream& out, const subgraph<Graph>& g) { - std::vector<bool> edge_marker(num_edges(g), true); - std::vector<bool> vertex_marker(num_vertices(g), true); - - detail::write_graphviz_subgraph(out, g, - vertex_marker.begin(), - edge_marker.begin(), - get(vertex_index, g)); - } - - template <typename Graph> - void write_graphviz(const std::string& filename, const subgraph<Graph>& g) { - std::ofstream out(filename.c_str()); - std::vector<bool> edge_marker(num_edges(g), true); - std::vector<bool> vertex_marker(num_vertices(g), true); - - detail::write_graphviz_subgraph(out, g, - vertex_marker.begin(), - edge_marker.begin(), - get(vertex_index, g)); - } - - template <typename Graph, typename VertexID> - void write_graphviz(std::ostream& out, const subgraph<Graph>& g, - VertexID vertex_id) - { - std::vector<bool> edge_marker(num_edges(g), true); - std::vector<bool> vertex_marker(num_vertices(g), true); - - detail::write_graphviz_subgraph(out, g, - vertex_marker.begin(), - edge_marker.begin(), - vertex_id); - } - - template <typename Graph, typename VertexID> - void write_graphviz(const std::string& filename, const subgraph<Graph>& g, - VertexID vertex_id) - { +template < typename Graph, typename VertexID > +void write_graphviz( + const std::string& filename, const subgraph< Graph >& g, VertexID vertex_id) +{ std::ofstream out(filename.c_str()); - std::vector<bool> edge_marker(num_edges(g), true); - std::vector<bool> vertex_marker(num_vertices(g), true); + std::vector< bool > edge_marker(num_edges(g), true); + std::vector< bool > vertex_marker(num_vertices(g), true); - detail::write_graphviz_subgraph(out, g, - vertex_marker.begin(), - edge_marker.begin(), - vertex_id); - } + detail::write_graphviz_subgraph( + out, g, vertex_marker.begin(), edge_marker.begin(), vertex_id); +} #if 0 // This interface has not worked for a long time @@ -473,486 +484,549 @@ namespace boost { // Library has not existed for a while extern void read_graphviz(const std::string& file, GraphvizDigraph& g); extern void read_graphviz(FILE* file, GraphvizDigraph& g); - + extern void read_graphviz(const std::string& file, GraphvizGraph& g); extern void read_graphviz(FILE* file, GraphvizGraph& g); #endif - class dynamic_properties_writer - { - public: - dynamic_properties_writer(const dynamic_properties& dp) : dp(&dp) { } +class dynamic_properties_writer +{ +public: + dynamic_properties_writer(const dynamic_properties& dp) : dp(&dp) {} - template<typename Descriptor> + template < typename Descriptor > void operator()(std::ostream& out, Descriptor key) const { - bool first = true; - for (dynamic_properties::const_iterator i = dp->begin(); - i != dp->end(); ++i) { - if (typeid(key) == i->second->key()) { - if (first) out << " ["; - else out << ", "; - first = false; - - out << i->first << "=" << escape_dot_string(i->second->get_string(key)); + bool first = true; + for (dynamic_properties::const_iterator i = dp->begin(); i != dp->end(); + ++i) + { + if (typeid(key) == i->second->key()) + { + if (first) + out << " ["; + else + out << ", "; + first = false; + + out << i->first << "=" + << escape_dot_string(i->second->get_string(key)); + } } - } - if (!first) out << "]"; + if (!first) + out << "]"; } - private: +private: const dynamic_properties* dp; - }; +}; - class dynamic_vertex_properties_writer - { - public: - dynamic_vertex_properties_writer(const dynamic_properties& dp, - const std::string& node_id) - : dp(&dp), node_id(&node_id) { } +class dynamic_vertex_properties_writer +{ +public: + dynamic_vertex_properties_writer( + const dynamic_properties& dp, const std::string& node_id) + : dp(&dp), node_id(&node_id) + { + } - template<typename Descriptor> + template < typename Descriptor > void operator()(std::ostream& out, Descriptor key) const { - bool first = true; - for (dynamic_properties::const_iterator i = dp->begin(); - i != dp->end(); ++i) { - if (typeid(key) == i->second->key() - && i->first != *node_id) { - if (first) out << " ["; - else out << ", "; - first = false; - - out << i->first << "=" << escape_dot_string(i->second->get_string(key)); + bool first = true; + for (dynamic_properties::const_iterator i = dp->begin(); i != dp->end(); + ++i) + { + if (typeid(key) == i->second->key() && i->first != *node_id) + { + if (first) + out << " ["; + else + out << ", "; + first = false; + + out << i->first << "=" + << escape_dot_string(i->second->get_string(key)); + } } - } - if (!first) out << "]"; + if (!first) + out << "]"; } - private: +private: const dynamic_properties* dp; const std::string* node_id; - }; +}; - template <typename Graph> - class dynamic_graph_properties_writer - { - public: - dynamic_graph_properties_writer(const dynamic_properties& dp, const Graph& g) : g(&g), dp(&dp) { } +template < typename Graph > class dynamic_graph_properties_writer +{ +public: + dynamic_graph_properties_writer( + const dynamic_properties& dp, const Graph& g) + : g(&g), dp(&dp) + { + } void operator()(std::ostream& out) const { - for (dynamic_properties::const_iterator i = dp->begin(); - i != dp->end(); ++i) { - if (typeid(Graph*) == i->second->key()) { - // const_cast here is to match interface used in read_graphviz - out << i->first << "=" << escape_dot_string(i->second->get_string(const_cast<Graph*>(g))) << ";\n"; + for (dynamic_properties::const_iterator i = dp->begin(); i != dp->end(); + ++i) + { + if (typeid(Graph*) == i->second->key()) + { + // const_cast here is to match interface used in read_graphviz + out << i->first << "=" + << escape_dot_string( + i->second->get_string(const_cast< Graph* >(g))) + << ";\n"; + } } - } } - private: +private: const Graph* g; const dynamic_properties* dp; - }; - - namespace graph { namespace detail { +}; - template<typename Vertex> - struct node_id_property_map +namespace graph +{ + namespace detail { - typedef std::string value_type; - typedef value_type reference; - typedef Vertex key_type; - typedef readable_property_map_tag category; - - node_id_property_map() {} - - node_id_property_map(const dynamic_properties& dp, - const std::string& node_id) - : dp(&dp), node_id(&node_id) { } - - const dynamic_properties* dp; - const std::string* node_id; - }; - - template<typename Vertex> - inline std::string - get(node_id_property_map<Vertex> pm, - typename node_id_property_map<Vertex>::key_type v) - { return get(*pm.node_id, *pm.dp, v); } - - } } // end namespace graph::detail - - template<typename Graph> - inline void - write_graphviz_dp(std::ostream& out, const Graph& g, - const dynamic_properties& dp, - const std::string& node_id = "node_id" - BOOST_GRAPH_ENABLE_IF_MODELS_PARM(Graph,vertex_list_graph_tag)) - { - typedef typename graph_traits<Graph>::vertex_descriptor Vertex; + + template < typename Vertex > struct node_id_property_map + { + typedef std::string value_type; + typedef value_type reference; + typedef Vertex key_type; + typedef readable_property_map_tag category; + + node_id_property_map() {} + + node_id_property_map( + const dynamic_properties& dp, const std::string& node_id) + : dp(&dp), node_id(&node_id) + { + } + + const dynamic_properties* dp; + const std::string* node_id; + }; + + template < typename Vertex > + inline std::string get(node_id_property_map< Vertex > pm, + typename node_id_property_map< Vertex >::key_type v) + { + return get(*pm.node_id, *pm.dp, v); + } + + } +} // end namespace graph::detail + +template < typename Graph > +inline void write_graphviz_dp(std::ostream& out, const Graph& g, + const dynamic_properties& dp, + const std::string& node_id + = "node_id" BOOST_GRAPH_ENABLE_IF_MODELS_PARM(Graph, vertex_list_graph_tag)) +{ + typedef typename graph_traits< Graph >::vertex_descriptor Vertex; write_graphviz_dp(out, g, dp, node_id, - graph::detail::node_id_property_map<Vertex>(dp, node_id)); - } - - template<typename Graph, typename VertexID> - void - write_graphviz_dp(std::ostream& out, const Graph& g, - const dynamic_properties& dp, const std::string& node_id, - VertexID id - BOOST_GRAPH_ENABLE_IF_MODELS_PARM(Graph,vertex_list_graph_tag)) - { - write_graphviz - (out, g, - /*vertex_writer=*/dynamic_vertex_properties_writer(dp, node_id), - /*edge_writer=*/dynamic_properties_writer(dp), - /*graph_writer=*/dynamic_graph_properties_writer<Graph>(dp, g), - id); - } + graph::detail::node_id_property_map< Vertex >(dp, node_id)); +} + +template < typename Graph, typename VertexID > +void write_graphviz_dp(std::ostream& out, const Graph& g, + const dynamic_properties& dp, const std::string& node_id, + VertexID id BOOST_GRAPH_ENABLE_IF_MODELS_PARM(Graph, vertex_list_graph_tag)) +{ + write_graphviz(out, g, + /*vertex_writer=*/dynamic_vertex_properties_writer(dp, node_id), + /*edge_writer=*/dynamic_properties_writer(dp), + /*graph_writer=*/dynamic_graph_properties_writer< Graph >(dp, g), id); +} ///////////////////////////////////////////////////////////////////////////// // Graph reader exceptions ///////////////////////////////////////////////////////////////////////////// -struct graph_exception : public std::exception { - virtual ~graph_exception() {} - virtual const char* what() const noexcept = 0; +struct BOOST_SYMBOL_VISIBLE graph_exception : public std::exception +{ + ~graph_exception() BOOST_OVERRIDE {} + const char* what() const noexcept BOOST_OVERRIDE = 0; }; -struct bad_parallel_edge : public graph_exception { - std::string from; - std::string to; - mutable std::string statement; - bad_parallel_edge(const std::string& i, const std::string& j) : - from(i), to(j) {} - - virtual ~bad_parallel_edge() {} - const char* what() const noexcept { - if(statement.empty()) - statement = - std::string("Failed to add parallel edge: (") - + from + "," + to + ")\n"; - - return statement.c_str(); - } -}; +struct BOOST_SYMBOL_VISIBLE bad_parallel_edge : public graph_exception +{ + std::string from; + std::string to; + mutable std::string statement; + bad_parallel_edge(const std::string& i, const std::string& j) + : from(i), to(j) + { + } -struct directed_graph_error : public graph_exception { - virtual ~directed_graph_error() {} - virtual const char* what() const noexcept { - return - "read_graphviz: " - "Tried to read a directed graph into an undirected graph."; - } -}; + ~bad_parallel_edge() BOOST_OVERRIDE {} + const char* what() const noexcept BOOST_OVERRIDE + { + if (statement.empty()) + statement = std::string("Failed to add parallel edge: (") + from + + "," + to + ")\n"; -struct undirected_graph_error : public graph_exception { - virtual ~undirected_graph_error() {} - virtual const char* what() const noexcept { - return - "read_graphviz: " - "Tried to read an undirected graph into a directed graph."; - } + return statement.c_str(); + } }; -struct bad_graphviz_syntax: public graph_exception { - std::string errmsg; - bad_graphviz_syntax(const std::string& errmsg) - : errmsg(errmsg) {} - const char* what() const noexcept {return errmsg.c_str();} - ~bad_graphviz_syntax() {}; +struct BOOST_SYMBOL_VISIBLE directed_graph_error : public graph_exception +{ + ~directed_graph_error() BOOST_OVERRIDE {} + const char* what() const noexcept BOOST_OVERRIDE + { + return "read_graphviz: " + "Tried to read a directed graph into an undirected graph."; + } }; -namespace detail { namespace graph { - -typedef std::string id_t; -typedef id_t node_t; - -// edges are not uniquely determined by adjacent nodes -class edge_t { - int idx_; - explicit edge_t(int i) : idx_(i) {} -public: - static edge_t new_edge() { - static int idx = 0; - return edge_t(idx++); - }; - - bool operator==(const edge_t& rhs) const { - return idx_ == rhs.idx_; - } - bool operator<(const edge_t& rhs) const { - return idx_ < rhs.idx_; - } +struct BOOST_SYMBOL_VISIBLE undirected_graph_error : public graph_exception +{ + ~undirected_graph_error() BOOST_OVERRIDE {} + const char* what() const noexcept BOOST_OVERRIDE + { + return "read_graphviz: " + "Tried to read an undirected graph into a directed graph."; + } }; -class mutate_graph +struct BOOST_SYMBOL_VISIBLE bad_graphviz_syntax : public graph_exception { - public: - virtual ~mutate_graph() {} - virtual bool is_directed() const = 0; - virtual void do_add_vertex(const node_t& node) = 0; - - virtual void - do_add_edge(const edge_t& edge, const node_t& source, const node_t& target) - = 0; - - virtual void - set_node_property(const id_t& key, const node_t& node, const id_t& value) = 0; - - virtual void - set_edge_property(const id_t& key, const edge_t& edge, const id_t& value) = 0; - - virtual void // RG: need new second parameter to support BGL subgraphs - set_graph_property(const id_t& key, const id_t& value) = 0; - - virtual void - finish_building_graph() = 0; + std::string errmsg; + bad_graphviz_syntax(const std::string& errmsg) : errmsg(errmsg) {} + const char* what() const noexcept BOOST_OVERRIDE { return errmsg.c_str(); } + ~bad_graphviz_syntax() BOOST_OVERRIDE {} }; -template<typename MutableGraph> -class mutate_graph_impl : public mutate_graph -{ - typedef typename graph_traits<MutableGraph>::vertex_descriptor bgl_vertex_t; - typedef typename graph_traits<MutableGraph>::edge_descriptor bgl_edge_t; - - public: - mutate_graph_impl(MutableGraph& graph, dynamic_properties& dp, - std::string node_id_prop) - : graph_(graph), dp_(dp), node_id_prop_(node_id_prop) { } - - ~mutate_graph_impl() {} - - bool is_directed() const - { - return - boost::is_convertible< - typename boost::graph_traits<MutableGraph>::directed_category, - boost::directed_tag>::value; - } - - virtual void do_add_vertex(const node_t& node) - { - // Add the node to the graph. - bgl_vertex_t v = add_vertex(graph_); - - // Set up a mapping from name to BGL vertex. - bgl_nodes.insert(std::make_pair(node, v)); - - // node_id_prop_ allows the caller to see the real id names for nodes. - put(node_id_prop_, dp_, v, node); - } - - void - do_add_edge(const edge_t& edge, const node_t& source, const node_t& target) - { - std::pair<bgl_edge_t, bool> result = - add_edge(bgl_nodes[source], bgl_nodes[target], graph_); - - if(!result.second) { - // In the case of no parallel edges allowed - boost::throw_exception(bad_parallel_edge(source, target)); - } else { - bgl_edges.insert(std::make_pair(edge, result.first)); - } - } - - void - set_node_property(const id_t& key, const node_t& node, const id_t& value) - { - put(key, dp_, bgl_nodes[node], value); - } - - void - set_edge_property(const id_t& key, const edge_t& edge, const id_t& value) - { - put(key, dp_, bgl_edges[edge], value); - } - - void - set_graph_property(const id_t& key, const id_t& value) - { - /* RG: pointer to graph prevents copying */ - put(key, dp_, &graph_, value); - } - - void finish_building_graph() {} - - - protected: - MutableGraph& graph_; - dynamic_properties& dp_; - std::string node_id_prop_; - std::map<node_t, bgl_vertex_t> bgl_nodes; - std::map<edge_t, bgl_edge_t> bgl_edges; -}; +namespace detail +{ + namespace graph + { -template<typename Directed, - typename VertexProperty, - typename EdgeProperty, - typename GraphProperty, - typename Vertex, - typename EdgeIndex> -class mutate_graph_impl<compressed_sparse_row_graph<Directed, VertexProperty, EdgeProperty, GraphProperty, Vertex, EdgeIndex> > - : public mutate_graph -{ - typedef compressed_sparse_row_graph<Directed, VertexProperty, EdgeProperty, GraphProperty, Vertex, EdgeIndex> CSRGraph; - typedef typename graph_traits<CSRGraph>::vertices_size_type bgl_vertex_t; - typedef typename graph_traits<CSRGraph>::edges_size_type bgl_edge_t; - typedef typename graph_traits<CSRGraph>::edge_descriptor edge_descriptor; - - public: - mutate_graph_impl(CSRGraph& graph, dynamic_properties& dp, - std::string node_id_prop) - : graph_(graph), dp_(dp), vertex_count(0), node_id_prop_(node_id_prop) { } - - ~mutate_graph_impl() {} - - void finish_building_graph() { - typedef compressed_sparse_row_graph<directedS, no_property, bgl_edge_t, GraphProperty, Vertex, EdgeIndex> TempCSRGraph; - TempCSRGraph temp(edges_are_unsorted_multi_pass, - edges_to_add.begin(), edges_to_add.end(), - counting_iterator<bgl_edge_t>(0), - vertex_count); - set_property(temp, graph_all, get_property(graph_, graph_all)); - graph_.assign(temp); // Copies structure, not properties - std::vector<edge_descriptor> edge_permutation_from_sorting(num_edges(temp)); - BGL_FORALL_EDGES_T(e, temp, TempCSRGraph) { - edge_permutation_from_sorting[temp[e]] = e; - } - typedef boost::tuple<id_t, bgl_vertex_t, id_t> v_prop; - BOOST_FOREACH(const v_prop& t, vertex_props) { - put(boost::get<0>(t), dp_, boost::get<1>(t), boost::get<2>(t)); - } - typedef boost::tuple<id_t, bgl_edge_t, id_t> e_prop; - BOOST_FOREACH(const e_prop& t, edge_props) { - put(boost::get<0>(t), dp_, edge_permutation_from_sorting[boost::get<1>(t)], boost::get<2>(t)); - } - } - - bool is_directed() const - { - return - boost::is_convertible< - typename boost::graph_traits<CSRGraph>::directed_category, - boost::directed_tag>::value; - } - - virtual void do_add_vertex(const node_t& node) - { - // Add the node to the graph. - bgl_vertex_t v = vertex_count++; - - // Set up a mapping from name to BGL vertex. - bgl_nodes.insert(std::make_pair(node, v)); - - // node_id_prop_ allows the caller to see the real id names for nodes. - vertex_props.push_back(boost::make_tuple(node_id_prop_, v, node)); - } - - void - do_add_edge(const edge_t& edge, const node_t& source, const node_t& target) - { - bgl_edge_t result = edges_to_add.size(); - edges_to_add.push_back(std::make_pair(bgl_nodes[source], bgl_nodes[target])); - bgl_edges.insert(std::make_pair(edge, result)); - } - - void - set_node_property(const id_t& key, const node_t& node, const id_t& value) - { - vertex_props.push_back(boost::make_tuple(key, bgl_nodes[node], value)); - } - - void - set_edge_property(const id_t& key, const edge_t& edge, const id_t& value) - { - edge_props.push_back(boost::make_tuple(key, bgl_edges[edge], value)); - } - - void - set_graph_property(const id_t& key, const id_t& value) - { - /* RG: pointer to graph prevents copying */ - put(key, dp_, &graph_, value); - } - - - protected: - CSRGraph& graph_; - dynamic_properties& dp_; - bgl_vertex_t vertex_count; - std::string node_id_prop_; - std::vector<boost::tuple<id_t, bgl_vertex_t, id_t> > vertex_props; - std::vector<boost::tuple<id_t, bgl_edge_t, id_t> > edge_props; - std::vector<std::pair<bgl_vertex_t, bgl_vertex_t> > edges_to_add; - std::map<node_t, bgl_vertex_t> bgl_nodes; - std::map<edge_t, bgl_edge_t> bgl_edges; -}; + typedef std::string id_t; + typedef id_t node_t; + + // edges are not uniquely determined by adjacent nodes + class edge_t + { + int idx_; + explicit edge_t(int i) : idx_(i) {} + + public: + static edge_t new_edge() + { + static int idx = 0; + return edge_t(idx++); + } + + bool operator==(const edge_t& rhs) const + { + return idx_ == rhs.idx_; + } + bool operator<(const edge_t& rhs) const { return idx_ < rhs.idx_; } + }; + + class mutate_graph + { + public: + virtual ~mutate_graph() {} + virtual bool is_directed() const = 0; + virtual void do_add_vertex(const node_t& node) = 0; + + virtual void do_add_edge( + const edge_t& edge, const node_t& source, const node_t& target) + = 0; + + virtual void set_node_property( + const id_t& key, const node_t& node, const id_t& value) + = 0; + + virtual void set_edge_property( + const id_t& key, const edge_t& edge, const id_t& value) + = 0; + + virtual void // RG: need new second parameter to support BGL + // subgraphs + set_graph_property(const id_t& key, const id_t& value) + = 0; + + virtual void finish_building_graph() = 0; + }; + + template < typename MutableGraph > + class mutate_graph_impl : public mutate_graph + { + typedef typename graph_traits< MutableGraph >::vertex_descriptor + bgl_vertex_t; + typedef typename graph_traits< MutableGraph >::edge_descriptor + bgl_edge_t; + + public: + mutate_graph_impl(MutableGraph& graph, dynamic_properties& dp, + std::string node_id_prop) + : graph_(graph), dp_(dp), node_id_prop_(node_id_prop) + { + } + + ~mutate_graph_impl() BOOST_OVERRIDE {} + + bool is_directed() const BOOST_OVERRIDE + { + return boost::is_convertible< + typename boost::graph_traits< + MutableGraph >::directed_category, + boost::directed_tag >::value; + } + + void do_add_vertex(const node_t& node) BOOST_OVERRIDE + { + // Add the node to the graph. + bgl_vertex_t v = add_vertex(graph_); + + // Set up a mapping from name to BGL vertex. + bgl_nodes.insert(std::make_pair(node, v)); + + // node_id_prop_ allows the caller to see the real id names for + // nodes. + put(node_id_prop_, dp_, v, node); + } + + void do_add_edge(const edge_t& edge, const node_t& source, + const node_t& target) BOOST_OVERRIDE + { + std::pair< bgl_edge_t, bool > result + = add_edge(bgl_nodes[source], bgl_nodes[target], graph_); + + if (!result.second) + { + // In the case of no parallel edges allowed + boost::throw_exception(bad_parallel_edge(source, target)); + } + else + { + bgl_edges.insert(std::make_pair(edge, result.first)); + } + } + + void set_node_property(const id_t& key, const node_t& node, + const id_t& value) BOOST_OVERRIDE + { + put(key, dp_, bgl_nodes[node], value); + } + + void set_edge_property(const id_t& key, const edge_t& edge, + const id_t& value) BOOST_OVERRIDE + { + put(key, dp_, bgl_edges[edge], value); + } + + void set_graph_property(const id_t& key, + const id_t& value) BOOST_OVERRIDE + { + /* RG: pointer to graph prevents copying */ + put(key, dp_, &graph_, value); + } + + void finish_building_graph() BOOST_OVERRIDE {} + + protected: + MutableGraph& graph_; + dynamic_properties& dp_; + std::string node_id_prop_; + std::map< node_t, bgl_vertex_t > bgl_nodes; + std::map< edge_t, bgl_edge_t > bgl_edges; + }; + + template < typename Directed, typename VertexProperty, + typename EdgeProperty, typename GraphProperty, typename Vertex, + typename EdgeIndex > + class mutate_graph_impl< compressed_sparse_row_graph< Directed, + VertexProperty, EdgeProperty, GraphProperty, Vertex, EdgeIndex > > + : public mutate_graph + { + typedef compressed_sparse_row_graph< Directed, VertexProperty, + EdgeProperty, GraphProperty, Vertex, EdgeIndex > + CSRGraph; + typedef typename graph_traits< CSRGraph >::vertices_size_type + bgl_vertex_t; + typedef + typename graph_traits< CSRGraph >::edges_size_type bgl_edge_t; + typedef typename graph_traits< CSRGraph >::edge_descriptor + edge_descriptor; + + public: + mutate_graph_impl(CSRGraph& graph, dynamic_properties& dp, + std::string node_id_prop) + : graph_(graph) + , dp_(dp) + , vertex_count(0) + , node_id_prop_(node_id_prop) + { + } + + ~mutate_graph_impl() BOOST_OVERRIDE {} + + void finish_building_graph() BOOST_OVERRIDE + { + typedef compressed_sparse_row_graph< directedS, no_property, + bgl_edge_t, GraphProperty, Vertex, EdgeIndex > + TempCSRGraph; + TempCSRGraph temp(edges_are_unsorted_multi_pass, + edges_to_add.begin(), edges_to_add.end(), + counting_iterator< bgl_edge_t >(0), vertex_count); + set_property(temp, graph_all, get_property(graph_, graph_all)); + graph_.assign(temp); // Copies structure, not properties + std::vector< edge_descriptor > edge_permutation_from_sorting( + num_edges(temp)); + BGL_FORALL_EDGES_T(e, temp, TempCSRGraph) + { + edge_permutation_from_sorting[temp[e]] = e; + } + typedef boost::tuple< id_t, bgl_vertex_t, id_t > v_prop; + BOOST_FOREACH (const v_prop& t, vertex_props) + { + put(boost::get< 0 >(t), dp_, boost::get< 1 >(t), + boost::get< 2 >(t)); + } + typedef boost::tuple< id_t, bgl_edge_t, id_t > e_prop; + BOOST_FOREACH (const e_prop& t, edge_props) + { + put(boost::get< 0 >(t), dp_, + edge_permutation_from_sorting[boost::get< 1 >(t)], + boost::get< 2 >(t)); + } + } + + bool is_directed() const BOOST_OVERRIDE + { + return boost::is_convertible< + typename boost::graph_traits< CSRGraph >::directed_category, + boost::directed_tag >::value; + } + + void do_add_vertex(const node_t& node) BOOST_OVERRIDE + { + // Add the node to the graph. + bgl_vertex_t v = vertex_count++; + + // Set up a mapping from name to BGL vertex. + bgl_nodes.insert(std::make_pair(node, v)); + + // node_id_prop_ allows the caller to see the real id names for + // nodes. + vertex_props.push_back( + boost::make_tuple(node_id_prop_, v, node)); + } + + void do_add_edge(const edge_t& edge, const node_t& source, + const node_t& target) BOOST_OVERRIDE + { + bgl_edge_t result = edges_to_add.size(); + edges_to_add.push_back( + std::make_pair(bgl_nodes[source], bgl_nodes[target])); + bgl_edges.insert(std::make_pair(edge, result)); + } + + void set_node_property(const id_t& key, const node_t& node, + const id_t& value) BOOST_OVERRIDE + { + vertex_props.push_back( + boost::make_tuple(key, bgl_nodes[node], value)); + } + + void set_edge_property(const id_t& key, const edge_t& edge, + const id_t& value) BOOST_OVERRIDE + { + edge_props.push_back( + boost::make_tuple(key, bgl_edges[edge], value)); + } + + void set_graph_property(const id_t& key, + const id_t& value) BOOST_OVERRIDE + { + /* RG: pointer to graph prevents copying */ + put(key, dp_, &graph_, value); + } + + protected: + CSRGraph& graph_; + dynamic_properties& dp_; + bgl_vertex_t vertex_count; + std::string node_id_prop_; + std::vector< boost::tuple< id_t, bgl_vertex_t, id_t > > + vertex_props; + std::vector< boost::tuple< id_t, bgl_edge_t, id_t > > edge_props; + std::vector< std::pair< bgl_vertex_t, bgl_vertex_t > > edges_to_add; + std::map< node_t, bgl_vertex_t > bgl_nodes; + std::map< edge_t, bgl_edge_t > bgl_edges; + }; -} } } // end namespace boost::detail::graph + } +} +} // end namespace boost::detail::graph #ifdef BOOST_GRAPH_USE_SPIRIT_PARSER -# ifndef BOOST_GRAPH_READ_GRAPHVIZ_ITERATORS -# define BOOST_GRAPH_READ_GRAPHVIZ_ITERATORS -# endif -# include <boost/graph/detail/read_graphviz_spirit.hpp> +#ifndef BOOST_GRAPH_READ_GRAPHVIZ_ITERATORS +#define BOOST_GRAPH_READ_GRAPHVIZ_ITERATORS +#endif +#include <boost/graph/detail/read_graphviz_spirit.hpp> #else // New default parser -# include <boost/graph/detail/read_graphviz_new.hpp> +#include <boost/graph/detail/read_graphviz_new.hpp> #endif // BOOST_GRAPH_USE_SPIRIT_PARSER -namespace boost { +namespace boost +{ // Parse the passed string as a GraphViz dot file. -template <typename MutableGraph> -bool read_graphviz(const std::string& data, - MutableGraph& graph, - dynamic_properties& dp, - std::string const& node_id = "node_id") { +template < typename MutableGraph > +bool read_graphviz(const std::string& data, MutableGraph& graph, + dynamic_properties& dp, std::string const& node_id = "node_id") +{ #ifdef BOOST_GRAPH_USE_SPIRIT_PARSER - return read_graphviz_spirit(data.begin(), data.end(), graph, dp, node_id); + return read_graphviz_spirit(data.begin(), data.end(), graph, dp, node_id); #else // Non-Spirit parser - return read_graphviz_new(data,graph,dp,node_id); + return read_graphviz_new(data, graph, dp, node_id); #endif } // Parse the passed iterator range as a GraphViz dot file. -template <typename InputIterator, typename MutableGraph> -bool read_graphviz(InputIterator user_first, - InputIterator user_last, - MutableGraph& graph, - dynamic_properties& dp, - std::string const& node_id = "node_id") { +template < typename InputIterator, typename MutableGraph > +bool read_graphviz(InputIterator user_first, InputIterator user_last, + MutableGraph& graph, dynamic_properties& dp, + std::string const& node_id = "node_id") +{ #ifdef BOOST_GRAPH_USE_SPIRIT_PARSER - typedef InputIterator is_t; - typedef boost::spirit::classic::multi_pass<is_t> iterator_t; + typedef InputIterator is_t; + typedef boost::spirit::classic::multi_pass< is_t > iterator_t; - iterator_t first(boost::spirit::classic::make_multi_pass(user_first)); - iterator_t last(boost::spirit::classic::make_multi_pass(user_last)); + iterator_t first(boost::spirit::classic::make_multi_pass(user_first)); + iterator_t last(boost::spirit::classic::make_multi_pass(user_last)); - return read_graphviz_spirit(first, last, graph, dp, node_id); + return read_graphviz_spirit(first, last, graph, dp, node_id); #else // Non-Spirit parser - return read_graphviz_new(std::string(user_first, user_last), graph, dp, node_id); + return read_graphviz_new( + std::string(user_first, user_last), graph, dp, node_id); #endif } // Parse the passed stream as a GraphViz dot file. -template <typename MutableGraph> +template < typename MutableGraph > bool read_graphviz(std::istream& in, MutableGraph& graph, - dynamic_properties& dp, - std::string const& node_id = "node_id") + dynamic_properties& dp, std::string const& node_id = "node_id") { - typedef std::istream_iterator<char> is_t; - in >> std::noskipws; - return read_graphviz(is_t(in), is_t(), graph, dp, node_id); + typedef std::istream_iterator< char > is_t; + in >> std::noskipws; + return read_graphviz(is_t(in), is_t(), graph, dp, node_id); } } // namespace boost -#ifdef BOOST_GRAPH_USE_MPI -# error #include <boost/graph/distributed/graphviz.hpp> -#endif +#include BOOST_GRAPH_MPI_INCLUDE(<boost/graph/distributed/graphviz.hpp>) #endif // BOOST_GRAPHVIZ_HPP diff --git a/contrib/restricted/boost/graph/include/boost/graph/iteration_macros.hpp b/contrib/restricted/boost/graph/include/boost/graph/iteration_macros.hpp index 2bf40f9580..0b830315c2 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/iteration_macros.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/iteration_macros.hpp @@ -12,8 +12,8 @@ #include <utility> -#define BGL_CAT(x,y) x ## y -#define BGL_RANGE(linenum) BGL_CAT(bgl_range_,linenum) +#define BGL_CAT(x, y) x##y +#define BGL_RANGE(linenum) BGL_CAT(bgl_range_, linenum) #define BGL_FIRST(linenum) (BGL_RANGE(linenum).first) #define BGL_LAST(linenum) (BGL_RANGE(linenum).second) @@ -21,7 +21,7 @@ BGL_FORALL_VERTICES_T(v, g, graph_t) // This is on line 9 expands to the following, but all on the same line - for (typename boost::graph_traits<graph_t>::vertex_iterator + for (typename boost::graph_traits<graph_t>::vertex_iterator bgl_first_9 = vertices(g).first, bgl_last_9 = vertices(g).second; bgl_first_9 != bgl_last_9; bgl_first_9 = bgl_last_9) for (typename boost::graph_traits<graph_t>::vertex_descriptor v; @@ -39,102 +39,158 @@ Use the _T versions when the graph type is a template parameter or dependent on a template parameter. Otherwise use the non _T versions. - + ----------------------- 6/9/09 THK - + The above contains two calls to the vertices function. I modified these macros to expand to - + for (std::pair<typename boost::graph_traits<graph_t>::vertex_iterator, - typename boost::graph_traits<graph_t>::vertex_iterator> bgl_range_9 = vertices(g); - bgl_range_9.first != bgl_range_9.second; + typename boost::graph_traits<graph_t>::vertex_iterator> + bgl_range_9 = vertices(g); bgl_range_9.first != bgl_range_9.second; bgl_range_9.first = bgl_range_9.second) for (typename boost::graph_traits<graph_t>::vertex_descriptor v; - bgl_range_9.first != bgl_range_9.second ? (v = *bgl_range_9.first, true) : false; + bgl_range_9.first != bgl_range_9.second ? (v = *bgl_range_9.first, + true) : false; ++bgl_range_9.first) - - */ + */ -#define BGL_FORALL_VERTICES_T(VNAME, GNAME, GraphType) \ -for (std::pair<typename boost::graph_traits<GraphType>::vertex_iterator, \ - typename boost::graph_traits<GraphType>::vertex_iterator> BGL_RANGE(__LINE__) = vertices(GNAME); \ - BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \ - for (typename boost::graph_traits<GraphType>::vertex_descriptor VNAME; \ - BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (VNAME = *BGL_FIRST(__LINE__), true):false; \ - ++BGL_FIRST(__LINE__)) - -#define BGL_FORALL_VERTICES(VNAME, GNAME, GraphType) \ -for (std::pair<boost::graph_traits<GraphType>::vertex_iterator, \ - boost::graph_traits<GraphType>::vertex_iterator> BGL_RANGE(__LINE__) = vertices(GNAME); \ - BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \ - for (boost::graph_traits<GraphType>::vertex_descriptor VNAME; \ - BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (VNAME = *BGL_FIRST(__LINE__), true):false; \ - ++BGL_FIRST(__LINE__)) - -#define BGL_FORALL_EDGES_T(ENAME, GNAME, GraphType) \ -for (std::pair<typename boost::graph_traits<GraphType>::edge_iterator, \ - typename boost::graph_traits<GraphType>::edge_iterator> BGL_RANGE(__LINE__) = edges(GNAME); \ - BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \ - for (typename boost::graph_traits<GraphType>::edge_descriptor ENAME; \ - BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (ENAME = *BGL_FIRST(__LINE__), true):false; \ - ++BGL_FIRST(__LINE__)) - -#define BGL_FORALL_EDGES(ENAME, GNAME, GraphType) \ -for (std::pair<boost::graph_traits<GraphType>::edge_iterator, \ - boost::graph_traits<GraphType>::edge_iterator> BGL_RANGE(__LINE__) = edges(GNAME); \ - BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \ - for (boost::graph_traits<GraphType>::edge_descriptor ENAME; \ - BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (ENAME = *BGL_FIRST(__LINE__), true):false; \ - ++BGL_FIRST(__LINE__)) - -#define BGL_FORALL_ADJ_T(UNAME, VNAME, GNAME, GraphType) \ -for (std::pair<typename boost::graph_traits<GraphType>::adjacency_iterator, \ - typename boost::graph_traits<GraphType>::adjacency_iterator> BGL_RANGE(__LINE__) = adjacent_vertices(UNAME, GNAME); \ - BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \ -for (typename boost::graph_traits<GraphType>::vertex_descriptor VNAME; \ - BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (VNAME = *BGL_FIRST(__LINE__), true) : false; \ - ++BGL_FIRST(__LINE__)) - -#define BGL_FORALL_ADJ(UNAME, VNAME, GNAME, GraphType) \ -for (std::pair<boost::graph_traits<GraphType>::adjacency_iterator, \ - boost::graph_traits<GraphType>::adjacency_iterator> BGL_RANGE(__LINE__) = adjacent_vertices(UNAME, GNAME); \ - BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \ -for (boost::graph_traits<GraphType>::vertex_descriptor VNAME; \ - BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (VNAME = *BGL_FIRST(__LINE__), true) : false; \ - ++BGL_FIRST(__LINE__)) - -#define BGL_FORALL_OUTEDGES_T(UNAME, ENAME, GNAME, GraphType) \ -for (std::pair<typename boost::graph_traits<GraphType>::out_edge_iterator, \ - typename boost::graph_traits<GraphType>::out_edge_iterator> BGL_RANGE(__LINE__) = out_edges(UNAME, GNAME); \ - BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \ -for (typename boost::graph_traits<GraphType>::edge_descriptor ENAME; \ - BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (ENAME = *BGL_FIRST(__LINE__), true) : false; \ - ++BGL_FIRST(__LINE__)) - -#define BGL_FORALL_OUTEDGES(UNAME, ENAME, GNAME, GraphType) \ -for (std::pair<boost::graph_traits<GraphType>::out_edge_iterator, \ - boost::graph_traits<GraphType>::out_edge_iterator> BGL_RANGE(__LINE__) = out_edges(UNAME, GNAME); \ - BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \ -for (boost::graph_traits<GraphType>::edge_descriptor ENAME; \ - BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (ENAME = *BGL_FIRST(__LINE__), true) : false; \ - ++BGL_FIRST(__LINE__)) - -#define BGL_FORALL_INEDGES_T(UNAME, ENAME, GNAME, GraphType) \ -for (std::pair<typename boost::graph_traits<GraphType>::in_edge_iterator, \ - typename boost::graph_traits<GraphType>::in_edge_iterator> BGL_RANGE(__LINE__) = in_edges(UNAME, GNAME); \ - BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \ -for (typename boost::graph_traits<GraphType>::edge_descriptor ENAME; \ - BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (ENAME = *BGL_FIRST(__LINE__), true) : false; \ - ++BGL_FIRST(__LINE__)) - -#define BGL_FORALL_INEDGES(UNAME, ENAME, GNAME, GraphType) \ -for (std::pair<boost::graph_traits<GraphType>::in_edge_iterator, \ - boost::graph_traits<GraphType>::in_edge_iterator> BGL_RANGE(__LINE__) = in_edges(UNAME, GNAME); \ - BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \ -for (boost::graph_traits<GraphType>::edge_descriptor ENAME; \ - BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) ? (ENAME = *BGL_FIRST(__LINE__), true) : false; \ - ++BGL_FIRST(__LINE__)) +#define BGL_FORALL_VERTICES_T(VNAME, GNAME, GraphType) \ + for (std::pair< \ + typename boost::graph_traits< GraphType >::vertex_iterator, \ + typename boost::graph_traits< GraphType >::vertex_iterator > \ + BGL_RANGE(__LINE__) \ + = vertices(GNAME); \ + BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); \ + BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \ + for (typename boost::graph_traits< GraphType >::vertex_descriptor \ + VNAME; \ + BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) \ + ? (VNAME = *BGL_FIRST(__LINE__), true) \ + : false; \ + ++BGL_FIRST(__LINE__)) + +#define BGL_FORALL_VERTICES(VNAME, GNAME, GraphType) \ + for (std::pair< boost::graph_traits< GraphType >::vertex_iterator, \ + boost::graph_traits< GraphType >::vertex_iterator > \ + BGL_RANGE(__LINE__) \ + = vertices(GNAME); \ + BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); \ + BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \ + for (boost::graph_traits< GraphType >::vertex_descriptor VNAME; \ + BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) \ + ? (VNAME = *BGL_FIRST(__LINE__), true) \ + : false; \ + ++BGL_FIRST(__LINE__)) + +#define BGL_FORALL_EDGES_T(ENAME, GNAME, GraphType) \ + for (std::pair< typename boost::graph_traits< GraphType >::edge_iterator, \ + typename boost::graph_traits< GraphType >::edge_iterator > \ + BGL_RANGE(__LINE__) \ + = edges(GNAME); \ + BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); \ + BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \ + for (typename boost::graph_traits< GraphType >::edge_descriptor ENAME; \ + BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) \ + ? (ENAME = *BGL_FIRST(__LINE__), true) \ + : false; \ + ++BGL_FIRST(__LINE__)) + +#define BGL_FORALL_EDGES(ENAME, GNAME, GraphType) \ + for (std::pair< boost::graph_traits< GraphType >::edge_iterator, \ + boost::graph_traits< GraphType >::edge_iterator > \ + BGL_RANGE(__LINE__) \ + = edges(GNAME); \ + BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); \ + BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \ + for (boost::graph_traits< GraphType >::edge_descriptor ENAME; \ + BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) \ + ? (ENAME = *BGL_FIRST(__LINE__), true) \ + : false; \ + ++BGL_FIRST(__LINE__)) + +#define BGL_FORALL_ADJ_T(UNAME, VNAME, GNAME, GraphType) \ + for (std::pair< \ + typename boost::graph_traits< GraphType >::adjacency_iterator, \ + typename boost::graph_traits< GraphType >::adjacency_iterator > \ + BGL_RANGE(__LINE__) \ + = adjacent_vertices(UNAME, GNAME); \ + BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); \ + BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \ + for (typename boost::graph_traits< GraphType >::vertex_descriptor \ + VNAME; \ + BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) \ + ? (VNAME = *BGL_FIRST(__LINE__), true) \ + : false; \ + ++BGL_FIRST(__LINE__)) + +#define BGL_FORALL_ADJ(UNAME, VNAME, GNAME, GraphType) \ + for (std::pair< boost::graph_traits< GraphType >::adjacency_iterator, \ + boost::graph_traits< GraphType >::adjacency_iterator > \ + BGL_RANGE(__LINE__) \ + = adjacent_vertices(UNAME, GNAME); \ + BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); \ + BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \ + for (boost::graph_traits< GraphType >::vertex_descriptor VNAME; \ + BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) \ + ? (VNAME = *BGL_FIRST(__LINE__), true) \ + : false; \ + ++BGL_FIRST(__LINE__)) + +#define BGL_FORALL_OUTEDGES_T(UNAME, ENAME, GNAME, GraphType) \ + for (std::pair< \ + typename boost::graph_traits< GraphType >::out_edge_iterator, \ + typename boost::graph_traits< GraphType >::out_edge_iterator > \ + BGL_RANGE(__LINE__) \ + = out_edges(UNAME, GNAME); \ + BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); \ + BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \ + for (typename boost::graph_traits< GraphType >::edge_descriptor ENAME; \ + BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) \ + ? (ENAME = *BGL_FIRST(__LINE__), true) \ + : false; \ + ++BGL_FIRST(__LINE__)) + +#define BGL_FORALL_OUTEDGES(UNAME, ENAME, GNAME, GraphType) \ + for (std::pair< boost::graph_traits< GraphType >::out_edge_iterator, \ + boost::graph_traits< GraphType >::out_edge_iterator > \ + BGL_RANGE(__LINE__) \ + = out_edges(UNAME, GNAME); \ + BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); \ + BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \ + for (boost::graph_traits< GraphType >::edge_descriptor ENAME; \ + BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) \ + ? (ENAME = *BGL_FIRST(__LINE__), true) \ + : false; \ + ++BGL_FIRST(__LINE__)) + +#define BGL_FORALL_INEDGES_T(UNAME, ENAME, GNAME, GraphType) \ + for (std::pair< \ + typename boost::graph_traits< GraphType >::in_edge_iterator, \ + typename boost::graph_traits< GraphType >::in_edge_iterator > \ + BGL_RANGE(__LINE__) \ + = in_edges(UNAME, GNAME); \ + BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); \ + BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \ + for (typename boost::graph_traits< GraphType >::edge_descriptor ENAME; \ + BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) \ + ? (ENAME = *BGL_FIRST(__LINE__), true) \ + : false; \ + ++BGL_FIRST(__LINE__)) + +#define BGL_FORALL_INEDGES(UNAME, ENAME, GNAME, GraphType) \ + for (std::pair< boost::graph_traits< GraphType >::in_edge_iterator, \ + boost::graph_traits< GraphType >::in_edge_iterator > \ + BGL_RANGE(__LINE__) \ + = in_edges(UNAME, GNAME); \ + BGL_FIRST(__LINE__) != BGL_LAST(__LINE__); \ + BGL_FIRST(__LINE__) = BGL_LAST(__LINE__)) \ + for (boost::graph_traits< GraphType >::edge_descriptor ENAME; \ + BGL_FIRST(__LINE__) != BGL_LAST(__LINE__) \ + ? (ENAME = *BGL_FIRST(__LINE__), true) \ + : false; \ + ++BGL_FIRST(__LINE__)) #endif // BOOST_GRAPH_ITERATION_MACROS_HPP diff --git a/contrib/restricted/boost/graph/include/boost/graph/lookup_edge.hpp b/contrib/restricted/boost/graph/include/boost/graph/lookup_edge.hpp index f8ea89e22a..7c46cd1106 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/lookup_edge.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/lookup_edge.hpp @@ -18,32 +18,37 @@ // lookup_edge: a function that acts like edge() but falls back to out_edges() // and a search when edge() is not provided. -namespace boost { - - template <typename Graph> - std::pair<typename boost::graph_traits<Graph>::edge_descriptor, bool> - lookup_edge(typename boost::graph_traits<Graph>::vertex_descriptor src, - typename boost::graph_traits<Graph>::vertex_descriptor tgt, - const Graph& g, - typename boost::enable_if<is_adjacency_matrix<Graph>, int>::type = 0) { +namespace boost +{ + +template < typename Graph > +std::pair< typename boost::graph_traits< Graph >::edge_descriptor, bool > +lookup_edge(typename boost::graph_traits< Graph >::vertex_descriptor src, + typename boost::graph_traits< Graph >::vertex_descriptor tgt, + const Graph& g, + typename boost::enable_if< is_adjacency_matrix< Graph >, int >::type = 0) +{ return edge(src, tgt, g); - } - - template <typename Graph> - std::pair<typename boost::graph_traits<Graph>::edge_descriptor, bool> - lookup_edge(typename boost::graph_traits<Graph>::vertex_descriptor src, - typename boost::graph_traits<Graph>::vertex_descriptor tgt, - const Graph& g, - typename boost::disable_if<is_adjacency_matrix<Graph>, int>::type = 0) { - typedef typename boost::graph_traits<Graph>::out_edge_iterator it; - typedef typename boost::graph_traits<Graph>::edge_descriptor edesc; - std::pair<it, it> oe = out_edges(src, g); - for (; oe.first != oe.second; ++oe.first) { - edesc e = *oe.first; - if (target(e, g) == tgt) return std::make_pair(e, true); +} + +template < typename Graph > +std::pair< typename boost::graph_traits< Graph >::edge_descriptor, bool > +lookup_edge(typename boost::graph_traits< Graph >::vertex_descriptor src, + typename boost::graph_traits< Graph >::vertex_descriptor tgt, + const Graph& g, + typename boost::disable_if< is_adjacency_matrix< Graph >, int >::type = 0) +{ + typedef typename boost::graph_traits< Graph >::out_edge_iterator it; + typedef typename boost::graph_traits< Graph >::edge_descriptor edesc; + std::pair< it, it > oe = out_edges(src, g); + for (; oe.first != oe.second; ++oe.first) + { + edesc e = *oe.first; + if (target(e, g) == tgt) + return std::make_pair(e, true); } return std::make_pair(edesc(), false); - } +} } diff --git a/contrib/restricted/boost/graph/include/boost/graph/named_function_params.hpp b/contrib/restricted/boost/graph/include/boost/graph/named_function_params.hpp index a9a9add6c8..bfe5670f7c 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/named_function_params.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/named_function_params.hpp @@ -13,731 +13,989 @@ #include <functional> #include <vector> #include <boost/limits.hpp> -#include <boost/ref.hpp> +#include <boost/core/enable_if.hpp> +#include <boost/core/ref.hpp> #include <boost/utility/result_of.hpp> #include <boost/preprocessor.hpp> +#include <boost/parameter/is_argument_pack.hpp> #include <boost/parameter/name.hpp> #include <boost/parameter/binding.hpp> #include <boost/type_traits.hpp> -#include <boost/mpl/not.hpp> +#include <boost/mpl/bool.hpp> +#include <boost/mpl/has_key.hpp> #include <boost/graph/properties.hpp> #include <boost/graph/detail/d_ary_heap.hpp> #include <boost/property_map/property_map.hpp> #include <boost/property_map/shared_array_property_map.hpp> -namespace boost { - - struct parity_map_t { }; - struct vertex_assignment_map_t { }; - struct distance_compare_t { }; - struct distance_combine_t { }; - struct distance_inf_t { }; - struct distance_zero_t { }; - struct buffer_param_t { }; - struct edge_copy_t { }; - struct vertex_copy_t { }; - struct vertex_isomorphism_t { }; - struct vertex_invariant_t { }; - struct vertex_invariant1_t { }; - struct vertex_invariant2_t { }; - struct edge_compare_t { }; - struct vertex_max_invariant_t { }; - struct orig_to_copy_t { }; - struct root_vertex_t { }; - struct polling_t { }; - struct lookahead_t { }; - struct in_parallel_t { }; - struct attractive_force_t { }; - struct repulsive_force_t { }; - struct force_pairs_t { }; - struct cooling_t { }; - struct vertex_displacement_t { }; - struct iterations_t { }; - struct diameter_range_t { }; - struct learning_constant_range_t { }; - struct vertices_equivalent_t { }; - struct edges_equivalent_t { }; - struct index_in_heap_map_t { }; - struct max_priority_queue_t { }; - -#define BOOST_BGL_DECLARE_NAMED_PARAMS \ - BOOST_BGL_ONE_PARAM_CREF(weight_map, edge_weight) \ - BOOST_BGL_ONE_PARAM_CREF(weight_map2, edge_weight2) \ - BOOST_BGL_ONE_PARAM_CREF(distance_map, vertex_distance) \ - BOOST_BGL_ONE_PARAM_CREF(distance_map2, vertex_distance2) \ - BOOST_BGL_ONE_PARAM_CREF(predecessor_map, vertex_predecessor) \ - BOOST_BGL_ONE_PARAM_CREF(rank_map, vertex_rank) \ - BOOST_BGL_ONE_PARAM_CREF(root_map, vertex_root) \ - BOOST_BGL_ONE_PARAM_CREF(root_vertex, root_vertex) \ - BOOST_BGL_ONE_PARAM_CREF(edge_centrality_map, edge_centrality) \ - BOOST_BGL_ONE_PARAM_CREF(centrality_map, vertex_centrality) \ - BOOST_BGL_ONE_PARAM_CREF(parity_map, parity_map) \ - BOOST_BGL_ONE_PARAM_CREF(color_map, vertex_color) \ - BOOST_BGL_ONE_PARAM_CREF(edge_color_map, edge_color) \ - BOOST_BGL_ONE_PARAM_CREF(capacity_map, edge_capacity) \ - BOOST_BGL_ONE_PARAM_CREF(residual_capacity_map, edge_residual_capacity) \ - BOOST_BGL_ONE_PARAM_CREF(reverse_edge_map, edge_reverse) \ - BOOST_BGL_ONE_PARAM_CREF(discover_time_map, vertex_discover_time) \ - BOOST_BGL_ONE_PARAM_CREF(lowpoint_map, vertex_lowpoint) \ - BOOST_BGL_ONE_PARAM_CREF(vertex_index_map, vertex_index) \ - BOOST_BGL_ONE_PARAM_CREF(vertex_index1_map, vertex_index1) \ - BOOST_BGL_ONE_PARAM_CREF(vertex_index2_map, vertex_index2) \ - BOOST_BGL_ONE_PARAM_CREF(vertex_assignment_map, vertex_assignment_map) \ - BOOST_BGL_ONE_PARAM_CREF(visitor, graph_visitor) \ - BOOST_BGL_ONE_PARAM_CREF(distance_compare, distance_compare) \ - BOOST_BGL_ONE_PARAM_CREF(distance_combine, distance_combine) \ - BOOST_BGL_ONE_PARAM_CREF(distance_inf, distance_inf) \ - BOOST_BGL_ONE_PARAM_CREF(distance_zero, distance_zero) \ - BOOST_BGL_ONE_PARAM_CREF(edge_copy, edge_copy) \ - BOOST_BGL_ONE_PARAM_CREF(vertex_copy, vertex_copy) \ - BOOST_BGL_ONE_PARAM_REF(buffer, buffer_param) \ - BOOST_BGL_ONE_PARAM_CREF(orig_to_copy, orig_to_copy) \ - BOOST_BGL_ONE_PARAM_CREF(isomorphism_map, vertex_isomorphism) \ - BOOST_BGL_ONE_PARAM_CREF(vertex_invariant, vertex_invariant) \ - BOOST_BGL_ONE_PARAM_CREF(vertex_invariant1, vertex_invariant1) \ - BOOST_BGL_ONE_PARAM_CREF(vertex_invariant2, vertex_invariant2) \ - BOOST_BGL_ONE_PARAM_CREF(vertex_max_invariant, vertex_max_invariant) \ - BOOST_BGL_ONE_PARAM_CREF(polling, polling) \ - BOOST_BGL_ONE_PARAM_CREF(lookahead, lookahead) \ - BOOST_BGL_ONE_PARAM_CREF(in_parallel, in_parallel) \ - BOOST_BGL_ONE_PARAM_CREF(displacement_map, vertex_displacement) \ - BOOST_BGL_ONE_PARAM_CREF(attractive_force, attractive_force) \ - BOOST_BGL_ONE_PARAM_CREF(repulsive_force, repulsive_force) \ - BOOST_BGL_ONE_PARAM_CREF(force_pairs, force_pairs) \ - BOOST_BGL_ONE_PARAM_CREF(cooling, cooling) \ - BOOST_BGL_ONE_PARAM_CREF(iterations, iterations) \ - BOOST_BGL_ONE_PARAM_CREF(diameter_range, diameter_range) \ +namespace boost +{ + +struct parity_map_t +{ +}; +struct vertex_assignment_map_t +{ +}; +struct distance_compare_t +{ +}; +struct distance_combine_t +{ +}; +struct distance_inf_t +{ +}; +struct distance_zero_t +{ +}; +struct buffer_param_t +{ +}; +struct edge_copy_t +{ +}; +struct vertex_copy_t +{ +}; +struct vertex_isomorphism_t +{ +}; +struct vertex_invariant_t +{ +}; +struct vertex_invariant1_t +{ +}; +struct vertex_invariant2_t +{ +}; +struct edge_compare_t +{ +}; +struct vertex_max_invariant_t +{ +}; +struct orig_to_copy_t +{ +}; +struct root_vertex_t +{ +}; +struct polling_t +{ +}; +struct lookahead_t +{ +}; +struct in_parallel_t +{ +}; +struct attractive_force_t +{ +}; +struct repulsive_force_t +{ +}; +struct force_pairs_t +{ +}; +struct cooling_t +{ +}; +struct vertex_displacement_t +{ +}; +struct iterations_t +{ +}; +struct diameter_range_t +{ +}; +struct learning_constant_range_t +{ +}; +struct vertices_equivalent_t +{ +}; +struct edges_equivalent_t +{ +}; +struct index_in_heap_map_t +{ +}; +struct max_priority_queue_t +{ +}; + +#define BOOST_BGL_DECLARE_NAMED_PARAMS \ + BOOST_BGL_ONE_PARAM_CREF(weight_map, edge_weight) \ + BOOST_BGL_ONE_PARAM_CREF(weight_map2, edge_weight2) \ + BOOST_BGL_ONE_PARAM_CREF(distance_map, vertex_distance) \ + BOOST_BGL_ONE_PARAM_CREF(distance_map2, vertex_distance2) \ + BOOST_BGL_ONE_PARAM_CREF(predecessor_map, vertex_predecessor) \ + BOOST_BGL_ONE_PARAM_CREF(rank_map, vertex_rank) \ + BOOST_BGL_ONE_PARAM_CREF(root_map, vertex_root) \ + BOOST_BGL_ONE_PARAM_CREF(root_vertex, root_vertex) \ + BOOST_BGL_ONE_PARAM_CREF(edge_centrality_map, edge_centrality) \ + BOOST_BGL_ONE_PARAM_CREF(centrality_map, vertex_centrality) \ + BOOST_BGL_ONE_PARAM_CREF(parity_map, parity_map) \ + BOOST_BGL_ONE_PARAM_CREF(color_map, vertex_color) \ + BOOST_BGL_ONE_PARAM_CREF(edge_color_map, edge_color) \ + BOOST_BGL_ONE_PARAM_CREF(capacity_map, edge_capacity) \ + BOOST_BGL_ONE_PARAM_CREF(residual_capacity_map, edge_residual_capacity) \ + BOOST_BGL_ONE_PARAM_CREF(reverse_edge_map, edge_reverse) \ + BOOST_BGL_ONE_PARAM_CREF(discover_time_map, vertex_discover_time) \ + BOOST_BGL_ONE_PARAM_CREF(lowpoint_map, vertex_lowpoint) \ + BOOST_BGL_ONE_PARAM_CREF(vertex_index_map, vertex_index) \ + BOOST_BGL_ONE_PARAM_CREF(vertex_index1_map, vertex_index1) \ + BOOST_BGL_ONE_PARAM_CREF(vertex_index2_map, vertex_index2) \ + BOOST_BGL_ONE_PARAM_CREF(vertex_assignment_map, vertex_assignment_map) \ + BOOST_BGL_ONE_PARAM_CREF(visitor, graph_visitor) \ + BOOST_BGL_ONE_PARAM_CREF(distance_compare, distance_compare) \ + BOOST_BGL_ONE_PARAM_CREF(distance_combine, distance_combine) \ + BOOST_BGL_ONE_PARAM_CREF(distance_inf, distance_inf) \ + BOOST_BGL_ONE_PARAM_CREF(distance_zero, distance_zero) \ + BOOST_BGL_ONE_PARAM_CREF(edge_copy, edge_copy) \ + BOOST_BGL_ONE_PARAM_CREF(vertex_copy, vertex_copy) \ + BOOST_BGL_ONE_PARAM_REF(buffer, buffer_param) \ + BOOST_BGL_ONE_PARAM_CREF(orig_to_copy, orig_to_copy) \ + BOOST_BGL_ONE_PARAM_CREF(isomorphism_map, vertex_isomorphism) \ + BOOST_BGL_ONE_PARAM_CREF(vertex_invariant, vertex_invariant) \ + BOOST_BGL_ONE_PARAM_CREF(vertex_invariant1, vertex_invariant1) \ + BOOST_BGL_ONE_PARAM_CREF(vertex_invariant2, vertex_invariant2) \ + BOOST_BGL_ONE_PARAM_CREF(vertex_max_invariant, vertex_max_invariant) \ + BOOST_BGL_ONE_PARAM_CREF(polling, polling) \ + BOOST_BGL_ONE_PARAM_CREF(lookahead, lookahead) \ + BOOST_BGL_ONE_PARAM_CREF(in_parallel, in_parallel) \ + BOOST_BGL_ONE_PARAM_CREF(displacement_map, vertex_displacement) \ + BOOST_BGL_ONE_PARAM_CREF(attractive_force, attractive_force) \ + BOOST_BGL_ONE_PARAM_CREF(repulsive_force, repulsive_force) \ + BOOST_BGL_ONE_PARAM_CREF(force_pairs, force_pairs) \ + BOOST_BGL_ONE_PARAM_CREF(cooling, cooling) \ + BOOST_BGL_ONE_PARAM_CREF(iterations, iterations) \ + BOOST_BGL_ONE_PARAM_CREF(diameter_range, diameter_range) \ BOOST_BGL_ONE_PARAM_CREF(learning_constant_range, learning_constant_range) \ - BOOST_BGL_ONE_PARAM_CREF(vertices_equivalent, vertices_equivalent) \ - BOOST_BGL_ONE_PARAM_CREF(edges_equivalent, edges_equivalent) \ - BOOST_BGL_ONE_PARAM_CREF(index_in_heap_map, index_in_heap_map) \ + BOOST_BGL_ONE_PARAM_CREF(vertices_equivalent, vertices_equivalent) \ + BOOST_BGL_ONE_PARAM_CREF(edges_equivalent, edges_equivalent) \ + BOOST_BGL_ONE_PARAM_CREF(index_in_heap_map, index_in_heap_map) \ BOOST_BGL_ONE_PARAM_REF(max_priority_queue, max_priority_queue) - template <typename T, typename Tag, typename Base = no_property> - struct bgl_named_params - { +template < typename T, typename Tag, typename Base = no_property > +struct bgl_named_params +{ typedef bgl_named_params self; typedef Base next_type; typedef Tag tag_type; typedef T value_type; - bgl_named_params(T v = T()) : m_value(v) { } - bgl_named_params(T v, const Base& b) : m_value(v), m_base(b) { } + bgl_named_params(T v = T()) : m_value(v) {} + bgl_named_params(T v, const Base& b) : m_value(v), m_base(b) {} T m_value; Base m_base; -#define BOOST_BGL_ONE_PARAM_REF(name, key) \ - template <typename PType> \ - bgl_named_params<boost::reference_wrapper<PType>, BOOST_PP_CAT(key, _t), self> \ - name(PType& p) const { \ - typedef bgl_named_params<boost::reference_wrapper<PType>, BOOST_PP_CAT(key, _t), self> Params; \ - return Params(boost::ref(p), *this); \ - } \ - -#define BOOST_BGL_ONE_PARAM_CREF(name, key) \ - template <typename PType> \ - bgl_named_params<PType, BOOST_PP_CAT(key, _t), self> \ - name(const PType& p) const { \ - typedef bgl_named_params<PType, BOOST_PP_CAT(key, _t), self> Params; \ - return Params(p, *this); \ - } \ +#define BOOST_BGL_ONE_PARAM_REF(name, key) \ + template < typename PType > \ + bgl_named_params< boost::reference_wrapper< PType >, \ + BOOST_PP_CAT(key, _t), self > \ + name(PType& p) const \ + { \ + typedef bgl_named_params< boost::reference_wrapper< PType >, \ + BOOST_PP_CAT(key, _t), self > \ + Params; \ + return Params(boost::ref(p), *this); \ + } -BOOST_BGL_DECLARE_NAMED_PARAMS +#define BOOST_BGL_ONE_PARAM_CREF(name, key) \ + template < typename PType > \ + bgl_named_params< PType, BOOST_PP_CAT(key, _t), self > name( \ + const PType& p) const \ + { \ + typedef bgl_named_params< PType, BOOST_PP_CAT(key, _t), self > Params; \ + return Params(p, *this); \ + } + + BOOST_BGL_DECLARE_NAMED_PARAMS #undef BOOST_BGL_ONE_PARAM_REF #undef BOOST_BGL_ONE_PARAM_CREF // Duplicate - template <typename PType> - bgl_named_params<PType, vertex_color_t, self> - vertex_color_map(const PType& p) const {return this->color_map(p);} - }; - -#define BOOST_BGL_ONE_PARAM_REF(name, key) \ - template <typename PType> \ - bgl_named_params<boost::reference_wrapper<PType>, BOOST_PP_CAT(key, _t)> \ - name(PType& p) { \ - typedef bgl_named_params<boost::reference_wrapper<PType>, BOOST_PP_CAT(key, _t)> Params; \ - return Params(boost::ref(p)); \ - } \ - -#define BOOST_BGL_ONE_PARAM_CREF(name, key) \ - template <typename PType> \ - bgl_named_params<PType, BOOST_PP_CAT(key, _t)> \ - name(const PType& p) { \ - typedef bgl_named_params<PType, BOOST_PP_CAT(key, _t)> Params; \ - return Params(p); \ - } \ + template < typename PType > + bgl_named_params< PType, vertex_color_t, self > vertex_color_map( + const PType& p) const + { + return this->color_map(p); + } +}; + +#define BOOST_BGL_ONE_PARAM_REF(name, key) \ + template < typename PType > \ + bgl_named_params< boost::reference_wrapper< PType >, \ + BOOST_PP_CAT(key, _t) > \ + name(PType& p) \ + { \ + typedef bgl_named_params< boost::reference_wrapper< PType >, \ + BOOST_PP_CAT(key, _t) > \ + Params; \ + return Params(boost::ref(p)); \ + } + +#define BOOST_BGL_ONE_PARAM_CREF(name, key) \ + template < typename PType > \ + bgl_named_params< PType, BOOST_PP_CAT(key, _t) > name(const PType& p) \ + { \ + typedef bgl_named_params< PType, BOOST_PP_CAT(key, _t) > Params; \ + return Params(p); \ + } BOOST_BGL_DECLARE_NAMED_PARAMS #undef BOOST_BGL_ONE_PARAM_REF #undef BOOST_BGL_ONE_PARAM_CREF - // Duplicate - template <typename PType> - bgl_named_params<PType, vertex_color_t> - vertex_color_map(const PType& p) {return color_map(p);} +// Duplicate +template < typename PType > +bgl_named_params< PType, vertex_color_t > vertex_color_map(const PType& p) +{ + return color_map(p); +} - namespace detail { - struct unused_tag_type {}; - } - typedef bgl_named_params<char, detail::unused_tag_type> no_named_parameters; +namespace detail +{ + struct unused_tag_type + { + }; +} +typedef bgl_named_params< char, detail::unused_tag_type > no_named_parameters; - //=========================================================================== - // Functions for extracting parameters from bgl_named_params +//=========================================================================== +// Functions for extracting parameters from bgl_named_params - template <typename Tag, typename Args> - struct lookup_named_param {}; +template < typename Tag, typename Args > struct lookup_named_param +{ +}; - template <typename T, typename Tag, typename Base> - struct lookup_named_param<Tag, bgl_named_params<T, Tag, Base> > { +template < typename T, typename Tag, typename Base > +struct lookup_named_param< Tag, bgl_named_params< T, Tag, Base > > +{ typedef T type; - static const T& get(const bgl_named_params<T, Tag, Base>& p) { - return p.m_value; + static const T& get(const bgl_named_params< T, Tag, Base >& p) + { + return p.m_value; } - }; +}; - template <typename Tag1, typename T, typename Tag, typename Base> - struct lookup_named_param<Tag1, bgl_named_params<T, Tag, Base> > { - typedef typename lookup_named_param<Tag1, Base>::type type; - static const type& get(const bgl_named_params<T, Tag, Base>& p) { - return lookup_named_param<Tag1, Base>::get(p.m_base); +template < typename Tag1, typename T, typename Tag, typename Base > +struct lookup_named_param< Tag1, bgl_named_params< T, Tag, Base > > +{ + typedef typename lookup_named_param< Tag1, Base >::type type; + static const type& get(const bgl_named_params< T, Tag, Base >& p) + { + return lookup_named_param< Tag1, Base >::get(p.m_base); } - }; +}; - template <typename Tag, typename Args, typename Def> - struct lookup_named_param_def { +template < typename Tag, typename Args, typename Def > +struct lookup_named_param_def +{ typedef Def type; - static const Def& get(const Args&, const Def& def) {return def;} - }; + static const Def& get(const Args&, const Def& def) { return def; } +}; - template <typename T, typename Tag, typename Base, typename Def> - struct lookup_named_param_def<Tag, bgl_named_params<T, Tag, Base>, Def> { +template < typename T, typename Tag, typename Base, typename Def > +struct lookup_named_param_def< Tag, bgl_named_params< T, Tag, Base >, Def > +{ typedef T type; - static const type& get(const bgl_named_params<T, Tag, Base>& p, const Def&) { - return p.m_value; + static const type& get( + const bgl_named_params< T, Tag, Base >& p, const Def&) + { + return p.m_value; } - }; - - template <typename Tag1, typename T, typename Tag, typename Base, typename Def> - struct lookup_named_param_def<Tag1, bgl_named_params<T, Tag, Base>, Def> { - typedef typename lookup_named_param_def<Tag1, Base, Def>::type type; - static const type& get(const bgl_named_params<T, Tag, Base>& p, const Def& def) { - return lookup_named_param_def<Tag1, Base, Def>::get(p.m_base, def); +}; + +template < typename Tag1, typename T, typename Tag, typename Base, + typename Def > +struct lookup_named_param_def< Tag1, bgl_named_params< T, Tag, Base >, Def > +{ + typedef typename lookup_named_param_def< Tag1, Base, Def >::type type; + static const type& get( + const bgl_named_params< T, Tag, Base >& p, const Def& def) + { + return lookup_named_param_def< Tag1, Base, Def >::get(p.m_base, def); } - }; +}; + +struct param_not_found +{ +}; +static param_not_found g_param_not_found; + +template < typename Tag, typename Args > +struct get_param_type : lookup_named_param_def< Tag, Args, param_not_found > +{ +}; + +template < class Tag, typename Args > +inline const typename lookup_named_param_def< Tag, Args, + param_not_found >::type& +get_param(const Args& p, Tag) +{ + return lookup_named_param_def< Tag, Args, param_not_found >::get( + p, g_param_not_found); +} + +template < class P, class Default > +const P& choose_param(const P& param, const Default&) +{ + return param; +} - struct param_not_found {}; +template < class Default > +Default choose_param(const param_not_found&, const Default& d) +{ + return d; +} - template <typename Tag, typename Args> - struct get_param_type: - lookup_named_param_def<Tag, Args, param_not_found> {}; +template < typename T > inline bool is_default_param(const T&) { return false; } - template <class Tag, typename Args> - inline - const typename lookup_named_param_def<Tag, Args, param_not_found>::type& - get_param(const Args& p, Tag) { - return lookup_named_param_def<Tag, Args, param_not_found>::get(p, param_not_found()); - } +inline bool is_default_param(const param_not_found&) { return true; } - template <class P, class Default> - const P& choose_param(const P& param, const Default&) { - return param; - } - - template <class Default> - Default choose_param(const param_not_found&, const Default& d) { - return d; - } - - template <typename T> - inline bool is_default_param(const T&) { return false; } - - inline bool is_default_param(const param_not_found&) - { return true; } - - namespace detail { - template <typename T> - struct const_type_as_type {typedef typename T::const_type type;}; - } // namespace detail - - - // Use this function instead of choose_param() when you want - // to avoid requiring get(tag, g) when it is not used. - namespace detail { - template <typename GraphIsConst, typename Graph, typename Param, typename Tag> - struct choose_impl_result: - boost::mpl::eval_if< - boost::is_same<Param, param_not_found>, - boost::mpl::eval_if< - GraphIsConst, - detail::const_type_as_type<property_map<Graph, Tag> >, - property_map<Graph, Tag> >, - boost::mpl::identity<Param> > {}; +namespace detail +{ + template < typename T > struct const_type_as_type + { + typedef typename T::const_type type; + }; +} // namespace detail + +// Use this function instead of choose_param() when you want +// to avoid requiring get(tag, g) when it is not used. +namespace detail +{ + template < typename GraphIsConst, typename Graph, typename Param, + typename Tag > + struct choose_impl_result + : boost::mpl::eval_if< boost::is_same< Param, param_not_found >, + boost::mpl::eval_if< GraphIsConst, + detail::const_type_as_type< property_map< Graph, Tag > >, + property_map< Graph, Tag > >, + boost::mpl::identity< Param > > + { + }; // Parameters of f are (GraphIsConst, Graph, Param, Tag) - template <bool Found> struct choose_impl_helper; - - template <> struct choose_impl_helper<false> { - template <typename Param, typename Graph, typename PropertyTag> - static typename property_map<typename boost::remove_const<Graph>::type, PropertyTag>::const_type - f(boost::mpl::true_, const Graph& g, const Param&, PropertyTag tag) { - return get(tag, g); - } - - template <typename Param, typename Graph, typename PropertyTag> - static typename property_map<typename boost::remove_const<Graph>::type, PropertyTag>::type - f(boost::mpl::false_, Graph& g, const Param&, PropertyTag tag) { - return get(tag, g); - } - }; - - template <> struct choose_impl_helper<true> { - template <typename GraphIsConst, typename Param, typename Graph, typename PropertyTag> - static Param f(GraphIsConst, const Graph&, const Param& p, PropertyTag) { - return p; - } - }; - } - - template <typename Param, typename Graph, typename PropertyTag> - typename detail::choose_impl_result<boost::mpl::true_, Graph, Param, PropertyTag>::type - choose_const_pmap(const Param& p, const Graph& g, PropertyTag tag) - { - return detail::choose_impl_helper<!boost::is_same<Param, param_not_found>::value> - ::f(boost::mpl::true_(), g, p, tag); - } - - template <typename Param, typename Graph, typename PropertyTag> - typename detail::choose_impl_result<boost::mpl::false_, Graph, Param, PropertyTag>::type - choose_pmap(const Param& p, Graph& g, PropertyTag tag) - { - return detail::choose_impl_helper<!boost::is_same<Param, param_not_found>::value> - ::f(boost::mpl::false_(), g, p, tag); - } - - namespace detail { + template < bool Found > struct choose_impl_helper; + + template <> struct choose_impl_helper< false > + { + template < typename Param, typename Graph, typename PropertyTag > + static + typename property_map< typename boost::remove_const< Graph >::type, + PropertyTag >::const_type + f(boost::mpl::true_, const Graph& g, const Param&, PropertyTag tag) + { + return get(tag, g); + } + + template < typename Param, typename Graph, typename PropertyTag > + static + typename property_map< typename boost::remove_const< Graph >::type, + PropertyTag >::type + f(boost::mpl::false_, Graph& g, const Param&, PropertyTag tag) + { + return get(tag, g); + } + }; + + template <> struct choose_impl_helper< true > + { + template < typename GraphIsConst, typename Param, typename Graph, + typename PropertyTag > + static Param f(GraphIsConst, const Graph&, const Param& p, PropertyTag) + { + return p; + } + }; +} + +template < typename Param, typename Graph, typename PropertyTag > +typename detail::choose_impl_result< boost::mpl::true_, Graph, Param, + PropertyTag >::type +choose_const_pmap(const Param& p, const Graph& g, PropertyTag tag) +{ + return detail::choose_impl_helper< !boost::is_same< Param, + param_not_found >::value >::f(boost::mpl::true_(), g, p, tag); +} + +template < typename Param, typename Graph, typename PropertyTag > +typename detail::choose_impl_result< boost::mpl::false_, Graph, Param, + PropertyTag >::type +choose_pmap(const Param& p, Graph& g, PropertyTag tag) +{ + return detail::choose_impl_helper< !boost::is_same< Param, + param_not_found >::value >::f(boost::mpl::false_(), g, p, tag); +} + +namespace detail +{ // used in the max-flow algorithms - template <class Graph, class P, class T, class R> + template < class Graph, class P, class T, class R > struct edge_capacity_value { - typedef bgl_named_params<P, T, R> Params; - typedef typename detail::choose_impl_result<boost::mpl::true_, Graph, typename get_param_type<edge_capacity_t, Params>::type, edge_capacity_t>::type CapacityEdgeMap; - typedef typename property_traits<CapacityEdgeMap>::value_type type; + typedef bgl_named_params< P, T, R > Params; + typedef typename detail::choose_impl_result< boost::mpl::true_, Graph, + typename get_param_type< edge_capacity_t, Params >::type, + edge_capacity_t >::type CapacityEdgeMap; + typedef typename property_traits< CapacityEdgeMap >::value_type type; }; // used in the max-flow algorithms - template <class Graph, class P, class T, class R> - struct edge_weight_value + template < class Graph, class P, class T, class R > struct edge_weight_value { - typedef bgl_named_params<P, T, R> Params; - typedef typename detail::choose_impl_result<boost::mpl::true_, Graph, typename get_param_type<edge_weight_t, Params>::type, edge_weight_t>::type WeightMap; - typedef typename property_traits<WeightMap>::value_type type; + typedef bgl_named_params< P, T, R > Params; + typedef typename detail::choose_impl_result< boost::mpl::true_, Graph, + typename get_param_type< edge_weight_t, Params >::type, + edge_weight_t >::type WeightMap; + typedef typename property_traits< WeightMap >::value_type type; }; - } +} - // Declare all new tags - namespace graph { - namespace keywords { +// Declare all new tags +namespace graph +{ + namespace keywords + { #define BOOST_BGL_ONE_PARAM_REF(name, key) BOOST_PARAMETER_NAME(name) #define BOOST_BGL_ONE_PARAM_CREF(name, key) BOOST_PARAMETER_NAME(name) - BOOST_BGL_DECLARE_NAMED_PARAMS + BOOST_BGL_DECLARE_NAMED_PARAMS #undef BOOST_BGL_ONE_PARAM_REF #undef BOOST_BGL_ONE_PARAM_CREF } - } +} - namespace detail { - template <typename Tag> struct convert_one_keyword {}; -#define BOOST_BGL_ONE_PARAM_REF(name, key) \ - template <> \ - struct convert_one_keyword<BOOST_PP_CAT(key, _t)> { \ - typedef boost::graph::keywords::tag::name type; \ +namespace detail +{ + template < typename Tag > struct convert_one_keyword + { + }; +#define BOOST_BGL_ONE_PARAM_REF(name, key) \ + template <> struct convert_one_keyword< BOOST_PP_CAT(key, _t) > \ + { \ + typedef boost::graph::keywords::tag::name type; \ }; #define BOOST_BGL_ONE_PARAM_CREF(name, key) BOOST_BGL_ONE_PARAM_REF(name, key) BOOST_BGL_DECLARE_NAMED_PARAMS #undef BOOST_BGL_ONE_PARAM_REF #undef BOOST_BGL_ONE_PARAM_CREF - template <typename T> - struct convert_bgl_params_to_boost_parameter { - typedef typename convert_one_keyword<typename T::tag_type>::type new_kw; - typedef boost::parameter::aux::tagged_argument<new_kw, const typename T::value_type> tagged_arg_type; - typedef convert_bgl_params_to_boost_parameter<typename T::next_type> rest_conv; - typedef boost::parameter::aux::arg_list<tagged_arg_type, typename rest_conv::type> type; - static type conv(const T& x) { - return type(tagged_arg_type(x.m_value), rest_conv::conv(x.m_base)); - } + template < typename T > struct convert_bgl_params_to_boost_parameter + { + typedef + typename convert_one_keyword< typename T::tag_type >::type new_kw; + typedef boost::parameter::aux::tagged_argument< new_kw, + const typename T::value_type > + tagged_arg_type; + typedef convert_bgl_params_to_boost_parameter< typename T::next_type > + rest_conv; + typedef boost::parameter::aux::arg_list< tagged_arg_type, + typename rest_conv::type > + type; + static type conv(const T& x) + { + return type(tagged_arg_type(x.m_value), rest_conv::conv(x.m_base)); + } }; - template <typename P, typename R> - struct convert_bgl_params_to_boost_parameter<bgl_named_params<P, int, R> > { - typedef convert_bgl_params_to_boost_parameter<R> rest_conv; - typedef typename rest_conv::type type; - static type conv(const bgl_named_params<P, int, R>& x) { - return rest_conv::conv(x.m_base); - } + template < typename P, typename R > + struct convert_bgl_params_to_boost_parameter< + bgl_named_params< P, int, R > > + { + typedef convert_bgl_params_to_boost_parameter< R > rest_conv; + typedef typename rest_conv::type type; + static type conv(const bgl_named_params< P, int, R >& x) + { + return rest_conv::conv(x.m_base); + } }; template <> - struct convert_bgl_params_to_boost_parameter<boost::no_property> { - typedef boost::parameter::aux::empty_arg_list type; - static type conv(const boost::no_property&) {return type();} + struct convert_bgl_params_to_boost_parameter< boost::no_property > + { + typedef boost::parameter::aux::empty_arg_list type; + static type conv(const boost::no_property&) { return type(); } }; template <> - struct convert_bgl_params_to_boost_parameter<boost::no_named_parameters> { - typedef boost::parameter::aux::empty_arg_list type; - static type conv(const boost::no_named_parameters&) {return type();} + struct convert_bgl_params_to_boost_parameter< boost::no_named_parameters > + { + typedef boost::parameter::aux::empty_arg_list type; + static type conv(const boost::no_named_parameters&) { return type(); } }; - struct bgl_parameter_not_found_type {}; - - template <typename ArgPack, typename KeywordType> - struct parameter_exists : boost::mpl::not_<boost::is_same<typename boost::parameter::binding<ArgPack, KeywordType, bgl_parameter_not_found_type>::type, bgl_parameter_not_found_type> > {}; - } + struct bgl_parameter_not_found_type + { + }; +} -#define BOOST_GRAPH_DECLARE_CONVERTED_PARAMETERS(old_type, old_var) \ - typedef typename boost::detail::convert_bgl_params_to_boost_parameter<old_type>::type arg_pack_type; \ - arg_pack_type arg_pack = boost::detail::convert_bgl_params_to_boost_parameter<old_type>::conv(old_var); +#define BOOST_GRAPH_DECLARE_CONVERTED_PARAMETERS(old_type, old_var) \ + typedef typename boost::detail::convert_bgl_params_to_boost_parameter< \ + old_type >::type arg_pack_type; \ + arg_pack_type arg_pack \ + = boost::detail::convert_bgl_params_to_boost_parameter< \ + old_type >::conv(old_var); - namespace detail { +namespace detail +{ - template <typename ArgType, typename Prop, typename Graph, bool Exists> - struct override_const_property_t { - typedef typename boost::remove_const<ArgType>::type result_type; - result_type operator()(const Graph&, const ArgType& a) const {return a;} + template < typename ArgType, typename Prop, typename Graph, bool Exists > + struct override_const_property_t + { + typedef typename boost::remove_const< ArgType >::type result_type; + result_type operator()(const Graph&, const ArgType& a) const + { + return a; + } }; - template <typename ArgType, typename Prop, typename Graph> - struct override_const_property_t<ArgType, Prop, Graph, false> { - typedef typename boost::property_map<Graph, Prop>::const_type result_type; - result_type operator()(const Graph& g, const ArgType&) const {return get(Prop(), g);} + template < typename ArgType, typename Prop, typename Graph > + struct override_const_property_t< ArgType, Prop, Graph, false > + { + typedef + typename boost::property_map< Graph, Prop >::const_type result_type; + result_type operator()(const Graph& g, const ArgType&) const + { + return get(Prop(), g); + } }; - template <typename ArgPack, typename Tag, typename Prop, typename Graph> - struct override_const_property_result { - typedef - typename override_const_property_t< - typename boost::parameter::value_type<ArgPack, Tag, int>::type, - Prop, - Graph, - boost::detail::parameter_exists<ArgPack, Tag>::value - >::result_type - type; + template < typename ArgPack, typename Tag, typename Prop, typename Graph > + struct override_const_property_result + { + typedef typename boost::mpl::has_key< ArgPack, Tag >::type + _parameter_exists; + typedef typename override_const_property_t< + typename boost::parameter::value_type< ArgPack, Tag, int >::type, + Prop, Graph, _parameter_exists::value >::result_type type; }; - template <typename ArgPack, typename Tag, typename Prop, typename Graph> - typename override_const_property_result<ArgPack, Tag, Prop, Graph>::type - override_const_property(const ArgPack& ap, const boost::parameter::keyword<Tag>& t, const Graph& g, Prop) { - return override_const_property_t< - typename boost::parameter::value_type<ArgPack, Tag, int>::type, - Prop, - Graph, - boost::detail::parameter_exists<ArgPack, Tag>::value - >()(g, ap[t | 0]); + template < typename ArgPack, typename Tag, typename Prop, typename Graph > + typename override_const_property_result< ArgPack, Tag, Prop, Graph >::type + override_const_property(const ArgPack& ap, + const boost::parameter::keyword< Tag >& t, const Graph& g, Prop) + { + typedef typename boost::mpl::has_key< ArgPack, Tag >::type + _parameter_exists; + return override_const_property_t< + typename boost::parameter::value_type< ArgPack, Tag, int >::type, + Prop, Graph, _parameter_exists::value >()(g, ap[t | 0]); } - template <typename ArgType, typename Prop, typename Graph, bool Exists> - struct override_property_t { - typedef ArgType result_type; - result_type operator()(const Graph&, const typename boost::add_reference<ArgType>::type a) const {return a;} - }; - - template <typename ArgType, typename Prop, typename Graph> - struct override_property_t<ArgType, Prop, Graph, false> { - typedef typename boost::property_map<Graph, Prop>::type result_type; - result_type operator()(const Graph& g, const ArgType&) const {return get(Prop(), g);} - }; - - template <typename ArgPack, typename Tag, typename Prop, typename Graph> - struct override_property_result { - typedef - typename override_property_t< - typename boost::parameter::value_type<ArgPack, Tag, int>::type, - Prop, - Graph, - boost::detail::parameter_exists<ArgPack, Tag>::value - >::result_type - type; - }; - - template <typename ArgPack, typename Tag, typename Prop, typename Graph> - typename override_property_result<ArgPack, Tag, Prop, Graph>::type - override_property(const ArgPack& ap, const boost::parameter::keyword<Tag>& t, const Graph& g, Prop) { - return override_property_t< - typename boost::parameter::value_type<ArgPack, Tag, int>::type, - Prop, - Graph, - boost::detail::parameter_exists<ArgPack, Tag>::value - >()(g, ap[t | 0]); - } + template < typename ArgType, typename Prop, typename Graph, bool Exists > + struct override_property_t + { + typedef ArgType result_type; + result_type operator()(const Graph&, + typename boost::add_lvalue_reference< ArgType >::type a) const + { + return a; + } + }; - template <typename F> struct make_arg_pack_type; - template <> struct make_arg_pack_type<void()> {typedef boost::parameter::aux::empty_arg_list type;}; - template <typename K, typename A> - struct make_arg_pack_type<void(K, A)> { - typedef boost::parameter::aux::tagged_argument<K, A> type; + template < typename ArgType, typename Prop, typename Graph > + struct override_property_t< ArgType, Prop, Graph, false > + { + typedef typename boost::property_map< Graph, Prop >::type result_type; + result_type operator()(const Graph& g, const ArgType&) const + { + return get(Prop(), g); + } }; -#define BOOST_GRAPH_OPENING_PART_OF_PAIR(z, i, n) boost::parameter::aux::arg_list<boost::parameter::aux::tagged_argument<BOOST_PP_CAT(Keyword, BOOST_PP_SUB(n, i)), BOOST_PP_CAT(Arg, BOOST_PP_SUB(n, i))>, -#define BOOST_GRAPH_MAKE_PAIR_PARAM(z, i, _) const boost::parameter::aux::tagged_argument<BOOST_PP_CAT(Keyword, i), BOOST_PP_CAT(Arg, i)>& BOOST_PP_CAT(kw, i) + template < typename ArgPack, typename Tag, typename Prop, typename Graph > + struct override_property_result + { + typedef typename boost::mpl::has_key< ArgPack, Tag >::type + _parameter_exists; + typedef typename override_property_t< + typename boost::parameter::value_type< ArgPack, Tag, int >::type, + Prop, Graph, _parameter_exists::value >::result_type type; + }; + + template < typename ArgPack, typename Tag, typename Prop, typename Graph > + typename override_property_result< ArgPack, Tag, Prop, Graph >::type + override_property(const ArgPack& ap, + const boost::parameter::keyword< Tag >& t, const Graph& g, Prop) + { + typedef typename boost::mpl::has_key< ArgPack, Tag >::type + _parameter_exists; + return override_property_t< + typename boost::parameter::value_type< ArgPack, Tag, int >::type, + Prop, Graph, _parameter_exists::value >()(g, ap[t | 0]); + } -#define BOOST_GRAPH_MAKE_AP_TYPE_SPECIALIZATION(z, i, _) \ - template <BOOST_PP_ENUM_PARAMS(i, typename Keyword), BOOST_PP_ENUM_PARAMS(i, typename Arg)> \ - struct make_arg_pack_type<void(BOOST_PP_ENUM_PARAMS(i, Keyword), BOOST_PP_ENUM_PARAMS(i, Arg))> { \ - typedef \ - BOOST_PP_REPEAT(i, BOOST_GRAPH_OPENING_PART_OF_PAIR, BOOST_PP_DEC(i)) boost::parameter::aux::empty_arg_list BOOST_PP_REPEAT(i, > BOOST_PP_TUPLE_EAT(3), ~) \ - type; \ + template < typename F > struct make_arg_pack_type; + template <> struct make_arg_pack_type< void() > + { + typedef boost::parameter::aux::empty_arg_list type; + }; + template < typename K, typename A > struct make_arg_pack_type< void(K, A) > + { + typedef boost::parameter::aux::tagged_argument< K, A > type; + }; + +#define BOOST_GRAPH_OPENING_PART_OF_PAIR(z, i, n) \ + boost::parameter::aux::arg_list \ + < boost::parameter::aux::tagged_argument< BOOST_PP_CAT(Keyword, \ + BOOST_PP_SUB(n, i)), \ + BOOST_PP_CAT(Arg, BOOST_PP_SUB(n, i)) >, +#define BOOST_GRAPH_MAKE_PAIR_PARAM(z, i, _) \ + const boost::parameter::aux::tagged_argument< BOOST_PP_CAT(Keyword, i), \ + BOOST_PP_CAT(Arg, i) >& BOOST_PP_CAT(kw, i) + +#define BOOST_GRAPH_MAKE_AP_TYPE_SPECIALIZATION(z, i, _) \ + template < BOOST_PP_ENUM_PARAMS(i, typename Keyword), \ + BOOST_PP_ENUM_PARAMS(i, typename Arg) > \ + struct make_arg_pack_type< void( \ + BOOST_PP_ENUM_PARAMS(i, Keyword), BOOST_PP_ENUM_PARAMS(i, Arg)) > \ + { \ + typedef BOOST_PP_REPEAT(i, BOOST_GRAPH_OPENING_PART_OF_PAIR, \ + BOOST_PP_DEC(i)) boost::parameter::aux::empty_arg_list \ + BOOST_PP_REPEAT(i, > BOOST_PP_TUPLE_EAT(3), ~) type; \ }; BOOST_PP_REPEAT_FROM_TO(2, 11, BOOST_GRAPH_MAKE_AP_TYPE_SPECIALIZATION, ~) #undef BOOST_GRAPH_MAKE_AP_TYPE_SPECIALIZATION -#define BOOST_GRAPH_MAKE_FORWARDING_FUNCTION(name, nfixed, nnamed_max) \ - /* Entry point for conversion from BGL-style named parameters */ \ - template <BOOST_PP_ENUM_PARAMS(nfixed, typename Param) BOOST_PP_COMMA_IF(nfixed) typename ArgPack> \ - typename boost::result_of< \ - detail::BOOST_PP_CAT(name, _impl)<BOOST_PP_ENUM_PARAMS(nfixed, Param)>(BOOST_PP_ENUM_PARAMS(nfixed, Param) BOOST_PP_COMMA_IF(nfixed) const ArgPack&) \ - >::type \ - BOOST_PP_CAT(name, _with_named_params)(BOOST_PP_ENUM_BINARY_PARAMS(nfixed, const Param, & param) BOOST_PP_COMMA_IF(nfixed) const ArgPack& arg_pack) { \ - return detail::BOOST_PP_CAT(name, _impl)<BOOST_PP_ENUM_PARAMS(nfixed, Param)>()(BOOST_PP_ENUM_PARAMS(nfixed, param) BOOST_PP_COMMA_IF(nfixed) arg_pack); \ - } \ - /* Individual functions taking Boost.Parameter-style keyword arguments */ \ - BOOST_PP_REPEAT(BOOST_PP_INC(nnamed_max), BOOST_GRAPH_MAKE_FORWARDING_FUNCTION_ONE, (name)(nfixed)) +#define BOOST_GRAPH_MAKE_FORWARDING_FUNCTION(name, nfixed, nnamed_max) \ + /* Entry point for conversion from BGL-style named parameters */ \ + template < BOOST_PP_ENUM_PARAMS(nfixed, typename Param) \ + BOOST_PP_COMMA_IF(nfixed) typename ArgPack > \ + typename boost::result_of< detail::BOOST_PP_CAT(name, _impl) \ + < BOOST_PP_ENUM_PARAMS(nfixed, Param) >(BOOST_PP_ENUM_PARAMS( \ + nfixed, Param) BOOST_PP_COMMA_IF(nfixed) const ArgPack&) \ + > ::type BOOST_PP_CAT(name, _with_named_params)( \ + BOOST_PP_ENUM_BINARY_PARAMS(nfixed, const Param, ¶m) \ + BOOST_PP_COMMA_IF(nfixed) const ArgPack& arg_pack) \ + { \ + return detail::BOOST_PP_CAT( \ + name, _impl)< BOOST_PP_ENUM_PARAMS(nfixed, Param) >()( \ + BOOST_PP_ENUM_PARAMS(nfixed, param) BOOST_PP_COMMA_IF(nfixed) \ + arg_pack); \ + } \ + /* Individual functions taking Boost.Parameter-style keyword arguments */ \ + BOOST_PP_REPEAT(BOOST_PP_INC(nnamed_max), \ + BOOST_GRAPH_MAKE_FORWARDING_FUNCTION_ONE, (name)(nfixed)) #define BOOST_GRAPH_MAKE_FORWARDING_FUNCTION_ONE(z, nnamed, seq) \ - BOOST_GRAPH_MAKE_FORWARDING_FUNCTION_ONEX(z, nnamed, BOOST_PP_SEQ_ELEM(0, seq), BOOST_PP_SEQ_ELEM(1, seq)) - -#define BOOST_GRAPH_MAKE_FORWARDING_FUNCTION_ONEX(z, nnamed, name, nfixed) \ - template <BOOST_PP_ENUM_PARAMS(nfixed, typename Param) BOOST_PP_ENUM_TRAILING_PARAMS(nnamed, typename Keyword) BOOST_PP_ENUM_TRAILING_PARAMS(nnamed, typename Arg)> \ - typename boost::result_of< \ - detail::BOOST_PP_CAT(name, _impl)<BOOST_PP_ENUM_PARAMS(nfixed, Param)> \ - (BOOST_PP_ENUM_PARAMS(nfixed, Param) BOOST_PP_COMMA_IF(nfixed) \ - const typename boost::detail::make_arg_pack_type<void(BOOST_PP_ENUM_PARAMS(nnamed, Keyword) BOOST_PP_COMMA_IF(nnamed) BOOST_PP_ENUM_PARAMS(nnamed, Arg))>::type&) \ - >::type \ - name(BOOST_PP_ENUM_BINARY_PARAMS(nfixed, const Param, & param) \ - BOOST_PP_ENUM_TRAILING(nnamed, BOOST_GRAPH_MAKE_PAIR_PARAM, ~)) { \ - return detail::BOOST_PP_CAT(name, _impl)<BOOST_PP_ENUM_PARAMS(nfixed, Param)>() \ - (BOOST_PP_ENUM_PARAMS(nfixed, param), \ - (boost::parameter::aux::empty_arg_list() BOOST_PP_ENUM_TRAILING_PARAMS(nnamed, kw))); \ - } - -#define BOOST_GRAPH_MAKE_OLD_STYLE_PARAMETER_FUNCTION(name, nfixed) \ - template <BOOST_PP_ENUM_PARAMS(nfixed, typename Param) BOOST_PP_COMMA_IF(nfixed) class P, class T, class R> \ - typename boost::result_of< \ - ::boost::graph::detail::BOOST_PP_CAT(name, _impl) BOOST_PP_EXPR_IF(nfixed, <) BOOST_PP_ENUM_PARAMS(nfixed, Param) BOOST_PP_EXPR_IF(nfixed, >) \ - (BOOST_PP_ENUM_PARAMS(nfixed, Param) BOOST_PP_COMMA_IF(nfixed) \ - const typename boost::detail::convert_bgl_params_to_boost_parameter<boost::bgl_named_params<P, T, R> >::type &) \ - >::type \ - name(BOOST_PP_ENUM_BINARY_PARAMS(nfixed, const Param, & param) BOOST_PP_COMMA_IF(nfixed) const boost::bgl_named_params<P, T, R>& old_style_params) { \ - typedef boost::bgl_named_params<P, T, R> old_style_params_type; \ - BOOST_GRAPH_DECLARE_CONVERTED_PARAMETERS(old_style_params_type, old_style_params) \ - return ::boost::graph::BOOST_PP_CAT(name, _with_named_params)(BOOST_PP_ENUM_PARAMS(nfixed, param) BOOST_PP_COMMA_IF(nfixed) arg_pack); \ - } \ - \ - BOOST_PP_EXPR_IF(nfixed, template <) BOOST_PP_ENUM_PARAMS(nfixed, typename Param) BOOST_PP_EXPR_IF(nfixed, >) \ - BOOST_PP_EXPR_IF(nfixed, typename) boost::result_of< \ - ::boost::graph::detail::BOOST_PP_CAT(name, _impl) BOOST_PP_EXPR_IF(nfixed, <) BOOST_PP_ENUM_PARAMS(nfixed, Param) BOOST_PP_EXPR_IF(nfixed, >) \ - (BOOST_PP_ENUM_PARAMS(nfixed, Param) BOOST_PP_COMMA_IF(nfixed) const boost::parameter::aux::empty_arg_list &) \ - >::type \ - name(BOOST_PP_ENUM_BINARY_PARAMS(nfixed, const Param, & param)) { \ - BOOST_GRAPH_DECLARE_CONVERTED_PARAMETERS(boost::no_named_parameters, boost::no_named_parameters()) \ - return ::boost::graph::BOOST_PP_CAT(name, _with_named_params)(BOOST_PP_ENUM_PARAMS(nfixed, param) BOOST_PP_COMMA_IF(nfixed) arg_pack); \ - } - - } - - namespace detail { - - template <bool Exists, typename Graph, typename ArgPack, typename Value, typename PM> - struct map_maker_helper { - typedef PM map_type; - static PM make_map(const Graph&, Value, const PM& pm, const ArgPack&) { - return pm; - } - }; - - template <typename Graph, typename ArgPack, typename Value, typename PM> - struct map_maker_helper<false, Graph, ArgPack, Value, PM> { - typedef typename boost::remove_const< - typename override_const_property_t< - typename boost::parameter::value_type< - ArgPack, boost::graph::keywords::tag::vertex_index_map, int>::type, - boost::vertex_index_t, - Graph, - boost::detail::parameter_exists< - ArgPack, boost::graph::keywords::tag::vertex_index_map>::value - >::result_type>::type vi_map_type; - typedef - boost::shared_array_property_map<Value, vi_map_type> - map_type; - static map_type make_map(const Graph& g, - Value v, - const PM&, - const ArgPack& ap) { - return make_shared_array_property_map( - num_vertices(g), - v, - override_const_property( - ap, - boost::graph::keywords::_vertex_index_map, - g, vertex_index)); - } - }; - - template <typename Graph, typename ArgPack, typename MapTag, typename ValueType> - struct map_maker { - BOOST_STATIC_CONSTANT( - bool, - has_map = - (parameter_exists<ArgPack, MapTag> - ::value)); - typedef map_maker_helper<has_map, Graph, ArgPack, ValueType, - typename boost::remove_const< - typename boost::parameter::value_type< - ArgPack, - MapTag, - int - >::type - >::type> helper; - typedef typename helper::map_type map_type; - static map_type make_map(const Graph& g, const ArgPack& ap, ValueType default_value) { - return helper::make_map(g, default_value, ap[::boost::parameter::keyword<MapTag>::instance | 0], ap); - } - }; - - template <typename MapTag, typename ValueType = void> - class make_property_map_from_arg_pack_gen { - ValueType default_value; - - public: - make_property_map_from_arg_pack_gen(ValueType default_value) - : default_value(default_value) {} - - template <typename Graph, typename ArgPack> - typename map_maker<Graph, ArgPack, MapTag, ValueType>::map_type - operator()(const Graph& g, const ArgPack& ap) const { - return map_maker<Graph, ArgPack, MapTag, ValueType>::make_map(g, ap, default_value); - } - }; - - template <typename MapTag> - class make_property_map_from_arg_pack_gen<MapTag, void> { - public: - template <typename ValueType, typename Graph, typename ArgPack> - typename map_maker<Graph, ArgPack, MapTag, ValueType>::map_type - operator()(const Graph& g, const ArgPack& ap, ValueType default_value) const { - return map_maker<Graph, ArgPack, MapTag, ValueType>::make_map(g, ap, default_value); - } - }; - - static const - make_property_map_from_arg_pack_gen< - boost::graph::keywords::tag::color_map, - default_color_type> - make_color_map_from_arg_pack(white_color); - - template <bool Exists, class Graph, class ArgPack, class KeyT, class ValueT, class KeyMapTag, class IndexInHeapMapTag, class Compare, class Q> - struct priority_queue_maker_helper { - typedef Q priority_queue_type; - - static priority_queue_type - make_queue(const Graph&, const ArgPack&, KeyT, const Q& q) { - return q; - } - }; - - template <class Graph, class ArgPack, class KeyT, class ValueT, class KeyMapTag, class IndexInHeapMapTag, class Compare, class Q> - struct priority_queue_maker_helper<false, Graph, ArgPack, KeyT, ValueT, KeyMapTag, IndexInHeapMapTag, Compare, Q> { - typedef typename std::vector<ValueT>::size_type default_index_in_heap_type; - typedef typename map_maker<Graph, ArgPack, IndexInHeapMapTag, default_index_in_heap_type>::helper::map_type index_in_heap_map; - typedef boost::d_ary_heap_indirect<ValueT, 4, index_in_heap_map, typename map_maker<Graph, ArgPack, KeyMapTag, KeyT>::helper::map_type, Compare> priority_queue_type; - - static priority_queue_type - make_queue(const Graph& g, const ArgPack& ap, KeyT defaultKey, const Q&) { - return priority_queue_type( - map_maker<Graph, ArgPack, KeyMapTag, KeyT>::make_map(g, ap, defaultKey), - map_maker<Graph, ArgPack, IndexInHeapMapTag, default_index_in_heap_type>::make_map(g, ap, typename boost::property_traits<index_in_heap_map>::value_type(-1)) - ); - } - }; - - template <class Graph, class ArgPack, class KeyT, class ValueT, class PriorityQueueTag, class KeyMapTag, class IndexInHeapMapTag, class Compare> - struct priority_queue_maker { - BOOST_STATIC_CONSTANT( - bool, - g_hasQ = - (parameter_exists<ArgPack, PriorityQueueTag> - ::value)); - typedef boost::reference_wrapper<int> int_refw; - typedef typename boost::parameter::value_type< - ArgPack, - PriorityQueueTag, - int_refw - >::type - param_value_type_wrapper; - typedef typename param_value_type_wrapper::type - param_value_type; - typedef typename boost::remove_const<param_value_type>::type param_value_type_no_const; - typedef priority_queue_maker_helper<g_hasQ, Graph, ArgPack, KeyT, ValueT, KeyMapTag, IndexInHeapMapTag, Compare, - param_value_type_no_const> helper; - typedef typename helper::priority_queue_type priority_queue_type; - - static priority_queue_type make_queue(const Graph& g, const ArgPack& ap, KeyT defaultKey) { - return helper::make_queue(g, ap, defaultKey, ap[::boost::parameter::keyword<PriorityQueueTag>::instance | 0]); - } - }; - - template <class PriorityQueueTag, class KeyT, class ValueT, class Compare = std::less<KeyT>, class KeyMapTag = boost::graph::keywords::tag::distance_map, class IndexInHeapMapTag = boost::graph::keywords::tag::index_in_heap_map> - struct make_priority_queue_from_arg_pack_gen { - KeyT defaultKey; - - make_priority_queue_from_arg_pack_gen(KeyT defaultKey_) : defaultKey(defaultKey_) { } - - template <class F> - struct result { - typedef typename remove_const<typename remove_reference<typename function_traits<F>::arg1_type>::type>::type graph_type; - typedef typename remove_const<typename remove_reference<typename function_traits<F>::arg2_type>::type>::type arg_pack_type; - typedef typename priority_queue_maker<graph_type, arg_pack_type, KeyT, ValueT, PriorityQueueTag, KeyMapTag, IndexInHeapMapTag, Compare>::priority_queue_type type; - }; - - template <class Graph, class ArgPack> - typename priority_queue_maker<Graph, ArgPack, KeyT, ValueT, PriorityQueueTag, KeyMapTag, IndexInHeapMapTag, Compare>::priority_queue_type - operator()(const Graph& g, const ArgPack& ap) const { - return priority_queue_maker<Graph, ArgPack, KeyT, ValueT, PriorityQueueTag, KeyMapTag, IndexInHeapMapTag, Compare>::make_queue(g, ap, defaultKey); - } - }; - - template <typename G> - typename boost::graph_traits<G>::vertex_descriptor - get_null_vertex(const G&) {return boost::graph_traits<G>::null_vertex();} - - template <typename G> - typename boost::graph_traits<G>::vertex_descriptor - get_default_starting_vertex(const G& g) { - std::pair<typename boost::graph_traits<G>::vertex_iterator, typename boost::graph_traits<G>::vertex_iterator> iters = vertices(g); - return (iters.first == iters.second) ? boost::graph_traits<G>::null_vertex() : *iters.first; + BOOST_GRAPH_MAKE_FORWARDING_FUNCTION_ONEX( \ + z, nnamed, BOOST_PP_SEQ_ELEM(0, seq), BOOST_PP_SEQ_ELEM(1, seq)) + +#define BOOST_GRAPH_MAKE_FORWARDING_FUNCTION_ONEX(z, nnamed, name, nfixed) \ + template < BOOST_PP_ENUM_PARAMS_Z(z, nfixed, typename Param) \ + BOOST_PP_ENUM_TRAILING_PARAMS_Z( \ + z, nnamed, typename ArgumentPack) > \ + typename BOOST_PP_EXPR_IF(nnamed, \ + boost::lazy_enable_if \ + < boost::parameter::is_argument_pack< ArgumentPack0 >) \ + BOOST_PP_COMMA_IF(nnamed)::boost::graph::detail::BOOST_PP_CAT( \ + name, _impl)< BOOST_PP_ENUM_PARAMS_Z(z, nfixed, Param) > \ + BOOST_PP_EXPR_IF(nnamed, >)::type name( \ + BOOST_PP_ENUM_BINARY_PARAMS_Z(z, nfixed, Param, const& param) \ + BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z( \ + z, nnamed, ArgumentPack, const& tagged_arg)) \ + { \ + return ::boost::graph::BOOST_PP_CAT(name, _with_named_params)( \ + BOOST_PP_ENUM_PARAMS_Z(z, nfixed, param) BOOST_PP_COMMA_IF(nnamed) \ + BOOST_PP_LPAREN_IF(nnamed) BOOST_PP_ENUM_PARAMS_Z( \ + z, nnamed, tagged_arg) BOOST_PP_RPAREN_IF(nnamed)); \ + } + +#define BOOST_GRAPH_MAKE_OLD_STYLE_PARAMETER_FUNCTION(name, nfixed) \ + template < BOOST_PP_ENUM_PARAMS(nfixed, typename Param) \ + BOOST_PP_COMMA_IF(nfixed) class P, \ + class T, class R > \ + typename boost::result_of< ::boost::graph::detail::BOOST_PP_CAT( \ + name, _impl) BOOST_PP_EXPR_IF(nfixed, <) BOOST_PP_ENUM_PARAMS(nfixed, \ + Param) BOOST_PP_EXPR_IF(nfixed, >)(BOOST_PP_ENUM_PARAMS(nfixed, Param) \ + BOOST_PP_COMMA_IF(nfixed) const typename boost::detail:: \ + convert_bgl_params_to_boost_parameter< \ + boost::bgl_named_params< P, T, R > >::type&) >::type \ + name(BOOST_PP_ENUM_BINARY_PARAMS(nfixed, const Param, ¶m) \ + BOOST_PP_COMMA_IF(nfixed) \ + const boost::bgl_named_params< P, T, R >& old_style_params) \ + { \ + typedef boost::bgl_named_params< P, T, R > old_style_params_type; \ + BOOST_GRAPH_DECLARE_CONVERTED_PARAMETERS( \ + old_style_params_type, old_style_params) \ + return ::boost::graph::BOOST_PP_CAT(name, _with_named_params)( \ + BOOST_PP_ENUM_PARAMS(nfixed, param) BOOST_PP_COMMA_IF(nfixed) \ + arg_pack); \ + } \ + BOOST_PP_EXPR_IF(nfixed, template < ) \ + BOOST_PP_ENUM_PARAMS(nfixed, typename Param) \ + BOOST_PP_EXPR_IF(nfixed, >) \ + BOOST_PP_EXPR_IF(nfixed, typename) \ + boost::result_of< ::boost::graph::detail::BOOST_PP_CAT( \ + name, _impl) BOOST_PP_EXPR_IF(nfixed, \ + <) BOOST_PP_ENUM_PARAMS(nfixed, Param) BOOST_PP_EXPR_IF(nfixed, \ + >)(BOOST_PP_ENUM_PARAMS(nfixed, Param) BOOST_PP_COMMA_IF(nfixed) \ + const boost::parameter::aux::empty_arg_list&) >::type \ + name(BOOST_PP_ENUM_BINARY_PARAMS(nfixed, const Param, ¶m)) \ + { \ + BOOST_GRAPH_DECLARE_CONVERTED_PARAMETERS( \ + boost::no_named_parameters, boost::no_named_parameters()) \ + return ::boost::graph::BOOST_PP_CAT(name, _with_named_params)( \ + BOOST_PP_ENUM_PARAMS(nfixed, param) BOOST_PP_COMMA_IF(nfixed) \ + arg_pack); \ + } + +} + +namespace detail +{ + + template < bool Exists, typename Graph, typename ArgPack, typename Value, + typename PM > + struct map_maker_helper + { + typedef PM map_type; + static PM make_map(const Graph&, Value, const PM& pm, const ArgPack&) + { + return pm; + } + }; + + template < typename Graph, typename ArgPack, typename Value, typename PM > + struct map_maker_helper< false, Graph, ArgPack, Value, PM > + { + typedef typename boost::mpl::has_key< ArgPack, + boost::graph::keywords::tag::vertex_index_map >::type + _parameter_exists; + typedef + typename boost::remove_const< typename override_const_property_t< + typename boost::parameter::value_type< ArgPack, + boost::graph::keywords::tag::vertex_index_map, int >::type, + boost::vertex_index_t, Graph, + _parameter_exists::value >::result_type >::type vi_map_type; + typedef boost::shared_array_property_map< Value, vi_map_type > map_type; + static map_type make_map( + const Graph& g, Value v, const PM&, const ArgPack& ap) + { + return make_shared_array_property_map(num_vertices(g), v, + override_const_property(ap, + boost::graph::keywords::_vertex_index_map, g, + vertex_index)); + } + }; + + template < typename Graph, typename ArgPack, typename MapTag, + typename ValueType > + struct map_maker + { + typedef typename boost::mpl::has_key< ArgPack, MapTag >::type + _parameter_exists; + BOOST_STATIC_CONSTANT(bool, has_map = (_parameter_exists::value)); + typedef map_maker_helper< has_map, Graph, ArgPack, ValueType, + typename boost::remove_const< typename boost::parameter::value_type< + ArgPack, MapTag, int >::type >::type > + helper; + typedef typename helper::map_type map_type; + static map_type make_map( + const Graph& g, const ArgPack& ap, ValueType default_value) + { + return helper::make_map(g, default_value, + ap[::boost::parameter::keyword< MapTag >::instance | 0], ap); + } + }; + + template < typename MapTag, typename ValueType = void > + class make_property_map_from_arg_pack_gen + { + ValueType default_value; + + public: + make_property_map_from_arg_pack_gen(ValueType default_value) + : default_value(default_value) + { + } + + template < typename Graph, typename ArgPack > + typename map_maker< Graph, ArgPack, MapTag, ValueType >::map_type + operator()(const Graph& g, const ArgPack& ap) const + { + return map_maker< Graph, ArgPack, MapTag, ValueType >::make_map( + g, ap, default_value); + } + }; + + template < typename MapTag > + class make_property_map_from_arg_pack_gen< MapTag, void > + { + public: + template < typename ValueType, typename Graph, typename ArgPack > + typename map_maker< Graph, ArgPack, MapTag, ValueType >::map_type + operator()( + const Graph& g, const ArgPack& ap, ValueType default_value) const + { + return map_maker< Graph, ArgPack, MapTag, ValueType >::make_map( + g, ap, default_value); + } + }; + + static const make_property_map_from_arg_pack_gen< + boost::graph::keywords::tag::color_map, default_color_type > + make_color_map_from_arg_pack(white_color); + + template < bool Exists, class Graph, class ArgPack, class KeyT, + class ValueT, class KeyMapTag, class IndexInHeapMapTag, class Compare, + class Q > + struct priority_queue_maker_helper + { + typedef Q priority_queue_type; + + static priority_queue_type make_queue( + const Graph&, const ArgPack&, KeyT, const Q& q) + { + return q; + } + }; + + template < class Graph, class ArgPack, class KeyT, class ValueT, + class KeyMapTag, class IndexInHeapMapTag, class Compare, class Q > + struct priority_queue_maker_helper< false, Graph, ArgPack, KeyT, ValueT, + KeyMapTag, IndexInHeapMapTag, Compare, Q > + { + typedef typename std::vector< ValueT >::size_type + default_index_in_heap_type; + typedef typename map_maker< Graph, ArgPack, IndexInHeapMapTag, + default_index_in_heap_type >::helper::map_type index_in_heap_map; + typedef boost::d_ary_heap_indirect< ValueT, 4, index_in_heap_map, + typename map_maker< Graph, ArgPack, KeyMapTag, + KeyT >::helper::map_type, + Compare > + priority_queue_type; + + static priority_queue_type make_queue( + const Graph& g, const ArgPack& ap, KeyT defaultKey, const Q&) + { + return priority_queue_type( + map_maker< Graph, ArgPack, KeyMapTag, KeyT >::make_map( + g, ap, defaultKey), + map_maker< Graph, ArgPack, IndexInHeapMapTag, + default_index_in_heap_type >::make_map(g, ap, + typename boost::property_traits< + index_in_heap_map >::value_type(-1))); + } + }; + + template < class Graph, class ArgPack, class KeyT, class ValueT, + class PriorityQueueTag, class KeyMapTag, class IndexInHeapMapTag, + class Compare > + struct priority_queue_maker + { + typedef typename boost::mpl::has_key< ArgPack, PriorityQueueTag >::type + _parameter_exists; + BOOST_STATIC_CONSTANT(bool, g_hasQ = (_parameter_exists::value)); + typedef boost::reference_wrapper< int > int_refw; + typedef typename boost::parameter::value_type< ArgPack, + PriorityQueueTag, int_refw >::type param_value_type_wrapper; + typedef typename param_value_type_wrapper::type param_value_type; + typedef typename boost::remove_const< param_value_type >::type + param_value_type_no_const; + typedef priority_queue_maker_helper< g_hasQ, Graph, ArgPack, KeyT, + ValueT, KeyMapTag, IndexInHeapMapTag, Compare, + param_value_type_no_const > + helper; + typedef typename helper::priority_queue_type priority_queue_type; + + static priority_queue_type make_queue( + const Graph& g, const ArgPack& ap, KeyT defaultKey) + { + return helper::make_queue(g, ap, defaultKey, + ap[::boost::parameter::keyword< PriorityQueueTag >::instance + | 0]); + } + }; + + template < class PriorityQueueTag, class KeyT, class ValueT, + class Compare = std::less< KeyT >, + class KeyMapTag = boost::graph::keywords::tag::distance_map, + class IndexInHeapMapTag + = boost::graph::keywords::tag::index_in_heap_map > + struct make_priority_queue_from_arg_pack_gen + { + KeyT defaultKey; + + make_priority_queue_from_arg_pack_gen(KeyT defaultKey_) + : defaultKey(defaultKey_) + { + } + + template < class F > struct result + { + typedef typename remove_const< typename remove_reference< + typename function_traits< F >::arg1_type >::type >::type + graph_type; + typedef typename remove_const< typename remove_reference< + typename function_traits< F >::arg2_type >::type >::type + arg_pack_type; + typedef typename priority_queue_maker< graph_type, arg_pack_type, + KeyT, ValueT, PriorityQueueTag, KeyMapTag, IndexInHeapMapTag, + Compare >::priority_queue_type type; + }; + + template < class Graph, class ArgPack > + typename priority_queue_maker< Graph, ArgPack, KeyT, ValueT, + PriorityQueueTag, KeyMapTag, IndexInHeapMapTag, + Compare >::priority_queue_type + operator()(const Graph& g, const ArgPack& ap) const + { + return priority_queue_maker< Graph, ArgPack, KeyT, ValueT, + PriorityQueueTag, KeyMapTag, IndexInHeapMapTag, + Compare >::make_queue(g, ap, defaultKey); + } + }; + + template < typename G > + typename boost::graph_traits< G >::vertex_descriptor get_null_vertex( + const G&) + { + return boost::graph_traits< G >::null_vertex(); + } + + template < typename G > + typename boost::graph_traits< G >::vertex_descriptor + get_default_starting_vertex(const G& g) + { + std::pair< typename boost::graph_traits< G >::vertex_iterator, + typename boost::graph_traits< G >::vertex_iterator > + iters = vertices(g); + return (iters.first == iters.second) + ? boost::graph_traits< G >::null_vertex() + : *iters.first; } - template <typename G> - struct get_default_starting_vertex_t { - typedef typename boost::graph_traits<G>::vertex_descriptor result_type; - const G& g; - get_default_starting_vertex_t(const G& g): g(g) {} - result_type operator()() const {return get_default_starting_vertex(g);} + template < typename G > struct get_default_starting_vertex_t + { + typedef + typename boost::graph_traits< G >::vertex_descriptor result_type; + const G& g; + get_default_starting_vertex_t(const G& g) : g(g) {} + result_type operator()() const + { + return get_default_starting_vertex(g); + } }; - // Wrapper to avoid instantiating numeric_limits when users provide distance_inf value manually - template <typename T> - struct get_max { - T operator()() const { - return (std::numeric_limits<T>::max)(); - } - typedef T result_type; + // Wrapper to avoid instantiating numeric_limits when users provide + // distance_inf value manually + template < typename T > struct get_max + { + T operator()() const { return (std::numeric_limits< T >::max)(); } + typedef T result_type; }; - } // namespace detail +} // namespace detail } // namespace boost diff --git a/contrib/restricted/boost/graph/include/boost/graph/named_graph.hpp b/contrib/restricted/boost/graph/include/boost/graph/named_graph.hpp index b5bcd7708d..991458bed1 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/named_graph.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/named_graph.hpp @@ -32,484 +32,489 @@ #include <stdexcept> // for std::runtime_error #include <utility> // for std::pair -#include <util/system/compiler.h> - -namespace boost { namespace graph { - -/******************************************************************* - * User-customized traits * - *******************************************************************/ - -/** - * @brief Trait used to extract the internal vertex name from a vertex - * property. - * - * To enable the use of internal vertex names in a graph type, - * specialize the @c internal_vertex_name trait for your graph - * property (e.g., @c a City class, which stores information about the - * vertices in a road map). - */ -template<typename VertexProperty> -struct internal_vertex_name +namespace boost { - /** - * The @c type field provides a function object that extracts a key - * from the @c VertexProperty. The function object type must have a - * nested @c result_type that provides the type of the key. For - * more information, see the @c KeyExtractor concept in the - * Boost.MultiIndex documentation: @c type must either be @c void - * (if @c VertexProperty does not have an internal vertex name) or - * a model of @c KeyExtractor. - */ - typedef void type; -}; - -/** - * Extract the internal vertex name from a @c property structure by - * looking at its base. - */ -template<typename Tag, typename T, typename Base> -struct internal_vertex_name<property<Tag, T, Base> > - : internal_vertex_name<Base> { }; - -/** - * Construct an instance of @c VertexProperty directly from its - * name. This function object should be used within the @c - * internal_vertex_constructor trait. - */ -template<typename VertexProperty> -struct vertex_from_name +namespace graph { -private: - typedef typename internal_vertex_name<VertexProperty>::type extract_name_type; - - typedef typename remove_cv< - typename remove_reference< - typename extract_name_type::result_type>::type>::type - vertex_name_type; - -public: - typedef vertex_name_type argument_type; - typedef VertexProperty result_type; - - VertexProperty operator()(const vertex_name_type& name) - { - return VertexProperty(name); - } -}; - -/** - * Throw an exception whenever one tries to construct a @c - * VertexProperty instance from its name. - */ -template<typename VertexProperty> -struct cannot_add_vertex -{ -private: - typedef typename internal_vertex_name<VertexProperty>::type extract_name_type; - - typedef typename remove_cv< - typename remove_reference< - typename extract_name_type::result_type>::type>::type - vertex_name_type; - -public: - typedef vertex_name_type argument_type; - typedef VertexProperty result_type; - - VertexProperty operator()(const vertex_name_type&) - { - boost::throw_exception(std::runtime_error("add_vertex: " - "unable to create a vertex from its name")); - } -}; - -/** - * @brief Trait used to construct an instance of a @c VertexProperty, - * which is a class type that stores the properties associated with a - * vertex in a graph, from just the name of that vertex property. This - * operation is used when an operation is required to map from a - * vertex name to a vertex descriptor (e.g., to add an edge outgoing - * from that vertex), but no vertex by the name exists. The function - * object provided by this trait will be used to add new vertices - * based only on their names. Since this cannot be done for arbitrary - * types, the default behavior is to throw an exception when this - * routine is called, which requires that all named vertices be added - * before adding any edges by name. - */ -template<typename VertexProperty> -struct internal_vertex_constructor -{ - /** - * The @c type field provides a function object that constructs a - * new instance of @c VertexProperty from the name of the vertex (as - * determined by @c internal_vertex_name). The function object shall - * accept a vertex name and return a @c VertexProperty. Predefined - * options include: - * - * @c vertex_from_name<VertexProperty>: construct an instance of - * @c VertexProperty directly from the name. - * - * @c cannot_add_vertex<VertexProperty>: the default value, which - * throws an @c std::runtime_error if one attempts to add a vertex - * given just the name. - */ - typedef cannot_add_vertex<VertexProperty> type; -}; - -/** - * Extract the internal vertex constructor from a @c property structure by - * looking at its base. - */ -template<typename Tag, typename T, typename Base> -struct internal_vertex_constructor<property<Tag, T, Base> > - : internal_vertex_constructor<Base> { }; - -/******************************************************************* - * Named graph mixin * - *******************************************************************/ - -/** - * named_graph is a mixin that provides names for the vertices of a - * graph, including a mapping from names to vertices. Graph types that - * may or may not be have vertex names (depending on the properties - * supplied by the user) should use maybe_named_graph. - * - * Template parameters: - * - * Graph: the graph type that derives from named_graph - * - * Vertex: the type of a vertex descriptor in Graph. Note: we cannot - * use graph_traits here, because the Graph is not yet defined. - * - * VertexProperty: the type stored with each vertex in the Graph. - */ -template<typename Graph, typename Vertex, typename VertexProperty> -class named_graph -{ -public: - /// The type of the function object that extracts names from vertex - /// properties. - typedef typename internal_vertex_name<VertexProperty>::type extract_name_type; - /// The type of the "bundled" property, from which the name can be - /// extracted. - typedef typename lookup_one_property<VertexProperty, vertex_bundle_t>::type - bundled_vertex_property_type; - - /// The type of the function object that generates vertex properties - /// from names, for the implicit addition of vertices. - typedef typename internal_vertex_constructor<VertexProperty>::type - vertex_constructor_type; - - /// The type used to name vertices in the graph - typedef typename remove_cv< - typename remove_reference< - typename extract_name_type::result_type>::type>::type - vertex_name_type; - - /// The type of vertex descriptors in the graph - typedef Vertex vertex_descriptor; - -private: - /// Key extractor for use with the multi_index_container - struct extract_name_from_vertex - { - typedef vertex_name_type result_type; - - extract_name_from_vertex(Graph& graph, const extract_name_type& extract) - : graph(graph), extract(extract) { } - - const result_type& operator()(Vertex vertex) const - { - return extract(graph[vertex]); - } - Graph& graph; - extract_name_type extract; - }; - -public: - /// The type that maps names to vertices - typedef multi_index::multi_index_container< - Vertex, + /******************************************************************* + * User-customized traits * + *******************************************************************/ + + /** + * @brief Trait used to extract the internal vertex name from a vertex + * property. + * + * To enable the use of internal vertex names in a graph type, + * specialize the @c internal_vertex_name trait for your graph + * property (e.g., @c a City class, which stores information about the + * vertices in a road map). + */ + template < typename VertexProperty > struct internal_vertex_name + { + /** + * The @c type field provides a function object that extracts a key + * from the @c VertexProperty. The function object type must have a + * nested @c result_type that provides the type of the key. For + * more information, see the @c KeyExtractor concept in the + * Boost.MultiIndex documentation: @c type must either be @c void + * (if @c VertexProperty does not have an internal vertex name) or + * a model of @c KeyExtractor. + */ + typedef void type; + }; + + /** + * Extract the internal vertex name from a @c property structure by + * looking at its base. + */ + template < typename Tag, typename T, typename Base > + struct internal_vertex_name< property< Tag, T, Base > > + : internal_vertex_name< Base > + { + }; + + /** + * Construct an instance of @c VertexProperty directly from its + * name. This function object should be used within the @c + * internal_vertex_constructor trait. + */ + template < typename VertexProperty > struct vertex_from_name + { + private: + typedef typename internal_vertex_name< VertexProperty >::type + extract_name_type; + + typedef typename remove_cv< typename remove_reference< + typename extract_name_type::result_type >::type >::type + vertex_name_type; + + public: + typedef vertex_name_type argument_type; + typedef VertexProperty result_type; + + VertexProperty operator()(const vertex_name_type& name) + { + return VertexProperty(name); + } + }; + + /** + * Throw an exception whenever one tries to construct a @c + * VertexProperty instance from its name. + */ + template < typename VertexProperty > struct cannot_add_vertex + { + private: + typedef typename internal_vertex_name< VertexProperty >::type + extract_name_type; + + typedef typename remove_cv< typename remove_reference< + typename extract_name_type::result_type >::type >::type + vertex_name_type; + + public: + typedef vertex_name_type argument_type; + typedef VertexProperty result_type; + + VertexProperty operator()(const vertex_name_type&) + { + boost::throw_exception( + std::runtime_error("add_vertex: " + "unable to create a vertex from its name")); + } + }; + + /** + * @brief Trait used to construct an instance of a @c VertexProperty, + * which is a class type that stores the properties associated with a + * vertex in a graph, from just the name of that vertex property. This + * operation is used when an operation is required to map from a + * vertex name to a vertex descriptor (e.g., to add an edge outgoing + * from that vertex), but no vertex by the name exists. The function + * object provided by this trait will be used to add new vertices + * based only on their names. Since this cannot be done for arbitrary + * types, the default behavior is to throw an exception when this + * routine is called, which requires that all named vertices be added + * before adding any edges by name. + */ + template < typename VertexProperty > struct internal_vertex_constructor + { + /** + * The @c type field provides a function object that constructs a + * new instance of @c VertexProperty from the name of the vertex (as + * determined by @c internal_vertex_name). The function object shall + * accept a vertex name and return a @c VertexProperty. Predefined + * options include: + * + * @c vertex_from_name<VertexProperty>: construct an instance of + * @c VertexProperty directly from the name. + * + * @c cannot_add_vertex<VertexProperty>: the default value, which + * throws an @c std::runtime_error if one attempts to add a vertex + * given just the name. + */ + typedef cannot_add_vertex< VertexProperty > type; + }; + + /** + * Extract the internal vertex constructor from a @c property structure by + * looking at its base. + */ + template < typename Tag, typename T, typename Base > + struct internal_vertex_constructor< property< Tag, T, Base > > + : internal_vertex_constructor< Base > + { + }; + + /******************************************************************* + * Named graph mixin * + *******************************************************************/ + + /** + * named_graph is a mixin that provides names for the vertices of a + * graph, including a mapping from names to vertices. Graph types that + * may or may not be have vertex names (depending on the properties + * supplied by the user) should use maybe_named_graph. + * + * Template parameters: + * + * Graph: the graph type that derives from named_graph + * + * Vertex: the type of a vertex descriptor in Graph. Note: we cannot + * use graph_traits here, because the Graph is not yet defined. + * + * VertexProperty: the type stored with each vertex in the Graph. + */ + template < typename Graph, typename Vertex, typename VertexProperty > + class named_graph + { + public: + /// The type of the function object that extracts names from vertex + /// properties. + typedef typename internal_vertex_name< VertexProperty >::type + extract_name_type; + /// The type of the "bundled" property, from which the name can be + /// extracted. + typedef typename lookup_one_property< VertexProperty, + vertex_bundle_t >::type bundled_vertex_property_type; + + /// The type of the function object that generates vertex properties + /// from names, for the implicit addition of vertices. + typedef typename internal_vertex_constructor< VertexProperty >::type + vertex_constructor_type; + + /// The type used to name vertices in the graph + typedef typename remove_cv< typename remove_reference< + typename extract_name_type::result_type >::type >::type + vertex_name_type; + + /// The type of vertex descriptors in the graph + typedef Vertex vertex_descriptor; + + private: + /// Key extractor for use with the multi_index_container + struct extract_name_from_vertex + { + typedef vertex_name_type result_type; + + extract_name_from_vertex( + Graph& graph, const extract_name_type& extract) + : graph(graph), extract(extract) + { + } + + const result_type& operator()(Vertex vertex) const + { + return extract(graph[vertex]); + } + + Graph& graph; + extract_name_type extract; + }; + + public: + /// The type that maps names to vertices + typedef multi_index::multi_index_container< Vertex, multi_index::indexed_by< - multi_index::hashed_unique<multi_index::tag<vertex_name_t>, - extract_name_from_vertex> > - > named_vertices_type; - - /// The set of vertices, indexed by name - typedef typename named_vertices_type::template index<vertex_name_t>::type - vertices_by_name_type; - - /// Construct an instance of the named graph mixin, using the given - /// function object to extract a name from the bundled property - /// associated with a vertex. - named_graph(const extract_name_type& extract = extract_name_type(), - const vertex_constructor_type& vertex_constructor - = vertex_constructor_type()); - - /// Notify the named_graph that we have added the given vertex. The - /// name of the vertex will be added to the mapping. - void added_vertex(Vertex vertex); - - /// Notify the named_graph that we are removing the given - /// vertex. The name of the vertex will be removed from the mapping. - template <typename VertexIterStability> - void removing_vertex(Vertex vertex, VertexIterStability); - - /// Notify the named_graph that we are clearing the graph. - /// This will clear out all of the name->vertex mappings - void clearing_graph(); - - /// Retrieve the derived instance - Graph& derived() { return static_cast<Graph&>(*this); } - const Graph& derived() const { return static_cast<const Graph&>(*this); } - - /// Extract the name from a vertex property instance - typename extract_name_type::result_type - extract_name(const bundled_vertex_property_type& property); - - /// Search for a vertex that has the given property (based on its - /// name) - optional<vertex_descriptor> - vertex_by_property(const bundled_vertex_property_type& property); - - /// Mapping from names to vertices - named_vertices_type named_vertices; - - /// Constructs a vertex from the name of that vertex - vertex_constructor_type vertex_constructor; -}; + multi_index::hashed_unique< multi_index::tag< vertex_name_t >, + extract_name_from_vertex > > > + named_vertices_type; + + /// The set of vertices, indexed by name + typedef + typename named_vertices_type::template index< vertex_name_t >::type + vertices_by_name_type; + + /// Construct an instance of the named graph mixin, using the given + /// function object to extract a name from the bundled property + /// associated with a vertex. + named_graph(const extract_name_type& extract = extract_name_type(), + const vertex_constructor_type& vertex_constructor + = vertex_constructor_type()); + + /// Notify the named_graph that we have added the given vertex. The + /// name of the vertex will be added to the mapping. + void added_vertex(Vertex vertex); + + /// Notify the named_graph that we are removing the given + /// vertex. The name of the vertex will be removed from the mapping. + template < typename VertexIterStability > + void removing_vertex(Vertex vertex, VertexIterStability); + + /// Notify the named_graph that we are clearing the graph. + /// This will clear out all of the name->vertex mappings + void clearing_graph(); + + /// Retrieve the derived instance + Graph& derived() { return static_cast< Graph& >(*this); } + const Graph& derived() const + { + return static_cast< const Graph& >(*this); + } + + /// Extract the name from a vertex property instance + typename extract_name_type::result_type extract_name( + const bundled_vertex_property_type& property); + + /// Search for a vertex that has the given property (based on its + /// name) + optional< vertex_descriptor > vertex_by_property( + const bundled_vertex_property_type& property); + + /// Mapping from names to vertices + named_vertices_type named_vertices; + + /// Constructs a vertex from the name of that vertex + vertex_constructor_type vertex_constructor; + }; /// Helper macro containing the template parameters of named_graph #define BGL_NAMED_GRAPH_PARAMS \ - typename Graph, typename Vertex, typename VertexProperty + typename Graph, typename Vertex, typename VertexProperty /// Helper macro containing the named_graph<...> instantiation -#define BGL_NAMED_GRAPH \ - named_graph<Graph, Vertex, VertexProperty> - -template<BGL_NAMED_GRAPH_PARAMS> -BGL_NAMED_GRAPH::named_graph(const extract_name_type& extract, - const vertex_constructor_type& vertex_constructor) - : named_vertices( - typename named_vertices_type::ctor_args_list( - boost::make_tuple( - boost::make_tuple( - 0, // initial number of buckets - extract_name_from_vertex(derived(), extract), - boost::hash<vertex_name_type>(), - std::equal_to<vertex_name_type>())))), - vertex_constructor(vertex_constructor) -{ -} - -template<BGL_NAMED_GRAPH_PARAMS> -inline void BGL_NAMED_GRAPH::added_vertex(Vertex vertex) -{ - named_vertices.insert(vertex); -} +#define BGL_NAMED_GRAPH named_graph< Graph, Vertex, VertexProperty > -template<BGL_NAMED_GRAPH_PARAMS> -template<typename VertexIterStability> -inline void BGL_NAMED_GRAPH::removing_vertex(Vertex vertex, VertexIterStability) -{ - Y_PRAGMA_DIAGNOSTIC_PUSH - Y_PRAGMA_NO_WSHADOW + template < BGL_NAMED_GRAPH_PARAMS > + BGL_NAMED_GRAPH::named_graph(const extract_name_type& extract, + const vertex_constructor_type& vertex_constructor) + : named_vertices(typename named_vertices_type::ctor_args_list( + boost::make_tuple(boost::make_tuple(0, // initial number of buckets + extract_name_from_vertex(derived(), extract), + boost::hash< vertex_name_type >(), + std::equal_to< vertex_name_type >())))) + , vertex_constructor(vertex_constructor) + { + } - BOOST_STATIC_ASSERT_MSG ((boost::is_base_of<boost::graph_detail::stable_tag, VertexIterStability>::value), "Named graphs cannot use vecS as vertex container and remove vertices; the lack of vertex descriptor stability (which iterator stability is a proxy for) means that the name -> vertex mapping would need to be completely rebuilt after each deletion. See https://svn.boost.org/trac/boost/ticket/7863 for more information and a test case."); - typedef typename BGL_NAMED_GRAPH::vertex_name_type vertex_name_type; - const vertex_name_type& vertex_name = extract_name(derived()[vertex]); - named_vertices.erase(vertex_name); + template < BGL_NAMED_GRAPH_PARAMS > + inline void BGL_NAMED_GRAPH::added_vertex(Vertex vertex) + { + named_vertices.insert(vertex); + } - Y_PRAGMA_DIAGNOSTIC_POP -} + template < BGL_NAMED_GRAPH_PARAMS > + template < typename VertexIterStability > + inline void BGL_NAMED_GRAPH::removing_vertex( + Vertex vertex, VertexIterStability) + { + BOOST_STATIC_ASSERT_MSG( + (boost::is_base_of< boost::graph_detail::stable_tag, + VertexIterStability >::value), + "Named graphs cannot use vecS as vertex container and remove " + "vertices; the lack of vertex descriptor stability (which iterator " + "stability is a proxy for) means that the name -> vertex mapping " + "would need to be completely rebuilt after each deletion. See " + "https://svn.boost.org/trac/boost/ticket/7863 for more information " + "and a test case."); + typedef typename BGL_NAMED_GRAPH::vertex_name_type vertex_name_type; + const vertex_name_type& vertex_name = extract_name(derived()[vertex]); + named_vertices.erase(vertex_name); + } -template<BGL_NAMED_GRAPH_PARAMS> -inline void BGL_NAMED_GRAPH::clearing_graph() -{ - named_vertices.clear(); -} + template < BGL_NAMED_GRAPH_PARAMS > + inline void BGL_NAMED_GRAPH::clearing_graph() + { + named_vertices.clear(); + } -template<BGL_NAMED_GRAPH_PARAMS> -typename BGL_NAMED_GRAPH::extract_name_type::result_type -BGL_NAMED_GRAPH::extract_name(const bundled_vertex_property_type& property) -{ - return named_vertices.key_extractor().extract(property); -} + template < BGL_NAMED_GRAPH_PARAMS > + typename BGL_NAMED_GRAPH::extract_name_type::result_type + BGL_NAMED_GRAPH::extract_name(const bundled_vertex_property_type& property) + { + return named_vertices.key_extractor().extract(property); + } -template<BGL_NAMED_GRAPH_PARAMS> -optional<typename BGL_NAMED_GRAPH::vertex_descriptor> -BGL_NAMED_GRAPH:: -vertex_by_property(const bundled_vertex_property_type& property) -{ - return find_vertex(extract_name(property), *this); -} + template < BGL_NAMED_GRAPH_PARAMS > + optional< typename BGL_NAMED_GRAPH::vertex_descriptor > + BGL_NAMED_GRAPH::vertex_by_property( + const bundled_vertex_property_type& property) + { + return find_vertex(extract_name(property), *this); + } -/// Retrieve the vertex associated with the given name -template<BGL_NAMED_GRAPH_PARAMS> -optional<Vertex> -find_vertex(typename BGL_NAMED_GRAPH::vertex_name_type const& name, - const BGL_NAMED_GRAPH& g) -{ - typedef typename BGL_NAMED_GRAPH::vertices_by_name_type - vertices_by_name_type; + /// Retrieve the vertex associated with the given name + template < BGL_NAMED_GRAPH_PARAMS > + optional< Vertex > find_vertex( + typename BGL_NAMED_GRAPH::vertex_name_type const& name, + const BGL_NAMED_GRAPH& g) + { + typedef typename BGL_NAMED_GRAPH::vertices_by_name_type + vertices_by_name_type; - // Retrieve the set of vertices indexed by name - vertices_by_name_type const& vertices_by_name - = g.named_vertices.template get<vertex_name_t>(); + // Retrieve the set of vertices indexed by name + vertices_by_name_type const& vertices_by_name + = g.named_vertices.template get< vertex_name_t >(); - /// Look for a vertex with the given name - typename vertices_by_name_type::const_iterator iter - = vertices_by_name.find(name); + /// Look for a vertex with the given name + typename vertices_by_name_type::const_iterator iter + = vertices_by_name.find(name); - if (iter == vertices_by_name.end()) - return optional<Vertex>(); // vertex not found - else - return *iter; -} + if (iter == vertices_by_name.end()) + return optional< Vertex >(); // vertex not found + else + return *iter; + } -/// Retrieve the vertex associated with the given name, or add a new -/// vertex with that name if no such vertex is available. -/// Note: This is enabled only when the vertex property type is different -/// from the vertex name to avoid ambiguous overload problems with -/// the add_vertex() function that takes a vertex property. -template<BGL_NAMED_GRAPH_PARAMS> - typename disable_if<is_same< - typename BGL_NAMED_GRAPH::vertex_name_type, - VertexProperty - >, -Vertex>::type -add_vertex(typename BGL_NAMED_GRAPH::vertex_name_type const& name, - BGL_NAMED_GRAPH& g) -{ - if (optional<Vertex> vertex = find_vertex(name, g)) - /// We found the vertex, so return it - return *vertex; - else - /// There is no vertex with the given name, so create one - return add_vertex(g.vertex_constructor(name), g.derived()); -} + /// Retrieve the vertex associated with the given name, or add a new + /// vertex with that name if no such vertex is available. + /// Note: This is enabled only when the vertex property type is different + /// from the vertex name to avoid ambiguous overload problems with + /// the add_vertex() function that takes a vertex property. + template < BGL_NAMED_GRAPH_PARAMS > + typename disable_if< + is_same< typename BGL_NAMED_GRAPH::vertex_name_type, VertexProperty >, + Vertex >::type + add_vertex(typename BGL_NAMED_GRAPH::vertex_name_type const& name, + BGL_NAMED_GRAPH& g) + { + if (optional< Vertex > vertex = find_vertex(name, g)) + /// We found the vertex, so return it + return *vertex; + else + /// There is no vertex with the given name, so create one + return add_vertex(g.vertex_constructor(name), g.derived()); + } -/// Add an edge using vertex names to refer to the vertices -template<BGL_NAMED_GRAPH_PARAMS> -std::pair<typename graph_traits<Graph>::edge_descriptor, bool> -add_edge(typename BGL_NAMED_GRAPH::vertex_name_type const& u_name, - typename BGL_NAMED_GRAPH::vertex_name_type const& v_name, - BGL_NAMED_GRAPH& g) -{ - return add_edge(add_vertex(u_name, g.derived()), - add_vertex(v_name, g.derived()), - g.derived()); -} + /// Add an edge using vertex names to refer to the vertices + template < BGL_NAMED_GRAPH_PARAMS > + std::pair< typename graph_traits< Graph >::edge_descriptor, bool > add_edge( + typename BGL_NAMED_GRAPH::vertex_name_type const& u_name, + typename BGL_NAMED_GRAPH::vertex_name_type const& v_name, + BGL_NAMED_GRAPH& g) + { + return add_edge(add_vertex(u_name, g.derived()), + add_vertex(v_name, g.derived()), g.derived()); + } -/// Add an edge using vertex descriptors or names to refer to the vertices -template<BGL_NAMED_GRAPH_PARAMS> -std::pair<typename graph_traits<Graph>::edge_descriptor, bool> -add_edge(typename BGL_NAMED_GRAPH::vertex_descriptor const& u, - typename BGL_NAMED_GRAPH::vertex_name_type const& v_name, - BGL_NAMED_GRAPH& g) -{ - return add_edge(u, - add_vertex(v_name, g.derived()), - g.derived()); -} + /// Add an edge using vertex descriptors or names to refer to the vertices + template < BGL_NAMED_GRAPH_PARAMS > + std::pair< typename graph_traits< Graph >::edge_descriptor, bool > add_edge( + typename BGL_NAMED_GRAPH::vertex_descriptor const& u, + typename BGL_NAMED_GRAPH::vertex_name_type const& v_name, + BGL_NAMED_GRAPH& g) + { + return add_edge(u, add_vertex(v_name, g.derived()), g.derived()); + } -/// Add an edge using vertex descriptors or names to refer to the vertices -template<BGL_NAMED_GRAPH_PARAMS> -std::pair<typename graph_traits<Graph>::edge_descriptor, bool> -add_edge(typename BGL_NAMED_GRAPH::vertex_name_type const& u_name, - typename BGL_NAMED_GRAPH::vertex_descriptor const& v, - BGL_NAMED_GRAPH& g) -{ - return add_edge(add_vertex(u_name, g.derived()), - v, - g.derived()); -} + /// Add an edge using vertex descriptors or names to refer to the vertices + template < BGL_NAMED_GRAPH_PARAMS > + std::pair< typename graph_traits< Graph >::edge_descriptor, bool > add_edge( + typename BGL_NAMED_GRAPH::vertex_name_type const& u_name, + typename BGL_NAMED_GRAPH::vertex_descriptor const& v, + BGL_NAMED_GRAPH& g) + { + return add_edge(add_vertex(u_name, g.derived()), v, g.derived()); + } -// Overloads to support EdgeMutablePropertyGraph graphs -template <BGL_NAMED_GRAPH_PARAMS> -std::pair<typename graph_traits<Graph>::edge_descriptor, bool> -add_edge(typename BGL_NAMED_GRAPH::vertex_descriptor const& u, - typename BGL_NAMED_GRAPH::vertex_name_type const& v_name, - typename edge_property_type<Graph>::type const& p, - BGL_NAMED_GRAPH& g) { - return add_edge(u, add_vertex(v_name, g.derived()), p, g.derived()); -} + // Overloads to support EdgeMutablePropertyGraph graphs + template < BGL_NAMED_GRAPH_PARAMS > + std::pair< typename graph_traits< Graph >::edge_descriptor, bool > add_edge( + typename BGL_NAMED_GRAPH::vertex_descriptor const& u, + typename BGL_NAMED_GRAPH::vertex_name_type const& v_name, + typename edge_property_type< Graph >::type const& p, BGL_NAMED_GRAPH& g) + { + return add_edge(u, add_vertex(v_name, g.derived()), p, g.derived()); + } -template <BGL_NAMED_GRAPH_PARAMS> -std::pair<typename graph_traits<Graph>::edge_descriptor, bool> -add_edge(typename BGL_NAMED_GRAPH::vertex_name_type const& u_name, - typename BGL_NAMED_GRAPH::vertex_descriptor const& v, - typename edge_property_type<Graph>::type const& p, - BGL_NAMED_GRAPH& g) { - return add_edge(add_vertex(u_name, g.derived()), v, p, g.derived()); -} + template < BGL_NAMED_GRAPH_PARAMS > + std::pair< typename graph_traits< Graph >::edge_descriptor, bool > add_edge( + typename BGL_NAMED_GRAPH::vertex_name_type const& u_name, + typename BGL_NAMED_GRAPH::vertex_descriptor const& v, + typename edge_property_type< Graph >::type const& p, BGL_NAMED_GRAPH& g) + { + return add_edge(add_vertex(u_name, g.derived()), v, p, g.derived()); + } -template <BGL_NAMED_GRAPH_PARAMS> -std::pair<typename graph_traits<Graph>::edge_descriptor, bool> -add_edge(typename BGL_NAMED_GRAPH::vertex_name_type const& u_name, - typename BGL_NAMED_GRAPH::vertex_name_type const& v_name, - typename edge_property_type<Graph>::type const& p, - BGL_NAMED_GRAPH& g) { - return add_edge(add_vertex(u_name, g.derived()), - add_vertex(v_name, g.derived()), p, g.derived()); -} + template < BGL_NAMED_GRAPH_PARAMS > + std::pair< typename graph_traits< Graph >::edge_descriptor, bool > add_edge( + typename BGL_NAMED_GRAPH::vertex_name_type const& u_name, + typename BGL_NAMED_GRAPH::vertex_name_type const& v_name, + typename edge_property_type< Graph >::type const& p, BGL_NAMED_GRAPH& g) + { + return add_edge(add_vertex(u_name, g.derived()), + add_vertex(v_name, g.derived()), p, g.derived()); + } #undef BGL_NAMED_GRAPH #undef BGL_NAMED_GRAPH_PARAMS -/******************************************************************* - * Maybe named graph mixin * - *******************************************************************/ - -/** - * A graph mixin that can provide a mapping from names to vertices, - * and use that mapping to simplify creation and manipulation of - * graphs. - */ -template<typename Graph, typename Vertex, typename VertexProperty, - typename ExtractName - = typename internal_vertex_name<VertexProperty>::type> -struct maybe_named_graph : public named_graph<Graph, Vertex, VertexProperty> -{ -}; - -/** - * A graph mixin that can provide a mapping from names to vertices, - * and use that mapping to simplify creation and manipulation of - * graphs. This partial specialization turns off this functionality - * when the @c VertexProperty does not have an internal vertex name. - */ -template<typename Graph, typename Vertex, typename VertexProperty> -struct maybe_named_graph<Graph, Vertex, VertexProperty, void> -{ - /// The type of the "bundled" property, from which the name can be - /// extracted. - typedef typename lookup_one_property<VertexProperty, vertex_bundle_t>::type - bundled_vertex_property_type; - - /// Notify the named_graph that we have added the given vertex. This - /// is a no-op. - void added_vertex(Vertex) { } - - /// Notify the named_graph that we are removing the given - /// vertex. This is a no-op. - template <typename VertexIterStability> - void removing_vertex(Vertex, VertexIterStability) { } - - /// Notify the named_graph that we are clearing the graph. This is a - /// no-op. - void clearing_graph() { } - - /// Search for a vertex that has the given property (based on its - /// name). This always returns an empty optional<> - optional<Vertex> - vertex_by_property(const bundled_vertex_property_type&) - { - return optional<Vertex>(); - } -}; - -} } // end namespace boost::graph + /******************************************************************* + * Maybe named graph mixin * + *******************************************************************/ + + /** + * A graph mixin that can provide a mapping from names to vertices, + * and use that mapping to simplify creation and manipulation of + * graphs. + */ + template < typename Graph, typename Vertex, typename VertexProperty, + typename ExtractName = + typename internal_vertex_name< VertexProperty >::type > + struct maybe_named_graph + : public named_graph< Graph, Vertex, VertexProperty > + { + }; + + /** + * A graph mixin that can provide a mapping from names to vertices, + * and use that mapping to simplify creation and manipulation of + * graphs. This partial specialization turns off this functionality + * when the @c VertexProperty does not have an internal vertex name. + */ + template < typename Graph, typename Vertex, typename VertexProperty > + struct maybe_named_graph< Graph, Vertex, VertexProperty, void > + { + /// The type of the "bundled" property, from which the name can be + /// extracted. + typedef typename lookup_one_property< VertexProperty, + vertex_bundle_t >::type bundled_vertex_property_type; + + /// Notify the named_graph that we have added the given vertex. This + /// is a no-op. + void added_vertex(Vertex) {} + + /// Notify the named_graph that we are removing the given + /// vertex. This is a no-op. + template < typename VertexIterStability > + void removing_vertex(Vertex, VertexIterStability) + { + } + + /// Notify the named_graph that we are clearing the graph. This is a + /// no-op. + void clearing_graph() {} + + /// Search for a vertex that has the given property (based on its + /// name). This always returns an empty optional<> + optional< Vertex > vertex_by_property( + const bundled_vertex_property_type&) + { + return optional< Vertex >(); + } + }; + +} +} // end namespace boost::graph #endif // BOOST_GRAPH_NAMED_GRAPH_HPP diff --git a/contrib/restricted/boost/graph/include/boost/graph/numeric_values.hpp b/contrib/restricted/boost/graph/include/boost/graph/numeric_values.hpp index ad01837270..d4d54e01ca 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/numeric_values.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/numeric_values.hpp @@ -12,39 +12,40 @@ namespace boost { -#define BOOST_GRAPH_SPECIALIZE_NUMERIC_FLOAT(type) \ - template <> struct numeric_values<type> { \ - typedef type value_type; \ - static type zero() { return 0.0; } \ - static type infinity() { return std::numeric_limits<type>::infinity(); } \ +#define BOOST_GRAPH_SPECIALIZE_NUMERIC_FLOAT(type) \ + template <> struct numeric_values< type > \ + { \ + typedef type value_type; \ + static type zero() { return 0.0; } \ + static type infinity() \ + { \ + return std::numeric_limits< type >::infinity(); \ + } \ }; - /** - * This generic type reports various numeric values for some type. In the - * general case, numeric values simply treat their maximum value as infinity - * and the default-constructed value as 0. - * - * Specializations of this template can redefine the notions of zero and - * infinity for various types. For example, the class is specialized for - * floating point types to use the built in notion of infinity. - */ - template <typename T> - struct numeric_values - { - typedef T value_type; - - static T zero() - { return T(); } - - static T infinity() - { return (std::numeric_limits<T>::max)(); } - }; +/** + * This generic type reports various numeric values for some type. In the + * general case, numeric values simply treat their maximum value as infinity + * and the default-constructed value as 0. + * + * Specializations of this template can redefine the notions of zero and + * infinity for various types. For example, the class is specialized for + * floating point types to use the built in notion of infinity. + */ +template < typename T > struct numeric_values +{ + typedef T value_type; + + static T zero() { return T(); } + + static T infinity() { return (std::numeric_limits< T >::max)(); } +}; - // Specializations for floating point types refer to 0.0 and their infinity - // value defined by numeric_limits. - BOOST_GRAPH_SPECIALIZE_NUMERIC_FLOAT(float) - BOOST_GRAPH_SPECIALIZE_NUMERIC_FLOAT(double) - BOOST_GRAPH_SPECIALIZE_NUMERIC_FLOAT(long double) +// Specializations for floating point types refer to 0.0 and their infinity +// value defined by numeric_limits. +BOOST_GRAPH_SPECIALIZE_NUMERIC_FLOAT(float) +BOOST_GRAPH_SPECIALIZE_NUMERIC_FLOAT(double) +BOOST_GRAPH_SPECIALIZE_NUMERIC_FLOAT(long double) #undef BOOST_GRAPH_SPECIALIZE_NUMERIC_VALUE } diff --git a/contrib/restricted/boost/graph/include/boost/graph/overloading.hpp b/contrib/restricted/boost/graph/include/boost/graph/overloading.hpp index a952e22fa8..5a4cc2525a 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/overloading.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/overloading.hpp @@ -17,24 +17,34 @@ #include <boost/type_traits/is_base_and_derived.hpp> #include <boost/utility/enable_if.hpp> -namespace boost { namespace graph { namespace detail { +namespace boost +{ +namespace graph +{ + namespace detail + { -struct no_parameter {}; + struct no_parameter + { + }; -} } } // end namespace boost::graph::detail + } +} +} // end namespace boost::graph::detail #ifndef BOOST_NO_SFINAE -#define BOOST_GRAPH_ENABLE_IF_MODELS(Graph, Tag, Type) \ - typename enable_if_c<(is_base_and_derived< \ - Tag, \ - typename graph_traits<Graph>::traversal_category>::value), \ - Type>::type - -#define BOOST_GRAPH_ENABLE_IF_MODELS_PARM(Graph, Tag) \ - , BOOST_GRAPH_ENABLE_IF_MODELS(Graph, Tag, \ - ::boost::graph::detail::no_parameter) \ - = ::boost::graph::detail::no_parameter() +#define BOOST_GRAPH_ENABLE_IF_MODELS(Graph, Tag, Type) \ + typename enable_if_c< \ + (is_base_and_derived< Tag, \ + typename graph_traits< Graph >::traversal_category >::value), \ + Type >::type + +#define BOOST_GRAPH_ENABLE_IF_MODELS_PARM(Graph, Tag) \ + , \ + BOOST_GRAPH_ENABLE_IF_MODELS( \ + Graph, Tag, ::boost::graph::detail::no_parameter) \ + = ::boost::graph::detail::no_parameter() #else diff --git a/contrib/restricted/boost/graph/include/boost/graph/properties.hpp b/contrib/restricted/boost/graph/include/boost/graph/properties.hpp index 660102b459..988d310397 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/properties.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/properties.hpp @@ -27,327 +27,344 @@ #include <boost/mpl/not.hpp> #include <boost/mpl/if.hpp> -namespace boost { - - enum default_color_type { white_color, gray_color, green_color, red_color, black_color }; - - template <class ColorValue> - struct color_traits { +namespace boost +{ + +enum default_color_type +{ + white_color, + gray_color, + green_color, + red_color, + black_color +}; + +template < class ColorValue > struct color_traits +{ static default_color_type white() { return white_color; } static default_color_type gray() { return gray_color; } static default_color_type green() { return green_color; } static default_color_type red() { return red_color; } static default_color_type black() { return black_color; } - }; - - // These functions are now obsolete, replaced by color_traits. - inline default_color_type white(default_color_type) { return white_color; } - inline default_color_type gray(default_color_type) { return gray_color; } - inline default_color_type green(default_color_type) { return green_color; } - inline default_color_type red(default_color_type) { return red_color; } - inline default_color_type black(default_color_type) { return black_color; } - - - struct graph_property_tag { }; - struct vertex_property_tag { }; - struct edge_property_tag { }; - - // See examples/edge_property.cpp for how to use this. -#define BOOST_INSTALL_PROPERTY(KIND, NAME) \ - template <> struct property_kind<KIND##_##NAME##_t> { \ - typedef KIND##_property_tag type; \ - } - -#define BOOST_DEF_PROPERTY(KIND, NAME) \ - enum KIND##_##NAME##_t { KIND##_##NAME }; \ - BOOST_INSTALL_PROPERTY(KIND, NAME) - - // These three are defined in boost/pending/property.hpp - BOOST_INSTALL_PROPERTY(vertex, all); - BOOST_INSTALL_PROPERTY(edge, all); - BOOST_INSTALL_PROPERTY(graph, all); - BOOST_DEF_PROPERTY(vertex, index); - BOOST_DEF_PROPERTY(vertex, index1); - BOOST_DEF_PROPERTY(vertex, index2); - BOOST_DEF_PROPERTY(vertex, root); - BOOST_DEF_PROPERTY(edge, index); - BOOST_DEF_PROPERTY(edge, name); - BOOST_DEF_PROPERTY(edge, weight); - BOOST_DEF_PROPERTY(edge, weight2); - BOOST_DEF_PROPERTY(edge, color); - BOOST_DEF_PROPERTY(vertex, name); - BOOST_DEF_PROPERTY(graph, name); - BOOST_DEF_PROPERTY(vertex, distance); - BOOST_DEF_PROPERTY(vertex, distance2); - BOOST_DEF_PROPERTY(vertex, color); - BOOST_DEF_PROPERTY(vertex, degree); - BOOST_DEF_PROPERTY(vertex, in_degree); - BOOST_DEF_PROPERTY(vertex, out_degree); - BOOST_DEF_PROPERTY(vertex, current_degree); - BOOST_DEF_PROPERTY(vertex, priority); - BOOST_DEF_PROPERTY(vertex, discover_time); - BOOST_DEF_PROPERTY(vertex, finish_time); - BOOST_DEF_PROPERTY(vertex, predecessor); - BOOST_DEF_PROPERTY(vertex, rank); - BOOST_DEF_PROPERTY(vertex, centrality); - BOOST_DEF_PROPERTY(vertex, lowpoint); - BOOST_DEF_PROPERTY(vertex, potential); - BOOST_DEF_PROPERTY(vertex, update); - BOOST_DEF_PROPERTY(vertex, underlying); - BOOST_DEF_PROPERTY(edge, reverse); - BOOST_DEF_PROPERTY(edge, capacity); - BOOST_DEF_PROPERTY(edge, flow); - BOOST_DEF_PROPERTY(edge, residual_capacity); - BOOST_DEF_PROPERTY(edge, centrality); - BOOST_DEF_PROPERTY(edge, discover_time); - BOOST_DEF_PROPERTY(edge, update); - BOOST_DEF_PROPERTY(edge, finished); - BOOST_DEF_PROPERTY(edge, underlying); - BOOST_DEF_PROPERTY(graph, visitor); - - // These tags are used for property bundles - // These three are defined in boost/pending/property.hpp - BOOST_INSTALL_PROPERTY(graph, bundle); - BOOST_INSTALL_PROPERTY(vertex, bundle); - BOOST_INSTALL_PROPERTY(edge, bundle); - - // These tags are used to denote the owners and local descriptors - // for the vertices and edges of a distributed graph. - BOOST_DEF_PROPERTY(vertex, global); - BOOST_DEF_PROPERTY(vertex, owner); - BOOST_DEF_PROPERTY(vertex, local); - BOOST_DEF_PROPERTY(edge, global); - BOOST_DEF_PROPERTY(edge, owner); - BOOST_DEF_PROPERTY(edge, local); - BOOST_DEF_PROPERTY(vertex, local_index); - BOOST_DEF_PROPERTY(edge, local_index); +}; + +// These functions are now obsolete, replaced by color_traits. +inline default_color_type white(default_color_type) { return white_color; } +inline default_color_type gray(default_color_type) { return gray_color; } +inline default_color_type green(default_color_type) { return green_color; } +inline default_color_type red(default_color_type) { return red_color; } +inline default_color_type black(default_color_type) { return black_color; } + +struct graph_property_tag +{ +}; +struct vertex_property_tag +{ +}; +struct edge_property_tag +{ +}; + +// See examples/edge_property.cpp for how to use this. +#define BOOST_INSTALL_PROPERTY(KIND, NAME) \ + template <> struct property_kind< KIND##_##NAME##_t > \ + { \ + typedef KIND##_property_tag type; \ + } + +#define BOOST_DEF_PROPERTY(KIND, NAME) \ + enum KIND##_##NAME##_t { KIND##_##NAME }; \ + BOOST_INSTALL_PROPERTY(KIND, NAME) + +// These three are defined in boost/pending/property.hpp +BOOST_INSTALL_PROPERTY(vertex, all); +BOOST_INSTALL_PROPERTY(edge, all); +BOOST_INSTALL_PROPERTY(graph, all); +BOOST_DEF_PROPERTY(vertex, index); +BOOST_DEF_PROPERTY(vertex, index1); +BOOST_DEF_PROPERTY(vertex, index2); +BOOST_DEF_PROPERTY(vertex, root); +BOOST_DEF_PROPERTY(edge, index); +BOOST_DEF_PROPERTY(edge, name); +BOOST_DEF_PROPERTY(edge, weight); +BOOST_DEF_PROPERTY(edge, weight2); +BOOST_DEF_PROPERTY(edge, color); +BOOST_DEF_PROPERTY(vertex, name); +BOOST_DEF_PROPERTY(graph, name); +BOOST_DEF_PROPERTY(vertex, distance); +BOOST_DEF_PROPERTY(vertex, distance2); +BOOST_DEF_PROPERTY(vertex, color); +BOOST_DEF_PROPERTY(vertex, degree); +BOOST_DEF_PROPERTY(vertex, in_degree); +BOOST_DEF_PROPERTY(vertex, out_degree); +BOOST_DEF_PROPERTY(vertex, current_degree); +BOOST_DEF_PROPERTY(vertex, priority); +BOOST_DEF_PROPERTY(vertex, discover_time); +BOOST_DEF_PROPERTY(vertex, finish_time); +BOOST_DEF_PROPERTY(vertex, predecessor); +BOOST_DEF_PROPERTY(vertex, rank); +BOOST_DEF_PROPERTY(vertex, centrality); +BOOST_DEF_PROPERTY(vertex, lowpoint); +BOOST_DEF_PROPERTY(vertex, potential); +BOOST_DEF_PROPERTY(vertex, update); +BOOST_DEF_PROPERTY(vertex, underlying); +BOOST_DEF_PROPERTY(edge, reverse); +BOOST_DEF_PROPERTY(edge, capacity); +BOOST_DEF_PROPERTY(edge, flow); +BOOST_DEF_PROPERTY(edge, residual_capacity); +BOOST_DEF_PROPERTY(edge, centrality); +BOOST_DEF_PROPERTY(edge, discover_time); +BOOST_DEF_PROPERTY(edge, update); +BOOST_DEF_PROPERTY(edge, finished); +BOOST_DEF_PROPERTY(edge, underlying); +BOOST_DEF_PROPERTY(graph, visitor); + +// These tags are used for property bundles +// These three are defined in boost/pending/property.hpp +BOOST_INSTALL_PROPERTY(graph, bundle); +BOOST_INSTALL_PROPERTY(vertex, bundle); +BOOST_INSTALL_PROPERTY(edge, bundle); + +// These tags are used to denote the owners and local descriptors +// for the vertices and edges of a distributed graph. +BOOST_DEF_PROPERTY(vertex, global); +BOOST_DEF_PROPERTY(vertex, owner); +BOOST_DEF_PROPERTY(vertex, local); +BOOST_DEF_PROPERTY(edge, global); +BOOST_DEF_PROPERTY(edge, owner); +BOOST_DEF_PROPERTY(edge, local); +BOOST_DEF_PROPERTY(vertex, local_index); +BOOST_DEF_PROPERTY(edge, local_index); #undef BOOST_DEF_PROPERTY - namespace detail { +namespace detail +{ - template <typename G, typename Tag> - struct property_kind_from_graph: property_kind<Tag> {}; + template < typename G, typename Tag > + struct property_kind_from_graph : property_kind< Tag > + { + }; #ifndef BOOST_GRAPH_NO_BUNDLED_PROPERTIES - template <typename G, typename R, typename T> - struct property_kind_from_graph<G, R T::*> { - typedef typename boost::mpl::if_< - boost::is_base_of<T, typename vertex_bundle_type<G>::type>, - vertex_property_tag, + template < typename G, typename R, typename T > + struct property_kind_from_graph< G, R T::* > + { + typedef typename boost::mpl::if_< + boost::is_base_of< T, typename vertex_bundle_type< G >::type >, + vertex_property_tag, + typename boost::mpl::if_< + boost::is_base_of< T, typename edge_bundle_type< G >::type >, + edge_property_tag, typename boost::mpl::if_< - boost::is_base_of<T, typename edge_bundle_type<G>::type>, - edge_property_tag, - typename boost::mpl::if_< - boost::is_base_of<T, typename graph_bundle_type<G>::type>, - graph_property_tag, - void>::type>::type>::type type; + boost::is_base_of< T, + typename graph_bundle_type< G >::type >, + graph_property_tag, void >::type >::type >::type type; }; #endif - struct dummy_edge_property_selector { - template <class Graph, class Property, class Tag> - struct bind_ { - typedef identity_property_map type; - typedef identity_property_map const_type; - }; + struct dummy_edge_property_selector + { + template < class Graph, class Property, class Tag > struct bind_ + { + typedef identity_property_map type; + typedef identity_property_map const_type; + }; }; - struct dummy_vertex_property_selector { - template <class Graph, class Property, class Tag> - struct bind_ { - typedef identity_property_map type; - typedef identity_property_map const_type; - }; + struct dummy_vertex_property_selector + { + template < class Graph, class Property, class Tag > struct bind_ + { + typedef identity_property_map type; + typedef identity_property_map const_type; + }; }; - } // namespace detail +} // namespace detail - // Graph classes can either partially specialize property_map - // or they can specialize these two selector classes. - template <class GraphTag> - struct edge_property_selector { +// Graph classes can either partially specialize property_map +// or they can specialize these two selector classes. +template < class GraphTag > struct edge_property_selector +{ typedef detail::dummy_edge_property_selector type; - }; +}; - template <class GraphTag> - struct vertex_property_selector { +template < class GraphTag > struct vertex_property_selector +{ typedef detail::dummy_vertex_property_selector type; - }; +}; - namespace detail { +namespace detail +{ - template <typename A> struct return_void {typedef void type;}; + template < typename A > struct return_void + { + typedef void type; + }; - template <typename Graph, typename Enable = void> - struct graph_tag_or_void { - typedef void type; + template < typename Graph, typename Enable = void > struct graph_tag_or_void + { + typedef void type; }; - template <typename Graph> - struct graph_tag_or_void<Graph, typename return_void<typename Graph::graph_tag>::type> { - typedef typename Graph::graph_tag type; + template < typename Graph > + struct graph_tag_or_void< Graph, + typename return_void< typename Graph::graph_tag >::type > + { + typedef typename Graph::graph_tag type; }; - template <class Graph, class PropertyTag> + template < class Graph, class PropertyTag > struct edge_property_map - : edge_property_selector< - typename graph_tag_or_void<Graph>::type - >::type::template bind_< - Graph, - typename edge_property_type<Graph>::type, - PropertyTag> - {}; - template <class Graph, class PropertyTag> + : edge_property_selector< typename graph_tag_or_void< Graph >::type >:: + type::template bind_< Graph, + typename edge_property_type< Graph >::type, PropertyTag > + { + }; + template < class Graph, class PropertyTag > struct vertex_property_map - : vertex_property_selector< - typename graph_tag_or_void<Graph>::type - >::type::template bind_< - Graph, - typename vertex_property_type<Graph>::type, - PropertyTag> - {}; - } // namespace detail - - template <class Graph, class Property, class Enable = void> - struct property_map: - mpl::if_< - is_same<typename detail::property_kind_from_graph<Graph, Property>::type, edge_property_tag>, - detail::edge_property_map<Graph, Property>, - detail::vertex_property_map<Graph, Property> >::type - {}; - - // shortcut for accessing the value type of the property map - template <class Graph, class Property> - class property_map_value { - typedef typename property_map<Graph, Property>::const_type PMap; - public: - typedef typename property_traits<PMap>::value_type type; - }; - - template <class Graph, class Property> - class graph_property { - public: + : vertex_property_selector< typename graph_tag_or_void< Graph >::type >:: + type::template bind_< Graph, + typename vertex_property_type< Graph >::type, PropertyTag > + { + }; +} // namespace detail + +template < class Graph, class Property, class Enable = void > +struct property_map +: mpl::if_< is_same< typename detail::property_kind_from_graph< Graph, + Property >::type, + edge_property_tag >, + detail::edge_property_map< Graph, Property >, + detail::vertex_property_map< Graph, Property > >::type +{ +}; + +// shortcut for accessing the value type of the property map +template < class Graph, class Property > class property_map_value +{ + typedef typename property_map< Graph, Property >::const_type PMap; + +public: + typedef typename property_traits< PMap >::value_type type; +}; + +template < class Graph, class Property > class graph_property +{ +public: typedef typename property_value< - typename boost::graph_property_type<Graph>::type, Property - >::type type; - }; - - template <typename Graph> struct vertex_property: vertex_property_type<Graph> {}; - template <typename Graph> struct edge_property: edge_property_type<Graph> {}; - - template <typename Graph> - class degree_property_map - : public put_get_helper<typename graph_traits<Graph>::degree_size_type, - degree_property_map<Graph> > - { - public: - typedef typename graph_traits<Graph>::vertex_descriptor key_type; - typedef typename graph_traits<Graph>::degree_size_type value_type; + typename boost::graph_property_type< Graph >::type, Property >::type + type; +}; + +template < typename Graph > +struct vertex_property : vertex_property_type< Graph > +{ +}; +template < typename Graph > struct edge_property : edge_property_type< Graph > +{ +}; + +template < typename Graph > +class degree_property_map +: public put_get_helper< typename graph_traits< Graph >::degree_size_type, + degree_property_map< Graph > > +{ +public: + typedef typename graph_traits< Graph >::vertex_descriptor key_type; + typedef typename graph_traits< Graph >::degree_size_type value_type; typedef value_type reference; typedef readable_property_map_tag category; - degree_property_map(const Graph& g) : m_g(g) { } - value_type operator[](const key_type& v) const { - return degree(v, m_g); - } - private: + degree_property_map(const Graph& g) : m_g(g) {} + value_type operator[](const key_type& v) const { return degree(v, m_g); } + +private: const Graph& m_g; - }; - template <typename Graph> - inline degree_property_map<Graph> - make_degree_map(const Graph& g) { - return degree_property_map<Graph>(g); - } - - //======================================================================== - // Iterator Property Map Generating Functions contributed by - // Kevin Vanhorn. (see also the property map generating functions - // in boost/property_map/property_map.hpp) +}; +template < typename Graph > +inline degree_property_map< Graph > make_degree_map(const Graph& g) +{ + return degree_property_map< Graph >(g); +} + +//======================================================================== +// Iterator Property Map Generating Functions contributed by +// Kevin Vanhorn. (see also the property map generating functions +// in boost/property_map/property_map.hpp) #if !defined(BOOST_NO_STD_ITERATOR_TRAITS) - // A helper function for creating a vertex property map out of a - // random access iterator and the internal vertex index map from a - // graph. - template <class PropertyGraph, class RandomAccessIterator> - inline - iterator_property_map< - RandomAccessIterator, - typename property_map<PropertyGraph, vertex_index_t>::type, - typename std::iterator_traits<RandomAccessIterator>::value_type, - typename std::iterator_traits<RandomAccessIterator>::reference - > - make_iterator_vertex_map(RandomAccessIterator iter, const PropertyGraph& g) - { +// A helper function for creating a vertex property map out of a +// random access iterator and the internal vertex index map from a +// graph. +template < class PropertyGraph, class RandomAccessIterator > +inline iterator_property_map< RandomAccessIterator, + typename property_map< PropertyGraph, vertex_index_t >::type, + typename std::iterator_traits< RandomAccessIterator >::value_type, + typename std::iterator_traits< RandomAccessIterator >::reference > +make_iterator_vertex_map(RandomAccessIterator iter, const PropertyGraph& g) +{ return make_iterator_property_map(iter, get(vertex_index, g)); - } - - // Use this next function when vertex_descriptor is known to be an - // integer type, with values ranging from 0 to num_vertices(g). - // - template <class RandomAccessIterator> - inline - iterator_property_map< - RandomAccessIterator, - identity_property_map, - typename std::iterator_traits<RandomAccessIterator>::value_type, - typename std::iterator_traits<RandomAccessIterator>::reference - > - make_iterator_vertex_map(RandomAccessIterator iter) - { +} + +// Use this next function when vertex_descriptor is known to be an +// integer type, with values ranging from 0 to num_vertices(g). +// +template < class RandomAccessIterator > +inline iterator_property_map< RandomAccessIterator, identity_property_map, + typename std::iterator_traits< RandomAccessIterator >::value_type, + typename std::iterator_traits< RandomAccessIterator >::reference > +make_iterator_vertex_map(RandomAccessIterator iter) +{ return make_iterator_property_map(iter, identity_property_map()); - } +} #endif - template <class PropertyGraph, class RandomAccessContainer> - inline - iterator_property_map< - typename RandomAccessContainer::iterator, - typename property_map<PropertyGraph, vertex_index_t>::type, +template < class PropertyGraph, class RandomAccessContainer > +inline iterator_property_map< typename RandomAccessContainer::iterator, + typename property_map< PropertyGraph, vertex_index_t >::type, typename RandomAccessContainer::value_type, - typename RandomAccessContainer::reference - > - make_container_vertex_map(RandomAccessContainer& c, const PropertyGraph& g) - { + typename RandomAccessContainer::reference > +make_container_vertex_map(RandomAccessContainer& c, const PropertyGraph& g) +{ BOOST_ASSERT(c.size() >= num_vertices(g)); return make_iterator_vertex_map(c.begin(), g); - } +} - template <class RandomAccessContainer> inline - iterator_property_map< - typename RandomAccessContainer::iterator, - identity_property_map, - typename RandomAccessContainer::value_type, - typename RandomAccessContainer::reference - > - make_container_vertex_map(RandomAccessContainer& c) - { +template < class RandomAccessContainer > +inline iterator_property_map< typename RandomAccessContainer::iterator, + identity_property_map, typename RandomAccessContainer::value_type, + typename RandomAccessContainer::reference > +make_container_vertex_map(RandomAccessContainer& c) +{ return make_iterator_vertex_map(c.begin()); - } - +} // NOTE: These functions are declared, but never defined since they need to // be overloaded by graph implementations. However, we need them to be // declared for the functions below. -template<typename Graph, typename Tag> -typename graph_property<Graph, graph_bundle_t>::type& -get_property(Graph& g, Tag); +template < typename Graph, typename Tag > +typename graph_property< Graph, graph_bundle_t >::type& get_property( + Graph& g, Tag); -template<typename Graph, typename Tag> -typename graph_property<Graph, graph_bundle_t>::type const& -get_property(Graph const& g, Tag); +template < typename Graph, typename Tag > +typename graph_property< Graph, graph_bundle_t >::type const& get_property( + Graph const& g, Tag); #ifndef BOOST_GRAPH_NO_BUNDLED_PROPERTIES // NOTE: This operation is a simple adaptor over the overloaded get_property // operations. -template<typename Graph> -inline typename graph_property<Graph, graph_bundle_t>::type& -get_property(Graph& g) { - return get_property(g, graph_bundle); +template < typename Graph > +inline typename graph_property< Graph, graph_bundle_t >::type& get_property( + Graph& g) +{ + return get_property(g, graph_bundle); } -template<typename Graph> -inline typename graph_property<Graph, graph_bundle_t>::type const& -get_property(const Graph& g) { - return get_property(g, graph_bundle); +template < typename Graph > +inline typename graph_property< Graph, graph_bundle_t >::type const& +get_property(const Graph& g) +{ + return get_property(g, graph_bundle); } #endif diff --git a/contrib/restricted/boost/graph/include/boost/graph/property_maps/constant_property_map.hpp b/contrib/restricted/boost/graph/include/boost/graph/property_maps/constant_property_map.hpp index 9d83ea18cc..7a815496cc 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/property_maps/constant_property_map.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/property_maps/constant_property_map.hpp @@ -9,83 +9,80 @@ #include <boost/property_map/property_map.hpp> - // TODO: This should really be part of the property maps library rather than // the Boost.Graph library. -namespace boost { +namespace boost +{ /** * A constant property is one, that regardless of the edge or vertex given, * will always return a constant value. */ -template <typename Key, typename Value> -struct constant_property_map - : public boost::put_get_helper< - const Value&, - constant_property_map<Key, Value> - > +template < typename Key, typename Value > +struct constant_property_map : public boost::put_get_helper< const Value&, + constant_property_map< Key, Value > > { typedef Key key_type; typedef Value value_type; typedef const Value& reference; typedef boost::readable_property_map_tag category; - constant_property_map() - : m_value() - { } + constant_property_map() : m_value() {} - constant_property_map(const value_type &value) - : m_value(value) - { } + constant_property_map(const value_type& value) : m_value(value) {} constant_property_map(const constant_property_map& copy) - : m_value(copy.m_value) - { } + : m_value(copy.m_value) + { + } - inline reference operator [](const key_type&) const - { return m_value; } + inline reference operator[](const key_type&) const { return m_value; } value_type m_value; }; -template <typename Key, typename Value> -inline constant_property_map<Key, Value> -make_constant_property(const Value& value) -{ return constant_property_map<Key, Value>(value); } +template < typename Key, typename Value > +inline constant_property_map< Key, Value > make_constant_property( + const Value& value) +{ + return constant_property_map< Key, Value >(value); +} /** * Same as above, but pretends to be writable as well. */ -template <typename Key, typename Value> -struct constant_writable_property_map { +template < typename Key, typename Value > struct constant_writable_property_map +{ typedef Key key_type; typedef Value value_type; typedef Value& reference; typedef boost::read_write_property_map_tag category; - constant_writable_property_map() - : m_value() - { } + constant_writable_property_map() : m_value() {} - constant_writable_property_map(const value_type &value) - : m_value(value) - { } + constant_writable_property_map(const value_type& value) : m_value(value) {} constant_writable_property_map(const constant_writable_property_map& copy) - : m_value(copy.m_value) - { } - - friend Value get(const constant_writable_property_map& me, Key) {return me.m_value;} + : m_value(copy.m_value) + { + } + + friend Value get(const constant_writable_property_map& me, Key) + { + return me.m_value; + } friend void put(const constant_writable_property_map&, Key, Value) {} value_type m_value; }; -template <typename Key, typename Value> -inline constant_writable_property_map<Key, Value> +template < typename Key, typename Value > +inline constant_writable_property_map< Key, Value > make_constant_writable_property(const Value& value) -{ return constant_writable_property_map<Key, Value>(value); } +{ + return constant_writable_property_map< Key, Value >(value); +} } /* namespace boost */ diff --git a/contrib/restricted/boost/graph/include/boost/graph/property_maps/null_property_map.hpp b/contrib/restricted/boost/graph/include/boost/graph/property_maps/null_property_map.hpp index 09ff55e348..50097a9943 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/property_maps/null_property_map.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/property_maps/null_property_map.hpp @@ -14,28 +14,31 @@ namespace boost { - // A null property is somewhat like the inverse of the constant - // property map except that instead of returning a single value, - // this eats any writes and cannot be read from. - - template <typename Key, typename Value> - struct null_property_map - { - typedef Key key_type; - typedef Value value_type; - typedef void reference; - typedef boost::writable_property_map_tag category; - }; - - // The null_property_map<K,V> only has a put() function. - template <typename K, typename V> - void put(null_property_map<K,V>& /*pm*/, const K& /*key*/, const V& /*value*/) - { } - - // A helper function for intantiating null property maps. - template <typename Key, typename Value> - inline null_property_map<Key, Value> make_null_property() - { return null_property_map<Key, Value>(); } +// A null property is somewhat like the inverse of the constant +// property map except that instead of returning a single value, +// this eats any writes and cannot be read from. + +template < typename Key, typename Value > struct null_property_map +{ + typedef Key key_type; + typedef Value value_type; + typedef void reference; + typedef boost::writable_property_map_tag category; +}; + +// The null_property_map<K,V> only has a put() function. +template < typename K, typename V > +void put( + null_property_map< K, V >& /*pm*/, const K& /*key*/, const V& /*value*/) +{ +} + +// A helper function for intantiating null property maps. +template < typename Key, typename Value > +inline null_property_map< Key, Value > make_null_property() +{ + return null_property_map< Key, Value >(); +} } #endif diff --git a/contrib/restricted/boost/graph/include/boost/graph/relax.hpp b/contrib/restricted/boost/graph/include/boost/graph/relax.hpp index e3866df484..10483dfdce 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/relax.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/relax.hpp @@ -14,79 +14,121 @@ #include <boost/graph/graph_traits.hpp> #include <boost/property_map/property_map.hpp> -namespace boost { +namespace boost +{ - // The following version of the plus functor prevents - // problems due to overflow at positive infinity. +// The following version of the plus functor prevents +// problems due to overflow at positive infinity. - template <class T> - struct closed_plus - { - const T inf; +template < class T > struct closed_plus +{ + const T inf; - closed_plus() : inf((std::numeric_limits<T>::max)()) { } - closed_plus(T inf) : inf(inf) { } + closed_plus() : inf((std::numeric_limits< T >::max)()) {} + closed_plus(T inf) : inf(inf) {} - T operator()(const T& a, const T& b) const { + T operator()(const T& a, const T& b) const + { using namespace std; - if (a == inf) return inf; - if (b == inf) return inf; - return a + b; - } - }; - - template <class Graph, class WeightMap, - class PredecessorMap, class DistanceMap, - class BinaryFunction, class BinaryPredicate> - bool relax(typename graph_traits<Graph>::edge_descriptor e, - const Graph& g, const WeightMap& w, - PredecessorMap& p, DistanceMap& d, - const BinaryFunction& combine, const BinaryPredicate& compare) + if (a == inf) + return inf; + if (b == inf) + return inf; + return a + b; + } +}; + +template < class Graph, class WeightMap, class PredecessorMap, + class DistanceMap, class BinaryFunction, class BinaryPredicate > +bool relax(typename graph_traits< Graph >::edge_descriptor e, const Graph& g, + const WeightMap& w, PredecessorMap& p, DistanceMap& d, + const BinaryFunction& combine, const BinaryPredicate& compare) +{ + typedef typename graph_traits< Graph >::directed_category DirCat; + bool is_undirected = is_same< DirCat, undirected_tag >::value; + typedef typename graph_traits< Graph >::vertex_descriptor Vertex; + Vertex u = source(e, g), v = target(e, g); + typedef typename property_traits< DistanceMap >::value_type D; + typedef typename property_traits< WeightMap >::value_type W; + const D d_u = get(d, u); + const D d_v = get(d, v); + const W& w_e = get(w, e); + + // The seemingly redundant comparisons after the distance puts are to + // ensure that extra floating-point precision in x87 registers does not + // lead to relax() returning true when the distance did not actually + // change. + if (compare(combine(d_u, w_e), d_v)) { - typedef typename graph_traits<Graph>::directed_category DirCat; - bool is_undirected = is_same<DirCat, undirected_tag>::value; - typedef typename graph_traits<Graph>::vertex_descriptor Vertex; - Vertex u = source(e, g), v = target(e, g); - typedef typename property_traits<DistanceMap>::value_type D; - typedef typename property_traits<WeightMap>::value_type W; - const D d_u = get(d, u); - const D d_v = get(d, v); - const W& w_e = get(w, e); - - // The seemingly redundant comparisons after the distance puts are to - // ensure that extra floating-point precision in x87 registers does not - // lead to relax() returning true when the distance did not actually - // change. - if ( compare(combine(d_u, w_e), d_v) ) { put(d, v, combine(d_u, w_e)); - if (compare(get(d, v), d_v)) { - put(p, v, u); - return true; - } else { - return false; + if (compare(get(d, v), d_v)) + { + put(p, v, u); + return true; + } + else + { + return false; } - } else if (is_undirected && compare(combine(d_v, w_e), d_u)) { + } + else if (is_undirected && compare(combine(d_v, w_e), d_u)) + { put(d, u, combine(d_v, w_e)); - if (compare(get(d, u), d_u)) { - put(p, u, v); - return true; - } else { - return false; + if (compare(get(d, u), d_u)) + { + put(p, u, v); + return true; + } + else + { + return false; } - } else - return false; } - - template <class Graph, class WeightMap, - class PredecessorMap, class DistanceMap> - bool relax(typename graph_traits<Graph>::edge_descriptor e, - const Graph& g, WeightMap w, PredecessorMap p, DistanceMap d) + else + return false; +} + +template < class Graph, class WeightMap, class PredecessorMap, + class DistanceMap, class BinaryFunction, class BinaryPredicate > +bool relax_target(typename graph_traits< Graph >::edge_descriptor e, + const Graph& g, const WeightMap& w, PredecessorMap& p, DistanceMap& d, + const BinaryFunction& combine, const BinaryPredicate& compare) +{ + typedef typename graph_traits< Graph >::vertex_descriptor Vertex; + typedef typename property_traits< DistanceMap >::value_type D; + typedef typename property_traits< WeightMap >::value_type W; + const Vertex u = source(e, g); + const Vertex v = target(e, g); + const D d_u = get(d, u); + const D d_v = get(d, v); + const W& w_e = get(w, e); + + // The seemingly redundant comparisons after the distance puts are to + // ensure that extra floating-point precision in x87 registers does not + // lead to relax() returning true when the distance did not actually + // change. + if (compare(combine(d_u, w_e), d_v)) { - typedef typename property_traits<DistanceMap>::value_type D; - typedef closed_plus<D> Combine; - typedef std::less<D> Compare; - return relax(e, g, w, p, d, Combine(), Compare()); + put(d, v, combine(d_u, w_e)); + if (compare(get(d, v), d_v)) + { + put(p, v, u); + return true; + } } + return false; +} + +template < class Graph, class WeightMap, class PredecessorMap, + class DistanceMap > +bool relax(typename graph_traits< Graph >::edge_descriptor e, const Graph& g, + WeightMap w, PredecessorMap p, DistanceMap d) +{ + typedef typename property_traits< DistanceMap >::value_type D; + typedef closed_plus< D > Combine; + typedef std::less< D > Compare; + return relax(e, g, w, p, d, Combine(), Compare()); +} } // namespace boost diff --git a/contrib/restricted/boost/graph/include/boost/graph/reverse_graph.hpp b/contrib/restricted/boost/graph/include/boost/graph/reverse_graph.hpp index 56ffe72dba..86bcdc4082 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/reverse_graph.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/reverse_graph.hpp @@ -4,7 +4,7 @@ // http://www.boost.org/LICENSE_1_0.txt) #ifndef REVERSE_GRAPH_DWA092300_H_ -# define REVERSE_GRAPH_DWA092300_H_ +#define REVERSE_GRAPH_DWA092300_H_ #include <boost/graph/adjacency_iterator.hpp> #include <boost/graph/properties.hpp> @@ -13,126 +13,191 @@ #include <boost/type_traits.hpp> #include <boost/mpl/if.hpp> -namespace boost { - -struct reverse_graph_tag { }; - - namespace detail { - - template <typename EdgeDesc> - class reverse_graph_edge_descriptor { - public: - EdgeDesc underlying_descx; // Odd name is because this needs to be public but shouldn't be exposed to users anymore - - private: - typedef EdgeDesc base_descriptor_type; - - public: - explicit reverse_graph_edge_descriptor(const EdgeDesc& underlying_descx = EdgeDesc()) - : underlying_descx(underlying_descx) {} - - friend bool operator==(const reverse_graph_edge_descriptor& a, const reverse_graph_edge_descriptor& b) { - return a.underlying_descx == b.underlying_descx; - } - friend bool operator!=(const reverse_graph_edge_descriptor& a, const reverse_graph_edge_descriptor& b) { - return a.underlying_descx != b.underlying_descx; - } - friend bool operator<(const reverse_graph_edge_descriptor& a, const reverse_graph_edge_descriptor& b) { - return a.underlying_descx < b.underlying_descx; - } - friend bool operator>(const reverse_graph_edge_descriptor& a, const reverse_graph_edge_descriptor& b) { - return a.underlying_descx > b.underlying_descx; - } - friend bool operator<=(const reverse_graph_edge_descriptor& a, const reverse_graph_edge_descriptor& b) { - return a.underlying_descx <= b.underlying_descx; - } - friend bool operator>=(const reverse_graph_edge_descriptor& a, const reverse_graph_edge_descriptor& b) { - return a.underlying_descx >= b.underlying_descx; - } +namespace boost +{ + +struct reverse_graph_tag +{ +}; + +namespace detail +{ + + template < typename EdgeDesc > class reverse_graph_edge_descriptor + { + public: + EdgeDesc + underlying_descx; // Odd name is because this needs to be public but + // shouldn't be exposed to users anymore + + private: + typedef EdgeDesc base_descriptor_type; + + public: + explicit reverse_graph_edge_descriptor( + const EdgeDesc& underlying_descx = EdgeDesc()) + : underlying_descx(underlying_descx) + { + } + + friend bool operator==(const reverse_graph_edge_descriptor& a, + const reverse_graph_edge_descriptor& b) + { + return a.underlying_descx == b.underlying_descx; + } + friend bool operator!=(const reverse_graph_edge_descriptor& a, + const reverse_graph_edge_descriptor& b) + { + return a.underlying_descx != b.underlying_descx; + } + friend bool operator<(const reverse_graph_edge_descriptor& a, + const reverse_graph_edge_descriptor& b) + { + return a.underlying_descx < b.underlying_descx; + } + friend bool operator>(const reverse_graph_edge_descriptor& a, + const reverse_graph_edge_descriptor& b) + { + return a.underlying_descx > b.underlying_descx; + } + friend bool operator<=(const reverse_graph_edge_descriptor& a, + const reverse_graph_edge_descriptor& b) + { + return a.underlying_descx <= b.underlying_descx; + } + friend bool operator>=(const reverse_graph_edge_descriptor& a, + const reverse_graph_edge_descriptor& b) + { + return a.underlying_descx >= b.underlying_descx; + } }; - template <typename EdgeDesc> - struct reverse_graph_edge_descriptor_maker { - typedef reverse_graph_edge_descriptor<EdgeDesc> result_type; + template < typename EdgeDesc > struct reverse_graph_edge_descriptor_maker + { + typedef reverse_graph_edge_descriptor< EdgeDesc > result_type; - reverse_graph_edge_descriptor<EdgeDesc> operator()(const EdgeDesc& ed) const { - return reverse_graph_edge_descriptor<EdgeDesc>(ed); - } + reverse_graph_edge_descriptor< EdgeDesc > operator()( + const EdgeDesc& ed) const + { + return reverse_graph_edge_descriptor< EdgeDesc >(ed); + } }; - template <typename EdgeDesc, typename Iter> - std::pair<transform_iterator<reverse_graph_edge_descriptor_maker<EdgeDesc>, Iter>, - transform_iterator<reverse_graph_edge_descriptor_maker<EdgeDesc>, Iter> > - reverse_edge_iter_pair(const std::pair<Iter, Iter>& ip) { - return std::make_pair(make_transform_iterator(ip.first, reverse_graph_edge_descriptor_maker<EdgeDesc>()), - make_transform_iterator(ip.second, reverse_graph_edge_descriptor_maker<EdgeDesc>())); + template < typename EdgeDesc, typename Iter > + std::pair< transform_iterator< + reverse_graph_edge_descriptor_maker< EdgeDesc >, Iter >, + transform_iterator< reverse_graph_edge_descriptor_maker< EdgeDesc >, + Iter > > + reverse_edge_iter_pair(const std::pair< Iter, Iter >& ip) + { + return std::make_pair( + make_transform_iterator( + ip.first, reverse_graph_edge_descriptor_maker< EdgeDesc >()), + make_transform_iterator( + ip.second, reverse_graph_edge_descriptor_maker< EdgeDesc >())); } // Get the underlying descriptor from a vertex or edge descriptor - template <typename Desc> - struct get_underlying_descriptor_from_reverse_descriptor { - typedef Desc type; - static Desc convert(const Desc& d) {return d;} + template < typename Desc > + struct get_underlying_descriptor_from_reverse_descriptor + { + typedef Desc type; + static Desc convert(const Desc& d) { return d; } }; - template <typename Desc> - struct get_underlying_descriptor_from_reverse_descriptor<reverse_graph_edge_descriptor<Desc> > { - typedef Desc type; - static Desc convert(const reverse_graph_edge_descriptor<Desc>& d) {return d.underlying_descx;} + template < typename Desc > + struct get_underlying_descriptor_from_reverse_descriptor< + reverse_graph_edge_descriptor< Desc > > + { + typedef Desc type; + static Desc convert(const reverse_graph_edge_descriptor< Desc >& d) + { + return d.underlying_descx; + } }; - template <bool isEdgeList> struct choose_rev_edge_iter { }; - template <> struct choose_rev_edge_iter<true> { - template <class G> struct bind_ { - typedef transform_iterator<reverse_graph_edge_descriptor_maker<typename graph_traits<G>::edge_descriptor>, typename graph_traits<G>::edge_iterator> type; - }; + template < bool isEdgeList > struct choose_rev_edge_iter + { + }; + template <> struct choose_rev_edge_iter< true > + { + template < class G > struct bind_ + { + typedef transform_iterator< + reverse_graph_edge_descriptor_maker< + typename graph_traits< G >::edge_descriptor >, + typename graph_traits< G >::edge_iterator > + type; + }; }; - template <> struct choose_rev_edge_iter<false> { - template <class G> struct bind_ { - typedef void type; - }; + template <> struct choose_rev_edge_iter< false > + { + template < class G > struct bind_ + { + typedef void type; + }; }; - } // namespace detail +} // namespace detail + +template < class BidirectionalGraph, + class GraphRef = const BidirectionalGraph& > +class reverse_graph +{ + typedef reverse_graph< BidirectionalGraph, GraphRef > Self; + typedef graph_traits< BidirectionalGraph > Traits; -template <class BidirectionalGraph, class GraphRef = const BidirectionalGraph&> -class reverse_graph { - typedef reverse_graph<BidirectionalGraph, GraphRef> Self; - typedef graph_traits<BidirectionalGraph> Traits; - public: +public: typedef BidirectionalGraph base_type; typedef GraphRef base_ref_type; // Constructor reverse_graph(GraphRef g) : m_g(g) {} - // Conversion from reverse_graph on non-const reference to one on const reference - reverse_graph(const reverse_graph<BidirectionalGraph, BidirectionalGraph&>& o): m_g(o.m_g) {} + // Conversion from reverse_graph on non-const reference to one on const + // reference + reverse_graph( + const reverse_graph< BidirectionalGraph, BidirectionalGraph& >& o) + : m_g(o.m_g) + { + } // Graph requirements typedef typename Traits::vertex_descriptor vertex_descriptor; - typedef detail::reverse_graph_edge_descriptor<typename Traits::edge_descriptor> edge_descriptor; + typedef detail::reverse_graph_edge_descriptor< + typename Traits::edge_descriptor > + edge_descriptor; typedef typename Traits::directed_category directed_category; typedef typename Traits::edge_parallel_category edge_parallel_category; typedef typename Traits::traversal_category traversal_category; // IncidenceGraph requirements - typedef transform_iterator<detail::reverse_graph_edge_descriptor_maker<typename Traits::edge_descriptor>, typename Traits::in_edge_iterator> out_edge_iterator; + typedef transform_iterator< detail::reverse_graph_edge_descriptor_maker< + typename Traits::edge_descriptor >, + typename Traits::in_edge_iterator > + out_edge_iterator; typedef typename Traits::degree_size_type degree_size_type; // BidirectionalGraph requirements - typedef transform_iterator<detail::reverse_graph_edge_descriptor_maker<typename Traits::edge_descriptor>, typename Traits::out_edge_iterator> in_edge_iterator; + typedef transform_iterator< detail::reverse_graph_edge_descriptor_maker< + typename Traits::edge_descriptor >, + typename Traits::out_edge_iterator > + in_edge_iterator; // AdjacencyGraph requirements - typedef typename adjacency_iterator_generator<Self, vertex_descriptor, out_edge_iterator>::type adjacency_iterator; + typedef typename adjacency_iterator_generator< Self, vertex_descriptor, + out_edge_iterator >::type adjacency_iterator; // VertexListGraph requirements typedef typename Traits::vertex_iterator vertex_iterator; // EdgeListGraph requirements - enum { is_edge_list = is_convertible<traversal_category, - edge_list_graph_tag>::value }; - typedef detail::choose_rev_edge_iter<is_edge_list> ChooseEdgeIter; - typedef typename ChooseEdgeIter:: - template bind_<BidirectionalGraph>::type edge_iterator; + enum + { + is_edge_list + = is_convertible< traversal_category, edge_list_graph_tag >::value + }; + typedef detail::choose_rev_edge_iter< is_edge_list > ChooseEdgeIter; + typedef typename ChooseEdgeIter::template bind_< BidirectionalGraph >::type + edge_iterator; typedef typename Traits::vertices_size_type vertices_size_type; typedef typename Traits::edges_size_type edges_size_type; @@ -140,386 +205,449 @@ class reverse_graph { #ifndef BOOST_GRAPH_NO_BUNDLED_PROPERTIES // Bundled properties support - template<typename Descriptor> - typename graph::detail::bundled_result< - BidirectionalGraph, - typename detail::get_underlying_descriptor_from_reverse_descriptor<Descriptor>::type - >::type& + template < typename Descriptor > + typename graph::detail::bundled_result< BidirectionalGraph, + typename detail::get_underlying_descriptor_from_reverse_descriptor< + Descriptor >::type >::type& operator[](Descriptor x) - { return m_g[detail::get_underlying_descriptor_from_reverse_descriptor<Descriptor>::convert(x)]; } + { + return m_g[detail::get_underlying_descriptor_from_reverse_descriptor< + Descriptor >::convert(x)]; + } - template<typename Descriptor> - typename graph::detail::bundled_result< - BidirectionalGraph, - typename detail::get_underlying_descriptor_from_reverse_descriptor<Descriptor>::type - >::type const& + template < typename Descriptor > + typename graph::detail::bundled_result< BidirectionalGraph, + typename detail::get_underlying_descriptor_from_reverse_descriptor< + Descriptor >::type >::type const& operator[](Descriptor x) const - { return m_g[detail::get_underlying_descriptor_from_reverse_descriptor<Descriptor>::convert(x)]; } + { + return m_g[detail::get_underlying_descriptor_from_reverse_descriptor< + Descriptor >::convert(x)]; + } #endif // BOOST_GRAPH_NO_BUNDLED_PROPERTIES - static vertex_descriptor null_vertex() - { return Traits::null_vertex(); } + static vertex_descriptor null_vertex() { return Traits::null_vertex(); } // would be private, but template friends aren't portable enough. - // private: + // private: GraphRef m_g; }; - // These are separate so they are not instantiated unless used (see bug 1021) -template <class BidirectionalGraph, class GraphRef> -struct vertex_property_type<reverse_graph<BidirectionalGraph, GraphRef> > { - typedef typename boost::vertex_property_type<BidirectionalGraph>::type type; +template < class BidirectionalGraph, class GraphRef > +struct vertex_property_type< reverse_graph< BidirectionalGraph, GraphRef > > +{ + typedef + typename boost::vertex_property_type< BidirectionalGraph >::type type; }; -template <class BidirectionalGraph, class GraphRef> -struct edge_property_type<reverse_graph<BidirectionalGraph, GraphRef> > { - typedef typename boost::edge_property_type<BidirectionalGraph>::type type; +template < class BidirectionalGraph, class GraphRef > +struct edge_property_type< reverse_graph< BidirectionalGraph, GraphRef > > +{ + typedef typename boost::edge_property_type< BidirectionalGraph >::type type; }; -template <class BidirectionalGraph, class GraphRef> -struct graph_property_type<reverse_graph<BidirectionalGraph, GraphRef> > { - typedef typename boost::graph_property_type<BidirectionalGraph>::type type; +template < class BidirectionalGraph, class GraphRef > +struct graph_property_type< reverse_graph< BidirectionalGraph, GraphRef > > +{ + typedef + typename boost::graph_property_type< BidirectionalGraph >::type type; }; #ifndef BOOST_GRAPH_NO_BUNDLED_PROPERTIES - template<typename Graph, typename GraphRef> - struct vertex_bundle_type<reverse_graph<Graph, GraphRef> > - : vertex_bundle_type<Graph> { }; +template < typename Graph, typename GraphRef > +struct vertex_bundle_type< reverse_graph< Graph, GraphRef > > +: vertex_bundle_type< Graph > +{ +}; - template<typename Graph, typename GraphRef> - struct edge_bundle_type<reverse_graph<Graph, GraphRef> > - : edge_bundle_type<Graph> { }; +template < typename Graph, typename GraphRef > +struct edge_bundle_type< reverse_graph< Graph, GraphRef > > +: edge_bundle_type< Graph > +{ +}; - template<typename Graph, typename GraphRef> - struct graph_bundle_type<reverse_graph<Graph, GraphRef> > - : graph_bundle_type<Graph> { }; +template < typename Graph, typename GraphRef > +struct graph_bundle_type< reverse_graph< Graph, GraphRef > > +: graph_bundle_type< Graph > +{ +}; #endif // BOOST_GRAPH_NO_BUNDLED_PROPERTIES -template <class BidirectionalGraph> -inline reverse_graph<BidirectionalGraph> -make_reverse_graph(const BidirectionalGraph& g) +template < class BidirectionalGraph > +inline reverse_graph< BidirectionalGraph > make_reverse_graph( + const BidirectionalGraph& g) { - return reverse_graph<BidirectionalGraph>(g); + return reverse_graph< BidirectionalGraph >(g); } -template <class BidirectionalGraph> -inline reverse_graph<BidirectionalGraph, BidirectionalGraph&> +template < class BidirectionalGraph > +inline reverse_graph< BidirectionalGraph, BidirectionalGraph& > make_reverse_graph(BidirectionalGraph& g) { - return reverse_graph<BidirectionalGraph, BidirectionalGraph&>(g); + return reverse_graph< BidirectionalGraph, BidirectionalGraph& >(g); } -template <class BidirectionalGraph, class GRef> -std::pair<typename reverse_graph<BidirectionalGraph>::vertex_iterator, - typename reverse_graph<BidirectionalGraph>::vertex_iterator> -vertices(const reverse_graph<BidirectionalGraph,GRef>& g) +template < class BidirectionalGraph, class GRef > +std::pair< typename reverse_graph< BidirectionalGraph >::vertex_iterator, + typename reverse_graph< BidirectionalGraph >::vertex_iterator > +vertices(const reverse_graph< BidirectionalGraph, GRef >& g) { return vertices(g.m_g); } -template <class BidirectionalGraph, class GRef> -std::pair<typename reverse_graph<BidirectionalGraph>::edge_iterator, - typename reverse_graph<BidirectionalGraph>::edge_iterator> -edges(const reverse_graph<BidirectionalGraph,GRef>& g) +template < class BidirectionalGraph, class GRef > +std::pair< typename reverse_graph< BidirectionalGraph >::edge_iterator, + typename reverse_graph< BidirectionalGraph >::edge_iterator > +edges(const reverse_graph< BidirectionalGraph, GRef >& g) { - return detail::reverse_edge_iter_pair<typename graph_traits<BidirectionalGraph>::edge_descriptor>(edges(g.m_g)); + return detail::reverse_edge_iter_pair< + typename graph_traits< BidirectionalGraph >::edge_descriptor >( + edges(g.m_g)); } -template <class BidirectionalGraph, class GRef> -inline std::pair<typename reverse_graph<BidirectionalGraph>::out_edge_iterator, - typename reverse_graph<BidirectionalGraph>::out_edge_iterator> -out_edges(const typename graph_traits<BidirectionalGraph>::vertex_descriptor u, - const reverse_graph<BidirectionalGraph,GRef>& g) +template < class BidirectionalGraph, class GRef > +inline std::pair< + typename reverse_graph< BidirectionalGraph >::out_edge_iterator, + typename reverse_graph< BidirectionalGraph >::out_edge_iterator > +out_edges( + const typename graph_traits< BidirectionalGraph >::vertex_descriptor u, + const reverse_graph< BidirectionalGraph, GRef >& g) { - return detail::reverse_edge_iter_pair<typename graph_traits<BidirectionalGraph>::edge_descriptor>(in_edges(u, g.m_g)); + return detail::reverse_edge_iter_pair< + typename graph_traits< BidirectionalGraph >::edge_descriptor >( + in_edges(u, g.m_g)); } -template <class BidirectionalGraph, class GRef> -inline typename graph_traits<BidirectionalGraph>::vertices_size_type -num_vertices(const reverse_graph<BidirectionalGraph,GRef>& g) +template < class BidirectionalGraph, class GRef > +inline typename graph_traits< BidirectionalGraph >::vertices_size_type +num_vertices(const reverse_graph< BidirectionalGraph, GRef >& g) { return num_vertices(g.m_g); } -template <class BidirectionalGraph, class GRef> -inline typename reverse_graph<BidirectionalGraph>::edges_size_type -num_edges(const reverse_graph<BidirectionalGraph,GRef>& g) +template < class BidirectionalGraph, class GRef > +inline typename reverse_graph< BidirectionalGraph >::edges_size_type num_edges( + const reverse_graph< BidirectionalGraph, GRef >& g) { return num_edges(g.m_g); } -template <class BidirectionalGraph, class GRef> -inline typename graph_traits<BidirectionalGraph>::degree_size_type -out_degree(const typename graph_traits<BidirectionalGraph>::vertex_descriptor u, - const reverse_graph<BidirectionalGraph,GRef>& g) +template < class BidirectionalGraph, class GRef > +inline typename graph_traits< BidirectionalGraph >::degree_size_type out_degree( + const typename graph_traits< BidirectionalGraph >::vertex_descriptor u, + const reverse_graph< BidirectionalGraph, GRef >& g) { return in_degree(u, g.m_g); } -template <class BidirectionalGraph, class GRef> -inline typename graph_traits<BidirectionalGraph>::vertex_descriptor -vertex(const typename graph_traits<BidirectionalGraph>::vertices_size_type v, - const reverse_graph<BidirectionalGraph,GRef>& g) +template < class BidirectionalGraph, class GRef > +inline typename graph_traits< BidirectionalGraph >::vertex_descriptor vertex( + const typename graph_traits< BidirectionalGraph >::vertices_size_type v, + const reverse_graph< BidirectionalGraph, GRef >& g) { return vertex(v, g.m_g); } -template <class BidirectionalGraph, class GRef> -inline std::pair< typename graph_traits<reverse_graph<BidirectionalGraph,GRef> >::edge_descriptor, - bool> -edge(const typename graph_traits<BidirectionalGraph>::vertex_descriptor u, - const typename graph_traits<BidirectionalGraph>::vertex_descriptor v, - const reverse_graph<BidirectionalGraph,GRef>& g) +template < class BidirectionalGraph, class GRef > +inline std::pair< typename graph_traits< reverse_graph< BidirectionalGraph, + GRef > >::edge_descriptor, + bool > +edge(const typename graph_traits< BidirectionalGraph >::vertex_descriptor u, + const typename graph_traits< BidirectionalGraph >::vertex_descriptor v, + const reverse_graph< BidirectionalGraph, GRef >& g) { - typedef typename graph_traits<BidirectionalGraph>::edge_descriptor underlying_edge_descriptor; - std::pair<underlying_edge_descriptor, bool> e = edge(v, u, g.m_g); - return std::make_pair(detail::reverse_graph_edge_descriptor<underlying_edge_descriptor>(e.first), e.second); + typedef typename graph_traits< BidirectionalGraph >::edge_descriptor + underlying_edge_descriptor; + std::pair< underlying_edge_descriptor, bool > e = edge(v, u, g.m_g); + return std::make_pair( + detail::reverse_graph_edge_descriptor< underlying_edge_descriptor >( + e.first), + e.second); } -template <class BidirectionalGraph, class GRef> -inline std::pair<typename reverse_graph<BidirectionalGraph>::in_edge_iterator, - typename reverse_graph<BidirectionalGraph>::in_edge_iterator> -in_edges(const typename graph_traits<BidirectionalGraph>::vertex_descriptor u, - const reverse_graph<BidirectionalGraph,GRef>& g) +template < class BidirectionalGraph, class GRef > +inline std::pair< + typename reverse_graph< BidirectionalGraph >::in_edge_iterator, + typename reverse_graph< BidirectionalGraph >::in_edge_iterator > +in_edges(const typename graph_traits< BidirectionalGraph >::vertex_descriptor u, + const reverse_graph< BidirectionalGraph, GRef >& g) { - return detail::reverse_edge_iter_pair<typename graph_traits<BidirectionalGraph>::edge_descriptor>(out_edges(u, g.m_g)); + return detail::reverse_edge_iter_pair< + typename graph_traits< BidirectionalGraph >::edge_descriptor >( + out_edges(u, g.m_g)); } -template <class BidirectionalGraph, class GRef> -inline std::pair<typename reverse_graph<BidirectionalGraph,GRef>::adjacency_iterator, - typename reverse_graph<BidirectionalGraph,GRef>::adjacency_iterator> -adjacent_vertices(typename graph_traits<BidirectionalGraph>::vertex_descriptor u, - const reverse_graph<BidirectionalGraph,GRef>& g) +template < class BidirectionalGraph, class GRef > +inline std::pair< + typename reverse_graph< BidirectionalGraph, GRef >::adjacency_iterator, + typename reverse_graph< BidirectionalGraph, GRef >::adjacency_iterator > +adjacent_vertices( + typename graph_traits< BidirectionalGraph >::vertex_descriptor u, + const reverse_graph< BidirectionalGraph, GRef >& g) { - typedef reverse_graph<BidirectionalGraph,GRef> Graph; - typename graph_traits<Graph>::out_edge_iterator first, last; + typedef reverse_graph< BidirectionalGraph, GRef > Graph; + typename graph_traits< Graph >::out_edge_iterator first, last; boost::tie(first, last) = out_edges(u, g); - typedef typename graph_traits<Graph>::adjacency_iterator adjacency_iterator; - return std::make_pair(adjacency_iterator(first, const_cast<Graph*>(&g)), - adjacency_iterator(last, const_cast<Graph*>(&g))); + typedef + typename graph_traits< Graph >::adjacency_iterator adjacency_iterator; + return std::make_pair(adjacency_iterator(first, const_cast< Graph* >(&g)), + adjacency_iterator(last, const_cast< Graph* >(&g))); } -template <class BidirectionalGraph, class GRef> -inline typename graph_traits<BidirectionalGraph>::degree_size_type -in_degree(const typename graph_traits<BidirectionalGraph>::vertex_descriptor u, - const reverse_graph<BidirectionalGraph,GRef>& g) +template < class BidirectionalGraph, class GRef > +inline typename graph_traits< BidirectionalGraph >::degree_size_type in_degree( + const typename graph_traits< BidirectionalGraph >::vertex_descriptor u, + const reverse_graph< BidirectionalGraph, GRef >& g) { return out_degree(u, g.m_g); } -template <class Edge, class BidirectionalGraph, class GRef> -inline typename graph_traits<BidirectionalGraph>::vertex_descriptor -source(const detail::reverse_graph_edge_descriptor<Edge>& e, const reverse_graph<BidirectionalGraph,GRef>& g) +template < class Edge, class BidirectionalGraph, class GRef > +inline typename graph_traits< BidirectionalGraph >::vertex_descriptor source( + const detail::reverse_graph_edge_descriptor< Edge >& e, + const reverse_graph< BidirectionalGraph, GRef >& g) { return target(e.underlying_descx, g.m_g); } -template <class Edge, class BidirectionalGraph, class GRef> -inline typename graph_traits<BidirectionalGraph>::vertex_descriptor -target(const detail::reverse_graph_edge_descriptor<Edge>& e, const reverse_graph<BidirectionalGraph,GRef>& g) +template < class Edge, class BidirectionalGraph, class GRef > +inline typename graph_traits< BidirectionalGraph >::vertex_descriptor target( + const detail::reverse_graph_edge_descriptor< Edge >& e, + const reverse_graph< BidirectionalGraph, GRef >& g) { return source(e.underlying_descx, g.m_g); } -template <class BidirectionalGraph, class GRef> -inline typename graph_traits<BidirectionalGraph>::degree_size_type -degree(const typename graph_traits<BidirectionalGraph>::vertex_descriptor u, - const reverse_graph<BidirectionalGraph,GRef>& g) +template < class BidirectionalGraph, class GRef > +inline typename graph_traits< BidirectionalGraph >::degree_size_type degree( + const typename graph_traits< BidirectionalGraph >::vertex_descriptor u, + const reverse_graph< BidirectionalGraph, GRef >& g) { return degree(u, g.m_g); } -namespace detail { +namespace detail +{ - template <typename PM> - struct reverse_graph_edge_property_map { + template < typename PM > struct reverse_graph_edge_property_map + { private: - PM underlying_pm; + PM underlying_pm; public: - typedef reverse_graph_edge_descriptor<typename property_traits<PM>::key_type> key_type; - typedef typename property_traits<PM>::value_type value_type; - typedef typename property_traits<PM>::reference reference; - typedef typename property_traits<PM>::category category; - - explicit reverse_graph_edge_property_map(const PM& pm): underlying_pm(pm) {} - - friend reference - get(const reverse_graph_edge_property_map& m, - const key_type& e) { - return get(m.underlying_pm, e.underlying_descx); - } - - friend void - put(const reverse_graph_edge_property_map& m, - const key_type& e, - const value_type& v) { - put(m.underlying_pm, e.underlying_descx, v); - } - - reference operator[](const key_type& k) const { - return (this->underlying_pm)[k.underlying_descx]; - } - }; + typedef reverse_graph_edge_descriptor< + typename property_traits< PM >::key_type > + key_type; + typedef typename property_traits< PM >::value_type value_type; + typedef typename property_traits< PM >::reference reference; + typedef typename property_traits< PM >::category category; + + explicit reverse_graph_edge_property_map(const PM& pm) + : underlying_pm(pm) + { + } + + friend reference get( + const reverse_graph_edge_property_map& m, const key_type& e) + { + return get(m.underlying_pm, e.underlying_descx); + } + + friend void put(const reverse_graph_edge_property_map& m, + const key_type& e, const value_type& v) + { + put(m.underlying_pm, e.underlying_descx, v); + } + + reference operator[](const key_type& k) const + { + return (this->underlying_pm)[k.underlying_descx]; + } + }; } // namespace detail -template <class BidirGraph, class GRef, class Property> -struct property_map<reverse_graph<BidirGraph, GRef>, Property> { - typedef boost::is_same<typename detail::property_kind_from_graph<BidirGraph, Property>::type, edge_property_tag> is_edge_prop; - typedef boost::is_const<typename boost::remove_reference<GRef>::type> is_ref_const; - typedef typename boost::mpl::if_< - is_ref_const, - typename property_map<BidirGraph, Property>::const_type, - typename property_map<BidirGraph, Property>::type>::type - orig_type; - typedef typename property_map<BidirGraph, Property>::const_type orig_const_type; - typedef typename boost::mpl::if_<is_edge_prop, detail::reverse_graph_edge_property_map<orig_type>, orig_type>::type type; - typedef typename boost::mpl::if_<is_edge_prop, detail::reverse_graph_edge_property_map<orig_const_type>, orig_const_type>::type const_type; +template < class BidirGraph, class GRef, class Property > +struct property_map< reverse_graph< BidirGraph, GRef >, Property > +{ + typedef boost::is_same< + typename detail::property_kind_from_graph< BidirGraph, Property >::type, + edge_property_tag > + is_edge_prop; + typedef boost::is_const< typename boost::remove_reference< GRef >::type > + is_ref_const; + typedef typename boost::mpl::if_< is_ref_const, + typename property_map< BidirGraph, Property >::const_type, + typename property_map< BidirGraph, Property >::type >::type orig_type; + typedef typename property_map< BidirGraph, Property >::const_type + orig_const_type; + typedef typename boost::mpl::if_< is_edge_prop, + detail::reverse_graph_edge_property_map< orig_type >, orig_type >::type + type; + typedef typename boost::mpl::if_< is_edge_prop, + detail::reverse_graph_edge_property_map< orig_const_type >, + orig_const_type >::type const_type; }; -template <class BidirGraph, class GRef, class Property> -struct property_map<const reverse_graph<BidirGraph, GRef>, Property> { - typedef boost::is_same<typename detail::property_kind_from_graph<BidirGraph, Property>::type, edge_property_tag> is_edge_prop; - typedef typename property_map<BidirGraph, Property>::const_type orig_const_type; - typedef typename boost::mpl::if_<is_edge_prop, detail::reverse_graph_edge_property_map<orig_const_type>, orig_const_type>::type const_type; - typedef const_type type; +template < class BidirGraph, class GRef, class Property > +struct property_map< const reverse_graph< BidirGraph, GRef >, Property > +{ + typedef boost::is_same< + typename detail::property_kind_from_graph< BidirGraph, Property >::type, + edge_property_tag > + is_edge_prop; + typedef typename property_map< BidirGraph, Property >::const_type + orig_const_type; + typedef typename boost::mpl::if_< is_edge_prop, + detail::reverse_graph_edge_property_map< orig_const_type >, + orig_const_type >::type const_type; + typedef const_type type; }; -template <class BidirGraph, class GRef, class Property> -typename disable_if< - is_same<Property, edge_underlying_t>, - typename property_map<reverse_graph<BidirGraph,GRef>, Property>::type>::type -get(Property p, reverse_graph<BidirGraph,GRef>& g) +template < class BidirGraph, class GRef, class Property > +typename disable_if< is_same< Property, edge_underlying_t >, + typename property_map< reverse_graph< BidirGraph, GRef >, + Property >::type >::type +get(Property p, reverse_graph< BidirGraph, GRef >& g) { - return typename property_map<reverse_graph<BidirGraph,GRef>, Property>::type(get(p, g.m_g)); + return typename property_map< reverse_graph< BidirGraph, GRef >, + Property >::type(get(p, g.m_g)); } -template <class BidirGraph, class GRef, class Property> -typename disable_if< - is_same<Property, edge_underlying_t>, - typename property_map<reverse_graph<BidirGraph,GRef>, Property>::const_type>::type -get(Property p, const reverse_graph<BidirGraph,GRef>& g) +template < class BidirGraph, class GRef, class Property > +typename disable_if< is_same< Property, edge_underlying_t >, + typename property_map< reverse_graph< BidirGraph, GRef >, + Property >::const_type >::type +get(Property p, const reverse_graph< BidirGraph, GRef >& g) { - const BidirGraph& gref = g.m_g; // in case GRef is non-const - return typename property_map<reverse_graph<BidirGraph,GRef>, Property>::const_type(get(p, gref)); + const BidirGraph& gref = g.m_g; // in case GRef is non-const + return typename property_map< reverse_graph< BidirGraph, GRef >, + Property >::const_type(get(p, gref)); } -template <class BidirectionalGraph, class GRef, class Property, class Key> -typename disable_if< - is_same<Property, edge_underlying_t>, - typename property_traits< - typename property_map<reverse_graph<BidirectionalGraph, GRef>, Property>::const_type - >::value_type>::type -get(Property p, const reverse_graph<BidirectionalGraph,GRef>& g, const Key& k) +template < class BidirectionalGraph, class GRef, class Property, class Key > +typename disable_if< is_same< Property, edge_underlying_t >, + typename property_traits< + typename property_map< reverse_graph< BidirectionalGraph, GRef >, + Property >::const_type >::value_type >::type +get(Property p, const reverse_graph< BidirectionalGraph, GRef >& g, + const Key& k) { - return get(get(p, g), k); + return get(get(p, g), k); } -template <class BidirectionalGraph, class GRef, class Property, class Key, class Value> -void -put(Property p, reverse_graph<BidirectionalGraph,GRef>& g, const Key& k, +template < class BidirectionalGraph, class GRef, class Property, class Key, + class Value > +void put(Property p, reverse_graph< BidirectionalGraph, GRef >& g, const Key& k, const Value& val) { - put(get(p, g), k, val); + put(get(p, g), k, val); } // Get the underlying descriptor from a reverse_graph's wrapped edge descriptor -namespace detail { - template <class E> - struct underlying_edge_desc_map_type { - E operator[](const reverse_graph_edge_descriptor<E>& k) const { - return k.underlying_descx; +namespace detail +{ + template < class E > struct underlying_edge_desc_map_type + { + E operator[](const reverse_graph_edge_descriptor< E >& k) const + { + return k.underlying_descx; + } + }; + + template < class E > + E get(underlying_edge_desc_map_type< E > m, + const reverse_graph_edge_descriptor< E >& k) + { + return m[k]; } - }; - - template <class E> - E - get(underlying_edge_desc_map_type<E> m, - const reverse_graph_edge_descriptor<E>& k) - { - return m[k]; - } } -template <class E> -struct property_traits<detail::underlying_edge_desc_map_type<E> > { - typedef detail::reverse_graph_edge_descriptor<E> key_type; - typedef E value_type; - typedef const E& reference; - typedef readable_property_map_tag category; +template < class E > +struct property_traits< detail::underlying_edge_desc_map_type< E > > +{ + typedef detail::reverse_graph_edge_descriptor< E > key_type; + typedef E value_type; + typedef const E& reference; + typedef readable_property_map_tag category; }; -template <class Graph, class GRef> -struct property_map<reverse_graph<Graph, GRef>, edge_underlying_t> { - private: - typedef typename graph_traits<Graph>::edge_descriptor ed; +template < class Graph, class GRef > +struct property_map< reverse_graph< Graph, GRef >, edge_underlying_t > +{ +private: + typedef typename graph_traits< Graph >::edge_descriptor ed; - public: - typedef detail::underlying_edge_desc_map_type<ed> type; - typedef detail::underlying_edge_desc_map_type<ed> const_type; +public: + typedef detail::underlying_edge_desc_map_type< ed > type; + typedef detail::underlying_edge_desc_map_type< ed > const_type; }; -template <typename T> struct is_reverse_graph: boost::mpl::false_ {}; -template <typename G, typename R> struct is_reverse_graph<reverse_graph<G, R> >: boost::mpl::true_ {}; +template < typename T > struct is_reverse_graph : boost::mpl::false_ +{ +}; +template < typename G, typename R > +struct is_reverse_graph< reverse_graph< G, R > > : boost::mpl::true_ +{ +}; -template <class G> -typename enable_if<is_reverse_graph<G>, - detail::underlying_edge_desc_map_type<typename graph_traits<typename G::base_type>::edge_descriptor> >::type -get(edge_underlying_t, - G&) +template < class G > +typename enable_if< is_reverse_graph< G >, + detail::underlying_edge_desc_map_type< typename graph_traits< + typename G::base_type >::edge_descriptor > >::type +get(edge_underlying_t, G&) { - return detail::underlying_edge_desc_map_type<typename graph_traits<typename G::base_type>::edge_descriptor>(); + return detail::underlying_edge_desc_map_type< + typename graph_traits< typename G::base_type >::edge_descriptor >(); } -template <class G> -typename enable_if<is_reverse_graph<G>, typename graph_traits<typename G::base_type>::edge_descriptor>::type -get(edge_underlying_t, - G&, - const typename graph_traits<G>::edge_descriptor& k) +template < class G > +typename enable_if< is_reverse_graph< G >, + typename graph_traits< typename G::base_type >::edge_descriptor >::type +get(edge_underlying_t, G&, const typename graph_traits< G >::edge_descriptor& k) { - return k.underlying_descx; + return k.underlying_descx; } -template <class G> -typename enable_if<is_reverse_graph<G>, detail::underlying_edge_desc_map_type<typename graph_traits<typename G::base_type>::edge_descriptor> >::type -get(edge_underlying_t, - const G&) +template < class G > +typename enable_if< is_reverse_graph< G >, + detail::underlying_edge_desc_map_type< typename graph_traits< + typename G::base_type >::edge_descriptor > >::type +get(edge_underlying_t, const G&) { - return detail::underlying_edge_desc_map_type<typename graph_traits<typename G::base_type>::edge_descriptor>(); + return detail::underlying_edge_desc_map_type< + typename graph_traits< typename G::base_type >::edge_descriptor >(); } -template <class G> -typename enable_if<is_reverse_graph<G>, typename graph_traits<typename G::base_type>::edge_descriptor>::type -get(edge_underlying_t, - const G&, - const typename graph_traits<G>::edge_descriptor& k) +template < class G > +typename enable_if< is_reverse_graph< G >, + typename graph_traits< typename G::base_type >::edge_descriptor >::type +get(edge_underlying_t, const G&, + const typename graph_traits< G >::edge_descriptor& k) { - return k.underlying_descx; + return k.underlying_descx; } // Access to wrapped graph's graph properties -template<typename BidirectionalGraph, typename GRef, typename Tag, - typename Value> -inline void -set_property(const reverse_graph<BidirectionalGraph,GRef>& g, Tag tag, - const Value& value) +template < typename BidirectionalGraph, typename GRef, typename Tag, + typename Value > +inline void set_property(const reverse_graph< BidirectionalGraph, GRef >& g, + Tag tag, const Value& value) { - set_property(g.m_g, tag, value); + set_property(g.m_g, tag, value); } -template<typename BidirectionalGraph, typename GRef, typename Tag> -inline -typename boost::mpl::if_< - boost::is_const<typename boost::remove_reference<GRef>::type>, - const typename graph_property<BidirectionalGraph, Tag>::type&, - typename graph_property<BidirectionalGraph, Tag>::type& >::type -get_property(const reverse_graph<BidirectionalGraph,GRef>& g, Tag tag) +template < typename BidirectionalGraph, typename GRef, typename Tag > +inline typename boost::mpl::if_< + boost::is_const< typename boost::remove_reference< GRef >::type >, + const typename graph_property< BidirectionalGraph, Tag >::type&, + typename graph_property< BidirectionalGraph, Tag >::type& >::type +get_property(const reverse_graph< BidirectionalGraph, GRef >& g, Tag tag) { - return get_property(g.m_g, tag); + return get_property(g.m_g, tag); } } // namespace boost diff --git a/contrib/restricted/boost/graph/include/boost/graph/strong_components.hpp b/contrib/restricted/boost/graph/include/boost/graph/strong_components.hpp index 2b3ef0f534..18e3f8fadd 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/strong_components.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/strong_components.hpp @@ -18,97 +18,116 @@ #include <boost/type_traits/conversion_traits.hpp> #include <boost/static_assert.hpp> #include <boost/graph/overloading.hpp> +#include <boost/graph/detail/mpi_include.hpp> #include <boost/concept/assert.hpp> -namespace boost { +namespace boost +{ - //========================================================================== - // This is Tarjan's algorithm for strongly connected components - // from his paper "Depth first search and linear graph algorithms". - // It calculates the components in a single application of DFS. - // We implement the algorithm as a dfs-visitor. +//========================================================================== +// This is Tarjan's algorithm for strongly connected components +// from his paper "Depth first search and linear graph algorithms". +// It calculates the components in a single application of DFS. +// We implement the algorithm as a dfs-visitor. - namespace detail { - - template <typename ComponentMap, typename RootMap, typename DiscoverTime, - typename Stack> - class tarjan_scc_visitor : public dfs_visitor<> +namespace detail +{ + + template < typename ComponentMap, typename RootMap, typename DiscoverTime, + typename Stack > + class tarjan_scc_visitor : public dfs_visitor<> { - typedef typename property_traits<ComponentMap>::value_type comp_type; - typedef typename property_traits<DiscoverTime>::value_type time_type; + typedef typename property_traits< ComponentMap >::value_type comp_type; + typedef typename property_traits< DiscoverTime >::value_type time_type; + public: - tarjan_scc_visitor(ComponentMap comp_map, RootMap r, DiscoverTime d, - comp_type& c_, Stack& s_) - : c(c_), comp(comp_map), root(r), discover_time(d), - dfs_time(time_type()), s(s_) { } - - template <typename Graph> - void discover_vertex(typename graph_traits<Graph>::vertex_descriptor v, - const Graph&) { - put(root, v, v); - put(comp, v, (std::numeric_limits<comp_type>::max)()); - put(discover_time, v, dfs_time++); - s.push(v); - } - template <typename Graph> - void finish_vertex(typename graph_traits<Graph>::vertex_descriptor v, - const Graph& g) { - typename graph_traits<Graph>::vertex_descriptor w; - typename graph_traits<Graph>::out_edge_iterator ei, ei_end; - for (boost::tie(ei, ei_end) = out_edges(v, g); ei != ei_end; ++ei) { - w = target(*ei, g); - if (get(comp, w) == (std::numeric_limits<comp_type>::max)()) - put(root, v, this->min_discover_time(get(root,v), get(root,w))); + tarjan_scc_visitor(ComponentMap comp_map, RootMap r, DiscoverTime d, + comp_type& c_, Stack& s_) + : c(c_) + , comp(comp_map) + , root(r) + , discover_time(d) + , dfs_time(time_type()) + , s(s_) + { + } + + template < typename Graph > + void discover_vertex( + typename graph_traits< Graph >::vertex_descriptor v, const Graph&) + { + put(root, v, v); + put(comp, v, (std::numeric_limits< comp_type >::max)()); + put(discover_time, v, dfs_time++); + s.push(v); } - if (get(root, v) == v) { - do { - w = s.top(); s.pop(); - put(comp, w, c); - put(root, w, v); - } while (w != v); - ++c; + template < typename Graph > + void finish_vertex( + typename graph_traits< Graph >::vertex_descriptor v, const Graph& g) + { + typename graph_traits< Graph >::vertex_descriptor w; + typename graph_traits< Graph >::out_edge_iterator ei, ei_end; + for (boost::tie(ei, ei_end) = out_edges(v, g); ei != ei_end; ++ei) + { + w = target(*ei, g); + if (get(comp, w) == (std::numeric_limits< comp_type >::max)()) + put(root, v, + this->min_discover_time(get(root, v), get(root, w))); + } + if (get(root, v) == v) + { + do + { + w = s.top(); + s.pop(); + put(comp, w, c); + put(root, w, v); + } while (w != v); + ++c; + } } - } + private: - template <typename Vertex> - Vertex min_discover_time(Vertex u, Vertex v) { - return get(discover_time, u) < get(discover_time,v) ? u : v; - } - - comp_type& c; - ComponentMap comp; - RootMap root; - DiscoverTime discover_time; - time_type dfs_time; - Stack& s; + template < typename Vertex > + Vertex min_discover_time(Vertex u, Vertex v) + { + return get(discover_time, u) < get(discover_time, v) ? u : v; + } + + comp_type& c; + ComponentMap comp; + RootMap root; + DiscoverTime discover_time; + time_type dfs_time; + Stack& s; }; - - template <class Graph, class ComponentMap, class RootMap, - class DiscoverTime, class P, class T, class R> - typename property_traits<ComponentMap>::value_type - strong_components_impl - (const Graph& g, // Input - ComponentMap comp, // Output - // Internal record keeping - RootMap root, - DiscoverTime discover_time, - const bgl_named_params<P, T, R>& params) + + template < class Graph, class ComponentMap, class RootMap, + class DiscoverTime, class P, class T, class R > + typename property_traits< ComponentMap >::value_type strong_components_impl( + const Graph& g, // Input + ComponentMap comp, // Output + // Internal record keeping + RootMap root, DiscoverTime discover_time, + const bgl_named_params< P, T, R >& params) { - typedef typename graph_traits<Graph>::vertex_descriptor Vertex; - BOOST_CONCEPT_ASSERT(( ReadWritePropertyMapConcept<ComponentMap, Vertex> )); - BOOST_CONCEPT_ASSERT(( ReadWritePropertyMapConcept<RootMap, Vertex> )); - typedef typename property_traits<RootMap>::value_type RootV; - BOOST_CONCEPT_ASSERT(( ConvertibleConcept<RootV, Vertex> )); - BOOST_CONCEPT_ASSERT(( ReadWritePropertyMapConcept<DiscoverTime, Vertex> )); - - typename property_traits<ComponentMap>::value_type total = 0; - - std::stack<Vertex> s; - detail::tarjan_scc_visitor<ComponentMap, RootMap, DiscoverTime, - std::stack<Vertex> > - vis(comp, root, discover_time, total, s); - depth_first_search(g, params.visitor(vis)); - return total; + typedef typename graph_traits< Graph >::vertex_descriptor Vertex; + BOOST_CONCEPT_ASSERT( + (ReadWritePropertyMapConcept< ComponentMap, Vertex >)); + BOOST_CONCEPT_ASSERT((ReadWritePropertyMapConcept< RootMap, Vertex >)); + typedef typename property_traits< RootMap >::value_type RootV; + BOOST_CONCEPT_ASSERT((ConvertibleConcept< RootV, Vertex >)); + BOOST_CONCEPT_ASSERT( + (ReadWritePropertyMapConcept< DiscoverTime, Vertex >)); + + typename property_traits< ComponentMap >::value_type total = 0; + + std::stack< Vertex > s; + detail::tarjan_scc_visitor< ComponentMap, RootMap, DiscoverTime, + std::stack< Vertex > > + vis(comp, root, discover_time, total, s); + depth_first_search(g, params.visitor(vis)); + return total; } //------------------------------------------------------------------------- @@ -116,145 +135,130 @@ namespace boost { // time property maps. // dispatch with class specialization to avoid VC++ bug - template <class DiscoverTimeMap> - struct strong_comp_dispatch2 { - template <class Graph, class ComponentMap, class RootMap, class P, class T, class R> - inline static typename property_traits<ComponentMap>::value_type - apply(const Graph& g, - ComponentMap comp, - RootMap r_map, - const bgl_named_params<P, T, R>& params, - DiscoverTimeMap time_map) - { - return strong_components_impl(g, comp, r_map, time_map, params); - } + template < class DiscoverTimeMap > struct strong_comp_dispatch2 + { + template < class Graph, class ComponentMap, class RootMap, class P, + class T, class R > + inline static typename property_traits< ComponentMap >::value_type + apply(const Graph& g, ComponentMap comp, RootMap r_map, + const bgl_named_params< P, T, R >& params, DiscoverTimeMap time_map) + { + return strong_components_impl(g, comp, r_map, time_map, params); + } }; - - template <> - struct strong_comp_dispatch2<param_not_found> { - template <class Graph, class ComponentMap, class RootMap, - class P, class T, class R> - inline static typename property_traits<ComponentMap>::value_type - apply(const Graph& g, - ComponentMap comp, - RootMap r_map, - const bgl_named_params<P, T, R>& params, - param_not_found) - { - typedef typename graph_traits<Graph>::vertices_size_type size_type; - size_type n = num_vertices(g) > 0 ? num_vertices(g) : 1; - std::vector<size_type> time_vec(n); - return strong_components_impl - (g, comp, r_map, - make_iterator_property_map(time_vec.begin(), choose_const_pmap - (get_param(params, vertex_index), - g, vertex_index), time_vec[0]), - params); - } + template <> struct strong_comp_dispatch2< param_not_found > + { + template < class Graph, class ComponentMap, class RootMap, class P, + class T, class R > + inline static typename property_traits< ComponentMap >::value_type + apply(const Graph& g, ComponentMap comp, RootMap r_map, + const bgl_named_params< P, T, R >& params, param_not_found) + { + typedef + typename graph_traits< Graph >::vertices_size_type size_type; + size_type n = num_vertices(g) > 0 ? num_vertices(g) : 1; + std::vector< size_type > time_vec(n); + return strong_components_impl(g, comp, r_map, + make_iterator_property_map(time_vec.begin(), + choose_const_pmap( + get_param(params, vertex_index), g, vertex_index), + time_vec[0]), + params); + } }; - template <class Graph, class ComponentMap, class RootMap, - class P, class T, class R, class DiscoverTimeMap> - inline typename property_traits<ComponentMap>::value_type - scc_helper2(const Graph& g, - ComponentMap comp, - RootMap r_map, - const bgl_named_params<P, T, R>& params, - DiscoverTimeMap time_map) + template < class Graph, class ComponentMap, class RootMap, class P, class T, + class R, class DiscoverTimeMap > + inline typename property_traits< ComponentMap >::value_type scc_helper2( + const Graph& g, ComponentMap comp, RootMap r_map, + const bgl_named_params< P, T, R >& params, DiscoverTimeMap time_map) { - return strong_comp_dispatch2<DiscoverTimeMap>::apply(g, comp, r_map, params, time_map); + return strong_comp_dispatch2< DiscoverTimeMap >::apply( + g, comp, r_map, params, time_map); } - template <class RootMap> - struct strong_comp_dispatch1 { - - template <class Graph, class ComponentMap, class P, class T, class R> - inline static typename property_traits<ComponentMap>::value_type - apply(const Graph& g, - ComponentMap comp, - const bgl_named_params<P, T, R>& params, - RootMap r_map) - { - return scc_helper2(g, comp, r_map, params, get_param(params, vertex_discover_time)); - } + template < class RootMap > struct strong_comp_dispatch1 + { + + template < class Graph, class ComponentMap, class P, class T, class R > + inline static typename property_traits< ComponentMap >::value_type + apply(const Graph& g, ComponentMap comp, + const bgl_named_params< P, T, R >& params, RootMap r_map) + { + return scc_helper2(g, comp, r_map, params, + get_param(params, vertex_discover_time)); + } }; - template <> - struct strong_comp_dispatch1<param_not_found> { - - template <class Graph, class ComponentMap, - class P, class T, class R> - inline static typename property_traits<ComponentMap>::value_type - apply(const Graph& g, - ComponentMap comp, - const bgl_named_params<P, T, R>& params, - param_not_found) - { - typedef typename graph_traits<Graph>::vertex_descriptor Vertex; - typename std::vector<Vertex>::size_type - n = num_vertices(g) > 0 ? num_vertices(g) : 1; - std::vector<Vertex> root_vec(n); - return scc_helper2 - (g, comp, - make_iterator_property_map(root_vec.begin(), choose_const_pmap - (get_param(params, vertex_index), - g, vertex_index), root_vec[0]), - params, - get_param(params, vertex_discover_time)); - } + template <> struct strong_comp_dispatch1< param_not_found > + { + + template < class Graph, class ComponentMap, class P, class T, class R > + inline static typename property_traits< ComponentMap >::value_type + apply(const Graph& g, ComponentMap comp, + const bgl_named_params< P, T, R >& params, param_not_found) + { + typedef typename graph_traits< Graph >::vertex_descriptor Vertex; + typename std::vector< Vertex >::size_type n + = num_vertices(g) > 0 ? num_vertices(g) : 1; + std::vector< Vertex > root_vec(n); + return scc_helper2(g, comp, + make_iterator_property_map(root_vec.begin(), + choose_const_pmap( + get_param(params, vertex_index), g, vertex_index), + root_vec[0]), + params, get_param(params, vertex_discover_time)); + } }; - template <class Graph, class ComponentMap, class RootMap, - class P, class T, class R> - inline typename property_traits<ComponentMap>::value_type - scc_helper1(const Graph& g, - ComponentMap comp, - const bgl_named_params<P, T, R>& params, - RootMap r_map) + template < class Graph, class ComponentMap, class RootMap, class P, class T, + class R > + inline typename property_traits< ComponentMap >::value_type scc_helper1( + const Graph& g, ComponentMap comp, + const bgl_named_params< P, T, R >& params, RootMap r_map) { - return detail::strong_comp_dispatch1<RootMap>::apply(g, comp, params, - r_map); + return detail::strong_comp_dispatch1< RootMap >::apply( + g, comp, params, r_map); } - } // namespace detail - - template <class Graph, class ComponentMap, - class P, class T, class R> - inline typename property_traits<ComponentMap>::value_type - strong_components(const Graph& g, ComponentMap comp, - const bgl_named_params<P, T, R>& params - BOOST_GRAPH_ENABLE_IF_MODELS_PARM(Graph, vertex_list_graph_tag)) - { - typedef typename graph_traits<Graph>::directed_category DirCat; - BOOST_STATIC_ASSERT((is_convertible<DirCat*, directed_tag*>::value == true)); - return detail::scc_helper1(g, comp, params, - get_param(params, vertex_root_t())); - } - - template <class Graph, class ComponentMap> - inline typename property_traits<ComponentMap>::value_type - strong_components(const Graph& g, ComponentMap comp - BOOST_GRAPH_ENABLE_IF_MODELS_PARM(Graph, vertex_list_graph_tag)) - { - typedef typename graph_traits<Graph>::directed_category DirCat; - BOOST_STATIC_ASSERT((is_convertible<DirCat*, directed_tag*>::value == true)); - bgl_named_params<int, int> params(0); +} // namespace detail + +template < class Graph, class ComponentMap, class P, class T, class R > +inline typename property_traits< ComponentMap >::value_type strong_components( + const Graph& g, ComponentMap comp, + const bgl_named_params< P, T, R >& params BOOST_GRAPH_ENABLE_IF_MODELS_PARM( + Graph, vertex_list_graph_tag)) +{ + typedef typename graph_traits< Graph >::directed_category DirCat; + BOOST_STATIC_ASSERT( + (is_convertible< DirCat*, directed_tag* >::value == true)); + return detail::scc_helper1( + g, comp, params, get_param(params, vertex_root_t())); +} + +template < class Graph, class ComponentMap > +inline typename property_traits< ComponentMap >::value_type strong_components( + const Graph& g, + ComponentMap comp BOOST_GRAPH_ENABLE_IF_MODELS_PARM( + Graph, vertex_list_graph_tag)) +{ + typedef typename graph_traits< Graph >::directed_category DirCat; + BOOST_STATIC_ASSERT( + (is_convertible< DirCat*, directed_tag* >::value == true)); + bgl_named_params< int, int > params(0); return strong_components(g, comp, params); - } - - template <typename Graph, typename ComponentMap, typename ComponentLists> - void build_component_lists - (const Graph& g, - typename graph_traits<Graph>::vertices_size_type num_scc, - ComponentMap component_number, - ComponentLists& components) - { +} + +template < typename Graph, typename ComponentMap, typename ComponentLists > +void build_component_lists(const Graph& g, + typename graph_traits< Graph >::vertices_size_type num_scc, + ComponentMap component_number, ComponentLists& components) +{ components.resize(num_scc); - typename graph_traits<Graph>::vertex_iterator vi, vi_end; + typename graph_traits< Graph >::vertex_iterator vi, vi_end; for (boost::tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi) - components[component_number[*vi]].push_back(*vi); - } - + components[component_number[*vi]].push_back(*vi); +} } // namespace boost @@ -264,80 +268,80 @@ namespace boost { #include <boost/pending/indirect_cmp.hpp> #include <boost/graph/connected_components.hpp> // for components_recorder -namespace boost { - - //========================================================================== - // This is the version of strongly connected components from - // "Intro. to Algorithms" by Cormen, Leiserson, Rivest, which was - // adapted from "Data Structure and Algorithms" by Aho, Hopcroft, - // and Ullman, who credit the algorithm to S.R. Kosaraju and M. Sharir. - // The algorithm is based on computing DFS forests the graph - // and its transpose. - - // This algorithm is slower than Tarjan's by a constant factor, uses - // more memory, and puts more requirements on the graph type. - - template <class Graph, class DFSVisitor, class ComponentsMap, - class DiscoverTime, class FinishTime, - class ColorMap> - typename property_traits<ComponentsMap>::value_type - kosaraju_strong_components(Graph& G, ComponentsMap c, - FinishTime finish_time, ColorMap color) - { - BOOST_CONCEPT_ASSERT(( MutableGraphConcept<Graph> )); +namespace boost +{ + +//========================================================================== +// This is the version of strongly connected components from +// "Intro. to Algorithms" by Cormen, Leiserson, Rivest, which was +// adapted from "Data Structure and Algorithms" by Aho, Hopcroft, +// and Ullman, who credit the algorithm to S.R. Kosaraju and M. Sharir. +// The algorithm is based on computing DFS forests the graph +// and its transpose. + +// This algorithm is slower than Tarjan's by a constant factor, uses +// more memory, and puts more requirements on the graph type. + +template < class Graph, class DFSVisitor, class ComponentsMap, + class DiscoverTime, class FinishTime, class ColorMap > +typename property_traits< ComponentsMap >::value_type +kosaraju_strong_components( + Graph& G, ComponentsMap c, FinishTime finish_time, ColorMap color) +{ + BOOST_CONCEPT_ASSERT((MutableGraphConcept< Graph >)); // ... - - typedef typename graph_traits<Graph>::vertex_descriptor Vertex; - typedef typename property_traits<ColorMap>::value_type ColorValue; - typedef color_traits<ColorValue> Color; - typename property_traits<FinishTime>::value_type time = 0; - depth_first_search - (G, make_dfs_visitor(stamp_times(finish_time, time, on_finish_vertex())), - color); + + typedef typename graph_traits< Graph >::vertex_descriptor Vertex; + typedef typename property_traits< ColorMap >::value_type ColorValue; + typedef color_traits< ColorValue > Color; + typename property_traits< FinishTime >::value_type time = 0; + depth_first_search(G, + make_dfs_visitor(stamp_times(finish_time, time, on_finish_vertex())), + color); Graph G_T(num_vertices(G)); transpose_graph(G, G_T); - typedef typename property_traits<ComponentsMap>::value_type count_type; + typedef typename property_traits< ComponentsMap >::value_type count_type; count_type c_count(0); - detail::components_recorder<ComponentsMap> - vis(c, c_count); + detail::components_recorder< ComponentsMap > vis(c, c_count); // initialize G_T - typename graph_traits<Graph>::vertex_iterator ui, ui_end; + typename graph_traits< Graph >::vertex_iterator ui, ui_end; for (boost::tie(ui, ui_end) = vertices(G_T); ui != ui_end; ++ui) - put(color, *ui, Color::white()); + put(color, *ui, Color::white()); - typedef typename property_traits<FinishTime>::value_type D; - typedef indirect_cmp< FinishTime, std::less<D> > Compare; + typedef typename property_traits< FinishTime >::value_type D; + typedef indirect_cmp< FinishTime, std::less< D > > Compare; Compare fl(finish_time); - std::priority_queue<Vertex, std::vector<Vertex>, Compare > Q(fl); + std::priority_queue< Vertex, std::vector< Vertex >, Compare > Q(fl); - typename graph_traits<Graph>::vertex_iterator i, j, iend, jend; + typename graph_traits< Graph >::vertex_iterator i, j, iend, jend; boost::tie(i, iend) = vertices(G_T); boost::tie(j, jend) = vertices(G); - for ( ; i != iend; ++i, ++j) { - put(finish_time, *i, get(finish_time, *j)); - Q.push(*i); + for (; i != iend; ++i, ++j) + { + put(finish_time, *i, get(finish_time, *j)); + Q.push(*i); } - while ( !Q.empty() ) { - Vertex u = Q.top(); - Q.pop(); - if (get(color, u) == Color::white()) { - depth_first_visit(G_T, u, vis, color); - ++c_count; - } + while (!Q.empty()) + { + Vertex u = Q.top(); + Q.pop(); + if (get(color, u) == Color::white()) + { + depth_first_visit(G_T, u, vis, color); + ++c_count; + } } return c_count; - } +} } // namespace boost -#ifdef BOOST_GRAPH_USE_MPI -# error #include <boost/graph/distributed/strong_components.hpp> -#endif +#include BOOST_GRAPH_MPI_INCLUDE(<boost/graph/distributed/strong_components.hpp>) #endif // BOOST_GRAPH_STRONG_COMPONENTS_HPP diff --git a/contrib/restricted/boost/graph/include/boost/graph/subgraph.hpp b/contrib/restricted/boost/graph/include/boost/graph/subgraph.hpp index 22706bc617..7f8bd809e2 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/subgraph.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/subgraph.hpp @@ -28,9 +28,12 @@ #include <boost/mpl/if.hpp> #include <boost/mpl/or.hpp> -namespace boost { +namespace boost +{ -struct subgraph_tag { }; +struct subgraph_tag +{ +}; /** @name Property Lookup * The local_property and global_property functions are used to create @@ -39,29 +42,29 @@ struct subgraph_tag { }; * Property types. */ //@{ -template <typename T> -struct local_property +template < typename T > struct local_property { typedef T kind; - local_property(T x) : value(x) { } + local_property(T x) : value(x) {} T value; }; -template <typename T> -inline local_property<T> local(T x) -{ return local_property<T>(x); } +template < typename T > inline local_property< T > local(T x) +{ + return local_property< T >(x); +} -template <typename T> -struct global_property +template < typename T > struct global_property { typedef T kind; - global_property(T x) : value(x) { } + global_property(T x) : value(x) {} T value; }; -template <typename T> -inline global_property<T> global(T x) -{ return global_property<T>(x); } +template < typename T > inline global_property< T > global(T x) +{ + return global_property< T >(x); +} //@} // Invariants of an induced subgraph: @@ -76,113 +79,121 @@ inline global_property<T> global(T x) // assumed that the edge vertices are assigned automatically, they are // explicitly assigned here. -template <typename Graph> -class subgraph { - typedef graph_traits<Graph> Traits; - typedef std::list<subgraph<Graph>*> ChildrenList; +template < typename Graph > class subgraph +{ + typedef graph_traits< Graph > Traits; + typedef std::list< subgraph< Graph >* > ChildrenList; + public: // Graph requirements - typedef typename Traits::vertex_descriptor vertex_descriptor; - typedef typename Traits::edge_descriptor edge_descriptor; - typedef typename Traits::directed_category directed_category; - typedef typename Traits::edge_parallel_category edge_parallel_category; - typedef typename Traits::traversal_category traversal_category; + typedef typename Traits::vertex_descriptor vertex_descriptor; + typedef typename Traits::edge_descriptor edge_descriptor; + typedef typename Traits::directed_category directed_category; + typedef typename Traits::edge_parallel_category edge_parallel_category; + typedef typename Traits::traversal_category traversal_category; // IncidenceGraph requirements - typedef typename Traits::out_edge_iterator out_edge_iterator; - typedef typename Traits::degree_size_type degree_size_type; + typedef typename Traits::out_edge_iterator out_edge_iterator; + typedef typename Traits::degree_size_type degree_size_type; // AdjacencyGraph requirements - typedef typename Traits::adjacency_iterator adjacency_iterator; + typedef typename Traits::adjacency_iterator adjacency_iterator; // VertexListGraph requirements - typedef typename Traits::vertex_iterator vertex_iterator; - typedef typename Traits::vertices_size_type vertices_size_type; + typedef typename Traits::vertex_iterator vertex_iterator; + typedef typename Traits::vertices_size_type vertices_size_type; // EdgeListGraph requirements - typedef typename Traits::edge_iterator edge_iterator; - typedef typename Traits::edges_size_type edges_size_type; + typedef typename Traits::edge_iterator edge_iterator; + typedef typename Traits::edges_size_type edges_size_type; - typedef typename Traits::in_edge_iterator in_edge_iterator; + typedef typename Traits::in_edge_iterator in_edge_iterator; - typedef typename edge_property_type<Graph>::type edge_property_type; - typedef typename vertex_property_type<Graph>::type vertex_property_type; - typedef subgraph_tag graph_tag; - typedef Graph graph_type; - typedef typename graph_property_type<Graph>::type graph_property_type; + typedef typename edge_property_type< Graph >::type edge_property_type; + typedef typename vertex_property_type< Graph >::type vertex_property_type; + typedef subgraph_tag graph_tag; + typedef Graph graph_type; + typedef typename graph_property_type< Graph >::type graph_property_type; // Create the main graph, the root of the subgraph tree - subgraph() - : m_parent(0), m_edge_counter(0) - { } + subgraph() : m_parent(0), m_edge_counter(0) {} subgraph(const graph_property_type& p) - : m_graph(p), m_parent(0), m_edge_counter(0) - { } + : m_graph(p), m_parent(0), m_edge_counter(0) + { + } - subgraph(vertices_size_type n, const graph_property_type& p = graph_property_type()) - : m_graph(n, p), m_parent(0), m_edge_counter(0), m_global_vertex(n) + subgraph(vertices_size_type n, + const graph_property_type& p = graph_property_type()) + : m_graph(n, p), m_parent(0), m_edge_counter(0), m_global_vertex(n) { typename Graph::vertex_iterator v, v_end; vertices_size_type i = 0; - for(boost::tie(v, v_end) = vertices(m_graph); v != v_end; ++v) + for (boost::tie(v, v_end) = vertices(m_graph); v != v_end; ++v) m_global_vertex[i++] = *v; } // copy constructor - subgraph(const subgraph& x) - : m_parent(x.m_parent), m_edge_counter(x.m_edge_counter) - , m_global_vertex(x.m_global_vertex), m_global_edge(x.m_global_edge) + subgraph(const subgraph& x) : m_parent(x.m_parent), m_edge_counter(0) { - if(x.is_root()) + if (x.is_root()) { - m_graph = x.m_graph; + m_graph = x.m_graph; + m_edge_counter = x.m_edge_counter; + m_global_vertex = x.m_global_vertex; + m_global_edge = x.m_global_edge; + } + else + { + get_property(*this) = get_property(x); + typename subgraph< Graph >::vertex_iterator vi, vi_end; + boost::tie(vi, vi_end) = vertices(x); + for (; vi != vi_end; ++vi) + { + add_vertex(x.local_to_global(*vi), *this); + } } // Do a deep copy (recursive). // Only the root graph is copied, the subgraphs contain // only references to the global vertices they own. - typename subgraph<Graph>::children_iterator i,i_end; - boost::tie(i,i_end) = x.children(); - for(; i != i_end; ++i) - { - subgraph<Graph> child = this->create_subgraph(); - child = *i; - vertex_iterator vi,vi_end; - boost::tie(vi,vi_end) = vertices(*i); - for (;vi!=vi_end;++vi) - { - add_vertex(*vi,child); - } - } + typename subgraph< Graph >::children_iterator i, i_end; + boost::tie(i, i_end) = x.children(); + for (; i != i_end; ++i) + { + m_children.push_back(new subgraph< Graph >(*i)); + m_children.back()->m_parent = this; + } } - - ~subgraph() { - for(typename ChildrenList::iterator i = m_children.begin(); - i != m_children.end(); ++i) + ~subgraph() + { + for (typename ChildrenList::iterator i = m_children.begin(); + i != m_children.end(); ++i) { delete *i; } } // Return a null vertex descriptor for the graph. - static vertex_descriptor null_vertex() - { return Traits::null_vertex(); } - + static vertex_descriptor null_vertex() { return Traits::null_vertex(); } // Create a subgraph - subgraph<Graph>& create_subgraph() { - m_children.push_back(new subgraph<Graph>()); + subgraph< Graph >& create_subgraph() + { + m_children.push_back(new subgraph< Graph >()); m_children.back()->m_parent = this; return *m_children.back(); } // Create a subgraph with the specified vertex set. - template <typename VertexIterator> - subgraph<Graph>& create_subgraph(VertexIterator first, VertexIterator last) { - m_children.push_back(new subgraph<Graph>()); + template < typename VertexIterator > + subgraph< Graph >& create_subgraph( + VertexIterator first, VertexIterator last) + { + m_children.push_back(new subgraph< Graph >()); m_children.back()->m_parent = this; - for(; first != last; ++first) { + for (; first != last; ++first) + { add_vertex(*first, *m_children.back()); } return *m_children.back(); @@ -190,39 +201,57 @@ public: // local <-> global descriptor conversion functions vertex_descriptor local_to_global(vertex_descriptor u_local) const - { return is_root() ? u_local : m_global_vertex[u_local]; } + { + return is_root() ? u_local : m_global_vertex[u_local]; + } - vertex_descriptor global_to_local(vertex_descriptor u_global) const { - vertex_descriptor u_local; bool in_subgraph; - if (is_root()) return u_global; + vertex_descriptor global_to_local(vertex_descriptor u_global) const + { + vertex_descriptor u_local; + bool in_subgraph; + if (is_root()) + return u_global; boost::tie(u_local, in_subgraph) = this->find_vertex(u_global); BOOST_ASSERT(in_subgraph == true); return u_local; } edge_descriptor local_to_global(edge_descriptor e_local) const - { return is_root() ? e_local : m_global_edge[get(get(edge_index, m_graph), e_local)]; } + { + return is_root() + ? e_local + : m_global_edge[get(get(edge_index, m_graph), e_local)]; + } edge_descriptor global_to_local(edge_descriptor e_global) const - { return is_root() ? e_global : (*m_local_edge.find(get(get(edge_index, root().m_graph), e_global))).second; } + { + return is_root() ? e_global + : (*m_local_edge.find( + get(get(edge_index, root().m_graph), e_global))) + .second; + } // Is vertex u (of the root graph) contained in this subgraph? // If so, return the matching local vertex. - std::pair<vertex_descriptor, bool> - find_vertex(vertex_descriptor u_global) const { - if (is_root()) return std::make_pair(u_global, true); - typename LocalVertexMap::const_iterator i = m_local_vertex.find(u_global); + std::pair< vertex_descriptor, bool > find_vertex( + vertex_descriptor u_global) const + { + if (is_root()) + return std::make_pair(u_global, true); + typename LocalVertexMap::const_iterator i + = m_local_vertex.find(u_global); bool valid = i != m_local_vertex.end(); return std::make_pair((valid ? (*i).second : null_vertex()), valid); } // Is edge e (of the root graph) contained in this subgraph? // If so, return the matching local edge. - std::pair<edge_descriptor, bool> - find_edge(edge_descriptor e_global) const { - if (is_root()) return std::make_pair(e_global, true); - typename LocalEdgeMap::const_iterator i = - m_local_edge.find(get(get(edge_index, root().m_graph), e_global)); + std::pair< edge_descriptor, bool > find_edge(edge_descriptor e_global) const + { + if (is_root()) + return std::make_pair(e_global, true); + typename LocalEdgeMap::const_iterator i + = m_local_edge.find(get(get(edge_index, root().m_graph), e_global)); bool valid = i != m_local_edge.end(); return std::make_pair((valid ? (*i).second : edge_descriptor()), valid); } @@ -235,90 +264,101 @@ public: bool is_root() const { return m_parent == 0; } // Return the root graph of the subgraph tree. - subgraph& root() - { return is_root() ? *this : m_parent->root(); } + subgraph& root() { return is_root() ? *this : m_parent->root(); } const subgraph& root() const - { return is_root() ? *this : m_parent->root(); } + { + return is_root() ? *this : m_parent->root(); + } // Return the children subgraphs of this graph/subgraph. // Use a list of pointers because the VC++ std::list doesn't like // storing incomplete type. - typedef indirect_iterator< - typename ChildrenList::const_iterator - , subgraph<Graph> - , std::bidirectional_iterator_tag - > - children_iterator; - - typedef indirect_iterator< - typename ChildrenList::const_iterator - , subgraph<Graph> const - , std::bidirectional_iterator_tag - > - const_children_iterator; - - std::pair<const_children_iterator, const_children_iterator> children() const { - return std::make_pair(const_children_iterator(m_children.begin()), - const_children_iterator(m_children.end())); + typedef indirect_iterator< typename ChildrenList::const_iterator, + subgraph< Graph >, std::bidirectional_iterator_tag > + children_iterator; + + typedef indirect_iterator< typename ChildrenList::const_iterator, + subgraph< Graph > const, std::bidirectional_iterator_tag > + const_children_iterator; + + std::pair< const_children_iterator, const_children_iterator > + children() const + { + return std::make_pair(const_children_iterator(m_children.begin()), + const_children_iterator(m_children.end())); } - std::pair<children_iterator, children_iterator> children() { - return std::make_pair(children_iterator(m_children.begin()), - children_iterator(m_children.end())); + std::pair< children_iterator, children_iterator > children() + { + return std::make_pair(children_iterator(m_children.begin()), + children_iterator(m_children.end())); } std::size_t num_children() const { return m_children.size(); } #ifndef BOOST_GRAPH_NO_BUNDLED_PROPERTIES // Defualt property access delegates the lookup to global properties. - template <typename Descriptor> - typename graph::detail::bundled_result<Graph, Descriptor>::type& + template < typename Descriptor > + typename graph::detail::bundled_result< Graph, Descriptor >::type& operator[](Descriptor x) - { return is_root() ? m_graph[x] : root().m_graph[local_to_global(x)]; } + { + return is_root() ? m_graph[x] : root().m_graph[local_to_global(x)]; + } - template <typename Descriptor> - typename graph::detail::bundled_result<Graph, Descriptor>::type const& + template < typename Descriptor > + typename graph::detail::bundled_result< Graph, Descriptor >::type const& operator[](Descriptor x) const - { return is_root() ? m_graph[x] : root().m_graph[local_to_global(x)]; } + { + return is_root() ? m_graph[x] : root().m_graph[local_to_global(x)]; + } // Local property access returns the local property of the given descripor. - template <typename Descriptor> - typename graph::detail::bundled_result<Graph, Descriptor>::type& - operator[](local_property<Descriptor> x) - { return m_graph[x.value]; } + template < typename Descriptor > + typename graph::detail::bundled_result< Graph, Descriptor >::type& + operator[](local_property< Descriptor > x) + { + return m_graph[x.value]; + } - template <typename Descriptor> - typename graph::detail::bundled_result<Graph, Descriptor>::type const& - operator[](local_property<Descriptor> x) const - { return m_graph[x.value]; } + template < typename Descriptor > + typename graph::detail::bundled_result< Graph, Descriptor >::type const& + operator[](local_property< Descriptor > x) const + { + return m_graph[x.value]; + } // Global property access returns the global property associated with the // given descriptor. This is an alias for the default bundled property // access operations. - template <typename Descriptor> - typename graph::detail::bundled_result<Graph, Descriptor>::type& - operator[](global_property<Descriptor> x) - { return (*this)[x.value]; } + template < typename Descriptor > + typename graph::detail::bundled_result< Graph, Descriptor >::type& + operator[](global_property< Descriptor > x) + { + return (*this)[x.value]; + } - template <typename Descriptor> - typename graph::detail::bundled_result<Graph, Descriptor>::type const& - operator[](global_property<Descriptor> x) const - { return (*this)[x.value]; } + template < typename Descriptor > + typename graph::detail::bundled_result< Graph, Descriptor >::type const& + operator[](global_property< Descriptor > x) const + { + return (*this)[x.value]; + } #endif // BOOST_GRAPH_NO_BUNDLED_PROPERTIES // private: - typedef typename property_map<Graph, edge_index_t>::type EdgeIndexMap; - typedef typename property_traits<EdgeIndexMap>::value_type edge_index_type; - BOOST_STATIC_ASSERT((!is_same<edge_index_type, - boost::detail::error_property_not_found>::value)); + typedef typename property_map< Graph, edge_index_t >::type EdgeIndexMap; + typedef + typename property_traits< EdgeIndexMap >::value_type edge_index_type; + BOOST_STATIC_ASSERT((!is_same< edge_index_type, + boost::detail::error_property_not_found >::value)); private: - typedef std::vector<vertex_descriptor> GlobalVertexList; - typedef std::vector<edge_descriptor> GlobalEdgeList; - typedef std::map<vertex_descriptor, vertex_descriptor> LocalVertexMap; - typedef std::map<edge_index_type, edge_descriptor> LocalEdgeMap; + typedef std::vector< vertex_descriptor > GlobalVertexList; + typedef std::vector< edge_descriptor > GlobalEdgeList; + typedef std::map< vertex_descriptor, vertex_descriptor > LocalVertexMap; + typedef std::map< edge_index_type, edge_descriptor > LocalEdgeMap; // TODO: Should the LocalVertexMap be: map<index_type, descriptor>? // TODO: Can we relax the indexing requirement if both descriptors are // LessThanComparable? @@ -326,17 +366,16 @@ private: public: // Probably shouldn't be public.... Graph m_graph; - subgraph<Graph>* m_parent; + subgraph< Graph >* m_parent; edge_index_type m_edge_counter; // for generating unique edge indices ChildrenList m_children; GlobalVertexList m_global_vertex; // local -> global - LocalVertexMap m_local_vertex; // global -> local - GlobalEdgeList m_global_edge; // local -> global + LocalVertexMap m_local_vertex; // global -> local + GlobalEdgeList m_global_edge; // local -> global LocalEdgeMap m_local_edge; // global -> local edge_descriptor local_add_edge(vertex_descriptor u_local, - vertex_descriptor v_local, - edge_descriptor e_global) + vertex_descriptor v_local, edge_descriptor e_global) { edge_descriptor e_local; bool inserted; @@ -348,68 +387,84 @@ public: // Probably shouldn't be public.... } }; -template <typename Graph> -struct vertex_bundle_type<subgraph<Graph> > - : vertex_bundle_type<Graph> -{ }; +template < typename Graph > +struct vertex_bundle_type< subgraph< Graph > > : vertex_bundle_type< Graph > +{ +}; -template<typename Graph> -struct edge_bundle_type<subgraph<Graph> > - : edge_bundle_type<Graph> -{ }; +template < typename Graph > +struct edge_bundle_type< subgraph< Graph > > : edge_bundle_type< Graph > +{ +}; -template<typename Graph> -struct graph_bundle_type<subgraph<Graph> > - : graph_bundle_type<Graph> -{ }; +template < typename Graph > +struct graph_bundle_type< subgraph< Graph > > : graph_bundle_type< Graph > +{ +}; //=========================================================================== // Functions special to the Subgraph Class -template <typename G> -typename subgraph<G>::vertex_descriptor -add_vertex(typename subgraph<G>::vertex_descriptor u_global, - subgraph<G>& g) +template < typename G > +typename subgraph< G >::vertex_descriptor add_vertex( + typename subgraph< G >::vertex_descriptor u_global, subgraph< G >& g) { BOOST_ASSERT(!g.is_root()); - typename subgraph<G>::vertex_descriptor u_local, v_global; - typename subgraph<G>::edge_descriptor e_global; + typename subgraph< G >::vertex_descriptor u_local; + bool exists_local; + boost::tie(u_local, exists_local) = g.find_vertex(u_global); - u_local = add_vertex(g.m_graph); - g.m_global_vertex.push_back(u_global); - g.m_local_vertex[u_global] = u_local; + if (!exists_local) + { + typename subgraph< G >::vertex_descriptor v_global; + typename subgraph< G >::edge_descriptor e_global; + // call recursion for parent subgraph + if (!g.parent().is_root()) + add_vertex(u_global, g.parent()); - subgraph<G>& r = g.root(); + u_local = add_vertex(g.m_graph); + g.m_global_vertex.push_back(u_global); + g.m_local_vertex[u_global] = u_local; - // remember edge global and local maps - { - typename subgraph<G>::out_edge_iterator ei, ei_end; - for (boost::tie(ei, ei_end) = out_edges(u_global, r); - ei != ei_end; ++ei) { - e_global = *ei; - v_global = target(e_global, r); - if (g.find_vertex(v_global).second == true) - g.local_add_edge(u_local, g.global_to_local(v_global), e_global); - } - } - if (is_directed(g)) { // not necessary for undirected graph - typename subgraph<G>::vertex_iterator vi, vi_end; - typename subgraph<G>::out_edge_iterator ei, ei_end; - for(boost::tie(vi, vi_end) = vertices(r); vi != vi_end; ++vi) { - v_global = *vi; - if (v_global == u_global) - continue; // don't insert self loops twice! - if (!g.find_vertex(v_global).second) - continue; // not a subgraph vertex => try next one - for(boost::tie(ei, ei_end) = out_edges(*vi, r); ei != ei_end; ++ei) { + subgraph< G >& r = g.root(); + + // remember edge global and local maps + { + typename subgraph< G >::out_edge_iterator ei, ei_end; + for (boost::tie(ei, ei_end) = out_edges(u_global, r); ei != ei_end; + ++ei) + { e_global = *ei; - if(target(e_global, r) == u_global) { - g.local_add_edge(g.global_to_local(v_global), u_local, e_global); + v_global = target(e_global, r); + if (g.find_vertex(v_global).second == true) + g.local_add_edge( + u_local, g.global_to_local(v_global), e_global); + } + } + if (is_directed(g)) + { // not necessary for undirected graph + typename subgraph< G >::vertex_iterator vi, vi_end; + typename subgraph< G >::out_edge_iterator ei, ei_end; + for (boost::tie(vi, vi_end) = vertices(r); vi != vi_end; ++vi) + { + v_global = *vi; + if (v_global == u_global) + continue; // don't insert self loops twice! + if (!g.find_vertex(v_global).second) + continue; // not a subgraph vertex => try next one + for (boost::tie(ei, ei_end) = out_edges(*vi, r); ei != ei_end; + ++ei) + { + e_global = *ei; + if (target(e_global, r) == u_global) + { + g.local_add_edge( + g.global_to_local(v_global), u_local, e_global); + } } } } } - return u_local; } @@ -418,147 +473,181 @@ add_vertex(typename subgraph<G>::vertex_descriptor u_global, //=========================================================================== // Functions required by the IncidenceGraph concept -template <typename G> -std::pair<typename graph_traits<G>::out_edge_iterator, - typename graph_traits<G>::out_edge_iterator> -out_edges(typename graph_traits<G>::vertex_descriptor v, const subgraph<G>& g) -{ return out_edges(v, g.m_graph); } +template < typename G > +std::pair< typename graph_traits< G >::out_edge_iterator, + typename graph_traits< G >::out_edge_iterator > +out_edges( + typename graph_traits< G >::vertex_descriptor v, const subgraph< G >& g) +{ + return out_edges(v, g.m_graph); +} -template <typename G> -typename graph_traits<G>::degree_size_type -out_degree(typename graph_traits<G>::vertex_descriptor v, const subgraph<G>& g) -{ return out_degree(v, g.m_graph); } +template < typename G > +typename graph_traits< G >::degree_size_type out_degree( + typename graph_traits< G >::vertex_descriptor v, const subgraph< G >& g) +{ + return out_degree(v, g.m_graph); +} -template <typename G> -typename graph_traits<G>::vertex_descriptor -source(typename graph_traits<G>::edge_descriptor e, const subgraph<G>& g) -{ return source(e, g.m_graph); } +template < typename G > +typename graph_traits< G >::vertex_descriptor source( + typename graph_traits< G >::edge_descriptor e, const subgraph< G >& g) +{ + return source(e, g.m_graph); +} -template <typename G> -typename graph_traits<G>::vertex_descriptor -target(typename graph_traits<G>::edge_descriptor e, const subgraph<G>& g) -{ return target(e, g.m_graph); } +template < typename G > +typename graph_traits< G >::vertex_descriptor target( + typename graph_traits< G >::edge_descriptor e, const subgraph< G >& g) +{ + return target(e, g.m_graph); +} //=========================================================================== // Functions required by the BidirectionalGraph concept -template <typename G> -std::pair<typename graph_traits<G>::in_edge_iterator, - typename graph_traits<G>::in_edge_iterator> -in_edges(typename graph_traits<G>::vertex_descriptor v, const subgraph<G>& g) -{ return in_edges(v, g.m_graph); } +template < typename G > +std::pair< typename graph_traits< G >::in_edge_iterator, + typename graph_traits< G >::in_edge_iterator > +in_edges( + typename graph_traits< G >::vertex_descriptor v, const subgraph< G >& g) +{ + return in_edges(v, g.m_graph); +} -template <typename G> -typename graph_traits<G>::degree_size_type -in_degree(typename graph_traits<G>::vertex_descriptor v, const subgraph<G>& g) -{ return in_degree(v, g.m_graph); } +template < typename G > +typename graph_traits< G >::degree_size_type in_degree( + typename graph_traits< G >::vertex_descriptor v, const subgraph< G >& g) +{ + return in_degree(v, g.m_graph); +} -template <typename G> -typename graph_traits<G>::degree_size_type -degree(typename graph_traits<G>::vertex_descriptor v, const subgraph<G>& g) -{ return degree(v, g.m_graph); } +template < typename G > +typename graph_traits< G >::degree_size_type degree( + typename graph_traits< G >::vertex_descriptor v, const subgraph< G >& g) +{ + return degree(v, g.m_graph); +} //=========================================================================== // Functions required by the AdjacencyGraph concept -template <typename G> -std::pair<typename subgraph<G>::adjacency_iterator, - typename subgraph<G>::adjacency_iterator> -adjacent_vertices(typename subgraph<G>::vertex_descriptor v, const subgraph<G>& g) -{ return adjacent_vertices(v, g.m_graph); } +template < typename G > +std::pair< typename subgraph< G >::adjacency_iterator, + typename subgraph< G >::adjacency_iterator > +adjacent_vertices( + typename subgraph< G >::vertex_descriptor v, const subgraph< G >& g) +{ + return adjacent_vertices(v, g.m_graph); +} //=========================================================================== // Functions required by the VertexListGraph concept -template <typename G> -std::pair<typename subgraph<G>::vertex_iterator, - typename subgraph<G>::vertex_iterator> -vertices(const subgraph<G>& g) -{ return vertices(g.m_graph); } +template < typename G > +std::pair< typename subgraph< G >::vertex_iterator, + typename subgraph< G >::vertex_iterator > +vertices(const subgraph< G >& g) +{ + return vertices(g.m_graph); +} -template <typename G> -typename subgraph<G>::vertices_size_type -num_vertices(const subgraph<G>& g) -{ return num_vertices(g.m_graph); } +template < typename G > +typename subgraph< G >::vertices_size_type num_vertices(const subgraph< G >& g) +{ + return num_vertices(g.m_graph); +} //=========================================================================== // Functions required by the EdgeListGraph concept -template <typename G> -std::pair<typename subgraph<G>::edge_iterator, - typename subgraph<G>::edge_iterator> -edges(const subgraph<G>& g) -{ return edges(g.m_graph); } +template < typename G > +std::pair< typename subgraph< G >::edge_iterator, + typename subgraph< G >::edge_iterator > +edges(const subgraph< G >& g) +{ + return edges(g.m_graph); +} -template <typename G> -typename subgraph<G>::edges_size_type -num_edges(const subgraph<G>& g) -{ return num_edges(g.m_graph); } +template < typename G > +typename subgraph< G >::edges_size_type num_edges(const subgraph< G >& g) +{ + return num_edges(g.m_graph); +} //=========================================================================== // Functions required by the AdjacencyMatrix concept -template <typename G> -std::pair<typename subgraph<G>::edge_descriptor, bool> -edge(typename subgraph<G>::vertex_descriptor u, - typename subgraph<G>::vertex_descriptor v, - const subgraph<G>& g) -{ return edge(u, v, g.m_graph); } +template < typename G > +std::pair< typename subgraph< G >::edge_descriptor, bool > edge( + typename subgraph< G >::vertex_descriptor u, + typename subgraph< G >::vertex_descriptor v, const subgraph< G >& g) +{ + return edge(u, v, g.m_graph); +} //=========================================================================== // Functions required by the MutableGraph concept -namespace detail { +namespace detail +{ - template <typename Vertex, typename Edge, typename Graph> - void add_edge_recur_down(Vertex u_global, Vertex v_global, Edge e_global, - subgraph<Graph>& g); + template < typename Vertex, typename Edge, typename Graph > + void add_edge_recur_down( + Vertex u_global, Vertex v_global, Edge e_global, subgraph< Graph >& g); - template <typename Vertex, typename Edge, typename Children, typename G> + template < typename Vertex, typename Edge, typename Children, typename G > void children_add_edge(Vertex u_global, Vertex v_global, Edge e_global, - Children& c, subgraph<G>* orig) + Children& c, subgraph< G >* orig) { - for(typename Children::iterator i = c.begin(); i != c.end(); ++i) { - if ((*i)->find_vertex(u_global).second && - (*i)->find_vertex(v_global).second) + for (typename Children::iterator i = c.begin(); i != c.end(); ++i) + { + if ((*i)->find_vertex(u_global).second + && (*i)->find_vertex(v_global).second) { add_edge_recur_down(u_global, v_global, e_global, **i, orig); } } } - template <typename Vertex, typename Edge, typename Graph> + template < typename Vertex, typename Edge, typename Graph > void add_edge_recur_down(Vertex u_global, Vertex v_global, Edge e_global, - subgraph<Graph>& g, subgraph<Graph>* orig) + subgraph< Graph >& g, subgraph< Graph >* orig) { - if(&g != orig ) { + if (&g != orig) + { // add local edge only if u_global and v_global are in subgraph g Vertex u_local, v_local; bool u_in_subgraph, v_in_subgraph; boost::tie(u_local, u_in_subgraph) = g.find_vertex(u_global); boost::tie(v_local, v_in_subgraph) = g.find_vertex(v_global); - if(u_in_subgraph && v_in_subgraph) { + if (u_in_subgraph && v_in_subgraph) + { g.local_add_edge(u_local, v_local, e_global); } } children_add_edge(u_global, v_global, e_global, g.m_children, orig); } - template <typename Vertex, typename Graph> - std::pair<typename subgraph<Graph>::edge_descriptor, bool> + template < typename Vertex, typename Graph > + std::pair< typename subgraph< Graph >::edge_descriptor, bool > add_edge_recur_up(Vertex u_global, Vertex v_global, - const typename Graph::edge_property_type& ep, - subgraph<Graph>& g, subgraph<Graph>* orig) + const typename Graph::edge_property_type& ep, subgraph< Graph >& g, + subgraph< Graph >* orig) { - if(g.is_root()) { - typename subgraph<Graph>::edge_descriptor e_global; + if (g.is_root()) + { + typename subgraph< Graph >::edge_descriptor e_global; bool inserted; - boost::tie(e_global, inserted) = add_edge(u_global, v_global, ep, g.m_graph); + boost::tie(e_global, inserted) + = add_edge(u_global, v_global, ep, g.m_graph); put(edge_index, g.m_graph, e_global, g.m_edge_counter++); g.m_global_edge.push_back(e_global); children_add_edge(u_global, v_global, e_global, g.m_children, orig); return std::make_pair(e_global, inserted); - } else { + } + else + { return add_edge_recur_up(u_global, v_global, ep, *g.m_parent, orig); } } @@ -569,58 +658,60 @@ namespace detail { // and v. In addition, the edge will be added to any (all) other subgraphs that // contain vertex descriptors u and v. -template <typename G> -std::pair<typename subgraph<G>::edge_descriptor, bool> -add_edge(typename subgraph<G>::vertex_descriptor u, - typename subgraph<G>::vertex_descriptor v, - const typename G::edge_property_type& ep, - subgraph<G>& g) +template < typename G > +std::pair< typename subgraph< G >::edge_descriptor, bool > add_edge( + typename subgraph< G >::vertex_descriptor u, + typename subgraph< G >::vertex_descriptor v, + const typename G::edge_property_type& ep, subgraph< G >& g) { - if (g.is_root()) { + if (g.is_root()) + { // u and v are really global return detail::add_edge_recur_up(u, v, ep, g, &g); - } else { - typename subgraph<G>::edge_descriptor e_local, e_global; + } + else + { + typename subgraph< G >::edge_descriptor e_local, e_global; bool inserted; - boost::tie(e_global, inserted) = - detail::add_edge_recur_up(g.local_to_global(u), - g.local_to_global(v), - ep, g, &g); + boost::tie(e_global, inserted) = detail::add_edge_recur_up( + g.local_to_global(u), g.local_to_global(v), ep, g, &g); e_local = g.local_add_edge(u, v, e_global); return std::make_pair(e_local, inserted); } } -template <typename G> -std::pair<typename subgraph<G>::edge_descriptor, bool> -add_edge(typename subgraph<G>::vertex_descriptor u, - typename subgraph<G>::vertex_descriptor v, - subgraph<G>& g) -{ return add_edge(u, v, typename G::edge_property_type(), g); } +template < typename G > +std::pair< typename subgraph< G >::edge_descriptor, bool > add_edge( + typename subgraph< G >::vertex_descriptor u, + typename subgraph< G >::vertex_descriptor v, subgraph< G >& g) +{ + return add_edge(u, v, typename G::edge_property_type(), g); +} -namespace detail { +namespace detail +{ //------------------------------------------------------------------------- // implementation of remove_edge(u,v,g) - template <typename Vertex, typename Graph> - void remove_edge_recur_down(Vertex u_global, Vertex v_global, - subgraph<Graph>& g); + template < typename Vertex, typename Graph > + void remove_edge_recur_down( + Vertex u_global, Vertex v_global, subgraph< Graph >& g); - template <typename Vertex, typename Children> - void children_remove_edge(Vertex u_global, Vertex v_global, - Children& c) + template < typename Vertex, typename Children > + void children_remove_edge(Vertex u_global, Vertex v_global, Children& c) { - for(typename Children::iterator i = c.begin(); i != c.end(); ++i) { - if((*i)->find_vertex(u_global).second && - (*i)->find_vertex(v_global).second) + for (typename Children::iterator i = c.begin(); i != c.end(); ++i) + { + if ((*i)->find_vertex(u_global).second + && (*i)->find_vertex(v_global).second) { remove_edge_recur_down(u_global, v_global, **i); } } } - template <typename Vertex, typename Graph> - void remove_edge_recur_down(Vertex u_global, Vertex v_global, - subgraph<Graph>& g) + template < typename Vertex, typename Graph > + void remove_edge_recur_down( + Vertex u_global, Vertex v_global, subgraph< Graph >& g) { Vertex u_local, v_local; u_local = g.m_local_vertex[u_global]; @@ -629,14 +720,17 @@ namespace detail { children_remove_edge(u_global, v_global, g.m_children); } - template <typename Vertex, typename Graph> - void remove_edge_recur_up(Vertex u_global, Vertex v_global, - subgraph<Graph>& g) + template < typename Vertex, typename Graph > + void remove_edge_recur_up( + Vertex u_global, Vertex v_global, subgraph< Graph >& g) { - if(g.is_root()) { + if (g.is_root()) + { remove_edge(u_global, v_global, g.m_graph); children_remove_edge(u_global, v_global, g.m_children); - } else { + } + else + { remove_edge_recur_up(u_global, v_global, *g.m_parent); } } @@ -644,90 +738,103 @@ namespace detail { //------------------------------------------------------------------------- // implementation of remove_edge(e,g) - template <typename G, typename Edge, typename Children> + template < typename G, typename Edge, typename Children > void children_remove_edge(Edge e_global, Children& c) { - for(typename Children::iterator i = c.begin(); i != c.end(); ++i) { - std::pair<typename subgraph<G>::edge_descriptor, bool> found = - (*i)->find_edge(e_global); - if (!found.second) { - continue; + for (typename Children::iterator i = c.begin(); i != c.end(); ++i) + { + std::pair< typename subgraph< G >::edge_descriptor, bool > found + = (*i)->find_edge(e_global); + if (!found.second) + { + continue; } - children_remove_edge<G>(e_global, (*i)->m_children); + children_remove_edge< G >(e_global, (*i)->m_children); remove_edge(found.first, (*i)->m_graph); } } } // namespace detail -template <typename G> -void -remove_edge(typename subgraph<G>::vertex_descriptor u, - typename subgraph<G>::vertex_descriptor v, - subgraph<G>& g) +template < typename G > +void remove_edge(typename subgraph< G >::vertex_descriptor u, + typename subgraph< G >::vertex_descriptor v, subgraph< G >& g) { - if(g.is_root()) { + if (g.is_root()) + { detail::remove_edge_recur_up(u, v, g); - } else { - detail::remove_edge_recur_up(g.local_to_global(u), - g.local_to_global(v), g); + } + else + { + detail::remove_edge_recur_up( + g.local_to_global(u), g.local_to_global(v), g); } } -template <typename G> -void -remove_edge(typename subgraph<G>::edge_descriptor e, subgraph<G>& g) +template < typename G > +void remove_edge(typename subgraph< G >::edge_descriptor e, subgraph< G >& g) { - typename subgraph<G>::edge_descriptor e_global = g.local_to_global(e); + typename subgraph< G >::edge_descriptor e_global = g.local_to_global(e); #ifndef NDEBUG - std::pair<typename subgraph<G>::edge_descriptor, bool> fe = g.find_edge(e_global); + std::pair< typename subgraph< G >::edge_descriptor, bool > fe + = g.find_edge(e_global); BOOST_ASSERT(fe.second && fe.first == e); -#endif //NDEBUG - subgraph<G> &root = g.root(); // chase to root - detail::children_remove_edge<G>(e_global, root.m_children); +#endif // NDEBUG + subgraph< G >& root = g.root(); // chase to root + detail::children_remove_edge< G >(e_global, root.m_children); remove_edge(e_global, root.m_graph); // kick edge from root } // This is slow, but there may not be a good way to do it safely otherwise -template <typename Predicate, typename G> -void -remove_edge_if(Predicate p, subgraph<G>& g) { - while (true) { - bool any_removed = false; - typedef typename subgraph<G>::edge_iterator ei_type; - for (std::pair<ei_type, ei_type> ep = edges(g); - ep.first != ep.second; ++ep.first) { - if (p(*ep.first)) { - any_removed = true; - remove_edge(*ep.first, g); - break; /* Since iterators may be invalidated */ - } +template < typename Predicate, typename G > +void remove_edge_if(Predicate p, subgraph< G >& g) +{ + while (true) + { + bool any_removed = false; + typedef typename subgraph< G >::edge_iterator ei_type; + for (std::pair< ei_type, ei_type > ep = edges(g); ep.first != ep.second; + ++ep.first) + { + if (p(*ep.first)) + { + any_removed = true; + remove_edge(*ep.first, g); + break; /* Since iterators may be invalidated */ + } + } + if (!any_removed) + break; } - if (!any_removed) break; - } } -template <typename G> -void -clear_vertex(typename subgraph<G>::vertex_descriptor v, subgraph<G>& g) { - while (true) { - typedef typename subgraph<G>::out_edge_iterator oei_type; - std::pair<oei_type, oei_type> p = out_edges(v, g); - if (p.first == p.second) break; - remove_edge(*p.first, g); - } +template < typename G > +void clear_vertex(typename subgraph< G >::vertex_descriptor v, subgraph< G >& g) +{ + while (true) + { + typedef typename subgraph< G >::out_edge_iterator oei_type; + std::pair< oei_type, oei_type > p = out_edges(v, g); + if (p.first == p.second) + break; + remove_edge(*p.first, g); + } } -namespace detail { - template <typename G> - typename subgraph<G>::vertex_descriptor - add_vertex_recur_up(subgraph<G>& g) +namespace detail +{ + template < typename G > + typename subgraph< G >::vertex_descriptor add_vertex_recur_up( + subgraph< G >& g) { - typename subgraph<G>::vertex_descriptor u_local, u_global; - if (g.is_root()) { + typename subgraph< G >::vertex_descriptor u_local, u_global; + if (g.is_root()) + { u_global = add_vertex(g.m_graph); g.m_global_vertex.push_back(u_global); - } else { + } + else + { u_global = add_vertex_recur_up(*g.m_parent); u_local = add_vertex(g.m_graph); g.m_global_vertex.push_back(u_global); @@ -737,16 +844,18 @@ namespace detail { } } // namespace detail -template <typename G> -typename subgraph<G>::vertex_descriptor -add_vertex(subgraph<G>& g) +template < typename G > +typename subgraph< G >::vertex_descriptor add_vertex(subgraph< G >& g) { - typename subgraph<G>::vertex_descriptor u_local, u_global; - if(g.is_root()) { + typename subgraph< G >::vertex_descriptor u_local, u_global; + if (g.is_root()) + { u_global = add_vertex(g.m_graph); g.m_global_vertex.push_back(u_global); u_local = u_global; - } else { + } + else + { u_global = detail::add_vertex_recur_up(g.parent()); u_local = add_vertex(g.m_graph); g.m_global_vertex.push_back(u_global); @@ -755,7 +864,6 @@ add_vertex(subgraph<G>& g) return u_local; } - #if 0 // TODO: Under Construction template <typename G> @@ -770,35 +878,29 @@ void remove_vertex(typename subgraph<G>::vertex_descriptor u, subgraph<G>& g) * The global property map returns the global properties associated with local * descriptors. */ -template <typename GraphPtr, typename PropertyMap, typename Tag> +template < typename GraphPtr, typename PropertyMap, typename Tag > class subgraph_global_property_map - : public put_get_helper< - typename property_traits<PropertyMap>::reference, - subgraph_global_property_map<GraphPtr, PropertyMap, Tag> - > +: public put_get_helper< typename property_traits< PropertyMap >::reference, + subgraph_global_property_map< GraphPtr, PropertyMap, Tag > > { - typedef property_traits<PropertyMap> Traits; + typedef property_traits< PropertyMap > Traits; + public: - typedef typename mpl::if_<is_const<typename remove_pointer<GraphPtr>::type>, - readable_property_map_tag, - typename Traits::category>::type - category; + typedef typename mpl::if_< + is_const< typename remove_pointer< GraphPtr >::type >, + readable_property_map_tag, typename Traits::category >::type category; typedef typename Traits::value_type value_type; typedef typename Traits::key_type key_type; typedef typename Traits::reference reference; - subgraph_global_property_map() - { } + subgraph_global_property_map() {} - subgraph_global_property_map(GraphPtr g, Tag tag) - : m_g(g), m_tag(tag) - { } + subgraph_global_property_map(GraphPtr g, Tag tag) : m_g(g), m_tag(tag) {} - reference operator[](key_type e) const { + reference operator[](key_type e) const + { PropertyMap pmap = get(m_tag, m_g->root().m_graph); - return m_g->is_root() - ? pmap[e] - : pmap[m_g->local_to_global(e)]; + return m_g->is_root() ? pmap[e] : pmap[m_g->local_to_global(e)]; } GraphPtr m_g; @@ -809,19 +911,17 @@ public: * The local property map returns the local property associated with the local * descriptors. */ -template <typename GraphPtr, typename PropertyMap, typename Tag> +template < typename GraphPtr, typename PropertyMap, typename Tag > class subgraph_local_property_map - : public put_get_helper< - typename property_traits<PropertyMap>::reference, - subgraph_local_property_map<GraphPtr, PropertyMap, Tag> - > +: public put_get_helper< typename property_traits< PropertyMap >::reference, + subgraph_local_property_map< GraphPtr, PropertyMap, Tag > > { - typedef property_traits<PropertyMap> Traits; + typedef property_traits< PropertyMap > Traits; + public: - typedef typename mpl::if_<is_const<typename remove_pointer<GraphPtr>::type>, - readable_property_map_tag, - typename Traits::category>::type - category; + typedef typename mpl::if_< + is_const< typename remove_pointer< GraphPtr >::type >, + readable_property_map_tag, typename Traits::category >::type category; typedef typename Traits::value_type value_type; typedef typename Traits::key_type key_type; typedef typename Traits::reference reference; @@ -829,14 +929,12 @@ public: typedef Tag tag; typedef PropertyMap pmap; - subgraph_local_property_map() - { } + subgraph_local_property_map() {} - subgraph_local_property_map(GraphPtr g, Tag tag) - : m_g(g), m_tag(tag) - { } + subgraph_local_property_map(GraphPtr g, Tag tag) : m_g(g), m_tag(tag) {} - reference operator[](key_type e) const { + reference operator[](key_type e) const + { // Get property map on the underlying graph. PropertyMap pmap = get(m_tag, m_g->m_graph); return pmap[e]; @@ -846,48 +944,64 @@ public: Tag m_tag; }; -namespace detail { +namespace detail +{ // Extract the actual tags from local or global property maps so we don't // try to find non-properties. - template <typename P> struct extract_lg_tag { typedef P type; }; - template <typename P> struct extract_lg_tag< local_property<P> > { + template < typename P > struct extract_lg_tag + { typedef P type; }; - template <typename P> struct extract_lg_tag< global_property<P> > { + template < typename P > struct extract_lg_tag< local_property< P > > + { + typedef P type; + }; + template < typename P > struct extract_lg_tag< global_property< P > > + { typedef P type; }; // NOTE: Mysterious Property template parameter unused in both metafunction // classes. - struct subgraph_global_pmap { - template <class Tag, class SubGraph, class Property> - struct bind_ { + struct subgraph_global_pmap + { + template < class Tag, class SubGraph, class Property > struct bind_ + { typedef typename SubGraph::graph_type Graph; typedef SubGraph* SubGraphPtr; typedef const SubGraph* const_SubGraphPtr; - typedef typename extract_lg_tag<Tag>::type TagType; - typedef typename property_map<Graph, TagType>::type PMap; - typedef typename property_map<Graph, TagType>::const_type const_PMap; + typedef typename extract_lg_tag< Tag >::type TagType; + typedef typename property_map< Graph, TagType >::type PMap; + typedef + typename property_map< Graph, TagType >::const_type const_PMap; + public: - typedef subgraph_global_property_map<SubGraphPtr, PMap, TagType> type; - typedef subgraph_global_property_map<const_SubGraphPtr, const_PMap, TagType> - const_type; + typedef subgraph_global_property_map< SubGraphPtr, PMap, TagType > + type; + typedef subgraph_global_property_map< const_SubGraphPtr, const_PMap, + TagType > + const_type; }; }; - struct subgraph_local_pmap { - template <class Tag, class SubGraph, class Property> - struct bind_ { + struct subgraph_local_pmap + { + template < class Tag, class SubGraph, class Property > struct bind_ + { typedef typename SubGraph::graph_type Graph; typedef SubGraph* SubGraphPtr; typedef const SubGraph* const_SubGraphPtr; - typedef typename extract_lg_tag<Tag>::type TagType; - typedef typename property_map<Graph, TagType>::type PMap; - typedef typename property_map<Graph, TagType>::const_type const_PMap; + typedef typename extract_lg_tag< Tag >::type TagType; + typedef typename property_map< Graph, TagType >::type PMap; + typedef + typename property_map< Graph, TagType >::const_type const_PMap; + public: - typedef subgraph_local_property_map<SubGraphPtr, PMap, TagType> type; - typedef subgraph_local_property_map<const_SubGraphPtr, const_PMap, TagType> - const_type; + typedef subgraph_local_property_map< SubGraphPtr, PMap, TagType > + type; + typedef subgraph_local_property_map< const_SubGraphPtr, const_PMap, + TagType > + const_type; }; }; @@ -895,99 +1009,108 @@ namespace detail { // are used by the choose_pmap metafunction below to specialize the choice // of local/global property map. By default, we defer to the global // property. - template <class Tag> - struct subgraph_choose_pmap_helper { + template < class Tag > struct subgraph_choose_pmap_helper + { typedef subgraph_global_pmap type; }; - template <class Tag> - struct subgraph_choose_pmap_helper< local_property<Tag> > { + template < class Tag > + struct subgraph_choose_pmap_helper< local_property< Tag > > + { typedef subgraph_local_pmap type; }; - template <class Tag> - struct subgraph_choose_pmap_helper< global_property<Tag> > { + template < class Tag > + struct subgraph_choose_pmap_helper< global_property< Tag > > + { typedef subgraph_global_pmap type; }; // As above, unless we're requesting vertex_index_t. Then it's always a // local property map. This enables the correct translation of descriptors // between local and global layers. - template <> - struct subgraph_choose_pmap_helper<vertex_index_t> { + template <> struct subgraph_choose_pmap_helper< vertex_index_t > + { typedef subgraph_local_pmap type; }; template <> - struct subgraph_choose_pmap_helper< local_property<vertex_index_t> > { + struct subgraph_choose_pmap_helper< local_property< vertex_index_t > > + { typedef subgraph_local_pmap type; }; template <> - struct subgraph_choose_pmap_helper< global_property<vertex_index_t> > { + struct subgraph_choose_pmap_helper< global_property< vertex_index_t > > + { typedef subgraph_local_pmap type; }; // Determine the kind of property. If SameType<Tag, vertex_index_t>, then // the property lookup is always local. Otherwise, the lookup is global. // NOTE: Property parameter is basically unused. - template <class Tag, class Graph, class Property> - struct subgraph_choose_pmap { - typedef typename subgraph_choose_pmap_helper<Tag>::type Helper; - typedef typename Helper::template bind_<Tag, Graph, Property> Bind; + template < class Tag, class Graph, class Property > + struct subgraph_choose_pmap + { + typedef typename subgraph_choose_pmap_helper< Tag >::type Helper; + typedef typename Helper::template bind_< Tag, Graph, Property > Bind; typedef typename Bind::type type; typedef typename Bind::const_type const_type; }; // Used by the vertex/edge property selectors to determine the kind(s) of // property maps used by the property_map type generator. - struct subgraph_property_generator { - template <class SubGraph, class Property, class Tag> - struct bind_ { - typedef subgraph_choose_pmap<Tag, SubGraph, Property> Choice; + struct subgraph_property_generator + { + template < class SubGraph, class Property, class Tag > struct bind_ + { + typedef subgraph_choose_pmap< Tag, SubGraph, Property > Choice; typedef typename Choice::type type; typedef typename Choice::const_type const_type; }; }; - } // namespace detail +} // namespace detail -template <> -struct vertex_property_selector<subgraph_tag> { +template <> struct vertex_property_selector< subgraph_tag > +{ typedef detail::subgraph_property_generator type; }; -template <> -struct edge_property_selector<subgraph_tag> { +template <> struct edge_property_selector< subgraph_tag > +{ typedef detail::subgraph_property_generator type; }; // ================================================== // get(p, g), get(p, g, k), and put(p, g, k, v) // ================================================== -template <typename G, typename Property> -typename property_map<subgraph<G>, Property>::type -get(Property p, subgraph<G>& g) { - typedef typename property_map< subgraph<G>, Property>::type PMap; +template < typename G, typename Property > +typename property_map< subgraph< G >, Property >::type get( + Property p, subgraph< G >& g) +{ + typedef typename property_map< subgraph< G >, Property >::type PMap; return PMap(&g, p); } -template <typename G, typename Property> -typename property_map<subgraph<G>, Property>::const_type -get(Property p, const subgraph<G>& g) { - typedef typename property_map< subgraph<G>, Property>::const_type PMap; +template < typename G, typename Property > +typename property_map< subgraph< G >, Property >::const_type get( + Property p, const subgraph< G >& g) +{ + typedef typename property_map< subgraph< G >, Property >::const_type PMap; return PMap(&g, p); } -template <typename G, typename Property, typename Key> +template < typename G, typename Property, typename Key > typename property_traits< - typename property_map<subgraph<G>, Property>::const_type ->::value_type -get(Property p, const subgraph<G>& g, const Key& k) { - typedef typename property_map< subgraph<G>, Property>::const_type PMap; + typename property_map< subgraph< G >, Property >::const_type >::value_type +get(Property p, const subgraph< G >& g, const Key& k) +{ + typedef typename property_map< subgraph< G >, Property >::const_type PMap; PMap pmap(&g, p); return pmap[k]; } -template <typename G, typename Property, typename Key, typename Value> -void put(Property p, subgraph<G>& g, const Key& k, const Value& val) { - typedef typename property_map< subgraph<G>, Property>::type PMap; +template < typename G, typename Property, typename Key, typename Value > +void put(Property p, subgraph< G >& g, const Key& k, const Value& val) +{ + typedef typename property_map< subgraph< G >, Property >::type PMap; PMap pmap(&g, p); pmap[k] = val; } @@ -996,21 +1119,21 @@ void put(Property p, subgraph<G>& g, const Key& k, const Value& val) { // get(global(p), g) // NOTE: get(global(p), g, k) and put(global(p), g, k, v) not supported // ================================================== -template <typename G, typename Property> -typename property_map<subgraph<G>, global_property<Property> >::type -get(global_property<Property> p, subgraph<G>& g) { - typedef typename property_map< - subgraph<G>, global_property<Property> - >::type Map; +template < typename G, typename Property > +typename property_map< subgraph< G >, global_property< Property > >::type get( + global_property< Property > p, subgraph< G >& g) +{ + typedef typename property_map< subgraph< G >, + global_property< Property > >::type Map; return Map(&g, p.value); } -template <typename G, typename Property> -typename property_map<subgraph<G>, global_property<Property> >::const_type -get(global_property<Property> p, const subgraph<G>& g) { - typedef typename property_map< - subgraph<G>, global_property<Property> - >::const_type Map; +template < typename G, typename Property > +typename property_map< subgraph< G >, global_property< Property > >::const_type +get(global_property< Property > p, const subgraph< G >& g) +{ + typedef typename property_map< subgraph< G >, + global_property< Property > >::const_type Map; return Map(&g, p.value); } @@ -1018,51 +1141,56 @@ get(global_property<Property> p, const subgraph<G>& g) { // get(local(p), g) // NOTE: get(local(p), g, k) and put(local(p), g, k, v) not supported // ================================================== -template <typename G, typename Property> -typename property_map<subgraph<G>, local_property<Property> >::type -get(local_property<Property> p, subgraph<G>& g) { - typedef typename property_map< - subgraph<G>, local_property<Property> - >::type Map; +template < typename G, typename Property > +typename property_map< subgraph< G >, local_property< Property > >::type get( + local_property< Property > p, subgraph< G >& g) +{ + typedef + typename property_map< subgraph< G >, local_property< Property > >::type + Map; return Map(&g, p.value); } -template <typename G, typename Property> -typename property_map<subgraph<G>, local_property<Property> >::const_type -get(local_property<Property> p, const subgraph<G>& g) { - typedef typename property_map< - subgraph<G>, local_property<Property> - >::const_type Map; +template < typename G, typename Property > +typename property_map< subgraph< G >, local_property< Property > >::const_type +get(local_property< Property > p, const subgraph< G >& g) +{ + typedef typename property_map< subgraph< G >, + local_property< Property > >::const_type Map; return Map(&g, p.value); } -template <typename G, typename Tag> -inline typename graph_property<G, Tag>::type& -get_property(subgraph<G>& g, Tag tag) { +template < typename G, typename Tag > +inline typename graph_property< G, Tag >::type& get_property( + subgraph< G >& g, Tag tag) +{ return get_property(g.m_graph, tag); } -template <typename G, typename Tag> -inline const typename graph_property<G, Tag>::type& -get_property(const subgraph<G>& g, Tag tag) { +template < typename G, typename Tag > +inline const typename graph_property< G, Tag >::type& get_property( + const subgraph< G >& g, Tag tag) +{ return get_property(g.m_graph, tag); } //=========================================================================== // Miscellaneous Functions -template <typename G> -typename subgraph<G>::vertex_descriptor -vertex(typename subgraph<G>::vertices_size_type n, const subgraph<G>& g) -{ return vertex(n, g.m_graph); } +template < typename G > +typename subgraph< G >::vertex_descriptor vertex( + typename subgraph< G >::vertices_size_type n, const subgraph< G >& g) +{ + return vertex(n, g.m_graph); +} //=========================================================================== // Mutability Traits // Just pull the mutability traits form the underlying graph. Note that this // will probably fail (badly) for labeled graphs. -template <typename G> -struct graph_mutability_traits< subgraph<G> > { - typedef typename graph_mutability_traits<G>::category category; +template < typename G > struct graph_mutability_traits< subgraph< G > > +{ + typedef typename graph_mutability_traits< G >::category category; }; } // namespace boost diff --git a/contrib/restricted/boost/graph/include/boost/graph/topological_sort.hpp b/contrib/restricted/boost/graph/include/boost/graph/topological_sort.hpp index 08baf69b89..5cffdde1a5 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/topological_sort.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/topological_sort.hpp @@ -18,59 +18,63 @@ #include <boost/graph/exception.hpp> #include <boost/throw_exception.hpp> -namespace boost { +namespace boost +{ +// Topological sort visitor +// +// This visitor merely writes the linear ordering into an +// OutputIterator. The OutputIterator could be something like an +// ostream_iterator, or it could be a back/front_insert_iterator. +// Note that if it is a back_insert_iterator, the recorded order is +// the reverse topological order. On the other hand, if it is a +// front_insert_iterator, the recorded order is the topological +// order. +// +template < typename OutputIterator > +struct topo_sort_visitor : public dfs_visitor<> +{ + topo_sort_visitor(OutputIterator _iter) : m_iter(_iter) {} - // Topological sort visitor - // - // This visitor merely writes the linear ordering into an - // OutputIterator. The OutputIterator could be something like an - // ostream_iterator, or it could be a back/front_insert_iterator. - // Note that if it is a back_insert_iterator, the recorded order is - // the reverse topological order. On the other hand, if it is a - // front_insert_iterator, the recorded order is the topological - // order. - // - template <typename OutputIterator> - struct topo_sort_visitor : public dfs_visitor<> - { - topo_sort_visitor(OutputIterator _iter) - : m_iter(_iter) { } - - template <typename Edge, typename Graph> - void back_edge(const Edge&, Graph&) { BOOST_THROW_EXCEPTION(not_a_dag()); } - - template <typename Vertex, typename Graph> - void finish_vertex(const Vertex& u, Graph&) { *m_iter++ = u; } - - OutputIterator m_iter; - }; + template < typename Edge, typename Graph > + void back_edge(const Edge&, Graph&) + { + BOOST_THROW_EXCEPTION(not_a_dag()); + } + template < typename Vertex, typename Graph > + void finish_vertex(const Vertex& u, Graph&) + { + *m_iter++ = u; + } - // Topological Sort - // - // The topological sort algorithm creates a linear ordering - // of the vertices such that if edge (u,v) appears in the graph, - // then u comes before v in the ordering. The graph must - // be a directed acyclic graph (DAG). The implementation - // consists mainly of a call to depth-first search. - // + OutputIterator m_iter; +}; + +// Topological Sort +// +// The topological sort algorithm creates a linear ordering +// of the vertices such that if edge (u,v) appears in the graph, +// then u comes before v in the ordering. The graph must +// be a directed acyclic graph (DAG). The implementation +// consists mainly of a call to depth-first search. +// - template <typename VertexListGraph, typename OutputIterator, - typename P, typename T, typename R> - void topological_sort(VertexListGraph& g, OutputIterator result, - const bgl_named_params<P, T, R>& params) - { - typedef topo_sort_visitor<OutputIterator> TopoVisitor; +template < typename VertexListGraph, typename OutputIterator, typename P, + typename T, typename R > +void topological_sort(VertexListGraph& g, OutputIterator result, + const bgl_named_params< P, T, R >& params) +{ + typedef topo_sort_visitor< OutputIterator > TopoVisitor; depth_first_search(g, params.visitor(TopoVisitor(result))); - } +} - template <typename VertexListGraph, typename OutputIterator> - void topological_sort(VertexListGraph& g, OutputIterator result) - { - topological_sort(g, result, - bgl_named_params<int, buffer_param_t>(0)); // bogus - } +template < typename VertexListGraph, typename OutputIterator > +void topological_sort(VertexListGraph& g, OutputIterator result) +{ + topological_sort( + g, result, bgl_named_params< int, buffer_param_t >(0)); // bogus +} } // namespace boost diff --git a/contrib/restricted/boost/graph/include/boost/graph/transpose_graph.hpp b/contrib/restricted/boost/graph/include/boost/graph/transpose_graph.hpp index b12ba1005d..9970e5936f 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/transpose_graph.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/transpose_graph.hpp @@ -16,24 +16,24 @@ #include <boost/graph/reverse_graph.hpp> #include <boost/graph/copy.hpp> +namespace boost +{ -namespace boost { - - template <class VertexListGraph, class MutableGraph> - void transpose_graph(const VertexListGraph& G, MutableGraph& G_T) - { - reverse_graph<VertexListGraph> R(G); +template < class VertexListGraph, class MutableGraph > +void transpose_graph(const VertexListGraph& G, MutableGraph& G_T) +{ + reverse_graph< VertexListGraph > R(G); copy_graph(R, G_T); - } - - template <class VertexListGraph, class MutableGraph, - class P, class T, class R> - void transpose_graph(const VertexListGraph& G, MutableGraph& G_T, - const bgl_named_params<P, T, R>& params) - { - reverse_graph<VertexListGraph> Rev(G); +} + +template < class VertexListGraph, class MutableGraph, class P, class T, + class R > +void transpose_graph(const VertexListGraph& G, MutableGraph& G_T, + const bgl_named_params< P, T, R >& params) +{ + reverse_graph< VertexListGraph > Rev(G); copy_graph(Rev, G_T, params); - } +} } // namespace boost diff --git a/contrib/restricted/boost/graph/include/boost/graph/two_bit_color_map.hpp b/contrib/restricted/boost/graph/include/boost/graph/two_bit_color_map.hpp index d67a68a7d9..a802644288 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/two_bit_color_map.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/two_bit_color_map.hpp @@ -15,95 +15,94 @@ #include <boost/property_map/property_map.hpp> #include <boost/graph/properties.hpp> +#include <boost/graph/detail/mpi_include.hpp> #include <boost/shared_array.hpp> #include <boost/config.hpp> #include <boost/assert.hpp> #include <algorithm> #include <limits> -namespace boost { +namespace boost +{ -enum two_bit_color_type { - two_bit_white = 0, - two_bit_gray = 1, - two_bit_green = 2, - two_bit_black = 3 +enum two_bit_color_type +{ + two_bit_white = 0, + two_bit_gray = 1, + two_bit_green = 2, + two_bit_black = 3 }; -template <> -struct color_traits<two_bit_color_type> +template <> struct color_traits< two_bit_color_type > { - static two_bit_color_type white() { return two_bit_white; } - static two_bit_color_type gray() { return two_bit_gray; } - static two_bit_color_type green() { return two_bit_green; } - static two_bit_color_type black() { return two_bit_black; } + static two_bit_color_type white() { return two_bit_white; } + static two_bit_color_type gray() { return two_bit_gray; } + static two_bit_color_type green() { return two_bit_green; } + static two_bit_color_type black() { return two_bit_black; } }; - -template<typename IndexMap = identity_property_map> -struct two_bit_color_map +template < typename IndexMap = identity_property_map > struct two_bit_color_map { - std::size_t n; - IndexMap index; - shared_array<unsigned char> data; - - BOOST_STATIC_CONSTANT(int, bits_per_char = std::numeric_limits<unsigned char>::digits); - BOOST_STATIC_CONSTANT(int, elements_per_char = bits_per_char / 2); - typedef typename property_traits<IndexMap>::key_type key_type; - typedef two_bit_color_type value_type; - typedef void reference; - typedef read_write_property_map_tag category; - - explicit two_bit_color_map(std::size_t n, const IndexMap& index = IndexMap()) - : n(n), index(index), data(new unsigned char[(n + elements_per_char - 1) / elements_per_char]) - { - // Fill to white - std::fill(data.get(), data.get() + (n + elements_per_char - 1) / elements_per_char, 0); - } + std::size_t n; + IndexMap index; + shared_array< unsigned char > data; + + BOOST_STATIC_CONSTANT( + int, bits_per_char = std::numeric_limits< unsigned char >::digits); + BOOST_STATIC_CONSTANT(int, elements_per_char = bits_per_char / 2); + typedef typename property_traits< IndexMap >::key_type key_type; + typedef two_bit_color_type value_type; + typedef void reference; + typedef read_write_property_map_tag category; + + explicit two_bit_color_map( + std::size_t n, const IndexMap& index = IndexMap()) + : n(n) + , index(index) + , data(new unsigned char[(n + elements_per_char - 1) / elements_per_char]()) + { + } }; -template<typename IndexMap> -inline two_bit_color_type -get(const two_bit_color_map<IndexMap>& pm, - typename property_traits<IndexMap>::key_type key) +template < typename IndexMap > +inline two_bit_color_type get(const two_bit_color_map< IndexMap >& pm, + typename property_traits< IndexMap >::key_type key) { - BOOST_STATIC_CONSTANT(int, elements_per_char = two_bit_color_map<IndexMap>::elements_per_char); - typename property_traits<IndexMap>::value_type i = get(pm.index, key); - BOOST_ASSERT ((std::size_t)i < pm.n); - std::size_t byte_num = i / elements_per_char; - std::size_t bit_position = ((i % elements_per_char) * 2); - return two_bit_color_type((pm.data.get()[byte_num] >> bit_position) & 3); + BOOST_STATIC_CONSTANT(int, + elements_per_char = two_bit_color_map< IndexMap >::elements_per_char); + typename property_traits< IndexMap >::value_type i = get(pm.index, key); + BOOST_ASSERT((std::size_t)i < pm.n); + std::size_t byte_num = i / elements_per_char; + std::size_t bit_position = ((i % elements_per_char) * 2); + return two_bit_color_type((pm.data.get()[byte_num] >> bit_position) & 3); } -template<typename IndexMap> -inline void -put(const two_bit_color_map<IndexMap>& pm, - typename property_traits<IndexMap>::key_type key, +template < typename IndexMap > +inline void put(const two_bit_color_map< IndexMap >& pm, + typename property_traits< IndexMap >::key_type key, two_bit_color_type value) { - BOOST_STATIC_CONSTANT(int, elements_per_char = two_bit_color_map<IndexMap>::elements_per_char); - typename property_traits<IndexMap>::value_type i = get(pm.index, key); - BOOST_ASSERT ((std::size_t)i < pm.n); - BOOST_ASSERT (value >= 0 && value < 4); - std::size_t byte_num = i / elements_per_char; - std::size_t bit_position = ((i % elements_per_char) * 2); - pm.data.get()[byte_num] = - (unsigned char) - ((pm.data.get()[byte_num] & ~(3 << bit_position)) - | (value << bit_position)); + BOOST_STATIC_CONSTANT(int, + elements_per_char = two_bit_color_map< IndexMap >::elements_per_char); + typename property_traits< IndexMap >::value_type i = get(pm.index, key); + BOOST_ASSERT((std::size_t)i < pm.n); + BOOST_ASSERT(value >= 0 && value < 4); + std::size_t byte_num = i / elements_per_char; + std::size_t bit_position = ((i % elements_per_char) * 2); + pm.data.get()[byte_num] + = (unsigned char)((pm.data.get()[byte_num] & ~(3 << bit_position)) + | (value << bit_position)); } -template<typename IndexMap> -inline two_bit_color_map<IndexMap> -make_two_bit_color_map(std::size_t n, const IndexMap& index_map) +template < typename IndexMap > +inline two_bit_color_map< IndexMap > make_two_bit_color_map( + std::size_t n, const IndexMap& index_map) { - return two_bit_color_map<IndexMap>(n, index_map); + return two_bit_color_map< IndexMap >(n, index_map); } } // end namespace boost -#endif // BOOST_TWO_BIT_COLOR_MAP_HPP +#include BOOST_GRAPH_MPI_INCLUDE(<boost/graph/distributed/two_bit_color_map.hpp>) -#ifdef BOOST_GRAPH_USE_MPI -# error #include <boost/graph/distributed/two_bit_color_map.hpp> -#endif +#endif // BOOST_TWO_BIT_COLOR_MAP_HPP diff --git a/contrib/restricted/boost/graph/include/boost/graph/visitors.hpp b/contrib/restricted/boost/graph/include/boost/graph/visitors.hpp index 120314f902..534794b6af 100644 --- a/contrib/restricted/boost/graph/include/boost/graph/visitors.hpp +++ b/contrib/restricted/boost/graph/include/boost/graph/visitors.hpp @@ -21,278 +21,406 @@ #include <boost/graph/graph_traits.hpp> #include <boost/limits.hpp> -namespace boost { +namespace boost +{ - // This is a bit more convenient than std::numeric_limits because - // you don't have to explicitly provide type T. - template <class T> - inline T numeric_limits_max(T) { return (std::numeric_limits<T>::max)(); } +// This is a bit more convenient than std::numeric_limits because +// you don't have to explicitly provide type T. +template < class T > inline T numeric_limits_max(T) +{ + return (std::numeric_limits< T >::max)(); +} - //======================================================================== - // Event Tags +//======================================================================== +// Event Tags - namespace detail { +namespace detail +{ // For partial specialization workaround enum event_visitor_enum - { on_no_event_num, - on_initialize_vertex_num, on_start_vertex_num, - on_discover_vertex_num, on_finish_vertex_num, on_examine_vertex_num, - on_examine_edge_num, on_tree_edge_num, on_non_tree_edge_num, - on_gray_target_num, on_black_target_num, - on_forward_or_cross_edge_num, on_back_edge_num, on_finish_edge_num, - on_edge_relaxed_num, on_edge_not_relaxed_num, - on_edge_minimized_num, on_edge_not_minimized_num + { + on_no_event_num, + on_initialize_vertex_num, + on_start_vertex_num, + on_discover_vertex_num, + on_finish_vertex_num, + on_examine_vertex_num, + on_examine_edge_num, + on_tree_edge_num, + on_non_tree_edge_num, + on_gray_target_num, + on_black_target_num, + on_forward_or_cross_edge_num, + on_back_edge_num, + on_finish_edge_num, + on_edge_relaxed_num, + on_edge_not_relaxed_num, + on_edge_minimized_num, + on_edge_not_minimized_num }; - template<typename Event, typename Visitor> + template < typename Event, typename Visitor > struct functor_to_visitor : Visitor { - typedef Event event_filter; - functor_to_visitor(const Visitor& visitor) : Visitor(visitor) {} + typedef Event event_filter; + functor_to_visitor(const Visitor& visitor) : Visitor(visitor) {} + }; + +} // namespace detail + +struct on_no_event +{ + enum + { + num = detail::on_no_event_num + }; +}; + +struct on_initialize_vertex +{ + enum + { + num = detail::on_initialize_vertex_num + }; +}; +struct on_start_vertex +{ + enum + { + num = detail::on_start_vertex_num + }; +}; +struct on_discover_vertex +{ + enum + { + num = detail::on_discover_vertex_num + }; +}; +struct on_examine_vertex +{ + enum + { + num = detail::on_examine_vertex_num + }; +}; +struct on_finish_vertex +{ + enum + { + num = detail::on_finish_vertex_num + }; +}; + +struct on_examine_edge +{ + enum + { + num = detail::on_examine_edge_num + }; +}; +struct on_tree_edge +{ + enum + { + num = detail::on_tree_edge_num + }; +}; +struct on_non_tree_edge +{ + enum + { + num = detail::on_non_tree_edge_num + }; +}; +struct on_gray_target +{ + enum + { + num = detail::on_gray_target_num + }; +}; +struct on_black_target +{ + enum + { + num = detail::on_black_target_num + }; +}; +struct on_forward_or_cross_edge +{ + enum + { + num = detail::on_forward_or_cross_edge_num }; +}; +struct on_back_edge +{ + enum + { + num = detail::on_back_edge_num + }; +}; +struct on_finish_edge +{ + enum + { + num = detail::on_finish_edge_num + }; +}; - } // namespace detail - - struct on_no_event { enum { num = detail::on_no_event_num }; }; - - struct on_initialize_vertex { - enum { num = detail::on_initialize_vertex_num }; }; - struct on_start_vertex { enum { num = detail::on_start_vertex_num }; }; - struct on_discover_vertex { enum { num = detail::on_discover_vertex_num }; }; - struct on_examine_vertex { enum { num = detail::on_examine_vertex_num }; }; - struct on_finish_vertex { enum { num = detail::on_finish_vertex_num }; }; - - struct on_examine_edge { enum { num = detail::on_examine_edge_num }; }; - struct on_tree_edge { enum { num = detail::on_tree_edge_num }; }; - struct on_non_tree_edge { enum { num = detail::on_non_tree_edge_num }; }; - struct on_gray_target { enum { num = detail::on_gray_target_num }; }; - struct on_black_target { enum { num = detail::on_black_target_num }; }; - struct on_forward_or_cross_edge { - enum { num = detail::on_forward_or_cross_edge_num }; }; - struct on_back_edge { enum { num = detail::on_back_edge_num }; }; - struct on_finish_edge { enum { num = detail::on_finish_edge_num }; }; - - struct on_edge_relaxed { enum { num = detail::on_edge_relaxed_num }; }; - struct on_edge_not_relaxed { - enum { num = detail::on_edge_not_relaxed_num }; }; - struct on_edge_minimized { enum { num = detail::on_edge_minimized_num }; }; - struct on_edge_not_minimized { - enum { num = detail::on_edge_not_minimized_num }; }; - - //======================================================================== - // base_visitor and null_visitor - - // needed for MSVC workaround - template <class Visitor> - struct base_visitor { +struct on_edge_relaxed +{ + enum + { + num = detail::on_edge_relaxed_num + }; +}; +struct on_edge_not_relaxed +{ + enum + { + num = detail::on_edge_not_relaxed_num + }; +}; +struct on_edge_minimized +{ + enum + { + num = detail::on_edge_minimized_num + }; +}; +struct on_edge_not_minimized +{ + enum + { + num = detail::on_edge_not_minimized_num + }; +}; + +//======================================================================== +// base_visitor and null_visitor + +// needed for MSVC workaround +template < class Visitor > struct base_visitor +{ typedef on_no_event event_filter; - template <class T, class Graph> - void operator()(T, Graph&) { } - }; + template < class T, class Graph > void operator()(T, Graph&) {} +}; - struct null_visitor : public base_visitor<null_visitor> { +struct null_visitor : public base_visitor< null_visitor > +{ typedef on_no_event event_filter; - template <class T, class Graph> - void operator()(T, Graph&) { } - }; + template < class T, class Graph > void operator()(T, Graph&) {} +}; - //======================================================================== - // The invoke_visitors() function +//======================================================================== +// The invoke_visitors() function - namespace detail { - template <class Visitor, class T, class Graph> - inline void invoke_dispatch(Visitor& v, T x, Graph& g, mpl::true_) { - v(x, g); +namespace detail +{ + template < class Visitor, class T, class Graph > + inline void invoke_dispatch(Visitor& v, T x, Graph& g, mpl::true_) + { + v(x, g); } - template <class Visitor, class T, class Graph> + template < class Visitor, class T, class Graph > inline void invoke_dispatch(Visitor&, T, Graph&, mpl::false_) - { } - } // namespace detail + { + } +} // namespace detail - template <class Visitor, class Rest, class T, class Graph, class Tag> - inline void - invoke_visitors(std::pair<Visitor, Rest>& vlist, T x, Graph& g, Tag tag) { +template < class Visitor, class Rest, class T, class Graph, class Tag > +inline void invoke_visitors( + std::pair< Visitor, Rest >& vlist, T x, Graph& g, Tag tag) +{ typedef typename Visitor::event_filter Category; - typedef typename is_same<Category, Tag>::type IsSameTag; + typedef typename is_same< Category, Tag >::type IsSameTag; detail::invoke_dispatch(vlist.first, x, g, IsSameTag()); invoke_visitors(vlist.second, x, g, tag); - } - template <class Visitor, class T, class Graph, class Tag> - inline void - invoke_visitors(Visitor& v, T x, Graph& g, Tag) { +} +template < class Visitor, class T, class Graph, class Tag > +inline void invoke_visitors(Visitor& v, T x, Graph& g, Tag) +{ typedef typename Visitor::event_filter Category; - typedef typename is_same<Category, Tag>::type IsSameTag; + typedef typename is_same< Category, Tag >::type IsSameTag; detail::invoke_dispatch(v, x, g, IsSameTag()); - } +} - //======================================================================== - // predecessor_recorder +//======================================================================== +// predecessor_recorder - template <class PredecessorMap, class Tag> - struct predecessor_recorder - : public base_visitor<predecessor_recorder<PredecessorMap, Tag> > - { +template < class PredecessorMap, class Tag > +struct predecessor_recorder +: public base_visitor< predecessor_recorder< PredecessorMap, Tag > > +{ typedef Tag event_filter; - predecessor_recorder(PredecessorMap pa) : m_predecessor(pa) { } - template <class Edge, class Graph> - void operator()(Edge e, const Graph& g) { - put(m_predecessor, target(e, g), source(e, g)); + predecessor_recorder(PredecessorMap pa) : m_predecessor(pa) {} + template < class Edge, class Graph > void operator()(Edge e, const Graph& g) + { + put(m_predecessor, target(e, g), source(e, g)); } PredecessorMap m_predecessor; - }; - template <class PredecessorMap, class Tag> - predecessor_recorder<PredecessorMap, Tag> - record_predecessors(PredecessorMap pa, Tag) { - return predecessor_recorder<PredecessorMap, Tag> (pa); - } - - //======================================================================== - // edge_predecessor_recorder - - template <class PredEdgeMap, class Tag> - struct edge_predecessor_recorder - : public base_visitor<edge_predecessor_recorder<PredEdgeMap, Tag> > - { +}; +template < class PredecessorMap, class Tag > +predecessor_recorder< PredecessorMap, Tag > record_predecessors( + PredecessorMap pa, Tag) +{ + return predecessor_recorder< PredecessorMap, Tag >(pa); +} + +//======================================================================== +// edge_predecessor_recorder + +template < class PredEdgeMap, class Tag > +struct edge_predecessor_recorder +: public base_visitor< edge_predecessor_recorder< PredEdgeMap, Tag > > +{ typedef Tag event_filter; - edge_predecessor_recorder(PredEdgeMap pa) : m_predecessor(pa) { } - template <class Edge, class Graph> - void operator()(Edge e, const Graph& g) { - put(m_predecessor, target(e, g), e); + edge_predecessor_recorder(PredEdgeMap pa) : m_predecessor(pa) {} + template < class Edge, class Graph > void operator()(Edge e, const Graph& g) + { + put(m_predecessor, target(e, g), e); } PredEdgeMap m_predecessor; - }; - template <class PredEdgeMap, class Tag> - edge_predecessor_recorder<PredEdgeMap, Tag> - record_edge_predecessors(PredEdgeMap pa, Tag) { - return edge_predecessor_recorder<PredEdgeMap, Tag> (pa); - } - - //======================================================================== - // distance_recorder - - template <class DistanceMap, class Tag> - struct distance_recorder - : public base_visitor<distance_recorder<DistanceMap, Tag> > - { +}; +template < class PredEdgeMap, class Tag > +edge_predecessor_recorder< PredEdgeMap, Tag > record_edge_predecessors( + PredEdgeMap pa, Tag) +{ + return edge_predecessor_recorder< PredEdgeMap, Tag >(pa); +} + +//======================================================================== +// distance_recorder + +template < class DistanceMap, class Tag > +struct distance_recorder +: public base_visitor< distance_recorder< DistanceMap, Tag > > +{ typedef Tag event_filter; - distance_recorder(DistanceMap pa) : m_distance(pa) { } - template <class Edge, class Graph> - void operator()(Edge e, const Graph& g) { - typename graph_traits<Graph>::vertex_descriptor - u = source(e, g), v = target(e, g); - put(m_distance, v, get(m_distance, u) + 1); + distance_recorder(DistanceMap pa) : m_distance(pa) {} + template < class Edge, class Graph > void operator()(Edge e, const Graph& g) + { + typename graph_traits< Graph >::vertex_descriptor u = source(e, g), + v = target(e, g); + put(m_distance, v, get(m_distance, u) + 1); } DistanceMap m_distance; - }; - template <class DistanceMap, class Tag> - distance_recorder<DistanceMap, Tag> - record_distances(DistanceMap pa, Tag) { - return distance_recorder<DistanceMap, Tag> (pa); - } - - //======================================================================== - // time_stamper - - - template <class TimeMap, class TimeT, class Tag> - struct time_stamper - : public base_visitor<time_stamper<TimeMap, TimeT, Tag> > - { +}; +template < class DistanceMap, class Tag > +distance_recorder< DistanceMap, Tag > record_distances(DistanceMap pa, Tag) +{ + return distance_recorder< DistanceMap, Tag >(pa); +} + +//======================================================================== +// time_stamper + +template < class TimeMap, class TimeT, class Tag > +struct time_stamper : public base_visitor< time_stamper< TimeMap, TimeT, Tag > > +{ typedef Tag event_filter; - time_stamper(TimeMap pa, TimeT& t) : m_time_pa(pa), m_time(t) { } - template <class Vertex, class Graph> - void operator()(Vertex u, const Graph&) { - put(m_time_pa, u, ++m_time); + time_stamper(TimeMap pa, TimeT& t) : m_time_pa(pa), m_time(t) {} + template < class Vertex, class Graph > + void operator()(Vertex u, const Graph&) + { + put(m_time_pa, u, ++m_time); } TimeMap m_time_pa; TimeT& m_time; - }; - template <class TimeMap, class TimeT, class Tag> - time_stamper<TimeMap, TimeT, Tag> - stamp_times(TimeMap pa, TimeT& time_counter, Tag) { - return time_stamper<TimeMap, TimeT, Tag>(pa, time_counter); - } - - //======================================================================== - // property_writer - - template <class PA, class OutputIterator, class Tag> - struct property_writer - : public base_visitor<property_writer<PA, OutputIterator, Tag> > - { +}; +template < class TimeMap, class TimeT, class Tag > +time_stamper< TimeMap, TimeT, Tag > stamp_times( + TimeMap pa, TimeT& time_counter, Tag) +{ + return time_stamper< TimeMap, TimeT, Tag >(pa, time_counter); +} + +//======================================================================== +// property_writer + +template < class PA, class OutputIterator, class Tag > +struct property_writer +: public base_visitor< property_writer< PA, OutputIterator, Tag > > +{ typedef Tag event_filter; - property_writer(PA pa, OutputIterator out) : m_pa(pa), m_out(out) { } + property_writer(PA pa, OutputIterator out) : m_pa(pa), m_out(out) {} - template <class T, class Graph> - void operator()(T x, Graph&) { *m_out++ = get(m_pa, x); } + template < class T, class Graph > void operator()(T x, Graph&) + { + *m_out++ = get(m_pa, x); + } PA m_pa; OutputIterator m_out; - }; - template <class PA, class OutputIterator, class Tag> - property_writer<PA, OutputIterator, Tag> - write_property(PA pa, OutputIterator out, Tag) { - return property_writer<PA, OutputIterator, Tag>(pa, out); - } - - //======================================================================== - // property_put - - /** - * Functor which just sets a given value to a vertex or edge in a property map. - */ - - template <typename PropertyMap, typename EventTag> - struct property_put - { +}; +template < class PA, class OutputIterator, class Tag > +property_writer< PA, OutputIterator, Tag > write_property( + PA pa, OutputIterator out, Tag) +{ + return property_writer< PA, OutputIterator, Tag >(pa, out); +} + +//======================================================================== +// property_put + +/** + * Functor which just sets a given value to a vertex or edge in a property map. + */ + +template < typename PropertyMap, typename EventTag > struct property_put +{ typedef EventTag event_filter; - - property_put (PropertyMap property_map, - typename property_traits <PropertyMap>::value_type value) : - property_map_ (property_map), value_ (value) - {} - - template <typename VertexOrEdge, typename Graph> - void operator() (VertexOrEdge v, const Graph&) + + property_put(PropertyMap property_map, + typename property_traits< PropertyMap >::value_type value) + : property_map_(property_map), value_(value) { - put (property_map_, v, value_); } - private: - PropertyMap property_map_; - typename property_traits <PropertyMap>::value_type value_; - }; - - /** - * Creates a property_put functor which just sets a given value to a vertex or edge. - * - * @param property_map Given writeable property map - * @param value Fixed value of the map - * @param tag Event Filter - * @return The functor. - */ - - template <typename PropertyMap, typename EventTag> - inline property_put <PropertyMap, EventTag> - put_property (PropertyMap property_map, - typename property_traits <PropertyMap>::value_type value, - EventTag) + template < typename VertexOrEdge, typename Graph > + void operator()(VertexOrEdge v, const Graph&) { - return property_put <PropertyMap, EventTag> (property_map, value); + put(property_map_, v, value_); } -#define BOOST_GRAPH_EVENT_STUB(Event,Kind) \ - typedef ::boost::Event Event##_type; \ - template<typename Visitor> \ - Kind##_visitor<std::pair<detail::functor_to_visitor<Event##_type, \ - Visitor>, Visitors> > \ - do_##Event(Visitor visitor) \ - { \ - typedef std::pair<detail::functor_to_visitor<Event##_type, Visitor>, \ - Visitors> visitor_list; \ - typedef Kind##_visitor<visitor_list> result_type; \ - return result_type(visitor_list(visitor, m_vis)); \ +private: + PropertyMap property_map_; + typename property_traits< PropertyMap >::value_type value_; +}; + +/** + * Creates a property_put functor which just sets a given value to a vertex or + * edge. + * + * @param property_map Given writeable property map + * @param value Fixed value of the map + * @param tag Event Filter + * @return The functor. + */ + +template < typename PropertyMap, typename EventTag > +inline property_put< PropertyMap, EventTag > put_property( + PropertyMap property_map, + typename property_traits< PropertyMap >::value_type value, EventTag) +{ + return property_put< PropertyMap, EventTag >(property_map, value); +} + +#define BOOST_GRAPH_EVENT_STUB(Event, Kind) \ + typedef ::boost::Event Event##_type; \ + template < typename Visitor > \ + Kind##_visitor< std::pair< \ + detail::functor_to_visitor< Event##_type, Visitor >, Visitors > > \ + do_##Event(Visitor visitor) \ + { \ + typedef std::pair< \ + detail::functor_to_visitor< Event##_type, Visitor >, Visitors > \ + visitor_list; \ + typedef Kind##_visitor< visitor_list > result_type; \ + return result_type(visitor_list(visitor, m_vis)); \ } } /* namespace boost */ diff --git a/contrib/restricted/boost/graph/include/boost/pending/container_traits.hpp b/contrib/restricted/boost/graph/include/boost/pending/container_traits.hpp index 13800a3001..8bf113a3e8 100644 --- a/contrib/restricted/boost/graph/include/boost/pending/container_traits.hpp +++ b/contrib/restricted/boost/graph/include/boost/pending/container_traits.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Jeremy Siek 2004 +// (C) Copyright Jeremy Siek 2004 // (C) Copyright Thomas Claveirole 2010 // (C) Copyright Ignacy Gawedzki 2010 // Distributed under the Boost Software License, Version 1.0. (See @@ -10,11 +10,11 @@ // Sure would be nice to be able to forward declare these // instead of pulling in all the headers. Too bad that -// is not legal. There ought to be a standard <stlfwd> header. -JGS +// is not legal. There ought to be a standard <stlfwd> header. -JGS #include <boost/next_prior.hpp> -#include <algorithm> // for std::remove +#include <algorithm> // for std::remove #include <utility> #include <vector> #include <list> @@ -36,528 +36,622 @@ #define BOOST_PENDING_FWD_VALUE(type, var) (var) #else #define BOOST_PENDING_FWD_TYPE(type) type&& -#define BOOST_PENDING_FWD_VALUE(type, var) (std::forward<type>((var))) +#define BOOST_PENDING_FWD_VALUE(type, var) (std::forward< type >((var))) #endif // The content of this file is in 'graph_detail' because otherwise -// there will be name clashes with +// there will be name clashes with // sandbox/boost/sequence_algo/container_traits.hpp // The 'detail' subnamespace will still cause problems. -namespace boost { namespace graph_detail { - - //====================================================================== - // Container Category Tags - // - // They use virtual inheritance because there are lots of - // inheritance diamonds. +namespace boost +{ +namespace graph_detail +{ + + //====================================================================== + // Container Category Tags + // + // They use virtual inheritance because there are lots of + // inheritance diamonds. + + struct container_tag + { + }; + struct forward_container_tag : virtual public container_tag + { + }; + struct reversible_container_tag : virtual public forward_container_tag + { + }; + struct random_access_container_tag : virtual public reversible_container_tag + { + }; + + struct sequence_tag : virtual public forward_container_tag + { + }; + + struct associative_container_tag : virtual public forward_container_tag + { + }; + + struct sorted_associative_container_tag + : virtual public associative_container_tag, + virtual public reversible_container_tag + { + }; + + struct front_insertion_sequence_tag : virtual public sequence_tag + { + }; + struct back_insertion_sequence_tag : virtual public sequence_tag + { + }; + + struct unique_associative_container_tag + : virtual public associative_container_tag + { + }; + struct multiple_associative_container_tag + : virtual public associative_container_tag + { + }; + struct simple_associative_container_tag + : virtual public associative_container_tag + { + }; + struct pair_associative_container_tag + : virtual public associative_container_tag + { + }; + + //====================================================================== + // Iterator Stability Tags + // + // Do mutating operations such as insert/erase/resize invalidate all + // outstanding iterators? + + struct stable_tag + { + }; + struct unstable_tag + { + }; + + //====================================================================== + // Container Traits Class and container_category() function + + // don't use this unless there is partial specialization + template < class Container > struct container_traits + { + typedef typename Container::category category; + typedef typename Container::iterator_stability iterator_stability; + }; + + // Use this as a compile-time assertion that X is stable + inline void require_stable(stable_tag) {} + + // std::vector + struct vector_tag : virtual public random_access_container_tag, + virtual public back_insertion_sequence_tag + { + }; + + template < class T, class Alloc > + vector_tag container_category(const std::vector< T, Alloc >&) + { + return vector_tag(); + } - struct container_tag { }; - struct forward_container_tag : virtual public container_tag { }; - struct reversible_container_tag : virtual public forward_container_tag { }; - struct random_access_container_tag - : virtual public reversible_container_tag { }; - - struct sequence_tag : virtual public forward_container_tag { }; + template < class T, class Alloc > + unstable_tag iterator_stability(const std::vector< T, Alloc >&) + { + return unstable_tag(); + } - struct associative_container_tag : virtual public forward_container_tag { }; + template < class T, class Alloc > + struct container_traits< std::vector< T, Alloc > > + { + typedef vector_tag category; + typedef unstable_tag iterator_stability; + }; - struct sorted_associative_container_tag - : virtual public associative_container_tag, - virtual public reversible_container_tag { }; - - struct front_insertion_sequence_tag : virtual public sequence_tag { }; - struct back_insertion_sequence_tag : virtual public sequence_tag { }; - - struct unique_associative_container_tag - : virtual public associative_container_tag { }; - struct multiple_associative_container_tag - : virtual public associative_container_tag { }; - struct simple_associative_container_tag - : virtual public associative_container_tag { }; - struct pair_associative_container_tag - : virtual public associative_container_tag { }; - - - //====================================================================== - // Iterator Stability Tags - // - // Do mutating operations such as insert/erase/resize invalidate all - // outstanding iterators? - - struct stable_tag { }; - struct unstable_tag { }; - - //====================================================================== - // Container Traits Class and container_category() function - - // don't use this unless there is partial specialization - template <class Container> - struct container_traits { - typedef typename Container::category category; - typedef typename Container::iterator_stability iterator_stability; - }; - - // Use this as a compile-time assertion that X is stable - inline void require_stable(stable_tag) { } - - // std::vector - struct vector_tag : - virtual public random_access_container_tag, - virtual public back_insertion_sequence_tag { }; - - template <class T, class Alloc> - vector_tag container_category(const std::vector<T,Alloc>&) - { return vector_tag(); } - - template <class T, class Alloc> - unstable_tag iterator_stability(const std::vector<T,Alloc>&) - { return unstable_tag(); } - - template <class T, class Alloc> - struct container_traits< std::vector<T,Alloc> > { - typedef vector_tag category; - typedef unstable_tag iterator_stability; - }; - - // std::list - struct list_tag : - virtual public reversible_container_tag, - virtual public back_insertion_sequence_tag + // std::list + struct list_tag : virtual public reversible_container_tag, + virtual public back_insertion_sequence_tag // this causes problems for push_dispatch... // virtual public front_insertion_sequence_tag - { }; - - template <class T, class Alloc> - list_tag container_category(const std::list<T,Alloc>&) - { return list_tag(); } - - template <class T, class Alloc> - stable_tag iterator_stability(const std::list<T,Alloc>&) - { return stable_tag(); } - - template <class T, class Alloc> - struct container_traits< std::list<T,Alloc> > { - typedef list_tag category; - typedef stable_tag iterator_stability; - }; - - // std::set - struct set_tag : - virtual public sorted_associative_container_tag, - virtual public simple_associative_container_tag, - virtual public unique_associative_container_tag - { }; - - template <class Key, class Cmp, class Alloc> - set_tag container_category(const std::set<Key,Cmp,Alloc>&) - { return set_tag(); } - - template <class Key, class Cmp, class Alloc> - stable_tag iterator_stability(const std::set<Key,Cmp,Alloc>&) - { return stable_tag(); } - - template <class Key, class Cmp, class Alloc> - struct container_traits< std::set<Key,Cmp,Alloc> > { - typedef set_tag category; - typedef stable_tag iterator_stability; - }; - - // std::multiset - struct multiset_tag : - virtual public sorted_associative_container_tag, - virtual public simple_associative_container_tag, - virtual public multiple_associative_container_tag - { }; - - template <class Key, class Cmp, class Alloc> - multiset_tag container_category(const std::multiset<Key,Cmp,Alloc>&) - { return multiset_tag(); } - - template <class Key, class Cmp, class Alloc> - stable_tag iterator_stability(const std::multiset<Key,Cmp,Alloc>&) - { return stable_tag(); } - - template <class Key, class Cmp, class Alloc> - struct container_traits< std::multiset<Key,Cmp,Alloc> > { - typedef multiset_tag category; - typedef stable_tag iterator_stability; - }; - - // deque - - // std::map - struct map_tag : - virtual public sorted_associative_container_tag, - virtual public pair_associative_container_tag, - virtual public unique_associative_container_tag - { }; - - template <class Key, class T, class Cmp, class Alloc> - struct container_traits< std::map<Key,T,Cmp,Alloc> > { - typedef map_tag category; - typedef stable_tag iterator_stability; - }; - - template <class Key, class T, class Cmp, class Alloc> - map_tag container_category(const std::map<Key,T,Cmp,Alloc>&) - { return map_tag(); } - - template <class Key, class T, class Cmp, class Alloc> - stable_tag iterator_stability(const std::map<Key,T,Cmp,Alloc>&) - { return stable_tag(); } - - // std::multimap - struct multimap_tag : - virtual public sorted_associative_container_tag, - virtual public pair_associative_container_tag, - virtual public multiple_associative_container_tag - { }; - - template <class Key, class T, class Cmp, class Alloc> - struct container_traits< std::multimap<Key,T,Cmp,Alloc> > { - typedef multimap_tag category; - typedef stable_tag iterator_stability; - }; - - template <class Key, class T, class Cmp, class Alloc> - multimap_tag container_category(const std::multimap<Key,T,Cmp,Alloc>&) - { return multimap_tag(); } - - template <class Key, class T, class Cmp, class Alloc> - stable_tag iterator_stability(const std::multimap<Key,T,Cmp,Alloc>&) - { return stable_tag(); } - - - // hash_set, hash_map - - struct unordered_set_tag : - virtual public simple_associative_container_tag, - virtual public unique_associative_container_tag - { }; - - struct unordered_multiset_tag : - virtual public simple_associative_container_tag, - virtual public multiple_associative_container_tag - { }; - - - struct unordered_map_tag : - virtual public pair_associative_container_tag, - virtual public unique_associative_container_tag - { }; - - struct unordered_multimap_tag : - virtual public pair_associative_container_tag, - virtual public multiple_associative_container_tag - { }; - - - template <class Key, class Eq, class Hash, class Alloc> - struct container_traits< boost::unordered_set<Key,Eq,Hash,Alloc> > { - typedef unordered_set_tag category; - typedef unstable_tag iterator_stability; - }; - template <class Key, class T, class Eq, class Hash, class Alloc> - struct container_traits< boost::unordered_map<Key,T,Eq,Hash,Alloc> > { - typedef unordered_map_tag category; - typedef unstable_tag iterator_stability; - }; - template <class Key, class Eq, class Hash, class Alloc> - struct container_traits< boost::unordered_multiset<Key,Eq,Hash,Alloc> > { - typedef unordered_multiset_tag category; - typedef unstable_tag iterator_stability; - }; - template <class Key, class T, class Eq, class Hash, class Alloc> - struct container_traits< boost::unordered_multimap<Key,T,Eq,Hash,Alloc> > { - typedef unordered_multimap_tag category; - typedef unstable_tag iterator_stability; - }; - - template <class Key, class Eq, class Hash, class Alloc> - unordered_set_tag - container_category(const boost::unordered_set<Key,Eq,Hash,Alloc>&) - { return unordered_set_tag(); } - - template <class Key, class T, class Eq, class Hash, class Alloc> - unordered_map_tag - container_category(const boost::unordered_map<Key,T,Eq,Hash,Alloc>&) - { return unordered_map_tag(); } - - template <class Key, class Eq, class Hash, class Alloc> - unstable_tag iterator_stability(const boost::unordered_set<Key,Eq,Hash,Alloc>&) - { return unstable_tag(); } - - template <class Key, class T, class Eq, class Hash, class Alloc> - unstable_tag iterator_stability(const boost::unordered_map<Key,T,Eq,Hash,Alloc>&) - { return unstable_tag(); } - template <class Key, class Eq, class Hash, class Alloc> - unordered_multiset_tag - container_category(const boost::unordered_multiset<Key,Eq,Hash,Alloc>&) - { return unordered_multiset_tag(); } - - template <class Key, class T, class Eq, class Hash, class Alloc> - unordered_multimap_tag - container_category(const boost::unordered_multimap<Key,T,Eq,Hash,Alloc>&) - { return unordered_multimap_tag(); } - - template <class Key, class Eq, class Hash, class Alloc> - unstable_tag - iterator_stability(const boost::unordered_multiset<Key,Eq,Hash,Alloc>&) - { return unstable_tag(); } - - template <class Key, class T, class Eq, class Hash, class Alloc> - unstable_tag - iterator_stability(const boost::unordered_multimap<Key,T,Eq,Hash,Alloc>&) - { return unstable_tag(); } + { + }; + + template < class T, class Alloc > + list_tag container_category(const std::list< T, Alloc >&) + { + return list_tag(); + } + + template < class T, class Alloc > + stable_tag iterator_stability(const std::list< T, Alloc >&) + { + return stable_tag(); + } + + template < class T, class Alloc > + struct container_traits< std::list< T, Alloc > > + { + typedef list_tag category; + typedef stable_tag iterator_stability; + }; + + // std::set + struct set_tag : virtual public sorted_associative_container_tag, + virtual public simple_associative_container_tag, + virtual public unique_associative_container_tag + { + }; + + template < class Key, class Cmp, class Alloc > + set_tag container_category(const std::set< Key, Cmp, Alloc >&) + { + return set_tag(); + } + + template < class Key, class Cmp, class Alloc > + stable_tag iterator_stability(const std::set< Key, Cmp, Alloc >&) + { + return stable_tag(); + } + + template < class Key, class Cmp, class Alloc > + struct container_traits< std::set< Key, Cmp, Alloc > > + { + typedef set_tag category; + typedef stable_tag iterator_stability; + }; + + // std::multiset + struct multiset_tag : virtual public sorted_associative_container_tag, + virtual public simple_associative_container_tag, + virtual public multiple_associative_container_tag + { + }; + + template < class Key, class Cmp, class Alloc > + multiset_tag container_category(const std::multiset< Key, Cmp, Alloc >&) + { + return multiset_tag(); + } + + template < class Key, class Cmp, class Alloc > + stable_tag iterator_stability(const std::multiset< Key, Cmp, Alloc >&) + { + return stable_tag(); + } + + template < class Key, class Cmp, class Alloc > + struct container_traits< std::multiset< Key, Cmp, Alloc > > + { + typedef multiset_tag category; + typedef stable_tag iterator_stability; + }; + + // deque + + // std::map + struct map_tag : virtual public sorted_associative_container_tag, + virtual public pair_associative_container_tag, + virtual public unique_associative_container_tag + { + }; + + template < class Key, class T, class Cmp, class Alloc > + struct container_traits< std::map< Key, T, Cmp, Alloc > > + { + typedef map_tag category; + typedef stable_tag iterator_stability; + }; + + template < class Key, class T, class Cmp, class Alloc > + map_tag container_category(const std::map< Key, T, Cmp, Alloc >&) + { + return map_tag(); + } + + template < class Key, class T, class Cmp, class Alloc > + stable_tag iterator_stability(const std::map< Key, T, Cmp, Alloc >&) + { + return stable_tag(); + } + + // std::multimap + struct multimap_tag : virtual public sorted_associative_container_tag, + virtual public pair_associative_container_tag, + virtual public multiple_associative_container_tag + { + }; + + template < class Key, class T, class Cmp, class Alloc > + struct container_traits< std::multimap< Key, T, Cmp, Alloc > > + { + typedef multimap_tag category; + typedef stable_tag iterator_stability; + }; + + template < class Key, class T, class Cmp, class Alloc > + multimap_tag container_category(const std::multimap< Key, T, Cmp, Alloc >&) + { + return multimap_tag(); + } + + template < class Key, class T, class Cmp, class Alloc > + stable_tag iterator_stability(const std::multimap< Key, T, Cmp, Alloc >&) + { + return stable_tag(); + } + + // hash_set, hash_map + + struct unordered_set_tag : virtual public simple_associative_container_tag, + virtual public unique_associative_container_tag + { + }; + + struct unordered_multiset_tag + : virtual public simple_associative_container_tag, + virtual public multiple_associative_container_tag + { + }; + + struct unordered_map_tag : virtual public pair_associative_container_tag, + virtual public unique_associative_container_tag + { + }; + + struct unordered_multimap_tag + : virtual public pair_associative_container_tag, + virtual public multiple_associative_container_tag + { + }; + + template < class Key, class Eq, class Hash, class Alloc > + struct container_traits< boost::unordered_set< Key, Eq, Hash, Alloc > > + { + typedef unordered_set_tag category; + typedef unstable_tag iterator_stability; + }; + template < class Key, class T, class Eq, class Hash, class Alloc > + struct container_traits< boost::unordered_map< Key, T, Eq, Hash, Alloc > > + { + typedef unordered_map_tag category; + typedef unstable_tag iterator_stability; + }; + template < class Key, class Eq, class Hash, class Alloc > + struct container_traits< boost::unordered_multiset< Key, Eq, Hash, Alloc > > + { + typedef unordered_multiset_tag category; + typedef unstable_tag iterator_stability; + }; + template < class Key, class T, class Eq, class Hash, class Alloc > + struct container_traits< + boost::unordered_multimap< Key, T, Eq, Hash, Alloc > > + { + typedef unordered_multimap_tag category; + typedef unstable_tag iterator_stability; + }; + + template < class Key, class Eq, class Hash, class Alloc > + unordered_set_tag container_category( + const boost::unordered_set< Key, Eq, Hash, Alloc >&) + { + return unordered_set_tag(); + } + + template < class Key, class T, class Eq, class Hash, class Alloc > + unordered_map_tag container_category( + const boost::unordered_map< Key, T, Eq, Hash, Alloc >&) + { + return unordered_map_tag(); + } + + template < class Key, class Eq, class Hash, class Alloc > + unstable_tag iterator_stability( + const boost::unordered_set< Key, Eq, Hash, Alloc >&) + { + return unstable_tag(); + } + + template < class Key, class T, class Eq, class Hash, class Alloc > + unstable_tag iterator_stability( + const boost::unordered_map< Key, T, Eq, Hash, Alloc >&) + { + return unstable_tag(); + } + template < class Key, class Eq, class Hash, class Alloc > + unordered_multiset_tag container_category( + const boost::unordered_multiset< Key, Eq, Hash, Alloc >&) + { + return unordered_multiset_tag(); + } + + template < class Key, class T, class Eq, class Hash, class Alloc > + unordered_multimap_tag container_category( + const boost::unordered_multimap< Key, T, Eq, Hash, Alloc >&) + { + return unordered_multimap_tag(); + } + + template < class Key, class Eq, class Hash, class Alloc > + unstable_tag iterator_stability( + const boost::unordered_multiset< Key, Eq, Hash, Alloc >&) + { + return unstable_tag(); + } + + template < class Key, class T, class Eq, class Hash, class Alloc > + unstable_tag iterator_stability( + const boost::unordered_multimap< Key, T, Eq, Hash, Alloc >&) + { + return unstable_tag(); + } #ifndef BOOST_NO_CXX11_HDR_UNORDERED_SET - template <class Key, class Eq, class Hash, class Alloc> - struct container_traits< std::unordered_set<Key,Eq,Hash,Alloc> > { - typedef unordered_set_tag category; - typedef unstable_tag iterator_stability; - }; + template < class Key, class Eq, class Hash, class Alloc > + struct container_traits< std::unordered_set< Key, Eq, Hash, Alloc > > + { + typedef unordered_set_tag category; + typedef unstable_tag iterator_stability; + }; #endif #ifndef BOOST_NO_CXX11_HDR_UNORDERED_MAP - template <class Key, class T, class Eq, class Hash, class Alloc> - struct container_traits< std::unordered_map<Key,T,Eq,Hash,Alloc> > { - typedef unordered_map_tag category; - typedef unstable_tag iterator_stability; - }; + template < class Key, class T, class Eq, class Hash, class Alloc > + struct container_traits< std::unordered_map< Key, T, Eq, Hash, Alloc > > + { + typedef unordered_map_tag category; + typedef unstable_tag iterator_stability; + }; #endif #ifndef BOOST_NO_CXX11_HDR_UNORDERED_SET - template <class Key, class Eq, class Hash, class Alloc> - struct container_traits< std::unordered_multiset<Key,Eq,Hash,Alloc> > { - typedef unordered_multiset_tag category; - typedef unstable_tag iterator_stability; - }; + template < class Key, class Eq, class Hash, class Alloc > + struct container_traits< std::unordered_multiset< Key, Eq, Hash, Alloc > > + { + typedef unordered_multiset_tag category; + typedef unstable_tag iterator_stability; + }; #endif #ifndef BOOST_NO_CXX11_HDR_UNORDERED_MAP - template <class Key, class T, class Eq, class Hash, class Alloc> - struct container_traits< std::unordered_multimap<Key,T,Eq,Hash,Alloc> > { - typedef unordered_multimap_tag category; - typedef unstable_tag iterator_stability; - }; + template < class Key, class T, class Eq, class Hash, class Alloc > + struct container_traits< + std::unordered_multimap< Key, T, Eq, Hash, Alloc > > + { + typedef unordered_multimap_tag category; + typedef unstable_tag iterator_stability; + }; #endif #ifndef BOOST_NO_CXX11_HDR_UNORDERED_SET - template <class Key, class Eq, class Hash, class Alloc> - unordered_set_tag - container_category(const std::unordered_set<Key,Eq,Hash,Alloc>&) - { return unordered_set_tag(); } + template < class Key, class Eq, class Hash, class Alloc > + unordered_set_tag container_category( + const std::unordered_set< Key, Eq, Hash, Alloc >&) + { + return unordered_set_tag(); + } #endif #ifndef BOOST_NO_CXX11_HDR_UNORDERED_MAP - template <class Key, class T, class Eq, class Hash, class Alloc> - unordered_map_tag - container_category(const std::unordered_map<Key,T,Eq,Hash,Alloc>&) - { return unordered_map_tag(); } + template < class Key, class T, class Eq, class Hash, class Alloc > + unordered_map_tag container_category( + const std::unordered_map< Key, T, Eq, Hash, Alloc >&) + { + return unordered_map_tag(); + } #endif #ifndef BOOST_NO_CXX11_HDR_UNORDERED_SET - template <class Key, class Eq, class Hash, class Alloc> - unstable_tag iterator_stability(const std::unordered_set<Key,Eq,Hash,Alloc>&) - { return unstable_tag(); } + template < class Key, class Eq, class Hash, class Alloc > + unstable_tag iterator_stability( + const std::unordered_set< Key, Eq, Hash, Alloc >&) + { + return unstable_tag(); + } #endif #ifndef BOOST_NO_CXX11_HDR_UNORDERED_MAP - template <class Key, class T, class Eq, class Hash, class Alloc> - unstable_tag iterator_stability(const std::unordered_map<Key,T,Eq,Hash,Alloc>&) - { return unstable_tag(); } + template < class Key, class T, class Eq, class Hash, class Alloc > + unstable_tag iterator_stability( + const std::unordered_map< Key, T, Eq, Hash, Alloc >&) + { + return unstable_tag(); + } #endif #ifndef BOOST_NO_CXX11_HDR_UNORDERED_SET - template <class Key, class Eq, class Hash, class Alloc> - unordered_multiset_tag - container_category(const std::unordered_multiset<Key,Eq,Hash,Alloc>&) - { return unordered_multiset_tag(); } + template < class Key, class Eq, class Hash, class Alloc > + unordered_multiset_tag container_category( + const std::unordered_multiset< Key, Eq, Hash, Alloc >&) + { + return unordered_multiset_tag(); + } #endif #ifndef BOOST_NO_CXX11_HDR_UNORDERED_MAP - template <class Key, class T, class Eq, class Hash, class Alloc> - unordered_multimap_tag - container_category(const std::unordered_multimap<Key,T,Eq,Hash,Alloc>&) - { return unordered_multimap_tag(); } + template < class Key, class T, class Eq, class Hash, class Alloc > + unordered_multimap_tag container_category( + const std::unordered_multimap< Key, T, Eq, Hash, Alloc >&) + { + return unordered_multimap_tag(); + } #endif #ifndef BOOST_NO_CXX11_HDR_UNORDERED_SET - template <class Key, class Eq, class Hash, class Alloc> - unstable_tag - iterator_stability(const std::unordered_multiset<Key,Eq,Hash,Alloc>&) - { return unstable_tag(); } + template < class Key, class Eq, class Hash, class Alloc > + unstable_tag iterator_stability( + const std::unordered_multiset< Key, Eq, Hash, Alloc >&) + { + return unstable_tag(); + } #endif #ifndef BOOST_NO_CXX11_HDR_UNORDERED_MAP - template <class Key, class T, class Eq, class Hash, class Alloc> - unstable_tag - iterator_stability(const std::unordered_multimap<Key,T,Eq,Hash,Alloc>&) - { return unstable_tag(); } + template < class Key, class T, class Eq, class Hash, class Alloc > + unstable_tag iterator_stability( + const std::unordered_multimap< Key, T, Eq, Hash, Alloc >&) + { + return unstable_tag(); + } #endif + //=========================================================================== + // Generalized Container Functions - //=========================================================================== - // Generalized Container Functions - - - // Erase - template <class Sequence, class T> - void erase_dispatch(Sequence& c, const T& x, - sequence_tag) - { - c.erase(std::remove(c.begin(), c.end(), x), c.end()); - } + // Erase + template < class Sequence, class T > + void erase_dispatch(Sequence& c, const T& x, sequence_tag) + { + c.erase(std::remove(c.begin(), c.end(), x), c.end()); + } - template <class AssociativeContainer, class T> - void erase_dispatch(AssociativeContainer& c, const T& x, - associative_container_tag) - { - c.erase(x); - } - template <class Container, class T> - void erase(Container& c, const T& x) - { - erase_dispatch(c, x, container_category(c)); - } + template < class AssociativeContainer, class T > + void erase_dispatch( + AssociativeContainer& c, const T& x, associative_container_tag) + { + c.erase(x); + } + template < class Container, class T > void erase(Container& c, const T& x) + { + erase_dispatch(c, x, container_category(c)); + } - // Erase If - template <class Sequence, class Predicate, class IteratorStability> - void erase_if_dispatch(Sequence& c, Predicate p, - sequence_tag, IteratorStability) - { + // Erase If + template < class Sequence, class Predicate, class IteratorStability > + void erase_if_dispatch( + Sequence& c, Predicate p, sequence_tag, IteratorStability) + { #if 0 c.erase(std::remove_if(c.begin(), c.end(), p), c.end()); #else - if (! c.empty()) - c.erase(std::remove_if(c.begin(), c.end(), p), c.end()); + if (!c.empty()) + c.erase(std::remove_if(c.begin(), c.end(), p), c.end()); #endif - } - template <class AssociativeContainer, class Predicate> - void erase_if_dispatch(AssociativeContainer& c, Predicate p, - associative_container_tag, stable_tag) - { - typename AssociativeContainer::iterator i, next; - for (i = next = c.begin(); next != c.end(); i = next) { - ++next; - if (p(*i)) - c.erase(i); } - } - template <class AssociativeContainer, class Predicate> - void erase_if_dispatch(AssociativeContainer& c, Predicate p, - associative_container_tag, unstable_tag) - { - // This method is really slow, so hopefully we won't have any - // associative containers with unstable iterators! - // Is there a better way to do this? - typename AssociativeContainer::iterator i; - typename AssociativeContainer::size_type n = c.size(); - while (n--) - for (i = c.begin(); i != c.end(); ++i) - if (p(*i)) { - c.erase(i); - break; + template < class AssociativeContainer, class Predicate > + void erase_if_dispatch(AssociativeContainer& c, Predicate p, + associative_container_tag, stable_tag) + { + typename AssociativeContainer::iterator i, next; + for (i = next = c.begin(); next != c.end(); i = next) + { + ++next; + if (p(*i)) + c.erase(i); } - } - template <class Container, class Predicate> - void erase_if(Container& c, Predicate p) - { - erase_if_dispatch(c, p, container_category(c), iterator_stability(c)); - } + } + template < class AssociativeContainer, class Predicate > + void erase_if_dispatch(AssociativeContainer& c, Predicate p, + associative_container_tag, unstable_tag) + { + // This method is really slow, so hopefully we won't have any + // associative containers with unstable iterators! + // Is there a better way to do this? + typename AssociativeContainer::iterator i; + typename AssociativeContainer::size_type n = c.size(); + while (n--) + for (i = c.begin(); i != c.end(); ++i) + if (p(*i)) + { + c.erase(i); + break; + } + } + template < class Container, class Predicate > + void erase_if(Container& c, Predicate p) + { + erase_if_dispatch(c, p, container_category(c), iterator_stability(c)); + } - // Push - template <class Container, class T> - std::pair<typename Container::iterator, bool> - push_dispatch(Container& c, BOOST_PENDING_FWD_TYPE(T) v, back_insertion_sequence_tag) - { - c.push_back(BOOST_PENDING_FWD_VALUE(T, v)); - return std::make_pair(boost::prior(c.end()), true); - } + // Push + template < class Container, class T > + std::pair< typename Container::iterator, bool > push_dispatch( + Container& c, BOOST_PENDING_FWD_TYPE(T) v, back_insertion_sequence_tag) + { + c.push_back(BOOST_PENDING_FWD_VALUE(T, v)); + return std::make_pair(boost::prior(c.end()), true); + } - template <class Container, class T> - std::pair<typename Container::iterator, bool> - push_dispatch(Container& c, BOOST_PENDING_FWD_TYPE(T) v, front_insertion_sequence_tag) - { - c.push_front(BOOST_PENDING_FWD_VALUE(T, v)); - return std::make_pair(c.begin(), true); - } + template < class Container, class T > + std::pair< typename Container::iterator, bool > push_dispatch( + Container& c, BOOST_PENDING_FWD_TYPE(T) v, front_insertion_sequence_tag) + { + c.push_front(BOOST_PENDING_FWD_VALUE(T, v)); + return std::make_pair(c.begin(), true); + } - template <class AssociativeContainer, class T> - std::pair<typename AssociativeContainer::iterator, bool> - push_dispatch(AssociativeContainer& c, BOOST_PENDING_FWD_TYPE(T) v, - unique_associative_container_tag) - { - return c.insert(BOOST_PENDING_FWD_VALUE(T, v)); - } + template < class AssociativeContainer, class T > + std::pair< typename AssociativeContainer::iterator, bool > push_dispatch( + AssociativeContainer& c, BOOST_PENDING_FWD_TYPE(T) v, + unique_associative_container_tag) + { + return c.insert(BOOST_PENDING_FWD_VALUE(T, v)); + } - template <class AssociativeContainer, class T> - std::pair<typename AssociativeContainer::iterator, bool> - push_dispatch(AssociativeContainer& c, BOOST_PENDING_FWD_TYPE(T) v, - multiple_associative_container_tag) - { - return std::make_pair(c.insert(BOOST_PENDING_FWD_VALUE(T, v)), true); - } + template < class AssociativeContainer, class T > + std::pair< typename AssociativeContainer::iterator, bool > push_dispatch( + AssociativeContainer& c, BOOST_PENDING_FWD_TYPE(T) v, + multiple_associative_container_tag) + { + return std::make_pair(c.insert(BOOST_PENDING_FWD_VALUE(T, v)), true); + } - template <class Container, class T> - std::pair<typename Container::iterator,bool> - push(Container& c, BOOST_PENDING_FWD_TYPE(T) v) - { - return push_dispatch(c, BOOST_PENDING_FWD_VALUE(T, v), container_category(c)); - } + template < class Container, class T > + std::pair< typename Container::iterator, bool > push( + Container& c, BOOST_PENDING_FWD_TYPE(T) v) + { + return push_dispatch( + c, BOOST_PENDING_FWD_VALUE(T, v), container_category(c)); + } - // Find - template <class Container, class Value> - typename Container::iterator - find_dispatch(Container& c, - const Value& value, - container_tag) - { - return std::find(c.begin(), c.end(), value); - } + // Find + template < class Container, class Value > + typename Container::iterator find_dispatch( + Container& c, const Value& value, container_tag) + { + return std::find(c.begin(), c.end(), value); + } - template <class AssociativeContainer, class Value> - typename AssociativeContainer::iterator - find_dispatch(AssociativeContainer& c, - const Value& value, - associative_container_tag) - { - return c.find(value); - } + template < class AssociativeContainer, class Value > + typename AssociativeContainer::iterator find_dispatch( + AssociativeContainer& c, const Value& value, associative_container_tag) + { + return c.find(value); + } - template <class Container, class Value> - typename Container::iterator - find(Container& c, - const Value& value) - { - return find_dispatch(c, value, - graph_detail::container_category(c)); - } + template < class Container, class Value > + typename Container::iterator find(Container& c, const Value& value) + { + return find_dispatch(c, value, graph_detail::container_category(c)); + } - // Find (const versions) - template <class Container, class Value> - typename Container::const_iterator - find_dispatch(const Container& c, - const Value& value, - container_tag) - { - return std::find(c.begin(), c.end(), value); - } + // Find (const versions) + template < class Container, class Value > + typename Container::const_iterator find_dispatch( + const Container& c, const Value& value, container_tag) + { + return std::find(c.begin(), c.end(), value); + } - template <class AssociativeContainer, class Value> - typename AssociativeContainer::const_iterator - find_dispatch(const AssociativeContainer& c, - const Value& value, - associative_container_tag) - { - return c.find(value); - } + template < class AssociativeContainer, class Value > + typename AssociativeContainer::const_iterator find_dispatch( + const AssociativeContainer& c, const Value& value, + associative_container_tag) + { + return c.find(value); + } - template <class Container, class Value> - typename Container::const_iterator - find(const Container& c, - const Value& value) - { - return find_dispatch(c, value, - graph_detail::container_category(c)); - } + template < class Container, class Value > + typename Container::const_iterator find( + const Container& c, const Value& value) + { + return find_dispatch(c, value, graph_detail::container_category(c)); + } - // Equal range + // Equal range #if 0 // Make the dispatch fail if c is not an Associative Container (and thus // doesn't have equal_range unless it is sorted, which we cannot check @@ -574,26 +668,25 @@ namespace boost { namespace graph_detail { } #endif - template <class AssociativeContainer, class Value> - std::pair<typename AssociativeContainer::iterator, - typename AssociativeContainer::iterator> - equal_range_dispatch(AssociativeContainer& c, - const Value& value, - associative_container_tag) - { - return c.equal_range(value); - } + template < class AssociativeContainer, class Value > + std::pair< typename AssociativeContainer::iterator, + typename AssociativeContainer::iterator > + equal_range_dispatch( + AssociativeContainer& c, const Value& value, associative_container_tag) + { + return c.equal_range(value); + } - template <class Container, class Value> - std::pair<typename Container::iterator, typename Container::iterator> - equal_range(Container& c, - const Value& value) - { - return equal_range_dispatch(c, value, - graph_detail::container_category(c)); - } + template < class Container, class Value > + std::pair< typename Container::iterator, typename Container::iterator > + equal_range(Container& c, const Value& value) + { + return equal_range_dispatch( + c, value, graph_detail::container_category(c)); + } -}} // namespace boost::graph_detail +} +} // namespace boost::graph_detail #undef BOOST_PENDING_FWD_TYPE #undef BOOST_PENDING_FWD_VALUE diff --git a/contrib/restricted/boost/graph/include/boost/pending/detail/property.hpp b/contrib/restricted/boost/graph/include/boost/pending/detail/property.hpp index 42c7ce07dc..9967ffb287 100644 --- a/contrib/restricted/boost/graph/include/boost/pending/detail/property.hpp +++ b/contrib/restricted/boost/graph/include/boost/pending/detail/property.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Jeremy Siek 2004 +// (C) Copyright Jeremy Siek 2004 // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) @@ -9,13 +9,17 @@ #include <utility> // for std::pair #include <boost/type_traits/same_traits.hpp> // for is_same -namespace boost { +namespace boost +{ - namespace detail { +namespace detail +{ - struct error_property_not_found { }; + struct error_property_not_found + { + }; - } // namespace detail +} // namespace detail } // namespace boost #endif // BOOST_DETAIL_PROPERTY_HPP diff --git a/contrib/restricted/boost/graph/include/boost/pending/indirect_cmp.hpp b/contrib/restricted/boost/graph/include/boost/pending/indirect_cmp.hpp index 14ee5314af..76088ea4c4 100644 --- a/contrib/restricted/boost/graph/include/boost/pending/indirect_cmp.hpp +++ b/contrib/restricted/boost/graph/include/boost/pending/indirect_cmp.hpp @@ -16,72 +16,77 @@ #include <boost/config.hpp> #include <boost/property_map/property_map.hpp> -namespace boost { +namespace boost +{ - //: indirect_cmp - // - // could also do this with compose_f_gx_hx, and the member binder... - // - //!category: functors - //!component: type - //!tparam: ReadablePropertyMap - a model of ReadablePropertyMap - //!definition: functor.h - template <class ReadablePropertyMap, class Compare> - class indirect_cmp { - public: - typedef typename boost::property_traits<ReadablePropertyMap>::value_type T; - typedef typename boost::property_traits<ReadablePropertyMap>::key_type K; +//: indirect_cmp +// +// could also do this with compose_f_gx_hx, and the member binder... +// +//! category: functors +//! component: type +//! tparam: ReadablePropertyMap - a model of ReadablePropertyMap +//! definition: functor.h +template < class ReadablePropertyMap, class Compare > class indirect_cmp +{ +public: + typedef + typename boost::property_traits< ReadablePropertyMap >::value_type T; + typedef typename boost::property_traits< ReadablePropertyMap >::key_type K; typedef K first_argument_type; typedef K second_argument_type; typedef bool result_type; - inline indirect_cmp(const ReadablePropertyMap& df, const Compare& c = Compare()) - : d(df), cmp(c) { } + inline indirect_cmp( + const ReadablePropertyMap& df, const Compare& c = Compare()) + : d(df), cmp(c) + { + } - template <class A, class B> - inline bool - operator()(const A& u, const B& v) const { - const T& du = get(d, u); - const T& dv = get(d, v); - return cmp(du, dv); + template < class A, class B > + inline bool operator()(const A& u, const B& v) const + { + const T& du = get(d, u); + const T& dv = get(d, v); + return cmp(du, dv); } - protected: + +protected: ReadablePropertyMap d; Compare cmp; - }; +}; - template <typename Compare, typename ReadablePropertyMap> - indirect_cmp<ReadablePropertyMap, Compare> - make_indirect_cmp(const Compare& cmp, ReadablePropertyMap pmap) { - indirect_cmp<ReadablePropertyMap, Compare> p(pmap, cmp); +template < typename Compare, typename ReadablePropertyMap > +indirect_cmp< ReadablePropertyMap, Compare > make_indirect_cmp( + const Compare& cmp, ReadablePropertyMap pmap) +{ + indirect_cmp< ReadablePropertyMap, Compare > p(pmap, cmp); return p; - } +} - template <class ReadablePropertyMap> - class indirect_pmap { - public: - typedef typename boost::property_traits<ReadablePropertyMap>::value_type T; - typedef typename boost::property_traits<ReadablePropertyMap>::key_type K; +template < class ReadablePropertyMap > class indirect_pmap +{ +public: + typedef + typename boost::property_traits< ReadablePropertyMap >::value_type T; + typedef typename boost::property_traits< ReadablePropertyMap >::key_type K; typedef K argument_type; typedef T result_type; - inline indirect_pmap(const ReadablePropertyMap& df) - : d(df) { } + inline indirect_pmap(const ReadablePropertyMap& df) : d(df) {} - inline T operator()(const K& u) const { - return get(d, u); - } - protected: + inline T operator()(const K& u) const { return get(d, u); } + +protected: ReadablePropertyMap d; - }; +}; - template <typename ReadablePropertyMap> - indirect_pmap<ReadablePropertyMap> - make_indirect_pmap(ReadablePropertyMap pmap) { - indirect_pmap<ReadablePropertyMap> f(pmap); +template < typename ReadablePropertyMap > +indirect_pmap< ReadablePropertyMap > make_indirect_pmap( + ReadablePropertyMap pmap) +{ + indirect_pmap< ReadablePropertyMap > f(pmap); return f; - } - +} } // namespace boost - #endif // GGCL_INDIRECT_CMP_HPP diff --git a/contrib/restricted/boost/graph/include/boost/pending/is_heap.hpp b/contrib/restricted/boost/graph/include/boost/pending/is_heap.hpp index b2e4b00694..697aa1ec8d 100644 --- a/contrib/restricted/boost/graph/include/boost/pending/is_heap.hpp +++ b/contrib/restricted/boost/graph/include/boost/pending/is_heap.hpp @@ -9,53 +9,54 @@ //======================================================================= // #if __KCC -namespace std { - -template <class RandomAccessIterator, class Distance> -bool __is_heap(RandomAccessIterator first, RandomAccessIterator last, - Distance*) +namespace std { - const Distance n = last - first; - Distance parent = 0; - for (Distance child = 1; child < n; ++child) { - if (first[parent] < first[child]) - return false; - if ((child & 1) == 0) - ++parent; - } - return true; +template < class RandomAccessIterator, class Distance > +bool __is_heap(RandomAccessIterator first, RandomAccessIterator last, Distance*) +{ + const Distance n = last - first; + + Distance parent = 0; + for (Distance child = 1; child < n; ++child) + { + if (first[parent] < first[child]) + return false; + if ((child & 1) == 0) + ++parent; + } + return true; } -template <class RandomAccessIterator> +template < class RandomAccessIterator > inline bool is_heap(RandomAccessIterator first, RandomAccessIterator last) { - return __is_heap(first, last, distance_type(first)); + return __is_heap(first, last, distance_type(first)); } - -template <class RandomAccessIterator, class Distance, class StrictWeakOrdering> +template < class RandomAccessIterator, class Distance, + class StrictWeakOrdering > bool __is_heap(RandomAccessIterator first, RandomAccessIterator last, - StrictWeakOrdering comp, - Distance*) + StrictWeakOrdering comp, Distance*) { - const Distance n = last - first; - - Distance parent = 0; - for (Distance child = 1; child < n; ++child) { - if (comp(first[parent], first[child])) - return false; - if ((child & 1) == 0) - ++parent; - } - return true; + const Distance n = last - first; + + Distance parent = 0; + for (Distance child = 1; child < n; ++child) + { + if (comp(first[parent], first[child])) + return false; + if ((child & 1) == 0) + ++parent; + } + return true; } -template <class RandomAccessIterator, class StrictWeakOrdering> +template < class RandomAccessIterator, class StrictWeakOrdering > inline bool is_heap(RandomAccessIterator first, RandomAccessIterator last, - StrictWeakOrdering comp) + StrictWeakOrdering comp) { - return __is_heap(first, last, comp, distance_type(first)); + return __is_heap(first, last, comp, distance_type(first)); } } diff --git a/contrib/restricted/boost/graph/include/boost/pending/mutable_heap.hpp b/contrib/restricted/boost/graph/include/boost/pending/mutable_heap.hpp index bbc8188190..b8f84fd33b 100644 --- a/contrib/restricted/boost/graph/include/boost/pending/mutable_heap.hpp +++ b/contrib/restricted/boost/graph/include/boost/pending/mutable_heap.hpp @@ -30,35 +30,38 @@ */ -namespace boost { +namespace boost +{ - template <class TreeNode, class Compare, class ExternalData> - inline TreeNode up_heap(TreeNode x, const Compare& comp, ExternalData& edata) { +template < class TreeNode, class Compare, class ExternalData > +inline TreeNode up_heap(TreeNode x, const Compare& comp, ExternalData& edata) +{ while (x.has_parent() && comp(x, x.parent())) - x.swap(x.parent(), edata); + x.swap(x.parent(), edata); return x; - } +} - template <class TreeNode, class Compare, class ExternalData> - inline TreeNode down_heap(TreeNode x, const Compare& comp, ExternalData& edata) { - while (x.children().size() > 0) { - typename TreeNode::children_type::iterator - child_iter = std::min_element(x.children().begin(), - x.children().end(), - comp); - if (comp(*child_iter, x)) - x.swap(*child_iter, edata); - else - break; +template < class TreeNode, class Compare, class ExternalData > +inline TreeNode down_heap(TreeNode x, const Compare& comp, ExternalData& edata) +{ + while (x.children().size() > 0) + { + typename TreeNode::children_type::iterator child_iter + = std::min_element(x.children().begin(), x.children().end(), comp); + if (comp(*child_iter, x)) + x.swap(*child_iter, edata); + else + break; } return x; - } +} - template <class TreeNode, class Compare, class ExternalData> - inline void update_heap(TreeNode x, const Compare& comp, ExternalData& edata) { +template < class TreeNode, class Compare, class ExternalData > +inline void update_heap(TreeNode x, const Compare& comp, ExternalData& edata) +{ x = down_heap(x, comp, edata); (void)up_heap(x, comp, edata); - } +} } #endif diff --git a/contrib/restricted/boost/graph/include/boost/pending/mutable_queue.hpp b/contrib/restricted/boost/graph/include/boost/pending/mutable_queue.hpp index 82cfdd8182..96c37d5e22 100644 --- a/contrib/restricted/boost/graph/include/boost/pending/mutable_queue.hpp +++ b/contrib/restricted/boost/graph/include/boost/pending/mutable_queue.hpp @@ -20,88 +20,97 @@ #include <boost/graph/detail/array_binary_tree.hpp> #include <iterator> -namespace boost { - - // The mutable queue whose elements are indexed - // - // This adaptor provides a special kind of priority queue that has - // and update operation. This allows the ordering of the items to - // change. After the ordering criteria for item x changes, one must - // call the Q.update(x) - // - // In order to efficiently find x in the queue, a functor must be - // provided to map value_type to a unique ID, which the - // mutable_queue will then use to map to the location of the - // item. The ID's generated must be between 0 and N, where N is the - // value passed to the constructor of mutable_queue - - template <class IndexedType, - class RandomAccessContainer = std::vector<IndexedType>, - class Comp = std::less<typename RandomAccessContainer::value_type>, - class ID = identity_property_map > - class mutable_queue { - public: +namespace boost +{ + +// The mutable queue whose elements are indexed +// +// This adaptor provides a special kind of priority queue that has +// and update operation. This allows the ordering of the items to +// change. After the ordering criteria for item x changes, one must +// call the Q.update(x) +// +// In order to efficiently find x in the queue, a functor must be +// provided to map value_type to a unique ID, which the +// mutable_queue will then use to map to the location of the +// item. The ID's generated must be between 0 and N, where N is the +// value passed to the constructor of mutable_queue + +template < class IndexedType, + class RandomAccessContainer = std::vector< IndexedType >, + class Comp = std::less< typename RandomAccessContainer::value_type >, + class ID = identity_property_map > +class mutable_queue +{ +public: typedef IndexedType value_type; typedef typename RandomAccessContainer::size_type size_type; - protected: + +protected: typedef typename RandomAccessContainer::iterator iterator; #if !defined BOOST_NO_STD_ITERATOR_TRAITS - typedef array_binary_tree_node<iterator, ID> Node; + typedef array_binary_tree_node< iterator, ID > Node; #else - typedef array_binary_tree_node<iterator, value_type, ID> Node; + typedef array_binary_tree_node< iterator, value_type, ID > Node; #endif - typedef compare_array_node<RandomAccessContainer,Comp> Compare; - typedef std::vector<size_type> IndexArray; - public: + typedef compare_array_node< RandomAccessContainer, Comp > Compare; + typedef std::vector< size_type > IndexArray; + +public: typedef Compare value_compare; typedef ID id_generator; mutable_queue(size_type n, const Comp& x, const ID& _id) - : index_array(n), comp(x), id(_id) { - c.reserve(n); + : index_array(n), comp(x), id(_id) + { + c.reserve(n); } - template <class ForwardIterator> - mutable_queue(ForwardIterator first, ForwardIterator last, - const Comp& x, const ID& _id) - : index_array(std::distance(first, last)), comp(x), id(_id) + template < class ForwardIterator > + mutable_queue(ForwardIterator first, ForwardIterator last, const Comp& x, + const ID& _id) + : index_array(std::distance(first, last)), comp(x), id(_id) { - while( first != last ) { - push(*first); - ++first; - } + while (first != last) + { + push(*first); + ++first; + } } bool empty() const { return c.empty(); } - void pop() { - value_type tmp = c.back(); - c.back() = c.front(); - c.front() = tmp; - - size_type id_f = get(id, c.back()); - size_type id_b = get(id, tmp); - size_type i = index_array[ id_b ]; - index_array[ id_b ] = index_array[ id_f ]; - index_array[ id_f ] = i; - - c.pop_back(); - Node node(c.begin(), c.end(), c.begin(), id); - down_heap(node, comp, index_array); + void pop() + { + value_type tmp = c.back(); + c.back() = c.front(); + c.front() = tmp; + + size_type id_f = get(id, c.back()); + size_type id_b = get(id, tmp); + size_type i = index_array[id_b]; + index_array[id_b] = index_array[id_f]; + index_array[id_f] = i; + + c.pop_back(); + Node node(c.begin(), c.end(), c.begin(), id); + down_heap(node, comp, index_array); } - void push(const IndexedType& x) { - c.push_back(x); - /*set index-array*/ - index_array[ get(id, x) ] = c.size()-1; - Node node(c.begin(), c.end(), c.end() - 1, id); - up_heap(node, comp, index_array); + void push(const IndexedType& x) + { + c.push_back(x); + /*set index-array*/ + index_array[get(id, x)] = c.size() - 1; + Node node(c.begin(), c.end(), c.end() - 1, id); + up_heap(node, comp, index_array); } - void update(const IndexedType& x) { - size_type current_pos = index_array[ get(id, x) ]; - c[current_pos] = x; + void update(const IndexedType& x) + { + size_type current_pos = index_array[get(id, x)]; + c[current_pos] = x; - Node node(c.begin(), c.end(), c.begin()+current_pos, id); - update_heap(node, comp, index_array); + Node node(c.begin(), c.end(), c.begin() + current_pos, id); + update_heap(node, comp, index_array); } value_type& front() { return c.front(); } @@ -122,13 +131,12 @@ namespace boost { } #endif - protected: +protected: IndexArray index_array; Compare comp; RandomAccessContainer c; ID id; - }; - +}; } diff --git a/contrib/restricted/boost/graph/include/boost/pending/property.hpp b/contrib/restricted/boost/graph/include/boost/pending/property.hpp index e63a2d203f..8e98e84eac 100644 --- a/contrib/restricted/boost/graph/include/boost/pending/property.hpp +++ b/contrib/restricted/boost/graph/include/boost/pending/property.hpp @@ -13,256 +13,365 @@ #include <boost/type_traits.hpp> #include <boost/static_assert.hpp> -namespace boost { +namespace boost +{ - struct no_property {}; +struct no_property +{ +}; - template <class Tag, class T, class Base = no_property> - struct property { +template < class Tag, class T, class Base = no_property > struct property +{ typedef Base next_type; typedef Tag tag_type; typedef T value_type; - property(const T& v = T()) : m_value(v) { } - property(const T& v, const Base& b) : m_value(v), m_base(b) { } + property(const T& v = T()) : m_value(v) {} + property(const T& v, const Base& b) : m_value(v), m_base(b) {} // copy constructor and assignment operator will be generated by compiler T m_value; Base m_base; - }; +}; - // Kinds of properties - namespace graph_introspect_detail { +// Kinds of properties +namespace graph_introspect_detail +{ BOOST_MPL_HAS_XXX_TRAIT_DEF(kind) - template <typename T, bool Cond> struct get_kind {typedef void type;}; - template <typename T> struct get_kind<T, true> {typedef typename T::kind type;}; - } - - // Having a default is to make this trait work for any type, not just valid - // properties, to work around VC++ <= 10 bugs related to SFINAE in - // compressed_sparse_row_graph's get functions and similar - template <class PropertyTag> - struct property_kind: - graph_introspect_detail::get_kind<PropertyTag, graph_introspect_detail::has_kind<PropertyTag>::value> - {}; - - // Some standard properties defined independently of Boost.Graph: - enum vertex_all_t {vertex_all}; - enum edge_all_t {edge_all}; - enum graph_all_t {graph_all}; - enum vertex_bundle_t {vertex_bundle}; - enum edge_bundle_t {edge_bundle}; - enum graph_bundle_t {graph_bundle}; - - // Code to look up one property in a property list: - template <typename PList, typename PropName, typename Enable = void> - struct lookup_one_property_internal {BOOST_STATIC_CONSTANT(bool, found = false); typedef void type;}; - - // Special-case properties (vertex_all, edge_all, graph_all) -#define BGL_ALL_PROP(tag) \ - template <typename T> \ - struct lookup_one_property_internal<T, tag> { \ - BOOST_STATIC_CONSTANT(bool, found = true); \ - typedef T type; \ - static T& lookup(T& x, tag) {return x;} \ - static const T& lookup(const T& x, tag) {return x;} \ - }; \ - template <typename Tag, typename T, typename Base> \ - struct lookup_one_property_internal<property<Tag, T, Base>, tag> { /* Avoid ambiguity */ \ - BOOST_STATIC_CONSTANT(bool, found = true); \ - typedef property<Tag, T, Base> type; \ - static type& lookup(type& x, tag) {return x;} \ - static const type& lookup(const type& x, tag) {return x;} \ - }; - - BGL_ALL_PROP(vertex_all_t) - BGL_ALL_PROP(edge_all_t) - BGL_ALL_PROP(graph_all_t) + template < typename T, bool Cond > struct get_kind + { + typedef void type; + }; + template < typename T > struct get_kind< T, true > + { + typedef typename T::kind type; + }; +} + +// Having a default is to make this trait work for any type, not just valid +// properties, to work around VC++ <= 10 bugs related to SFINAE in +// compressed_sparse_row_graph's get functions and similar +template < class PropertyTag > +struct property_kind +: graph_introspect_detail::get_kind< PropertyTag, + graph_introspect_detail::has_kind< PropertyTag >::value > +{ +}; + +// Some standard properties defined independently of Boost.Graph: +enum vertex_all_t +{ + vertex_all +}; +enum edge_all_t +{ + edge_all +}; +enum graph_all_t +{ + graph_all +}; +enum vertex_bundle_t +{ + vertex_bundle +}; +enum edge_bundle_t +{ + edge_bundle +}; +enum graph_bundle_t +{ + graph_bundle +}; + +// Code to look up one property in a property list: +template < typename PList, typename PropName, typename Enable = void > +struct lookup_one_property_internal +{ + BOOST_STATIC_CONSTANT(bool, found = false); + typedef void type; +}; + +// Special-case properties (vertex_all, edge_all, graph_all) +#define BGL_ALL_PROP(tag) \ + template < typename T > struct lookup_one_property_internal< T, tag > \ + { \ + BOOST_STATIC_CONSTANT(bool, found = true); \ + typedef T type; \ + static T& lookup(T& x, tag) { return x; } \ + static const T& lookup(const T& x, tag) { return x; } \ + }; \ + template < typename Tag, typename T, typename Base > \ + struct lookup_one_property_internal< property< Tag, T, Base >, tag > \ + { /* Avoid ambiguity */ \ + BOOST_STATIC_CONSTANT(bool, found = true); \ + typedef property< Tag, T, Base > type; \ + static type& lookup(type& x, tag) { return x; } \ + static const type& lookup(const type& x, tag) { return x; } \ + }; + +BGL_ALL_PROP(vertex_all_t) +BGL_ALL_PROP(edge_all_t) +BGL_ALL_PROP(graph_all_t) #undef BGL_ALL_PROP - // *_bundled; these need to be macros rather than inheritance to resolve ambiguities - #define BGL_DO_ONE_BUNDLE_TYPE(kind) \ - template <typename T> \ - struct lookup_one_property_internal<T, BOOST_JOIN(kind, _bundle_t)> { \ - BOOST_STATIC_CONSTANT(bool, found = true); \ - typedef T type; \ - static T& lookup(T& x, BOOST_JOIN(kind, _bundle_t)) {return x;} \ - static const T& lookup(const T& x, BOOST_JOIN(kind, _bundle_t)) {return x;} \ - }; \ - \ - template <typename Tag, typename T, typename Base> \ - struct lookup_one_property_internal<property<Tag, T, Base>, BOOST_JOIN(kind, _bundle_t)>: lookup_one_property_internal<Base, BOOST_JOIN(kind, _bundle_t)> { \ - private: \ - typedef lookup_one_property_internal<Base, BOOST_JOIN(kind, _bundle_t)> base_type; \ - public: \ - template <typename BundleTag> \ - static typename lazy_enable_if_c<(base_type::found && (is_same<BundleTag, BOOST_JOIN(kind, _bundle_t)>::value)), \ - add_reference<typename base_type::type> >::type \ - lookup(property<Tag, T, Base>& p, BundleTag) {return base_type::lookup(p.m_base, BOOST_JOIN(kind, _bundle_t)());} \ - template <typename BundleTag> \ - static typename lazy_enable_if_c<(base_type::found && (is_same<BundleTag, BOOST_JOIN(kind, _bundle_t)>::value)), \ - add_reference<const typename base_type::type> >::type \ - lookup(const property<Tag, T, Base>& p, BundleTag) {return base_type::lookup(p.m_base, BOOST_JOIN(kind, _bundle_t)());} \ - }; \ - - BGL_DO_ONE_BUNDLE_TYPE(vertex) - BGL_DO_ONE_BUNDLE_TYPE(edge) - BGL_DO_ONE_BUNDLE_TYPE(graph) +// *_bundled; these need to be macros rather than inheritance to resolve +// ambiguities +#define BGL_DO_ONE_BUNDLE_TYPE(kind) \ + template < typename T > \ + struct lookup_one_property_internal< T, BOOST_JOIN(kind, _bundle_t) > \ + { \ + BOOST_STATIC_CONSTANT(bool, found = true); \ + typedef T type; \ + static T& lookup(T& x, BOOST_JOIN(kind, _bundle_t)) { return x; } \ + static const T& lookup(const T& x, BOOST_JOIN(kind, _bundle_t)) \ + { \ + return x; \ + } \ + }; \ + \ + template < typename Tag, typename T, typename Base > \ + struct lookup_one_property_internal< property< Tag, T, Base >, \ + BOOST_JOIN(kind, _bundle_t) > \ + : lookup_one_property_internal< Base, BOOST_JOIN(kind, _bundle_t) > \ + { \ + private: \ + typedef lookup_one_property_internal< Base, \ + BOOST_JOIN(kind, _bundle_t) > \ + base_type; \ + \ + public: \ + template < typename BundleTag > \ + static typename lazy_enable_if_c< \ + (base_type::found \ + && (is_same< BundleTag, \ + BOOST_JOIN(kind, _bundle_t) >::value)), \ + add_reference< typename base_type::type > >::type \ + lookup(property< Tag, T, Base >& p, BundleTag) \ + { \ + return base_type::lookup(p.m_base, BOOST_JOIN(kind, _bundle_t)()); \ + } \ + template < typename BundleTag > \ + static typename lazy_enable_if_c< \ + (base_type::found \ + && (is_same< BundleTag, \ + BOOST_JOIN(kind, _bundle_t) >::value)), \ + add_reference< const typename base_type::type > >::type \ + lookup(const property< Tag, T, Base >& p, BundleTag) \ + { \ + return base_type::lookup(p.m_base, BOOST_JOIN(kind, _bundle_t)()); \ + } \ + }; + +BGL_DO_ONE_BUNDLE_TYPE(vertex) +BGL_DO_ONE_BUNDLE_TYPE(edge) +BGL_DO_ONE_BUNDLE_TYPE(graph) #undef BGL_DO_ONE_BUNDLE_TYPE - // Normal old-style properties; second case also handles chaining of bundled property accesses - template <typename Tag, typename T, typename Base> - struct lookup_one_property_internal<boost::property<Tag, T, Base>, Tag> { +// Normal old-style properties; second case also handles chaining of bundled +// property accesses +template < typename Tag, typename T, typename Base > +struct lookup_one_property_internal< boost::property< Tag, T, Base >, Tag > +{ BOOST_STATIC_CONSTANT(bool, found = true); - typedef property<Tag, T, Base> prop; + typedef property< Tag, T, Base > prop; typedef T type; - template <typename U> - static typename enable_if<is_same<prop, U>, T&>::type - lookup(U& prop, const Tag&) {return prop.m_value;} - template <typename U> - static typename enable_if<is_same<prop, U>, const T&>::type - lookup(const U& prop, const Tag&) {return prop.m_value;} - }; - - template <typename Tag, typename T, typename Base, typename PropName> - struct lookup_one_property_internal<boost::property<Tag, T, Base>, PropName>: lookup_one_property_internal<Base, PropName> { - private: - typedef lookup_one_property_internal<Base, PropName> base_type; - public: - template <typename PL> - static typename lazy_enable_if<is_same<PL, boost::property<Tag, T, Base> >, - add_reference<typename base_type::type> >::type - lookup(PL& prop, const PropName& tag) { - return base_type::lookup(prop.m_base, tag); + template < typename U > + static typename enable_if< is_same< prop, U >, T& >::type lookup( + U& prop, const Tag&) + { + return prop.m_value; + } + template < typename U > + static typename enable_if< is_same< prop, U >, const T& >::type lookup( + const U& prop, const Tag&) + { + return prop.m_value; } - template <typename PL> - static typename lazy_enable_if<is_same<PL, boost::property<Tag, T, Base> >, - add_reference<const typename base_type::type> >::type - lookup(const PL& prop, const PropName& tag) { - return base_type::lookup(prop.m_base, tag); +}; + +template < typename Tag, typename T, typename Base, typename PropName > +struct lookup_one_property_internal< boost::property< Tag, T, Base >, PropName > +: lookup_one_property_internal< Base, PropName > +{ +private: + typedef lookup_one_property_internal< Base, PropName > base_type; + +public: + template < typename PL > + static + typename lazy_enable_if< is_same< PL, boost::property< Tag, T, Base > >, + add_reference< typename base_type::type > >::type + lookup(PL& prop, const PropName& tag) + { + return base_type::lookup(prop.m_base, tag); } - }; + template < typename PL > + static + typename lazy_enable_if< is_same< PL, boost::property< Tag, T, Base > >, + add_reference< const typename base_type::type > >::type + lookup(const PL& prop, const PropName& tag) + { + return base_type::lookup(prop.m_base, tag); + } +}; - // Pointer-to-member access to bundled properties +// Pointer-to-member access to bundled properties #ifndef BOOST_GRAPH_NO_BUNDLED_PROPERTIES - template <typename T, typename TMaybeBase, typename R> - struct lookup_one_property_internal<T, R TMaybeBase::*, typename enable_if<is_base_of<TMaybeBase, T> >::type> { +template < typename T, typename TMaybeBase, typename R > +struct lookup_one_property_internal< T, R TMaybeBase::*, + typename enable_if< is_base_of< TMaybeBase, T > >::type > +{ BOOST_STATIC_CONSTANT(bool, found = true); typedef R type; - static R& lookup(T& x, R TMaybeBase::*ptr) {return x.*ptr;} - static const R& lookup(const T& x, R TMaybeBase::*ptr) {return x.*ptr;} - }; + static R& lookup(T& x, R TMaybeBase::*ptr) { return x.*ptr; } + static const R& lookup(const T& x, R TMaybeBase::*ptr) { return x.*ptr; } +}; #endif - // Version of above handling const property lists properly - template <typename T, typename Tag> - struct lookup_one_property: lookup_one_property_internal<T, Tag> {}; - - template <typename T, typename Tag> - struct lookup_one_property<const T, Tag> { - BOOST_STATIC_CONSTANT(bool, found = (lookup_one_property_internal<T, Tag>::found)); - typedef const typename lookup_one_property_internal<T, Tag>::type type; - template <typename U> - static typename lazy_enable_if<is_same<T, U>, - add_reference<const typename lookup_one_property_internal<T, Tag>::type> >::type - lookup(const U& p, Tag tag) { - return lookup_one_property_internal<T, Tag>::lookup(p, tag); +// Version of above handling const property lists properly +template < typename T, typename Tag > +struct lookup_one_property : lookup_one_property_internal< T, Tag > +{ +}; + +template < typename T, typename Tag > struct lookup_one_property< const T, Tag > +{ + BOOST_STATIC_CONSTANT( + bool, found = (lookup_one_property_internal< T, Tag >::found)); + typedef const typename lookup_one_property_internal< T, Tag >::type type; + template < typename U > + static typename lazy_enable_if< is_same< T, U >, + add_reference< const typename lookup_one_property_internal< T, + Tag >::type > >::type + lookup(const U& p, Tag tag) + { + return lookup_one_property_internal< T, Tag >::lookup(p, tag); } - }; +}; - // The BGL properties specialize property_kind and - // property_num, and use enum's for the Property type (see - // graph/properties.hpp), but the user may want to use a class - // instead with a nested kind type and num. Also, we may want to - // switch BGL back to using class types for properties at some point. +// The BGL properties specialize property_kind and +// property_num, and use enum's for the Property type (see +// graph/properties.hpp), but the user may want to use a class +// instead with a nested kind type and num. Also, we may want to +// switch BGL back to using class types for properties at some point. - template <class P> - struct has_property : boost::mpl::true_ {}; - template <> - struct has_property<no_property> : boost::mpl::false_ {}; +template < class P > struct has_property : boost::mpl::true_ +{ +}; +template <> struct has_property< no_property > : boost::mpl::false_ +{ +}; } // namespace boost #include <boost/pending/detail/property.hpp> -namespace boost { +namespace boost +{ - template <class PropertyList, class Tag> - struct property_value: lookup_one_property<PropertyList, Tag> {}; +template < class PropertyList, class Tag > +struct property_value : lookup_one_property< PropertyList, Tag > +{ +}; - template <class PropertyList, class Tag> - inline typename lookup_one_property<PropertyList, Tag>::type& - get_property_value(PropertyList& p, Tag tag) { - return lookup_one_property<PropertyList, Tag>::lookup(p, tag); - } +template < class PropertyList, class Tag > +inline typename lookup_one_property< PropertyList, Tag >::type& +get_property_value(PropertyList& p, Tag tag) +{ + return lookup_one_property< PropertyList, Tag >::lookup(p, tag); +} - template <class PropertyList, class Tag> - inline const typename lookup_one_property<PropertyList, Tag>::type& - get_property_value(const PropertyList& p, Tag tag) { - return lookup_one_property<PropertyList, Tag>::lookup(p, tag); - } +template < class PropertyList, class Tag > +inline const typename lookup_one_property< PropertyList, Tag >::type& +get_property_value(const PropertyList& p, Tag tag) +{ + return lookup_one_property< PropertyList, Tag >::lookup(p, tag); +} - namespace detail { +namespace detail +{ - /** This trait returns true if T is no_property. */ - template <typename T> - struct is_no_property - : mpl::bool_<is_same<T, no_property>::value> - { }; + /** This trait returns true if T is no_property. */ + template < typename T > + struct is_no_property : mpl::bool_< is_same< T, no_property >::value > + { + }; - template <typename PList, typename Tag> - class lookup_one_property_f; + template < typename PList, typename Tag > class lookup_one_property_f; - template <typename PList, typename Tag, typename F> struct lookup_one_property_f_result; + template < typename PList, typename Tag, typename F > + struct lookup_one_property_f_result; - template <typename PList, typename Tag> - struct lookup_one_property_f_result<PList, Tag, const lookup_one_property_f<PList, Tag>(PList)> { - typedef typename lookup_one_property<PList, Tag>::type type; + template < typename PList, typename Tag > + struct lookup_one_property_f_result< PList, Tag, + const lookup_one_property_f< PList, Tag >(PList) > + { + typedef typename lookup_one_property< PList, Tag >::type type; }; - template <typename PList, typename Tag> - struct lookup_one_property_f_result<PList, Tag, const lookup_one_property_f<PList, Tag>(PList&)> { - typedef typename lookup_one_property<PList, Tag>::type& type; + template < typename PList, typename Tag > + struct lookup_one_property_f_result< PList, Tag, + const lookup_one_property_f< PList, Tag >(PList&) > + { + typedef typename lookup_one_property< PList, Tag >::type& type; }; - template <typename PList, typename Tag> - struct lookup_one_property_f_result<PList, Tag, const lookup_one_property_f<PList, Tag>(const PList&)> { - typedef const typename lookup_one_property<PList, Tag>::type& type; + template < typename PList, typename Tag > + struct lookup_one_property_f_result< PList, Tag, + const lookup_one_property_f< PList, Tag >(const PList&) > + { + typedef const typename lookup_one_property< PList, Tag >::type& type; }; - template <typename PList, typename Tag> - class lookup_one_property_f { - Tag tag; - public: - lookup_one_property_f(Tag tag): tag(tag) {} - template <typename F> struct result: lookup_one_property_f_result<PList, Tag, F> {}; - - typename lookup_one_property_f_result<PList, Tag, const lookup_one_property_f(PList&)>::type - operator()(PList& pl) const { - return lookup_one_property<PList, Tag>::lookup(pl, tag); - } + template < typename PList, typename Tag > class lookup_one_property_f + { + Tag tag; + + public: + lookup_one_property_f(Tag tag) : tag(tag) {} + template < typename F > + struct result : lookup_one_property_f_result< PList, Tag, F > + { + }; + + typename lookup_one_property_f_result< PList, Tag, + const lookup_one_property_f(PList&) >::type + operator()(PList& pl) const + { + return lookup_one_property< PList, Tag >::lookup(pl, tag); + } }; } // namespace detail -namespace detail { - // Stuff for directed_graph and undirected_graph to skip over their first - // vertex_index and edge_index properties when providing vertex_all and - // edge_all; make sure you know the exact structure of your properties if you - // use there. - struct remove_first_property { - template <typename F> - struct result { - typedef typename boost::function_traits<F>::arg1_type a1; - typedef typename boost::remove_reference<a1>::type non_ref; - typedef typename non_ref::next_type nx; - typedef typename boost::mpl::if_<boost::is_const<non_ref>, boost::add_const<nx>, nx>::type with_const; - typedef typename boost::add_reference<with_const>::type type; +namespace detail +{ + // Stuff for directed_graph and undirected_graph to skip over their first + // vertex_index and edge_index properties when providing vertex_all and + // edge_all; make sure you know the exact structure of your properties if + // you use there. + struct remove_first_property + { + template < typename F > struct result + { + typedef typename boost::function_traits< F >::arg1_type a1; + typedef typename boost::remove_reference< a1 >::type non_ref; + typedef typename non_ref::next_type nx; + typedef typename boost::mpl::if_< boost::is_const< non_ref >, + boost::add_const< nx >, nx >::type with_const; + typedef typename boost::add_reference< with_const >::type type; + }; + template < typename Prop > + typename Prop::next_type& operator()(Prop& p) const + { + return p.m_base; + } + template < typename Prop > + const typename Prop::next_type& operator()(const Prop& p) const + { + return p.m_base; + } }; - template <typename Prop> - typename Prop::next_type& operator()(Prop& p) const {return p.m_base;} - template <typename Prop> - const typename Prop::next_type& operator()(const Prop& p) const {return p.m_base;} - }; } } // namesapce boost diff --git a/contrib/restricted/boost/graph/include/boost/pending/queue.hpp b/contrib/restricted/boost/graph/include/boost/pending/queue.hpp index f5f5b6336e..bf4879b868 100644 --- a/contrib/restricted/boost/graph/include/boost/pending/queue.hpp +++ b/contrib/restricted/boost/graph/include/boost/pending/queue.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Jeremy Siek 2004 +// (C) Copyright Jeremy Siek 2004 // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) @@ -9,109 +9,109 @@ #include <deque> #include <algorithm> -namespace boost { - -template <class _Tp, - class _Sequence = std::deque<_Tp> > -class queue; +namespace boost +{ -template <class _Tp, class _Seq> -inline bool operator==(const queue<_Tp, _Seq>&, const queue<_Tp, _Seq>&); +template < class _Tp, class _Sequence = std::deque< _Tp > > class queue; -template <class _Tp, class _Seq> -inline bool operator<(const queue<_Tp, _Seq>&, const queue<_Tp, _Seq>&); +template < class _Tp, class _Seq > +inline bool operator==(const queue< _Tp, _Seq >&, const queue< _Tp, _Seq >&); +template < class _Tp, class _Seq > +inline bool operator<(const queue< _Tp, _Seq >&, const queue< _Tp, _Seq >&); -template <class _Tp, class _Sequence> -class queue { +template < class _Tp, class _Sequence > class queue +{ #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS - template <class _Tp1, class _Seq1> - friend bool operator== (const queue<_Tp1, _Seq1>&, - const queue<_Tp1, _Seq1>&); - template <class _Tp1, class _Seq1> - friend bool operator< (const queue<_Tp1, _Seq1>&, - const queue<_Tp1, _Seq1>&); + template < class _Tp1, class _Seq1 > + friend bool operator==( + const queue< _Tp1, _Seq1 >&, const queue< _Tp1, _Seq1 >&); + template < class _Tp1, class _Seq1 > + friend bool operator<( + const queue< _Tp1, _Seq1 >&, const queue< _Tp1, _Seq1 >&); #endif public: - typedef typename _Sequence::value_type value_type; - typedef typename _Sequence::size_type size_type; - typedef _Sequence container_type; + typedef typename _Sequence::value_type value_type; + typedef typename _Sequence::size_type size_type; + typedef _Sequence container_type; - typedef typename _Sequence::reference reference; - typedef typename _Sequence::const_reference const_reference; + typedef typename _Sequence::reference reference; + typedef typename _Sequence::const_reference const_reference; #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS protected: #endif - _Sequence c; + _Sequence c; + public: - queue() : c() {} - explicit queue(const _Sequence& __c) : c(__c) {} - - bool empty() const { return c.empty(); } - size_type size() const { return c.size(); } - reference front() { return c.front(); } - const_reference front() const { return c.front(); } - reference top() { return c.front(); } - const_reference top() const { return c.front(); } - reference back() { return c.back(); } - const_reference back() const { return c.back(); } - void push(const value_type& __x) { c.push_back(__x); } - void pop() { c.pop_front(); } - - void swap(queue& other) - { - using std::swap; - swap(c, other.c); - } + queue() : c() {} + explicit queue(const _Sequence& __c) : c(__c) {} + + bool empty() const { return c.empty(); } + size_type size() const { return c.size(); } + reference front() { return c.front(); } + const_reference front() const { return c.front(); } + reference top() { return c.front(); } + const_reference top() const { return c.front(); } + reference back() { return c.back(); } + const_reference back() const { return c.back(); } + void push(const value_type& __x) { c.push_back(__x); } + void pop() { c.pop_front(); } + + void swap(queue& other) + { + using std::swap; + swap(c, other.c); + } }; -template <class _Tp, class _Sequence> -bool -operator==(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y) +template < class _Tp, class _Sequence > +bool operator==( + const queue< _Tp, _Sequence >& __x, const queue< _Tp, _Sequence >& __y) { - return __x.c == __y.c; + return __x.c == __y.c; } -template <class _Tp, class _Sequence> -bool -operator<(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y) +template < class _Tp, class _Sequence > +bool operator<( + const queue< _Tp, _Sequence >& __x, const queue< _Tp, _Sequence >& __y) { - return __x.c < __y.c; + return __x.c < __y.c; } -template <class _Tp, class _Sequence> -bool -operator!=(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y) +template < class _Tp, class _Sequence > +bool operator!=( + const queue< _Tp, _Sequence >& __x, const queue< _Tp, _Sequence >& __y) { - return !(__x == __y); + return !(__x == __y); } -template <class _Tp, class _Sequence> -bool -operator>(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y) +template < class _Tp, class _Sequence > +bool operator>( + const queue< _Tp, _Sequence >& __x, const queue< _Tp, _Sequence >& __y) { - return __y < __x; + return __y < __x; } -template <class _Tp, class _Sequence> -bool -operator<=(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y) +template < class _Tp, class _Sequence > +bool operator<=( + const queue< _Tp, _Sequence >& __x, const queue< _Tp, _Sequence >& __y) { - return !(__y < __x); + return !(__y < __x); } -template <class _Tp, class _Sequence> -bool -operator>=(const queue<_Tp, _Sequence>& __x, const queue<_Tp, _Sequence>& __y) +template < class _Tp, class _Sequence > +bool operator>=( + const queue< _Tp, _Sequence >& __x, const queue< _Tp, _Sequence >& __y) { - return !(__x < __y); + return !(__x < __y); } -template <class _Tp, class _Sequence> -inline void -swap(queue<_Tp, _Sequence>& __x, queue<_Tp, _Sequence>& __y) -{ __x.swap(__y); } +template < class _Tp, class _Sequence > +inline void swap(queue< _Tp, _Sequence >& __x, queue< _Tp, _Sequence >& __y) +{ + __x.swap(__y); +} } /* namespace boost */ diff --git a/contrib/restricted/boost/graph/include/boost/pending/relaxed_heap.hpp b/contrib/restricted/boost/graph/include/boost/pending/relaxed_heap.hpp deleted file mode 100644 index 1c80df6942..0000000000 --- a/contrib/restricted/boost/graph/include/boost/pending/relaxed_heap.hpp +++ /dev/null @@ -1,647 +0,0 @@ -// Copyright 2004 The Trustees of Indiana University. - -// Use, modification and distribution is subject to the Boost Software -// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#ifndef BOOST_RELAXED_HEAP_HEADER -#define BOOST_RELAXED_HEAP_HEADER - -#include <functional> -#include <boost/property_map/property_map.hpp> -#include <boost/optional.hpp> -#include <vector> -#include <climits> // for CHAR_BIT -#include <boost/none.hpp> - -#ifdef BOOST_RELAXED_HEAP_DEBUG -# include <iostream> -#endif // BOOST_RELAXED_HEAP_DEBUG - -#if defined(BOOST_MSVC) -# pragma warning(push) -# pragma warning(disable:4355) // complaint about using 'this' to -#endif // initialize a member - -namespace boost { - -template<typename IndexedType, - typename Compare = std::less<IndexedType>, - typename ID = identity_property_map> -class relaxed_heap -{ - struct group; - - typedef relaxed_heap self_type; - typedef std::size_t rank_type; - -public: - typedef IndexedType value_type; - typedef rank_type size_type; - -private: - /** - * The kind of key that a group has. The actual values are discussed - * in-depth in the documentation of the @c kind field of the @c group - * structure. Note that the order of the enumerators *IS* important - * and must not be changed. - */ - enum group_key_kind { smallest_key, stored_key, largest_key }; - - struct group { - explicit group(group_key_kind kind = largest_key) - : kind(kind), parent(this), rank(0) { } - - /** The value associated with this group. This value is only valid - * when @c kind!=largest_key (which indicates a deleted - * element). Note that the use of boost::optional increases the - * memory requirements slightly but does not result in extraneous - * memory allocations or deallocations. The optional could be - * eliminated when @c value_type is a model of - * DefaultConstructible. - */ - ::boost::optional<value_type> value; - - /** - * The kind of key stored at this group. This may be @c - * smallest_key, which indicates that the key is infinitely small; - * @c largest_key, which indicates that the key is infinitely - * large; or @c stored_key, which means that the key is unknown, - * but its relationship to other keys can be determined via the - * comparison function object. - */ - group_key_kind kind; - - /// The parent of this group. Will only be NULL for the dummy root group - group* parent; - - /// The rank of this group. Equivalent to the number of children in - /// the group. - rank_type rank; - - /** The children of this group. For the dummy root group, these are - * the roots. This is an array of length log n containing pointers - * to the child groups. - */ - group** children; - }; - - size_type log_base_2(size_type n) // log2 is a macro on some platforms - { - size_type leading_zeroes = 0; - do { - size_type next = n << 1; - if (n == (next >> 1)) { - ++leading_zeroes; - n = next; - } else { - break; - } - } while (true); - return sizeof(size_type) * CHAR_BIT - leading_zeroes - 1; - } - -public: - relaxed_heap(size_type n, const Compare& compare = Compare(), - const ID& id = ID()) - : compare(compare), id(id), root(smallest_key), groups(n), - smallest_value(0) - { - if (n == 0) { - root.children = new group*[1]; - return; - } - - log_n = log_base_2(n); - if (log_n == 0) log_n = 1; - size_type g = n / log_n; - if (n % log_n > 0) ++g; - size_type log_g = log_base_2(g); - size_type r = log_g; - - // Reserve an appropriate amount of space for data structures, so - // that we do not need to expand them. - index_to_group.resize(g); - A.resize(r + 1, 0); - root.rank = r + 1; - root.children = new group*[(log_g + 1) * (g + 1)]; - for (rank_type i = 0; i < r+1; ++i) root.children[i] = 0; - - // Build initial heap - size_type idx = 0; - while (idx < g) { - root.children[r] = &index_to_group[idx]; - idx = build_tree(root, idx, r, log_g + 1); - if (idx != g) - r = static_cast<size_type>(log_base_2(g-idx)); - } - } - - ~relaxed_heap() { delete [] root.children; } - - void push(const value_type& x) - { - groups[get(id, x)] = x; - update(x); - } - - void update(const value_type& x) - { - group* a = &index_to_group[get(id, x) / log_n]; - if (!a->value - || *a->value == x - || compare(x, *a->value)) { - if (a != smallest_value) smallest_value = 0; - a->kind = stored_key; - a->value = x; - promote(a); - } - } - - void remove(const value_type& x) - { - group* a = &index_to_group[get(id, x) / log_n]; - assert(groups[get(id, x)]); - a->value = x; - a->kind = smallest_key; - promote(a); - smallest_value = a; - pop(); - } - - value_type& top() - { - find_smallest(); - assert(smallest_value->value != none); - return *smallest_value->value; - } - - const value_type& top() const - { - find_smallest(); - assert(smallest_value->value != none); - return *smallest_value->value; - } - - bool empty() const - { - find_smallest(); - return !smallest_value || (smallest_value->kind == largest_key); - } - - bool contains(const value_type& x) const { - return static_cast<bool>(groups[get(id, x)]); - } - - - void pop() - { - // Fill in smallest_value. This is the group x. - find_smallest(); - group* x = smallest_value; - smallest_value = 0; - - // Make x a leaf, giving it the smallest value within its group - rank_type r = x->rank; - group* p = x->parent; - { - assert(x->value != none); - - // Find x's group - size_type start = get(id, *x->value) - get(id, *x->value) % log_n; - size_type end = start + log_n; - if (end > groups.size()) end = groups.size(); - - // Remove the smallest value from the group, and find the new - // smallest value. - groups[get(id, *x->value)].reset(); - x->value.reset(); - x->kind = largest_key; - for (size_type i = start; i < end; ++i) { - if (groups[i] && (!x->value || compare(*groups[i], *x->value))) { - x->kind = stored_key; - x->value = groups[i]; - } - } - } - x->rank = 0; - - // Combine prior children of x with x - group* y = x; - for (size_type c = 0; c < r; ++c) { - group* child = x->children[c]; - if (A[c] == child) A[c] = 0; - y = combine(y, child); - } - - // If we got back something other than x, let y take x's place - if (y != x) { - y->parent = p; - p->children[r] = y; - - assert(r == y->rank); - if (A[y->rank] == x) - A[y->rank] = do_compare(y, p)? y : 0; - } - } - -#ifdef BOOST_RELAXED_HEAP_DEBUG - /************************************************************************* - * Debugging support * - *************************************************************************/ - void dump_tree() { dump_tree(std::cout); } - void dump_tree(std::ostream& out) { dump_tree(out, &root); } - - void dump_tree(std::ostream& out, group* p, bool in_progress = false) - { - if (!in_progress) { - out << "digraph heap {\n" - << " edge[dir=\"back\"];\n"; - } - - size_type p_index = 0; - if (p != &root) while (&index_to_group[p_index] != p) ++p_index; - - for (size_type i = 0; i < p->rank; ++i) { - group* c = p->children[i]; - if (c) { - size_type c_index = 0; - if (c != &root) while (&index_to_group[c_index] != c) ++c_index; - - out << " "; - if (p == &root) out << 'p'; else out << p_index; - out << " -> "; - if (c == &root) out << 'p'; else out << c_index; - if (A[c->rank] == c) out << " [style=\"dotted\"]"; - out << ";\n"; - dump_tree(out, c, true); - - // Emit node information - out << " "; - if (c == &root) out << 'p'; else out << c_index; - out << " [label=\""; - if (c == &root) out << 'p'; else out << c_index; - out << ":"; - size_type start = c_index * log_n; - size_type end = start + log_n; - if (end > groups.size()) end = groups.size(); - while (start != end) { - if (groups[start]) { - out << " " << get(id, *groups[start]); - if (*groups[start] == *c->value) out << "(*)"; - } - ++start; - } - out << '"'; - - if (do_compare(c, p)) { - out << " "; - if (c == &root) out << 'p'; else out << c_index; - out << ", style=\"filled\", fillcolor=\"gray\""; - } - out << "];\n"; - } else { - assert(p->parent == p); - } - } - if (!in_progress) out << "}\n"; - } - - bool valid() - { - // Check that the ranks in the A array match the ranks of the - // groups stored there. Also, the active groups must be the last - // child of their parent. - for (size_type r = 0; r < A.size(); ++r) { - if (A[r] && A[r]->rank != r) return false; - - if (A[r] && A[r]->parent->children[A[r]->parent->rank-1] != A[r]) - return false; - } - - // The root must have no value and a key of -Infinity - if (root.kind != smallest_key) return false; - - return valid(&root); - } - - bool valid(group* p) - { - for (size_type i = 0; i < p->rank; ++i) { - group* c = p->children[i]; - if (c) { - // Check link structure - if (c->parent != p) return false; - if (c->rank != i) return false; - - // A bad group must be active - if (do_compare(c, p) && A[i] != c) return false; - - // Check recursively - if (!valid(c)) return false; - } else { - // Only the root may - if (p != &root) return false; - } - } - return true; - } - -#endif // BOOST_RELAXED_HEAP_DEBUG - -private: - size_type - build_tree(group& parent, size_type idx, size_type r, size_type max_rank) - { - group& this_group = index_to_group[idx]; - this_group.parent = &parent; - ++idx; - - this_group.children = root.children + (idx * max_rank); - this_group.rank = r; - for (size_type i = 0; i < r; ++i) { - this_group.children[i] = &index_to_group[idx]; - idx = build_tree(this_group, idx, i, max_rank); - } - return idx; - } - - void find_smallest() const - { - group** roots = root.children; - - if (!smallest_value) { - std::size_t i; - for (i = 0; i < root.rank; ++i) { - if (roots[i] && - (!smallest_value || do_compare(roots[i], smallest_value))) { - smallest_value = roots[i]; - } - } - for (i = 0; i < A.size(); ++i) { - if (A[i] && (!smallest_value || do_compare(A[i], smallest_value))) - smallest_value = A[i]; - } - } - } - - bool do_compare(group* x, group* y) const - { - return (x->kind < y->kind - || (x->kind == y->kind - && x->kind == stored_key - && compare(*x->value, *y->value))); - } - - void promote(group* a) - { - assert(a != 0); - rank_type r = a->rank; - group* p = a->parent; - assert(p != 0); - if (do_compare(a, p)) { - // s is the rank + 1 sibling - group* s = p->rank > r + 1? p->children[r + 1] : 0; - - // If a is the last child of p - if (r == p->rank - 1) { - if (!A[r]) A[r] = a; - else if (A[r] != a) pair_transform(a); - } else { - assert(s != 0); - if (A[r + 1] == s) active_sibling_transform(a, s); - else good_sibling_transform(a, s); - } - } - } - - group* combine(group* a1, group* a2) - { - assert(a1->rank == a2->rank); - if (do_compare(a2, a1)) do_swap(a1, a2); - a1->children[a1->rank++] = a2; - a2->parent = a1; - clean(a1); - return a1; - } - - void clean(group* q) - { - if (2 > q->rank) return; - group* qp = q->children[q->rank-1]; - rank_type s = q->rank - 2; - group* x = q->children[s]; - group* xp = qp->children[s]; - assert(s == x->rank); - - // If x is active, swap x and xp - if (A[s] == x) { - q->children[s] = xp; - xp->parent = q; - qp->children[s] = x; - x->parent = qp; - } - } - - void pair_transform(group* a) - { -#if defined(BOOST_RELAXED_HEAP_DEBUG) && BOOST_RELAXED_HEAP_DEBUG > 1 - std::cerr << "- pair transform\n"; -#endif - rank_type r = a->rank; - - // p is a's parent - group* p = a->parent; - assert(p != 0); - - // g is p's parent (a's grandparent) - group* g = p->parent; - assert(g != 0); - - // a' <- A(r) - assert(A[r] != 0); - group* ap = A[r]; - assert(ap != 0); - - // A(r) <- nil - A[r] = 0; - - // let a' have parent p' - group* pp = ap->parent; - assert(pp != 0); - - // let a' have grandparent g' - group* gp = pp->parent; - assert(gp != 0); - - // Remove a and a' from their parents - assert(ap == pp->children[pp->rank-1]); // Guaranteed because ap is active - --pp->rank; - - // Guaranteed by caller - assert(a == p->children[p->rank-1]); - --p->rank; - - // Note: a, ap, p, pp all have rank r - if (do_compare(pp, p)) { - do_swap(a, ap); - do_swap(p, pp); - do_swap(g, gp); - } - - // Assuming k(p) <= k(p') - // make p' the rank r child of p - assert(r == p->rank); - p->children[p->rank++] = pp; - pp->parent = p; - - // Combine a, ap into a rank r+1 group c - group* c = combine(a, ap); - - // make c the rank r+1 child of g' - assert(gp->rank > r+1); - gp->children[r+1] = c; - c->parent = gp; - -#if defined(BOOST_RELAXED_HEAP_DEBUG) && BOOST_RELAXED_HEAP_DEBUG > 1 - std::cerr << "After pair transform...\n"; - dump_tree(); -#endif - - if (A[r+1] == pp) A[r+1] = c; - else promote(c); - } - - void active_sibling_transform(group* a, group* s) - { -#if defined(BOOST_RELAXED_HEAP_DEBUG) && BOOST_RELAXED_HEAP_DEBUG > 1 - std::cerr << "- active sibling transform\n"; -#endif - group* p = a->parent; - group* g = p->parent; - - // remove a, s from their parents - assert(s->parent == p); - assert(p->children[p->rank-1] == s); - --p->rank; - assert(p->children[p->rank-1] == a); - --p->rank; - - rank_type r = a->rank; - A[r+1] = 0; - a = combine(p, a); - group* c = combine(a, s); - - // make c the rank r+2 child of g - assert(g->children[r+2] == p); - g->children[r+2] = c; - c->parent = g; - if (A[r+2] == p) A[r+2] = c; - else promote(c); - } - - void good_sibling_transform(group* a, group* s) - { -#if defined(BOOST_RELAXED_HEAP_DEBUG) && BOOST_RELAXED_HEAP_DEBUG > 1 - std::cerr << "- good sibling transform\n"; -#endif - rank_type r = a->rank; - group* c = s->children[s->rank-1]; - assert(c->rank == r); - if (A[r] == c) { -#if defined(BOOST_RELAXED_HEAP_DEBUG) && BOOST_RELAXED_HEAP_DEBUG > 1 - std::cerr << "- good sibling pair transform\n"; -#endif - A[r] = 0; - group* p = a->parent; - - // Remove c from its parent - --s->rank; - - // Make s the rank r child of p - s->parent = p; - p->children[r] = s; - - // combine a, c and let the result by the rank r+1 child of p - assert(p->rank > r+1); - group* x = combine(a, c); - x->parent = p; - p->children[r+1] = x; - - if (A[r+1] == s) A[r+1] = x; - else promote(x); - -#if defined(BOOST_RELAXED_HEAP_DEBUG) && BOOST_RELAXED_HEAP_DEBUG > 1 - dump_tree(std::cerr); -#endif - // pair_transform(a); - } else { - // Clean operation - group* p = a->parent; - s->children[r] = a; - a->parent = s; - p->children[r] = c; - c->parent = p; - - promote(a); - } - } - - static void do_swap(group*& x, group*& y) - { - group* tmp = x; - x = y; - y = tmp; - } - - /// Function object that compares two values in the heap - Compare compare; - - /// Mapping from values to indices in the range [0, n). - ID id; - - /** The root group of the queue. This group is special because it will - * never store a value, but it acts as a parent to all of the - * roots. Thus, its list of children is the list of roots. - */ - group root; - - /** Mapping from the group index of a value to the group associated - * with that value. If a value is not in the queue, then the "value" - * field will be empty. - */ - std::vector<group> index_to_group; - - /** Flat data structure containing the values in each of the - * groups. It will be indexed via the id of the values. The groups - * are each log_n long, with the last group potentially being - * smaller. - */ - std::vector< ::boost::optional<value_type> > groups; - - /** The list of active groups, indexed by rank. When A[r] is null, - * there is no active group of rank r. Otherwise, A[r] is the active - * group of rank r. - */ - std::vector<group*> A; - - /** The group containing the smallest value in the queue, which must - * be either a root or an active group. If this group is null, then we - * will need to search for this group when it is needed. - */ - mutable group* smallest_value; - - /// Cached value log_base_2(n) - size_type log_n; -}; - - -} // end namespace boost - -#if defined(BOOST_MSVC) -# pragma warning(pop) -#endif - -#endif // BOOST_RELAXED_HEAP_HEADER diff --git a/contrib/restricted/boost/graph/src/graphml.cpp b/contrib/restricted/boost/graph/src/graphml.cpp index 302d03a56d..af930fad9f 100644 --- a/contrib/restricted/boost/graph/src/graphml.cpp +++ b/contrib/restricted/boost/graph/src/graphml.cpp @@ -18,141 +18,196 @@ #include <boost/graph/dll_import_export.hpp> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/xml_parser.hpp> +#include <map> +#include <string> +#include <vector> using namespace boost; -namespace { +namespace +{ class graphml_reader { public: - graphml_reader(mutate_graph& g) - : m_g(g) { } + graphml_reader(mutate_graph& g) : m_g(g) {} - static boost::property_tree::ptree::path_type path(const std::string& str) { - return boost::property_tree::ptree::path_type(str, '/'); + static boost::property_tree::ptree::path_type path(const std::string& str) + { + return boost::property_tree::ptree::path_type(str, '/'); } void get_graphs(const boost::property_tree::ptree& top, - size_t desired_idx /* or -1 for all */, bool is_root, - std::vector<const boost::property_tree::ptree*>& result) { - using boost::property_tree::ptree; - size_t current_idx = 0; - bool is_first = is_root; - BOOST_FOREACH(const ptree::value_type& n, top) { - if (n.first == "graph") { - if (current_idx == desired_idx || desired_idx == (size_t)(-1)) { - result.push_back(&n.second); - if(is_first) + size_t desired_idx /* or -1 for all */, bool is_root, + std::vector< const boost::property_tree::ptree* >& result) + { + using boost::property_tree::ptree; + size_t current_idx = 0; + bool is_first = is_root; + BOOST_FOREACH (const ptree::value_type& n, top) + { + if (n.first == "graph") { - is_first = false; - BOOST_FOREACH(const ptree::value_type& attr, n.second) { - if (attr.first != "data") - continue; - std::string key = attr.second.get<std::string>(path("<xmlattr>/key")); - std::string value = attr.second.get_value(""); - handle_graph_property(key, value); - } + if (current_idx == desired_idx || desired_idx == (size_t)(-1)) + { + result.push_back(&n.second); + if (is_first) + { + is_first = false; + BOOST_FOREACH (const ptree::value_type& attr, n.second) + { + if (attr.first != "data") + continue; + std::string key = attr.second.get< std::string >( + path("<xmlattr>/key")); + std::string value = attr.second.get_value(""); + handle_graph_property(key, value); + } + } + + get_graphs(n.second, (size_t)(-1), false, result); + if (desired_idx != (size_t)(-1)) + break; + } + ++current_idx; } - - get_graphs(n.second, (size_t)(-1), false, result); - if (desired_idx != (size_t)(-1)) break; - } - ++current_idx; } - } } - + void run(std::istream& in, size_t desired_idx) { - using boost::property_tree::ptree; - ptree pt; - read_xml(in, pt, boost::property_tree::xml_parser::no_comments | boost::property_tree::xml_parser::trim_whitespace); - ptree gml = pt.get_child(path("graphml")); - // Search for attributes - BOOST_FOREACH(const ptree::value_type& child, gml) { - if (child.first != "key") continue; - std::string id = child.second.get(path("<xmlattr>/id"), ""); - std::string for_ = child.second.get(path("<xmlattr>/for"), ""); - std::string name = child.second.get(path("<xmlattr>/attr.name"), ""); - std::string type = child.second.get(path("<xmlattr>/attr.type"), ""); - key_kind kind = all_key; - if (for_ == "graph") kind = graph_key; - else if (for_ == "node") kind = node_key; - else if (for_ == "edge") kind = edge_key; - else if (for_ == "hyperedge") kind = hyperedge_key; - else if (for_ == "port") kind = port_key; - else if (for_ == "endpoint") kind = endpoint_key; - else if (for_ == "all") kind = all_key; - else if (for_ == "graphml") kind = graphml_key; - else {BOOST_THROW_EXCEPTION(parse_error("Attribute for is not valid: " + for_));} - m_keys[id] = kind; - m_key_name[id] = name; - m_key_type[id] = type; - boost::optional<std::string> default_ = child.second.get_optional<std::string>(path("default")); - if (default_) m_key_default[id] = default_.get(); - } - // Search for graphs - std::vector<const ptree*> graphs; - handle_graph(); - get_graphs(gml, desired_idx, true, graphs); - BOOST_FOREACH(const ptree* gr, graphs) { - // Search for nodes - BOOST_FOREACH(const ptree::value_type& node, *gr) { - if (node.first != "node") continue; - std::string id = node.second.get<std::string>(path("<xmlattr>/id")); - handle_vertex(id); - BOOST_FOREACH(const ptree::value_type& attr, node.second) { - if (attr.first != "data") continue; - std::string key = attr.second.get<std::string>(path("<xmlattr>/key")); - std::string value = attr.second.get_value(""); - handle_node_property(key, id, value); - } + using boost::property_tree::ptree; + ptree pt; + read_xml(in, pt, + boost::property_tree::xml_parser::no_comments + | boost::property_tree::xml_parser::trim_whitespace); + ptree gml = pt.get_child(path("graphml")); + // Search for attributes + BOOST_FOREACH (const ptree::value_type& child, gml) + { + if (child.first != "key") + continue; + std::string id = child.second.get(path("<xmlattr>/id"), ""); + std::string for_ = child.second.get(path("<xmlattr>/for"), ""); + std::string name + = child.second.get(path("<xmlattr>/attr.name"), ""); + std::string type + = child.second.get(path("<xmlattr>/attr.type"), ""); + key_kind kind = all_key; + if (for_ == "graph") + kind = graph_key; + else if (for_ == "node") + kind = node_key; + else if (for_ == "edge") + kind = edge_key; + else if (for_ == "hyperedge") + kind = hyperedge_key; + else if (for_ == "port") + kind = port_key; + else if (for_ == "endpoint") + kind = endpoint_key; + else if (for_ == "all") + kind = all_key; + else if (for_ == "graphml") + kind = graphml_key; + else + { + BOOST_THROW_EXCEPTION( + parse_error("Attribute for is not valid: " + for_)); + } + m_keys[id] = kind; + m_key_name[id] = name; + m_key_type[id] = type; + boost::optional< std::string > default_ + = child.second.get_optional< std::string >(path("default")); + if (default_) + m_key_default[id] = default_.get(); + } + // Search for graphs + std::vector< const ptree* > graphs; + handle_graph(); + get_graphs(gml, desired_idx, true, graphs); + BOOST_FOREACH (const ptree* gr, graphs) + { + // Search for nodes + BOOST_FOREACH (const ptree::value_type& node, *gr) + { + if (node.first != "node") + continue; + std::string id + = node.second.get< std::string >(path("<xmlattr>/id")); + handle_vertex(id); + BOOST_FOREACH (const ptree::value_type& attr, node.second) + { + if (attr.first != "data") + continue; + std::string key + = attr.second.get< std::string >(path("<xmlattr>/key")); + std::string value = attr.second.get_value(""); + handle_node_property(key, id, value); + } + } } - } - BOOST_FOREACH(const ptree* gr, graphs) { - bool default_directed = gr->get<std::string>(path("<xmlattr>/edgedefault")) == "directed"; - // Search for edges - BOOST_FOREACH(const ptree::value_type& edge, *gr) { - if (edge.first != "edge") continue; - std::string source = edge.second.get<std::string>(path("<xmlattr>/source")); - std::string target = edge.second.get<std::string>(path("<xmlattr>/target")); - std::string local_directed = edge.second.get(path("<xmlattr>/directed"), ""); - bool is_directed = (local_directed == "" ? default_directed : local_directed == "true"); - if (is_directed != m_g.is_directed()) { - if (is_directed) { - BOOST_THROW_EXCEPTION(directed_graph_error()); - } else { - BOOST_THROW_EXCEPTION(undirected_graph_error()); + BOOST_FOREACH (const ptree* gr, graphs) + { + bool default_directed + = gr->get< std::string >(path("<xmlattr>/edgedefault")) + == "directed"; + // Search for edges + BOOST_FOREACH (const ptree::value_type& edge, *gr) + { + if (edge.first != "edge") + continue; + std::string source + = edge.second.get< std::string >(path("<xmlattr>/source")); + std::string target + = edge.second.get< std::string >(path("<xmlattr>/target")); + std::string local_directed + = edge.second.get(path("<xmlattr>/directed"), ""); + bool is_directed + = (local_directed.empty() ? default_directed + : local_directed == "true"); + if (is_directed != m_g.is_directed()) + { + if (is_directed) + { + BOOST_THROW_EXCEPTION(directed_graph_error()); + } + else + { + BOOST_THROW_EXCEPTION(undirected_graph_error()); + } + } + size_t old_edges_size = m_edge.size(); + handle_edge(source, target); + BOOST_FOREACH (const ptree::value_type& attr, edge.second) + { + if (attr.first != "data") + continue; + std::string key + = attr.second.get< std::string >(path("<xmlattr>/key")); + std::string value = attr.second.get_value(""); + handle_edge_property(key, old_edges_size, value); + } } - } - size_t old_edges_size = m_edge.size(); - handle_edge(source, target); - BOOST_FOREACH(const ptree::value_type& attr, edge.second) { - if (attr.first != "data") continue; - std::string key = attr.second.get<std::string>(path("<xmlattr>/key")); - std::string value = attr.second.get_value(""); - handle_edge_property(key, old_edges_size, value); - } } - } } private: /// The kinds of keys. Not all of these are supported - enum key_kind { - graph_key, - node_key, + enum key_kind + { + graph_key, + node_key, edge_key, hyperedge_key, port_key, - endpoint_key, + endpoint_key, all_key, graphml_key }; - void - handle_vertex(const std::string& v) + void handle_vertex(const std::string& v) { bool is_new = false; @@ -164,8 +219,9 @@ private: if (is_new) { - std::map<std::string, std::string>::iterator iter; - for (iter = m_key_default.begin(); iter != m_key_default.end(); ++iter) + std::map< std::string, std::string >::iterator iter; + for (iter = m_key_default.begin(); iter != m_key_default.end(); + ++iter) { if (m_keys[iter->first] == node_key) handle_node_property(iter->first, v, iter->second); @@ -173,14 +229,9 @@ private: } } - any - get_vertex_descriptor(const std::string& v) - { - return m_vertex[v]; - } + any get_vertex_descriptor(const std::string& v) { return m_vertex[v]; } - void - handle_edge(const std::string& u, const std::string& v) + void handle_edge(const std::string& u, const std::string& v) { handle_vertex(u); handle_vertex(v); @@ -192,14 +243,15 @@ private: any edge; bool added; boost::tie(edge, added) = m_g.do_add_edge(source, target); - if (!added) { + if (!added) + { BOOST_THROW_EXCEPTION(bad_parallel_edge(u, v)); } size_t e = m_edge.size(); m_edge.push_back(edge); - - std::map<std::string, std::string>::iterator iter; + + std::map< std::string, std::string >::iterator iter; for (iter = m_key_default.begin(); iter != m_key_default.end(); ++iter) { if (m_keys[iter->first] == edge_key) @@ -207,48 +259,52 @@ private: } } - void - handle_graph() + void handle_graph() { - std::map<std::string, std::string>::iterator iter; - for (iter = m_key_default.begin(); iter != m_key_default.end(); ++iter) - { - if (m_keys[iter->first] == graph_key) - handle_graph_property(iter->first, iter->second); - } + std::map< std::string, std::string >::iterator iter; + for (iter = m_key_default.begin(); iter != m_key_default.end(); ++iter) + { + if (m_keys[iter->first] == graph_key) + handle_graph_property(iter->first, iter->second); + } } - void handle_graph_property(const std::string& key_id, const std::string& value) + void handle_graph_property( + const std::string& key_id, const std::string& value) { - m_g.set_graph_property(m_key_name[key_id], value, m_key_type[key_id]); + m_g.set_graph_property(m_key_name[key_id], value, m_key_type[key_id]); } - void handle_node_property(const std::string& key_id, const std::string& descriptor, const std::string& value) + void handle_node_property(const std::string& key_id, + const std::string& descriptor, const std::string& value) { - m_g.set_vertex_property(m_key_name[key_id], m_vertex[descriptor], value, m_key_type[key_id]); + m_g.set_vertex_property(m_key_name[key_id], m_vertex[descriptor], value, + m_key_type[key_id]); } - void handle_edge_property(const std::string& key_id, size_t descriptor, const std::string& value) + void handle_edge_property( + const std::string& key_id, size_t descriptor, const std::string& value) { - m_g.set_edge_property(m_key_name[key_id], m_edge[descriptor], value, m_key_type[key_id]); + m_g.set_edge_property( + m_key_name[key_id], m_edge[descriptor], value, m_key_type[key_id]); } mutate_graph& m_g; - std::map<std::string, key_kind> m_keys; - std::map<std::string, std::string> m_key_name; - std::map<std::string, std::string> m_key_type; - std::map<std::string, std::string> m_key_default; - std::map<std::string, any> m_vertex; - std::vector<any> m_edge; + std::map< std::string, key_kind > m_keys; + std::map< std::string, std::string > m_key_name; + std::map< std::string, std::string > m_key_type; + std::map< std::string, std::string > m_key_default; + std::map< std::string, any > m_vertex; + std::vector< any > m_edge; }; } namespace boost { -void BOOST_GRAPH_DECL -read_graphml(std::istream& in, mutate_graph& g, size_t desired_idx) -{ +void BOOST_GRAPH_DECL read_graphml( + std::istream& in, mutate_graph& g, size_t desired_idx) +{ graphml_reader reader(g); reader.run(in, desired_idx); } diff --git a/contrib/restricted/boost/graph/src/read_graphviz_new.cpp b/contrib/restricted/boost/graph/src/read_graphviz_new.cpp index 2881bb125d..ca68fc3c50 100644 --- a/contrib/restricted/boost/graph/src/read_graphviz_new.cpp +++ b/contrib/restricted/boost/graph/src/read_graphviz_new.cpp @@ -5,19 +5,19 @@ // http://www.boost.org/LICENSE_1_0.txt) // -// read_graphviz_new.cpp - +// read_graphviz_new.cpp - // Initialize a model of the BGL's MutableGraph concept and an associated // collection of property maps using a graph expressed in the GraphViz -// DOT Language. +// DOT Language. // // Based on the grammar found at: -// http://www.graphviz.org/cvs/doc/info/lang.html +// https://web.archive.org/web/20041213234742/http://www.graphviz.org/cvs/doc/info/lang.html // // Jeremiah rewrite used grammar found at: // http://www.graphviz.org/doc/info/lang.html // and page 34 or http://www.graphviz.org/pdf/dotguide.pdf // -// See documentation for this code at: +// See documentation for this code at: // http://www.boost.org/libs/graph/doc/read_graphviz.html // @@ -33,775 +33,1149 @@ #include <boost/graph/graph_traits.hpp> #include <boost/detail/workaround.hpp> #include <boost/algorithm/string/case_conv.hpp> +#include <cstdlib> #include <algorithm> #include <exception> // for std::exception +#include <iostream> +#include <map> +#include <set> #include <string> #include <vector> -#include <set> #include <utility> -#include <map> -#include <iostream> -#include <cstdlib> #include <boost/throw_exception.hpp> #include <boost/regex.hpp> #include <boost/function.hpp> -#include <boost/bind.hpp> #include <boost/graph/dll_import_export.hpp> #include <boost/graph/graphviz.hpp> -namespace boost { - -namespace read_graphviz_detail { - struct token { - enum token_type { - kw_strict, - kw_graph, - kw_digraph, - kw_node, - kw_edge, - kw_subgraph, - left_brace, - right_brace, - semicolon, - equal, - left_bracket, - right_bracket, - comma, - colon, - dash_greater, - dash_dash, - plus, - left_paren, - right_paren, - at, - identifier, - quoted_string, // Only used internally in tokenizer - eof, - invalid +namespace boost +{ + +namespace read_graphviz_detail +{ + struct token + { + enum token_type + { + kw_strict, + kw_graph, + kw_digraph, + kw_node, + kw_edge, + kw_subgraph, + left_brace, + right_brace, + semicolon, + equal, + left_bracket, + right_bracket, + comma, + colon, + dash_greater, + dash_dash, + plus, + left_paren, + right_paren, + at, + identifier, + quoted_string, // Only used internally in tokenizer + eof, + invalid + }; + token_type type; + std::string normalized_value; // May have double-quotes removed and/or + // some escapes replaced + token(token_type type, const std::string& normalized_value) + : type(type), normalized_value(normalized_value) + { + } + token() : type(invalid), normalized_value("") {} + friend std::ostream& operator<<(std::ostream& o, const token& t) + { + switch (t.type) + { + case token::kw_strict: + o << "<strict>"; + break; + case token::kw_graph: + o << "<graph>"; + break; + case token::kw_digraph: + o << "<digraph>"; + break; + case token::kw_node: + o << "<node>"; + break; + case token::kw_edge: + o << "<edge>"; + break; + case token::kw_subgraph: + o << "<subgraph>"; + break; + case token::left_brace: + o << "<left_brace>"; + break; + case token::right_brace: + o << "<right_brace>"; + break; + case token::semicolon: + o << "<semicolon>"; + break; + case token::equal: + o << "<equal>"; + break; + case token::left_bracket: + o << "<left_bracket>"; + break; + case token::right_bracket: + o << "<right_bracket>"; + break; + case token::comma: + o << "<comma>"; + break; + case token::colon: + o << "<colon>"; + break; + case token::dash_greater: + o << "<dash-greater>"; + break; + case token::dash_dash: + o << "<dash-dash>"; + break; + case token::plus: + o << "<plus>"; + break; + case token::left_paren: + o << "<left_paren>"; + break; + case token::right_paren: + o << "<right_paren>"; + break; + case token::at: + o << "<at>"; + break; + case token::identifier: + o << "<identifier>"; + break; + case token::quoted_string: + o << "<quoted_string>"; + break; + case token::eof: + o << "<eof>"; + break; + default: + o << "<invalid type>"; + break; + } + o << " '" << t.normalized_value << "'"; + return o; + } }; - token_type type; - std::string normalized_value; // May have double-quotes removed and/or some escapes replaced - token(token_type type, const std::string& normalized_value) - : type(type), normalized_value(normalized_value) {} - token(): type(invalid), normalized_value("") {} - friend std::ostream& operator<<(std::ostream& o, const token& t) { - switch (t.type) { - case token::kw_strict: o << "<strict>"; break; - case token::kw_graph: o << "<graph>"; break; - case token::kw_digraph: o << "<digraph>"; break; - case token::kw_node: o << "<node>"; break; - case token::kw_edge: o << "<edge>"; break; - case token::kw_subgraph: o << "<subgraph>"; break; - case token::left_brace: o << "<left_brace>"; break; - case token::right_brace: o << "<right_brace>"; break; - case token::semicolon: o << "<semicolon>"; break; - case token::equal: o << "<equal>"; break; - case token::left_bracket: o << "<left_bracket>"; break; - case token::right_bracket: o << "<right_bracket>"; break; - case token::comma: o << "<comma>"; break; - case token::colon: o << "<colon>"; break; - case token::dash_greater: o << "<dash-greater>"; break; - case token::dash_dash: o << "<dash-dash>"; break; - case token::plus: o << "<plus>"; break; - case token::left_paren: o << "<left_paren>"; break; - case token::right_paren: o << "<right_paren>"; break; - case token::at: o << "<at>"; break; - case token::identifier: o << "<identifier>"; break; - case token::quoted_string: o << "<quoted_string>"; break; - case token::eof: o << "<eof>"; break; - default: o << "<invalid type>"; break; - } - o << " '" << t.normalized_value << "'"; - return o; - } - }; - bad_graphviz_syntax lex_error(const std::string& errmsg, char bad_char) { - if (bad_char == '\0') { - return bad_graphviz_syntax(errmsg + " (at end of input)"); - } else { - return bad_graphviz_syntax(errmsg + " (char is '" + bad_char + "')"); + bad_graphviz_syntax lex_error(const std::string& errmsg, char bad_char) + { + if (bad_char == '\0') + { + return bad_graphviz_syntax(errmsg + " (at end of input)"); + } + else + { + return bad_graphviz_syntax( + errmsg + " (char is '" + bad_char + "')"); + } } - } - - bad_graphviz_syntax parse_error(const std::string& errmsg, const token& bad_token) { - return bad_graphviz_syntax(errmsg + " (token is \"" + boost::lexical_cast<std::string>(bad_token) + "\")"); - } - - struct tokenizer { - std::string::const_iterator begin, end; - std::vector<token> lookahead; - // Precomputed regexes - boost::regex stuff_to_skip; - boost::regex basic_id_token; - boost::regex punctuation_token; - boost::regex number_token; - boost::regex quoted_string_token; - boost::regex xml_tag_token; - boost::regex cdata; - - tokenizer(const std::string& str) : begin(str.begin()), end(str.end()) + + bad_graphviz_syntax parse_error( + const std::string& errmsg, const token& bad_token) { - std::string end_of_token = "(?=(?:\\W))"; - std::string whitespace = "(?:\\s+)"; - std::string slash_slash_comment = "(?://.*?$)"; - std::string slash_star_comment = "(?:/\\*.*?\\*/)"; - std::string hash_comment = "(?:^#.*?$)"; - std::string backslash_newline = "(?:[\\\\][\\n])"; - stuff_to_skip = "\\A(?:" + whitespace + "|" + - slash_slash_comment + "|" + - slash_star_comment + "|" + - hash_comment + "|" + - backslash_newline + ")*"; - basic_id_token = "\\A([[:alpha:]_](?:\\w*))"; - punctuation_token = "\\A([][{};=,:+()@]|[-][>-])"; - number_token = "\\A([-]?(?:(?:\\.\\d+)|(?:\\d+(?:\\.\\d*)?)))"; - quoted_string_token = "\\A(\"(?:[^\"\\\\]|(?:[\\\\].))*\")"; - xml_tag_token = "\\A<(/?)(?:[^!?'\"]|(?:'[^']*?')|(?:\"[^\"]*?\"))*?(/?)>"; - cdata = "\\A\\Q<![CDATA[\\E.*?\\Q]]>\\E"; + return bad_graphviz_syntax(errmsg + " (token is \"" + + boost::lexical_cast< std::string >(bad_token) + "\")"); } - void skip() { - boost::match_results<std::string::const_iterator> results; + struct tokenizer + { + std::string::const_iterator begin, end; + std::vector< token > lookahead; + // Precomputed regexes + boost::regex stuff_to_skip; + boost::regex basic_id_token; + boost::regex punctuation_token; + boost::regex number_token; + boost::regex quoted_string_token; + boost::regex xml_tag_token; + boost::regex cdata; + + tokenizer(const std::string& str) : begin(str.begin()), end(str.end()) + { + std::string end_of_token = "(?=(?:\\W))"; + std::string whitespace = "(?:\\s+)"; + std::string slash_slash_comment = "(?://.*?$)"; + std::string slash_star_comment = "(?:/\\*.*?\\*/)"; + std::string hash_comment = "(?:^#.*?$)"; + std::string backslash_newline = "(?:[\\\\][\\n])"; + stuff_to_skip = "\\A(?:" + whitespace + "|" + slash_slash_comment + + "|" + slash_star_comment + "|" + hash_comment + "|" + + backslash_newline + ")*"; + basic_id_token = "\\A([[:alpha:]_](?:\\w*))"; + punctuation_token = "\\A([][{};=,:+()@]|[-][>-])"; + number_token = "\\A([-]?(?:(?:\\.\\d+)|(?:\\d+(?:\\.\\d*)?)))"; + quoted_string_token = "\\A(\"(?:[^\"\\\\]|(?:[\\\\].))*\")"; + xml_tag_token + = "\\A<(/?)(?:[^!?'\"]|(?:'[^']*?')|(?:\"[^\"]*?\"))*?(/?)>"; + cdata = "\\A\\Q<![CDATA[\\E.*?\\Q]]>\\E"; + } + + void skip() + { + boost::match_results< std::string::const_iterator > results; #ifndef NDEBUG - bool found = + bool found = #endif - boost::regex_search(begin, end, results, stuff_to_skip); + boost::regex_search(begin, end, results, stuff_to_skip); #ifndef NDEBUG - BOOST_ASSERT (found); + BOOST_ASSERT(found); #endif - boost::sub_match<std::string::const_iterator> sm1 = results.suffix(); - BOOST_ASSERT (sm1.second == end); - begin = sm1.first; - } + boost::sub_match< std::string::const_iterator > sm1 + = results.suffix(); + BOOST_ASSERT(sm1.second == end); + begin = sm1.first; + } - token get_token_raw() { - if (!lookahead.empty()) { - token t = lookahead.front(); - lookahead.erase(lookahead.begin()); - return t; - } - skip(); - if (begin == end) return token(token::eof, ""); - // Look for keywords first - bool found; - boost::match_results<std::string::const_iterator> results; - found = boost::regex_search(begin, end, results, basic_id_token); - if (found) { - std::string str = results[1].str(); - std::string str_lower = boost::algorithm::to_lower_copy(str); - begin = results.suffix().first; - if (str_lower == "strict") { - return token(token::kw_strict, str); - } else if (str_lower == "graph") { - return token(token::kw_graph, str); - } else if (str_lower == "digraph") { - return token(token::kw_digraph, str); - } else if (str_lower == "node") { - return token(token::kw_node, str); - } else if (str_lower == "edge") { - return token(token::kw_edge, str); - } else if (str_lower == "subgraph") { - return token(token::kw_subgraph, str); - } else { - return token(token::identifier, str); - } - } - found = boost::regex_search(begin, end, results, punctuation_token); - if (found) { - std::string str = results[1].str(); - begin = results.suffix().first; - switch (str[0]) { - case '[': return token(token::left_bracket, str); - case ']': return token(token::right_bracket, str); - case '{': return token(token::left_brace, str); - case '}': return token(token::right_brace, str); - case ';': return token(token::semicolon, str); - case '=': return token(token::equal, str); - case ',': return token(token::comma, str); - case ':': return token(token::colon, str); - case '+': return token(token::plus, str); - case '(': return token(token::left_paren, str); - case ')': return token(token::right_paren, str); - case '@': return token(token::at, str); - case '-': { - switch (str[1]) { - case '-': return token(token::dash_dash, str); - case '>': return token(token::dash_greater, str); - default: BOOST_ASSERT (!"Definition of punctuation_token does not match switch statement"); - } - } - default: BOOST_ASSERT (!"Definition of punctuation_token does not match switch statement"); - } - } - found = boost::regex_search(begin, end, results, number_token); - if (found) { - std::string str = results[1].str(); - begin = results.suffix().first; - return token(token::identifier, str); - } - found = boost::regex_search(begin, end, results, quoted_string_token); - if (found) { - std::string str = results[1].str(); - begin = results.suffix().first; - // Remove the beginning and ending quotes - BOOST_ASSERT (str.size() >= 2); - str.erase(str.begin()); - str.erase(str.end() - 1); - // Unescape quotes in the middle, but nothing else (see format spec) - for (size_t i = 0; i + 1 < str.size() /* May change */; ++i) { - if (str[i] == '\\' && str[i + 1] == '"') { - str.erase(str.begin() + i); - // Don't need to adjust i - } else if (str[i] == '\\' && str[i + 1] == '\n') { - str.erase(str.begin() + i); - str.erase(str.begin() + i); - --i; // Invert ++ that will be applied - } - } - return token(token::quoted_string, str); - } - if (*begin == '<') { - std::string::const_iterator saved_begin = begin; - int counter = 0; - do { - if (begin == end) throw_lex_error("Unclosed HTML string"); - if (*begin != '<') { - ++begin; - continue; - } - found = boost::regex_search(begin, end, results, xml_tag_token); - if (found) { - begin = results.suffix().first; - if (results[1].str() == "/") { // Close tag - --counter; - } else if (results[2].str() == "/") { // Empty tag - } else { // Open tag - ++counter; - } - continue; - } - found = boost::regex_search(begin, end, results, cdata); - if (found) { - begin = results.suffix().first; - continue; - } - throw_lex_error("Invalid contents in HTML string"); - } while (counter > 0); - return token(token::identifier, std::string(saved_begin, begin)); - } else { - throw_lex_error("Invalid character"); - return token(); - } - } + token get_token_raw() + { + if (!lookahead.empty()) + { + token t = lookahead.front(); + lookahead.erase(lookahead.begin()); + return t; + } + skip(); + if (begin == end) + return token(token::eof, ""); + // Look for keywords first + bool found; + boost::match_results< std::string::const_iterator > results; + found = boost::regex_search(begin, end, results, basic_id_token); + if (found) + { + std::string str = results[1].str(); + std::string str_lower = boost::algorithm::to_lower_copy(str); + begin = results.suffix().first; + if (str_lower == "strict") + { + return token(token::kw_strict, str); + } + else if (str_lower == "graph") + { + return token(token::kw_graph, str); + } + else if (str_lower == "digraph") + { + return token(token::kw_digraph, str); + } + else if (str_lower == "node") + { + return token(token::kw_node, str); + } + else if (str_lower == "edge") + { + return token(token::kw_edge, str); + } + else if (str_lower == "subgraph") + { + return token(token::kw_subgraph, str); + } + else + { + return token(token::identifier, str); + } + } + found = boost::regex_search(begin, end, results, punctuation_token); + if (found) + { + std::string str = results[1].str(); + begin = results.suffix().first; + switch (str[0]) + { + case '[': + return token(token::left_bracket, str); + case ']': + return token(token::right_bracket, str); + case '{': + return token(token::left_brace, str); + case '}': + return token(token::right_brace, str); + case ';': + return token(token::semicolon, str); + case '=': + return token(token::equal, str); + case ',': + return token(token::comma, str); + case ':': + return token(token::colon, str); + case '+': + return token(token::plus, str); + case '(': + return token(token::left_paren, str); + case ')': + return token(token::right_paren, str); + case '@': + return token(token::at, str); + case '-': + { + switch (str[1]) + { + case '-': + return token(token::dash_dash, str); + case '>': + return token(token::dash_greater, str); + default: + BOOST_ASSERT(!"Definition of punctuation_token does " + "not match switch statement"); + } + // Prevent static analyzers complaining about fallthrough: + break; + } + default: + BOOST_ASSERT(!"Definition of punctuation_token does not " + "match switch statement"); + } + } + found = boost::regex_search(begin, end, results, number_token); + if (found) + { + std::string str = results[1].str(); + begin = results.suffix().first; + return token(token::identifier, str); + } + found + = boost::regex_search(begin, end, results, quoted_string_token); + if (found) + { + std::string str = results[1].str(); + begin = results.suffix().first; + // Remove the beginning and ending quotes + BOOST_ASSERT(str.size() >= 2); + str.erase(str.begin()); + str.erase(str.end() - 1); + // Unescape quotes in the middle, but nothing else (see format + // spec) + for (size_t i = 0; i + 1 < str.size() /* May change */; ++i) + { + if (str[i] == '\\' && str[i + 1] == '"') + { + str.erase(str.begin() + i); + // Don't need to adjust i + } + else if (str[i] == '\\' && str[i + 1] == '\n') + { + str.erase(str.begin() + i); + str.erase(str.begin() + i); + --i; // Invert ++ that will be applied + } + } + return token(token::quoted_string, str); + } + if (*begin == '<') + { + std::string::const_iterator saved_begin = begin; + int counter = 0; + do + { + if (begin == end) + throw_lex_error("Unclosed HTML string"); + if (*begin != '<') + { + ++begin; + continue; + } + found = boost::regex_search( + begin, end, results, xml_tag_token); + if (found) + { + begin = results.suffix().first; + if (results[1].str() == "/") + { // Close tag + --counter; + } + else if (results[2].str() == "/") + { // Empty tag + } + else + { // Open tag + ++counter; + } + continue; + } + found = boost::regex_search(begin, end, results, cdata); + if (found) + { + begin = results.suffix().first; + continue; + } + throw_lex_error("Invalid contents in HTML string"); + } while (counter > 0); + return token( + token::identifier, std::string(saved_begin, begin)); + } + else + { + throw_lex_error("Invalid character"); + return token(); + } + } - token peek_token_raw() { - if (lookahead.empty()) { - token t = get_token_raw(); - lookahead.push_back(t); - } - return lookahead.front(); - } + token peek_token_raw() + { + if (lookahead.empty()) + { + token t = get_token_raw(); + lookahead.push_back(t); + } + return lookahead.front(); + } - token get_token() { // Handle string concatenation - token t = get_token_raw(); - if (t.type != token::quoted_string) return t; - std::string str = t.normalized_value; - while (peek_token_raw().type == token::plus) { - get_token_raw(); - token t2 = get_token_raw(); - if (t2.type != token::quoted_string) { - throw_lex_error("Must have quoted string after string concatenation"); - } - str += t2.normalized_value; - } - return token(token::identifier, str); // Note that quoted_string does not get passed to the parser - } + token get_token() + { // Handle string concatenation + token t = get_token_raw(); + if (t.type != token::quoted_string) + return t; + std::string str = t.normalized_value; + while (peek_token_raw().type == token::plus) + { + get_token_raw(); + token t2 = get_token_raw(); + if (t2.type != token::quoted_string) + { + throw_lex_error( + "Must have quoted string after string concatenation"); + } + str += t2.normalized_value; + } + return token( + token::identifier, str); // Note that quoted_string does not get + // passed to the parser + } - void throw_lex_error(const std::string& errmsg) { - boost::throw_exception(lex_error(errmsg, (begin == end ? '\0' : *begin))); - } - }; - - struct edge_endpoint { - bool is_subgraph; - node_and_port node_ep; - subgraph_name subgraph_ep; - - static edge_endpoint node(const node_and_port& ep) { - edge_endpoint r; - r.is_subgraph = false; - r.node_ep = ep; - return r; - } + void throw_lex_error(const std::string& errmsg) + { + boost::throw_exception( + lex_error(errmsg, (begin == end ? '\0' : *begin))); + } + }; - static edge_endpoint subgraph(const subgraph_name& ep) { - edge_endpoint r; - r.is_subgraph = true; - r.subgraph_ep = ep; - return r; - } - }; - - struct node_or_subgraph_ref { - bool is_subgraph; - std::string name; // Name for subgraphs or nodes, "___root___" for root graph - }; - - static node_or_subgraph_ref noderef(const node_name& n) { - node_or_subgraph_ref r; - r.is_subgraph = false; - r.name = n; - return r; - } - - static node_or_subgraph_ref subgraphref(const subgraph_name& n) { - node_or_subgraph_ref r; - r.is_subgraph = true; - r.name = n; - return r; - } - - typedef std::vector<node_or_subgraph_ref> subgraph_member_list; - - struct subgraph_info { - properties def_node_props; - properties def_edge_props; - subgraph_member_list members; - }; - - struct parser { - tokenizer the_tokenizer; - std::vector<token> lookahead; - parser_result& r; - std::map<subgraph_name, subgraph_info> subgraphs; - std::string current_subgraph_name; - int sgcounter; // Counter for anonymous subgraphs - std::set<std::pair<node_name, node_name> > existing_edges; // Used for checking in strict graphs - - subgraph_info& current() {return subgraphs[current_subgraph_name];} - properties& current_graph_props() {return r.graph_props[current_subgraph_name];} - subgraph_member_list& current_members() {return current().members;} - - parser(const std::string& gr, parser_result& result) - : the_tokenizer(gr), lookahead(), r(result), sgcounter(0) { - current_subgraph_name = "___root___"; - current() = subgraph_info(); // Initialize root graph - current_graph_props().clear(); - current_members().clear(); - } + struct edge_endpoint + { + bool is_subgraph; + node_and_port node_ep; + subgraph_name subgraph_ep; - token get() { - if (lookahead.empty()) { - token t = the_tokenizer.get_token(); - return t; - } else { - token t = lookahead.front(); - lookahead.erase(lookahead.begin()); - return t; - } - } + static edge_endpoint node(const node_and_port& ep) + { + edge_endpoint r; + r.is_subgraph = false; + r.node_ep = ep; + return r; + } - token peek() { - if (lookahead.empty()) { - lookahead.push_back(the_tokenizer.get_token()); - } - return lookahead.front(); - } + static edge_endpoint subgraph(const subgraph_name& ep) + { + edge_endpoint r; + r.is_subgraph = true; + r.subgraph_ep = ep; + return r; + } + }; - void error(const std::string& str) { - boost::throw_exception(parse_error(str, peek())); - } + struct node_or_subgraph_ref + { + bool is_subgraph; + std::string + name; // Name for subgraphs or nodes, "___root___" for root graph + }; - void parse_graph(bool want_directed) { - bool is_strict = false; - bool is_directed = false; - std::string name; - if (peek().type == token::kw_strict) {get(); is_strict = true;} - switch (peek().type) { - case token::kw_graph: is_directed = false; break; - case token::kw_digraph: is_directed = true; break; - default: error("Wanted \"graph\" or \"digraph\""); - } - r.graph_is_directed = is_directed; // Used to check edges - r.graph_is_strict = is_strict; - if (want_directed != r.graph_is_directed) { - if (want_directed) { - boost::throw_exception(boost::undirected_graph_error()); - } else { - boost::throw_exception(boost::directed_graph_error()); - } - } - get(); - switch (peek().type) { - case token::identifier: name = peek().normalized_value; get(); break; - case token::left_brace: break; - default: error("Wanted a graph name or left brace"); - } - if (peek().type == token::left_brace) get(); else error("Wanted a left brace to start the graph"); - parse_stmt_list(); - if (peek().type == token::right_brace) get(); else error("Wanted a right brace to end the graph"); - if (peek().type == token::eof) {} else error("Wanted end of file"); + static node_or_subgraph_ref noderef(const node_name& n) + { + node_or_subgraph_ref r; + r.is_subgraph = false; + r.name = n; + return r; } - void parse_stmt_list() { - while (true) { - if (peek().type == token::right_brace) return; - parse_stmt(); - if (peek().type == token::semicolon) get(); - } + static node_or_subgraph_ref subgraphref(const subgraph_name& n) + { + node_or_subgraph_ref r; + r.is_subgraph = true; + r.name = n; + return r; } - void parse_stmt() { - switch (peek().type) { - case token::kw_node: - case token::kw_edge: - case token::kw_graph: parse_attr_stmt(); break; - case token::kw_subgraph: - case token::left_brace: - case token::identifier: { - token id = get(); - if (id.type == token::identifier && peek().type == token::equal) { // Graph property + typedef std::vector< node_or_subgraph_ref > subgraph_member_list; + + struct subgraph_info + { + properties def_node_props; + properties def_edge_props; + subgraph_member_list members; + }; + + struct parser + { + tokenizer the_tokenizer; + std::vector< token > lookahead; + parser_result& r; + std::map< subgraph_name, subgraph_info > subgraphs; + std::string current_subgraph_name; + int sgcounter; // Counter for anonymous subgraphs + std::set< std::pair< node_name, node_name > > + existing_edges; // Used for checking in strict graphs + + subgraph_info& current() { return subgraphs[current_subgraph_name]; } + properties& current_graph_props() + { + return r.graph_props[current_subgraph_name]; + } + subgraph_member_list& current_members() { return current().members; } + + parser(const std::string& gr, parser_result& result) + : the_tokenizer(gr), lookahead(), r(result), sgcounter(0) + { + current_subgraph_name = "___root___"; + current() = subgraph_info(); // Initialize root graph + current_graph_props().clear(); + current_members().clear(); + } + + token get() + { + if (lookahead.empty()) + { + token t = the_tokenizer.get_token(); + return t; + } + else + { + token t = lookahead.front(); + lookahead.erase(lookahead.begin()); + return t; + } + } + + token peek() + { + if (lookahead.empty()) + { + lookahead.push_back(the_tokenizer.get_token()); + } + return lookahead.front(); + } + + void error(const std::string& str) + { + boost::throw_exception(parse_error(str, peek())); + } + + void parse_graph(bool want_directed) + { + bool is_strict = false; + bool is_directed = false; + std::string name; + if (peek().type == token::kw_strict) + { + get(); + is_strict = true; + } + switch (peek().type) + { + case token::kw_graph: + is_directed = false; + break; + case token::kw_digraph: + is_directed = true; + break; + default: + error("Wanted \"graph\" or \"digraph\""); + } + r.graph_is_directed = is_directed; // Used to check edges + r.graph_is_strict = is_strict; + if (want_directed != r.graph_is_directed) + { + if (want_directed) + { + boost::throw_exception(boost::undirected_graph_error()); + } + else + { + boost::throw_exception(boost::directed_graph_error()); + } + } get(); - if (peek().type != token::identifier) error("Wanted identifier as right side of ="); - token id2 = get(); - current_graph_props()[id.normalized_value] = id2.normalized_value; - } else { - edge_endpoint ep = parse_endpoint_rest(id); - if (peek().type == token::dash_dash || peek().type == token::dash_greater) { // Edge - parse_edge_stmt(ep); - } else { - if (!ep.is_subgraph) { // Only nodes can have attribute lists - // This node already exists because of its first mention - // (properties set to defaults by parse_node_and_port, called - // by parse_endpoint_rest) - properties this_node_props; - if (peek().type == token::left_bracket) { - parse_attr_list(this_node_props); + switch (peek().type) + { + case token::identifier: + name = peek().normalized_value; + get(); + break; + case token::left_brace: + break; + default: + error("Wanted a graph name or left brace"); + } + if (peek().type == token::left_brace) + get(); + else + error("Wanted a left brace to start the graph"); + parse_stmt_list(); + if (peek().type == token::right_brace) + get(); + else + error("Wanted a right brace to end the graph"); + if (peek().type == token::eof) + { + } + else + error("Wanted end of file"); + } + + void parse_stmt_list() + { + while (true) + { + if (peek().type == token::right_brace) + return; + parse_stmt(); + if (peek().type == token::semicolon) + get(); + } + } + + void parse_stmt() + { + switch (peek().type) + { + case token::kw_node: + case token::kw_edge: + case token::kw_graph: + parse_attr_stmt(); + break; + case token::kw_subgraph: + case token::left_brace: + case token::identifier: + { + token id = get(); + if (id.type == token::identifier && peek().type == token::equal) + { // Graph property + get(); + if (peek().type != token::identifier) + error("Wanted identifier as right side of ="); + token id2 = get(); + current_graph_props()[id.normalized_value] + = id2.normalized_value; } - for (properties::const_iterator i = this_node_props.begin(); - i != this_node_props.end(); ++i) { - // Override old properties with same names - r.nodes[ep.node_ep.name][i->first] = i->second; + else + { + edge_endpoint ep = parse_endpoint_rest(id); + if (peek().type == token::dash_dash + || peek().type == token::dash_greater) + { // Edge + parse_edge_stmt(ep); + } + else + { + if (!ep.is_subgraph) + { // Only nodes can have attribute lists + // This node already exists because of its first + // mention (properties set to defaults by + // parse_node_and_port, called by + // parse_endpoint_rest) + properties this_node_props; + if (peek().type == token::left_bracket) + { + parse_attr_list(this_node_props); + } + for (properties::const_iterator i + = this_node_props.begin(); + i != this_node_props.end(); ++i) + { + // Override old properties with same names + r.nodes[ep.node_ep.name][i->first] = i->second; + } + current_members().push_back( + noderef(ep.node_ep.name)); + } + else + { + current_members().push_back( + subgraphref(ep.subgraph_ep)); + } + } } - current_members().push_back(noderef(ep.node_ep.name)); - } else { - current_members().push_back(subgraphref(ep.subgraph_ep)); - } + break; + } + default: + error("Invalid start token for statement"); } - } - break; } - default: error("Invalid start token for statement"); - } - } - void parse_attr_stmt() { - switch (get().type) { - case token::kw_graph: parse_attr_list(current_graph_props()); break; - case token::kw_node: parse_attr_list(current().def_node_props); break; - case token::kw_edge: parse_attr_list(current().def_edge_props); break; - default: BOOST_ASSERT (!"Bad attr_stmt case"); - } - } + void parse_attr_stmt() + { + switch (get().type) + { + case token::kw_graph: + parse_attr_list(current_graph_props()); + break; + case token::kw_node: + parse_attr_list(current().def_node_props); + break; + case token::kw_edge: + parse_attr_list(current().def_edge_props); + break; + default: + BOOST_ASSERT(!"Bad attr_stmt case"); + } + } - edge_endpoint parse_endpoint() { - switch (peek().type) { - case token::kw_subgraph: - case token::left_brace: - case token::identifier: { - token first = get(); - return parse_endpoint_rest(first); + edge_endpoint parse_endpoint() + { + switch (peek().type) + { + case token::kw_subgraph: + case token::left_brace: + case token::identifier: + { + token first = get(); + return parse_endpoint_rest(first); + } + default: + { + error("Wanted \"subgraph\", \"{\", or identifier to start node " + "or subgraph"); + return edge_endpoint(); + } + } } - default: { - error("Wanted \"subgraph\", \"{\", or identifier to start node or subgraph"); - return edge_endpoint(); + + edge_endpoint parse_endpoint_rest(const token& first_token) + { + switch (first_token.type) + { + case token::kw_subgraph: + case token::left_brace: + return edge_endpoint::subgraph(parse_subgraph(first_token)); + default: + return edge_endpoint::node(parse_node_and_port(first_token)); + } } - } - } - edge_endpoint parse_endpoint_rest(const token& first_token) { - switch (first_token.type) { - case token::kw_subgraph: - case token::left_brace: return edge_endpoint::subgraph(parse_subgraph(first_token)); - default: return edge_endpoint::node(parse_node_and_port(first_token)); - } - } + subgraph_name parse_subgraph(const token& first_token) + { + std::string name; + bool is_anonymous = true; + if (first_token.type == token::kw_subgraph) + { + if (peek().type == token::identifier) + { + name = get().normalized_value; + is_anonymous = false; + } + } + if (is_anonymous) + { + name = "___subgraph_" + + boost::lexical_cast< std::string >(++sgcounter); + } + if (subgraphs.find(name) == subgraphs.end()) + { + subgraphs[name] + = current(); // Initialize properties and defaults + subgraphs[name].members.clear(); // Except member list + } + if (first_token.type == token::kw_subgraph + && peek().type != token::left_brace) + { + if (is_anonymous) + error("Subgraph reference needs a name"); + return name; + } + subgraph_name old_sg = current_subgraph_name; + current_subgraph_name = name; + if (peek().type == token::left_brace) + get(); + else + error("Wanted left brace to start subgraph"); + parse_stmt_list(); + if (peek().type == token::right_brace) + get(); + else + error("Wanted right brace to end subgraph"); + current_subgraph_name = old_sg; + return name; + } - subgraph_name parse_subgraph(const token& first_token) { - std::string name; - bool is_anonymous = true; - if (first_token.type == token::kw_subgraph) { - if (peek().type == token::identifier) { - name = get().normalized_value; - is_anonymous = false; - } - } - if (is_anonymous) { - name = "___subgraph_" + - boost::lexical_cast<std::string>(++sgcounter); - } - if (subgraphs.find(name) == subgraphs.end()) { - subgraphs[name] = current(); // Initialize properties and defaults - subgraphs[name].members.clear(); // Except member list - } - if (first_token.type == token::kw_subgraph && peek().type != token::left_brace) { - if (is_anonymous) error("Subgraph reference needs a name"); - return name; - } - subgraph_name old_sg = current_subgraph_name; - current_subgraph_name = name; - if (peek().type == token::left_brace) get(); else error("Wanted left brace to start subgraph"); - parse_stmt_list(); - if (peek().type == token::right_brace) get(); else error("Wanted right brace to end subgraph"); - current_subgraph_name = old_sg; - return name; - } + node_and_port parse_node_and_port(const token& name) + { + // A node ID is a node name, followed optionally by a port angle and + // a port location (in either order); a port location is either :id, + // :id:id, or :(id,id); the last two forms are treated as equivalent + // although I am not sure about that. + node_and_port id; + id.name = name.normalized_value; + parse_more: + switch (peek().type) + { + case token::at: + { + get(); + if (peek().type != token::identifier) + error("Wanted identifier as port angle"); + if (!id.angle.empty()) + error("Duplicate port angle"); + id.angle = get().normalized_value; + goto parse_more; + } + case token::colon: + { + get(); + if (!id.location.empty()) + error("Duplicate port location"); + switch (peek().type) + { + case token::identifier: + { + id.location.push_back(get().normalized_value); + switch (peek().type) + { + case token::colon: + { + get(); + if (peek().type != token::identifier) + error("Wanted identifier as port location"); + id.location.push_back(get().normalized_value); + goto parse_more; + } + default: + goto parse_more; + } + } + case token::left_paren: + { + get(); + if (peek().type != token::identifier) + error("Wanted identifier as first element of port " + "location"); + id.location.push_back(get().normalized_value); + if (peek().type != token::comma) + error("Wanted comma between parts of port location"); + get(); + if (peek().type != token::identifier) + error("Wanted identifier as second element of port " + "location"); + id.location.push_back(get().normalized_value); + if (peek().type != token::right_paren) + error( + "Wanted right parenthesis to close port location"); + get(); + goto parse_more; + } + default: + error("Wanted identifier or left parenthesis as start of " + "port location"); + } + } + default: + break; + } + if (r.nodes.find(id.name) == r.nodes.end()) + { // First mention + r.nodes[id.name] = current().def_node_props; + } + return id; + } - node_and_port parse_node_and_port(const token& name) { - // A node ID is a node name, followed optionally by a port angle and a - // port location (in either order); a port location is either :id, - // :id:id, or :(id,id); the last two forms are treated as equivalent - // although I am not sure about that. - node_and_port id; - id.name = name.normalized_value; - parse_more: - switch (peek().type) { - case token::at: { - get(); - if (peek().type != token::identifier) error("Wanted identifier as port angle"); - if (id.angle != "") error("Duplicate port angle"); - id.angle = get().normalized_value; - goto parse_more; - } - case token::colon: { - get(); - if (!id.location.empty()) error("Duplicate port location"); - switch (peek().type) { - case token::identifier: { - id.location.push_back(get().normalized_value); - switch (peek().type) { - case token::colon: { - get(); - if (peek().type != token::identifier) error("Wanted identifier as port location"); - id.location.push_back(get().normalized_value); - goto parse_more; + void parse_edge_stmt(const edge_endpoint& lhs) + { + std::vector< edge_endpoint > nodes_in_chain(1, lhs); + while (true) + { + bool leave_loop = true; + switch (peek().type) + { + case token::dash_dash: + { + if (r.graph_is_directed) + error("Using -- in directed graph"); + get(); + nodes_in_chain.push_back(parse_endpoint()); + leave_loop = false; + break; } - default: goto parse_more; - } - } - case token::left_paren: { - get(); - if (peek().type != token::identifier) error("Wanted identifier as first element of port location"); - id.location.push_back(get().normalized_value); - if (peek().type != token::comma) error("Wanted comma between parts of port location"); - get(); - if (peek().type != token::identifier) error("Wanted identifier as second element of port location"); - id.location.push_back(get().normalized_value); - if (peek().type != token::right_paren) error("Wanted right parenthesis to close port location"); - get(); - goto parse_more; - } - default: error("Wanted identifier or left parenthesis as start of port location"); - } - } - default: break; - } - if (r.nodes.find(id.name) == r.nodes.end()) { // First mention - r.nodes[id.name] = current().def_node_props; - } - return id; - } + case token::dash_greater: + { + if (!r.graph_is_directed) + error("Using -> in undirected graph"); + get(); + nodes_in_chain.push_back(parse_endpoint()); + leave_loop = false; + break; + } + default: + leave_loop = true; + break; + } + if (leave_loop) + break; + } + properties this_edge_props = current().def_edge_props; + if (peek().type == token::left_bracket) + parse_attr_list(this_edge_props); + BOOST_ASSERT(nodes_in_chain.size() + >= 2); // Should be in node parser otherwise + for (size_t i = 0; i + 1 < nodes_in_chain.size(); ++i) + { + do_orig_edge( + nodes_in_chain[i], nodes_in_chain[i + 1], this_edge_props); + } + } - void parse_edge_stmt(const edge_endpoint& lhs) { - std::vector<edge_endpoint> nodes_in_chain(1, lhs); - while (true) { - bool leave_loop = true; - switch (peek().type) { - case token::dash_dash: { - if (r.graph_is_directed) error("Using -- in directed graph"); - get(); - nodes_in_chain.push_back(parse_endpoint()); - leave_loop = false; - break; - } - case token::dash_greater: { - if (!r.graph_is_directed) error("Using -> in undirected graph"); - get(); - nodes_in_chain.push_back(parse_endpoint()); - leave_loop = false; - break; - } - default: leave_loop = true; break; - } - if (leave_loop) break; - } - properties this_edge_props = current().def_edge_props; - if (peek().type == token::left_bracket) parse_attr_list(this_edge_props); - BOOST_ASSERT (nodes_in_chain.size() >= 2); // Should be in node parser otherwise - for (size_t i = 0; i + 1 < nodes_in_chain.size(); ++i) { - do_orig_edge(nodes_in_chain[i], nodes_in_chain[i + 1], this_edge_props); - } - } + // Do an edge from the file, the edge may need to be expanded if it + // connects to a subgraph + void do_orig_edge(const edge_endpoint& src, const edge_endpoint& tgt, + const properties& props) + { + std::set< node_and_port > sources = get_recursive_members(src); + std::set< node_and_port > targets = get_recursive_members(tgt); + for (std::set< node_and_port >::const_iterator i = sources.begin(); + i != sources.end(); ++i) + { + for (std::set< node_and_port >::const_iterator j + = targets.begin(); + j != targets.end(); ++j) + { + do_edge(*i, *j, props); + } + } + } - // Do an edge from the file, the edge may need to be expanded if it connects to a subgraph - void do_orig_edge(const edge_endpoint& src, const edge_endpoint& tgt, const properties& props) { - std::set<node_and_port> sources = get_recursive_members(src); - std::set<node_and_port> targets = get_recursive_members(tgt); - for (std::set<node_and_port>::const_iterator i = sources.begin(); i != sources.end(); ++i) { - for (std::set<node_and_port>::const_iterator j = targets.begin(); j != targets.end(); ++j) { - do_edge(*i, *j, props); + // Get nodes in an edge_endpoint, recursively + std::set< node_and_port > get_recursive_members( + const edge_endpoint& orig_ep) + { + std::set< node_and_port > result; + std::vector< edge_endpoint > worklist(1, orig_ep); + std::set< subgraph_name > done; + while (!worklist.empty()) + { + edge_endpoint ep = worklist.back(); + worklist.pop_back(); + if (ep.is_subgraph) + { + if (done.find(ep.subgraph_ep) == done.end()) + { + done.insert(ep.subgraph_ep); + std::map< subgraph_name, subgraph_info >::const_iterator + info_i + = subgraphs.find(ep.subgraph_ep); + if (info_i != subgraphs.end()) + { + const subgraph_member_list& members + = info_i->second.members; + for (subgraph_member_list::const_iterator i + = members.begin(); + i != members.end(); ++i) + { + node_or_subgraph_ref ref = *i; + if (ref.is_subgraph) + { + worklist.push_back( + edge_endpoint::subgraph(ref.name)); + } + else + { + node_and_port np; + np.name = ref.name; + worklist.push_back(edge_endpoint::node(np)); + } + } + } + } + } + else + { + result.insert(ep.node_ep); + } + } + return result; } - } - } - // Get nodes in an edge_endpoint, recursively - std::set<node_and_port> get_recursive_members(const edge_endpoint& orig_ep) { - std::set<node_and_port> result; - std::vector<edge_endpoint> worklist(1, orig_ep); - std::set<subgraph_name> done; - while (!worklist.empty()) { - edge_endpoint ep = worklist.back(); - worklist.pop_back(); - if (ep.is_subgraph) { - if (done.find(ep.subgraph_ep) == done.end()) { - done.insert(ep.subgraph_ep); - std::map<subgraph_name, subgraph_info>::const_iterator - info_i = subgraphs.find(ep.subgraph_ep); - if (info_i != subgraphs.end()) { - const subgraph_member_list& members = info_i->second.members; - for (subgraph_member_list::const_iterator i = members.begin(); - i != members.end(); ++i) { - node_or_subgraph_ref ref = *i; - if (ref.is_subgraph) { - worklist.push_back(edge_endpoint::subgraph(ref.name)); - } else { - node_and_port np; - np.name = ref.name; - worklist.push_back(edge_endpoint::node(np)); + // Do a fixed-up edge, with only nodes as endpoints + void do_edge(const node_and_port& src, const node_and_port& tgt, + const properties& props) + { + if (r.graph_is_strict) + { + if (src.name == tgt.name) + return; + std::pair< node_name, node_name > tag(src.name, tgt.name); + if (existing_edges.find(tag) != existing_edges.end()) + { + return; // Parallel edge } - } + existing_edges.insert(tag); } - } - } else { - result.insert(ep.node_ep); + edge_info e; + e.source = src; + e.target = tgt; + e.props = props; + r.edges.push_back(e); } - } - return result; - } - // Do a fixed-up edge, with only nodes as endpoints - void do_edge(const node_and_port& src, const node_and_port& tgt, const properties& props) { - if (r.graph_is_strict) { - if (src.name == tgt.name) return; - std::pair<node_name, node_name> tag(src.name, tgt.name); - if (existing_edges.find(tag) != existing_edges.end()) { - return; // Parallel edge - } - existing_edges.insert(tag); - } - edge_info e; - e.source = src; - e.target = tgt; - e.props = props; - r.edges.push_back(e); - } + void parse_attr_list(properties& props) + { + while (true) + { + if (peek().type == token::left_bracket) + get(); + else + error("Wanted left bracket to start attribute list"); + while (true) + { + switch (peek().type) + { + case token::right_bracket: + break; + case token::identifier: + { + std::string lhs = get().normalized_value; + std::string rhs = "true"; + if (peek().type == token::equal) + { + get(); + if (peek().type != token::identifier) + error( + "Wanted identifier as value of attribute"); + rhs = get().normalized_value; + } + props[lhs] = rhs; + break; + } + default: + error("Wanted identifier as name of attribute"); + } + if (peek().type == token::comma + || peek().type == token::semicolon) + get(); + else if (peek().type == token::right_bracket) + break; + } + if (peek().type == token::right_bracket) + get(); + else + error("Wanted right bracket to end attribute list"); + if (peek().type != token::left_bracket) + break; + } + } + }; - void parse_attr_list(properties& props) { - while (true) { - if (peek().type == token::left_bracket) get(); else error("Wanted left bracket to start attribute list"); - while (true) { - switch (peek().type) { - case token::right_bracket: break; - case token::identifier: { - std::string lhs = get().normalized_value; - std::string rhs = "true"; - if (peek().type == token::equal) { - get(); - if (peek().type != token::identifier) error("Wanted identifier as value of attribute"); - rhs = get().normalized_value; - } - props[lhs] = rhs; - break; - } - default: error("Wanted identifier as name of attribute"); - } - if (peek().type == token::comma || peek().type == token::semicolon) get(); - else if(peek().type == token::right_bracket) break; - } - if (peek().type == token::right_bracket) get(); else error("Wanted right bracket to end attribute list"); - if (peek().type != token::left_bracket) break; - } - } - }; - - void parse_graphviz_from_string(const std::string& str, parser_result& result, bool want_directed) { - parser p(str, result); - p.parse_graph(want_directed); - } - - // Some debugging stuff - std::ostream& operator<<(std::ostream& o, const node_and_port& n) { - o << n.name; - for (size_t i = 0; i < n.location.size(); ++i) { - o << ":" << n.location[i]; - } - if (!n.angle.empty()) o << "@" << n.angle; - return o; - } - - // Can't be operator<< because properties is just an std::map - std::string props_to_string(const properties& props) { - std::string result = "["; - for (properties::const_iterator i = props.begin(); i != props.end(); ++i) { - if (i != props.begin()) result += ", "; - result += i->first + "=" + i->second; + void parse_graphviz_from_string( + const std::string& str, parser_result& result, bool want_directed) + { + parser p(str, result); + p.parse_graph(want_directed); } - result += "]"; - return result; - } - - void translate_results_to_graph(const parser_result& r, ::boost::detail::graph::mutate_graph* mg) { - typedef boost::detail::graph::edge_t edge; - for (std::map<node_name, properties>::const_iterator i = r.nodes.begin(); i != r.nodes.end(); ++i) { - // std::cerr << i->first << " " << props_to_string(i->second) << std::endl; - mg->do_add_vertex(i->first); - for (properties::const_iterator j = i->second.begin(); j != i->second.end(); ++j) { - mg->set_node_property(j->first, i->first, j->second); - } + + // Some debugging stuff + std::ostream& operator<<(std::ostream& o, const node_and_port& n) + { + o << n.name; + for (size_t i = 0; i < n.location.size(); ++i) + { + o << ":" << n.location[i]; + } + if (!n.angle.empty()) + o << "@" << n.angle; + return o; } - for (std::vector<edge_info>::const_iterator i = r.edges.begin(); i != r.edges.end(); ++i) { - const edge_info& ei = *i; - // std::cerr << ei.source << " -> " << ei.target << " " << props_to_string(ei.props) << std::endl; - edge e = edge::new_edge(); - mg->do_add_edge(e, ei.source.name, ei.target.name); - for (properties::const_iterator j = ei.props.begin(); j != ei.props.end(); ++j) { - mg->set_edge_property(j->first, e, j->second); - } + + // Can't be operator<< because properties is just an std::map + std::string props_to_string(const properties& props) + { + std::string result = "["; + for (properties::const_iterator i = props.begin(); i != props.end(); + ++i) + { + if (i != props.begin()) + result += ", "; + result += i->first + "=" + i->second; + } + result += "]"; + return result; } - std::map<subgraph_name, properties>::const_iterator root_graph_props_i = r.graph_props.find("___root___"); - BOOST_ASSERT (root_graph_props_i != r.graph_props.end()); // Should not happen - const properties& root_graph_props = root_graph_props_i->second; - // std::cerr << "ending graph " << props_to_string(root_graph_props) << std::endl; - for (properties::const_iterator i = root_graph_props.begin(); i != root_graph_props.end(); ++i) { - mg->set_graph_property(i->first, i->second); + + void translate_results_to_graph( + const parser_result& r, ::boost::detail::graph::mutate_graph* mg) + { + typedef boost::detail::graph::edge_t edge; + for (std::map< node_name, properties >::const_iterator i + = r.nodes.begin(); + i != r.nodes.end(); ++i) + { + // std::cerr << i->first << " " << props_to_string(i->second) << + // std::endl; + mg->do_add_vertex(i->first); + for (properties::const_iterator j = i->second.begin(); + j != i->second.end(); ++j) + { + mg->set_node_property(j->first, i->first, j->second); + } + } + for (std::vector< edge_info >::const_iterator i = r.edges.begin(); + i != r.edges.end(); ++i) + { + const edge_info& ei = *i; + // std::cerr << ei.source << " -> " << ei.target << " " << + // props_to_string(ei.props) << std::endl; + edge e = edge::new_edge(); + mg->do_add_edge(e, ei.source.name, ei.target.name); + for (properties::const_iterator j = ei.props.begin(); + j != ei.props.end(); ++j) + { + mg->set_edge_property(j->first, e, j->second); + } + } + std::map< subgraph_name, properties >::const_iterator root_graph_props_i + = r.graph_props.find("___root___"); + BOOST_ASSERT( + root_graph_props_i != r.graph_props.end()); // Should not happen + const properties& root_graph_props = root_graph_props_i->second; + // std::cerr << "ending graph " << props_to_string(root_graph_props) << + // std::endl; + for (properties::const_iterator i = root_graph_props.begin(); + i != root_graph_props.end(); ++i) + { + mg->set_graph_property(i->first, i->second); + } + mg->finish_building_graph(); } - mg->finish_building_graph(); - } } // end namespace read_graphviz_detail -namespace detail { - namespace graph { +namespace detail +{ + namespace graph + { - BOOST_GRAPH_DECL bool read_graphviz_new(const std::string& str, boost::detail::graph::mutate_graph* mg) { - read_graphviz_detail::parser_result parsed_file; - read_graphviz_detail::parse_graphviz_from_string(str, parsed_file, mg->is_directed()); - read_graphviz_detail::translate_results_to_graph(parsed_file, mg); - return true; - } + BOOST_GRAPH_DECL bool read_graphviz_new( + const std::string& str, boost::detail::graph::mutate_graph* mg) + { + read_graphviz_detail::parser_result parsed_file; + read_graphviz_detail::parse_graphviz_from_string( + str, parsed_file, mg->is_directed()); + read_graphviz_detail::translate_results_to_graph(parsed_file, mg); + return true; + } - } // end namespace graph + } // end namespace graph } // end namespace detail } // end namespace boost |