Skip to content

Commit

Permalink
added additional test for theta star, weights disabled for theta star
Browse files Browse the repository at this point in the history
  • Loading branch information
harisankar95 committed Jan 27, 2024
1 parent 282a94b commit 1d247f0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 3 additions & 1 deletion pathfinding3d/finder/theta_star.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(
):
"""
Find shortest path using Theta* algorithm
Diagonal movement is forced to always.
Diagonal movement is forced to always. Not weighted.
Parameters
----------
Expand Down Expand Up @@ -52,6 +52,8 @@ def __init__(
max_runs=max_runs,
)

self.weighted = False

def process_node(
self,
grid: Grid,
Expand Down
17 changes: 14 additions & 3 deletions test/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
BiAStarFinder,
DijkstraFinder,
MinimumSpanningTree,
ThetaStarFinder,
]

SIMPLE_MATRIX = np.zeros((5, 5, 5))
Expand Down Expand Up @@ -90,8 +89,6 @@ def test_weighted_path():
start = grid.node(0, 0, 0)
end = grid.node(4, 4, 0)
for find in weighted_finders:
if find == ThetaStarFinder:
continue
grid.cleanup()
finder = find(time_limit=TIME_LIMIT)
path_, runs = finder.find_path(start, end, grid)
Expand Down Expand Up @@ -171,3 +168,17 @@ def test_msp():

finder = MinimumSpanningTree()
assert finder.tree(grid, start).sort() == [node for row in grid.nodes for col in row for node in col].sort()


def test_theta_star(caplog):
"""
Test that the theta star finder returns the correct path.
"""
caplog.set_level("WARNING")
grid = Grid(matrix=WEIGHTED_SIMPLE_MATRIX)
start = grid.node(0, 0, 0)
end = grid.node(4, 4, 0)

finder = ThetaStarFinder(diagonal_movement=DiagonalMovement.never, time_limit=TIME_LIMIT)
assert finder.diagonal_movement == DiagonalMovement.always
assert "Diagonal movement is forced to always" in caplog.text

0 comments on commit 1d247f0

Please sign in to comment.