A collection of Traveling Salesman Problem (TSP) algorithm implementations for performance comparison and analysis.
This repository contains implementations of four different TSP algorithms:
- Branch and Bound - Exact algorithm using branch and bound technique
- Genetic Algorithm - Evolutionary algorithm approach
- Held-Karp - Dynamic programming exact algorithm
- Simulated Annealing - Metaheuristic optimization algorithm
tsp-playground/
├── tsp-branch-and-bound/
├── tsp-genetic-algorithm/
├── tsp-held-karp/
├── tsp-simulated-annealing/
└── README.md
- C/C++ compiler (gcc/g++)
- Make utility
- Standard C/C++ libraries
Each algorithm is contained in its own directory and can be run independently. Follow these steps for any algorithm:
cd tsp-branch-and-bound # For Branch and Bound
# OR
cd tsp-genetic-algorithm # For Genetic Algorithm
# OR
cd tsp-held-karp # For Held-Karp
# OR
cd tsp-simulated-annealing # For Simulated AnnealingmakeThis will create an executable in the bin/ directory.
./bin/mainEach algorithm can be configured using the settings.ini file located in the respective algorithm directory.
You can tweak the following settings in settings.ini:
- random_instance_test: Generate random TSP instances
- File Instance Mode: Use predefined TSP instance files
Example settings.ini:
;mode = file_instance_test
mode = random_instance_test
;Configure minimum node and max node
[random_instance_test]
min_size = 3
max_size = 23gcc GA_TSP_Serial_Random.c -o gatsp -lmThis will create an executable gatsp in root directory.
./gatsp instance_mode./gatspUpdate this file for min and max nodes for which you want to run random instance test
./tsp-playground/tsp-genetic-algorithm/GA_TSP_Serial_Random.c
Example GA_TSP_Serial_Random.c:
#define MIN_NODES 5
#define MAX_NODES 30- Type: Exact algorithm
- Best for: Small to medium instances (< 20 vertices)
- Time Complexity: Exponential (worst case)
- Type: Evolutionary metaheuristic
- Best for: Large instances where approximate solutions are acceptable
- Customizable: Population size, mutation rate, crossover rate
- Type: Dynamic programming exact algorithm
- Best for: Small instances (< 15 vertices due to memory constraints)
- Time Complexity: O(n²2ⁿ)
- Type: Metaheuristic optimization
- Best for: Large instances with good quality approximate solutions
- Customizable: Temperature schedule, cooling rate
Each algorithm outputs:
- Execution time
- Best distance found
- Gap percentage (if optimal is known)
- Convergence information
To clean compiled files in any algorithm directory:
make cleanThis project is for educational and research purposes.