Skip to content

Commit 0bd8b9c

Browse files
committed
fix: TSP in graph
1 parent 5fe84b5 commit 0bd8b9c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

graphs/travlelling_salesman_problem.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def travelling_salesman_brute_force(
6363
6464
>>> graph = {"A": [10, 20], "B": [30, 21], "C": [15, 35]}
6565
>>> travelling_salesman_brute_force(graph)
66-
(['A', 'B', 'C', 'A'], 65.52370249788875)
66+
(['A', 'C', 'B', 'A'], 56.35465722402587)
6767
>>> travelling_salesman_brute_force({})
6868
Traceback (most recent call last):
6969
...
@@ -107,7 +107,7 @@ def travelling_salesman_dynamic_programming(
107107
108108
>>> graph = {"A": [10, 20], "B": [30, 21], "C": [15, 35]}
109109
>>> travelling_salesman_dynamic_programming(graph)
110-
(['A', 'B', 'C', 'A'], 65.52370249788875)
110+
(['A', 'C', 'B', 'A'], 56.35465722402587)
111111
>>> travelling_salesman_dynamic_programming({})
112112
Traceback (most recent call last):
113113
...
@@ -167,6 +167,7 @@ def travelling_salesman_dynamic_programming(
167167

168168
path.append(nodes[0])
169169
path.reverse()
170+
path.append(nodes[0])
170171

171172
return path, min_cost
172173

0 commit comments

Comments
 (0)