Commit a2bb7ff8 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Fix compatibility with boost 1.48

This works around a regression introduced in boost 1.48, relating to the
edge descriptors of reversed graphs.

See: https://svn.boost.org/trac/boost/ticket/6391
parent 08ebe246
...@@ -44,6 +44,7 @@ namespace boost { ...@@ -44,6 +44,7 @@ namespace boost {
typedef typename graph_traits<Graph1>::vertex_descriptor vertex1_t; typedef typename graph_traits<Graph1>::vertex_descriptor vertex1_t;
typedef typename graph_traits<Graph2>::vertex_descriptor vertex2_t; typedef typename graph_traits<Graph2>::vertex_descriptor vertex2_t;
typedef typename graph_traits<Graph1>::edge_descriptor edge1_t; typedef typename graph_traits<Graph1>::edge_descriptor edge1_t;
typedef typename graph_traits<Graph2>::edge_descriptor edge2_t;
typedef typename graph_traits<Graph1>::vertices_size_type size_type; typedef typename graph_traits<Graph1>::vertices_size_type size_type;
typedef typename Invariant1::result_type invar1_value; typedef typename Invariant1::result_type invar1_value;
typedef typename Invariant2::result_type invar2_value; typedef typename Invariant2::result_type invar2_value;
...@@ -208,7 +209,7 @@ namespace boost { ...@@ -208,7 +209,7 @@ namespace boost {
bool match(edge_iter iter, int dfs_num_k) bool match(edge_iter iter, int dfs_num_k)
{ {
if (iter != ordered_edges.end()) { if (iter != ordered_edges.end()) {
vertex1_t i = source(*iter, G1), j = target(*iter, G2); vertex1_t i = source(edge1_t(*iter), G1), j = target(edge2_t(*iter), G2);
if (dfs_num[i] > dfs_num_k) { if (dfs_num[i] > dfs_num_k) {
vertex1_t kp1 = dfs_vertices[dfs_num_k + 1]; vertex1_t kp1 = dfs_vertices[dfs_num_k + 1];
BGL_FORALL_VERTICES_T(u, G2, Graph2) { BGL_FORALL_VERTICES_T(u, G2, Graph2) {
...@@ -289,7 +290,8 @@ namespace boost { ...@@ -289,7 +290,8 @@ namespace boost {
size_t get_num_vertices(const Graph& g) size_t get_num_vertices(const Graph& g)
{ {
size_t n = 0; size_t n = 0;
BGL_FORALL_VERTICES_T(v, g, Graph) typename boost::graph_traits<Graph>::vertex_iterator v, v_end;
for(tie(v, v_end) = vertices(g); v != v_end; ++v)
n++; n++;
return n; return n;
} }
...@@ -298,7 +300,8 @@ namespace boost { ...@@ -298,7 +300,8 @@ namespace boost {
size_t get_num_edges(const Graph& g) size_t get_num_edges(const Graph& g)
{ {
size_t n = 0; size_t n = 0;
BGL_FORALL_EDGES_T(e, g, Graph) typename boost::graph_traits<Graph>::edge_iterator e, e_end;
for(tie(e, e_end) = edges(g); e != e_end; ++e)
n++; n++;
return n; return n;
} }
......
// (C) Copyright David Abrahams 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 REVERSE_GRAPH_DWA092300_H_
# define REVERSE_GRAPH_DWA092300_H_
#include <boost/graph/adjacency_iterator.hpp>
#include <boost/graph/properties.hpp>
#include <boost/iterator/transform_iterator.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/type_traits.hpp>
#include <boost/mpl/if.hpp>
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
// Stay out of the way of the concept checking class
# define BidirectionalGraph BidirectionalGraph_
#endif
namespace boost {
struct reverse_graph_tag { };
namespace detail {
template <typename EdgeDesc>
class reverse_graph_edge_descriptor: public EdgeDesc {
public:
typedef EdgeDesc base_t;
explicit reverse_graph_edge_descriptor(const EdgeDesc& underlying_desc = EdgeDesc())
: base_t(underlying_desc) {}
};
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);
}
};
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 <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;
};
};
} // namespace detail
template <class BidirectionalGraph, class GraphRef = const BidirectionalGraph&>
class reverse_graph {
typedef reverse_graph<BidirectionalGraph, GraphRef> Self;
typedef graph_traits<BidirectionalGraph> Traits;
public:
typedef BidirectionalGraph base_type;
// Constructor
reverse_graph(GraphRef g) : m_g(g) {}
// Graph requirements
typedef typename Traits::vertex_descriptor vertex_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 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;
// AdjacencyGraph requirements
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;
typedef typename Traits::vertices_size_type vertices_size_type;
typedef typename Traits::edges_size_type edges_size_type;
typedef reverse_graph_tag graph_tag;
#ifndef BOOST_GRAPH_NO_BUNDLED_PROPERTIES
// Bundled properties support
template<typename Descriptor>
typename graph::detail::bundled_result<BidirectionalGraph, Descriptor>::type&
operator[](Descriptor x)
{ return m_g[x]; }
template<typename Descriptor>
typename graph::detail::bundled_result<BidirectionalGraph, Descriptor>::type const&
operator[](Descriptor x) const
{ return m_g[x]; }
#endif // BOOST_GRAPH_NO_BUNDLED_PROPERTIES
static vertex_descriptor null_vertex()
{ return Traits::null_vertex(); }
// would be private, but template friends aren't portable enough.
// 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 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;
};
#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 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> { };
#endif // BOOST_GRAPH_NO_BUNDLED_PROPERTIES
template <class BidirectionalGraph>
inline reverse_graph<BidirectionalGraph>
make_reverse_graph(const BidirectionalGraph& g)
{
return reverse_graph<BidirectionalGraph>(g);
}
template <class BidirectionalGraph>
inline reverse_graph<BidirectionalGraph, BidirectionalGraph&>
make_reverse_graph(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)
{
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)
{
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)
{
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)
{
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)
{
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)
{
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)
{
return vertex(v, g.m_g);
}
template <class BidirectionalGraph, class GRef>
inline std::pair<typename graph_traits<BidirectionalGraph>::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)
{
return edge(v, u, g.m_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));
}
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;
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)));
}
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)
{
return target(Edge(e), 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)
{
return source(Edge(e), g.m_g);
}
namespace detail {
template <typename PM>
struct reverse_graph_edge_property_map {
private:
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_desc);
}
friend void
put(const reverse_graph_edge_property_map& m,
const key_type& e,
const value_type& v) {
put(m.underlying_pm, e.underlying_desc, v);
}
reference operator[](const key_type& k) {
return (this->underlying_pm)[k.underlying_desc];
}
};
struct reverse_graph_vertex_property_selector {
template <class ReverseGraph, class Property, class Tag>
struct bind_ {
typedef typename ReverseGraph::base_type Graph;
typedef property_map<Graph, Tag> PMap;
typedef typename PMap::type type;
typedef typename PMap::const_type const_type;
};
};
struct reverse_graph_edge_property_selector {
template <class ReverseGraph, class Property, class Tag>
struct bind_ {
typedef typename ReverseGraph::base_type Graph;
typedef property_map<Graph, Tag> PMap;
typedef reverse_graph_edge_property_map<typename PMap::type> type;
typedef reverse_graph_edge_property_map<typename PMap::const_type> const_type;
};
};
} // namespace detail
template <>
struct vertex_property_selector<reverse_graph_tag> {
typedef detail::reverse_graph_vertex_property_selector type;
};
template <>
struct edge_property_selector<reverse_graph_tag> {
typedef detail::reverse_graph_edge_property_selector type;
};
template <class BidirGraph, class GRef, class Property>
typename property_map<reverse_graph<BidirGraph,GRef>, Property>::type
get(Property p, reverse_graph<BidirGraph,GRef>& g)
{
return typename property_map<reverse_graph<BidirGraph,GRef>, Property>::type(get(p, g.m_g));
}
template <class BidirGraph, class GRef, class Property>
typename property_map<reverse_graph<BidirGraph,GRef>, Property>::const_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));
}
template <class BidirectionalGraph, class GRef, class Property, class Key>
typename property_traits<
typename property_map<BidirectionalGraph, Property>::const_type
>::value_type
get(Property p, const reverse_graph<BidirectionalGraph,GRef>& g, const Key& 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,
const Value& val)
{
put(get(p, g), k, val);
}
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);
}
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);
}
} // namespace boost
#endif
...@@ -18,9 +18,14 @@ ...@@ -18,9 +18,14 @@
#ifndef FILTERING_HH #ifndef FILTERING_HH
#define FILTERING_HH #define FILTERING_HH
#include <boost/version.hpp>
#include <boost/graph/graph_traits.hpp> #include <boost/graph/graph_traits.hpp>
#include <boost/graph/filtered_graph.hpp> #include <boost/graph/filtered_graph.hpp>
#include <boost/graph/reverse_graph.hpp> #if (BOOST_VERSION / 100 % 1000 >= 48)
#include <boost/graph/reverse_graph_alt.hpp>
#else
#include <boost/graph/reverse_graph.hpp>
#endif
#include <boost/mpl/vector.hpp> #include <boost/mpl/vector.hpp>
#include <boost/mpl/erase.hpp> #include <boost/mpl/erase.hpp>
#include <boost/mpl/clear.hpp> #include <boost/mpl/clear.hpp>
......
...@@ -55,4 +55,3 @@ void ungroup_vector_property(GraphInterface& g, boost::any vector_prop, ...@@ -55,4 +55,3 @@ void ungroup_vector_property(GraphInterface& g, boost::any vector_prop,
vertex_vector_properties(), writable_vertex_properties()) vertex_vector_properties(), writable_vertex_properties())
(vector_prop, prop); (vector_prop, prop);
} }
...@@ -202,11 +202,12 @@ struct get_edge_descriptor ...@@ -202,11 +202,12 @@ struct get_edge_descriptor
typename GraphInterface::edge_t& edge, typename GraphInterface::edge_t& edge,
bool& found) const bool& found) const
{ {
typedef typename graph_traits<Graph>::edge_descriptor edge_t;
PythonEdge<Graph>& pe = python::extract<PythonEdge<Graph>&>(e); PythonEdge<Graph>& pe = python::extract<PythonEdge<Graph>&>(e);
pe.CheckValid(); pe.CheckValid();
pe.SetValid(false); pe.SetValid(false);
typename graph_traits<Graph>::out_edge_iterator e_begin, e_end; typename graph_traits<Graph>::out_edge_iterator e_begin, e_end;
tie(e_begin, e_end) = out_edges(source(pe.GetDescriptor(),g),g); tie(e_begin, e_end) = out_edges(source(edge_t(pe.GetDescriptor()),g),g);
while(e_begin != e_end && *e_begin != pe.GetDescriptor()) while(e_begin != e_end && *e_begin != pe.GetDescriptor())
++e_begin; ++e_begin;
if (e_begin == e_end) if (e_begin == e_end)
......
...@@ -279,7 +279,8 @@ public: ...@@ -279,7 +279,8 @@ public:
const edge_descriptor& edge, python::object& vertex) const edge_descriptor& edge, python::object& vertex)
const const
{ {
vertex = python::object(PythonVertex(pg, source(edge, g))); typedef typename graph_traits<GraphType>::edge_descriptor edge_t;
vertex = python::object(PythonVertex(pg, source(edge_t(edge), g)));
} }
}; };
...@@ -300,7 +301,8 @@ public: ...@@ -300,7 +301,8 @@ public:
const edge_descriptor& edge, python::object& vertex) const edge_descriptor& edge, python::object& vertex)
const const
{ {
vertex = python::object(PythonVertex(pg, target(edge, g))); typedef typename graph_traits<GraphType>::edge_descriptor edge_t;
vertex = python::object(PythonVertex(pg, target(edge_t(edge), g)));
} }
}; };
...@@ -318,7 +320,7 @@ public: ...@@ -318,7 +320,7 @@ public:
{ {
PythonVertex src = python::extract<PythonVertex>(GetSource()); PythonVertex src = python::extract<PythonVertex>(GetSource());
PythonVertex tgt = python::extract<PythonVertex>(GetTarget()); PythonVertex tgt = python::extract<PythonVertex>(GetTarget());
return "(" + src.GetString() + "," + tgt.GetString() + ")"; return "(" + src.GetString() + ", " + tgt.GetString() + ")";
} }
size_t GetHash() const size_t GetHash() const
......
...@@ -20,7 +20,11 @@ ...@@ -20,7 +20,11 @@
#include <boost/graph/graph_traits.hpp> #include <boost/graph/graph_traits.hpp>
#include <boost/graph/filtered_graph.hpp> #include <boost/graph/filtered_graph.hpp>
#include <boost/graph/reverse_graph.hpp> #if (BOOST_VERSION / 100 % 1000 >= 48)
#include <boost/graph/reverse_graph_alt.hpp>
#else
#include <boost/graph/reverse_graph.hpp>
#endif
#include <boost/algorithm/string/predicate.hpp> #include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/split.hpp> #include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp> #include <boost/algorithm/string/classification.hpp>
......
...@@ -36,7 +36,7 @@ public: ...@@ -36,7 +36,7 @@ public:
typedef typename property_traits<Label2>::value_type value_type2; typedef typename property_traits<Label2>::value_type value_type2;