This repository contains the source code for the scientific article "A Hybrid of Bees Algorithm and Genetic Algorithm for the Traveling Salesman Problem" (the full text is available in the included PDF file).
The project introduces a novel hybrid metaheuristic approach and evaluates its performance against the standard Bees Algorithm (BA) and Genetic Algorithm (GA) in solving the Traveling Salesperson Problem (TSP). To achieve optimal routing, the solvers implement specialized evolutionary and swarm mechanics—including tournament selection, ordered crossover, partial shuffle mutation, and a 2-opt local search heuristic. The engine natively supports the TSPLIB benchmark standard, automatically parsing Euclidean (EUC_2D) node coordinates to construct exact distance matrices for fitness evaluation.
- C++: Core logic and object-oriented architecture.
- STL (Standard Template Library): Utilized for data management via
std::vectorand algorithm timing via<chrono>. - Mersenne Twister (MT19937): High-quality pseudo-random number generation for genetic diversity and population initialization.
The project requires a compiler that supports C++11 or higher. Example datasets are located in the /data folder; all instances are from the TSPLIB benchmark library.
Inside main.cpp, you can adjust the algorithms' parameters and your preferred problem instance. The Result class will execute the algorithms across multiple seeds and output the average runtime and fitness for each metaheuristic.
cmake -B build -G "Ninja"
cmake --build build.\build\TSPOptimizationComparison.exe├── include/
│ ├── ProblemLoader.h # Parser: header for TSP file parsing functions/classes
│ ├── ProblemData.h # Data Model: header for coordinate storage and distance matrix interface
│ ├── Result.h # Benchmark Engine: header for execution management and statistics averaging
│ ├── GeneticAlgorithm.h # GA Engine: header for population loop, selection, crossover, and mutation
│ ├── BeesAlgorithm.h # BA Engine: header for site management and neighborhood search
│ ├── HybridAlgorithm.h # HA Engine: header for swarm intelligence and crossover hybridization
│ ├── Individual.h # Solution Model: header for routes, crossovers, mutations, and 2-opt
│ └── Evaluator.h # Fitness Function: header for route evaluation logic
└── src/
├── main.cpp # Entry point: sets parameters and triggers the Result class
├── ProblemLoader.cpp # Parser: reads .tsp files and parses DIMENSION and NODE_COORD_SECTION
├── ProblemData.cpp # Data Model: stores coordinates and computes the distance matrix
├── Result.cpp # Benchmark Engine: runs algorithms across multiple seeds and averages time/fitness
├── GeneticAlgorithm.cpp# GA Engine: manages the population loop using selection, crossover, and mutation
├── BeesAlgorithm.cpp # BA Engine: manages elite/selected sites and neighborhood searches
├── HybridAlgorithm.cpp # HA Engine: combines swarm intelligence site searching with evolutionary crossover
├── Individual.cpp # Solution Model: handles genotypes (routes), ordered crossover, partial shuffle mutation, and 2-opt
└── Evaluator.cpp # Fitness Function: calculates the total travel cost for a given route sequence