Skip to content

Commit cd75fc9

Browse files
committed
Fix Dijkstra handling of unreachable goals
1 parent 89a281e commit cd75fc9

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

‎PathPlanning/Dijkstra/dijkstra.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ def planning(self, sx, sy, gx, gy):
7272
open_set[self.calc_index(start_node)] = start_node
7373

7474
while True:
75+
if len(open_set) == 0:
76+
print("Open set is empty..")
77+
return [], []
78+
7579
c_id = min(open_set, key=lambda o: open_set[o].cost)
7680
current = open_set[c_id]
7781

‎tests/test_dijkstra.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,20 @@ def test_1():
77
m.main()
88

99

10+
def test_unreachable_goal():
11+
m.show_animation = False
12+
13+
ox, oy = [], []
14+
for i in range(7):
15+
ox.extend([0.0, 6.0, float(i), float(i), 3.0])
16+
oy.extend([float(i), float(i), 0.0, 6.0, float(i)])
17+
18+
planner = m.DijkstraPlanner(ox, oy, 1.0, 0.0)
19+
rx, ry = planner.planning(1.0, 3.0, 5.0, 3.0)
20+
21+
assert rx == []
22+
assert ry == []
23+
24+
1025
if __name__ == '__main__':
1126
conftest.run_this_test(__file__)

0 commit comments

Comments
 (0)