Graphs and Dijkstra's algorithm by Charawi Detphumi
Project description
ShabiiNetwork is a Python library for dealing with Graphs and Dijkstra’s algorithm.
Installation
Use the package manager pip to install ShabiiNetwork.
pip install ShabiiNetwork
Usage
from ShabiiNetwork import Digraph,Dijkstra
graph2 = Digraph()
#To check add_edge and add_edges functions
graph2.add_edges([('A','B',0.3),('A','C',0.5),
('B','A',0.3),('B','C',0.9),
('C','A',0.5),('C','D',1.2),
('D','C',1.2)])
print(graph2.Edict)
graph2.add_edges([('A','D',45),('A','E',23)])
print(graph2.Edict)
#To check remove_edge and remove_edges functions
graph2.remove_edges([('A','D'),('A','E')])
print(graph2.Edict)
#To check add_vertex and add_vertices functions
graph2.add_vertices(['I','J','K'])
print(graph2.Edict)
#To check remove_vertex and remove_vertices functions
graph2.remove_vertices(['I','J','K'])
print(graph2.Edict)
#To check Dijkstra class and its functions
dijkstra = Dijkstra(graph2, start_vertex='A')
dijkstra.dijkstra()
dijkstra.print_result()
"""
Output:
{'A': {'B': 0.3, 'C': 0.5}, 'B': {'A': 0.3, 'C': 0.9}, 'C': {'A': 0.5, 'D': 1.2}, 'D': {'C': 1.2}}
{'A': {'B': 0.3, 'C': 0.5, 'D': 45, 'E': 23}, 'B': {'A': 0.3, 'C': 0.9}, 'C': {'A': 0.5, 'D': 1.2}, 'D': {'C': 1.2}}
{'A': {'B': 0.3, 'C': 0.5}, 'B': {'A': 0.3, 'C': 0.9}, 'C': {'A': 0.5, 'D': 1.2}, 'D': {'C': 1.2}}
{'A': {'B': 0.3, 'C': 0.5}, 'B': {'A': 0.3, 'C': 0.9}, 'C': {'A': 0.5, 'D': 1.2}, 'D': {'C': 1.2}, 'I': {}, 'J': {}, 'K': {}}
{'A': {'B': 0.3, 'C': 0.5}, 'B': {'A': 0.3, 'C': 0.9}, 'C': {'A': 0.5, 'D': 1.2}, 'D': {'C': 1.2}}
A -> A: ['A'] distance: 0
A -> B: ['A', 'B'] distance: 0.3
A -> C: ['A', 'C'] distance: 0.5
A -> D: ['A', 'C', 'D'] distance: 1.7
"""
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
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
ShabiiNetwork-0.0.1.tar.gz
(4.3 kB
view details)
File details
Details for the file ShabiiNetwork-0.0.1.tar.gz
.
File metadata
- Download URL: ShabiiNetwork-0.0.1.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32879bdc5edd332f7f47d86cf07f9b63485f4441f3ba29ad2d84603ba35e1030 |
|
MD5 | 04705b574d8ad454b1b15e87f29ce603 |
|
BLAKE2b-256 | 544ea73d939eaf0032cdc0171108ad3f89853c474d5bb38091b31b9f83e6dae6 |