2
0
mirror of https://github.com/boostorg/graph.git synced 2026-02-27 17:12:11 +00:00

Merged bug fixes from trunk (r68781,r68949,r68972,r68979,r69021,r69404,r69430) for 1.46.1

[SVN r69502]
This commit is contained in:
Jeremiah Willcock
2011-03-03 00:29:41 +00:00
parent 6e73c470a4
commit 2e4073a8b7
7 changed files with 68 additions and 55 deletions

View File

@@ -217,6 +217,11 @@ namespace boost {
//?? not the right place ?? Lee
typedef boost::forward_traversal_tag multi_pass_input_iterator_tag;
// Forward declare graph_bundle_t property name (from
// boost/graph/properties.hpp, which includes this file) for
// bundled_result.
enum graph_bundle_t {graph_bundle};
template <typename G>
struct graph_property_type {
typedef typename G::graph_property_type type;
@@ -261,6 +266,14 @@ namespace boost {
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;
public:
typedef typename bundler::type type;
};
} } // namespace graph::detail
namespace graph_detail {

View File

@@ -284,18 +284,30 @@ namespace boost {
typedef size_type result_type;
degree_vertex_invariant(const InDegreeMap& in_degree_map, const Graph& g)
: m_in_degree_map(in_degree_map), m_g(g) { }
: m_in_degree_map(in_degree_map),
m_max_vertex_in_degree(0),
m_max_vertex_out_degree(0),
m_g(g) {
BGL_FORALL_VERTICES_T(v, g, Graph) {
m_max_vertex_in_degree =
(std::max)(m_max_vertex_in_degree, get(m_in_degree_map, v));
m_max_vertex_out_degree =
(std::max)(m_max_vertex_out_degree, out_degree(v, g));
}
}
size_type operator()(vertex_t v) const {
return (num_vertices(m_g) + 1) * out_degree(v, m_g)
return (m_max_vertex_in_degree + 1) * out_degree(v, m_g)
+ get(m_in_degree_map, v);
}
// The largest possible vertex invariant number
size_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const {
return num_vertices(m_g) * num_vertices(m_g) + num_vertices(m_g);
return (m_max_vertex_in_degree + 2) * m_max_vertex_out_degree + 1;
}
private:
InDegreeMap m_in_degree_map;
size_type m_max_vertex_in_degree;
size_type m_max_vertex_out_degree;
const Graph& m_g;
};

View File

@@ -126,7 +126,8 @@ namespace boost {
BOOST_DEF_PROPERTY(graph, visitor);
// These tags are used for property bundles
BOOST_DEF_PROPERTY(graph, bundle);
// BOOST_DEF_PROPERTY(graph, bundle); -- needed in graph_traits.hpp, so enum is defined there
BOOST_INSTALL_PROPERTY(graph, bundle);
BOOST_DEF_PROPERTY(vertex, bundle);
BOOST_DEF_PROPERTY(edge, bundle);

View File

@@ -90,12 +90,6 @@ class reverse_graph {
typename graph::detail::bundled_result<BidirectionalGraph, Descriptor>::type const&
operator[](Descriptor x) const
{ return m_g[x]; }
typename boost::graph_property_type<base_type>::type& operator[](graph_bundle_t)
{ return get_property(*this); }
typename boost::graph_property_type<base_type>::type const& operator[](graph_bundle_t) const
{ return get_property(*this); }
#endif // BOOST_GRAPH_NO_BUNDLED_PROPERTIES
static vertex_descriptor null_vertex()

View File

@@ -78,12 +78,12 @@ 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;
// 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;
// IncidenceGraph requirements
typedef typename Traits::out_edge_iterator out_edge_iterator;
@@ -196,12 +196,22 @@ typedef typename Traits::traversal_category traversal_category;
std::pair<vertex_descriptor, bool>
find_vertex(vertex_descriptor u_global) const {
if (is_root()) return std::make_pair(u_global, true);
typename std::map<vertex_descriptor, vertex_descriptor>::const_iterator
i = m_local_vertex.find(u_global);
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));
bool valid = i != m_local_edge.end();
return std::make_pair((valid ? (*i).second : edge_descriptor()), valid);
}
// Return the parent graph.
subgraph& parent() { return *m_parent; }
const subgraph& parent() const { return *m_parent; }
@@ -617,38 +627,18 @@ namespace detail {
//-------------------------------------------------------------------------
// implementation of remove_edge(e,g)
template <typename Edge, typename Graph>
void remove_edge_recur_down(Edge e_global, subgraph<Graph>& g);
template <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) {
if((*i)->find_vertex(source(e_global, **i)).second &&
(*i)->find_vertex(target(e_global, **i)).second)
{
remove_edge_recur_down(source(e_global, **i),
target(e_global, **i),
**i);
std::pair<typename subgraph<G>::edge_descriptor, bool> found =
(*i)->find_edge(e_global);
if (!found.second) {
continue;
}
}
}
template <typename Edge, typename Graph>
void remove_edge_recur_down(Edge e_global, subgraph<Graph>& g)
{
remove_edge(g.global_to_local(e_global), g.m_graph);
children_remove_edge(e_global, g.m_children);
}
template <typename Edge, typename Graph>
void remove_edge_recur_up(Edge e_global, subgraph<Graph>& g)
{
if (g.is_root()) {
remove_edge(e_global, g.m_graph);
children_remove_edge(e_global, g.m_children);
} else {
remove_edge_recur_up(e_global, *g.m_parent);
children_remove_edge<G>(e_global, (*i)->m_children);
remove_edge(found.first, (*i)->m_graph);
}
}
@@ -672,11 +662,14 @@ template <typename G>
void
remove_edge(typename subgraph<G>::edge_descriptor e, subgraph<G>& g)
{
if(g.is_root()) {
detail::remove_edge_recur_up(e, g);
} else {
detail::remove_edge_recur_up(g.local_to_global(e), g);
}
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);
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);
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
@@ -691,7 +684,7 @@ remove_edge_if(Predicate p, subgraph<G>& g) {
if (p(*ep.first)) {
any_removed = true;
remove_edge(*ep.first, g);
continue; /* Since iterators may be invalidated */
break; /* Since iterators may be invalidated */
}
}
if (!any_removed) break;

View File

@@ -99,7 +99,7 @@ transitive_reduction(const Graph& g, GraphTR& tr,
{
//and run through all vertices in topological order
typename std::vector<Vertex>::reverse_iterator
rit = topo_order.rbegin();
rit = topo_order.rbegin(),
rend = topo_order.rend();
for(; rit != rend; ++rit ) {
//looking if they are successors of *it