boostorg / graph

Boost.org graph module
http://boost.org/libs/graph
325 stars 208 forks source link

astar_search: visitor edge_relaxed method called inconsistently before or after cost map is set #233

Open risicle opened 3 years ago

risicle commented 3 years ago

astar_bfs_visitor calls m_vis.edge_relaxed before setting the new cost map value in tree_edge and black_target (and in astar_search_no_init_tree's main loop from the looks of it), but afterwards in gray_target. This is very confusing if you want to look up the new cost value in your visitor method.

qbit86 commented 3 years ago

Let me attach the code for clarity.

tree_edge

m_vis.edge_relaxed(e, g);
put(m_cost, target(e, g),
    m_combine(
        get(m_distance, target(e, g)), m_h(target(e, g))));

gray_target

put(m_cost, target(e, g),
    m_combine(
        get(m_distance, target(e, g)), m_h(target(e, g))));
m_Q.update(target(e, g));
m_vis.edge_relaxed(e, g);

black_target

m_vis.edge_relaxed(e, g);
put(m_cost, target(e, g),
    m_combine(
        get(m_distance, target(e, g)), m_h(target(e, g))));
m_Q.push(target(e, g));
put(m_color, target(e, g), Color::gray());
m_vis.black_target(e, g);

At the moment of edge_relaxed event:

The queue should probably be updated after edge_relaxed, to be consistent with “outer” breadth_first_visit. The cost map should almost certainly be updated before edge_relaxed.

jeremy-murphy commented 1 year ago

Could one of you make a PR to fix it? @qbit86 I think you already have the code ready? :)