Giter Club home page Giter Club logo

Comments (5)

jrialland avatar jrialland commented on May 17, 2024

Thanks for your input ! - I don't think i'm going to make any change anyway : The "heuristic cost" of a given node is not meant to change over time in a general case; so I don't see any improvement in reordering the heap for each visited node. Contrary to what you mean, this implementation is 100% correct, at least regarding this.
If you need to tweak it case-specific improvements, I recommand you to craft your own implementation -
Cheers,

from python-astar.

jaromiru avatar jaromiru commented on May 17, 2024

Let me explain. The heuristic value cannot change - correct. But the algorithm can find an alternate shorter path to a node X, which means the g-value needs to be updated. You are correctly updating it in this case, but merely updating the object does not re-sort the heap itself. The updated object should be brought up in priority, which is not done here.

Because of this, the line 87: current = heappop(openSet) no longer returns the element with lowest f-value. Still, the algorithm finds a solution, but that may be not the optimal one.

I assume you made the mistake by implementing the pseudo-code in python, but mistaken the heap object for auto-sorting priority queue.

from python-astar.

jrialland avatar jrialland commented on May 17, 2024

I understand your explanation, but you may have missed something in the definition of heappush/heappop : The heap is re-sorted, so heappop always returns the best item. (as illustrated here : https://docs.python.org/3/library/heapq.html#basic-examples) ( https://stackoverflow.com/questions/19979518/what-is-pythons-heapq-module ).

I'm sorry to insist, but heappush/heappop really actually do the auto-sorting thing, that's why these are made for

Anyway It would be very kind from you if you managed to provide a unit test that illustrates the issue

from python-astar.

jaromiru avatar jaromiru commented on May 17, 2024

Let me try once more. In lines 100-101, you modify the neighbor object in-place. This object may be already present in the heap, in which case, after the modification, the heap is not magically re-sorted, i.e., the heappop will not return this object even if it's the best (you can easily test this yourself).

from python-astar.

jrialland avatar jrialland commented on May 17, 2024

@jaromiru Thank you for insisting on your explanations, I've fixed the code, and will release it soon - It seems that I'm one of those guys who "understand quickly if explained for a long time" :)

from python-astar.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.