BEE-TSP-Optimizer

A hybrid Python/C++/Matlab implementation of the Bee Algorithm for solving the Traveling Salesman Problem. Features interactive visualizations, performance optimizations, and customizable colony parameters to efficiently find near-optimal routes.

Overview

This project implements the Bee Colony Optimization algorithm as a metaheuristic solver for the classic Traveling Salesman Problem (TSP). Instead of using standard approaches like Branch and Bound or Dynamic Programming, I explored nature-inspired computing through the Bee Algorithm—a population-based search technique that mimics honeybee foraging behavior to efficiently navigate complex solution spaces.

The repository provides a complete ecosystem for TSP experimentation:

The hybrid approach allows for flexibility: rapid prototyping and interactive visualization in Python, with the option to scale to the C++ implementation for production use. Both implementations share the same algorithmic foundation but are optimized for their respective environments.

The solver features adaptive neighborhood search techniques (2-opt, swap operators) that balance exploration and exploitation through carefully tuned colony parameters. The visualization modules provide real-time feedback on the algorithm’s convergence progress, illustrating how different bee types (scouts, followers, elites) collaborate to find increasingly optimal tours.

Tech Stack

The project leverages several technologies to balance performance, flexibility, and visual feedback:

Getting Started

  1. Clone the repository:
    git clone https://github.com/Nicolas2912/BEE-TSP-Optimizer.git
    cd BEE-TSP-Optimizer
    
  2. Python setup:
    pip install -r requirements.txt
    
  3. C++ setup:
    cd cpp
    g++ main.cpp TSP.cpp Bee.cpp -std=c++17 -O3 -o bee_tsp
    

Usage

Python Implementation

python BeeAlgorithm.py \
    --ns 75 --nb 55 --ne 15 --nrb 25 --nre 25 \
    --routeLen 50 --iterations 100 \
    --visualize True --visualize_final True

Parameters explained:

C++ Implementation

  1. Compile:
    cd cpp
    g++ main.cpp TSP.cpp Bee.cpp -std=c++17 -O3 -o bee_tsp
    
  2. Run with default parameters:
    ./bee_tsp
    
  3. Or with custom parameters:
    ./bee_tsp 75 55 15 25 25 50 100
    

    (Parameters follow the same order as the Python implementation)

MATLAB Animation

Open MATLAB and run:

main

Set animate = true in the script to watch the colony explore the TSP landscape in real-time.

Architecture & Components

Core Modules:

Utilities:

Experimental Assets:

Testing:

Challenges & Solutions

Several technical challenges emerged during development:

What I Learned

Improvements I’d Like to Make

Here are enhancements planned for future iterations:

Screenshots

BeeTSPOptimizer_animation

View on GitHub