Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64612 - in sandbox/SOC/2010/graph: boost/graph libs/test
From: dbarbosa_at_[hidden]
Date: 2010-08-05 04:18:59


Author: dbarbosa
Date: 2010-08-05 04:14:45 EDT (Thu, 05 Aug 2010)
New Revision: 64612
URL: http://svn.boost.org/trac/boost/changeset/64612

Log:
Adding a new edge visitor to complement

Text files modified:
   sandbox/SOC/2010/graph/boost/graph/complement.hpp | 20 +++++++++++++++++---
   sandbox/SOC/2010/graph/boost/graph/named_function_params.hpp | 2 ++
   sandbox/SOC/2010/graph/boost/graph/union.hpp | 1 +
   sandbox/SOC/2010/graph/libs/test/property_test.cpp | 21 ++++++++++++++++++---
   4 files changed, 38 insertions(+), 6 deletions(-)

Modified: sandbox/SOC/2010/graph/boost/graph/complement.hpp
==============================================================================
--- sandbox/SOC/2010/graph/boost/graph/complement.hpp (original)
+++ sandbox/SOC/2010/graph/boost/graph/complement.hpp 2010-08-05 04:14:45 EDT (Thu, 05 Aug 2010)
@@ -19,11 +19,19 @@
 
 namespace boost {
   namespace detail {
- template <class Graph, class MutableGraph,
+
+ template <typename EdgeDescriptor, typename Graph>
+ struct default_edge_visitor {
+ void operator()(const EdgeDescriptor &, Graph &) { }
+ };
+
+ template <typename Graph, typename MutableGraph,
               typename CopyVertex,
- typename Orig2OutVertexIndexMap>
+ typename Orig2OutVertexIndexMap,
+ typename NewEdgeVisitor>
     void graph_complement_impl(const Graph& g_in, MutableGraph& g_out,
                                CopyVertex copy_vertex, Orig2OutVertexIndexMap orig2out,
+ NewEdgeVisitor edge_visitor,
                                bool reflexive)
     {
       typedef typename graph_traits<Graph>::vertex_descriptor InVertex;
@@ -49,6 +57,7 @@
                                                    get(orig2out, *vi),
                                                    g_out);
             assert(inserted);
+ edge_visitor(new_e, g_out);
           }
         }
       }
@@ -59,6 +68,7 @@
   void graph_complement(const VertexListGraph& g_in, MutableGraph& g_out, bool reflexive)
   {
     typedef typename graph_traits<MutableGraph>::vertex_descriptor vertex_t;
+ typedef typename graph_traits<MutableGraph>::edge_descriptor edge_t;
     std::vector<vertex_t> orig2out(num_vertices(g_in));
 
     detail::graph_complement_impl
@@ -66,15 +76,17 @@
        detail::make_vertex_copier(g_in, g_out),
        make_iterator_property_map(orig2out.begin(),
                                   get(vertex_index, g_in), orig2out[0]),
+ detail::default_edge_visitor<edge_t, MutableGraph>(),
        reflexive
        );
   }
 
   template <typename VertexListGraph, typename MutableGraph,
- class P, class T, class R>
+ typename P, typename T, typename R>
   void graph_complement(const VertexListGraph& g_in, MutableGraph& g_out,
                         const bgl_named_params<P, T, R>& params, bool reflexive)
   {
+ typedef typename graph_traits<MutableGraph>::edge_descriptor edge_t;
     typename std::vector<T>::size_type n;
     n = is_default_param(get_param(params, orig_to_copy_t()))
       ? num_vertices(g_in) : 1;
@@ -87,6 +99,8 @@
                                     g_in, g_out),
        make_iterator_property_map(orig2out.begin(),
                                   get(vertex_index, g_in), orig2out[0]),
+ choose_param(get_param(params, edge_visitor_t()),
+ detail::default_edge_visitor<edge_t, MutableGraph>()),
        reflexive
        );
   }

