-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathastar.py
45 lines (34 loc) · 1.05 KB
/
astar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from __future__ import annotations
from types import FunctionType
from solver.base import BaseSolver
from solver.pruning.base import BasePruning
from graph.grid import GridMap
from graph.node import Node
from utils.utils import getDirection
class AStar(BaseSolver):
def __init__(
self,
h_func: FunctionType,
prune: BasePruning,
) -> AStar:
super().__init__(h_func, prune)
def getSuccessors(
self,
state: Node,
goal: Node,
grid: GridMap,
k: int,
) -> list:
optimal = self.prune.getOptimalDirections(state, goal)
nodes = [
Node(
i = state.i + mv[0],
j = state.j + mv[1],
h = self.h_func(state.i + mv[0], state.j + mv[1], goal.i, goal.j),
parent = state,
k = k,
)
for mv in grid.getAllowedMovements(state.i, state.j)
if mv in optimal
]
return nodes