Genetic Algorithm for Shortest Path:
Genetic algorithm to find the shortest path between 2 nodes in a graph. The solution below (second image) was obtained over 400 iterations on a 100 node graph with a population size of 30 and 5% mutation rate. The optimal solution is found using Dijkstra's algorithm (first image). Different random initialisations for the GA led to different results, as expected.
Run using ShortestPathGA/testing.py
and visualised using NetworkX and Gephi.
Optimal shortest path (by Dijkstra) Cost: 1.156
Genetic Algorithm Cost: 1.562
Dijkstra vs. Genetic Algorithm
Usage:
- Run
pip install requirements.txt
- Run
main()
in the testing.py files with the required hyperparameters.