Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…Finder into develop
  • Loading branch information
jmnorheim committed Aug 10, 2024
2 parents c421d69 + efa8724 commit e6eda0f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
12 changes: 7 additions & 5 deletions backend/graphtraversal/algorithms/a_star.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ def find_path(
return a_star(map, start, goal, heuristic)


def a_star(map: Map, start: Node, goal: Node, heuristic: Callable) -> list[Position]:
def a_star(
map: Map, start: Node, goal: Node, heuristic: Callable
) -> tuple[list[Position], list[Node]]:
"""
A* algorithm implementation
Expand Down Expand Up @@ -109,11 +111,11 @@ def a_star(map: Map, start: Node, goal: Node, heuristic: Callable) -> list[Posit

came_from[neighbor] = current
cost_to_reach_position[neighbor] = tentative_cost_to_reach
estimated_remaining_distance[
neighbor
] = tentative_cost_to_reach + heuristic(neighbor, goal_pos)
estimated_remaining_distance[neighbor] = (
tentative_cost_to_reach + heuristic(neighbor, goal_pos)
)

# Add the neighbor to the frontier if it is not explored yet
if neighbor not in frontier.get_frontier():
frontier.insert(neighbor, tentative_cost_to_reach)
return None
return [], []
2 changes: 1 addition & 1 deletion backend/graphtraversal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def post_graph_traversal(request):
time_taken = datetime.now().timestamp() - current_time
print(f"path: {path}")
print(f"node_order: {node_order}")
pathfinder_status: str = "success" if path is not None else "failure"
pathfinder_status: str = "success" if len(path) == 0 else "failure"

# Serialize the list of dictionaries to a JSON string
path_dicts = [node.to_dict() for node in path]
Expand Down
1 change: 1 addition & 0 deletions frontend/src/assets/icons/redo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 0 additions & 2 deletions frontend/src/services/postTraversal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ export const postTraversal = async ({
const responseData = response.data;
return responseData;
} else if (response.status === 400) {
console.error("Error in postTraversal frontend:", response.data.message);
return null;
} else if (response.status === 500) {
console.error("Error in postTraversal backend:", response.data.message);
return null;
}

Expand Down

0 comments on commit e6eda0f

Please sign in to comment.