summaryrefslogtreecommitdiff
path: root/networkx/algorithms/approximation
diff options
context:
space:
mode:
authorMatt Schwennesen <mjschwenne@gmail.com>2022-06-26 19:54:00 -0500
committerGitHub <noreply@github.com>2022-06-26 20:54:00 -0400
commit2b258dfd59ff69b54428126decfb59aadfd94189 (patch)
treecf5dfecf0b38d48b5dec693c8983ac55bccde733 /networkx/algorithms/approximation
parentdd2d7d9b4455b08f23c663cbec0c6901957640b7 (diff)
downloadnetworkx-2b258dfd59ff69b54428126decfb59aadfd94189.tar.gz
Fix #5817 (#5822)
* Potential fix? * removed unneeded line
Diffstat (limited to 'networkx/algorithms/approximation')
-rw-r--r--networkx/algorithms/approximation/traveling_salesman.py14
1 files changed, 4 insertions, 10 deletions
diff --git a/networkx/algorithms/approximation/traveling_salesman.py b/networkx/algorithms/approximation/traveling_salesman.py
index c7a90420..806c8b74 100644
--- a/networkx/algorithms/approximation/traveling_salesman.py
+++ b/networkx/algorithms/approximation/traveling_salesman.py
@@ -668,21 +668,15 @@ def held_karp_ascent(G, weight="weight"):
a_eq = np.empty((len(G) + 1, len(minimum_1_arborescences)), dtype=int)
b_eq = np.zeros(len(G) + 1, dtype=int)
b_eq[len(G)] = 1
- arb_count = 0
- for arborescence in minimum_1_arborescences:
+ for arb_count, arborescence in enumerate(minimum_1_arborescences):
n_count = len(G) - 1
for n, deg in arborescence.degree:
a_eq[n_count][arb_count] = deg - 2
n_count -= 1
a_eq[len(G)][arb_count] = 1
- arb_count += 1
- program_result = optimize.linprog(
- c, A_eq=a_eq, b_eq=b_eq, method="interior-point"
- )
- bool_result = program_result.x >= 0
- if program_result.status == 0 and np.sum(bool_result) == len(
- minimum_1_arborescences
- ):
+ program_result = optimize.linprog(c, A_eq=a_eq, b_eq=b_eq)
+ # If the constants exist, then the direction of ascent doesn't
+ if program_result.success:
# There is no direction of ascent
return None, minimum_1_arborescences