Modified: sandbox/SOC/2010/graph/boost/graph/named_function_params.hpp
==============================================================================
--- sandbox/SOC/2010/graph/boost/graph/named_function_params.hpp (original)
+++ sandbox/SOC/2010/graph/boost/graph/named_function_params.hpp 2010-08-05 04:14:45 EDT (Thu, 05 Aug 2010)
@@ -30,6 +30,7 @@
   struct buffer_param_t { };
   struct edge_copy_t { };
   struct vertex_copy_t { };
+ struct edge_visitor_t { };
   struct vertex_isomorphism_t { };
   struct vertex_invariant_t { };
   struct vertex_invariant1_t { };
@@ -79,6 +80,7 @@
     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_CREF(edge_visitor, edge_visitor) \
     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) \

Modified: sandbox/SOC/2010/graph/boost/graph/union.hpp
==============================================================================
--- sandbox/SOC/2010/graph/boost/graph/union.hpp (original)
+++ sandbox/SOC/2010/graph/boost/graph/union.hpp 2010-08-05 04:14:45 EDT (Thu, 05 Aug 2010)
@@ -18,6 +18,7 @@
 
 namespace boost {
 
+ // This is also disjoint! But it uses graph_sum and vertice/edge names
   template <class VertexListGraph, class MutableGraph>
   void graph_union(const VertexListGraph& g1, const VertexListGraph& g2, MutableGraph& g_out)
   {

Modified: sandbox/SOC/2010/graph/libs/test/property_test.cpp
==============================================================================
--- sandbox/SOC/2010/graph/libs/test/property_test.cpp (original)
+++ sandbox/SOC/2010/graph/libs/test/property_test.cpp 2010-08-05 04:14:45 EDT (Thu, 05 Aug 2010)
@@ -43,6 +43,8 @@
 };
 
 
+// First look at main()
+// These are auxiliary functions
 
 // copier that sets the name mapping
 template <typename G1, typename G2>
@@ -66,6 +68,18 @@
   mutable typename property_map<G2, vertex_all_t>::type vertex_all_map2;
 };
 
+// edge visitor for new edges
+template <typename EdgeDescriptor, typename Graph>
+struct my_edge_visitor {
+ void operator()(const EdgeDescriptor &e, Graph &g)
+ {
+ typename graph_traits<Graph>::vertex_descriptor u, v;
+ u = source(e, g);
+ v = target(e, g);
+ g[e].name = g[u].name * 100 + g[v].name;
+ get_property(g, graph_label).hack->edges[ g[e].name ] = e;
+ }
+};
 
 // name vertices and edges
 template <class Graph>
@@ -173,21 +187,22 @@
 
   cout << "Complement of g1:" << endl;
   graph_complement(g1, g_simple_compl, false); // ignore name mapping (but copy vertex properties)
+ // check(g_compl); // graph_complement don't set graph_label
   print(g_simple_compl);
   cout << endl;
 
   cout << "Complement of g1:" << endl;
   my_copier<Graph, Graph> c(g1, g_compl);
   graph_complement(g1, g_compl, vertex_copy(c), false);
- check(g_compl, false); // graph_complement don't set edge names
+ check(g_compl, false); // graph_complement don't set edge names in graph_label, but my_copier do it for vertices
   print(g_compl);
   cout << endl;
 
   cout << "Reflexive complement of g1:" << endl;
   my_copier<Graph, Graph> cc(g1, g_rcompl);
- graph_complement(g1, g_rcompl, vertex_copy(cc), true);
+ graph_complement(g1, g_rcompl, vertex_copy(cc).edge_visitor(my_edge_visitor<Edge, Graph>()), true);
   print(g_rcompl);
- check(g_rcompl, false); // graph_complement don't set edge names
+ check(g_rcompl);
   cout << endl;
 
   cout << "Intersection of g1 and g2:" << endl;


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk