Category: Optimization
Status: ✅ Complete
Language: Python
Implementation of a genetic algorithm (evolutionary computation) to solve the Traveling Salesman Problem (TSP). Demonstrates meta-heuristic optimization for NP-hard combinatorial problems.
Find the shortest route visiting all cities exactly once and returning to the start:
- Classical NP-hard problem
- Brute force infeasible for >20 cities
- Meta-heuristics provide good solutions in reasonable time
- Population: Random initial tours
- Selection: Tournament selection (fittest individuals survive)
- Crossover: Combine parent tours to create offspring
- Mutation: Random changes to prevent convergence
- Iteration: Repeat until convergence
- Population size: 100-500
- Generations: Configurable (typically 1000+)
- Crossover rate: 0.8
- Mutation rate: 0.01-0.1
- Convergence: Monitor fitness over generations
- 100 cities: Solution within 3-5% of optimal
- 500 cities: Solution within 8-10% of optimal
- Convergence time: Seconds to minutes (depends on config)
| Method | Time | Quality | Scalability |
|---|---|---|---|
| Brute Force | Exponential | Optimal | Poor |
| Nearest Neighbor | Fast | 20-30% | Good |
| GA | Moderate | 3-8% | Excellent |
| Simulated Annealing | Slow | 2-5% | Good |
- Logistics & route optimization
- Manufacturing (job scheduling)
- Telecommunications (network design)
- Drone delivery path planning
- Encoding: Permutation (tour sequence)
- Fitness: Inverse of total distance
- Parent selection: Tournament (k=3)
- Crossover: Order-1 (OX) crossover
- Mutation: Swap or reverse segments
genetic_algorithm_tsp.py- Main GA implementationtsp_analysis.ipynb- Performance analysis and visualizationbenchmark.py- Comparison with other algorithms
from genetic_algorithm_tsp import GeneticAlgorithmTSP
ga = GeneticAlgorithmTSP(cities, population_size=200, generations=1000)
best_tour, best_distance = ga.solve()
ga.plot_convergence()Full analysis in tsp_analysis.ipynb