Prove the correctness and optimality of Dijkstra's algorithm for positive weighted graphs.
-
Model the positive weighted graph as a
MapofVertexto a list ofEdge(a.k.a. adjacency list).- Checklist: DONE. See the
GraphDefinitionsnamespace.
- Checklist: DONE. See the
-
Implement Dijkstra's algorithm to find the shortest paths from a source vertex to all other vertices in the graph.
- Checklist: DONE. See the
DijkstraUtilsandDijkstraAlgorithmnamespaces.
- Checklist: DONE. See the
-
Prove that:
- The algorithm terminates.
- Checklist: DONE. See the
termination_byanddecreasing_byannotations in thedijkstraAuxiliaryfunction.
- Checklist: DONE. See the
- The algorithm finds the shortest paths in the graph.
- Checklist: NOT DONE.
- The algorithm terminates.
-
(Optional) Prove that if a negative weight cycle exists in the graph, the correctness of the algorithm won't be guaranteed.
- Checklist: NOT DONE.
The code is organized into several namespaces (and a main function at the end).
-
The
GraphDefinitionsnamespace contains the data structures to represent the graph, including theVertex,Weight, andEdgetypes. -
The
DijkstraUtilsnamespace contains utility data structures and functions for Dijkstra's algorithm, including theFrontierandDistanceMaptypes. -
The
DijkstraAlgorithmnamespace contains the implementation of Dijkstra's algorithm, including thedijkstrafunction. -
The
Stuffsnamespace contains some example graphs to test the algorithm. -
The
mainfunction demonstrates how to use the graph and Dijkstra's algorithm.
To run the code, you can run the following command in the root directory of the project:
lean --run LEAN4DIJKSTRA/Graph.leanTo modify the graph, you can add your own generateGraphXX functions in the Stuffs namespace and call them in the main function, or modify the existing generateGraphXX functions.