teachmedijkstra library in Python
Dijkstra’s algorithm is very similar to Prim’s algorithm for minimum spanning trees. Like Prim’s MST, we generate a SPT (shortest path tree) with a given source as root. We maintain two sets, one set contains vertices included in the shortest path tree, other set includes vertices not yet included in the shortest path tree. At every step of the algorithm, we find a vertex that is in the other set (set of not yet included) and has a minimum distance from the source.
teachmedijkstra: Utility library helping in rendering explained Dijkstra’s alogirithm in latex format for teaching purposes. The rows of the matrix represent vertex of graph and column represent each unit time step of explanation, gets the shortest path tree constructed for shortest distance algorithm.
This module does not come built-in with Python. To install it type the below command in the terminal.
pip install teachmedijkstra
After installation of the library, steps to proceed with are :
- Initializing the Undirected/Directed Graph
- Addition of Vertex and Edges to Graph
- Using Dijaskstra(), to input created graph with a starting point.
- run(), runs the algorithm.
- At the end, the latex file produced can be saved by the required name.
Function Used :
- teachmedijkstra.UndirectedGraph() : Initializes the graph with undirected Graph.
- graph.addVertex(name, coordinate) : Adds name of vertex along with graphical coordinate it should belong to.
- graph.addEdge(strt, end, weight) : Adds edge from 1 node to another with particular weight.
- teachmedijkstra.Dijkstra(graph_obj, strt_point) : Initializes the variable with graph instance with starting point.
- dijkstra.run() : Runs the dijkstra algorithm.
- dijkstra.saveToLaTeXFile(file_name) : Saves the constructed graph in file_name in latex format.
Produced Latex File :
Output ( After converting Latex ):
Example 2: Directed Graph
In this example, we will create a directed graph with this module.
Latex Output :
Please Login to comment...