A package containing an implementation for a priority queue algorithm and dijkstra's algorithm.
Project description
graphs_mcsteestu: Dijkstra's Shortest Path Algorithm in Python
A Python library for running Dijkstra's shortest path algorithm on weighted graphs with non-negative weights. This project uses a priority queue algorithm to implement Dijkstra's shortest path algorithm.
How to install the graphs_mcsteestu library
pip3 install graphs_mcsteestu
How to use the graphs_mcsteestu library
Import the package into your Python file
from graphs_mcsteestu import sp
Example Python file and library usage
Test File test.py :
from graphs_mcsteestu import sp
import sys
if __name__ == '__main__':
if len(sys.argv) != 2:
print(f'Use: {sys.argv[0]} graph_file')
sys.exit(1)
graph = {}
with open(sys.argv[1], 'rt') as f:
f.readline() # skip first line
for line in f:
line = line.strip()
s, d, w = line.split()
s = int(s)
d = int(d)
w = int(w)
if s not in graph:
graph[s] = {}
graph[s][d] = w
print("Dijkstra's Shortest Path Algorithm")
s = 0
dist, path = sp.dijkstra(graph, s)
print(f'Shortest distances from {s}:')
print(dist)
for d in path:
print(f'spf to {d}: {path[d]}')
Command:
python3 test.py GraphNodes.txt
Credits
- Dr. Mota for providing the code for implementing Dijkstra's algorithm.
- Kevin O'Connor, Tim Peters, and Raymond Hettinger for providing the code implementing the heap queue algorithm in python.
License
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file graphs_mcsteestu-0.0.2.tar.gz.
File metadata
- Download URL: graphs_mcsteestu-0.0.2.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b1092b0a8ef62a82409e2b27fa3c7a0fe378ac3ac70d931224ccb53dd5480842
|
|
| MD5 |
8347ec6e2ae985d5806da0ced8775c15
|
|
| BLAKE2b-256 |
2c37d6781eb3fd77616de21e59d7beef197b37d754b1ae0e59e87b035cb35f9d
|
File details
Details for the file graphs_mcsteestu-0.0.2-py3-none-any.whl.
File metadata
- Download URL: graphs_mcsteestu-0.0.2-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5c2bb340640b42ec009ace971aa8e03da90ba0859f0df279ea4f345b8763591
|
|
| MD5 |
d379bce2ff1a4b9910565e6bc5f2dff3
|
|
| BLAKE2b-256 |
d65e282d4a9151c28a4c0083a0040d3bf40e8532ab4855de0b1d85be663d5645
|