Calculate shortest path through a grocery store

前端 未结 5 734
走了就别回头了
走了就别回头了 2020-12-31 06:31

I\'m trying to find a way to find the shortest path through a grocery store, visiting a list of locations (shopping list). The path should start at a specified start positio

5条回答
  •  难免孤独
    2020-12-31 07:09

    Only breadth first searching will make sure you don't "miss" a path through the store which is better than you're current "best" solution, but you need not search every node in the path. Nodes which are "obviously" longer than the current "best" solution may be expanded later.

    This means you approach the problem like a "breath first" search, but alter the expansion of your nodes based on the current distance travelled. Some branches of the search tree will expand faster than others, because the manage to visit more nodes in the same amount of time.

    So if node expansion is not truly breath-first, why do I keep using that word? Because after you do find a solution, you must still expand the current set of "considered nodes" until each one of those search paths exceed the solution. This avoids missing a path which has a lot of time consuming initial legs, but finishes faster than the current solution because the last step is lighting fast.

提交回复
热议问题