From c4cc323d68ad230370f3de1139a67feaf60e9223 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Langlois Date: Wed, 16 Mar 2022 14:33:25 -0400 Subject: [PATCH 1/7] Compatibility with python 3.7+ --- postman_problems/examples/star/rpp_star.py | 2 +- postman_problems/solver.py | 4 ++-- postman_problems/viz.py | 12 ++++++------ setup.py | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/postman_problems/examples/star/rpp_star.py b/postman_problems/examples/star/rpp_star.py index 9e986f0..fae541a 100644 --- a/postman_problems/examples/star/rpp_star.py +++ b/postman_problems/examples/star/rpp_star.py @@ -20,7 +20,7 @@ def create_star_graph(n_nodes=10, ring=True): """ graph = nx.MultiGraph() node_names = list(string.ascii_lowercase)[:n_nodes] - graph.add_star(node_names) + nx.add_star(graph, node_names) nx.set_edge_attributes(graph, 10, 'distance') nx.set_edge_attributes(graph, 1, 'required') nx.set_edge_attributes(graph, 'solid', 'style') diff --git a/postman_problems/solver.py b/postman_problems/solver.py index 890284e..2519c33 100644 --- a/postman_problems/solver.py +++ b/postman_problems/solver.py @@ -51,7 +51,7 @@ def rpp(edgelist_filename, start_node=None, edge_weight='distance', verbose=Fals logger_rpp.info('Find min weight matching using blossom algorithm') g_odd_complete = create_complete_graph(odd_node_pairs_shortest_paths, flip_weights=True) - odd_matching = dedupe_matching(nx.algorithms.max_weight_matching(g_odd_complete, True)) + odd_matching = nx.algorithms.max_weight_matching(g_odd_complete, True) logger_rpp.info('add the min weight matching edges to g') g_aug = add_augmenting_path_to_graph(g_req, odd_matching) @@ -94,7 +94,7 @@ def cpp(edgelist_filename, start_node=None, edge_weight='distance', verbose=Fals g_odd_complete = create_complete_graph(odd_node_pairs_shortest_paths, flip_weights=True) logger_cpp.info('Find min weight matching using blossom algorithm') - odd_matching = dedupe_matching(nx.algorithms.max_weight_matching(g_odd_complete, True)) + odd_matching = nx.algorithms.max_weight_matching(g_odd_complete, True) logger_cpp.info('add the min weight matching edges to g') g_aug = add_augmenting_path_to_graph(g, odd_matching) diff --git a/postman_problems/viz.py b/postman_problems/viz.py index 3bb725a..e54f829 100644 --- a/postman_problems/viz.py +++ b/postman_problems/viz.py @@ -113,9 +113,9 @@ def convert_networkx_graph_to_graphiz(graph, directed=False): G = gv.Graph() # add nodes and their attributes to graphviz object - for n in graph.nodes(): - n_attr = {k: str(v) for k, v in graph.node[n].items()} - G.attr('node', n_attr) + for n, attr in graph.nodes(data=True): + # n_attr = {k: str(v) for k, v in graph.node[n].items()} + G.attr('node', attr) G.node(str(n), str(n)) # add edges and their attributes to graphviz object @@ -229,7 +229,7 @@ def make_circuit_images(circuit, graph, outfile_dir, format='png', engine='neato # Start w a blank (OK, opaque) canvas for e in graph_white.edges(keys=True): - graph_white.node[e[0]]['color'] = graph_white.node[e[1]]['color'] = '#eeeeee' + graph_white.nodes[e[0]]['color'] = graph_white.nodes[e[1]]['color'] = '#eeeeee' graph_white[e[0]][e[1]][e[2]]['color'] = '#eeeeee' graph_white[e[0]][e[1]][e[2]]['label'] = '' @@ -238,8 +238,8 @@ def make_circuit_images(circuit, graph, outfile_dir, format='png', engine='neato # adding node colors eid = e[3]['id'] - graph_white.node[e[0]]['color'] = 'black' - graph_white.node[e[1]]['color'] = 'red' # will get overwritten at next step + graph_white.nodes[e[0]]['color'] = 'black' + graph_white.nodes[e[1]]['color'] = 'red' # will get overwritten at next step # adding edge colors and attributes key = e[2] diff --git a/setup.py b/setup.py index 8cfbb4b..97a3d34 100644 --- a/setup.py +++ b/setup.py @@ -47,10 +47,10 @@ def read(fname): 'rural_postman_star=postman_problems.examples.star.rpp_star:main' ] }, - python_requires='>=2.7', + python_requires='>=3.7', install_requires=[ 'pandas', - 'networkx==2.0' + 'networkx' ], extras_require={ 'viz': ['imageio', 'matplotlib', 'graphviz', 'tqdm'], From 9a1e3df4b62200210d2c681803ba00afe39d450a Mon Sep 17 00:00:00 2001 From: Pierre-Yves Langlois Date: Wed, 16 Mar 2022 14:48:57 -0400 Subject: [PATCH 2/7] networkx supports 3.8+ --- .travis.yml | 8 +++----- setup.py | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index f859cc4..c4a0705 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,8 @@ language: python python: - - "2.7" - - "3.3" - - "3.4" - - "3.5" - - "3.6" + - "3.8" + - "3.9" + - "3.10" before_install: - pip install coveralls - pip install codecov diff --git a/setup.py b/setup.py index 97a3d34..dc0e7dc 100644 --- a/setup.py +++ b/setup.py @@ -47,7 +47,7 @@ def read(fname): 'rural_postman_star=postman_problems.examples.star.rpp_star:main' ] }, - python_requires='>=3.7', + python_requires='>=3.8', install_requires=[ 'pandas', 'networkx' From d072e1242e219d9a962b89eb28b693be405eb54d Mon Sep 17 00:00:00 2001 From: Pierre-Yves Langlois Date: Wed, 16 Mar 2022 21:31:17 -0400 Subject: [PATCH 3/7] Remove dead code --- postman_problems/viz.py | 1 - 1 file changed, 1 deletion(-) diff --git a/postman_problems/viz.py b/postman_problems/viz.py index e54f829..3ef44aa 100644 --- a/postman_problems/viz.py +++ b/postman_problems/viz.py @@ -114,7 +114,6 @@ def convert_networkx_graph_to_graphiz(graph, directed=False): # add nodes and their attributes to graphviz object for n, attr in graph.nodes(data=True): - # n_attr = {k: str(v) for k, v in graph.node[n].items()} G.attr('node', attr) G.node(str(n), str(n)) From cd5945b5d6aa28f0cc8fb6e1c5dffef290932766 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Langlois Date: Wed, 23 Mar 2022 11:28:22 -0400 Subject: [PATCH 4/7] networkx uses the function nodes instead of node in newer version Fix the regression that causes graphviz to raise an Exception with integer. --- postman_problems/viz.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/postman_problems/viz.py b/postman_problems/viz.py index 3ef44aa..5cb431e 100644 --- a/postman_problems/viz.py +++ b/postman_problems/viz.py @@ -51,8 +51,8 @@ def add_pos_node_attribute(graph, origin='bottomleft'): for node_id in graph.nodes(): try: # dividing by arbitrary number to make pos appear as required type: double - graph.node[node_id]['pos'] = "{},{}!".format(ori['X']*graph.node[node_id]['X']/100, - ori['Y']*graph.node[node_id]['Y']/100) + graph.nodes[node_id]['pos'] = "{},{}!".format(ori['X']*graph.nodes[node_id]['X']/100, + ori['Y']*graph.nodes[node_id]['Y']/100) except KeyError as e: print(e) print('No X, Y coordinates found for node: {}'.format(node_id)) @@ -113,8 +113,9 @@ def convert_networkx_graph_to_graphiz(graph, directed=False): G = gv.Graph() # add nodes and their attributes to graphviz object - for n, attr in graph.nodes(data=True): - G.attr('node', attr) + for n in graph.nodes(): + n_attr = {k: str(v) for k, v in graph.nodes[n].items()} + G.attr('node', n_attr) G.node(str(n), str(n)) # add edges and their attributes to graphviz object From 040eccbffdedee4e423fe1d6454b0d4c7d956895 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Langlois Date: Wed, 23 Mar 2022 11:42:29 -0400 Subject: [PATCH 5/7] Python 3.7 is compatible with earlier version of networkx --- .travis.yml | 1 + setup.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c4a0705..4728f0d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: python python: + - "3.7" - "3.8" - "3.9" - "3.10" diff --git a/setup.py b/setup.py index dc0e7dc..97a3d34 100644 --- a/setup.py +++ b/setup.py @@ -47,7 +47,7 @@ def read(fname): 'rural_postman_star=postman_problems.examples.star.rpp_star:main' ] }, - python_requires='>=3.8', + python_requires='>=3.7', install_requires=[ 'pandas', 'networkx' From 772c67919dcf9ada2284aa7a0fbb8d0a7a6d5c19 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Langlois Date: Wed, 23 Mar 2022 12:25:49 -0400 Subject: [PATCH 6/7] Tested compatibility with networkx>=2.0 with python 3.7 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 97a3d34..bbcf8ea 100644 --- a/setup.py +++ b/setup.py @@ -50,7 +50,7 @@ def read(fname): python_requires='>=3.7', install_requires=[ 'pandas', - 'networkx' + 'networkx>=2.0' ], extras_require={ 'viz': ['imageio', 'matplotlib', 'graphviz', 'tqdm'], From d23b9fcdba59ff55ec7fcb71ee2e57f3ba6a59e6 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Langlois Date: Thu, 21 Apr 2022 18:16:23 -0400 Subject: [PATCH 7/7] Compatibility with networkx>=2.0 and python 3.7+ --- .travis.yml | 2 -- setup.py | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4728f0d..5a906e1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,7 @@ language: python python: - - "3.7" - "3.8" - "3.9" - - "3.10" before_install: - pip install coveralls - pip install codecov diff --git a/setup.py b/setup.py index bbcf8ea..aca2e72 100644 --- a/setup.py +++ b/setup.py @@ -47,7 +47,7 @@ def read(fname): 'rural_postman_star=postman_problems.examples.star.rpp_star:main' ] }, - python_requires='>=3.7', + python_requires='>=3.7.1', install_requires=[ 'pandas', 'networkx>=2.0'