From b0dbc39dfc2552c3cdcebf354d86de23cf2e744f Mon Sep 17 00:00:00 2001 From: Jeremy Siek Date: Fri, 2 Feb 2001 04:38:17 +0000 Subject: [PATCH] added some comments and a copyright [SVN r8851] --- include/boost/graph/subgraph.hpp | 147 +++++++++++++++++++++++++++---- 1 file changed, 130 insertions(+), 17 deletions(-) diff --git a/include/boost/graph/subgraph.hpp b/include/boost/graph/subgraph.hpp index bf554a69..c07b7fea 100644 --- a/include/boost/graph/subgraph.hpp +++ b/include/boost/graph/subgraph.hpp @@ -1,3 +1,28 @@ +//======================================================================= +// Copyright 2001 University of Notre Dame. +// Author: Jeremy G. Siek +// +// This file is part of the Boost Graph Library +// +// You should have received a copy of the License Agreement for the +// Boost Graph Library along with the software; see the file LICENSE. +// If not, contact Office of Research, University of Notre Dame, Notre +// Dame, IN 46556. +// +// Permission to modify the code and to distribute modified code is +// granted, provided the text of this NOTICE is retained, a notice that +// the code was modified is included with the above COPYRIGHT NOTICE and +// with the COPYRIGHT NOTICE in the LICENSE file, and that the LICENSE +// file is distributed with the modified code. +// +// LICENSOR MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. +// By way of example, but not limitation, Licensor MAKES NO +// REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY +// PARTICULAR PURPOSE OR THAT THE USE OF THE LICENSED SOFTWARE COMPONENTS +// OR DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, COPYRIGHTS, TRADEMARKS +// OR OTHER RIGHTS. +//======================================================================= + #ifndef BOOST_SUBGRAPH_HPP #define BOOST_SUBGRAPH_HPP @@ -16,8 +41,10 @@ namespace boost { struct subgraph_tag { }; // Invariants: - // If vertex u is in subgraph g, then u must be in g.parent(). - // If edge e is in subgraph e, then e must be in g.parent(). + // - If vertex u is in subgraph g, then u must be in g.parent(). + // - If edge e is in subgraph e, then e must be in g.parent(). + // - If edge e=(u,v) is in the root graph, then edge e + // is also in any subgraph that contains both vertex u and v. // The Graph template parameter must have a vertex_index // and edge_index internal property. It is assumed that @@ -31,10 +58,10 @@ namespace boost { typedef graph_traits Traits; 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::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; // IncidenceGraph requirements typedef typename Traits::out_edge_iterator out_edge_iterator; @@ -56,6 +83,7 @@ namespace boost { typedef typename Graph::edge_property_type edge_property_type; typedef typename Graph::vertex_property_type vertex_property_type; typedef subgraph_tag graph_tag; + typedef Graph graph_type; // Constructors @@ -73,6 +101,18 @@ namespace boost { { m_parent->add_child(this); } + // Create a subgraph with the specified vertex set. + template + subgraph(subgraph& parent, + VertexIterator first, VertexIterator last) + : m_parent(&parent), + m_vertex_membership(num_vertices(parent.m_graph), false), + m_local_vertex(num_vertices(parent)), + m_edge_counter(0) + { + for (; first != last; ++first) + add_vertex(*first, *this); + } // local <-> global descriptor conversion functions vertex_descriptor local_to_global(vertex_descriptor u_local) @@ -122,9 +162,9 @@ namespace boost { typedef typename property_map::type EdgeIndexMap; typedef typename property_traits::value_type edge_index_type; - std::vector m_global_edge; // local -> global + std::vector m_global_edge; // local -> global std::map m_local_edge; // global -> local - edge_index_type m_edge_counter; + edge_index_type m_edge_counter; // for generating unique edge indices edge_descriptor local_add_edge(vertex_descriptor u_local, vertex_descriptor v_local, @@ -344,6 +384,7 @@ namespace boost { namespace detail { + //------------------------------------------------------------------------- // implementation of remove_edge(u,v,g) template @@ -382,6 +423,7 @@ namespace boost { remove_edge_recur_up(u_global, v_global, *g.m_parent); } + //------------------------------------------------------------------------- // implementation of remove_edge(e,g) template @@ -489,35 +531,106 @@ namespace boost { //=========================================================================== // Functions required by the PropertyGraph concept + template + class subgraph_property_map + : public put_get_at_helper< + typename property_traits< + typename property_map::type + >::value_type, + subgraph_property_map > + { + typedef typename property_map::type PropertyMap; + public: + typedef typename property_traits::value_type value_type; + typedef Key key_type; + + subgraph_property_map() { } + + subgraph_property_map(subgraph& g) + : m_g(&g), m_pmap(get(Property, g.root())) { } + + inline value_type& operator[](key_type e_local) { + if (m_g->m_parent == 0) + return m_pmap[e_local]; + else + return m_pmap[m_g->local_to_global(e_local)]; + } + inline const value_type& operator[](key_type e_local) const { + if (m_g->m_parent == 0) + return m_pmap[e_local]; + else + return m_pmap[m_g->local_to_global(e_local)]; + } + subgraph* m_g; + ProperyMap m_pmap; + }; + + namespace detail { + + struct subgraph_vertex_property_selector { + template + struct bind { + typedef subgraph_property_map type; + typedef type const_type; + }; + }; + + struct subgraph_edge_property_selector { + template + struct bind { + typedef subgraph_property_map type; + typedef type const_type; + }; + }; + + } // namespace detail + + template <> + struct vertex_property_selector { + typedef detail::subgraph_vertex_property_selector type; + }; + + template <> + struct edge_property_selector { + typedef detail::subgraph_edge_property_selector type; + }; + template typename property_map::type - get(Property p, subgraph& g) + get(Property, subgraph& g) { - return get(p, g.m_graph); + typedef typename property_map::type PMap; + return PMap(g); } template typename property_map::const_type - get(Property p, const subgraph& g) + get(Property, const subgraph& g) { - return get(p, g.m_graph); + typedef typename property_map::const_type PMap; + return PMap(g); } template typename property_traits< typename property_map::const_type >::value_type - get(Property p, const subgraph& g, const Key& k) + get(Property, const subgraph& g, const Key& k) { - return get(p, g.m_graph, k); + typedef typename property_map::const_type PMap; + PMap pmap(g); + return pmap[k]; } template void - put(Property p, const subgraph& g, const Key& k, - const Value& val) + put(Property, const subgraph& g, const Key& k, const Value& val) { - put(p, g.m_graph, k, val); + typedef typename property_map::const_type PMap; + PMap pmap(g); + pmap[k] = val; }