Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alek-dr/graphlib
Graph library
https://github.com/alek-dr/graphlib
bellman-ford-algorithm bfs-algorithm dfs dijkstra-algorithm graph graph-algorithms graphs shortest-paths topological-sort
Last synced: about 4 hours ago
JSON representation
Graph library
- Host: GitHub
- URL: https://github.com/alek-dr/graphlib
- Owner: Alek-dr
- Created: 2019-10-18T12:43:54.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-04-03T15:20:20.000Z (7 months ago)
- Last Synced: 2024-05-03T03:58:45.447Z (6 months ago)
- Topics: bellman-ford-algorithm, bfs-algorithm, dfs, dijkstra-algorithm, graph, graph-algorithms, graphs, shortest-paths, topological-sort
- Language: Python
- Homepage:
- Size: 250 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# GraphLib
Graph library
Implementation of different graph algorithms and representations.
Minimalistic pure-python graph algorithms implementation
Implemented algoritms:
* DFS
* BFS
* Dijkstra
* Bellman-Ford
* Topological sortExample:
Find shortest paths for given graph from vertex S:
![alt text](tests/graph_images/graph_2.png)
```
from core.algorithms import dijkstra
from core.graphs import create_graph, Nodedef create_test_graph():
graph = create_graph(directed=True)
nodeS = Node("S")
nodeB = Node("B")
nodeD = Node("D")
nodeE = Node("E")
nodeC = Node("C")
nodeF = Node("F")graph.add_node(nodeS)
graph.add_node(nodeB)
graph.add_node(nodeD)
graph.add_node(nodeE)
graph.add_node(nodeC)
graph.add_node(nodeF)graph.add_edge("S", "B")
graph.add_edge("S", "D")
graph.add_edge("B", "E")
graph.add_edge("D", "E")
graph.add_edge("B", "C")
graph.add_edge("D", "F")
graph.add_edge("C", "F")
return graphif __name__ == '__main__':
graph = create_test_graph()
walks = dijkstra(graph, "S")
for v, w in walks.items():
print(f"{v}: {w}\tweight: {w.weight}")
```
Output:
```
E: S -> (a) -> B -> (c) -> E weight: 2
F: S -> (b) -> D -> (f) -> F weight: 2
C: S -> (a) -> B -> (e) -> C weight: 2
B: S -> (a) -> B weight: 1
D: S -> (b) -> D weight: 1
S: S weight: 0
```# Dependencies
https://graphviz.org/download/Graphviz
```
sudo apt install graphviz
```