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.


pypi-AgEIcHlwaS5vcmcCJDRkNTQ5Yzk5LWQzNTgtNGZiZS1hOGEyLWI0MTNhZmEyMDllZQACKlszLCI4NmU3NTdlNy1iYWJiLTQzNTQtYjhlOC04ZTA3NWY0NThiYTkiXQAABiA_nmoBeOPi25RiDzwqaUokVcrjsG3TeUCAsTq1bUDsNQ

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 biolab33 0.1.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 biolab33 0.1.0
File Size Uploaded Provenance
biolab33-0.1.0.tar.gz 19.4 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 39.6 kB

Release files / biolab33-0.1.0.tar.gz

Download URL biolab33-0.1.0.tar.gz
Size 19.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f916204c89d139164e7cc667e471f58dd5dee13337392bfab9037596b3914fb2
BLAKE2b-256 checksum
How to use checksums
c49e33e47439336f0cd94c75a928ac8a7b027547c64b6b5ca4ec65ef9294faa0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.11

Release files / biolab33-0.1.0-py3-none-any.whl

Download URL biolab33-0.1.0-py3-none-any.whl
Size 20.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c675866e162d845f85776b55998388144c5dfa516dad6ed5ea61a9fe64c0a116
BLAKE2b-256 checksum
How to use checksums
11be0df3f8a014e92d310a0eeb8c3da27718da80dd44b79a9d0209a3d70463ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.11

Security for biolab33 0.1.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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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