bioalgo
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/*
3. Test on TestPyPI (Recommended first)
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.9.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| bioalgo-0.9.3.tar.gz | 19.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| bioalgo-0.9.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 38.2 kB
Release files / bioalgo-0.9.3.tar.gz
| Download URL | bioalgo-0.9.3.tar.gz |
|---|---|
| Size | 19.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
64308935893c27e71c95b7c8004cb09f39e3585bd8c50902a21f207e925bb759
|
|
BLAKE2b-256 checksum How to use checksums |
b55b5b424ba8fb654059c332e4a8f4e515ba1e708b5c70159f6b09a07e673015
|
| 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.9.3-py3-none-any.whl
| Download URL | bioalgo-0.9.3-py3-none-any.whl |
|---|---|
| Size | 19.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
90468ca7dfbf4074db06f19bf8f3922ce3f4d5cf3cfc1df42bdf122a61e05b14
|
|
BLAKE2b-256 checksum How to use checksums |
ad3965b40f44cc32630a20b1a5a7787e1eddd2bc06ab158359578e935ba5113d
|
| 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.9.3
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.