Package: pathfinding
python-pathfindingPathfinding algorithms for python 3.Currently there are 7 path-finders bundled in this library, namely:A*DijkstraBest-FirstBi-directional A*Breadth First Search (BFS)Iterative Deeping A* (IDA*)Minimum Spanning Tree (MSP)Dijkstra and A* take the weight of the fields on the map into account.If you are still using python 2 take a look at the (unmaintained)python2-branch.InstallationThis library is provided by pypi, so you can just install the current stable version using pip:pipinstallpathfindingseepathfinding on pypiUsage examplesFor usage examples with detailed descriptions take a look at thedocsfolder, also take a look at thetest/folder for more examples, e.g. how to use pandasRerun the algorithmWhile running the pathfinding algorithm it might set values on the nodes. Depending on your path finding algorithm things like calculated distances or visited flags might be stored on them. So if you want to run the algorithm in a loop you need to clean the grid first (seeGrid.cleanup). Please note that because cleanup looks at all nodes of the grid it might be an operation that can take a bit of time!Implementation detailsAll pathfinding algorithms in this library are inheriting the Finder class. It has some common functionality that can be overwritten by the implementation of a path finding algorithm.The normal process works like this:You callfind_pathon one of your finder implementations.init_findinstantiates theopen_listand resets all values and counters.The main loop starts on theopen_list. This list gets filled with all nodes that will be processed next (e.g. all current neighbors that are walkable). For this you need to implementcheck_neighborsin your own finder implementation.For example in A*s implementation ofcheck_neighborsyou first want to get the next node closest from the current starting point from the open list. thenext_nodemethod in Finder does this by giving you the node with a minimumf-value from the open list, it closes it and removes it from theopen_list.if this node is not the end node we go on and get its neighbors by callingfind_neighbors. This just callsgrid.neighborsfor most algorithms.If none of the neighbors are the end node we want to process the neighbors to calculate their distances inprocess_nodeprocess_nodecalculates the costffrom the start to the current node using thecalc_costmethod and the cost after calculatinghfromapply_heuristic.finallyprocess_nodeupdates the open list sofind_pathcan runcheck_neighborson it in the next node in the next iteration of the main loop.flow:find_path
    init_find  # (re)set global values and open list
    check_neighbors  # for every node in open list
      next_node  # closest node to start in open list
      find_neighbors  # get neighbors
      process_node  # calculate new cost for neighboring nodeTestingYou can run the tests locally using pytest. Take a look at thetest-folderYou can follow below steps to setup your virtual environment and run the tests.# Go to repocdpython-pathfinding# Setup virtual env and activate it - Mac/Linux for windows use source venv/Scripts/activatepython3-mvenvvenvsourcevenv/bin/activate# Install test requirementspipinstall-rtest/requirements.txt# Run all the testspytestContributingPlease use theissue trackerto submit bug reports and feature requests. Please use merge requests as describedhereto add/adapt functionality.Licensepython-pathfinding is distributed under theMIT license.MaintainerAndreas Bresser,self@andreasbresser.deAuthors / ContributersAuthors and contributers arelisted on github.Inspired byPathfinding.JS