Skip to content

Commit

Permalink
Use nodelist feature of from_numpy_array. (networkx#7425)
Browse files Browse the repository at this point in the history
  • Loading branch information
rossbar authored and cvanelteren committed Apr 22, 2024
1 parent 30db0ba commit 7038964
Showing 1 changed file with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -815,15 +815,14 @@ def test_asadpour_real_world():
]
)

node_map = {0: "JFK", 1: "LAX", 2: "ORD", 3: "IAH", 4: "PHX", 5: "PHL"}
node_list = ["JFK", "LAX", "ORD", "IAH", "PHX", "PHL"]

expected_tours = [
["JFK", "LAX", "PHX", "ORD", "IAH", "PHL", "JFK"],
["JFK", "ORD", "PHX", "LAX", "IAH", "PHL", "JFK"],
]

G = nx.from_numpy_array(G_array, create_using=nx.DiGraph)
nx.relabel_nodes(G, node_map, copy=False)
G = nx.from_numpy_array(G_array, nodelist=node_list, create_using=nx.DiGraph)

tour = nx_app.traveling_salesman_problem(
G, weight="weight", method=nx_app.asadpour_atsp, seed=37, source="JFK"
Expand Down Expand Up @@ -862,15 +861,14 @@ def test_asadpour_real_world_path():
]
)

node_map = {0: "JFK", 1: "LAX", 2: "ORD", 3: "IAH", 4: "PHX", 5: "PHL"}
node_list = ["JFK", "LAX", "ORD", "IAH", "PHX", "PHL"]

expected_paths = [
["ORD", "PHX", "LAX", "IAH", "PHL", "JFK"],
["JFK", "PHL", "IAH", "ORD", "PHX", "LAX"],
]

G = nx.from_numpy_array(G_array, create_using=nx.DiGraph)
nx.relabel_nodes(G, node_map, copy=False)
G = nx.from_numpy_array(G_array, nodelist=node_list, create_using=nx.DiGraph)

path = nx_app.traveling_salesman_problem(
G, weight="weight", cycle=False, method=nx_app.asadpour_atsp, seed=56
Expand Down

0 comments on commit 7038964

Please sign in to comment.