
A high-performance Rust library for local search optimization algorithms (metaheuristics). Built with parallel execution using Rayon and a flexible trait-based design for implementing custom optimization problems.
Features
This library implements 13+ local search optimization algorithms, all parallelized with Rayon:
Local Search Algorithms
- Random Search - Baseline random sampling method
- Hill Climbing - Deterministic greedy ascent
- Epsilon-Greedy - Probabilistic acceptance of worse solutions
- Metropolis - MCMC method with fixed temperature
- Tabu Search - Memory-based search with forbidden move lists
- Great Deluge - Threshold-based acceptance with decreasing water levels
Simulated Annealing Variants
- Simulated Annealing - Classic temperature-based acceptance with cooling schedules
- Adaptive Annealing - Dynamic temperature adaptation to target acceptance rates
- Logistic Annealing - Relative score differences with logistic acceptance curves
- Relative Annealing - Exponential acceptance based on relative score changes
- Tsallis Relative Annealing - Generalized acceptance using Tsallis statistics
Population-Based Methods
- Population Annealing - Parallel simulated annealing with population resampling
- Parallel Tempering - Multiple chains at different temperatures with replica exchange
Installation
Add this to your Cargo.toml:
[]
= "0.24.0"
Requires Rust 1.92 or later.
Quick Start
Implement the OptModel trait for your problem and choose an optimizer. Here's a quadratic function minimization example:
use Duration;
use ;
use NotNan;
use Uniform;
type SolutionType = ;
type ScoreType = ;
// Usage
let model = new;
let opt = new;
let = opt
.run
.unwrap;
Advanced Examples
Traveling Salesman Problem
The examples/tsp_model.rs demonstrates solving TSP using multiple algorithms with custom tabu lists and progress callbacks. It reads city coordinates from a file and compares performance against optimal routes.
Key features shown:
- Custom
TabuListimplementation for move prohibition - Parallel optimizer comparison (Hill Climbing, Simulated Annealing, Tabu Search, etc.)
- Progress bars with acceptance ratio monitoring
- Optimal route validation
Additional Capabilities
You can also add preprocess_solution and postprocess_solution to your model for setup and result formatting. See the examples for complete implementations.
API Documentation
- API Reference - Complete generated documentation
- API Design - Detailed trait and method documentation
- Algorithm Reference - In-depth algorithm descriptions and parameters
Contributing
Contributions are welcome! Please follow these guidelines:
- Follow the repository conventions for code style and documentation
- Ensure all public items have documentation (enforced by
#![forbid(missing_docs)]) - Run pre-commit checks:
cargo fmt,cargo clippy,cargo test - Add tests for new functionality
Report issues and feature requests at: GitHub Issues
Development
Setup
Clone and build:
Development Workflow
After making changes, verify code correctness in this order:
cargo check -q— Ensure code compiles without errorscargo test -q— Execute all tests and ensure correctnesscargo clippy -q --fix --allow-dirty— Automatically fix lint issuescargo clippy -q -- -D warnings— Ensure no lint warnings remain
Tip: Run cargo fmt before committing to ensure consistent formatting. For manual formatting, use nightly fmt: cargo +nightly fmt.
Code Standards
- Module Layout: Use
src/x.rsandsrc/x/for submodules. Never usemod.rs. - Testing: Place integration tests in
src/(not a top-leveltests/folder) - Documentation: All public items must have documentation (enforced by
#![forbid(missing_docs)]) - Safety: Avoid
.unwrap()without a safety comment
See AGENTS.md for full conventions.
Running Examples
# TSP example (requires city coordinates file)
# Usage: cargo run --example tsp_model -- <cities_file> [optimal_route_file]
# Compare against optimal route (optional)
# Run all examples
Performance & Compatibility
- Parallel Execution: All algorithms leverage Rayon for CPU-parallel candidate evaluation
- Thread Safety: All types implement
Sync + Sendfor concurrent use - WASM Support: Conditional compilation available for web targets
- Rust Version: Requires Rust 1.92+
License
Licensed under the Apache License, Version 2.0. See LICENSE for details.