Skip to main content

Colonyx Logo

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.

PyPI version docs

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

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

Release files for colonyx 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for colonyx 0.3.0
File Size Uploaded
colonyx-0.3.0.tar.gz 115.4 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for colonyx 0.3.0
File
colonyx-0.3.0-cp312-cp312-manylinux_2_34_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.34+ x86-64 Details
colonyx-0.3.0-cp311-cp311-manylinux_2_34_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.34+ x86-64 Details
colonyx-0.3.0-cp310-cp310-manylinux_2_34_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.34+ x86-64 Details
colonyx-0.3.0-cp39-cp39-manylinux_2_34_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.34+ x86-64 Details

Total release size: 2.2 MB

Release files / colonyx-0.3.0.tar.gz

Download URL colonyx-0.3.0.tar.gz
Size 115.4 kB
Tags Source
SHA-256 checksum
How to use checksums
43a12c5a3a128b6e776ddbf9ce69e40caaa6a78737184317be7573de644ba9de
BLAKE2b-256 checksum
How to use checksums
da1b67f937ba9c9292265bf2ce95fa206553b2ed7fcea95a3751520bef92391f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.14.1

Release files / colonyx-0.3.0-cp312-cp312-manylinux_2_34_x86_64.whl

Download URL colonyx-0.3.0-cp312-cp312-manylinux_2_34_x86_64.whl
Size 528.7 kB
Tags CPython 3.12 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
e462cbf472ab4bc7de2f67062f555c12b8d43367a5e19ce0ba27cf2c1c79b71c
BLAKE2b-256 checksum
How to use checksums
f996a6c95d3e47d1290ff6ae36726671b2e7667f71c7fb2512d0d2f4e8d2814b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.14.1

Release files / colonyx-0.3.0-cp311-cp311-manylinux_2_34_x86_64.whl

Download URL colonyx-0.3.0-cp311-cp311-manylinux_2_34_x86_64.whl
Size 528.8 kB
Tags CPython 3.11 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
367bab795126fa12a387a2d68a13c41bd142fe1a5b248502c3014d6c7f89e032
BLAKE2b-256 checksum
How to use checksums
0e9129bd582432f45414ccda1c708d495858297261c49bb2239ef5f5bee17361
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.14.1

Release files / colonyx-0.3.0-cp310-cp310-manylinux_2_34_x86_64.whl

Download URL colonyx-0.3.0-cp310-cp310-manylinux_2_34_x86_64.whl
Size 528.7 kB
Tags CPython 3.10 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
dd38b1f91aa38c8e52a35108955884ade7e9f38dbef63eeb774f0791ff11ac1a
BLAKE2b-256 checksum
How to use checksums
2ef00a2211c275a07e0c2898f30ae60f54b10aced16f32f69b075be0dc9b6b70
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.14.1

Release files / colonyx-0.3.0-cp39-cp39-manylinux_2_34_x86_64.whl

Download URL colonyx-0.3.0-cp39-cp39-manylinux_2_34_x86_64.whl
Size 528.7 kB
Tags CPython 3.9 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
c3265d2a12bd3169d131a32f58c215670753a119be10cbe68fe95a4bf567bb53
BLAKE2b-256 checksum
How to use checksums
88bb9c1b300a4662cce9b0e758c0307528e85cdaa147705abdba36ba27b73774
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.14.1

Release history Release notifications | RSS feed

This release

0.3.0 This release

5 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page