diff --git a/build/python/Jamfile b/build/python/Jamfile deleted file mode 100644 index 98580135..00000000 --- a/build/python/Jamfile +++ /dev/null @@ -1,61 +0,0 @@ -# Copyright 2005 The Trustees of Indiana University. - -# Use, modification and distribution is subject to 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) - -# Authors: Douglas Gregor -# Andrew Lumsdaine - -subproject libs/graph/build/python ; - -SEARCH on python.jam = $(BOOST_BUILD_PATH) ; -include python.jam ; - -extension bgl -: # Sources - ../../src/python/module.cpp - # Graph types - ../../src/python/graph.cpp - ../../src/python/digraph.cpp - # Graph I/O - ../../src/python/graphviz.cpp - # Graph algorithms - # Core Algorithm Patterns - ../../src/python/breadth_first_search.cpp - ../../src/python/depth_first_search.cpp - # Shortest Paths Algorithms - ../../src/python/dijkstra_shortest_paths.cpp - ../../src/python/bellman_ford_shortest_paths.cpp - ../../src/python/dag_shortest_paths.cpp - # Minimum Spanning Tree Algorithms - ../../src/python/kruskal_min_spanning_tree.cpp - ../../src/python/prim_minimum_spanning_tree.cpp - # Connected Components Algorithms - ../../src/python/connected_components.cpp - ../../src/python/strong_components.cpp - ../../src/python/biconnected_components.cpp - ../../src/python/incremental_components.cpp - # ... - # Other algorithms - ../../src/python/topological_sort.cpp - ../../src/python/transitive_closure.cpp -# ../../src/python/transpose_graph.cpp Need copy_graph to work, first - ../../src/python/isomorphism.cpp - ../../src/python/betweenness_centrality.cpp - ../../src/python/sequential_vertex_coloring.cpp - # Sparse Matrix Ordering - ../../src/python/cuthill_mckee_ordering.cpp - ../../src/python/king_ordering.cpp -# ../../src/python/minimum_degree_ordering.cpp - ../../src/python/circle_layout.cpp - ../../src/python/fruchterman_reingold.cpp - ../../src/python/kamada_kawai_spring_layout.cpp - ../../src/python/page_rank.cpp - # Pickling support - ../../src/python/pickle.cpp - ../../../python/build/boost_python - ../bgl-viz - : # Default build - off - ; diff --git a/example/python/biconnected_components.dot b/example/python/biconnected_components.dot deleted file mode 100644 index ef4ba592..00000000 --- a/example/python/biconnected_components.dot +++ /dev/null @@ -1,13 +0,0 @@ -graph G { - A -- B - A -- F - A -- G - B -- C - B -- D - B -- E - C -- D - E -- F - G -- H - G -- I - H -- I -} diff --git a/example/python/biconnected_components.py b/example/python/biconnected_components.py deleted file mode 100644 index f55b27a0..00000000 --- a/example/python/biconnected_components.py +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright 2005 The Trustees of Indiana University. - -# Use, modification and distribution is subject to 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) - -# Authors: Douglas Gregor -# Andrew Lumsdaine - -import bgl - -g = bgl.Graph("biconnected_components.dot", bgl.file_kind.graphviz) -art_points = bgl.biconnected_components(g, g.get_edge_int_map("label")); -g.write_graphviz("biconnected_components_out.dot") - -print "Articulation points: ", -node_id = g.get_vertex_string_map("node_id") -for v in art_points: - print node_id[v], - print " ", -print "" diff --git a/example/python/breadth_first_search.py b/example/python/breadth_first_search.py deleted file mode 100644 index ba48af3c..00000000 --- a/example/python/breadth_first_search.py +++ /dev/null @@ -1,15 +0,0 @@ -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")), "label") - - -breadth_first_search(g, s, visitor=bfs_print_discover_visitor()) - diff --git a/example/python/disconnected.dot b/example/python/disconnected.dot deleted file mode 100644 index e7685ad8..00000000 --- a/example/python/disconnected.dot +++ /dev/null @@ -1,10 +0,0 @@ -graph G { - A -- F - B -- C - B -- D - C -- D - E -- F - G -- H - G -- I - H -- I -} diff --git a/example/python/mst.dot b/example/python/mst.dot deleted file mode 100644 index 508b4c77..00000000 --- a/example/python/mst.dot +++ /dev/null @@ -1,10 +0,0 @@ -graph G { - A -- C [weight="1.0"] - B -- D [weight="1.0"] - B -- E [weight="2.0"] - C -- B [weight="7.0"] - C -- D [weight="3.0"] - D -- E [weight="1.0"] - E -- A [weight="1.0"] - E -- B [weight="1.0"] -} \ No newline at end of file diff --git a/example/python/vis.py b/example/python/vis.py deleted file mode 100644 index 5624de5b..00000000 --- a/example/python/vis.py +++ /dev/null @@ -1,706 +0,0 @@ -import bgl -import wx -import wx.lib.ogl as ogl -# import wx.lib.masked -import os -import random -import sys - -wildcard = "GraphViz (*.dot)|*.dot|" \ - "All files (*.*)|*.*" - -def path_to_title(path): - title = path - dot_idx = title.rfind('.') - if dot_idx != -1: title = title[:dot_idx] - slash_idx = title.rfind('/') - if slash_idx != -1: title = title[slash_idx+1:] - slash_idx = title.rfind('\\') - if slash_idx != -1: title = title[slash_idx+1:] - return title - -class GraphCanvas(ogl.ShapeCanvas): - def __init__(self, parent): - ogl.ShapeCanvas.__init__(self, parent) - - maxWidth = 400 - maxHeight = 400 - self.SetScrollbars(20, 20, maxWidth/20, maxHeight/20) - - def set_graph(self, graph, position_map, property_maps): - self.diagram = ogl.Diagram() - self.SetDiagram(self.diagram) - self.diagram.SetCanvas(self) - - self.graph = graph - self.position_map = position_map - self.property_maps = property_maps - self.vertex_position_rect = self.compute_rect() - self.vertex_to_shape = graph.get_vertex_object_map("__stored_shape") - self.edge_to_shape = graph.get_edge_object_map("__stored_shape") - self.shape_to_vertex = {} - - for v in graph.vertices: - self.add_vertex(v) - - for e in graph.edges: - self.add_edge(e) - - self.Refresh() - - def compute_rect(self): - pos = self.position_map - if self.graph.num_vertices() == 0: - return (-50, -50, 50, 50) - else: - left, top, right, bottom = 0, 0, 0, 0 - for v in self.graph.vertices: - if pos[v].x < left: left = pos[v].x - if pos[v].y < top: top = pos[v].y - if pos[v].x > right: right = pos[v].x - if pos[v].y > bottom: bottom = pos[v].y - return (left, top, right, bottom) - - def update_layout(self): - self.vertex_position_rect = self.compute_rect() - dc = wx.ClientDC(self) - self.PrepareDC(dc) - for v in self.graph.vertices: - shape = self.vertex_to_shape[v] - x, y = self.vertex_position_to_shape_position(v) - shape.Move(dc, x, y, False) - self.Refresh() - - def vertex_position_to_shape_position(self, vertex): - (width, height) = self.GetVirtualSize() - width = width - 20 - height = height - 20 - (pos_width, pos_height) = (self.vertex_position_rect[2] - - self.vertex_position_rect[0], - self.vertex_position_rect[3] - - self.vertex_position_rect[1]) - return ((self.position_map[vertex].x - self.vertex_position_rect[0]) - / pos_width * width + 10, - (self.position_map[vertex].y - self.vertex_position_rect[1]) - / pos_height * height + 10); - - def translate_color(self, color): - if color=="black": return wx.BLACK - elif color=="blue": return wx.BLUE - elif color=="red": return wx.RED - elif color=="green": return wx.GREEN - else: return wx.BLACK - - def add_vertex(self, vertex): - shape = self.CreateVertex(vertex) - shape.SetDraggable(True, True) - shape.SetCanvas(self) - x, y = self.vertex_position_to_shape_position(vertex) - shape.SetX(x) - shape.SetY(y) - shape.SetPen(self.VertexPen(vertex)) - shape.SetBrush(self.VertexBrush(vertex)) - s = self.VertexLabel(vertex) - if s != "": shape.AddText(s) - self.diagram.AddShape(shape) - shape.Show(True) - self.vertex_to_shape[vertex] = shape - self.shape_to_vertex[shape] = vertex - - evthandler = VertexEventHandler(self) - evthandler.SetShape(shape) - evthandler.SetPreviousHandler(shape.GetEventHandler()) - shape.SetEventHandler(evthandler) - - return shape; - - def CreateVertex(self, vertex): - return ogl.CircleShape(20) - - def VertexPen(self, vertex): - thickness = 1 - color = wx.BLACK - if "vertex.border.thickness" in self.property_maps: - thickness = self.property_maps["vertex.border.thickness"][vertex] - if "vertex.border.color" in self.property_maps: - color_text = self.property_maps["vertex.border.color"][vertex] - color = translate_color(color_text) - return wx.Pen(color, thickness) - - def VertexBrush(self, vertex): - return wx.GREEN_BRUSH - - def VertexLabel(self, vertex): - if "vertex.label" in self.property_maps: - return self.property_maps["vertex.label"][vertex] - else: - return "" - - def VertexShape(self, vertex): - return self.vertex_to_shape[vertex] - - def add_edge(self, edge): - (u, v) = (self.graph.source(edge), self.graph.target(edge)) - line = ogl.LineShape() - line.SetCanvas(self) - line.SetPen(wx.BLACK_PEN) - line.SetBrush(wx.BLACK_BRUSH) - if self.graph.is_directed(): line.AddArrow(ogl.ARROW_ARROW) - if "edge.label" in self.property_maps: - label = str(self.property_maps["edge.label"][edge]) - line.AddText(label) - line.MakeLineControlPoints(2) - self.vertex_to_shape[u].AddLine(line, self.vertex_to_shape[v]) - self.diagram.AddShape(line) - line.Show(True) - self.edge_to_shape[edge] = line - return line - - def EdgeShape(self, edge): - return self.edge_to_shape[edge] - - def set_vertex_colors_from_components(self, component_map): - brushes = {} - for v in self.graph.vertices: - shape = self.vertex_to_shape[v] - comp = component_map[v] - if not comp in brushes: - brushes[comp] = wx.Brush(wx.Color(random.randint(0, 200), - random.randint(0, 200), - random.randint(0, 200))) - shape.SetBrush(brushes[comp]) - self.Refresh() - - def set_edge_colors_from_components(self, component_map): - pens = {} - for e in self.graph.edges: - shape = self.edge_to_shape[e] - comp = component_map[e] - if not comp in pens: - pens[comp] = wx.Pen(wx.Color(random.randint(0, 200), - random.randint(0, 200), - random.randint(0, 200)), - 1) - shape.SetPen(pens[comp]) - self.Refresh() - - def default_property_maps(self, graph, node_id = "node_id"): - maps = {} - if graph.has_vertex_map("label"): - maps["vertex.label"] = graph.get_vertex_string_map("label") - elif graph.has_vertex_map(node_id): - maps["vertex.label"] = graph.get_vertex_string_map(node_id) - if graph.has_edge_map("label"): - maps["edge.label"] = graph.get_edge_string_map("label") - elif graph.has_edge_map("weight"): - maps["edge.label"] = graph.get_edge_double_map("weight") - return maps - -class VertexEventHandler(ogl.ShapeEvtHandler): - def __init__(self, graphwin): - ogl.ShapeEvtHandler.__init__(self) - self.graphwin = graphwin - - def OnEndDragLeft(self, x, y, keys=0, attachment=0): - shape = self.GetShape() - if shape.Selected(): - vertex = self.graphwin.shape_to_vertex[shape] - self.graphwin.position_map[vertex].x = x - self.graphwin.position_map[vertex].y = y - ogl.ShapeEvtHandler.OnEndDragLeft(self, x, y, keys, attachment) - -class ErdosRenyiDialog(wx.Dialog): - def __init__( - self, parent, ID, title, size=wx.DefaultSize, pos=wx.DefaultPosition, - style=wx.DEFAULT_DIALOG_STYLE - ): - wx.Dialog.__init__(self, parent, ID, title, pos, size, style, - "Erdos-Renyi Generator") - - sizer = wx.BoxSizer(wx.VERTICAL) - - box = wx.BoxSizer(wx.HORIZONTAL) - - box.Add(wx.StaticText(self, -1, "Number of vertices (n)"), 0, - wx.ALIGN_CENTRE|wx.ALL, 5) - - num_vertices_spin = wx.SpinCtrl(self, -1, "", (30, 50)) - num_vertices_spin.SetRange(0,10000000) - num_vertices_spin.SetValue(10) - box.Add(num_vertices_spin, 1, wx.ALIGN_CENTRE|wx.ALL, 5) - self.num_vertices_spin = num_vertices_spin - sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5) - - box = wx.BoxSizer(wx.HORIZONTAL) - - box.Add(wx.StaticText(self, -1, "Edge probability (%)"), 0, - wx.ALIGN_CENTRE|wx.ALL, 5) - - # This is better than what we're currently doing with a SpinCtrl, but - # it makes the program unstable (?) -# probability_ctrl = wx.lib.masked.numctrl.NumCtrl(self, value = 0.2, -# integerWidth = 1, -# fractionWidth = 3, -# allowNegative = False, -# min = 0.0, max = 1.0) - - probability_ctrl = wx.SpinCtrl(self, -1, "", (30, 50)) - probability_ctrl.SetRange(0,100) - probability_ctrl.SetValue(20) - self.probability_ctrl = probability_ctrl - box.Add(probability_ctrl, 1, wx.ALIGN_CENTRE|wx.ALL, 5) - sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5) - - box = wx.BoxSizer(wx.HORIZONTAL) - box.Add(wx.StaticText(self, -1, "Random seed"), 0, - wx.ALIGN_CENTRE|wx.ALL, 5) - - seed_ctrl = wx.SpinCtrl(self, -1, "", (30, 50)) - seed_ctrl.SetRange(1, sys.maxint) - seed_ctrl.SetValue(random.randint(1, sys.maxint)) - self.seed_ctrl = seed_ctrl - box.Add(seed_ctrl, 1, wx.ALIGN_CENTRE|wx.ALL, 5) - - sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5) - - line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL) - sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, 5) - - box = wx.BoxSizer(wx.HORIZONTAL) - - btn = wx.Button(self, wx.ID_OK, " Generate! ") - btn.SetDefault() - box.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5) - - btn = wx.Button(self, wx.ID_CANCEL, " Cancel ") - box.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5) - - sizer.Add(box, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5) - - self.SetSizer(sizer) - self.SetAutoLayout(True) - sizer.Fit(self) - - def GetNumVertices(self): - return self.num_vertices_spin.GetValue() - - def GetProbability(self): - return float(self.probability_ctrl.GetValue()) - - def GetRandomSeed(self): - return int(self.seed_ctrl.GetValue()) - -class PLODDialog(wx.Dialog): - def __init__( - self, parent, ID, title, size=wx.DefaultSize, pos=wx.DefaultPosition, - style=wx.DEFAULT_DIALOG_STYLE - ): - wx.Dialog.__init__(self, parent, ID, title, pos, size, style) - - sizer = wx.BoxSizer(wx.VERTICAL) - - box = wx.BoxSizer(wx.HORIZONTAL) - - box.Add(wx.StaticText(self, -1, "Number of vertices (n)"), 0, - wx.ALIGN_CENTRE|wx.ALL, 5) - - num_vertices_spin = wx.SpinCtrl(self, -1, "", (30, 50)) - num_vertices_spin.SetRange(0,10000000) - num_vertices_spin.SetValue(10) - box.Add(num_vertices_spin, 1, wx.ALIGN_CENTRE|wx.ALL, 5) - self.num_vertices_spin = num_vertices_spin - sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5) - - # Alpha - box = wx.BoxSizer(wx.HORIZONTAL) - box.Add(wx.StaticText(self, -1, "Alpha"), 0, - wx.ALIGN_CENTRE|wx.ALL, 5) - alpha_ctrl = wx.TextCtrl(self, -1, "2.75", (30, 50)) - self.alpha_ctrl = alpha_ctrl - box.Add(alpha_ctrl, 1, wx.ALIGN_CENTRE|wx.ALL, 5) - sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5) - - - # Beta - box = wx.BoxSizer(wx.HORIZONTAL) - box.Add(wx.StaticText(self, -1, "Beta"), 0, - wx.ALIGN_CENTRE|wx.ALL, 5) - beta_ctrl = wx.SpinCtrl(self, -1, "", (30, 50)) - beta_ctrl.SetRange(1, sys.maxint) - beta_ctrl.SetValue(300) - self.beta_ctrl = beta_ctrl - box.Add(beta_ctrl, 1, wx.ALIGN_CENTRE|wx.ALL, 5) - sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5) - - - box = wx.BoxSizer(wx.HORIZONTAL) - box.Add(wx.StaticText(self, -1, "Random seed"), 0, - wx.ALIGN_CENTRE|wx.ALL, 5) - - seed_ctrl = wx.SpinCtrl(self, -1, "", (30, 50)) - seed_ctrl.SetRange(1, sys.maxint) - seed_ctrl.SetValue(random.randint(1, sys.maxint)) - self.seed_ctrl = seed_ctrl - box.Add(seed_ctrl, 1, wx.ALIGN_CENTRE|wx.ALL, 5) - - sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5) - - line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL) - sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, 5) - - box = wx.BoxSizer(wx.HORIZONTAL) - - btn = wx.Button(self, wx.ID_OK, " Generate! ") - btn.SetDefault() - box.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5) - - btn = wx.Button(self, wx.ID_CANCEL, " Cancel ") - box.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5) - - sizer.Add(box, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5) - - self.SetSizer(sizer) - self.SetAutoLayout(True) - sizer.Fit(self) - - def GetNumVertices(self): - return self.num_vertices_spin.GetValue() - - def GetAlpha(self): - return float(self.alpha_ctrl.GetValue()) - - def GetBeta(self): - return float(self.beta_ctrl.GetValue()) - - def GetRandomSeed(self): - return int(self.seed_ctrl.GetValue()) - -class SmallWorldDialog(wx.Dialog): - def __init__( - self, parent, ID, title, size=wx.DefaultSize, pos=wx.DefaultPosition, - style=wx.DEFAULT_DIALOG_STYLE - ): - wx.Dialog.__init__(self, parent, ID, title, pos, size, style) - - sizer = wx.BoxSizer(wx.VERTICAL) - - box = wx.BoxSizer(wx.HORIZONTAL) - - box.Add(wx.StaticText(self, -1, "Number of vertices (n)"), 0, - wx.ALIGN_CENTRE|wx.ALL, 5) - - num_vertices_spin = wx.SpinCtrl(self, -1, "", (30, 50)) - num_vertices_spin.SetRange(0,10000000) - num_vertices_spin.SetValue(10) - box.Add(num_vertices_spin, 1, wx.ALIGN_CENTRE|wx.ALL, 5) - self.num_vertices_spin = num_vertices_spin - sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5) - - # Number of neighbors - box = wx.BoxSizer(wx.HORIZONTAL) - - box.Add(wx.StaticText(self, -1, "Number of neighbors (k)"), 0, - wx.ALIGN_CENTRE|wx.ALL, 5) - - num_neighbors_spin = wx.SpinCtrl(self, -1, "", (30, 50)) - num_neighbors_spin.SetRange(0,10000000) - num_neighbors_spin.SetValue(4) - box.Add(num_neighbors_spin, 1, wx.ALIGN_CENTRE|wx.ALL, 5) - self.num_neighbors_spin = num_neighbors_spin - sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5) - - box = wx.BoxSizer(wx.HORIZONTAL) - - box.Add(wx.StaticText(self, -1, "Rewiring probability (%)"), 0, - wx.ALIGN_CENTRE|wx.ALL, 5) - - # This is better than what we're currently doing with a SpinCtrl, but - # it makes the program unstable (?) -# probability_ctrl = wx.lib.masked.numctrl.NumCtrl(self, value = 0.2, -# integerWidth = 1, -# fractionWidth = 3, -# allowNegative = False, -# min = 0.0, max = 1.0) - - probability_ctrl = wx.SpinCtrl(self, -1, "", (30, 50)) - probability_ctrl.SetRange(0,100) - probability_ctrl.SetValue(20) - self.probability_ctrl = probability_ctrl - box.Add(probability_ctrl, 1, wx.ALIGN_CENTRE|wx.ALL, 5) - sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5) - - box = wx.BoxSizer(wx.HORIZONTAL) - box.Add(wx.StaticText(self, -1, "Random seed"), 0, - wx.ALIGN_CENTRE|wx.ALL, 5) - - seed_ctrl = wx.SpinCtrl(self, -1, "", (30, 50)) - seed_ctrl.SetRange(1, sys.maxint) - seed_ctrl.SetValue(random.randint(1, sys.maxint)) - self.seed_ctrl = seed_ctrl - box.Add(seed_ctrl, 1, wx.ALIGN_CENTRE|wx.ALL, 5) - - sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5) - - line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL) - sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, 5) - - box = wx.BoxSizer(wx.HORIZONTAL) - - btn = wx.Button(self, wx.ID_OK, " Generate! ") - btn.SetDefault() - box.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5) - - btn = wx.Button(self, wx.ID_CANCEL, " Cancel ") - box.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5) - - sizer.Add(box, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5) - - self.SetSizer(sizer) - self.SetAutoLayout(True) - sizer.Fit(self) - - def GetNumVertices(self): - return self.num_vertices_spin.GetValue() - - def GetNumNeighbors(self): - return self.num_neighbors_spin.GetValue() - - def GetProbability(self): - return float(self.probability_ctrl.GetValue()) - - def GetRandomSeed(self): - return int(self.seed_ctrl.GetValue()) - -class GraphEditorWindow(wx.Frame): - def __init__(self, parent, title='BGL Graph Viewer'): - wx.Frame.__init__(self, parent, -1, title); - self.canvas = GraphCanvas(self) - self.CreateMenuBar() - self.erdos_renyi_dlg = None - self.plod_dlg = None - self.small_world_dlg = None - self.NewGraph(None) - - def CreateMenuBar(self): - menuBar = wx.MenuBar() - - # File menu - fileMenu = wx.Menu() - - # New graph menu - newGraphMenu = wx.Menu() - newGraphMenu.Append(111, "Empty graph") - newGraphMenu.Append(112, "Erdos-Renyi graph...") - newGraphMenu.Append(113, "Power Law Out Degree graph...") - newGraphMenu.Append(114, "Small-world graph...") - fileMenu.AppendMenu(110, "&New graph", newGraphMenu) - - fileMenu.Append(120, "&Open graph") - fileMenu.Append(130, "&Save graph") - menuBar.Append(fileMenu, "&File") - - # Algorithms menu - algorithmsMenu = wx.Menu() - # - Connected components menu - ccMenu = wx.Menu(); - ccMenu.Append(201, "Connected Components") - ccMenu.Append(202, "Strongly-Connected Components") - ccMenu.Append(203, "Biconnected Components") - algorithmsMenu.AppendMenu(200, "Connected Components", ccMenu) - - # - Minimum Spanning Tree menu - mstMenu = wx.Menu(); - mstMenu.Append(212, "Kruskal") - algorithmsMenu.AppendMenu(210, "Minimum Spanning Tree", mstMenu) - - # Other algorithms... - algorithmsMenu.Append(221, "Sequential vertex coloring") - - menuBar.Append(algorithmsMenu, "&Algorithms") - - - # Layout menu - layoutMenu = wx.Menu() - layoutMenu.Append(301, "&Circle layout") - layoutMenu.Append(302, "&Fruchterman-Reingold layout") - layoutMenu.Append(303, "&Kamada-Kawai layout") - menuBar.Append(layoutMenu, "&Layout") - - # File menu events - self.Bind(wx.EVT_MENU, self.NewGraph, id=111) - self.Bind(wx.EVT_MENU, self.ErdosRenyiGraph, id=112) - self.Bind(wx.EVT_MENU, self.PLODGraph, id=113) - self.Bind(wx.EVT_MENU, self.SmallWorldGraph, id=114) - self.Bind(wx.EVT_MENU, self.OpenGraph, id=120) - self.Bind(wx.EVT_MENU, self.SaveGraph, id=130) - - # Algorithms menu events - self.Bind(wx.EVT_MENU, self.ConnectedComponents, id=201) - self.Bind(wx.EVT_MENU, self.StrongComponents, id=202) - self.Bind(wx.EVT_MENU, self.BiconnectedComponents, id=203) - self.Bind(wx.EVT_MENU, self.KruskalMST, id=212) - self.Bind(wx.EVT_MENU, self.SequentialVertexColoring, id=221) - - # Layout menu events - self.Bind(wx.EVT_MENU, self.CircleLayout, id=301) - self.Bind(wx.EVT_MENU, self.FruchtermanReingoldLayout, id=302) - self.Bind(wx.EVT_MENU, self.KamadaKawaiLayout, id=303) - - self.SetMenuBar(menuBar) - - def NewGraph(self, event): - graph = bgl.Graph() - position_map = graph.get_vertex_point2d_map("position") - self.canvas.set_graph(graph, position_map, {}) - self.SetTitle("Graph") - - def ErdosRenyiGraph(self, event): - if not self.erdos_renyi_dlg: - self.erdos_renyi_dlg = ErdosRenyiDialog(self, -1, - "Erdos-Renyi Generator") - dlg = self.erdos_renyi_dlg - if dlg.ShowModal() == wx.ID_OK: - graph = bgl.Graph(bgl.ErdosRenyi(dlg.GetNumVertices(), - dlg.GetProbability() / 100), - dlg.GetRandomSeed()) - position_map = graph.get_vertex_point2d_map("position") - bgl.circle_graph_layout(graph, position_map, 50) - self.canvas.set_graph(graph, position_map, {}) - self.SetTitle("Erdos-Renyi Graph (" - + str(dlg.GetNumVertices()) + ", " - + str(dlg.GetProbability() / 100) + ")") - def PLODGraph(self, event): - if not self.plod_dlg: - self.plod_dlg = PLODDialog(self, -1, - "Power Law Out Degree Generator") - dlg = self.plod_dlg - if dlg.ShowModal() == wx.ID_OK: - graph = bgl.Graph(bgl.PowerLawOutDegree(dlg.GetNumVertices(), - dlg.GetAlpha(), - dlg.GetBeta()), - dlg.GetRandomSeed()) - position_map = graph.get_vertex_point2d_map("position") - bgl.circle_graph_layout(graph, position_map, 50) - self.canvas.set_graph(graph, position_map, {}) - self.SetTitle("Power Law Out Degree Graph (" - + str(dlg.GetNumVertices()) + ", " - + str(dlg.GetAlpha()) + ", " - + str(dlg.GetBeta()) + ")") - - def SmallWorldGraph(self, event): - if not self.small_world_dlg: - self.small_world_dlg = SmallWorldDialog(self, -1, - "Small-World Generator") - dlg = self.small_world_dlg - if dlg.ShowModal() == wx.ID_OK: - graph = bgl.Graph(bgl.SmallWorld(dlg.GetNumVertices(), - dlg.GetNumNeighbors(), - dlg.GetProbability() / 100), - dlg.GetRandomSeed()) - position_map = graph.get_vertex_point2d_map("position") - bgl.circle_graph_layout(graph, position_map, 50) - self.canvas.set_graph(graph, position_map, {}) - self.SetTitle("Small-World Graph (" - + str(dlg.GetNumVertices()) + ", " - + str(dlg.GetNumNeighbors()) + ", " - + str(dlg.GetProbability() / 100) + ")") - - def OpenGraph(self, event): - dlg = wx.FileDialog( - self, message="Choose a file", defaultDir=os.getcwd(), - defaultFile="", wildcard=wildcard, style=wx.OPEN | wx.CHANGE_DIR) - if dlg.ShowModal() == wx.ID_OK: - path = dlg.GetPath() - try: - graph = bgl.Graph(path, bgl.file_kind.graphviz) - except bgl.directed_graph_error: - graph = bgl.Digraph(path, bgl.file_kind.graphviz) - needs_layout = not graph.has_vertex_map("position") - position_map = graph.get_vertex_point2d_map("position") - if needs_layout: - bgl.circle_graph_layout(graph, position_map, 50) - - self.canvas.set_graph(graph, position_map, - self.canvas.default_property_maps(graph)) - - self.SetTitle(path_to_title(path)) - - dlg.Destroy() - - def SaveGraph(self, event): - dlg = wx.FileDialog( - self, message="Choose a file", defaultDir=os.getcwd(), - defaultFile="", wildcard=wildcard, style=wx.SAVE | wx.CHANGE_DIR) - if dlg.ShowModal() == wx.ID_OK: - path = dlg.GetPath() - # TBD: This fails because we can't serialize Python - # objects. Need to be able to mark some property maps as - # internal (i.e., don't serialize them). - self.canvas.graph.write_graphviz(path) - dlg.Destroy() - - def ConnectedComponents(self, event): - graph = self.canvas.graph - component_map = graph.get_vertex_int_map("component") - bgl.connected_components(graph, component_map) - self.canvas.set_vertex_colors_from_components(component_map) - - def StrongComponents(self, event): - graph = self.canvas.graph - component_map = graph.get_vertex_int_map("component") - bgl.strong_components(graph, component_map) - self.canvas.set_vertex_colors_from_components(component_map) - - def BiconnectedComponents(self, event): - graph = self.canvas.graph - component_map = graph.get_edge_int_map("component") - art_points = bgl.biconnected_components(graph, component_map) - for v in art_points: - self.canvas.VertexShape(v).SetBrush(wx.RED_BRUSH) - self.canvas.set_edge_colors_from_components(component_map) - - def KruskalMST(self, event): - graph = self.canvas.graph - weight_map = graph.get_edge_double_map("weight") - mst_edges = bgl.kruskal_minimum_spanning_tree(graph, weight_map) - for e in mst_edges: - shape = self.canvas.EdgeShape(e) - shape.SetPen(wx.Pen(shape.GetPen().GetColour(), 3)) - self.canvas.Refresh() - - def SequentialVertexColoring(self, event): - graph = self.canvas.graph - color_map = graph.get_vertex_int_map("color") - bgl.sequential_vertex_coloring(graph, color_map) - self.canvas.set_vertex_colors_from_components(color_map) - - def CircleLayout(self, event): - bgl.circle_graph_layout(self.canvas.graph, self.canvas.position_map, 50) - self.canvas.update_layout() - - def FruchtermanReingoldLayout(self, event): - bgl.fruchterman_reingold_force_directed_layout(self.canvas.graph, - self.canvas.position_map, - width=100, height=100, - progressive=True) - self.canvas.update_layout() - - def KamadaKawaiLayout(self, event): - bgl.kamada_kawai_spring_layout(self.canvas.graph, - self.canvas.position_map, side_length=90) - self.canvas.update_layout() - - -class GraphDrawApp(wx.App): - def OnInit(self): - # This creates some pens and brushes that the OGL library uses. - # It should be called after the app object has been created, but - # before OGL is used. - ogl.OGLInitialize() - - self.editor = GraphEditorWindow(None) - self.editor.Show(True) - return True - -app = GraphDrawApp(0) -app.MainLoop() diff --git a/src/python/basic_graph.cpp b/src/python/basic_graph.cpp deleted file mode 100644 index 5970d609..00000000 --- a/src/python/basic_graph.cpp +++ /dev/null @@ -1,686 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#include "basic_graph.hpp" -#include - -namespace boost { - -inline std::ostream& operator<<(std::ostream& out, default_color_type c) -{ - switch (c) { - case white_color: return out << "white"; - case gray_color: return out << "gray"; - case green_color: return out << "green"; - case red_color: return out << "red"; - case black_color: return out << "black"; - } - return out; -} - -inline std::istream& operator>>(std::istream& in, default_color_type& c) -{ - std::string text; - if (in >> text) { - if (text == "white") c = white_color; - else if (text == "gray") c = gray_color; - else if (text == "green") c = green_color; - else if (text == "red") c = red_color; - else if (text == "black") c = black_color; - else { - in.setstate(std::ios_base::failbit); - return in; - } - } - return in; -} - -namespace graph { namespace python { - -template -struct build_string_property_maps -{ - build_string_property_maps(basic_graph* g) : g(g) { } - - std::auto_ptr - operator()(const std::string& name, const boost::any& key, - const boost::any& value) - { - typedef typename basic_graph::VertexIndexMap VertexIndexMap; - typedef typename basic_graph::EdgeIndexMap EdgeIndexMap; - - std::auto_ptr result(0); - - if (key.type() == typeid(typename basic_graph::Vertex)) { - typedef vector_property_map - property_map_type; - typedef python_dynamic_adaptor adaptor_type; - result.reset - (new adaptor_type(property_map_type(g->num_vertices(), - g->get_vertex_index_map()))); - } else if (key.type() == typeid(typename basic_graph::Edge)) { - typedef vector_property_map property_map_type; - typedef python_dynamic_adaptor adaptor_type; - result.reset - (new adaptor_type(property_map_type(g->num_edges(), - g->get_edge_index_map()))); - } - return result; - } - -private: - basic_graph* g; -}; - -// ---------------------------------------------------------- -// Constructors -// ---------------------------------------------------------- -template -basic_graph::basic_graph() - : inherited(), dp(build_string_property_maps(this)) -{ } - -template -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]; - object vp = l[i][1]; - - typename std::map::iterator pos; - pos = verts.find(up); - 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 (!name_map.empty()) name[v] = vp; - } - else v = pos->second; - - add_edge(u, v); - } -} - -template -basic_graph::basic_graph(const std::string& filename, - graph_file_kind kind) - : inherited(), dp(build_string_property_maps(this)) -{ - switch (kind) { - case gfk_adjlist: - break; - case gfk_graphviz: - read_graphviz(filename); - break; - } -} - -template -basic_graph::basic_graph(erdos_renyi er, int seed) - : stored_minstd_rand(seed), - inherited(er_iterator(this->gen, er.n, er.p), er_iterator(), er.n) -{ - renumber_vertices(); - renumber_edges(); -} - -template -basic_graph::basic_graph(power_law_out_degree plod, int seed) - : stored_minstd_rand(seed), - inherited(sf_iterator(this->gen, plod.n, plod.alpha, plod.beta), - sf_iterator(), - plod.n) -{ - renumber_vertices(); - renumber_edges(); -} - -template -basic_graph::basic_graph(small_world sw, int seed) - : stored_minstd_rand(seed), - inherited(sw_iterator(this->gen, sw.n, sw.k, sw.p), sw_iterator(), sw.n) -{ - renumber_vertices(); - renumber_edges(); -} - -// ---------------------------------------------------------- -// Incidence basic_graph concept -// ---------------------------------------------------------- -template -typename basic_graph::Vertex -basic_graph::source(Edge e) const -{ return Vertex(boost::source(e.base, base())); } - -template -typename basic_graph::Vertex -basic_graph::target(Edge e) const -{ return Vertex(boost::target(e.base, base())); } - - -template -std::pair::out_edge_iterator, - typename basic_graph::out_edge_iterator> -basic_graph::out_edges(Vertex u) const -{ - std::pair rng = - boost::out_edges(u.base, base()); - return std::make_pair(out_edge_iterator(rng.first, typename Edge::create()), - out_edge_iterator(rng.second,typename Edge::create())); -} - -template -simple_python_iterator::out_edge_iterator> -basic_graph::py_out_edges(Vertex u) const -{ - return simple_python_iterator(out_edges(u)); -} - -template -std::size_t -basic_graph::out_degree(Vertex u) const -{ - return boost::out_degree(u.base, base()); -} - -// ---------------------------------------------------------- -// Bidirectional basic_graph concept -// ---------------------------------------------------------- -template -std::pair::in_edge_iterator, - typename basic_graph::in_edge_iterator> -basic_graph::in_edges(Vertex u) const -{ - std::pair rng = - boost::in_edges(u.base, base()); - return std::make_pair(in_edge_iterator(rng.first, typename Edge::create()), - in_edge_iterator(rng.second, typename Edge::create())); -} - -template -simple_python_iterator::in_edge_iterator> -basic_graph::py_in_edges(Vertex u) const -{ - return simple_python_iterator(in_edges(u)); -} - -template -std::size_t -basic_graph::in_degree(Vertex u) const -{ - return boost::in_degree(u.base, base()); -} - -// ---------------------------------------------------------- -// Adjacency basic_graph concept -// ---------------------------------------------------------- -template -std::pair::adjacency_iterator, - typename basic_graph::adjacency_iterator> -basic_graph::adjacent_vertices(Vertex u) const -{ - std::pair rng = - boost::adjacent_vertices(u.base, base()); - return std::make_pair(adjacency_iterator(rng.first, typename Vertex::create()), - adjacency_iterator(rng.second, typename Vertex::create())); -} - -template -simple_python_iterator::adjacency_iterator> -basic_graph::py_adjacent_vertices(Vertex u) const -{ - return - simple_python_iterator(adjacent_vertices(u)); -} - -// ---------------------------------------------------------- -// Vertex properties -// ---------------------------------------------------------- -template -template -vector_property_map::VertexIndexMap> -basic_graph::get_vertex_map(const std::string& name) -{ - typedef vector_property_map result_type; - typedef python_dynamic_adaptor adaptor_type; - - dynamic_properties::iterator i = dp.lower_bound(name); - while (i != dp.end() && i->first == name) { - if (i->second->key() == typeid(Vertex)) { - if (i->second->value() == typeid(T)) { - return dynamic_cast(*i->second).base(); - } else { - // Convert the property map element-by-element to the - // requested type. - result_type result(num_vertices(), get_vertex_index_map()); - for(vertex_iterator v = vertices().first; v != vertices().second; - ++v) { - put(result, *v, lexical_cast(i->second->get_string(*v))); - } - - // Replace the existing property map with the converted one - adaptor_type* adaptor = new adaptor_type(result); - delete i->second; - i->second = adaptor; - - // Return the new property map. - return result; - } - } - ++i; - } - - typedef vector_property_map property_map_type; - typedef python_dynamic_adaptor adaptor_type; - property_map_type result(num_vertices(), get_vertex_index_map()); - dp.insert(name, - std::auto_ptr(new adaptor_type(result))); - return result; -} - -template -bool -basic_graph::has_vertex_map(const std::string& name) const -{ - dynamic_properties::const_iterator i = dp.lower_bound(name); - while (i != dp.end() && i->first == name) { - if (i->second->key() == typeid(Vertex)) - return true; - } - return false; -} - -// ---------------------------------------------------------- -// Edge properties -// ---------------------------------------------------------- -template -template -vector_property_map::EdgeIndexMap> -basic_graph::get_edge_map(const std::string& name) -{ - typedef vector_property_map result_type; - typedef python_dynamic_adaptor adaptor_type; - - dynamic_properties::iterator i = dp.lower_bound(name); - while (i != dp.end() && i->first == name) { - if (i->second->key() == typeid(Edge)) { - if (i->second->value() == typeid(T)) { - return dynamic_cast(*i->second).base(); - } else { - // Convert the property map element-by-element to the - // requested type. - result_type result(num_vertices(), get_edge_index_map()); - for(edge_iterator e = edges().first; e != edges().second; ++e) { - put(result, *e, lexical_cast(i->second->get_string(*e))); - } - - // Replace the existing property map with the converted one - adaptor_type* adaptor = new adaptor_type(result); - delete i->second; - i->second = adaptor; - - // Return the new property map. - return result; - } - } - ++i; - } - - typedef vector_property_map property_map_type; - typedef python_dynamic_adaptor adaptor_type; - property_map_type result(num_edges(), get_edge_index_map()); - dp.insert(name, - std::auto_ptr(new adaptor_type(result))); - return result; -} - -template -bool -basic_graph::has_edge_map(const std::string& name) const -{ - dynamic_properties::const_iterator i = dp.lower_bound(name); - while (i != dp.end() && i->first == name) { - if (i->second->key() == typeid(Edge)) - return true; - } - return false; -} - -// ---------------------------------------------------------- -// Mutable graph -// ---------------------------------------------------------- -template -typename basic_graph::Vertex basic_graph::add_vertex() -{ - using boost::add_vertex; - - base_vertex_descriptor v = add_vertex(base()); - put(vertex_index, base(), v, index_to_vertex.size()); - index_to_vertex.push_back(v); - return Vertex(v); -} - -template -void basic_graph::clear_vertex(Vertex vertex) -{ - // Remove all incoming and outgoing edges - while (out_degree(vertex) > 0) remove_edge(*out_edges(vertex).first); - while (in_degree(vertex) > 0) remove_edge(*in_edges(vertex).first); -} - -template -void basic_graph::remove_vertex(Vertex vertex) -{ - using boost::remove_vertex; - - // Update property maps - for (dynamic_properties::iterator i = dp.begin(); i != dp.end(); ++i) { - if (i->second->key() == typeid(Vertex)) { - dynamic_cast(&*i->second)-> - copy_value(vertex, Vertex(index_to_vertex.back())); - } - } - - // Update vertex indices - std::size_t index = get(vertex_index, base(), vertex.base); - index_to_vertex[index] = index_to_vertex.back(); - put(vertex_index, base(), index_to_vertex[index], index); - index_to_vertex.pop_back(); - - // Remove the actual vertex - remove_vertex(vertex.base, base()); -} - -template -std::size_t basic_graph::num_vertices() const -{ - using boost::num_vertices; - return num_vertices(base()); -} - -template -typename basic_graph::vertex_iterator -basic_graph::vertices_begin() const -{ - return make_transform_iterator(boost::vertices(base()).first, - typename Vertex::create()); -} - -template -typename basic_graph::vertex_iterator -basic_graph::vertices_end() const -{ - return make_transform_iterator(boost::vertices(base()).second, - typename Vertex::create()); -} - -template -std::pair::vertex_iterator, - typename basic_graph::vertex_iterator> -basic_graph::vertices() const -{ - return std::make_pair(vertices_begin(), vertices_end()); -} - -template -simple_python_iterator::vertex_iterator> -basic_graph::py_vertices() const -{ - return simple_python_iterator(vertices()); -} - -template -typename basic_graph::Edge -basic_graph::add_edge(Vertex u, Vertex v) -{ - using boost::add_edge; - - base_edge_descriptor e = add_edge(u.base, v.base, base()).first; - put(edge_index, base(), e, index_to_edge.size()); - index_to_edge.push_back(e); - return Edge(e); -} - -template -void basic_graph::remove_edge(Edge edge) -{ - using boost::remove_edge; - - // Update property maps - for (dynamic_properties::iterator i = dp.begin(); i != dp.end(); ++i) { - if (i->second->key() == typeid(Edge)) { - dynamic_cast(&*i->second)-> - copy_value(edge, Edge(index_to_edge.back())); - } - } - - // Update edge indices - std::size_t index = get(edge_index, base(), edge.base); - index_to_edge[index] = index_to_edge.back(); - put(edge_index, base(), index_to_edge[index], index); - index_to_edge.pop_back(); - - // Remove the actual edge - remove_edge(edge.base, base()); -} - -template -std::size_t basic_graph::num_edges() const -{ - using boost::num_edges; - return num_edges(base()); -} - -template -typename basic_graph::edge_iterator -basic_graph::edges_begin() const -{ - return make_transform_iterator(boost::edges(base()).first, - typename Edge::create()); -} - -template -typename basic_graph::edge_iterator -basic_graph::edges_end() const -{ - return make_transform_iterator(boost::edges(base()).second, - typename Edge::create()); -} - -template -std::pair::edge_iterator, - typename basic_graph::edge_iterator> -basic_graph::edges() const -{ - return std::make_pair(edges_begin(), edges_end()); -} - -template -simple_python_iterator::edge_iterator> -basic_graph::py_edges() const -{ - return simple_python_iterator(edges()); -} - -template -void basic_graph::renumber_vertices() -{ - using boost::vertices; - - BGL_FORALL_VERTICES_T(v, base(), inherited) { - put(vertex_index, base(), v, index_to_vertex.size()); - index_to_vertex.push_back(v); - } -} - -template -void basic_graph::renumber_edges() -{ - using boost::edges; - - BGL_FORALL_EDGES_T(e, base(), inherited) { - put(edge_index, base(), e, index_to_edge.size()); - index_to_edge.push_back(e); - } -} - -template void export_in_graph(); - -template -void export_basic_graph(const char* name) -{ - using boost::python::arg; - using boost::python::class_; - using boost::python::init; - using boost::python::object; - using boost::python::range; - using boost::python::scope; - using boost::python::self; - using boost::python::tuple; - - typedef basic_graph Graph; - typedef typename Graph::Vertex Vertex; - typedef typename Graph::Edge Edge; - typedef typename Graph::VertexIndexMap VertexIndexMap; - typedef typename Graph::EdgeIndexMap EdgeIndexMap; - - { - scope s( - class_ >(name) - // Constructors - .def(init()) - .def(init()) - .def(init()) - .def(init( - (arg("generator"), arg("seed") = 1))) - .def(init( - (arg("generator"), arg("seed") = 1))) - .def(init( - (arg("generator"), arg("seed") = 1))) - .def("is_directed", &Graph::is_directed) - // Vertex List Graph concept - .def("num_vertices", &Graph::num_vertices) - .add_property("vertices", &Graph::py_vertices) - // Edge List Graph concept - .def("num_edges", &Graph::num_edges) - .add_property("edges", &Graph::py_edges) - // Mutable Graph concept - .def("add_vertex", &Graph::add_vertex) - .def("clear_vertex", &Graph::clear_vertex) - .def("remove_vertex", &Graph::remove_vertex) - .def("add_edge", &Graph::add_edge) - .def("remove_edge", &Graph::remove_edge) - // Incidence Graph concept - .def("source", &Graph::source) - .def("target", &Graph::target) - .def("out_edges", &Graph::py_out_edges) - .def("out_degree", &Graph::out_degree) - .def("in_edges", &Graph::py_in_edges) - .def("in_degree", &Graph::in_degree) - .def("adjacent_vertices", &Graph::py_adjacent_vertices) - // Vertex property maps - .def("has_vertex_map", &Graph::has_vertex_map) - .def("get_vertex_index_map", &Graph::get_vertex_index_map) - .def("get_vertex_color_map", &Graph::get_vertex_color_map) - .def("get_vertex_double_map", &Graph::get_vertex_double_map) - .def("get_vertex_int_map", &Graph::get_vertex_int_map) - .def("get_vertex_string_map", &Graph::get_vertex_string_map) - .def("get_vertex_object_map", &Graph::get_vertex_object_map) - .def("get_vertex_point2d_map", &Graph::get_vertex_point2d_map) - // Edge property maps - .def("has_edge_map", &Graph::has_edge_map) - .def("get_edge_index_map", &Graph::get_edge_index_map) - .def("get_edge_color_map", &Graph::get_edge_color_map) - .def("get_edge_double_map", &Graph::get_edge_double_map) - .def("get_edge_int_map", &Graph::get_edge_int_map) - .def("get_edge_string_map", &Graph::get_edge_string_map) - .def("get_edge_object_map", &Graph::get_edge_object_map) - // Graph I/O - .def("read_graphviz", &Graph::read_graphviz) - .def("write_graphviz", &Graph::write_graphviz) - .def("write_graphviz", &Graph::write_graphviz_def) - // Pickling - .def_pickle(graph_pickle_suite()) - ); - - export_in_graph(); - } - - if (!type_already_registered()) - class_("Vertex") - .def(self == self) - .def(self != self); - - if (!type_already_registered()) - class_("Edge") - .def(self == self) - .def(self != self); - - // Iterators - simple_python_iterator - ::declare("vertex_iterator"); - simple_python_iterator - ::declare("edge_iterator"); - simple_python_iterator - ::declare("out_edge_iterator"); - simple_python_iterator - ::declare("in_edge_iterator"); - simple_python_iterator - ::declare("adjacency_iterator"); - - // Vertex property maps - declare_readable_property_map - ::declare("vertex_index_map"); - declare_property_map > - ::declare("vertex_vertex_map"); - declare_property_map > - ::declare("vertex_double_map"); - declare_property_map > - ::declare("vertex_int_map"); - declare_property_map > - ::declare("vertex_string_map"); - declare_property_map > - ::declare("vertex_object_map"); - declare_property_map > - ::declare("vertex_color_map"); - declare_property_map > - ::declare("vertex_point2d_map"); - - // Edge property maps - declare_readable_property_map - ::declare("edge_index_map"); - declare_property_map > - ::declare("edge_edge_map"); - declare_property_map > - ::declare("edge_double_map"); - declare_property_map > - ::declare("edge_int_map"); - declare_property_map > - ::declare("edge_string_map"); - declare_property_map > - ::declare("edge_object_map"); - declare_property_map > - ::declare("edge_color_map"); -} - -} } } // end namespace boost::graph::python diff --git a/src/python/basic_graph.hpp b/src/python/basic_graph.hpp deleted file mode 100644 index ad522111..00000000 --- a/src/python/basic_graph.hpp +++ /dev/null @@ -1,596 +0,0 @@ -// Copyright 2004-5 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#ifndef BOOST_GRAPH_BASIC_GRAPH_HPP -#define BOOST_GRAPH_BASIC_GRAPH_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "point2d.hpp" -#include "generators.hpp" - -namespace boost { namespace graph { namespace python { - -template bool type_already_registered() -{ - using boost::python::objects::registered_class_object; - using boost::python::type_id; - - return registered_class_object(type_id()).get() != 0; -} - -template -class simple_python_iterator -{ -public: - typedef typename std::iterator_traits::difference_type - difference_type; - - simple_python_iterator(std::pair p) - : orig_first(p.first), first(p.first), last(p.second), n(-1) { } - - typename std::iterator_traits::value_type next() - { - using boost::python::objects::stop_iteration_error; - - if (first == last) stop_iteration_error(); - return *first++; - } - - difference_type len() - { - if (n == -1) n = std::distance(first, last); - return n; - } - - static void declare(const char* name) - { - using boost::python::class_; - using boost::python::no_init; - using boost::python::objects::identity_function; - if (!type_already_registered()) - class_ >(name, no_init) - .def("__iter__", identity_function()) - .def("__len__", &simple_python_iterator::len) - .def("next", &simple_python_iterator::next) - ; - } - -private: - Iterator orig_first; - Iterator first; - Iterator last; - difference_type n; -}; - -template -struct declare_readable_property_map -{ - typedef typename property_traits::key_type key_type; - typedef typename property_traits::value_type value_type; - - static value_type getitem(const PropertyMap& pm, const key_type& key) - { return get(pm, key); } - - static void declare(const char* name) - { - using boost::python::class_; - using boost::python::no_init; - - if (!type_already_registered()) - class_(name, no_init) - .def("__getitem__", &getitem) - ; - } -}; - -template -struct declare_property_map -{ - typedef typename property_traits::key_type key_type; - typedef typename property_traits::value_type value_type; - - static value_type getitem(const PropertyMap& pm, const key_type& key) - { return get(pm, key); } - - static void - setitem(const PropertyMap& pm, const key_type& key,const value_type& value) - { return put(pm, key, value); } - - static void declare(const char* name) - { - using boost::python::class_; - using boost::python::no_init; - - if (!type_already_registered()) - class_(name, no_init) - .def("__getitem__", &getitem) - .def("__setitem__", &setitem) - ; - } -}; - -template -struct basic_descriptor -{ - basic_descriptor() {} - basic_descriptor(T base) : base(base) { } - - operator T() const { return base; } - - struct create - { - typedef basic_descriptor result_type; - basic_descriptor operator()(T base) const { return base; } - }; - - T base; -}; - -template -inline bool -operator==(const basic_descriptor& u, - const basic_descriptor& v) -{ return u.base == v.base; } - -template -inline bool -operator!=(const basic_descriptor& u, - const basic_descriptor& v) -{ return u.base != v.base; } - -template -struct basic_index_map -{ - typedef Key key_type; - typedef typename property_traits::value_type value_type; - typedef typename property_traits::reference reference; - typedef typename property_traits::category category; - - basic_index_map(const IndexMap& id = IndexMap()) - : id(id) { } - - IndexMap id; -}; - -template -inline typename basic_index_map::value_type -get(const basic_index_map& pm, - typename basic_index_map::key_type const& key) -{ return get(pm.id, key.base); } - -enum graph_file_kind { gfk_adjlist, gfk_graphviz }; - -struct stored_minstd_rand -{ - stored_minstd_rand(int seed = 1) : gen(seed) { } - - minstd_rand gen; -}; - -template -class basic_graph - : public stored_minstd_rand, - public adjacency_list, - property > -{ - typedef adjacency_list, - property > inherited; - typedef graph_traits traits; - - typedef typename traits::vertex_iterator base_vertex_iterator; - typedef typename traits::edge_iterator base_edge_iterator; - typedef typename traits::out_edge_iterator base_out_edge_iterator; - typedef typename traits::in_edge_iterator base_in_edge_iterator; - typedef typename traits::adjacency_iterator base_adjacency_iterator; - typedef typename property_map::const_type - base_vertex_index_map; - typedef typename property_map::const_type - base_edge_index_map; - typedef typename traits::vertex_descriptor base_vertex_descriptor; - typedef typename traits::edge_descriptor base_edge_descriptor; - - typedef erdos_renyi_iterator > - er_iterator; - typedef plod_iterator > - sf_iterator; - typedef small_world_iterator > - sw_iterator; - - public: - typedef basic_descriptor - Vertex; - typedef Vertex vertex_descriptor; - typedef basic_descriptor - Edge; - typedef Edge edge_descriptor; - typedef basic_index_map - VertexIndexMap; - typedef basic_index_map EdgeIndexMap; - typedef std::size_t vertices_size_type; - typedef std::size_t edges_size_type; - typedef std::size_t degree_size_type; - typedef typename traits::directed_category directed_category; - typedef typename traits::edge_parallel_category edge_parallel_category; - typedef typename traits::traversal_category traversal_category; - typedef transform_iterator - vertex_iterator; - typedef transform_iterator - edge_iterator; - typedef transform_iterator - out_edge_iterator; - typedef transform_iterator - in_edge_iterator; - typedef transform_iterator - adjacency_iterator; - - basic_graph(); - 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); - basic_graph(small_world, int seed); - - bool is_directed() const - { return is_convertible::value; } - - Vertex add_vertex(); - void clear_vertex(Vertex vertex); - void remove_vertex(Vertex vertex); - std::size_t num_vertices() const; - std::pair vertices() const; - simple_python_iterator py_vertices() const; - vertex_iterator vertices_begin() const; - vertex_iterator vertices_end() const; - - Edge add_edge(Vertex u, Vertex v); - void remove_edge(Edge edge); - std::size_t num_edges() const; - std::pair edges() const; - simple_python_iterator py_edges() const; - edge_iterator edges_begin() const; - edge_iterator edges_end() const; - - // Incidence Graph concept - Vertex source(Edge e) const; - Vertex target(Edge e) const; - std::pair out_edges(Vertex u) const; - simple_python_iterator py_out_edges(Vertex u) const; - std::size_t out_degree(Vertex u) const; - - // Bidirectional Graph concept - std::pair in_edges(Vertex u) const; - simple_python_iterator py_in_edges(Vertex u) const; - std::size_t in_degree(Vertex u) const; - - // Adjacency Graph concept - std::pair - adjacent_vertices(Vertex u) const; - - simple_python_iterator - py_adjacent_vertices(Vertex u) const; - - // Vertex property maps - VertexIndexMap get_vertex_index_map() const - { return get(vertex_index, base()); } - - template - vector_property_map - get_vertex_map(const std::string& name); - - bool has_vertex_map(const std::string& name) const; - - // Edge property maps - EdgeIndexMap get_edge_index_map() const - { return get(edge_index, base()); } - - template - vector_property_map - get_edge_map(const std::string& name); - - bool has_edge_map(const std::string& name) const; - - // Graph I/O - void read_graphviz(const std::string& filename, - const std::string& node_id = std::string("node_id")); - - void write_graphviz(const std::string& filename, - const std::string& node_id = std::string("node_id")); - - void write_graphviz_def(const std::string& filename) - { write_graphviz(filename); } - - // Simple functions for Visual C++ 7.1 :( - vector_property_map - get_vertex_color_map(const std::string& name) - { return get_vertex_map(name); } - - vector_property_map - get_vertex_double_map(const std::string& name) - { return get_vertex_map(name); } - - vector_property_map - get_vertex_int_map(const std::string& name) - { return get_vertex_map(name); } - - vector_property_map - get_vertex_string_map(const std::string& name) - { return get_vertex_map(name); } - - vector_property_map - get_vertex_object_map(const std::string& name) - { return get_vertex_map(name); } - - vector_property_map - get_vertex_point2d_map(const std::string& name) - { return get_vertex_map(name); } - - vector_property_map - get_edge_color_map(const std::string& name) - { return get_edge_map(name); } - - vector_property_map - get_edge_double_map(const std::string& name) - { return get_edge_map(name); } - - vector_property_map - get_edge_int_map(const std::string& name) - { return get_edge_map(name); } - - vector_property_map - get_edge_string_map(const std::string& name) - { return get_edge_map(name); } - - vector_property_map - get_edge_object_map(const std::string& name) - { return get_edge_map(name); } - - inherited& base() { return *this; } - const inherited& base() const { return *this; } - - dynamic_properties& get_dynamic_properties() { return dp; } - const dynamic_properties& get_dynamic_properties() const { return dp; } - -protected: - void renumber_vertices(); - void renumber_edges(); - -private: - std::vector index_to_vertex; - std::vector index_to_edge; - dynamic_properties dp; -}; - -// Vertex List Graph concept -template -inline std::pair::vertex_iterator, - typename basic_graph::vertex_iterator> -vertices(const basic_graph& g) -{ return g.vertices(); } - -template -inline std::size_t num_vertices(const basic_graph& g) -{ return g.num_vertices(); } - -// Edge List Graph concept -template -inline std::pair::edge_iterator, - typename basic_graph::edge_iterator> -edges(const basic_graph& g) -{ return g.edges(); } - -template -inline std::size_t num_edges(const basic_graph& g) -{ return g.num_edges(); } - -// Incidence Graph concept -template -inline typename basic_graph::vertex_descriptor -source(typename basic_graph::edge_descriptor e, - const basic_graph& g) -{ return g.source(e); } - -template -inline typename basic_graph::vertex_descriptor -target(typename basic_graph::edge_descriptor e, - const basic_graph& g) -{ return g.target(e); } - -template -inline std::pair::out_edge_iterator, - typename basic_graph::out_edge_iterator> -out_edges(typename basic_graph::vertex_descriptor u, - const basic_graph& g) -{ return g.out_edges(u); } - -template -inline std::size_t -out_degree(typename basic_graph::vertex_descriptor u, - const basic_graph& g) -{ return g.out_degree(u); } - -// Bidirectional Graph concept -template -inline std::pair::in_edge_iterator, - typename basic_graph::in_edge_iterator> -in_edges(typename basic_graph::vertex_descriptor u, - const basic_graph& g) -{ return g.in_edges(u); } - -template -inline std::size_t -in_degree(typename basic_graph::vertex_descriptor u, - const basic_graph& g) -{ return g.in_degree(u); } - -// Adjacency Graph concept -template -inline std::pair::adjacency_iterator, - typename basic_graph::adjacency_iterator> -adjacent_vertices(typename basic_graph::vertex_descriptor u, - const basic_graph& g) -{ return g.adjacent_vertices(u); } - -// Mutable basic_graph concept -template -inline typename basic_graph::vertex_descriptor -add_vertex(basic_graph& g) -{ return g.add_vertex(); } - -template -inline std::pair::edge_descriptor, bool> -add_edge(typename basic_graph::vertex_descriptor u, - typename basic_graph::vertex_descriptor v, - basic_graph& g) -{ return std::make_pair(g.add_edge(u, v), true); } - -template -void export_basic_graph(const char* name); - -template -typename basic_graph::VertexIndexMap -get(vertex_index_t, const basic_graph& g) -{ return g.get_vertex_index_map(); } - -template -typename basic_graph::EdgeIndexMap -get(edge_index_t, const basic_graph& g) -{ return g.get_edge_index_map(); } - -template -struct graph_pickle_suite : boost::python::pickle_suite -{ - typedef basic_graph Graph; - typedef typename Graph::vertex_descriptor Vertex; - typedef typename Graph::edge_descriptor Edge; - - static - boost::python::tuple - getstate(boost::python::object g_obj); - - static - void - setstate(boost::python::object g_obj, boost::python::tuple state); -}; - -class python_dynamic_property_map -{ - public: - virtual ~python_dynamic_property_map() {} - - virtual void copy_value(const any& to, const any& from) = 0; - virtual boost::python::object get_python(const any& key) = 0; -}; - -template::value_type> -class python_dynamic_adaptor - : public boost::detail::dynamic_property_map_adaptor, - public python_dynamic_property_map -{ - typedef boost::detail::dynamic_property_map_adaptor inherited; - -public: - typedef typename property_traits::key_type key_type; - - explicit python_dynamic_adaptor(const PropertyMap& property_map) - : inherited(property_map) { } - - virtual void copy_value(const any& to, const any& from) - { - boost::put(this->base(), any_cast(to), - boost::get(this->base(), any_cast(from))); - } - - virtual boost::python::object get_python(const any& key) - { -#if defined(__GNUC__) && (__GNUC__ == 2) && (__GNUC_MINOR__ == 95) - return boost::get(this->base(), any_cast(key)); -#else - using boost::get; - - return boost::python::object(get(this->base(), any_cast(key))); -#endif - } -}; - -template -class python_dynamic_adaptor - : public boost::detail::dynamic_property_map_adaptor, - public python_dynamic_property_map -{ - typedef boost::detail::dynamic_property_map_adaptor inherited; - -public: - typedef typename property_traits::key_type key_type; - - explicit python_dynamic_adaptor(const PropertyMap& property_map) - : inherited(property_map) { } - - virtual void copy_value(const any& to, const any& from) - { - boost::put(this->base(), any_cast(to), - boost::get(this->base(), any_cast(from))); - } - - virtual std::string get_string(const any& key) - { - using boost::python::extract; - using boost::python::str; - return std::string( - extract(str(boost::get(this->base(), - any_cast(key))))); - } - - virtual boost::python::object get_python(const any& key) - { -#if defined(__GNUC__) && (__GNUC__ == 2) && (__GNUC_MINOR__ == 95) - return boost::get(this->base(), any_cast(key)); -#else - using boost::get; - - return get(this->base(), any_cast(key)); -#endif - } -}; - -} } } // end namespace boost::graph::python - -#if 0 -// Triggers bugs in GCC -namespace boost { - template - struct property_map, vertex_index_t> - { - typedef typename graph::python::basic_graph::VertexIndexMap - type; - typedef type const_type; - }; - - template - struct property_map, edge_index_t> - { - typedef typename graph::python::basic_graph::EdgeIndexMap - type; - typedef type const_type; - }; -} -#endif - -#endif // BOOST_GRAPH_BASIC_GRAPH_HPP diff --git a/src/python/bellman_ford_events.hpp b/src/python/bellman_ford_events.hpp deleted file mode 100644 index db31d60b..00000000 --- a/src/python/bellman_ford_events.hpp +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -BGL_PYTHON_EVENT(initialize_vertex, vertex_descriptor) -BGL_PYTHON_EVENT(examine_edge, edge_descriptor) -BGL_PYTHON_EVENT(edge_relaxed, edge_descriptor) -BGL_PYTHON_EVENT(edge_not_relaxed, edge_descriptor) -BGL_PYTHON_EVENT(edge_minimized, edge_descriptor) -BGL_PYTHON_EVENT(edge_not_minimized, edge_descriptor) - diff --git a/src/python/bellman_ford_shortest_paths.cpp b/src/python/bellman_ford_shortest_paths.cpp deleted file mode 100644 index 22edacfc..00000000 --- a/src/python/bellman_ford_shortest_paths.cpp +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#include -#include "graph.hpp" -#include "digraph.hpp" -#include - -namespace boost { namespace graph { namespace python { - -#define BGL_PYTHON_VISITOR bellman_ford_visitor -#define BGL_PYTHON_EVENTS_HEADER "bellman_ford_events.hpp" -#include "visitor.hpp" -#undef BGL_PYTHON_EVENTS_HEADER -#undef BGL_PYTHON_VISITOR - -template -void -bellman_ford_shortest_paths - (Graph& g, typename Graph::Vertex s, - const vector_property_map* in_predecessor, - const vector_property_map* in_distance, - const vector_property_map* in_weight, - const bellman_ford_visitor& visitor) -{ - typedef vector_property_map - PredecessorMap; - typedef vector_property_map - DistanceMap; - typedef vector_property_map - WeightMap; - - PredecessorMap predecessor = - in_predecessor? *in_predecessor - : PredecessorMap(g.num_vertices(), g.get_vertex_index_map()); - - DistanceMap distance = - in_distance? *in_distance - : DistanceMap(g.num_vertices(), g.get_vertex_index_map()); - - WeightMap weight = in_weight? *in_weight - : g.template get_edge_map("weight"); - - typedef typename bellman_ford_visitor::default_arg default_visitor; - bool has_default_visitor = dynamic_cast(&visitor); - - if (!has_default_visitor) { - boost::bellman_ford_shortest_paths - (g, - root_vertex(s). - vertex_index_map(g.get_vertex_index_map()). - visitor(typename bellman_ford_visitor::ref(visitor)). - predecessor_map(predecessor). - distance_map(distance). - weight_map(weight)); - } else { - boost::bellman_ford_shortest_paths - (g, - root_vertex(s). - vertex_index_map(g.get_vertex_index_map()). - predecessor_map(predecessor). - distance_map(distance). - weight_map(weight)); - } -} - - -template -void export_bellman_ford_shortest_paths_in_graph() -{ - bellman_ford_visitor::declare("BellmanFordVisitor", - "DefaultBellmanFordVisitor"); -} - -void export_bellman_ford_shortest_paths() -{ - using boost::python::arg; - using boost::python::def; - - def("bellman_ford_shortest_paths", &bellman_ford_shortest_paths, - (arg("graph"), arg("root_vertex"), - arg("predecessor_map") = - (vector_property_map*)0, - arg("distance_map") = - (vector_property_map*)0, - arg("weight_map") = - (vector_property_map*)0, - arg("visitor") = bellman_ford_visitor::default_arg())); - - def("bellman_ford_shortest_paths", &bellman_ford_shortest_paths, - (arg("graph"), arg("root_vertex"), - arg("predecessor_map") = - (vector_property_map*)0, - arg("distance_map") = - (vector_property_map*)0, - arg("weight_map") = - (vector_property_map*)0, - arg("visitor") = bellman_ford_visitor::default_arg())); -} - -template void export_bellman_ford_shortest_paths_in_graph(); -template void export_bellman_ford_shortest_paths_in_graph(); - -} } } // end namespace boost::graph::python diff --git a/src/python/betweenness_centrality.cpp b/src/python/betweenness_centrality.cpp deleted file mode 100644 index 7949f74d..00000000 --- a/src/python/betweenness_centrality.cpp +++ /dev/null @@ -1,196 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#include "graph.hpp" -#include "digraph.hpp" -#include -#include - -namespace boost { namespace graph { namespace python { - -template -void -brandes_betweenness_centrality - (Graph& g, - const vector_property_map* in_vertex_centrality, - const vector_property_map* in_edge_centrality, - const vector_property_map* weight) -{ - typedef vector_property_map - VertexCentralityMap; - - typedef vector_property_map - EdgeCentralityMap; - - VertexCentralityMap vertex_centrality = - in_vertex_centrality? *in_vertex_centrality - : g.template get_vertex_map("centrality"); - - EdgeCentralityMap edge_centrality = - in_edge_centrality? *in_edge_centrality - : g.template get_edge_map("centrality"); - - if (weight) { - boost::brandes_betweenness_centrality - (g, - weight_map(*weight). - centrality_map(vertex_centrality). - edge_centrality_map(edge_centrality). - vertex_index_map(g.get_vertex_index_map())); - } else { - boost::brandes_betweenness_centrality - (g, - centrality_map(vertex_centrality). - edge_centrality_map(edge_centrality). - vertex_index_map(g.get_vertex_index_map())); - } -} - -template -void -relative_betweenness_centrality - (Graph& g, - const vector_property_map* in_centrality) -{ - typedef vector_property_map - CentralityMap; - - CentralityMap centrality = - in_centrality? *in_centrality - : g.template get_vertex_map("centrality"); - - relative_betweenness_centrality(g, centrality); -} - -template -double -central_point_dominance - (Graph& g, - const vector_property_map* in_centrality) -{ - typedef vector_property_map - CentralityMap; - - CentralityMap centrality = - in_centrality? *in_centrality - : g.template get_vertex_map("centrality"); - - return boost::central_point_dominance(g, centrality); -} - -struct bc_clustering_done_python -{ - explicit bc_clustering_done_python(boost::python::object done) - : done(done) { } - - template - bool - operator()(double max_centrality, - typename graph_traits::edge_descriptor e, - const Graph& g) - { - using boost::python::extract; - return extract(done(max_centrality, e, ref(g))); - } - -private: - boost::python::object done; -}; - -template -void -betweenness_centrality_clustering - (Graph& g, boost::python::object done, - const vector_property_map* in_edge_centrality) -// const vector_property_map* weight) -{ - typedef vector_property_map - EdgeCentralityMap; - - EdgeCentralityMap edge_centrality = - in_edge_centrality? *in_edge_centrality - : g.template get_edge_map("centrality"); - -#if 0 - if (weight) { - boost::betweenness_centrality_clustering - (g, - weight_map(*weight). - centrality_map(vertex_centrality). - edge_centrality_map(edge_centrality). - vertex_index_map(g.get_vertex_index_map())); - } else { -#endif - boost::betweenness_centrality_clustering(g, - bc_clustering_done_python(done), - edge_centrality, - g.get_vertex_index_map()); - // } -} - -void export_betweenness_centrality() -{ - using boost::python::arg; - using boost::python::def; - - // Graph - def("brandes_betweenness_centrality", - &brandes_betweenness_centrality, - (arg("graph"), - arg("vertex_centrality_map") = - (vector_property_map*)0, - arg("edge_centrality_map") = - (vector_property_map*)0, - arg("weight_map") = - (vector_property_map*)0)); - def("relative_betweenness_centrality", - &relative_betweenness_centrality, - (arg("graph"), - arg("vertex_centrality_map") = - (vector_property_map*)0)); - def("central_point_dominance", - ¢ral_point_dominance, - (arg("graph"), - arg("vertex_centrality_map") = - (vector_property_map*)0)); - def("betweenness_centrality_clustering", - &betweenness_centrality_clustering, - (arg("graph"), - arg("done"), - arg("edge_centrality_map") = - (vector_property_map*)0)); - - // Digraph - def("brandes_betweenness_centrality", - &brandes_betweenness_centrality, - (arg("graph"), - arg("vertex_centrality_map") = - (vector_property_map*)0, - arg("edge_centrality_map") = - (vector_property_map*)0, - arg("weight_map") = - (vector_property_map*)0)); - def("relative_betweenness_centrality", - &relative_betweenness_centrality, - (arg("graph"), - arg("vertex_centrality_map") = - (vector_property_map*)0)); - def("central_point_dominance", - ¢ral_point_dominance, - (arg("graph"), - arg("vertex_centrality_map") = - (vector_property_map*)0)); - def("betweenness_centrality_clustering", - &betweenness_centrality_clustering, - (arg("graph"), - arg("done"), - arg("edge_centrality_map") = - (vector_property_map*)0)); -} - -} } } // end namespace boost::graph::python diff --git a/src/python/bfs_events.hpp b/src/python/bfs_events.hpp deleted file mode 100644 index f0cb6f23..00000000 --- a/src/python/bfs_events.hpp +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine - -BGL_PYTHON_EVENT(initialize_vertex, vertex_descriptor) -BGL_PYTHON_EVENT(discover_vertex, vertex_descriptor) -BGL_PYTHON_EVENT(examine_vertex, vertex_descriptor) -BGL_PYTHON_EVENT(examine_edge, edge_descriptor) -BGL_PYTHON_EVENT(tree_edge, edge_descriptor) -BGL_PYTHON_EVENT(non_tree_edge, edge_descriptor) -BGL_PYTHON_EVENT(gray_target, edge_descriptor) -BGL_PYTHON_EVENT(black_target, edge_descriptor) -BGL_PYTHON_EVENT(finish_vertex, vertex_descriptor) diff --git a/src/python/biconnected_components.cpp b/src/python/biconnected_components.cpp deleted file mode 100644 index 76e164be..00000000 --- a/src/python/biconnected_components.cpp +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#include -#include "graph.hpp" -#include "digraph.hpp" -#include -#include -#include - -namespace boost { namespace graph { namespace python { - -template -boost::python::list -biconnected_components - (Graph& g, - const vector_property_map* in_component) -{ - typedef vector_property_map ComponentMap; - - ComponentMap component = - in_component? *in_component : g.template get_edge_map("bicomponent"); - - std::list art_points; - boost::biconnected_components(g, component, std::back_inserter(art_points), - boost::vertex_index_map(g.get_vertex_index_map())); - boost::python::list result; - for (typename std::list::iterator i - = art_points.begin(); i != art_points.end(); ++i) - result.append(*i); - return result; -} - -template -boost::python::list -articulation_points(const Graph& g) -{ - std::list art_points; - boost::python::list result; - boost::articulation_points(g, std::back_inserter(art_points), - boost::vertex_index_map(g.get_vertex_index_map())); - for (typename std::list::iterator i - = art_points.begin(); i != art_points.end(); ++i) - result.append(*i); - return result; -} - -void export_biconnected_components() -{ - using boost::python::arg; - using boost::python::def; - - def("biconnected_components", &biconnected_components, - (arg("graph"), - arg("component_map") = - (vector_property_map*)0)); - def("articulation_points", &articulation_points, (arg("graph"))); - - def("biconnected_components", &biconnected_components, - (arg("graph"), - arg("component_map") = - (vector_property_map*)0)); - def("articulation_points", &articulation_points, (arg("graph"))); -} - -} } } // end namespace boost::graph::python diff --git a/src/python/breadth_first_search.cpp b/src/python/breadth_first_search.cpp deleted file mode 100644 index 43ca1cbc..00000000 --- a/src/python/breadth_first_search.cpp +++ /dev/null @@ -1,147 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#include -#include "graph.hpp" -#include "digraph.hpp" -#include "queue.hpp" - -namespace boost { namespace graph { namespace python { - -#define BGL_PYTHON_VISITOR bfs_visitor -#define BGL_PYTHON_EVENTS_HEADER "bfs_events.hpp" -#include "visitor.hpp" -#undef BGL_PYTHON_EVENTS_HEADER -#undef BGL_PYTHON_VISITOR - -template -void -breadth_first_search - (const Graph& g, - typename Graph::Vertex s, - python_queue& Q, - const bfs_visitor& visitor, - const vector_property_map* in_color) -{ - typedef vector_property_map ColorMap; - - ColorMap color = - in_color? *in_color : ColorMap(g.num_vertices(), g.get_vertex_index_map()); - - typedef typename python_queue::default_queue - default_queue_type; - - bool has_default_buffer = dynamic_cast(&Q); - bool has_default_visitor = - dynamic_cast::default_arg const*>(&visitor); - - if (has_default_buffer) { - if (has_default_visitor) { - boost::breadth_first_search(g, s, color_map(color)); - } else { - boost::breadth_first_search - (g, s, - color_map(color). - visitor(typename bfs_visitor::ref(visitor))); - } - } else { - if (has_default_visitor) { - boost::breadth_first_search(g, s, - buffer(Q). - color_map(color)); - } else { - boost::breadth_first_search - (g, s, Q, typename bfs_visitor::ref(visitor), color); - } - } -} - -template -void -breadth_first_visit - (const Graph& g, - typename Graph::Vertex s, - python_queue& Q, - const bfs_visitor& visitor, - const vector_property_map& color) -{ - typedef typename python_queue::default_queue - default_queue_type; - - bool has_default_buffer = dynamic_cast(&Q); - bool has_default_visitor = - dynamic_cast::default_arg const*>(&visitor); - - if (has_default_buffer) { - if (has_default_visitor) { - boost::breadth_first_visit(g, s, color_map(color)); - } else { - boost::breadth_first_visit - (g, s, - color_map(color). - visitor(typename bfs_visitor::ref(visitor))); - } - } else { - if (has_default_visitor) { - boost::breadth_first_visit(g, s, - buffer(Q). - color_map(color)); - } else { - boost::breadth_first_visit - (g, s, Q, typename bfs_visitor::ref(visitor), color); - } - } -} - -void export_breadth_first_search() -{ - using boost::python::arg; - using boost::python::def; - - def("breadth_first_search", &breadth_first_search, - (arg("graph"), "root_vertex", - arg("buffer") = python_queue::default_queue(), - arg("visitor") = bfs_visitor::default_arg(), - arg("color_map") = - (vector_property_map*)0)); - - def("breadth_first_visit", &breadth_first_visit, - (arg("graph"), "root_vertex", - arg("buffer") = python_queue::default_queue(), - arg("visitor") = bfs_visitor::default_arg(), - arg("color_map"))); - - def("breadth_first_search", &breadth_first_search, - (arg("graph"), "root_vertex", - arg("buffer") = python_queue::default_queue(), - arg("visitor") = bfs_visitor::default_arg(), - arg("color_map") = - (vector_property_map*)0)); - - def("breadth_first_visit", &breadth_first_visit, - (arg("graph"), "root_vertex", - arg("buffer") = python_queue::default_queue(), - arg("visitor") = bfs_visitor::default_arg(), - arg("color_map"))); -} - -template -void export_breadth_first_search_in_graph() -{ - bfs_visitor::declare("BFSVisitor", "DefaultBFSVisitor"); - python_queue::declare("VertexQueue", - "DefaultVertexQueue"); -} - -template void export_breadth_first_search_in_graph(); -template void export_breadth_first_search_in_graph(); - -} } } // end namespace boost::graph::python diff --git a/src/python/circle_layout.cpp b/src/python/circle_layout.cpp deleted file mode 100644 index 1f2d8e34..00000000 --- a/src/python/circle_layout.cpp +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#include -#include "graph.hpp" -#include "digraph.hpp" -#include "point2d.hpp" - -namespace boost { namespace graph { namespace python { - -template -void -circle_graph_layout - (Graph& g, - const vector_property_map* in_pos, - double radius) -{ - typedef vector_property_map - PositionMap; - - PositionMap pos = - in_pos? *in_pos : g.template get_vertex_map("position"); - - circle_graph_layout(g, pos, radius); -} - -void export_circle_graph_layout() -{ - using boost::python::arg; - using boost::python::def; - - def("circle_graph_layout", - &circle_graph_layout, - (arg("graph"), - arg("position") = - (vector_property_map*)0, - arg("radius") = 250.0)); - - def("circle_graph_layout", - &circle_graph_layout, - (arg("graph"), - arg("position") = - (vector_property_map*)0, - arg("radius") = 250.0)); -} - -} } } // end namespace boost::graph::python diff --git a/src/python/connected_components.cpp b/src/python/connected_components.cpp deleted file mode 100644 index e91ffa56..00000000 --- a/src/python/connected_components.cpp +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#include -#include "graph.hpp" -#include "digraph.hpp" -#include - -namespace boost { namespace graph { namespace python { - -template -int -connected_components - (Graph& g, - const vector_property_map* in_component, - const vector_property_map* in_color) -{ - typedef vector_property_map ComponentMap; - - typedef vector_property_map ColorMap; - - ComponentMap component = - in_component? *in_component : g.template get_vertex_map("component"); - - ColorMap color = - in_color? *in_color : ColorMap(g.num_vertices(), g.get_vertex_index_map()); - - return boost::connected_components(g, component, color_map(color)); -} - -void export_connected_components() -{ - using boost::python::arg; - using boost::python::def; - - def("connected_components", &connected_components, - (arg("graph"), - arg("component_map") = - (vector_property_map*)0, - arg("color_map") = - (vector_property_map*)0)); -} - -} } } // end namespace boost::graph::python diff --git a/src/python/cuthill_mckee_ordering.cpp b/src/python/cuthill_mckee_ordering.cpp deleted file mode 100644 index 8d9cce4e..00000000 --- a/src/python/cuthill_mckee_ordering.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#include -#include "graph.hpp" -#include "digraph.hpp" -#include -#include -#include - -namespace boost { namespace graph { namespace python { - -template -boost::python::list -cuthill_mckee_ordering(const Graph& g) -{ - std::list ordering; - boost::python::list result; - boost::cuthill_mckee_ordering(g, std::back_inserter(ordering), - g.get_vertex_index_map()); - for (typename std::list::iterator i - = ordering.begin(); i != ordering.end(); ++i) - result.append(*i); - return result; -} - -void export_cuthill_mckee_ordering() -{ - using boost::python::arg; - using boost::python::def; - def("cuthill_mckee_ordering", &cuthill_mckee_ordering, arg("graph")); -} - -} } } // end namespace boost::graph::python diff --git a/src/python/dag_shortest_paths.cpp b/src/python/dag_shortest_paths.cpp deleted file mode 100644 index 88659bd5..00000000 --- a/src/python/dag_shortest_paths.cpp +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#include -#include "graph.hpp" -#include "digraph.hpp" -#include -#include "dijkstra_visitor.hpp" - -namespace boost { namespace graph { namespace python { - -template -void -dag_shortest_paths - (Graph& g, typename Graph::Vertex s, - const vector_property_map* in_predecessor, - const vector_property_map* in_distance, - const vector_property_map* in_weight, - const dijkstra_visitor& visitor) -{ - typedef vector_property_map - PredecessorMap; - typedef vector_property_map - DistanceMap; - typedef vector_property_map - WeightMap; - - PredecessorMap predecessor = - in_predecessor? *in_predecessor - : PredecessorMap(g.num_vertices(), g.get_vertex_index_map()); - - DistanceMap distance = - in_distance? *in_distance - : DistanceMap(g.num_vertices(), g.get_vertex_index_map()); - - WeightMap weight = in_weight? *in_weight - : g.template get_edge_map("weight"); - - typedef typename dijkstra_visitor::default_arg default_visitor; - bool has_default_visitor = dynamic_cast(&visitor); - - if (!has_default_visitor) { - boost::dag_shortest_paths - (g, s, - vertex_index_map(g.get_vertex_index_map()). - visitor(typename dijkstra_visitor::ref(visitor)). - predecessor_map(predecessor). - distance_map(distance). - weight_map(weight)); - } else { - boost::dag_shortest_paths - (g, s, - vertex_index_map(g.get_vertex_index_map()). - predecessor_map(predecessor). - distance_map(distance). - weight_map(weight)); - } -} - -template -void export_dag_shortest_paths_in_graph() -{ - dijkstra_visitor::declare("DijkstraVisitor", - "DefaultDijkstraVisitor"); -} - -void export_dag_shortest_paths() -{ - using boost::python::arg; - using boost::python::def; - - def("dag_shortest_paths", &dag_shortest_paths, - (arg("graph"), arg("root_vertex"), - arg("predecessor_map") = - (vector_property_map*)0, - arg("distance_map") = - (vector_property_map*)0, - arg("weight_map") = - (vector_property_map*)0, - arg("visitor") = dijkstra_visitor::default_arg())); - - def("dag_shortest_paths", &dag_shortest_paths, - (arg("graph"), arg("root_vertex"), - arg("predecessor_map") = - (vector_property_map*)0, - arg("distance_map") = - (vector_property_map*)0, - arg("weight_map") = - (vector_property_map*)0, - arg("visitor") = dijkstra_visitor::default_arg())); -} - -template void export_dag_shortest_paths_in_graph(); -template void export_dag_shortest_paths_in_graph(); - -} } } // end namespace boost::graph::python diff --git a/src/python/depth_first_search.cpp b/src/python/depth_first_search.cpp deleted file mode 100644 index 84f2d66b..00000000 --- a/src/python/depth_first_search.cpp +++ /dev/null @@ -1,163 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#include -#include -#include "graph.hpp" -#include "digraph.hpp" -#include "queue.hpp" - -namespace boost { namespace graph { namespace python { - -#define BGL_PYTHON_VISITOR dfs_visitor -#define BGL_PYTHON_EVENTS_HEADER "dfs_events.hpp" -#include "visitor.hpp" -#undef BGL_PYTHON_EVENTS_HEADER -#undef BGL_PYTHON_VISITOR - -template -void -depth_first_search - (const Graph& g, - typename Graph::Vertex s, - const dfs_visitor& visitor, - const vector_property_map* in_color) -{ - typedef vector_property_map ColorMap; - - ColorMap color = - in_color? *in_color : ColorMap(g.num_vertices(), g.get_vertex_index_map()); - - bool has_default_visitor = - dynamic_cast::default_arg const*>(&visitor); - - if (s == graph_traits::null_vertex() && g.num_vertices() > 0) - s = *g.vertices().first; - - - if (has_default_visitor) { - boost::depth_first_search(g, boost::dfs_visitor<>(), color, s); - } else { - boost::depth_first_search(g, typename dfs_visitor::ref(visitor), - color, s); - } -} - -template -void -depth_first_visit - (const Graph& g, - typename Graph::Vertex s, - const dfs_visitor& visitor, - const vector_property_map* in_color) -{ - typedef vector_property_map ColorMap; - - ColorMap color = - in_color? *in_color : ColorMap(g.num_vertices(), g.get_vertex_index_map()); - - bool has_default_visitor = - dynamic_cast::default_arg const*>(&visitor); - - if (has_default_visitor) { - boost::depth_first_visit(g, s, boost::dfs_visitor<>(), color); - } else { - boost::depth_first_visit(g, s, typename dfs_visitor::ref(visitor), - color); - } -} - -template -void -undirected_dfs - (const Graph& g, - const dfs_visitor& visitor, - const vector_property_map* in_color, - const vector_property_map* in_edge_color) -{ - typedef vector_property_map ColorMap; - typedef vector_property_map EdgeColorMap; - - ColorMap color = - in_color? *in_color : ColorMap(g.num_vertices(), g.get_vertex_index_map()); - - EdgeColorMap edge_color = - in_edge_color? *in_edge_color - : EdgeColorMap(g.num_edges(), g.get_edge_index_map()); - - bool has_default_visitor = - dynamic_cast::default_arg const*>(&visitor); - - if (has_default_visitor) { - boost::undirected_dfs(g, boost::dfs_visitor<>(), color, edge_color); - } else { - boost::undirected_dfs(g, typename dfs_visitor::ref(visitor), - color, edge_color); - } -} - -void export_depth_first_search() -{ - using boost::python::arg; - using boost::python::def; - - def("depth_first_search", &depth_first_search, - (arg("graph"), - arg("root_vertex") = graph_traits::null_vertex(), - arg("visitor") = dfs_visitor::default_arg(), - arg("color_map") = - (vector_property_map*)0)); - - def("depth_first_visit", &depth_first_visit, - (arg("graph"), - arg("root_vertex"), - arg("visitor") = dfs_visitor::default_arg(), - arg("color_map") = - (vector_property_map*)0)); - - def("undirected_dfs", &undirected_dfs, - (arg("graph"), - arg("visitor") = dfs_visitor::default_arg(), - arg("color_map") = - (vector_property_map*)0, - arg("edge_color_map") = - (vector_property_map*)0)); - - def("depth_first_search", &depth_first_search, - (arg("graph"), - arg("root_vertex") = graph_traits::null_vertex(), - arg("visitor") = dfs_visitor::default_arg(), - arg("color_map") = - (vector_property_map*)0)); - - def("depth_first_visit", &depth_first_visit, - (arg("graph"), - arg("root_vertex"), - arg("visitor") = dfs_visitor::default_arg(), - arg("color_map") = - (vector_property_map*)0)); -} - -template -void export_depth_first_search_in_graph() -{ - dfs_visitor::declare("DFSVisitor", "DefaultDFSVisitor"); -} - -template void export_depth_first_search_in_graph(); -template void export_depth_first_search_in_graph(); - -} } } // end namespace boost::graph::python diff --git a/src/python/dfs_events.hpp b/src/python/dfs_events.hpp deleted file mode 100644 index d0813388..00000000 --- a/src/python/dfs_events.hpp +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine - -BGL_PYTHON_EVENT(initialize_vertex, vertex_descriptor) -BGL_PYTHON_EVENT(start_vertex, vertex_descriptor) -BGL_PYTHON_EVENT(discover_vertex, vertex_descriptor) -BGL_PYTHON_EVENT(examine_vertex, vertex_descriptor) -BGL_PYTHON_EVENT(examine_edge, edge_descriptor) -BGL_PYTHON_EVENT(tree_edge, edge_descriptor) -BGL_PYTHON_EVENT(back_edge, edge_descriptor) -BGL_PYTHON_EVENT(forward_or_cross_edge, edge_descriptor) -BGL_PYTHON_EVENT(finish_vertex, vertex_descriptor) diff --git a/src/python/digraph.cpp b/src/python/digraph.cpp deleted file mode 100644 index 70c2d305..00000000 --- a/src/python/digraph.cpp +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#include "digraph.hpp" -#include "basic_graph.cpp" - -namespace boost { namespace graph { namespace python { - -void export_Digraph() -{ - export_basic_graph("Digraph"); -} -} } } // end namespace boost::graph::python diff --git a/src/python/digraph.hpp b/src/python/digraph.hpp deleted file mode 100644 index c11648af..00000000 --- a/src/python/digraph.hpp +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#ifndef BOOST_GRAPH_PYTHON_DIGRAPH_HPP -#define BOOST_GRAPH_PYTHON_DIGRAPH_HPP - -#include "basic_graph.hpp" - -namespace boost { namespace graph { namespace python { - typedef basic_graph Digraph; -} } } // end namespace boost::graph::python - -#endif // BOOST_GRAPH_PYTHON_DIGRAPH_HPP diff --git a/src/python/dijkstra_events.hpp b/src/python/dijkstra_events.hpp deleted file mode 100644 index 9199b7b6..00000000 --- a/src/python/dijkstra_events.hpp +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -BGL_PYTHON_EVENT(initialize_vertex, vertex_descriptor) -BGL_PYTHON_EVENT(examine_vertex, vertex_descriptor) -BGL_PYTHON_EVENT(examine_edge, edge_descriptor) -BGL_PYTHON_EVENT(discover_vertex, vertex_descriptor) -BGL_PYTHON_EVENT(edge_relaxed, edge_descriptor) -BGL_PYTHON_EVENT(edge_not_relaxed, edge_descriptor) -BGL_PYTHON_EVENT(finish_vertex, vertex_descriptor) diff --git a/src/python/dijkstra_shortest_paths.cpp b/src/python/dijkstra_shortest_paths.cpp deleted file mode 100644 index ff7db509..00000000 --- a/src/python/dijkstra_shortest_paths.cpp +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#include -#include "graph.hpp" -#include "digraph.hpp" -#include -#include "dijkstra_visitor.hpp" - -namespace boost { namespace graph { namespace python { - -template -void -dijkstra_shortest_paths - (Graph& g, typename Graph::Vertex s, - const vector_property_map* in_predecessor, - const vector_property_map* in_distance, - const vector_property_map* in_weight, - const dijkstra_visitor& visitor) -{ - typedef vector_property_map - PredecessorMap; - typedef vector_property_map - DistanceMap; - typedef vector_property_map - WeightMap; - - PredecessorMap predecessor = - in_predecessor? *in_predecessor - : PredecessorMap(g.num_vertices(), g.get_vertex_index_map()); - - DistanceMap distance = - in_distance? *in_distance - : DistanceMap(g.num_vertices(), g.get_vertex_index_map()); - - WeightMap weight = in_weight? *in_weight - : g.template get_edge_map("weight"); - - typedef typename dijkstra_visitor::default_arg default_visitor; - bool has_default_visitor = dynamic_cast(&visitor); - - if (!has_default_visitor) { - boost::dijkstra_shortest_paths - (g, s, - vertex_index_map(g.get_vertex_index_map()). - visitor(typename dijkstra_visitor::ref(visitor)). - predecessor_map(predecessor). - distance_map(distance). - weight_map(weight)); - } else { - boost::dijkstra_shortest_paths - (g, s, - vertex_index_map(g.get_vertex_index_map()). - predecessor_map(predecessor). - distance_map(distance). - weight_map(weight)); - } -} - -template -void export_dijkstra_shortest_paths_in_graph() -{ - dijkstra_visitor::declare("DijkstraVisitor", - "DefaultDijkstraVisitor"); -} - -void export_dijkstra_shortest_paths() -{ - using boost::python::arg; - using boost::python::def; - - def("dijkstra_shortest_paths", &dijkstra_shortest_paths, - (arg("graph"), arg("root_vertex"), - arg("predecessor_map") = - (vector_property_map*)0, - arg("distance_map") = - (vector_property_map*)0, - arg("weight_map") = - (vector_property_map*)0, - arg("visitor") = dijkstra_visitor::default_arg())); - - def("dijkstra_shortest_paths", &dijkstra_shortest_paths, - (arg("graph"), arg("root_vertex"), - arg("predecessor_map") = - (vector_property_map*)0, - arg("distance_map") = - (vector_property_map*)0, - arg("weight_map") = - (vector_property_map*)0, - arg("visitor") = dijkstra_visitor::default_arg())); -} - -template void export_dijkstra_shortest_paths_in_graph(); -template void export_dijkstra_shortest_paths_in_graph(); - -} } } // end namespace boost::graph::python diff --git a/src/python/dijkstra_visitor.hpp b/src/python/dijkstra_visitor.hpp deleted file mode 100644 index 520f2dc8..00000000 --- a/src/python/dijkstra_visitor.hpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#ifndef BOOST_GRAPH_PYTHON_DIJKSTRA_VISITOR_HPP -#define BOOST_GRAPH_PYTHON_DIJKSTRA_VISITOR_HPP -namespace boost { namespace graph { namespace python { - -#define BGL_PYTHON_VISITOR dijkstra_visitor -#define BGL_PYTHON_EVENTS_HEADER "dijkstra_events.hpp" -#include "visitor.hpp" -#undef BGL_PYTHON_EVENTS_HEADER -#undef BGL_PYTHON_VISITOR - -} } } // end namespace boost::graph::python -#endif BOOST_GRAPH_PYTHON_DIJKSTRA_VISITOR_HPP diff --git a/src/python/fruchterman_reingold.cpp b/src/python/fruchterman_reingold.cpp deleted file mode 100644 index 6ae168a9..00000000 --- a/src/python/fruchterman_reingold.cpp +++ /dev/null @@ -1,136 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#include -#include -#include "graph.hpp" -#include "digraph.hpp" -#include "point2d.hpp" -#include -#include - -namespace boost { namespace graph { namespace python { - -template -struct python_or_functor -{ - explicit python_or_functor(boost::python::object callable, const F& f = F()) - : callable(callable), f(f) { } - - // For cooling - Result operator()() - { - using boost::python::object; - using boost::python::extract; - if (callable != object()) return extract(callable()); - else return f(); - } - - // For the attractive_force - template - Result - operator()(typename graph_traits::edge_descriptor e, - double k, double dist, const Graph& g) const - { - using boost::python::object; - using boost::python::extract; - if (callable != object()) return extract(callable(e, k, dist, g)); - else return f(e, k, dist, g); - } - - // For the repulsive_force - template - Result - operator()(typename graph_traits::vertex_descriptor u, - typename graph_traits::vertex_descriptor v, - double k, double dist, const Graph& g) const - { - using boost::python::object; - using boost::python::extract; - if (callable != object()) - return extract(callable(u, v, k, dist, g)); - else return f(u, v, k, dist, g); - } - -private: - boost::python::object callable; - F f; -}; - - -template -void -fruchterman_reingold_force_directed_layout - (Graph& g, - const vector_property_map* in_pos, - double width, double height, - boost::python::object attractive_force, - boost::python::object repulsive_force, - // TBD: force pairs? - boost::python::object cooling, - bool progressive) -{ - using boost::python::object; - - typedef vector_property_map - PositionMap; - - PositionMap pos = - in_pos? *in_pos : g.template get_vertex_map("position"); - - if (!progressive) { - minstd_rand gen(std::time(0)); - random_graph_layout(g, pos, -width/2, width/2, -height/2, height/2, gen); - } - - python_or_functor > cool(cooling, 100); - - if (attractive_force != object() || repulsive_force != object()) { - python_or_functor fa(attractive_force); - python_or_functor fr(repulsive_force); - - boost::fruchterman_reingold_force_directed_layout - (g, pos, width, height, - boost::vertex_index_map(g.get_vertex_index_map()). - attractive_force(fa).repulsive_force(fr). - cooling(cool)); - } else { - if (cooling != object()) { - boost::fruchterman_reingold_force_directed_layout - (g, pos, width, height, - boost::vertex_index_map(g.get_vertex_index_map()). - cooling(cool)); - } else { - boost::fruchterman_reingold_force_directed_layout - (g, pos, width, height, - vertex_index_map(g.get_vertex_index_map())); - } - } -} - -void export_fruchterman_reingold_force_directed_layout() -{ - using boost::python::arg; - using boost::python::def; - using boost::python::object; - - def("fruchterman_reingold_force_directed_layout", - &fruchterman_reingold_force_directed_layout, - (arg("graph"), - arg("position") = - (vector_property_map*)0, - arg("width") = 500.0, - arg("height") = 500.0, - arg("attractive_force") = object(), - arg("repulsive_force") = object(), - arg("cooling") = object(), - arg("progressive") = false)); - -} - -} } } // end namespace boost::graph::python diff --git a/src/python/generators.hpp b/src/python/generators.hpp deleted file mode 100644 index 02f8e263..00000000 --- a/src/python/generators.hpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2004-5 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#ifndef BOOST_GRAPH_PYTHON_GENERATORS_HPP -#define BOOST_GRAPH_PYTHON_GENERATORS_HPP - -#include - -namespace boost { namespace graph { namespace python { - -struct erdos_renyi -{ - erdos_renyi(std::size_t n, double p) : n(n), p(p) { } - - std::size_t n; - double p; -}; - -struct power_law_out_degree -{ - power_law_out_degree(std::size_t n, double alpha, double beta) - : n(n), alpha(alpha), beta(beta) { } - - std::size_t n; - double alpha; - double beta; -}; - -struct small_world -{ - small_world(std::size_t n, std::size_t k, double p) : n(n), k(k), p(p) { } - - std::size_t n; - std::size_t k; - double p; -}; - -} } } // end namespace boost::graph::python - -#endif // BOOST_GRAPH_PYTHON_GENERATORS_HPP diff --git a/src/python/graph.cpp b/src/python/graph.cpp deleted file mode 100644 index e7b2b33a..00000000 --- a/src/python/graph.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#include "graph.hpp" -#include "basic_graph.cpp" -#include - -namespace boost { namespace graph { namespace python { - -void export_Graph() -{ - export_basic_graph("Graph"); -} -} } } // end namespace boost::graph::python diff --git a/src/python/graph.hpp b/src/python/graph.hpp deleted file mode 100644 index 818d2583..00000000 --- a/src/python/graph.hpp +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#ifndef BOOST_GRAPH_PYTHON_GRAPH_HPP -#define BOOST_GRAPH_PYTHON_GRAPH_HPP - -#include "basic_graph.hpp" - -namespace boost { namespace graph { namespace python { - - typedef basic_graph Graph; - -#if 0 - class Graph : public basic_graph - { - typedef basic_graph inherited; - - public: - Graph() : inherited() { } - Graph(const std::string& filename, graph_file_kind kind) - : inherited(filename, kind) { } - - vertex_iterator vertices_begin() const; - vertex_iterator vertices_end() const; - edge_iterator edges_begin() const; - edge_iterator edges_end() const; - }; -#endif -} } } // end namespace boost::graph::python - -#endif // BOOST_GRAPH_PYTHON_GRAPH_HPP diff --git a/src/python/graphviz.cpp b/src/python/graphviz.cpp deleted file mode 100644 index 0433fd13..00000000 --- a/src/python/graphviz.cpp +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#include "basic_graph.hpp" -#include -#include -#include -#include - -namespace boost { namespace graph { namespace python { - -template -void -basic_graph::read_graphviz(const std::string& filename, - const std::string& node_id) -{ - std::ifstream in(filename.c_str()); - boost::read_graphviz(in, *this, dp, node_id); -} - -template -void -basic_graph::write_graphviz(const std::string& filename, - const std::string& node_id) -{ - std::ofstream out(filename.c_str()); - - if (has_vertex_map(node_id)) - boost::write_graphviz(out, *this, dp, node_id, - get_vertex_map(node_id)); - else - boost::write_graphviz(out, *this, dp, node_id, get_vertex_index_map()); -} - -template -class translate_exception -{ - explicit translate_exception(boost::python::object type) : type(type) { } - -public: - template - static void declare(const char* name) - { - using boost::python::class_; - using boost::python::bases; - - declare(class_ >(name)); - } - - static void declare(boost::python::object type) - { - using boost::python::register_exception_translator; - register_exception_translator(translate_exception(type)); - } - - void operator()(const E& e) const - { - using boost::python::object; - PyErr_SetObject(type.ptr(), object(e).ptr()); - } - -private: - boost::python::object type; -}; - -void export_graphviz() -{ - using boost::python::class_; - using boost::python::bases; - using boost::python::init; - using boost::python::no_init; - using boost::python::object; - - object ge_type = - class_("graph_exception", no_init); - translate_exception::declare(ge_type); - - object bpe_type = - class_ >("bad_parallel_edge", - no_init) - .def(init()); - translate_exception::declare(bpe_type); - - translate_exception - ::declare("directed_graph_error"); - translate_exception - ::declare("undirected_graph_error"); -} - -// Explicit instantiations -template - void - basic_graph::read_graphviz(const std::string& filename, - const std::string& node_id); -template - void - basic_graph::write_graphviz(const std::string& filename, - const std::string& node_id); - -template - void - basic_graph::read_graphviz(const std::string& filename, - const std::string& node_id); -template - void - basic_graph::write_graphviz(const std::string& filename, - const std::string& node_id); - -} } } // end namespace boost::graph::python diff --git a/src/python/incremental_components.cpp b/src/python/incremental_components.cpp deleted file mode 100644 index 100515c2..00000000 --- a/src/python/incremental_components.cpp +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#include -#include "graph.hpp" -#include "digraph.hpp" -#include - -namespace boost { namespace graph { namespace python { - -template -class IncrementalComponents -{ -public: - typedef typename graph_traits::vertex_descriptor vertex_descriptor; - typedef vector_property_map ParentMap; - typedef vector_property_map RankMap; - - IncrementalComponents(const Graph& g) - : ds(RankMap(num_vertices(g), g.get_vertex_index_map()), - ParentMap(num_vertices(g), g.get_vertex_index_map())) - { - initialize_incremental_components(g, ds); - incremental_components(g, ds); - } - - void make_set(vertex_descriptor u) { ds.make_set(u); } - - void union_set(vertex_descriptor u, vertex_descriptor v) - { ds.union_set(u, v); } - - bool same_component(vertex_descriptor u, vertex_descriptor v) - { return boost::same_component(u, v, ds); } - -private: - disjoint_sets ds; -}; - -template -std::auto_ptr > -incremental_components(Graph& g) -{ - typedef std::auto_ptr > result_type; - return result_type(new IncrementalComponents(g)); -} - -void export_incremental_components() -{ - using boost::python::arg; - using boost::python::def; - using boost::python::class_; - using boost::python::no_init; - class_ >("IncrementalComponents", no_init) - .def("make_set", &IncrementalComponents::make_set) - .def("union_set", &IncrementalComponents::union_set) - .def("same_component", &IncrementalComponents::same_component) - ; - def("incremental_components", &incremental_components); -} - -} } } // end namespace boost::graph::python diff --git a/src/python/isomorphism.cpp b/src/python/isomorphism.cpp deleted file mode 100644 index 4a9d21d7..00000000 --- a/src/python/isomorphism.cpp +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#include -#include "graph.hpp" -#include "digraph.hpp" -#include - -namespace boost { namespace graph { namespace python { - -template -struct py_vertex_invariant -{ - explicit py_vertex_invariant(boost::python::object invariant) - : invariant(invariant) { } - - int operator()(const Vertex& v1, const Vertex& v2) - { return boost::python::extract(invariant(v1, v2)); } - -private: - boost::python::object invariant; -}; - -template -bool -isomorphism - (Graph& g1, - Graph& g2, - const vector_property_map* in_iso, - boost::python::object invariant) -{ - typedef typename Graph::Vertex Vertex; - - typedef vector_property_map IsoMap; - - IsoMap iso = - in_iso? *in_iso - : IsoMap(num_vertices(g1), g1.get_vertex_index_map()); - - if (invariant != boost::python::object()) - return boost::isomorphism - (g1, g2, - isomorphism_map(iso). - vertex_invariant(py_vertex_invariant(invariant)). - vertex_index1_map(g1.get_vertex_index_map()). - vertex_index2_map(g2.get_vertex_index_map())); - else - return boost::isomorphism - (g1, g2, - isomorphism_map(iso). - vertex_index1_map(g1.get_vertex_index_map()). - vertex_index2_map(g2.get_vertex_index_map())); -} - -void export_isomorphism() -{ - using boost::python::arg; - using boost::python::def; - using boost::python::object; - - def("isomorphism", &isomorphism, - (arg("g1"), arg("g2"), - arg("isomorphism_map") = - (vector_property_map*)0, - arg("vertex_invariant") = object())); - - def("isomorphism", &isomorphism, - (arg("g1"), arg("g2"), - arg("isomorphism_map") = - (vector_property_map*)0, - arg("vertex_invariant") = object())); -} - -} } } // end namespace boost::graph::python diff --git a/src/python/kamada_kawai_spring_layout.cpp b/src/python/kamada_kawai_spring_layout.cpp deleted file mode 100644 index 374815d6..00000000 --- a/src/python/kamada_kawai_spring_layout.cpp +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#include -#include -#include "graph.hpp" -#include "digraph.hpp" -#include "point2d.hpp" -#include - -namespace boost { namespace graph { namespace python { - -template -void -kamada_kawai_spring_layout - (Graph& g, - const vector_property_map* in_pos, - const vector_property_map* in_weight, - double side_length, - boost::python::object done, - double spring_constant, - bool progressive) -{ - using boost::python::object; - - typedef vector_property_map - PositionMap; - typedef vector_property_map - WeightMap; - - PositionMap pos = - in_pos? *in_pos : g.template get_vertex_map("position"); - - WeightMap weight = - in_weight? *in_weight : WeightMap(num_edges(g), g.get_edge_index_map()); - - // If we weren't give a weight map, assume unweighted edges - if (!in_weight) BGL_FORALL_EDGES_T(e, g, Graph) put(weight, e, 1.0); - - if (!progressive) circle_graph_layout(g, pos, side_length/2); - - if (done != object()) { - boost::kamada_kawai_spring_layout(g, pos, weight, - boost::side_length(side_length), done, - spring_constant, - g.get_vertex_index_map()); - } else { - boost::kamada_kawai_spring_layout(g, pos, weight, - boost::side_length(side_length), - layout_tolerance(), - spring_constant, - g.get_vertex_index_map()); - } -} - -void export_kamada_kawai_spring_layout() -{ - using boost::python::arg; - using boost::python::def; - using boost::python::object; - - def("kamada_kawai_spring_layout", - &kamada_kawai_spring_layout, - (arg("graph"), - arg("position") = - (vector_property_map*)0, - arg("weight") = - (vector_property_map*)0, - arg("side_length") = 500.0, - arg("done") = object(), - arg("spring_constant") = 1.0, - arg("progressive") = false)); -} - -} } } // end namespace boost::graph::python diff --git a/src/python/king_ordering.cpp b/src/python/king_ordering.cpp deleted file mode 100644 index c8a94a87..00000000 --- a/src/python/king_ordering.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#include -#include "graph.hpp" -#include "digraph.hpp" -#include -#include -#include - -namespace boost { namespace graph { namespace python { - -template -boost::python::list -king_ordering(const Graph& g) -{ - std::list ordering; - boost::python::list result; - boost::king_ordering(g, std::back_inserter(ordering), - g.get_vertex_index_map()); - for (typename std::list::iterator i - = ordering.begin(); i != ordering.end(); ++i) - result.append(*i); - return result; -} - -void export_king_ordering() -{ - using boost::python::arg; - using boost::python::def; - def("king_ordering", &king_ordering, arg("graph")); -} - -} } } // end namespace boost::graph::python diff --git a/src/python/kruskal_min_spanning_tree.cpp b/src/python/kruskal_min_spanning_tree.cpp deleted file mode 100644 index 11bf0e2a..00000000 --- a/src/python/kruskal_min_spanning_tree.cpp +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#include -#include "graph.hpp" -#include "digraph.hpp" -#include -#include -#include - -namespace boost { namespace graph { namespace python { - -template -boost::python::list -kruskal_minimum_spanning_tree - (Graph& g, - const vector_property_map* in_weight) -{ - typedef vector_property_map WeightMap; - - WeightMap weight = - in_weight? *in_weight : g.template get_edge_map("weight"); - - std::list mst_edges; - boost::kruskal_minimum_spanning_tree - (g, - std::back_inserter(mst_edges), - vertex_index_map(g.get_vertex_index_map()). - weight_map(weight)); - boost::python::list result; - for (typename std::list::iterator i - = mst_edges.begin(); i != mst_edges.end(); ++i) - result.append(*i); - return result; -} - -void export_kruskal_minimum_spanning_tree() -{ - using boost::python::arg; - using boost::python::def; - - def("kruskal_minimum_spanning_tree", &kruskal_minimum_spanning_tree, - (arg("graph"), - arg("weight_map") = - (vector_property_map*)0)); -} - -} } } // end namespace boost::graph::python diff --git a/src/python/module.cpp b/src/python/module.cpp deleted file mode 100644 index ccfe303b..00000000 --- a/src/python/module.cpp +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#include "basic_graph.cpp" -#include "graph.hpp" -#include "digraph.hpp" -#include -#include "point2d.hpp" -#include "generators.hpp" - -namespace boost { namespace graph { namespace python { - -extern void export_Graph(); -extern void export_Digraph(); -extern void export_graphviz(); -extern void export_breadth_first_search(); -extern void export_depth_first_search(); -extern void export_dijkstra_shortest_paths(); -extern void export_bellman_ford_shortest_paths(); -extern void export_dag_shortest_paths(); -extern void export_prim_minimum_spanning_tree(); -template void export_breadth_first_search_in_graph(); -template void export_depth_first_search_in_graph(); -template void export_dijkstra_shortest_paths_in_graph(); -template void export_dag_shortest_paths_in_graph(); -template void export_bellman_ford_shortest_paths_in_graph(); -template void export_prim_minimum_spanning_tree_in_graph(); -extern void export_connected_components(); -extern void export_strong_components(); -extern void export_biconnected_components(); -extern void export_incremental_components(); -extern void export_topological_sort(); -extern void export_cuthill_mckee_ordering(); -extern void export_king_ordering(); - //extern void export_minimum_degree_ordering(); -extern void export_sequential_vertex_coloring(); -extern void export_betweenness_centrality(); -extern void export_page_rank(); -extern void export_circle_graph_layout(); -extern void export_fruchterman_reingold_force_directed_layout(); -extern void export_kamada_kawai_spring_layout(); -extern void export_kruskal_minimum_spanning_tree(); -extern void export_transitive_closure(); - //extern void export_transpose_graph(); -extern void export_isomorphism(); - -template -void export_in_graph() -{ - export_breadth_first_search_in_graph(); - export_depth_first_search_in_graph(); - export_dijkstra_shortest_paths_in_graph(); - export_bellman_ford_shortest_paths_in_graph(); - export_dag_shortest_paths_in_graph(); - export_prim_minimum_spanning_tree_in_graph(); -} - -BOOST_PYTHON_MODULE(bgl) -{ - using boost::python::class_; - using boost::python::enum_; - using boost::python::no_init; - using boost::python::init; - using boost::python::arg; - - enum_("file_kind") - .value("adjlist", gfk_adjlist) - .value("graphviz", gfk_graphviz) - ; - - enum_("Color") - .value("white", color_traits::white()) - .value("gray", color_traits::gray()) - .value("black", color_traits::black()) - ; - - class_("Point2D") - .def_readwrite("x", &point2d::x) - .def_readwrite("y", &point2d::y) - ; - - class_("ErdosRenyi", no_init) - .def(init( - (arg("n"), arg("probability") = 1))) - ; - - class_("PowerLawOutDegree", no_init) - .def(init( - (arg("n"), arg("alpha"), arg("beta")))) - ; - - class_("SmallWorld", no_init) - .def(init - ((arg("n"), arg("k"), arg("probability")))) - ; - - export_Graph(); - export_Digraph(); - export_graphviz(); - // Core Algorithm Patterns - export_breadth_first_search(); - export_depth_first_search(); - // Shortest Paths Algorithms - export_dijkstra_shortest_paths(); - export_bellman_ford_shortest_paths(); - export_dag_shortest_paths(); - // Minimum Spanning Tree Algorithms - export_kruskal_minimum_spanning_tree(); - export_prim_minimum_spanning_tree(); - // Connected Components Algorithms - export_connected_components(); - export_strong_components(); - export_biconnected_components(); - export_incremental_components(); - - // Sparse Matrix Ordering - export_cuthill_mckee_ordering(); - export_king_ordering(); - // export_minimum_degree_ordering(); - - // Other algorithms - export_topological_sort(); - export_transitive_closure(); - export_sequential_vertex_coloring(); - export_betweenness_centrality(); - export_page_rank(); - - // Layout Algorithms - export_circle_graph_layout(); - export_fruchterman_reingold_force_directed_layout(); - export_kamada_kawai_spring_layout(); - - // export_transpose_graph(); - export_isomorphism(); -} - -template void export_in_graph(); -template void export_in_graph(); - -} } } // end namespace boost::graph::python diff --git a/src/python/page_rank.cpp b/src/python/page_rank.cpp deleted file mode 100644 index aa2d47c3..00000000 --- a/src/python/page_rank.cpp +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#include "digraph.hpp" -#include - -namespace boost { namespace graph { namespace python { - -template -void -page_rank_iterations - (Graph& g, - const vector_property_map* in_rank, - int iterations) -{ - typedef vector_property_map - RankMap; - - RankMap rank = - in_rank? *in_rank : g.template get_vertex_map("pagerank"); - - boost::graph::page_rank(g, rank, graph::n_iterations(20)); -} - -struct page_rank_wrap_done -{ - page_rank_wrap_done(boost::python::object done) : done(done) { } - - template - bool - operator()(const RankMap& rank, const Graph& g) const - { - using boost::python::extract; - return extract(done(rank, g)); - } - -private: - boost::python::object done; -}; - - -template -void -page_rank_done - (Graph& g, - const vector_property_map* in_rank, - boost::python::object done) -{ - typedef vector_property_map - RankMap; - - RankMap rank = - in_rank? *in_rank : g.template get_vertex_map("pagerank"); - - boost::graph::page_rank(g, rank, page_rank_wrap_done(done)); -} - -void export_page_rank() -{ - using boost::python::arg; - using boost::python::def; - - def("page_rank", &page_rank_iterations, - (arg("graph"), - arg("rank_map") = - (vector_property_map*)0, - arg("iterations") = 20)); - def("page_rank", &page_rank_done, - (arg("graph"), - arg("rank_map") = - (vector_property_map*)0, - arg("done"))); -} - - -} } } // end namespace boost::graph::python diff --git a/src/python/pickle.cpp b/src/python/pickle.cpp deleted file mode 100644 index 9fe11323..00000000 --- a/src/python/pickle.cpp +++ /dev/null @@ -1,154 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#include "graph.hpp" -#include "digraph.hpp" -#include - -namespace boost { namespace graph { namespace python { - -template -boost::python::tuple -graph_pickle_suite::getstate(boost::python::object g_obj) -{ - using boost::python::tuple; - using boost::python::make_tuple; - using boost::python::list; - using boost::python::extract; - using boost::python::dict; - using boost::python::object; - - const Graph& g = extract(g_obj)(); - typename Graph::VertexIndexMap vertex_index_map = g.get_vertex_index_map(); - typename Graph::EdgeIndexMap edge_index_map = g.get_edge_index_map(); - - dict vertex_properties; - dict edge_properties; - - // Collect edges - std::vector the_edges(g.num_edges()); - BGL_FORALL_EDGES_T(e, g, Graph) - the_edges[get(edge_index_map, e)] = - make_tuple(get(vertex_index_map, source(e, g)), - get(vertex_index_map, target(e, g))); - - list edges_list; - for (std::vector::iterator i = the_edges.begin(); - i != the_edges.end(); ++i) - edges_list.append(*i); - - // Collect vertex and edge properties - const dynamic_properties& dp = g.get_dynamic_properties(); - for (dynamic_properties::const_iterator pm = dp.begin(); - pm != dp.end(); ++pm) { - python_dynamic_property_map* pmap = - dynamic_cast(pm->second); - if (pm->second->key() == typeid(Vertex)) { - std::vector values(g.num_vertices()); - BGL_FORALL_VERTICES_T(v, g, Graph) - values[get(vertex_index_map, v)] = pmap->get_python(v); - - list values_list; - for (std::vector::iterator i = values.begin(); - i != values.end(); ++i) - values_list.append(*i); - vertex_properties[pm->first] = tuple(values_list); - } else if (pm->second->key() == typeid(Edge)) { - std::vector values(g.num_edges()); - BGL_FORALL_EDGES_T(e, g, Graph) - values[get(edge_index_map, e)] = pmap->get_python(e); - - list values_list; - for (std::vector::iterator i = values.begin(); - i != values.end(); ++i) - values_list.append(*i); - edge_properties[pm->first] = tuple(values_list); - } else { - assert(false); - } - } - - return make_tuple(g_obj.attr("__dict__"), - g.num_vertices(), - edges_list, - vertex_properties, - edge_properties); -} - -template -void -graph_pickle_suite::setstate(boost::python::object g_obj, - boost::python::tuple state) -{ - using boost::python::tuple; - using boost::python::make_tuple; - using boost::python::list; - using boost::python::extract; - using boost::python::dict; - using boost::python::object; - - Graph& g = extract(g_obj)(); - - // restore the graph's __dict__ - dict d = extract(g_obj.attr("__dict__"))(); - d.update(state[0]); - - // Get the number of vertices - typedef typename graph_traits::vertices_size_type vertices_size_type; - vertices_size_type n = extract(state[1]); - std::vector vertices; - vertices.reserve(n); - while (vertices.size() < n) vertices.push_back(g.add_vertex()); - - // Get the edges - typedef typename graph_traits::edges_size_type edges_size_type; - std::vector the_edges; - list edges_list = extract(state[2]); - edges_size_type m = extract(edges_list.attr("__len__")()); - the_edges.reserve(m); - for (unsigned i = 0; i < m; ++i) { - tuple e = extract(edges_list[i]); - the_edges.push_back - (g.add_edge(vertices[extract(e[0])], - vertices[extract(e[1])])); - } - - // Get the vertex properties - typedef typename Graph::VertexIndexMap VertexIndexMap; - dict vertex_properties = extract(state[3]); - list vertex_map_names = vertex_properties.keys(); - while (vertex_map_names != list()) { - object name_obj = vertex_map_names.pop(0); - const char* name = extract(name_obj); - vector_property_map pmap = - g.get_vertex_object_map(name); - tuple values = extract(vertex_properties[name_obj]); - for (vertices_size_type i = 0; i < g.num_vertices(); ++i) - put(pmap, vertices[i], values[i]); - } - - // Get the edge properties - typedef typename Graph::EdgeIndexMap EdgeIndexMap; - dict edge_properties = extract(state[4]); - list edge_map_names = edge_properties.keys(); - while (edge_map_names != list()) { - object name_obj = edge_map_names.pop(0); - const char* name = extract(name_obj); - vector_property_map pmap = - g.get_edge_object_map(name); - tuple values = extract(edge_properties[name_obj]); - for (edges_size_type i = 0; i < g.num_edges(); ++i) - put(pmap, the_edges[i], values[i]); - } -} - -template struct graph_pickle_suite; -template struct graph_pickle_suite; - -} } } // end namespace boost::graph::python - diff --git a/src/python/point2d.hpp b/src/python/point2d.hpp deleted file mode 100644 index a53cbc82..00000000 --- a/src/python/point2d.hpp +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#ifndef BOOST_GRAPH_PYTHON_POINT2D_HPP -#define BOOST_GRAPH_PYTHON_POINT2D_HPP - -#include - -namespace boost { namespace graph { namespace python { - struct point2d - { - double x; - double y; - }; - - inline std::ostream& operator<<(std::ostream& out, point2d p) - { return out << p.x << ' ' << p.y; } - - inline std::istream& operator>>(std::istream& in, point2d& p) - { return in >> p.x >> p.y; } -} } } // end namespace boost::graph::python - -#endif // BOOST_GRAPH_PYTHON_POINT2D_HPP diff --git a/src/python/prim_minimum_spanning_tree.cpp b/src/python/prim_minimum_spanning_tree.cpp deleted file mode 100644 index d7f17d0f..00000000 --- a/src/python/prim_minimum_spanning_tree.cpp +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#include -#include "graph.hpp" -#include "digraph.hpp" -#include -#include "dijkstra_visitor.hpp" - -namespace boost { namespace graph { namespace python { - -template -void -prim_minimum_spanning_tree - (Graph& g, typename Graph::Vertex s, - const vector_property_map* in_predecessor, - const vector_property_map* in_distance, - const vector_property_map* in_weight, - const dijkstra_visitor& visitor) -{ - typedef vector_property_map - PredecessorMap; - typedef vector_property_map - DistanceMap; - typedef vector_property_map - WeightMap; - - PredecessorMap predecessor = - in_predecessor? *in_predecessor - : PredecessorMap(g.num_vertices(), g.get_vertex_index_map()); - - DistanceMap distance = - in_distance? *in_distance - : DistanceMap(g.num_vertices(), g.get_vertex_index_map()); - - WeightMap weight = in_weight? *in_weight - : g.template get_edge_map("weight"); - - typedef typename dijkstra_visitor::default_arg default_visitor; - bool has_default_visitor = dynamic_cast(&visitor); - - if (!has_default_visitor) { - boost::prim_minimum_spanning_tree - (g, - predecessor, - root_vertex(s). - vertex_index_map(g.get_vertex_index_map()). - visitor(typename dijkstra_visitor::ref(visitor)). - distance_map(distance). - weight_map(weight)); - } else { - boost::prim_minimum_spanning_tree - (g, - predecessor, - root_vertex(s). - vertex_index_map(g.get_vertex_index_map()). - distance_map(distance). - weight_map(weight)); - } -} - -template -void export_prim_minimum_spanning_tree_in_graph() -{ - dijkstra_visitor::declare("DijkstraVisitor", - "DefaultDijkstraVisitor"); -} - -void export_prim_minimum_spanning_tree() -{ - using boost::python::arg; - using boost::python::def; - - def("prim_minimum_spanning_tree", &prim_minimum_spanning_tree, - (arg("graph"), arg("root_vertex"), - arg("predecessor_map") = - (vector_property_map*)0, - arg("distance_map") = - (vector_property_map*)0, - arg("weight_map") = - (vector_property_map*)0, - arg("visitor") = dijkstra_visitor::default_arg())); - - def("prim_minimum_spanning_tree", &prim_minimum_spanning_tree, - (arg("graph"), arg("root_vertex"), - arg("predecessor_map") = - (vector_property_map*)0, - arg("distance_map") = - (vector_property_map*)0, - arg("weight_map") = - (vector_property_map*)0, - arg("visitor") = dijkstra_visitor::default_arg())); -} - -template void export_prim_minimum_spanning_tree_in_graph(); -template void export_prim_minimum_spanning_tree_in_graph(); - -} } } // end namespace boost::graph::python diff --git a/src/python/queue.hpp b/src/python/queue.hpp deleted file mode 100644 index 1c4b8ab4..00000000 --- a/src/python/queue.hpp +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#ifndef BOOST_GRAPH_PYTHON_QUEUE_HPP -#define BOOST_GRAPH_PYTHON_QUEUE_HPP - -#include - -namespace boost { namespace graph { namespace python { - -template -class python_queue -{ - class wrap - : public python_queue, public boost::python::wrapper > - { - public: - bool empty() const { return this->get_override("empty")(); } - T top() const { return this->get_override("top")(); } - void pop() { this->get_override("pop")(); } - void push(const T& x) { this->get_override("push")(x); } - }; - - public: - class default_queue : public python_queue - { - bool empty() const { return true; } - T top() const { return T(); } - void pop() {} - void push(const T&) {} - }; - - virtual ~python_queue() {} - virtual bool empty() const = 0; - virtual T top() const = 0; - virtual void pop() = 0; - virtual void push(const T&) = 0; - - static void declare(const char* name, const char* default_name) - { - using boost::python::objects::registered_class_object; - using boost::python::type_id; - using boost::python::class_; - using boost::python::bases; - using boost::python::no_init; - using boost::python::pure_virtual; - - if (registered_class_object(type_id()).get() == 0) { - class_(name) - .def("empty", pure_virtual(&python_queue::empty)) - .def("top", pure_virtual(&python_queue::top)) - .def("pop", pure_virtual(&python_queue::pop)) - .def("push", pure_virtual(&python_queue::push)) - ; - } - - if (registered_class_object(type_id()).get() == 0) - { - class_ >(default_name, no_init); - } - } -}; - -} } } // end namespace boost::graph::python - -#endif // BOOST_GRAPH_PYTHON_QUEUE_HPP diff --git a/src/python/sequential_vertex_coloring.cpp b/src/python/sequential_vertex_coloring.cpp deleted file mode 100644 index 6bc6e1be..00000000 --- a/src/python/sequential_vertex_coloring.cpp +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#include "graph.hpp" -#include "digraph.hpp" -#include - -namespace boost { namespace graph { namespace python { - -template -int -sequential_vertex_coloring - (Graph& g, - const vector_property_map* in_color) -{ - typedef vector_property_map ColorMap; - - ColorMap color = - in_color? *in_color - : ColorMap(num_vertices(g), g.get_vertex_index_map()); - - return boost::sequential_vertex_coloring(g, color); -} - -void export_sequential_vertex_coloring() -{ - using boost::python::arg; - using boost::python::def; - - def("sequential_vertex_coloring", - &sequential_vertex_coloring, - (arg("graph"), - arg("color_map") = - (vector_property_map*)0)); - def("sequential_vertex_coloring", - &sequential_vertex_coloring, - (arg("graph"), - arg("color_map") = - (vector_property_map*)0)); -} - -} } } // end namespace boost::graph::python diff --git a/src/python/strong_components.cpp b/src/python/strong_components.cpp deleted file mode 100644 index 8b02d45b..00000000 --- a/src/python/strong_components.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#include -#include "graph.hpp" -#include "digraph.hpp" -#include - -namespace boost { namespace graph { namespace python { - -template -int -strong_components - (Graph& g, - const vector_property_map* in_component) -{ - typedef vector_property_map ComponentMap; - - ComponentMap component = - in_component? *in_component : g.template get_vertex_map("component"); - - return boost::strong_components (g, component, - vertex_index_map(g.get_vertex_index_map())); -} - -void export_strong_components() -{ - using boost::python::arg; - using boost::python::def; - - def("strong_components", &strong_components, - (arg("graph"), - arg("component_map") = - (vector_property_map*)0)); -} - -} } } // end namespace boost::graph::python diff --git a/src/python/topological_sort.cpp b/src/python/topological_sort.cpp deleted file mode 100644 index e1979e7e..00000000 --- a/src/python/topological_sort.cpp +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#include -#include "graph.hpp" -#include "digraph.hpp" -#include -#include -#include - -namespace boost { namespace graph { namespace python { - -template -boost::python::list -topological_sort - (const Graph& g, - const vector_property_map* in_color) -{ - typedef vector_property_map ColorMap; - - ColorMap color = - in_color? *in_color : ColorMap(g.num_vertices(), g.get_vertex_index_map()); - - std::list topo_order; - boost::python::list result; - boost::topological_sort(g, std::back_inserter(topo_order), color_map(color)); - for (typename std::list::iterator i - = topo_order.begin(); i != topo_order.end(); ++i) - result.append(*i); - return result; -} - -void export_topological_sort() -{ - using boost::python::arg; - using boost::python::def; - - def("topological_sort", &topological_sort, - (arg("graph"), - arg("color_map") = - (vector_property_map*)0)); - def("topological_sort", &topological_sort, - (arg("graph"), - arg("color_map") = - (vector_property_map*)0)); -} - -} } } // end namespace boost::graph::python diff --git a/src/python/transitive_closure.cpp b/src/python/transitive_closure.cpp deleted file mode 100644 index a7655606..00000000 --- a/src/python/transitive_closure.cpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -#include -#include "graph.hpp" -#include "digraph.hpp" -#include -#include -#include - -namespace boost { namespace graph { namespace python { - -template -std::auto_ptr -transitive_closure - (const Graph& g, - const vector_property_map* g_to_tc_map) -{ - std::auto_ptr tc(new Graph); - if (g_to_tc_map) - boost::transitive_closure(g, *tc, *g_to_tc_map, g.get_vertex_index_map()); - else - boost::transitive_closure(g, *tc, - vertex_index_map(g.get_vertex_index_map())); - return tc; -} - -void export_transitive_closure() -{ - using boost::python::arg; - using boost::python::def; - - def("transitive_closure", &transitive_closure, - (arg("graph"), - arg("orig_to_copy") = - (vector_property_map*)0)); -} - -} } } // end namespace boost::graph::python diff --git a/src/python/visitor.hpp b/src/python/visitor.hpp deleted file mode 100644 index 52b2905f..00000000 --- a/src/python/visitor.hpp +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2005 The Trustees of Indiana University. - -// Use, modification and distribution is subject to 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) - -// Authors: Douglas Gregor -// Andrew Lumsdaine -template -class BGL_PYTHON_VISITOR -{ - class wrap - : public BGL_PYTHON_VISITOR, - public boost::python::wrapper > - { - public: - typedef typename BGL_PYTHON_VISITOR::vertex_descriptor vertex_descriptor; - typedef typename BGL_PYTHON_VISITOR::edge_descriptor edge_descriptor; - -#define BGL_PYTHON_EVENT(Name,Descriptor) \ - void Name(Descriptor x, const Graph& g) const \ - { \ - if (boost::python::override f = this->get_override(#Name)) \ - f(x, boost::cref(g)); \ - else BGL_PYTHON_VISITOR::Name(x, g); \ - } \ - \ - void default_##Name(Descriptor x, const Graph& g) const \ - { this->BGL_PYTHON_VISITOR::Name(x, g); } -# include BGL_PYTHON_EVENTS_HEADER -#undef BGL_PYTHON_EVENT - }; - - public: - class default_arg : public BGL_PYTHON_VISITOR { }; - - struct ref - { - typedef typename graph_traits::vertex_descriptor vertex_descriptor; - typedef typename graph_traits::edge_descriptor edge_descriptor; - - ref(const BGL_PYTHON_VISITOR& v) : v(v) { } - -#define BGL_PYTHON_EVENT(Name, Descriptor) \ - void Name(Descriptor x, const Graph& g) const { v.Name(x, g); } -# include BGL_PYTHON_EVENTS_HEADER -#undef BGL_PYTHON_EVENT - - private: - const BGL_PYTHON_VISITOR& v; - }; - - typedef typename graph_traits::vertex_descriptor vertex_descriptor; - typedef typename graph_traits::edge_descriptor edge_descriptor; - - virtual ~BGL_PYTHON_VISITOR() {} - -#define BGL_PYTHON_EVENT(Name, Descriptor) \ - virtual void Name(Descriptor x, const Graph& g) const {} -# include BGL_PYTHON_EVENTS_HEADER -#undef BGL_PYTHON_EVENT - - static void declare(const char* name, const char* default_name) - { - using boost::python::class_; - using boost::python::bases; - using boost::python::no_init; - using boost::python::objects::registered_class_object; - using boost::python::type_id; - - if (registered_class_object(type_id()).get() != 0) - return; - -#define BGL_PYTHON_EVENT(Name, Descriptor) \ - .def(#Name, &BGL_PYTHON_VISITOR::Name, &wrap::default_##Name) - class_(name) -# include BGL_PYTHON_EVENTS_HEADER -#undef BGL_PYTHON_EVENT - ; - - class_ > >(default_name, - no_init); - } -}; - diff --git a/test/python/biconnected_components.dot b/test/python/biconnected_components.dot deleted file mode 100644 index ef4ba592..00000000 --- a/test/python/biconnected_components.dot +++ /dev/null @@ -1,13 +0,0 @@ -graph G { - A -- B - A -- F - A -- G - B -- C - B -- D - B -- E - C -- D - E -- F - G -- H - G -- I - H -- I -} diff --git a/test/python/biconnected_components.py b/test/python/biconnected_components.py deleted file mode 100644 index f55b27a0..00000000 --- a/test/python/biconnected_components.py +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright 2005 The Trustees of Indiana University. - -# Use, modification and distribution is subject to 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) - -# Authors: Douglas Gregor -# Andrew Lumsdaine - -import bgl - -g = bgl.Graph("biconnected_components.dot", bgl.file_kind.graphviz) -art_points = bgl.biconnected_components(g, g.get_edge_int_map("label")); -g.write_graphviz("biconnected_components_out.dot") - -print "Articulation points: ", -node_id = g.get_vertex_string_map("node_id") -for v in art_points: - print node_id[v], - print " ", -print "" diff --git a/test/python/circle_layout.py b/test/python/circle_layout.py deleted file mode 100644 index 93698c5b..00000000 --- a/test/python/circle_layout.py +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright 2005 The Trustees of Indiana University. - -# Use, modification and distribution is subject to 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) - -# Authors: Douglas Gregor -# Andrew Lumsdaine - -import bgl - -g = bgl.Graph("biconnected_components.dot", bgl.file_kind.graphviz) -bgl.circle_graph_layout(g, radius=200) -g.write_graphviz("circle_graph_layout_out.dot") diff --git a/test/python/fruchterman_reingold.py b/test/python/fruchterman_reingold.py deleted file mode 100644 index a0d593f9..00000000 --- a/test/python/fruchterman_reingold.py +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright 2005 The Trustees of Indiana University. - -# Use, modification and distribution is subject to 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) - -# Authors: Douglas Gregor -# Andrew Lumsdaine - -import bgl - -g = bgl.Graph("biconnected_components.dot", bgl.file_kind.graphviz) -bgl.fruchterman_reingold_force_directed_layout(g, width=400, height=400) -g.write_graphviz("fruchterman_reingold_out.dot") diff --git a/test/python/kamada_kawai_spring_layout.py b/test/python/kamada_kawai_spring_layout.py deleted file mode 100644 index 12625a2e..00000000 --- a/test/python/kamada_kawai_spring_layout.py +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright 2005 The Trustees of Indiana University. - -# Use, modification and distribution is subject to 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) - -# Authors: Douglas Gregor -# Andrew Lumsdaine - -import bgl - -g = bgl.Graph("biconnected_components.dot", bgl.file_kind.graphviz) -bgl.kamada_kawai_spring_layout(g, side_length=400) -g.write_graphviz("kamada_kawai_spring_layout_out.dot") diff --git a/test/python/py_dijkstra.py b/test/python/py_dijkstra.py deleted file mode 100644 index 9bd23f95..00000000 --- a/test/python/py_dijkstra.py +++ /dev/null @@ -1,110 +0,0 @@ -# Copyright 2005 The Trustees of Indiana University. - -# Use, modification and distribution is subject to 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) - -# Authors: Douglas Gregor -# Andrew Lumsdaine - -# Note: this code requires the Boost Graph Library bindings for Python -# and the priodict module. The latter is part of the Python NMS -# library (http://pynms.sourceforge.net/). - -import bgl -import priodict - -class pqueue(bgl.Digraph.VertexQueue): - def __init__(self, distance): - bgl.Digraph.VertexQueue.__init__(self) - self.Q = priodict.priorityDictionary() - self.distance = distance - def empty(self): - return self.Q == {} - def top(self): - return self.Q.smallest(); - def pop(self): - del self.Q[self.Q.smallest()] - def push(self, x): - self.Q[x] = self.distance[x] - def update(self, x, v): - self.distance[x] = v - self.Q[x] = v - -class dijkstra_bfs_visitor(bgl.Digraph.BFSVisitor): - def __init__(self, Q, weight, distance, predecessor): - bgl.Digraph.BFSVisitor.__init__(self) - self.Q = Q - self.weight = weight - self.distance = distance - self.predecessor = predecessor - - def tree_edge(self, e, g): - (u, v) = (g.source(e), g.target(e)) - self.distance[v] = self.distance[u] + self.weight[e] - self.predecessor[v] = u - - def gray_target(self, e, g): - (u, v) = (g.source(e), g.target(e)) - if self.distance[u] + self.weight[e] < self.distance[v]: - self.Q.update(v, self.distance[u] + self.weight[e]) - self.predecessor[v] = u; - - -g = bgl.Digraph() - -# Create vertices in the graph -name = g.get_vertex_string_map("node_id") -A = g.add_vertex() -name[A] = "A" -B = g.add_vertex() -name[B] = "B" -C = g.add_vertex() -name[C] = "C" -D = g.add_vertex() -name[D] = "D" -E = g.add_vertex() -name[E] = "E" - -# Create (weighted) edges in the graph -weight = g.get_edge_double_map("label") -weight[g.add_edge(A, C)] = 1 -weight[g.add_edge(B, B)] = 2 -weight[g.add_edge(B, D)] = 1 -weight[g.add_edge(B, E)] = 2.5 -weight[g.add_edge(C, B)] = 7 -weight[g.add_edge(C, D)] = 3 -weight[g.add_edge(D, E)] = 1 -weight[g.add_edge(E, A)] = 1 -weight[g.add_edge(E, B)] = 1 - -# Initialize property maps -predecessor = {} -distance = g.get_vertex_double_map("distance_from_A") -for v in g.vertices: - predecessor[v] = v - distance[v] = 1e100 - -# Run breadth-first search to compute shortest paths -distance[A] = 0 -buf = pqueue(distance) - -bgl.breadth_first_search(g, A, buf, - dijkstra_bfs_visitor(buf,weight,distance,predecessor), - color_map = g.get_vertex_color_map("color")) - -class show_relaxed_edges(bgl.Digraph.DijkstraVisitor): - def edge_relaxed(self, e, g): - text = "Relaxed edge (" + name[g.source(e)] + ", " + name[g.target(e)] + ")" - print text - -# Run Dijkstra's algorithm to compute shortest paths -distance2 = g.get_vertex_double_map("distance_from_A_also"); -bgl.dijkstra_shortest_paths(g, A, distance_map = distance2, - visitor=show_relaxed_edges(), - weight_map = g.get_edge_double_map("label")); - -# Emit graph -g.write_graphviz("dijkstra-example.dot") - -