Skip to main content

bioalgo

PyPI version Python versions License: MIT

bioalgo is a lightweight, pure-Python library for nature-inspired, bio-inspired, and metaheuristic optimization algorithms. It includes both discrete combinatorial solvers (N-Queens, Traveling Salesman Problem) and continuous multimodal function optimizers.


Algorithms Included

Algorithm Type Description / Operators Typical Applications
Hill Climbing Discrete Local Search Steepest ascent, conflict evaluation, random-restart heuristics N-Queens, constraint satisfaction
Simulated Annealing (SA) Metaheuristic Metropolis acceptance criterion ($P = e^{-\Delta E / T}$), 2-opt swaps, geometric cooling Traveling Salesman Problem (TSP), combinatorial routing
Particle Swarm Optimization (PSO) Swarm Intelligence Velocity/position updates, cognitive ($\text{pBest}$) and social ($\text{gBest}$) components, inertia damping Continuous multimodal minimization
Differential Evolution (DE) Evolutionary Mutation (DE/rand/1, DE/best/1), binomial crossover ($CR$), one-to-one selection Non-linear parameter estimation, benchmark optimization
Biogeography-Based Optimization (BBO) Ecological Species migration ($\lambda, \mu$), Habitat Suitability Index (HSI), elitism, mutation Continuous global optimization
Firefly Algorithm (FA) Swarm Intelligence Light intensity, distance attractiveness ($\beta(r) = \beta_0 e^{-\gamma r^2}$), randomized step damping Multimodal landscapes with multiple local optima

Installation

Install via pip:

pip install bioalgo

Or install in development/editable mode:

git clone https://github.com/example/bioalgo.git
cd bioalgo
pip install -e .

Quickstart

1. Particle Swarm Optimization (PSO)

from bioalgo import ParticleSwarmOptimization
from bioalgo.benchmarks import rastrigin

# Optimize the multimodal Rastrigin function in 5 dimensions
pso = ParticleSwarmOptimization(
    cost_func=rastrigin,
    dim=5,
    bounds=(-5.12, 5.12),
    num_particles=40
)

best_vector, best_cost, history = pso.optimize(max_iter=100)
print(f"Optimal Cost: {best_cost:.6e}")
print(f"Optimal Solution: {best_vector}")

2. Differential Evolution (DE)

from bioalgo import DifferentialEvolution
from bioalgo.benchmarks import ackley

de = DifferentialEvolution(
    cost_func=ackley,
    dim=5,
    bounds=(-32.768, 32.768),
    pop_size=40,
    strategy="best/1/bin"
)

best_vector, best_cost, history = de.optimize(max_generations=100)
print(f"Ackley Minimum: {best_cost:.6e}")

3. Solve N-Queens with Hill Climbing

from bioalgo import NQueensProblem, HillClimbing

problem = NQueensProblem(n=8)
solver = HillClimbing(problem)
solution, restarts, steps = solver.search_with_restarts(max_restarts=50)

print(f"Solved in {restarts} restart(s) and {steps} steps:")
print(problem.render_board(solution))

4. Traveling Salesman Problem (TSP) with Simulated Annealing

from bioalgo import TravelingSalesmanProblem, SimulatedAnnealing

problem = TravelingSalesmanProblem()
sa = SimulatedAnnealing(problem, initial_temp=1000.0, cooling_rate=0.995)

best_tour, best_distance, history = sa.optimize(seed=42)
print(f"Best Tour Length: {best_distance:.2f}")
print("Tour Sequence:", " -> ".join(best_tour))

Built-in Benchmark Functions

bioalgo.benchmarks includes standard continuous functions:

  • sphere(x)
  • rastrigin(x)
  • ackley(x)
  • rosenbrock(x)
  • griewank(x)

Command Line Interface (CLI)

bioalgo comes with a command-line interface:

# Solve 8-Queens and render the board
bioalgo nqueens -n 8 --render

# Solve Traveling Salesman Problem
bioalgo tsp --temp 1000 --cooling 0.995

# Optimize a continuous benchmark using PSO, DE, BBO, or FA
bioalgo optimize pso --func rastrigin --dim 5 --iters 100
bioalgo optimize de --func ackley --dim 5 --iters 100
bioalgo optimize bbo --func sphere --dim 5 --iters 100
bioalgo optimize fa --func rastrigin --dim 5 --iters 100

Building and Publishing to PyPI

1. Build the Distribution Archives

python -m build

This produces .tar.gz (source distribution) and .whl (built wheel) in dist/.

2. Check Package Metadata

twine check dist/*
twine upload --repository testpypi dist/*

4. Upload to Production PyPI

twine upload dist/*

License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for bioalgo 0.7.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 bioalgo 0.7.0
File Size Uploaded Provenance
bioalgo-0.7.0.tar.gz 19.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for bioalgo 0.7.0
File Interpreter ABI Platform
bioalgo-0.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 39.0 kB

Release files / bioalgo-0.7.0.tar.gz

Download URL bioalgo-0.7.0.tar.gz
Size 19.1 kB
Tags Source
SHA-256 checksum
How to use checksums
aa4ee0730b30d0ce1f24f3d3bae54e7e271eddeec67ec65858d24a93633c43c5
BLAKE2b-256 checksum
How to use checksums
12026e55b57d2c09fd3b01a7142cc3f4c59ca05c8b14524326c609e25a9e3399
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.11

Release files / bioalgo-0.7.0-py3-none-any.whl

Download URL bioalgo-0.7.0-py3-none-any.whl
Size 19.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
febbaf5f0a1ec56efa36e85113a400beb2e51fe0c0a2d1b517959462e6460c7d
BLAKE2b-256 checksum
How to use checksums
2734a902b4b74f24180d5ef9c7c12ca919f78a1f57d8553c3933b637b333d321
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.11

Security for bioalgo 0.7.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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