sid-sr / Shortest-Path-Genetic-Algorithm

Genetic algorithm implementation for a graph problem.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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:


  1. Run pip install requirements.txt
  2. Run main() in the testing.py files with the required hyperparameters.

About

Genetic algorithm implementation for a graph problem.


Languages

Language:Python 100.0%