Skip to content

Commit

Permalink
Merge pull request #68 from pylanglois/pylanglois/py38
Browse files Browse the repository at this point in the history
Compatibility with networkx>=2.0 and python 3.7+
  • Loading branch information
brooksandrew authored Apr 26, 2022
2 parents 34f7790 + d23b9fc commit 4b2ba0c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
7 changes: 2 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
language: python
python:
- "2.7"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
- "3.8"
- "3.9"
before_install:
- pip install coveralls
- pip install codecov
Expand Down
2 changes: 1 addition & 1 deletion postman_problems/examples/star/rpp_star.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions postman_problems/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions postman_problems/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -114,7 +114,7 @@ def convert_networkx_graph_to_graphiz(graph, directed=False):

# 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()}
n_attr = {k: str(v) for k, v in graph.nodes[n].items()}
G.attr('node', n_attr)
G.node(str(n), str(n))

Expand Down Expand Up @@ -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'] = ''

Expand All @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.1',
install_requires=[
'pandas',
'networkx==2.0'
'networkx>=2.0'
],
extras_require={
'viz': ['imageio', 'matplotlib', 'graphviz', 'tqdm'],
Expand Down

0 comments on commit 4b2ba0c

Please sign in to comment.