Skip to content

Commit 71ae59d

Browse files
committed
fix: Add type annotations for queue, distance, previous, and path in DijkstraPathPlanning
1 parent 3de16f8 commit 71ae59d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

adf_core_python/implement/module/algorithm/dijkstra_path_planning.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import heapq
4+
from typing import Optional
45

56
from rcrs_core.entities.area import Area
67
from rcrs_core.worldmodel.entityID import EntityID
@@ -49,10 +50,10 @@ def get_path(
4950
self, from_entity_id: EntityID, to_entity_id: EntityID
5051
) -> list[EntityID]:
5152
# ダイクストラ法で最短経路を計算
52-
queue = []
53+
queue: list[tuple[float, EntityID]] = []
5354
heapq.heappush(queue, (0, from_entity_id))
54-
distance = {from_entity_id: 0}
55-
previous = {from_entity_id: None}
55+
distance: dict[EntityID, float] = {from_entity_id: 0}
56+
previous: dict[EntityID, Optional[EntityID]] = {from_entity_id: None}
5657

5758
while queue:
5859
current_distance, current_node = heapq.heappop(queue)
@@ -70,7 +71,7 @@ def get_path(
7071
heapq.heappush(queue, (new_distance, neighbor))
7172
previous[neighbor] = current_node
7273

73-
path = []
74+
path: list[EntityID] = []
7475
current_node = to_entity_id
7576
while current_node is not None:
7677
path.append(current_node)

0 commit comments

Comments
 (0)