This repository is a heuristic algorithm project designed for teaching and classroom demonstrations. Each algorithm is provided as an independent Jupyter Notebook, with emphasis on three things:
- The underlying idea should be explained clearly.
- The experiments should run successfully.
- The visualizations should be intuitive enough for teaching.
The project is suitable for:
- classroom instruction
- introductory algorithm lab courses
- self-study for heuristic algorithms
- talks, lectures, or teaching demos
The project currently includes 12 core heuristic algorithm notebooks. Directories are numbered so they can be taught in a natural sequence.
.
├── PRD_Heuristic_Algorithms.md
├── README.md
├── pyproject.toml
├── 01_Hill_Climbing/
├── 02_Random_Restart_Hill_Climbing/
├── 03_Simulated_Annealing/
├── 04_Tabu_Search/
├── 05_Genetic_Algorithm/
├── 06_Evolution_Strategy/
├── 07_Differential_Evolution/
├── 08_Particle_Swarm_Optimization/
├── 09_Ant_Colony_Optimization/
├── 10_Artificial_Bee_Colony/
├── 11_GRASP/
└── 12_Iterated_Local_Search/
01_Hill_ClimbingHill Climbing Classic example: Himmelblau function02_Random_Restart_Hill_ClimbingRandom Restart Hill Climbing Classic example: Rastrigin function06_Evolution_StrategyEvolution Strategy Classic example: Rosenbrock function07_Differential_EvolutionDifferential Evolution Classic example: Ackley function08_Particle_Swarm_OptimizationParticle Swarm Optimization Classic example: Himmelblau function10_Artificial_Bee_ColonyArtificial Bee Colony Classic example: Ackley function
03_Simulated_AnnealingSimulated Annealing Classic example: TSP04_Tabu_SearchTabu Search Classic example: TSP05_Genetic_AlgorithmGenetic Algorithm Classic example: TSP09_Ant_Colony_OptimizationAnt Colony Optimization Classic example: TSP11_GRASPGreedy Randomized Adaptive Search Procedure Classic example: TSP12_Iterated_Local_SearchIterated Local Search Classic example: TSP
Most notebooks follow the same teaching structure:
- Learning objectives
- Why this classic example was chosen
- Algorithm intuition
- From-scratch implementation
- Single-run demonstration
- Visualization of results
- Statistics over multiple runs
- Parameter sensitivity analysis
- Classroom summary
The purpose is to let students switch between algorithms without having to adapt to a new reading pattern each time.
Python 3.11 or later is recommended.
If you use a toolchain that supports pyproject.toml, you can install dependencies from it directly.
For example, with pip:
pip install -e .Or install the core dependencies directly:
pip install numpy pandas matplotlib seaborn jupyter nbconvert nbformat ipykerneljupyter notebookor:
jupyter labIf you plan to use this for teaching, the following order is recommended because it builds algorithm intuition more naturally:
01_Hill_Climbing02_Random_Restart_Hill_Climbing03_Simulated_Annealing04_Tabu_Search05_Genetic_Algorithm08_Particle_Swarm_Optimization09_Ant_Colony_Optimization06_Evolution_Strategy07_Differential_Evolution10_Artificial_Bee_Colony11_GRASP12_Iterated_Local_Search
The logic behind this order is:
- start with the most intuitive local search methods
- then move to strategies that can escape local optima
- transition into population-based and swarm-intelligence methods
- finish with constructive and iterative-improvement approaches
If you are using these notebooks for a course or lecture, each notebook should at least address the following questions:
- What is the algorithm's core search move?
- Why can it improve the current solution?
- Why can it fail?
- How does it balance exploration and exploitation?
- Which parameter matters most, and what does it control?
For continuous optimization notebooks, it is recommended to pay special attention to:
- search trajectories on contour plots
- how the population distribution evolves
- the rate at which convergence curves decrease
For TSP notebooks, it is recommended to pay special attention to:
- the difference between the initial route and the final route
- how route structure changes during the process
- how different algorithms generate new candidate routes
The charts in this project are designed to explain clearly rather than simply look attractive. As a result, most notebooks include at least:
- a convergence curve
- a search-process figure
- a final-result figure
Some algorithms also include targeted visualizations:
- PSO: particle position evolution
- ACO: pheromone heatmap
- GA: population distribution or fitness distribution
- SA: acceptance rate changes
- GRASP / ILS: before-and-after comparisons for construction or perturbation
- Project-level design document: PRD_Heuristic_Algorithms.md
This material currently prioritizes teaching clarity. The implementations are designed to be readable in class rather than packaged as industrial-grade high-performance code. Possible future extensions include:
- more benchmark functions
- more complex TSP datasets
- animated visualizations
- interactive parameter controls
- a unified export set for lecture slides