Skip to content

This repository contains Python implementations of the Simulated Annealing optimization algorithm. It includes two Colab notebooks — one that evaluates Simulated Annealing across 55 benchmark functions and another that focuses on a single test function (Ackley) — along with sample result files and documentation.

License

Notifications You must be signed in to change notification settings

ak-rahul/Simulated-Annealing

Repository files navigation

🔥 Simulated Annealing

A robust implementation of the Simulated Annealing algorithm benchmarked against 55+ optimization test functions using the optimization-benchmarks package.

License: MIT Python 3.7+ NumPy

📖 Overview

This repository contains a production-ready implementation of the Simulated Annealing metaheuristic algorithm with comprehensive benchmarking capabilities. The implementation features adaptive cooling, multiple restart strategies, and robust boundary handling.

✨ Features

  • Robust Implementation: Handles multiple bound formats and edge cases
  • Adaptive Cooling: Dynamic cooling rate adjustment based on acceptance ratio
  • Multiple Restarts: 5 restart strategies for improved global search
  • Comprehensive Benchmarking: Tested against 55 optimization functions
  • Single Function Analysis: Detailed statistical analysis with 30 independent trials
  • Production Ready: Error handling, type conversion, and boundary management

⚙️ Algorithm Details

Core Parameters

  • Initial Temperature: 100.0
  • Cooling Rate: 0.99 (adaptive: 0.98-0.995)
  • Max Iterations: 20,000 per restart
  • Restart Strategies: 5 (center, near-center, random, lower-biased, upper-biased)

Key Features

  • Temperature-dependent step size adaptation
  • Metropolis acceptance criterion
  • Adaptive cooling based on acceptance ratio
  • Boundary clipping for constraint handling
  • Scalar conversion for NumPy compatibility

📊 Benchmark Results

Complete Suite Performance

Metric Value
Total Functions 55
Successfully Converged 41/55 (74.5%)
Perfect Solutions 27 functions (error = 0)
Median Error 0.000279
Average Time 0.82s per function

Single Function Performance (Ackley)

Metric Value
Success Rate 100% (30/30 trials)
Mean Error 0.0
Std Dev Error 0.0
Average Time 0.66s per trial

🚀 Installation

  1. Clone repository locally:
git clone https://github.com/ak-rahul/Simulated-Annealing.git
cd Simulated-Annealing
  1. Upload to Google Colab:
  • Go to Google Colab
  • Click FileUpload notebook
  • Select either:
    • Simulated-Annealing.ipynb (single function)
    • Simulated-Annealing-with-Complete-Benchmarks.ipynb (all functions)
  1. Run in Colab:
  • The notebook will automatically install optimization-benchmarks
  • Click RuntimeRun all
  • Results will be saved to Colab's /content/ directory

📓 Notebooks

1. Simulated-Annealing.ipynb

Single function benchmark with detailed analysis:

  • 30 independent trials
  • Statistical summary (mean, median, std dev)
  • Individual trial results
  • CSV export with metadata

2. Simulated-Annealing-with-Complete-Benchmarks.ipynb

Complete suite benchmark across all 55 functions:

  • Per-function results with timing
  • Success rate analysis
  • Top 5 best/worst performers
  • Comprehensive CSV export

🎯 Test Functions

The implementation is tested against diverse optimization landscapes:

Multimodal: Ackley, Rastrigin, Griewank, Schwefel, Levy, Michalewicz

Unimodal: Sphere, Rosenbrock, Sum Squares, Hyperellipsoid

2D Specialized: Beale, Booth, Himmelblau, Goldstein-Price, Branin, Camel

Special Cases: Eggholder, Kowalik, Langermann, Box-Betts

💪 Algorithm Strengths

  • Exploration: Multiple restart strategies prevent local optima
  • Exploitation: Adaptive cooling balances search intensity
  • Robustness: Handles diverse function landscapes effectively
  • Efficiency: Fast convergence on smooth landscapes

📦 Requirements

  • Python 3.7+
  • NumPy >= 1.20.0
  • optimization-benchmarks == 0.1.1

📄 License

MIT License - see LICENSE.md for details.

🙏 Acknowledgments

  • Built using the optimization-benchmarks package
  • Inspired by classical SA implementations and modern optimization research

About

This repository contains Python implementations of the Simulated Annealing optimization algorithm. It includes two Colab notebooks — one that evaluates Simulated Annealing across 55 benchmark functions and another that focuses on a single test function (Ackley) — along with sample result files and documentation.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published