Skip to content

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

Closed

Description

@risicle

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.

Activity

  1. qbit86 commented on Jun 1, 2021

    @qbit86
    Contributor

    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 predecessor map and the distance map are already updated;
    • the color map is not updated yet;
    • the queue and the cost map are inconsistently updated.

    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.

  2. added a commit that references this issue on Jun 3, 2021
    b4b56aa
  3. self-assigned this
    on May 7, 2023
  4. jeremy-murphy commented on May 7, 2023

    @jeremy-murphy
    Collaborator

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

  5. added
    algorithm
    on Jun 4, 2026
  6. added theissue type on Jun 4, 2026
  7. added
    priority: medium
    on Jun 4, 2026
  8. Becheler commented on Jun 4, 2026

    @Becheler
    Collaborator

    Hi @qbit86 ! Just trying to assess if you are still around for opening a PR? I can also fix it myself.
    Anyway, thanks a lot for reporting and exploring this ! ❤️

  9. qbit86 commented on Jun 4, 2026

    @qbit86
    Contributor

    Hi @Becheler, It's been a while and I've lost track of this one, so if you're happy to fix it yourself, please go ahead — much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

algorithmbeginner friendlypriority: medium

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions