This is my student project, the task of which is to learn how to visualize algorithms on graphs.
In this work, I have animated the work of DFS and BFS.
To work with graphs, I used the networkx
package and the matplotlib
and celluloid
packages to create a .gif file.
Documentation hosted on free documentation hosting Read the docs
It's require to install third-party dependencies. For this write in the python console.
pip install -r requirements
First of all it is necessary to fill the text file with adjacency lists.
NB: The file should contain only lines of the form: node1: node2, node3...
For example the content of the file located in "../input/graph.txt" the demo and default for the main function.
A: B, C
B: D, E
C: F, G
D: H
E: I, J
Then it is enough to call the main function with the required argument start
- node from which the search will start.
Optionally, it is possible to specify a text file with a graph, the algorithm to be animated and the directory in which you want to save the file.
The default arguments are "../input/graph.txt", depth-first search, "../output/".
from src.main import main
main(start='A', algorithm='bfs')
Or by running in the console:
python main.py A -algo bfs
python main.py -h
Result:
And for:
from src.main import main
main(start='A', algorithm='dfs')
Or by running in the console:
python main.py A -algo dfs
- Email: danilov.na@edu.spbstu.ru
- Telegram: @dannik0103