Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix A* star selection logic #22

Open
wants to merge 11 commits into
base: feature/clang_format_reorder_includes
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ bool SkeletonAStar::getPathBetweenVertices(

const voxblox::Point t_odom_current_vertex =
current_submap.getPose() * current_vertex.point;
const FloatingPoint h_score = (goal_point - t_odom_current_vertex).norm();
g_score_map[current_vertex_id] =
(t_odom_current_vertex - start_point).norm();
f_score_map[current_vertex_id] =
(goal_point - t_odom_current_vertex).norm();
f_score_map[current_vertex_id] = h_score;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentionally called h_score and then assigned to the f_score_map? I'm not too familiar with the terminology but might lead to confusions.

Copy link
Member Author

@victorreijgwart victorreijgwart Mar 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strictly speaking, the update equation here should be f[neighbor] = g[neighbor] + h[neighbor]. The code above only initializes the starting vertices and will result in all of them being expanded before any regular vertex, so it won't affect the result. But I agree it's confusing and there's no advantage of not using the standard update equation.
In general, this whole getPathBetweenVertices(...) method grew organically and got quite messy. I'll do some refactoring.

open_set.insert(current_vertex_id);
}

Expand Down Expand Up @@ -264,7 +264,7 @@ bool SkeletonAStar::getPathBetweenVertices(
g_score_map[current_vertex_id] +
(goal_point - current_vertex.point).norm();
if (g_score_map.count(kGoalVertexId) == 0 ||
g_score_map[kGoalVertexId] < tentative_g_score) {
tentative_g_score < g_score_map[kGoalVertexId]) {
g_score_map[kGoalVertexId] = tentative_g_score;
f_score_map[kGoalVertexId] = tentative_g_score;
parent_map[kGoalVertexId] = current_vertex_id;
Expand Down Expand Up @@ -333,11 +333,12 @@ bool SkeletonAStar::getPathBetweenVertices(
g_score_map[current_vertex_id] +
(t_odom_nearby_vertex - t_odom_current_vertex).norm();
if (g_score_map.count(nearby_vertex_global_id) == 0 ||
g_score_map[nearby_vertex_global_id] < tentative_g_score) {
tentative_g_score < g_score_map[nearby_vertex_global_id]) {
const FloatingPoint h_score =
(goal_point - t_odom_nearby_vertex).norm();
g_score_map[nearby_vertex_global_id] = tentative_g_score;
f_score_map[nearby_vertex_global_id] =
tentative_g_score +
(goal_point - t_odom_nearby_vertex).norm();
tentative_g_score + h_score;
parent_map[nearby_vertex_global_id] = current_vertex_id;
}
} else {
Expand Down Expand Up @@ -389,10 +390,11 @@ bool SkeletonAStar::getPathBetweenVertices(
// NOTE: Since the vertex and its neighbor are already in the same
// (submap) frame, we can directly compute their distance above
if (g_score_map.count(neighbor_vertex_id) == 0 ||
g_score_map[neighbor_vertex_id] < tentative_g_score) {
tentative_g_score < g_score_map[neighbor_vertex_id]) {
const FloatingPoint h_score =
(goal_point - t_odom_neighbor_vertex).norm();
g_score_map[neighbor_vertex_id] = tentative_g_score;
f_score_map[neighbor_vertex_id] =
tentative_g_score + (goal_point - t_odom_neighbor_vertex).norm();
f_score_map[neighbor_vertex_id] = tentative_g_score + h_score;
parent_map[neighbor_vertex_id] = current_vertex_id;
}
}
Expand Down