|
| 1 | +======================= |
| 2 | +Path Finding Algorithms |
| 3 | +======================= |
| 4 | + |
| 5 | +Some pathfinding algorithms and their implementations |
| 6 | + |
| 7 | +Quick Start Guide |
| 8 | +----------------- |
| 9 | + |
| 10 | +.. code-block:: python |
| 11 | +
|
| 12 | + # import the required pathing algorithm |
| 13 | + from pygorithm.pathing import dijkstra |
| 14 | +
|
| 15 | + # import a graph data structure |
| 16 | + from pygorithm.data_structures import graph |
| 17 | +
|
| 18 | + # initialize the graph with nodes from (0, 0) to (4, 4) |
| 19 | + # with weight corresponding to distance (orthogonal |
| 20 | + # is 1, diagonal is sqrt(2)) |
| 21 | + my_graph = graph.WeightedUndirectedGraph() |
| 22 | + my_graph.gridify(5, 1) |
| 23 | +
|
| 24 | + # make the graph more interesting by removing along the |
| 25 | + # x=2 column except for (2,4) |
| 26 | + my_graph.remove_edge((2, 0)) |
| 27 | + my_graph.remove_edge((2, 1)) |
| 28 | + my_graph.remove_edge((2, 2)) |
| 29 | + my_graph.remove_edge((2, 3)) |
| 30 | +
|
| 31 | + # calculate a path |
| 32 | + my_path = dijkstra.find_path(my_graph, (0, 0), (3, 0)) |
| 33 | +
|
| 34 | + # print path |
| 35 | + print(' -> '.join(my_path)) |
| 36 | + # (0, 0) -> (1, 1) -> (0, 2) -> (1, 3) -> (2, 4) -> (3, 3) -> (3, 2) -> (3, 1) -> (3, 0) |
| 37 | +
|
| 38 | +Features |
| 39 | +-------- |
| 40 | + |
| 41 | +* Algorithms available: |
| 42 | + - Dijkstra (dijkstra) |
| 43 | + |
| 44 | + |
| 45 | +* To see all the available functions in a module there is a `modules()` function available. For example, |
| 46 | + |
| 47 | +.. code:: python |
| 48 | +
|
| 49 | + >>> from pygorithm.pathfinding import modules |
| 50 | + >>> modules.modules() |
| 51 | + ['dijkstra'] |
| 52 | +
|
| 53 | +* Get the code used for any of the algorithm |
| 54 | + |
| 55 | +.. code-block:: python |
| 56 | +
|
| 57 | + from pygorithm.pathing import dijkstra |
| 58 | +
|
| 59 | + # for printing the source code of Dijkstra object |
| 60 | + print(dijkstra.Dijikstra.get_code()) |
| 61 | +
|
| 62 | +Dijkstra |
| 63 | +-------- |
| 64 | + |
| 65 | +* Functions and their uses |
| 66 | + |
| 67 | +.. function:: dijkstra.find_path(pygorithm.data_structures.WeightedUndirectedGraph, vertex, vertex) |
| 68 | + |
| 69 | +- **pygorithm.data_structures.WeightedUndirectedGraph** : acts like an object with `graph` (see WeightedUndirectedGraph) |
| 70 | +- **vertex** : any hashable type for the start of the path |
| 71 | +- **vertex** : any hashable type for the end of the path |
| 72 | +- **Return Value** : returns a `List` of vertexes (of the same type as the graph) starting with from and going to to. This algorithm does *not* respect weights. |
| 73 | + |
| 74 | +.. function:: dijkstra.get_code() |
| 75 | + |
| 76 | +- **Return Value** : returns the code for the ``Dijkstra`` object |
0 commit comments