Commit 80259313 authored by Jerome Mariette's avatar Jerome Mariette
Browse files

from python2 to python3 > ok from command line

parent f1028f5b
...@@ -60,4 +60,4 @@ A quick introductory example: ...@@ -60,4 +60,4 @@ A quick introductory example:
{'A': 'B', 'C': 'A', 'B': 'Y', 'Y': 'X', 'X': None, 'Z': 'X'} {'A': 'B', 'C': 'A', 'B': 'Y', 'Y': 'X', 'X': None, 'Z': 'X'}
""" """
__import__('pkg_resources').declare_namespace(__name__) #__import__('pkg_resources').declare_namespace(__name__)
...@@ -63,7 +63,7 @@ def generate(num_nodes, num_edges, directed=False, weight_range=(1, 1)): ...@@ -63,7 +63,7 @@ def generate(num_nodes, num_edges, directed=False, weight_range=(1, 1)):
random_graph = graph() random_graph = graph()
# Nodes # Nodes
nodes = range(num_nodes) nodes = list(range(num_nodes))
random_graph.add_nodes(nodes) random_graph.add_nodes(nodes)
# Build a list of all possible edges # Build a list of all possible edges
......
...@@ -429,7 +429,7 @@ def cut_value(graph, flow, cut): ...@@ -429,7 +429,7 @@ def cut_value(graph, flow, cut):
#max flow/min cut value calculation #max flow/min cut value calculation
S = [] S = []
T = [] T = []
for node in cut.keys(): for node in list(cut.keys()):
if cut[node] == 0: if cut[node] == 0:
S.append(node) S.append(node)
elif cut[node] == 1: elif cut[node] == 1:
...@@ -481,7 +481,7 @@ def cut_tree(igraph, caps = None): ...@@ -481,7 +481,7 @@ def cut_tree(igraph, caps = None):
N = N + 1 N = N + 1
#predecessor function #predecessor function
p = {}.fromkeys(range(N),0) p = {}.fromkeys(list(range(N)),0)
p[0] = None p[0] = None
for s in range(1,N): for s in range(1,N):
......
...@@ -64,7 +64,7 @@ def depth_first_search(graph, root=None, filter=null()): ...@@ -64,7 +64,7 @@ def depth_first_search(graph, root=None, filter=null()):
pre.append(node) pre.append(node)
# Explore recursively the connected component # Explore recursively the connected component
for each in graph[node]: for each in graph[node]:
if (each not in visited and filter(each, node)): if (each not in visited and list(filter(each, node))):
spanning_tree[each] = node spanning_tree[each] = node
dfs(each) dfs(each)
post.append(node) post.append(node)
...@@ -77,7 +77,7 @@ def depth_first_search(graph, root=None, filter=null()): ...@@ -77,7 +77,7 @@ def depth_first_search(graph, root=None, filter=null()):
# DFS from one node only # DFS from one node only
if (root is not None): if (root is not None):
if filter(root, None): if list(filter(root, None)):
spanning_tree[root] = None spanning_tree[root] = None
dfs(root) dfs(root)
setrecursionlimit(recursionlimit) setrecursionlimit(recursionlimit)
...@@ -86,7 +86,7 @@ def depth_first_search(graph, root=None, filter=null()): ...@@ -86,7 +86,7 @@ def depth_first_search(graph, root=None, filter=null()):
# Algorithm loop # Algorithm loop
for each in graph: for each in graph:
# Select a non-visited node # Select a non-visited node
if (each not in visited and filter(each, None)): if (each not in visited and list(filter(each, None))):
spanning_tree[each] = None spanning_tree[each] = None
# Explore node's connected component # Explore node's connected component
dfs(each) dfs(each)
...@@ -122,7 +122,7 @@ def breadth_first_search(graph, root=None, filter=null()): ...@@ -122,7 +122,7 @@ def breadth_first_search(graph, root=None, filter=null()):
node = queue.pop(0) node = queue.pop(0)
for other in graph[node]: for other in graph[node]:
if (other not in spanning_tree and filter(other, node)): if (other not in spanning_tree and list(filter(other, node))):
queue.append(other) queue.append(other)
ordering.append(other) ordering.append(other)
spanning_tree[other] = node spanning_tree[other] = node
...@@ -134,7 +134,7 @@ def breadth_first_search(graph, root=None, filter=null()): ...@@ -134,7 +134,7 @@ def breadth_first_search(graph, root=None, filter=null()):
# BFS from one node only # BFS from one node only
if (root is not None): if (root is not None):
if filter(root, None): if list(filter(root, None)):
queue.append(root) queue.append(root)
ordering.append(root) ordering.append(root)
spanning_tree[root] = None spanning_tree[root] = None
...@@ -144,7 +144,7 @@ def breadth_first_search(graph, root=None, filter=null()): ...@@ -144,7 +144,7 @@ def breadth_first_search(graph, root=None, filter=null()):
# Algorithm # Algorithm
for each in graph: for each in graph:
if (each not in spanning_tree): if (each not in spanning_tree):
if filter(each, None): if list(filter(each, None)):
queue.append(each) queue.append(each)
ordering.append(each) ordering.append(each)
spanning_tree[each] = None spanning_tree[each] = None
......
...@@ -101,7 +101,7 @@ class digraph (basegraph, common, labeling): ...@@ -101,7 +101,7 @@ class digraph (basegraph, common, labeling):
return [ a for a in self._edges() ] return [ a for a in self._edges() ]
def _edges(self): def _edges(self):
for n, neighbors in self.node_neighbors.items(): for n, neighbors in list(self.node_neighbors.items()):
for neighbor in neighbors: for neighbor in neighbors:
yield (n, neighbor) yield (n, neighbor)
......
...@@ -87,7 +87,7 @@ class graph(basegraph, common, labeling): ...@@ -87,7 +87,7 @@ class graph(basegraph, common, labeling):
@rtype: list @rtype: list
@return: List of all edges in the graph. @return: List of all edges in the graph.
""" """
return [ a for a in self.edge_properties.keys() ] return [ a for a in list(self.edge_properties.keys()) ]
def has_node(self, node): def has_node(self, node):
""" """
......
...@@ -30,4 +30,4 @@ Base classes used to compose the the graph classes. ...@@ -30,4 +30,4 @@ Base classes used to compose the the graph classes.
The classes in this namespace should not be used directly. The classes in this namespace should not be used directly.
""" """
__import__('pkg_resources').declare_namespace(__name__) #__import__('pkg_resources').declare_namespace(__name__)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment