From 34bc3a8786acabc3f04b61bd765c11024575cd61 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 20 Apr 2005 23:45:55 +0000 Subject: [PATCH] doc/*: Document Python bindings src/python/basic_graph.cpp src/python/basic_graph.hpp: - Add ability to record the names of vertices input via the adjacency list reader. example/python/breadth_first_search.py: Building a better example [SVN r28350] --- doc/bc_clustering.html | 103 +++-- doc/history.html | 1 + doc/python.html | 541 ++++++++++++++++++++++++- doc/table_of_contents.html | 1 + example/python/breadth_first_search.py | 9 +- src/python/basic_graph.cpp | 17 +- src/python/basic_graph.hpp | 3 +- 7 files changed, 622 insertions(+), 53 deletions(-) diff --git a/doc/bc_clustering.html b/doc/bc_clustering.html index 5f136942..9cb70890 100644 --- a/doc/bc_clustering.html +++ b/doc/bc_clustering.html @@ -10,8 +10,12 @@
-

(Python)Function -betweenness_centrality_clustering

+ +C++ Boost + +

(Python)Function +betweenness_centrality_clustering

boost::betweenness_centrality_clustering — Graph clustering based on edge betweenness centrality.

@@ -48,53 +52,68 @@ clustering based on edge betweenness centrality.

Description

-
-

Parameters

-
-
done
-
-

The function object that indicates termination of the algorithm. -It must be a ternary function object thats accepts the maximum -centrality, the descriptor of the edge that will be removed, and -the graph g .

-
-
edge_centrality
-
-

(UTIL/OUT) The property map that will store the betweenness -centrality for each edge. When the algorithm terminates, it will -contain the edge centralities for the graph. The type of this -property map must model the ReadWritePropertyMap concept. Defaults -to an iterator_property_map whose -value type is Done::centrality_type -and using get(edge_index, g) for -the index map.

-
-
g
-
-

The graph on which clustering will be performed. The type of -this parameter (MutableGraph ) must -be a model of the VertexListGraph, IncidenceGraph, EdgeListGraph, -and Mutable Graph concepts.

-
-
vertex_index
-
-

(IN) The property map that maps vertices to indices in the range -[0, num_vertices(g)). This type of this property map must model the -ReadablePropertyMap concept and its value type must be an integral -type. Defaults to get(vertex_index, -g) .

-
-
-

This algorithm implements graph clustering based on edge betweenness centrality. It is an iterative algorithm, where in each step it compute the edge betweenness centrality (via brandes_betweenness_centrality) and +"betweenness_centrality.html">brandes_betweenness_centrality) and removes the edge with the maximum betweenness centrality. The done function object determines when the algorithm terminates (the edge found when the algorithm terminates will not be removed).

-
+ +

Parameters

+IN: const Graph& g +
+ The graph object on which the algorithm will be applied. The type + Graph must be a model of Vertex List Graph and Incidence Graph. When an edge + centrality map is supplied, it must also model Edge List Graph and MutableGraph.
+ +Python: The parameter is named graph. +
+ +IN: Done done +
+The function object that indicates termination of the algorithm. +It must be a ternary function object thats accepts the maximum +centrality, the descriptor of the edge that will be removed, and +the graph g.
+Python: Any callable Python object will suffice. +
+ +OUT/UTIL: EdgeCentralityMap edge_centrality_map +
+ This property map is used to accumulate the betweenness centrality + of each edge, and is a secondary form of output for the + algorithm. The type EdgeCentralityMap must be a model of Read/Write + Property Map, with the graph's edge descriptor type as its key + type. The value type of this property map should be the same as the + value type of the CentralityMap property map.
+ + Default: a dummy_property_map, which requires no + work to compute and returns no answer.
+ Python: The color map must be a edge_double_map for + the graph.
+ Python default: graph.get_edge_double_map("centrality") +
+ +IN: VertexIndexMap vertex_index +
+ This maps each vertex to an integer in the range [0, + num_vertices(g)). This is necessary for efficient updates of the + heap data structure when an edge is relaxed. The type + VertexIndexMap must be a model of + Readable Property Map. The value type of the map must be an + integer type. The vertex descriptor type of the graph needs to be + usable as the key type of the map.
+ Default: get(vertex_index, g)
+ Python: Unsupported parameter. +
+ diff --git a/doc/history.html b/doc/history.html index 979a74d8..5dca5d24 100644 --- a/doc/history.html +++ b/doc/history.html @@ -82,6 +82,7 @@ September 27, 2000.
diff --git a/doc/table_of_contents.html b/doc/table_of_contents.html index 96472e8f..68352ba7 100644 --- a/doc/table_of_contents.html +++ b/doc/table_of_contents.html @@ -67,6 +67,7 @@
  • Mutable Property Graph
  • The Property Map Library (technically not part of the graph library, but used a lot here) +
  • (Python)Python bindings
  • Visitor Concepts
    1. (Python)BFS Visitor diff --git a/example/python/breadth_first_search.py b/example/python/breadth_first_search.py index 18179ad5..ba48af3c 100644 --- a/example/python/breadth_first_search.py +++ b/example/python/breadth_first_search.py @@ -1,14 +1,15 @@ from bgl import * class bfs_print_discover_visitor(Graph.BFSVisitor): + def bfs_print_discover_visitor(self, dtime_map): + Graph.BFSVisitor.__init__(self) + def discover_vertex(self, u, g): print "Discovered vertex ", print u -g = Graph((("r", "s"), ("r", "v"), ("s", "w"), ("w", "r"), ("w", "t"), ("w", "x"), ("x", "t"), ("t", "u"), ("x", "y"), ("u", "y"))) +g = Graph((("r", "s"), ("r", "v"), ("s", "w"), ("w", "r"), ("w", "t"), ("w", "x"), ("x", "t"), ("t", "u"), ("x", "y"), ("u", "y")), "label") + -iter = g.vertices.__iter__() -iter.next() -s = iter.next() breadth_first_search(g, s, visitor=bfs_print_discover_visitor()) diff --git a/src/python/basic_graph.cpp b/src/python/basic_graph.cpp index 69461105..c5f819b1 100644 --- a/src/python/basic_graph.cpp +++ b/src/python/basic_graph.cpp @@ -114,13 +114,17 @@ basic_graph::basic_graph() { } template -basic_graph::basic_graph(::boost::python::object l) +basic_graph::basic_graph(boost::python::object l, + const std::string& name_map) : inherited() { using boost::python::object; std::map verts; int len = ::boost::python::extract(l.attr("__len__")()); + vector_property_map name; + if (!name_map.empty()) name = get_vertex_map(name_map); + for (int i = 0; i < len; ++i) { vertex_descriptor u, v; object up = l[i][0]; @@ -128,10 +132,16 @@ basic_graph::basic_graph(::boost::python::object l) typename std::map::iterator pos; pos = verts.find(up); - if (pos == verts.end()) u = verts[up] = add_vertex(); + if (pos == verts.end()) { + u = verts[up] = add_vertex(); + if (!name_map.empty()) name[u] = up; + } else u = pos->second; pos = verts.find(vp); - if (pos == verts.end()) v = verts[vp] = add_vertex(); + if (pos == verts.end()) { + v = verts[vp] = add_vertex(); + if (!name_map.empty()) name[v] = vp; + } else v = pos->second; add_edge(u, v); @@ -572,6 +582,7 @@ void export_basic_graph(const char* name) class_ >(name) // Constructors .def(init()) + .def(init()) .def(init()) .def(init( (arg("generator"), arg("seed") = 1))) diff --git a/src/python/basic_graph.hpp b/src/python/basic_graph.hpp index 06b8192f..b700bf07 100644 --- a/src/python/basic_graph.hpp +++ b/src/python/basic_graph.hpp @@ -228,7 +228,8 @@ class basic_graph adjacency_iterator; basic_graph(); - basic_graph(::boost::python::object); + basic_graph(boost::python::object, + const std::string& name_map = std::string()); basic_graph(const std::string& filename, graph_file_kind kind); basic_graph(erdos_renyi, int seed); basic_graph(power_law_out_degree, int seed);