Metadata-Version: 2.4
Name: swarmopt
Version: 0.3.0
Summary: Reproducible particle swarm optimization, including multiobjective, cooperative, and safety-bounded swarms
Author-email: Siobhan K Cronin <siobhankcronin@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/SioKCronin/swarmopt
Project-URL: Source, https://github.com/SioKCronin/swarmopt
Project-URL: Issues, https://github.com/SioKCronin/swarmopt/issues
Project-URL: Changelog, https://github.com/SioKCronin/swarmopt/blob/master/CHANGELOG.md
Project-URL: Documentation, https://github.com/SioKCronin/swarmopt/tree/master/docs
Keywords: particle swarm optimization,PSO,swarm intelligence,optimization,multiobjective,cooperative PSO,reproducibility
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Scientific/Engineering :: Mathematics
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE.md
Requires-Dist: numpy>=1.23
Requires-Dist: scipy>=1.9
Provides-Extra: viz
Requires-Dist: matplotlib>=3.5; extra == "viz"
Provides-Extra: tda
Requires-Dist: giotto-tda>=0.5.0; extra == "tda"
Provides-Extra: examples
Requires-Dist: matplotlib>=3.5; extra == "examples"
Provides-Extra: dev
Requires-Dist: pytest>=7; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: twine; extra == "dev"
Dynamic: license-file

![particles](https://github.com/SioKCronin/PSO-baselines/blob/master/media/swarmopt_lateral.png)

# SwarmOpt

SwarmOpt is a library of swarm optimization algorithms implemented in Python. 

Swarm intelligence leverages population-based search solutions to balance exploration and exploitation with respect 
to specified cost functions. The PSO lineage was sparked by Eberhart and Kennedy in their original paper on PSOs in 1995, 
and the intervening years have seen many variations spring from their central idea. 

## Installation

To install SwarmOpt, run this command in your terminal:

```shell
$ pip install swarmopt
```

## Quick Start

```python
from swarmopt import Swarm
from swarmopt.functions import sphere

# Basic usage
swarm = Swarm(
    n_particles=30,
    dims=2,
    c1=2.0,
    c2=2.0,
    w=0.9,
    epochs=100,
    obj_func=sphere,
    algo='global'
)

swarm.optimize()
print(f"Best cost: {swarm.best_cost}")
```

### Reproducible runs

Pass `seed` to get the same result every time. SwarmOpt draws all randomness
from its own `numpy.random.Generator` and never touches NumPy's or Python's
global random state.

```python
swarm = Swarm(n_particles=30, dims=2, c1=2.0, c2=2.0, w=0.9,
              epochs=100, obj_func=sphere, seed=42)
```

## Testing

Run the comprehensive test suite:

```bash
# Unit tests (what CI runs on every pull request)
python -m pytest

# Run all tests, including the slower integration scripts
python infra/run_tests.py

# Or run specific test categories
python infra/run_tests.py --unit           # Fast unit tests only
python infra/run_tests.py --show           # Show all available tests
python tests/index.py                      # Interactive test runner
```

Build, release, Docker, and dependency pin files live under [`infra/`](infra/).

For local development from a clone:

```bash
pip install -e ".[dev]"
make -C infra init   # optional extras (matplotlib, TDA examples, etc.)
```

## Benchmarks

Stratified empirical comparisons (repeated trials, spread, ranks per function class) are in [`benchmarks/README.md`](benchmarks/README.md). Run the driver from the repo root with `python benchmarks/run_benchmarks.py` (see that file for options and requirements).

## Algorithms

### Single-Objective
* Global Best PSO - Kennedy & Eberhart 1995
* Local Best PSO - Kennedy & Eberhart 1995
* Unified PSO - Parsopoulos &  Vrahatis 2004
* Dynamic Multi-Swarm PSO - Liang & Suganthan 2005 *(being reworked; not available in 0.3)*
* Simulated Annealing PSO - Mu, Cao, & Wang 2009
* Cooperative PSO (CPSO) - Van den Bergh & Engelbrecht 2004
* Horse Herd Optimization Algorithm (HHOA) - Ibrahim et al. 2025

### Multiobjective
* Multiobjective PSO - Handles multiple conflicting objectives simultaneously 

## Benchmark Functions

### Single Objective
* Sphere Function
* Rosenbrock's Function
* Ackley's Function
* Griewank's Function
* Rastrigin's Function
* Weierstrass Function

### Multiobjective
* **ZDT1, ZDT2, ZDT3** - Zitzler-Deb-Thiele test functions
* **DTLZ1, DTLZ2** - Deb-Thiele-Laumanns-Zitzler test functions

## Implemented Features

### Inertia Weight Variations
* **Constant** - Traditional fixed inertia weight
* **Linear Decreasing** - Classic linear decay (default)
* **Chaotic** - Chaotic inertia using logistic map
* **Random** - Random inertia between 0.5-1.0
* **Adaptive** - Adapts based on convergence progress
* **Chaotic-Random** - Combination of chaotic and random
* **Exponential Decreasing** - Exponential decay
* **Sigmoid Decreasing** - Sigmoid decay curve

### Velocity Clamping Variations
* **No Clamping** - Particles can move freely
* **Basic Clamping** - Standard velocity bounds
* **Adaptive Clamping** - Decreases over time
* **Exponential Clamping** - Exponential decay
* **Sigmoid Clamping** - Sigmoid decay
* **Random Clamping** - Random bounds
* **Chaotic Clamping** - Chaotic bounds using logistic map
* **Soft Clamping** - Soft bounds using tanh
* **Hybrid Clamping** - Adaptive + exponential
* **Convergence-Based** - Based on optimization progress

## Sample Applications

* Neural network number of layers and weight optimization
* Routing in communication networks
* Satellite repair helper-swarm standoff positioning

## Security

See [SECURITY.md](SECURITY.md) to report a vulnerability privately or to
verify a release's build provenance.

## Citation

Siobhan K Cronin, SwarmOpt (2018), GitHub repository, https://github.com/SioKCronin/SwarmOpt
