Skip to content

Commit 6c81591

Browse files
committed
Cleanup, test fixes and readme
1 parent e2a6a91 commit 6c81591

29 files changed

Lines changed: 662 additions & 413 deletions

Changelog

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Enhancements:
1313
Make shortest_path (Dijkstra's algorithm) run in O(E log V) instead of O(E^2) (dkorduban)
1414
Make graph.add_edge run in O(1) instead of O(degree(V)) (dkorduban)
1515
Added implementation of Kruskal's Minimum Spanning Tree construction algorithm (goldragoon)
16-
16+
Repackaged and updated to python3 (robinharms)
1717

1818
Release 1.8.2 [July 14, 2012]
1919

Makefile renamed to Makefile.old

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# python-graph
22
# Makefile
3+
# Note! This file is only kept as a reference
34

45

56
# Module directories -------------------------------------------------

README.rst

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,11 @@
22
python-graph
33
============
44

5-
.. image:: https://travis-ci.org/Shoobx/python-graph.png?branch=master
6-
:target: https://travis-ci.org/Shoobx/python-graph
7-
8-
.. image:: https://coveralls.io/repos/github/Shoobx/python-graph/badge.svg?branch=master
9-
:target: https://coveralls.io/github/Shoobx/python-graph?branch=master
10-
11-
.. image:: https://img.shields.io/pypi/v/python-graph-core.svg
12-
:target: https://pypi.org/project/python-graph-core/
13-
14-
.. image:: https://img.shields.io/pypi/pyversions/python-graph-core.svg
15-
:target: https://pypi.org/project/python-graph-core/
16-
17-
.. image:: https://api.codeclimate.com/v1/badges/8e78b3479160f2c5cdd0/maintainability
18-
:target: https://codeclimate.com/github/Shoobx/python-graph/maintainability
19-
:alt: Maintainability
205

216
A library for working with graphs in Python
227
-------------------------------------------
238

24-
This software provides a suitable data structure for representing graphs and a
9+
This software provides a suitable data structure for representing graphs and a
2510
whole set of important algorithms.
2611

2712

@@ -30,27 +15,17 @@ INSTALLING
3015

3116
To install the core module, run:
3217

33-
make install-core
18+
pip install python-graph
3419

3520
To install the dot language support, run:
3621

37-
make install-dot
38-
39-
Alternatively, if you don't have make, you can install the modules by running:
40-
41-
./setup.py install
42-
43-
inside the module directory.
22+
pip install python-graph[dot]
4423

4524

4625
DOCUMENTATION
4726
-------------
4827

49-
To generate the API documentation for this package, run:
50-
51-
make docs
52-
53-
You'll need epydoc installed in your system.
28+
FIXME: Module documentation isn't available
5429

5530

5631
WEBSITE
@@ -147,6 +122,9 @@ Daniel Merritt <dmerritt@gmail.com>
147122
Sandro Tosi <morph@debian.org>
148123
* Some improvements to Makefile
149124

125+
Robin Harms Oredsson <robin@betahaus.net>
126+
* Repackaging and modernization to make it work with python3 and modern distribution.
127+
* Typing
150128

151129
LICENSE
152130
-------

poetry.lock

Lines changed: 302 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pygraph/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@
5656
>>> # Depth first search rooted on node X
5757
>>> st, pre, post = depth_first_search(gr, root='X')
5858
>>> # Print the spanning tree
59-
>>> print st
60-
{'A': 'B', 'C': 'A', 'B': 'Y', 'Y': 'X', 'X': None, 'Z': 'X'}
59+
>>> {x:st[x] for x in sorted(st)}
60+
{'A': 'B', 'B': 'Y', 'C': 'A', 'X': None, 'Y': 'X', 'Z': 'X'}
6161
"""

pygraph/algorithms/critical.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def critical_path(graph):
149149
# find the critical node
150150
max = 0
151151
critical_node = None
152-
for k, v in list(node_tuples.items()):
152+
for k, v in node_tuples.items():
153153
if v[1] >= max:
154154
max = v[1]
155155
critical_node = k

pygraph/algorithms/generators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ def generate_hypergraph(num_nodes, num_edges, r=0):
103103
random_graph = hypergraph()
104104

105105
# Nodes
106-
nodes = list(map(str, list(range(num_nodes))))
106+
nodes = list(map(str, range(num_nodes)))
107107
random_graph.add_nodes(nodes)
108108

109109
# Base edges
110-
edges = list(map(str, list(range(num_nodes, num_nodes + num_edges))))
110+
edges = list(map(str, range(num_nodes, num_nodes + num_edges)))
111111
random_graph.add_hyperedges(edges)
112112

113113
# Connect the edges

pygraph/algorithms/heuristics/chow.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def optimize(self, graph):
5656
"""
5757
for center in self.centers:
5858
shortest_routes = shortest_path(graph, center)[1]
59-
for node, weight in list(shortest_routes.items()):
59+
for node, weight in shortest_routes.items():
6060
self.nodes.setdefault(node, []).append(weight)
6161

6262
def __call__(self, start, end):
@@ -69,10 +69,10 @@ def __call__(self, start, end):
6969
@type end: node
7070
@param end: End node.
7171
"""
72-
assert len(list(self.nodes.keys())) > 0, (
72+
assert len(self.nodes.keys()) > 0, (
7373
"You need to optimize this heuristic for your graph before it can be used to estimate."
7474
)
7575

76-
cmp_sequence = list(zip(self.nodes[start], self.nodes[end]))
76+
cmp_sequence = zip(self.nodes[start], self.nodes[end])
7777
chow_number = max(abs(a - b) for a, b in cmp_sequence)
7878
return chow_number

pygraph/algorithms/heuristics/euclidean.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,20 @@ class euclidean:
4040
3. The C{optimize()} method should be called before the heuristic search.
4141
4242
A small example for clarification:
43-
43+
>>> from pygraph.classes import graph
4444
>>> g = graph.graph()
4545
>>> g.add_nodes(['A','B','C'])
4646
>>> g.add_node_attribute('A', ('position',(0,0)))
4747
>>> g.add_node_attribute('B', ('position',(1,1)))
4848
>>> g.add_node_attribute('C', ('position',(0,2)))
49-
>>> g.add_edge('A','B', wt=2)
50-
>>> g.add_edge('B','C', wt=2)
51-
>>> g.add_edge('A','C', wt=4)
52-
>>> h = graph.heuristics.euclidean()
49+
>>> g.add_edge(('A','B'), wt=2)
50+
>>> g.add_edge(('B','C'), wt=2)
51+
>>> g.add_edge(('A','C'), wt=4)
52+
>>> h = euclidean()
5353
>>> h.optimize(g)
54-
>>> g.heuristic_search('A', 'C', h)
54+
>>> from pygraph.algorithms.minmax import heuristic_search
55+
>>> heuristic_search(g, 'A', 'C', h)
56+
['A', 'C']
5557
"""
5658

5759
def __init__(self):
@@ -92,7 +94,7 @@ def __call__(self, start, end):
9294
@type end: node
9395
@param end: End node.
9496
"""
95-
assert len(list(self.distances.keys())) > 0, (
97+
assert len(self.distances.keys()) > 0, (
9698
"You need to optimize this heuristic for your graph before it can be used to estimate."
9799
)
98100

pygraph/algorithms/searching.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def dfs(node):
6464
pre.append(node)
6565
# Explore recursively the connected component
6666
for each in graph[node]:
67-
if each not in visited and list(filter(each, node)):
67+
if each not in visited and filter(each, node):
6868
spanning_tree[each] = node
6969
dfs(each)
7070
post.append(node)
@@ -77,7 +77,7 @@ def dfs(node):
7777

7878
# DFS from one node only
7979
if root is not None:
80-
if list(filter(root, None)):
80+
if filter(root, None):
8181
spanning_tree[root] = None
8282
dfs(root)
8383
setrecursionlimit(recursionlimit)
@@ -86,7 +86,7 @@ def dfs(node):
8686
# Algorithm loop
8787
for each in graph:
8888
# Select a non-visited node
89-
if each not in visited and list(filter(each, None)):
89+
if each not in visited and filter(each, None):
9090
spanning_tree[each] = None
9191
# Explore node's connected component
9292
dfs(each)
@@ -123,7 +123,7 @@ def bfs():
123123
node = queue.pop(0)
124124

125125
for other in graph[node]:
126-
if other not in spanning_tree and list(filter(other, node)):
126+
if other not in spanning_tree and filter(other, node):
127127
queue.append(other)
128128
ordering.append(other)
129129
spanning_tree[other] = node
@@ -135,7 +135,7 @@ def bfs():
135135

136136
# BFS from one node only
137137
if root is not None:
138-
if list(filter(root, None)):
138+
if filter(root, None):
139139
queue.append(root)
140140
ordering.append(root)
141141
spanning_tree[root] = None
@@ -145,7 +145,7 @@ def bfs():
145145
# Algorithm
146146
for each in graph:
147147
if each not in spanning_tree:
148-
if list(filter(each, None)):
148+
if filter(each, None):
149149
queue.append(each)
150150
ordering.append(each)
151151
spanning_tree[each] = None

0 commit comments

Comments
 (0)