path finding algorithms in python
Project description
PathFind
Implementation of path finding algorithms including:
- Depth-First Search (DFS)
- Breadth-First Search (BFS)
- Dijkstra Search
- Greedy Best-First Search
- A* Search
Install
pip install pathfind
Usage
Define a graph to transform graph from a matrix, then find a path from start point to end point.
import pathfind
m = [
[1, 1, 1, 1, 1],
[1, 2, -1, 1, 1],
[1, 1, 1, 1, 1],
[8, 3, 1, 1, 1],
[1, 1, 1, 1, 1],
]
graph = pathfind.transform.matrix2graph(m)
path = pathfind.find(graph, start="4,0", end="0,0")
# ['4,0', '4,1', '3,1', '2,1', '2,0', '1,0', '0,0']
graph.plot(trace=path)
Finder can be changed by passing a string method ("a*", "bfs", "greedy", "dijkstra", "dfs").
path = pathfind.find(graph, start="4,0", end="0,0", method="bfs")
# ['2,2', '2,1', '1,1', '0,1', '0,2']
graph.plot(trace=path)
Set graph by hand.
conf = [
["n1", "n2", 0.1],
["n1", "n3", 0.2],
["n2", "n3", 0.3]
]
graph = pathfind.Graph(conf)
graph.plot()
Or you can set edge's and node's details by following way:
n1 = pathfind.Node()
n2 = pathfind.Node()
n3 = pathfind.Node()
e1 = pathfind.Edge(node1=n1, node2=n2, weight=0.2)
e2 = pathfind.Edge(node1=n1, node2=n3, weight=0.1)
e3 = pathfind.Edge(n2, n3, weight=0)
g = pathfind.Graph()
g.add_edges([e1, e2, e3])
g.edges
"""
{'n0:n1': n0:n1, 'n0:n2': n0:n2, 'n1:n2': n1:n2}
"""
More examples
More examples and usages can be found in test
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pathfind-0.0.3.tar.gz
(8.3 kB
view details)
Built Distribution
pathfind-0.0.3-py3-none-any.whl
(11.5 kB
view details)
File details
Details for the file pathfind-0.0.3.tar.gz
.
File metadata
- Download URL: pathfind-0.0.3.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b62a25b92792ab233a377185ecbac58b66cd322daedebe82082efd5bf1625014 |
|
MD5 | 807f36486c9cf6bc6b3dd08ecb90d643 |
|
BLAKE2b-256 | c6f51138f4c37d38935590ea0b3cf35a2ec6d102c1510a9733595bc4f9a557d1 |
File details
Details for the file pathfind-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: pathfind-0.0.3-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c99c721b591294b1f6327250764e4a09d451eedf061c1c3e8f15cd069270e24d |
|
MD5 | 1cd2120304cb3fb0e1d4b43a903b6e1f |
|
BLAKE2b-256 | 59cb936cbc8e6c08eeb154ae6871c4c2000b8b66ae5f1384d2722416e2dda0c7 |