A Pythonic toolkit for Ant Colony, Particle Swarm, and Bee Colony optimization — written in Rust for high performance, designed for real-world use.
Project description
colonyx
colonyx is a Python library for solving optimization problems using swarm intelligence algorithms like Ant Colony Optimization (ACO), Particle Swarm Optimization (PSO), Artificial Bee Colony (ABC), Grey Wolf Optimization (GWO), Firefly (FA), Simulated Annealing (SA), Cuckoo Search (CS), Bat Algorithm (BA), Glowworm Swarm Optimization (GSO), Bacterial Foraging (BFO), and Differential Evolution (DE).
While the interface is Pythonic and easy to use, the core is written in Rust to deliver better performance for larger or more complex problems.
Documentation: see docs/index.md for the library guide and API overview.
This is an early version — contributions, suggestions, and feedback are all welcome.
Features
- Ant Colony Optimization (ACO) — for discrete problems like TSP
- Particle Swarm Optimization (PSO) — for continuous function optimization
- Artificial Bee Colony (ABC) — inspired by bee foraging behavior
- Grey Wolf Optimization (GWO), Firefly (FA), Simulated Annealing (SA)
- Cuckoo Search (CS), Bat Algorithm (BA), Glowworm Swarm Optimization (GSO)
- Bacterial Foraging (BFO), Differential Evolution (DE)
- CMA-ES for covariance-adaptive continuous search
- Binary PSO, permutation GA, NSGA-II, and MOPSO for advanced search
- ACO variants including ACS, elitist, and MMAS behavior
- Simple, clean Python API
- Fast backend powered by Rust
Installation
pip install colonyx
(Install from source while release automation is being prepared.)
Example
All algorithms are used through the unified AutoColony interface, selected
via the mode parameter.
Continuous optimization (PSO / ABC) — minimize an objective function over a
box, given per-dimension bounds:
from colonyx import AutoColony
def sphere(x):
return sum(xi * xi for xi in x) # minimum 0 at the origin
opt = AutoColony(mode="pso", n_iterations=150, random_state=42)
opt.fit(sphere, bounds=[(-5, 5), (-5, 5), (-5, 5)])
opt.predict() # best position, ~ [0, 0, 0]
opt.score() # objective value at that position, ~ 0
# Artificial Bee Colony works the same way:
AutoColony(mode="abc", n_iterations=200).fit(sphere, bounds=[(-5, 5)] * 3)
Discrete optimization (ACO) — find a short tour through a square distance matrix (TSP):
import numpy as np
from colonyx import AutoColony
distance_matrix = np.array([
[0, 1, 9, 9, 1],
[1, 0, 1, 9, 9],
[9, 1, 0, 1, 9],
[9, 9, 1, 0, 1],
[1, 9, 9, 1, 0],
], dtype=float)
opt = AutoColony(mode="aco", n_iterations=100, random_state=42)
opt.fit(distance_matrix)
opt.predict() # best tour, e.g. [0, 1, 2, 3, 4]
opt.score() # tour length (lower is better)
Use mode="auto" to let colonyx pick ACO for a square matrix or PSO for an
objective function automatically.
For advanced optimizers, see docs/algorithms/advanced.md.
Rust usage
The optimization core is implemented in Rust. If you are working on the Rust side of the codebase, you can use the core types and optimizers directly:
use colonyx::algorithms::base::Optimizer;
use colonyx::algorithms::pso::ParticleSwarm;
use colonyx::core::{Bounds, ContinuousProblem};
fn main() {
let bounds = Bounds::uniform(3, -5.0, 5.0).unwrap();
let mut optimizer = ParticleSwarm::new(30, 100, 0.7, 1.5, 1.5, bounds);
optimizer.set_random_seed(Some(42));
let problem = ContinuousProblem {
name: "sphere".to_string(),
dimensions: 3,
objective_function: Box::new(|x: &[f64]| x.iter().map(|xi| xi * xi).sum()),
};
optimizer.fit(&problem).unwrap();
let best = optimizer.predict().unwrap();
println!("best position: {:?}", best.variables);
println!("best score: {:?}", optimizer.score().unwrap());
}
For discrete problems, use AntColony with DiscreteProblem and a distance
matrix.
Documentation
- Library guide:
docs/index.md - AutoColony API:
docs/autocolony-api.md - CLI:
docs/cli.md - Getting started:
docs/getting-started.md - Algorithm overview:
docs/algorithms.md - Release and packaging notes:
docs/release.md
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file colonyx-0.2.0.tar.gz.
File metadata
- Download URL: colonyx-0.2.0.tar.gz
- Upload date:
- Size: 106.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
086bd24785d3efc27402e0a539b0c4448ada9944fd67a0cbc98f87b03480f2ba
|
|
| MD5 |
172820292d157dcb94f87b1c57c58dd6
|
|
| BLAKE2b-256 |
1cd4ca6e33c7e40ef4a5f3d9bb95d7ecb49a87df356033b6e56d374f350fcdf7
|
File details
Details for the file colonyx-0.2.0-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: colonyx-0.2.0-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 409.1 kB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.14.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7eb60bdcd0c5aa6767008a1a0e87bc0da8cc37691a8a305974727b8bafe5490
|
|
| MD5 |
bd77ad0388c61f239ecc319b04409437
|
|
| BLAKE2b-256 |
f9bdab674dfbae0cd74a596598d4eefa47696f906f936826eae4e5e9054edfc7
|