|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r64737 - in sandbox/SOC/2010/graph: boost/graph libs/test
From: dbarbosa_at_[hidden]
Date: 2010-08-11 05:39:40
Author: dbarbosa
Date: 2010-08-11 05:39:39 EDT (Wed, 11 Aug 2010)
New Revision: 64737
URL: http://svn.boost.org/trac/boost/changeset/64737
Log:
Removing everything about global vertex mapping
Removing auto keyword
Fixing warnings when using bjam
Removed:
sandbox/SOC/2010/graph/boost/graph/global_vertex_mapping.hpp
sandbox/SOC/2010/graph/libs/test/globalid.cpp
sandbox/SOC/2010/graph/libs/test/test.cpp
Text files modified:
sandbox/SOC/2010/graph/boost/graph/difference.hpp | 55 ++------------------------
sandbox/SOC/2010/graph/boost/graph/intersection.hpp | 56 ++-------------------------
sandbox/SOC/2010/graph/boost/graph/sum.hpp | 81 +++------------------------------------
sandbox/SOC/2010/graph/libs/test/Jamfile | 3
sandbox/SOC/2010/graph/libs/test/property_test.cpp | 6 -
5 files changed, 20 insertions(+), 181 deletions(-)
Modified: sandbox/SOC/2010/graph/boost/graph/difference.hpp
==============================================================================
--- sandbox/SOC/2010/graph/boost/graph/difference.hpp (original)
+++ sandbox/SOC/2010/graph/boost/graph/difference.hpp 2010-08-11 05:39:39 EDT (Wed, 11 Aug 2010)
@@ -12,7 +12,6 @@
#define BOOST_GRAPH_DIFFERENCE_HPP
#include <utility>
-#include <boost/graph/global_vertex_mapping.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/default.hpp>
@@ -30,9 +29,9 @@
typedef typename graph_traits<Graph>::vertex_descriptor InVertex;
typedef typename graph_traits<MutableGraph>::vertex_descriptor OutVertex;
- auto & gl1 = get_property(g1);
- auto & gl2 = get_property(g2);
- auto & gl_out = get_property(g_out);
+ //typename graph_bundle_type<Graph>::type const& gl1 = get_property(g1);
+ typename graph_bundle_type<Graph>::type const& gl2 = get_property(g2);
+ typename graph_bundle_type<MutableGraph>::type& gl_out = get_property(g_out);
typename graph_traits < Graph >::vertex_iterator vi, vi_end;
// copy vertices from g1
@@ -47,8 +46,8 @@
// copy edges from g1 that are not in g2
typename graph_traits < Graph >::edge_iterator ei, ei_end;
for (tie(ei, ei_end) = edges(g1); ei != ei_end; ++ei) {
- auto src = g1[source(*ei, g1)].name;
- auto targ = g1[target(*ei, g1)].name;
+ size_t src = g1[source(*ei, g1)].name;
+ size_t targ = g1[target(*ei, g1)].name;
assert( gl_out.vertices.find(src) != gl_out.vertices.end() );
assert( gl_out.vertices.find(targ) != gl_out.vertices.end() );
@@ -95,50 +94,6 @@
detail::default_set_edge_label<MutableGraph>())
);
}
-
- // Version with globalVertexMapping
- template <class VertexListGraph, class MutableGraph, class globalVertexMapping>
- void gvm_graph_difference(const VertexListGraph& g1, const VertexListGraph& g2, globalVertexMapping m, MutableGraph& g_out)
- {
- typedef typename graph_traits<VertexListGraph>::vertex_descriptor InVertex;
- typedef typename graph_traits<MutableGraph>::vertex_descriptor OutVertex;
-
- detail::vertex_copier<VertexListGraph, MutableGraph> copy_vertex = detail::make_vertex_copier(g1, g_out);
- detail::edge_copier<VertexListGraph, MutableGraph> copy_edge = detail::make_edge_copier(g1, g_out);
-
- // copy vertices from g1
- typename graph_traits < VertexListGraph >::vertex_iterator vi, vi_end;
- for (tie(vi, vi_end) = vertices(g1); vi != vi_end; ++vi) {
- OutVertex new_v = add_vertex(g_out);
- copy_vertex(*vi, new_v);
- std::pair < typename globalVertexMapping::global_id_type, bool > id = m.get_id(g1, *vi);
- assert (id.second == true);
- m.associate(g_out, new_v, id.first);
- }
-
-
- // copy edges from g1 that are not in g2
- typename graph_traits < VertexListGraph >::edge_iterator ei, ei_end;
- for (tie(ei, ei_end) = edges(g1); ei != ei_end; ++ei) {
- std::pair < InVertex, bool > g2_s, g2_t;
- std::pair < OutVertex, bool > out_s, out_t;
- g2_s = m.find_vertex( g1, source(*ei, g1), g2 );
- g2_t = m.find_vertex( g1, target(*ei, g1), g2 );
- out_s = m.find_vertex( g1, source(*ei, g1), g_out );
- out_t = m.find_vertex( g1, target(*ei, g1), g_out );
-
- assert(out_s.second == true && out_t.second == true);
-
- if ( ! (g2_s.second && g2_t.second && edge(g2_s.first, g2_t.first, g2).second) ) {
- typename graph_traits<MutableGraph>::edge_descriptor new_e;
- bool inserted;
- boost::tie(new_e, inserted) = add_edge(out_s.first, out_t.first, g_out);
- copy_edge(*ei, new_e); // -> should copy vertex properties here
- }
- }
-
- }
-
} // namespace boost
#endif // BOOST_GRAPH_DIFFERENCE_HPP
Deleted: sandbox/SOC/2010/graph/boost/graph/global_vertex_mapping.hpp
==============================================================================
--- sandbox/SOC/2010/graph/boost/graph/global_vertex_mapping.hpp 2010-08-11 05:39:39 EDT (Wed, 11 Aug 2010)
+++ (empty file)
@@ -1,98 +0,0 @@
-#ifndef BOOST_GRAPH_GLOBAL_VERTEX_MAPPING_HPP
-#define BOOST_GRAPH_GLOBAL_VERTEX_MAPPING_HPP
-
-#include <utility>
-#include <map>
-#include <boost/bimap.hpp>
-#include <boost/graph/graph_traits.hpp>
-
-namespace boost {
- template <class Graph, typename id_type = int, typename graph_name_type = std::string>
- class GlobalVertexMapping
- {
- private:
- typedef typename graph_traits<const Graph>::vertex_descriptor Vertex;
- typedef typename boost::bimap < Vertex, id_type > bm_type;
- typedef typename bm_type::value_type association;
-
- struct labelling {
- graph_name_type name;
- bm_type mapping;
- };
-
- std::map < const Graph *, labelling > graph_labelling;
- id_type dummy_id;
- Vertex dummy_vertex;
-
- public:
- typedef id_type global_id_type;
-
- GlobalVertexMapping (Vertex dummy_vertex_arg, id_type dummy_id_arg)
- : dummy_vertex(dummy_vertex_arg), dummy_id(dummy_id_arg) { }
-
- void add_graph(const Graph &G, graph_name_type name)
- {
- graph_labelling[&G].name = name;
- }
-
- void associate(const Graph &G, Vertex v, id_type id)
- {
- graph_labelling[&G].mapping.insert( association( v, id ));
- }
-
- std::pair < Vertex, bool > find_vertex(const Graph &G, Vertex v, const Graph &g_out)
- {
- std::pair < id_type, bool > id = get_id(G, v);
- if (id.second == false)
- return std::pair<Vertex, bool> (dummy_vertex, false);
- return get_vertex(g_out, id.first);
- }
-
- std::pair < Vertex, bool > get_vertex(const Graph &G, id_type id)
- {
- try {
- return std::pair<Vertex, bool> (graph_labelling[&G].mapping.right.at(id), true);
- }
- catch ( std::out_of_range & e ) {
- return std::pair<Vertex, bool> (dummy_vertex, false);
- }
- }
-
- std::pair < id_type, bool > get_id(const Graph &G, Vertex v)
- {
- try {
- return std::pair<id_type, bool> (graph_labelling[&G].mapping.left.at(v), true);
- }
- catch ( std::out_of_range & e ) {
- return std::pair<id_type, bool> (dummy_id, false);
- }
- }
-
- bool equal(const Graph &G1, Vertex v1, const Graph &G2, Vertex v2)
- {
- typename std::map < const Graph *, labelling >::const_iterator
- i1 = graph_labelling.find(&G1), i2 = graph_labelling.find(&G2);
- if (i1 == graph_labelling.end() || i2 == graph_labelling.end())
- return false;
- bm_type m1 = i1->second.mapping, m2 = i2->second.mapping;
- typename bm_type::left_const_iterator b1 = m1.left.find(v1), b2 = m2.left.find(v2);
- if (b1 == m1.left.end() || b2 == m2.left.end())
- return false;
- return b1->second == b2->second;
- }
-
- void show_associations()
- {
- typename std::map < const Graph *, labelling >::const_iterator iter;
- for ( iter = graph_labelling.begin(); iter != graph_labelling.end(); iter++) {
- labelling l = iter->second;
- std::cout << "Graph " << l.name << ": (" << l.mapping.size() << " associations)" << std::endl;
- typename bm_type::const_iterator liter, lend = l.mapping.end();
- for ( liter = l.mapping.begin(); liter != lend; liter++ )
- std::cout << " " << liter->left << " <--> " << liter->right << std::endl;
- }
- }
- };
-}
-
-#endif
Modified: sandbox/SOC/2010/graph/boost/graph/intersection.hpp
==============================================================================
--- sandbox/SOC/2010/graph/boost/graph/intersection.hpp (original)
+++ sandbox/SOC/2010/graph/boost/graph/intersection.hpp 2010-08-11 05:39:39 EDT (Wed, 11 Aug 2010)
@@ -12,7 +12,6 @@
#define BOOST_GRAPH_INTERSECTION_HPP
#include <utility>
-#include <boost/graph/global_vertex_mapping.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/default.hpp>
@@ -30,9 +29,9 @@
typedef typename graph_traits<Graph>::vertex_descriptor InVertex;
typedef typename graph_traits<MutableGraph>::vertex_descriptor OutVertex;
- auto & gl1 = get_property(g1);
- auto & gl2 = get_property(g2);
- auto & gl_out = get_property(g_out);
+ //typename graph_bundle_type<Graph>::type const& gl1 = get_property(g1);
+ typename graph_bundle_type<Graph>::type const& gl2 = get_property(g2);
+ typename graph_bundle_type<MutableGraph>::type& gl_out = get_property(g_out);
// copy vertices from (g1 intersection g2)
typename graph_traits < Graph >::vertex_iterator vi, vi_end;
@@ -51,15 +50,14 @@
bool inserted;
// copy edges from (g1 intersection g2)
for (tie(ei, ei_end) = edges(g1); ei != ei_end; ++ei) {
- auto src = g1[source(*ei, g1)].name;
- auto targ = g1[target(*ei, g1)].name;
+ size_t src = g1[source(*ei, g1)].name;
+ size_t targ = g1[target(*ei, g1)].name;
assert( gl_out.vertices.find(src) != gl_out.vertices.end() );
assert( gl_out.vertices.find(targ) != gl_out.vertices.end() );
if ( gl2.edges.find( g1[*ei].name ) != gl2.edges.end() ) { // if ei is in g2
boost::tie(new_e, inserted) = add_edge(gl_out.vertices[src], gl_out.vertices[targ], g_out);
assert( inserted );
- // merge_edges(*ei, g1, gl2.edges[ g1[*ei].name ], g2, new_e, g_out); // Does not compile! Why?
merge_edges(*ei, g1, gl2.edges.find( g1[*ei].name )->second, g2, new_e, g_out);
set_edge_label(g1[*ei].name, new_e, g_out);
assert( g_out[new_e].name == g1[*ei].name ); // set_edge_label did it
@@ -98,50 +96,6 @@
detail::default_set_edge_label<MutableGraph>())
);
}
-
- // Version with globalVertexMapping
- template <class Graph, class MutableGraph, class globalVertexMapping>
- void gvm_graph_intersection(const Graph& g1, const Graph& g2, globalVertexMapping m, MutableGraph& g_out)
- {
- typedef typename graph_traits<Graph>::vertex_descriptor InVertex;
- typedef typename graph_traits<MutableGraph>::vertex_descriptor OutVertex;
-
- detail::vertex_copier<Graph, MutableGraph> copy_vertex = detail::make_vertex_copier(g1, g_out);
- detail::edge_copier<Graph, MutableGraph> copy_edge = detail::make_edge_copier(g1, g_out);
-
- // copy vertices from (g1 intersection g2)
- typename graph_traits < Graph >::vertex_iterator vi, vi_end;
- for (tie(vi, vi_end) = vertices(g1); vi != vi_end; ++vi) {
- std::pair < InVertex, bool > v = m.find_vertex( g1, *vi, g2 ); // search for vi in g2
- if (v.second == true) { // vi is also in g2
- OutVertex new_v = add_vertex(g_out);
- copy_vertex(*vi, new_v);
- std::pair < typename globalVertexMapping::global_id_type, bool > id = m.get_id(g1, *vi);
- assert (id.second == true);
- m.associate(g_out, new_v, id.first);
- }
- }
-
- // copy edges from (g1 intersection g2)
- typename graph_traits < Graph >::edge_iterator ei, ei_end;
- for (tie(ei, ei_end) = edges(g1); ei != ei_end; ++ei) {
- std::pair < InVertex, bool > g2_s, g2_t;
- std::pair < OutVertex, bool > out_s, out_t;
- g2_s = m.find_vertex( g1, source(*ei, g1), g2 );
- g2_t = m.find_vertex( g1, target(*ei, g1), g2 );
- out_s = m.find_vertex( g1, source(*ei, g1), g_out );
- out_t = m.find_vertex( g1, target(*ei, g1), g_out );
-
- if ( (g2_s.second && g2_t.second && edge(g2_s.first, g2_t.first, g2).second) ) {
- assert(out_s.second == true && out_t.second == true);
- typename graph_traits<MutableGraph>::edge_descriptor new_e;
- bool inserted;
- boost::tie(new_e, inserted) = add_edge(out_s.first, out_t.first, g_out);
- copy_edge(*ei, new_e);
- }
- }
- }
-
} // namespace boost
#endif // BOOST_GRAPH_INTERSECTION_HPP
Modified: sandbox/SOC/2010/graph/boost/graph/sum.hpp
==============================================================================
--- sandbox/SOC/2010/graph/boost/graph/sum.hpp (original)
+++ sandbox/SOC/2010/graph/boost/graph/sum.hpp 2010-08-11 05:39:39 EDT (Wed, 11 Aug 2010)
@@ -12,7 +12,6 @@
#define BOOST_GRAPH_SUM_HPP
#include <utility>
-#include <boost/graph/global_vertex_mapping.hpp>
#include <boost/graph/default.hpp>
#include <boost/graph/graph_traits.hpp>
@@ -32,9 +31,9 @@
typedef typename graph_traits<Graph>::vertex_descriptor InVertex;
typedef typename graph_traits<MutableGraph>::vertex_descriptor OutVertex;
- auto & gl1 = get_property(g1);
- auto & gl2 = get_property(g2);
- auto & gl_out = get_property(g_out);
+ //typename graph_bundle_type<Graph>::type const& gl1 = get_property(g1);
+ typename graph_bundle_type<Graph>::type const& gl2 = get_property(g2);
+ typename graph_bundle_type<MutableGraph>::type& gl_out = get_property(g_out);
typename graph_traits < Graph >::vertex_iterator vi, vi_end;
// copy vertices from g1
@@ -47,8 +46,6 @@
assert( gl_out.vertices[ g1[*vi].name ] == new_v ); // set_vertex_label did it
} else { // vi is also in g2, we should merge them
OutVertex new_v = add_vertex(g_out);
- InVertex v1 = *vi;
- // merge_vertices(v1, g1, gl2.vertices[ g1[*vi].name ], g2, new_v, g_out); // Does not compile! Why?
merge_vertices(*vi, g1, gl2.vertices.find ( g1[*vi].name )->second, g2, new_v, g_out);
set_vertex_label(g1[*vi].name, new_v, g_out);
assert( g_out[new_v].name == g1[*vi].name ); // set_vertex_label did it
@@ -72,8 +69,8 @@
// copy edges from g1
for (tie(ei, ei_end) = edges(g1); ei != ei_end; ++ei) {
- auto src = g1[source(*ei, g1)].name;
- auto targ = g1[target(*ei, g1)].name;
+ size_t src = g1[source(*ei, g1)].name;
+ size_t targ = g1[target(*ei, g1)].name;
assert( gl_out.vertices.find(src) != gl_out.vertices.end() );
assert( gl_out.vertices.find(targ) != gl_out.vertices.end() );
@@ -87,7 +84,6 @@
} else {
boost::tie(new_e, inserted) = add_edge(gl_out.vertices[src], gl_out.vertices[targ], g_out);
assert( inserted );
- // merge_edges(*ei, g1, gl2.edges[ g1[*ei].name ], g2, new_e, g_out); // Does not compile! Why?
merge_edges(*ei, g1, gl2.edges.find( g1[*ei].name )->second, g2, new_e, g_out);
set_edge_label(g1[*ei].name, new_e, g_out);
assert( g_out[new_e].name == g1[*ei].name ); // set_edge_label did it
@@ -96,8 +92,8 @@
}
// copy edges from g2 if it is *not* already there
for (tie(ei, ei_end) = edges(g2); ei != ei_end; ++ei) {
- auto src = g2[source(*ei, g2)].name;
- auto targ = g2[target(*ei, g2)].name;
+ size_t src = g2[source(*ei, g2)].name;
+ size_t targ = g2[target(*ei, g2)].name;
assert( gl_out.vertices.find(src) != gl_out.vertices.end() );
assert( gl_out.vertices.find(targ) != gl_out.vertices.end() );
@@ -149,69 +145,6 @@
detail::default_set_edge_label<MutableGraph>())
);
}
-
- // Version with globalVertexMapping
- template <typename Graph, typename MutableGraph, typename globalVertexMapping>
- void gvm_graph_sum(const Graph& g1, const Graph& g2, globalVertexMapping m, MutableGraph& g_out)
- {
- typedef typename graph_traits<Graph>::vertex_descriptor InVertex;
- typedef typename graph_traits<MutableGraph>::vertex_descriptor OutVertex;
- typedef typename globalVertexMapping::global_id_type id_type;
-
- detail::vertex_copier<Graph, MutableGraph>
- copy_vertex1 = detail::make_vertex_copier(g1, g_out), copy_vertex2 = detail::make_vertex_copier(g2, g_out);
- detail::edge_copier<Graph, MutableGraph>
- copy_edge1 = detail::make_edge_copier(g1, g_out), copy_edge2 = detail::make_edge_copier(g2, g_out);
-
-
- typename graph_traits < Graph >::vertex_iterator vi, vi_end;
- // copy vertices from g1
- for (tie(vi, vi_end) = vertices(g1); vi != vi_end; ++vi) {
- OutVertex new_v = add_vertex(g_out);
- copy_vertex1(*vi, new_v);
- std::pair < typename globalVertexMapping::global_id_type, bool > id = m.get_id(g1, *vi);
- assert (id.second == true);
- m.associate(g_out, new_v, id.first);
- }
- // copy vertices from (g2 - g1)
- for (tie(vi, vi_end) = vertices(g2); vi != vi_end; ++vi) {
- std::pair < InVertex, bool > v = m.find_vertex( g2, *vi, g1 ); // search for vi in g1
- if (v.second == false) { // vi is not in g1
- OutVertex new_v = add_vertex(g_out);
- copy_vertex2(*vi, new_v);
- std::pair < id_type, bool > id = m.get_id(g2, *vi);
- assert (id.second == true);
- m.associate(g_out, new_v, id.first);
- }
- }
-
- typename graph_traits < Graph >::edge_iterator ei, ei_end;
- // copy edges from g1
- for (tie(ei, ei_end) = edges(g1); ei != ei_end; ++ei) {
- std::pair < OutVertex, bool > out_s, out_t;
- out_s = m.find_vertex( g1, source(*ei, g1), g_out );
- out_t = m.find_vertex( g1, target(*ei, g1), g_out );
- assert(out_s.second == true && out_t.second == true);
-
- typename graph_traits<MutableGraph>::edge_descriptor new_e;
- bool inserted;
- boost::tie(new_e, inserted) = add_edge(out_s.first, out_t.first, g_out);
- copy_edge1(*ei, new_e);
- }
- // copy edges from g2
- for (tie(ei, ei_end) = edges(g2); ei != ei_end; ++ei) {
- std::pair < OutVertex, bool > out_s, out_t;
- out_s = m.find_vertex( g2, source(*ei, g2), g_out );
- out_t = m.find_vertex( g2, target(*ei, g2), g_out );
- assert(out_s.second == true && out_t.second == true);
-
- typename graph_traits<MutableGraph>::edge_descriptor new_e;
- bool inserted;
- boost::tie(new_e, inserted) = add_edge(out_s.first, out_t.first, g_out);
- copy_edge2(*ei, new_e);
- }
- }
-
} // namespace boost
#endif // BOOST_GRAPH_SUM_HPP
Modified: sandbox/SOC/2010/graph/libs/test/Jamfile
==============================================================================
--- sandbox/SOC/2010/graph/libs/test/Jamfile (original)
+++ sandbox/SOC/2010/graph/libs/test/Jamfile 2010-08-11 05:39:39 EDT (Wed, 11 Aug 2010)
@@ -20,7 +20,6 @@
# as part of the test suite.
test-suite graph_test
:
- [ run test.cpp ]
- [ run globalid.cpp ]
[ run property_test.cpp ]
+ [ run disjoint_union.cpp ]
;
Deleted: sandbox/SOC/2010/graph/libs/test/globalid.cpp
==============================================================================
--- sandbox/SOC/2010/graph/libs/test/globalid.cpp 2010-08-11 05:39:39 EDT (Wed, 11 Aug 2010)
+++ (empty file)
@@ -1,138 +0,0 @@
-#include <iostream>
-#include <utility>
-#include <algorithm>
-
-#include <boost/graph/adjacency_list.hpp>
-#include <boost/graph/graph_utility.hpp>
-
-#include <boost/graph/global_vertex_mapping.hpp>
-
-#include <boost/graph/difference.hpp>
-#include <boost/graph/intersection.hpp>
-#include <boost/graph/sum.hpp>
-
-using namespace boost;
-using namespace std;
-
-// create a typedef for the Graph type
-typedef adjacency_list < vecS, vecS, bidirectionalS, property < vertex_name_t, char > > Graph;
-typedef pair < int, int > Edge;
-
-// if d == 1 creates a cycle
-Graph create_graph(int n, int d)
-{
- // declare a graph object
- Graph g(n);
- char name = 'a';
- property_map < Graph, vertex_name_t >::type name_map = get(vertex_name, g);
- graph_traits < Graph >::vertex_iterator vi, vi_end;
-
- // add the edges to the graph object
- for (int i = 0; i < n; ++i) {
- add_edge(i, (i-d+n)%n, g);
- add_edge(i, (i+d)%n, g);
- }
-
- for (tie(vi, vi_end) = vertices(g); vi != vi_end; vi++, name++)
- name_map[*vi] = name;
-
- return g;
-}
-
-
-int main(int,char*[])
-{
- // Make convenient labels for the vertices
- enum { E, D, C, B, A, N };
- const int num_vertices = N;
- const char name[] = "ABCDE";
- Edge edge_array[] =
- { Edge(A,B), Edge(A,D), Edge(C,A), Edge(D,C),
- Edge(C,E), Edge(B,D), Edge(D,E), };
- const int num_edges = sizeof(edge_array)/sizeof(edge_array[0]);
- typedef graph_traits<Graph>::vertex_iterator vertex_iter;
-
- // declare a graph object, adding the edges and edge properties
- Graph g1(edge_array, edge_array + num_edges, num_vertices);
- property_map < Graph, vertex_index_t>::type vertex_id = get(vertex_index, g1);
- property_map < Graph, vertex_name_t >::type name_map1 = get(vertex_name, g1);
-
- for (std::pair<vertex_iter, vertex_iter> vp = vertices(g1); vp.first != vp.second; ++vp.first) {
- int id = get(vertex_id, *vp.first);
- name_map1[id] = name[id];
- }
-
- graph_traits<Graph>::edge_iterator ei, ei_end;
- cout << "edges = ";
- for (tie(ei, ei_end) = edges(g1); ei != ei_end; ++ei)
- cout << "(" << vertex_id[source(*ei, g1)]
- << "," << vertex_id[target(*ei, g1)] << ") ";
- cout << endl;
-
-
- print_graph(g1, name_map1);
-
- Graph g2 = create_graph(5,1);
- property_map < Graph, vertex_name_t >::type name_map2 = get(vertex_name, g2);
- print_graph(g2, name_map2);
-
-
-
-
- GlobalVertexMapping < Graph, int, string > globalId(*vertices(g1).second, -2);
- globalId.add_graph(g1,"g1");
- globalId.add_graph(g2,"g2");
- globalId.associate(g1,0,0);
- globalId.associate(g1,1,1);
- globalId.associate(g1,1,0); // does nothing because (g1,1) is already associated to 1
- globalId.associate(g1,0,1); // does nothing because (g1,0) is already associated to 0
- globalId.associate(g1,2,2);
- globalId.associate(g1,3,3);
- globalId.associate(g1,4,4);
-
- globalId.associate(g2,0,4);
- globalId.associate(g2,1,3);
- globalId.associate(g2,2,2);
- globalId.associate(g2,3,1);
- globalId.associate(g2,4,0);
-
- globalId.show_associations();
-
- assert( globalId.equal(g1,0, g2,4));
- assert( globalId.equal(g1,1, g2,3));
- assert( globalId.equal(g1,2, g2,2));
- assert( globalId.equal(g1,3, g2,1));
- assert( globalId.equal(g1,4, g2,0));
-
- assert(!globalId.equal(g1,0, g2,0));
- assert(!globalId.equal(g1,0, g2,1));
- assert(!globalId.equal(g1,0, g2,2));
- assert(!globalId.equal(g1,0, g2,3));
- assert(!globalId.equal(g1,1, g2,0));
- assert(!globalId.equal(g1,1, g2,1));
- assert(!globalId.equal(g1,1, g2,2));
- assert(!globalId.equal(g1,1, g2,4));
-
- assert( globalId.get_id(g1,0).first == 0 );
- assert( globalId.get_id(g1,1).first == 1 );
- assert( globalId.get_id(g2,0).first == 4 );
- assert( globalId.get_id(g2,3).first == 1 );
- assert( globalId.get_id(g2,4).first == 0 );
-
- cout << "g1 + g2:" << endl;
- Graph gs;
- gvm_graph_sum(g1, g2, globalId, gs);
- print_graph(gs);
-
- cout << "g1 - g2:" << endl;
- Graph gd;
- gvm_graph_difference(g1, g2, globalId, gd);
- print_graph(gd);
-
- cout << "g1 intersection g2:" << endl;
- Graph gi;
- gvm_graph_intersection(g1, g2, globalId, gi);
- print_graph(gi);
-
- return 0;
-}
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-11 05:39:39 EDT (Wed, 11 Aug 2010)
@@ -61,9 +61,8 @@
typedef typename graph_traits<G1>::vertex_descriptor Vertex1;
typedef typename graph_traits<G2>::vertex_descriptor Vertex2;
void operator()(const Vertex1& v1, const G1& g1, Vertex2& v2, G2& g2) const {
- auto & gl2 = get_property(g2).vertices;
put(get(vertex_all, g2), v2, get(get(vertex_all, g1), v1));
- gl2[ g1[v1].name ] = v2;
+ get_property(g2).vertices[ g1[v1].name ] = v2;
}
};
@@ -73,9 +72,8 @@
typedef typename graph_traits<G1>::edge_descriptor Edge1;
typedef typename graph_traits<G2>::edge_descriptor Edge2;
void operator()(const Edge1& e1, const G1& g1, Edge2& e2, G2& g2) const {
- auto & gl2 = get_property(g2).edges;
put(get(edge_all, g2), e2, get(get(edge_all, g1), e1));
- gl2[ g1[e1].name ] = e2;
+ get_property(g2).edges[ g1[e1].name ] = e2;
}
};
Deleted: sandbox/SOC/2010/graph/libs/test/test.cpp
==============================================================================
--- sandbox/SOC/2010/graph/libs/test/test.cpp 2010-08-11 05:39:39 EDT (Wed, 11 Aug 2010)
+++ (empty file)
@@ -1,250 +0,0 @@
-//
-//=======================================================================
-// Copyright (C) 2010 Davi M. J. Barbosa
-//
-// 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)
-//=======================================================================
-//
-
-#include <iostream> // for std::cout
-#include <utility> // for std::pair
-#include <algorithm> // for std::for_each
-
-#include <boost/graph/adjacency_list.hpp>
-#include <boost/graph/graph_utility.hpp>
-
-#include <boost/graph/global_vertex_mapping.hpp>
-
-#include <boost/graph/union.hpp>
-#include <boost/graph/sum.hpp>
-#include <boost/graph/intersection.hpp>
-#include <boost/graph/difference.hpp>
-
-
-using namespace boost;
-using namespace std;
-
-// create a typedef for the Graph type
-typedef adjacency_list < vecS, vecS, bidirectionalS, property < vertex_name_t, char > > Graph;
-typedef pair<int, int> Edge;
-
-/*******************************************
- * Just playing with BGL in this beginning
- */
-
-template <class Graph> struct exercise_vertex {
- exercise_vertex(Graph& g_) : g(g_) {}
- typedef graph_traits<Graph> GraphTraits;
- typedef typename GraphTraits::vertex_descriptor Vertex;
-
- void operator()(const Vertex& v) const
- {
- typename property_map<Graph, vertex_index_t>::type index = get(vertex_index, g);
- typename GraphTraits::out_edge_iterator out_i, out_end;
- typename GraphTraits::in_edge_iterator in_i, in_end;
- typename GraphTraits::adjacency_iterator ai, ai_end;
- typename GraphTraits::edge_descriptor e;
-
- cout << "vertex " << index[v] << "" << endl;
- cout << " out-edges: ";
- for (tie(out_i, out_end) = out_edges(v, g); out_i != out_end; ++out_i) {
- e = *out_i;
- Vertex src = source(e, g), targ = target(e, g);
- cout << "(" << index[src] << "," << index[targ] << ") ";
- }
- cout << endl;
-
- cout << " in-edges: ";
- for (tie(in_i, in_end) = in_edges(v,g); in_i != in_end; ++in_i) {
- e = *in_i;
- Vertex src = source(e, g), targ = target(e, g);
- cout << "(" << index[src] << "," << index[targ] << ") ";
- }
- cout << endl;
-
- cout << " adjacent vertices: ";
- for (tie(ai, ai_end) = adjacent_vertices(v, g); ai != ai_end; ++ai)
- cout << index[*ai] << " ";
- cout << endl;
-
-
- }
-
- //...
- Graph& g;
-};
-
-
-void prt_vertices(Graph g) {
- // get the property map for vertex indices
- property_map<Graph, vertex_index_t>::type index = get(vertex_index, g);
- graph_traits<Graph>::vertex_iterator vi, vi_end;
-
- cout << "vertices = ";
- for (tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi)
- cout << index[*vi] << " ";
- cout << endl;
-}
-
-void prt_edges(Graph g) {
- // get the property map for vertex indices
- property_map<Graph, vertex_index_t>::type index = get(vertex_index, g);
- graph_traits<Graph>::edge_iterator ei, ei_end;
-
- cout << "edges = ";
- for (tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
- cout << "(" << index[source(*ei, g)]
- << "," << index[target(*ei, g)] << ") ";
- cout << endl;
-}
-
-void explore(Graph g) {
- exercise_vertex<Graph> blerg(g);
-
- for_each(vertices(g).first, vertices(g).second,
- exercise_vertex<Graph>(g));
-
- graph_traits<Graph>::vertex_iterator vi, vi_end;
- for (tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi)
- blerg(*vi);
-}
-
-void prt(Graph g) {
- property_map < Graph, vertex_name_t >::type name_map = get(vertex_name, g);
- print_graph(g, name_map);
- prt_vertices(g);
- prt_edges(g);
-}
-
-
-
-
-/*******************************************
- * To create graphs...
- */
-
-// if d == 1 creates a cycle
-Graph create_graph(int n, int d)
-{
- // declare a graph object
- Graph g(n);
- char name = 'a';
- property_map < Graph, vertex_name_t >::type name_map = get(vertex_name, g);
- graph_traits < Graph >::vertex_iterator vi, vi_end;
-
- // add the edges to the graph object
- for (int i = 0; i < n; ++i) {
- add_edge(i, (i-d+n)%n, g);
- add_edge(i, (i+d)%n, g);
- }
-
- for (tie(vi, vi_end) = vertices(g); vi != vi_end; vi++, name++)
- name_map[*vi] = name;
-
- return g;
-}
-
-//void add_source(char bla, Graph &g, char name)
-void to_source(Graph &g, size_t v, char name)
-{
- property_map < Graph, vertex_name_t >::type name_map = get(vertex_name, g);
- graph_traits < Graph >::vertex_iterator vi, vi_end;
- property_map < Graph, vertex_index_t >::type index = get(vertex_index, g);
-
- // int v = add_vertex(g);
- for (tie(vi, vi_end) = vertices(g); vi != vi_end; vi++)
- if (v != *vi)
- add_edge(v, *vi, g);
-
- // name_map[* --vertices(g).second] = name;
- name_map[v] = name;
-}
-
-void to_sink(Graph &g, size_t v, char name)
-{
- property_map < Graph, vertex_name_t >::type name_map = get(vertex_name, g);
- graph_traits < Graph >::vertex_iterator vi, vi_end;
- property_map < Graph, vertex_index_t >::type index = get(vertex_index, g);
-
- // int v = add_vertex(g);
- for (tie(vi, vi_end) = vertices(g); vi != vi_end; vi++)
- if (v != *vi)
- add_edge(*vi, v, g);
-
- // name_map[* --vertices(g).second] = name;
- name_map[v] = name;
-}
-
-
-
-int main(int,char*[])
-{
- Graph h1 = create_graph(5,1);
- Graph h2 = create_graph(5,2);
- graph_traits < Graph >::vertex_descriptor w, z;
-
- to_source(h1, 5, 'x');
- to_sink(h1, 5, 'x');
-
- to_sink(h2, 5, 'y');
- // x and y are the "same"
-
- w = add_vertex(h1); // vertex 6 (w) is only in h1
- add_edge(*vertices(h1).first, w, h1);
- add_edge(w, *vertices(h1).first, h1);
- get(vertex_name, h1)[w] = 'w';
-
- z = add_vertex(h2); // vertex 6 (w) is only in h1
- add_edge(*vertices(h2).first, w, h2);
- add_edge(w, *vertices(h2).first, h2);
- get(vertex_name, h2)[z] = 'z';
-
- cout << "graph h1:" << endl;
- prt(h1);
- cout << "graph h2:" << endl;
- prt(h2);
-
- Graph h_du;
- cout << "Disjoint union: (h1 union h2)" << endl;
- graph_disjoint_union(h1, h2, h_du);
- prt(h_du);
- // is there any way to clear h_du and use the same variable for all?
-
- GlobalVertexMapping < Graph, graph_traits<Graph>::vertex_descriptor, string > globalId(*vertices(h1).second, -2);
-
- globalId.add_graph(h1,"h1");
- globalId.add_graph(h2,"h2");
-
- globalId.associate(h1, w, 20);
- globalId.associate(h2, z, 40);
-
- graph_traits < Graph >::vertex_iterator vi, vi_end;
- for (tie(vi, vi_end) = vertices(h1); vi != vi_end; vi++)
- globalId.associate(h1, *vi, *vi);
- for (tie(vi, vi_end) = vertices(h2); vi != vi_end; vi++)
- globalId.associate(h2, *vi, *vi);
-
- cout << "Global id:" << endl;
- globalId.show_associations();
-
- // in this example (graph sum), it creates some parallel edges (e.g., a --> x appears twice)
- // because x and y are the considered as the same
- Graph h_s;
- cout << "Graph sum: (h1 + h2)" << endl;
- gvm_graph_sum(h1, h2, globalId, h_s);
- prt(h_s);
-
- Graph h_i;
- cout << "Graph intersection: (h1 intersection h2)" << endl;
- gvm_graph_intersection(h1, h2, globalId, h_i);
- prt(h_i);
-
- Graph h_diff;
- cout << "Graph difference: (h1 - h2)" << endl;
- gvm_graph_difference(h1, h2, globalId, h_diff);
- prt(h_diff);
-
- return 0;
-}
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