# PyApso
**PyApso** is an implementation of the **Adaptive Particle Swarm Optimization (APSO)** algorithm and designed for solving continuous, multi-objective, and multi-dimensional optimization problems.
---
## Installation
Install the package using pip:
```bash
pip install pyapso
````
Or from source:
```bash
git clone https://github.com/smohamadabedy/pyapso.git
cd pyapso
pip install .
```
## Features
ADAPTIVE - key parameters: (inertia weight, avg weight)
Continuous optimization support
Single and multi-objective fitness evaluation
Constraint-aware evolution
Batch evaluation and parallel execution
Excel and JSON logging
Custom callbacks and visualizations
## Usage
```python
from pyapso import APSO
import numpy as np
def fitness(x):
return np.sum(x**2)
if __name__ == "__main__":
best, score, history, hd = APSO(
objective_function=fitness,
dim=1,
bounds=([-10], [10]),
num_particles=100,
max_iter=10,
verbose = 1,live_plot=False,folder="results_folder",save_prefix="results_file"
).run()
print("Best solution:", best)
print("Best score:", score)
# Save optimization history (JSON,CSV)
hd.save()
# Plot optimization history
hd.plot()
```
## Modes
```python
apso.run("avg", c1=1.8, c2=1.8, w_min=0.5, w_max=0.9)
```
"avg" mode adapts the inertia weight dynamically between w_min and w_max using swarm behavior.
```python
apso.run("inertia",c1=1.8, c2=1.8, inertia=0.05)
```
"inertia" mode adapts a fixed inertia weight throughout the optimization (default).
💡 Tip:
- A higher c1 encourages particles to explore their own search path.
- A higher c2 encourages convergence to the global best.
- Lower inertia means the swarm is more reactive and less explorative.
## Examples
You can find runnable demos in the examples/ directory:
```bash
examples/
├── demo_1.py # 5D Rastrigin function
├── demo_2.py # 3D constrained benchmark
├── demo_3.py # 2D McCormick function
```
Run an example:
```bash
python examples/demo_2.py
```
Raw data
{
"_id": null,
"home_page": "https://github.com/smohamadabedy/pyapso",
"name": "PyApso",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "optimization, particle swarm optimization, APSO, metaheuristic",
"author": null,
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/8e/c9/9543f66238597358216069565826780f3194049ebe7fb345cab7d1039965/pyapso-1.1.0.tar.gz",
"platform": null,
"description": "# PyApso\r\n\r\n**PyApso** is an implementation of the **Adaptive Particle Swarm Optimization (APSO)** algorithm and designed for solving continuous, multi-objective, and multi-dimensional optimization problems. \r\n\r\n---\r\n\r\n## Installation\r\n\r\nInstall the package using pip:\r\n\r\n```bash\r\npip install pyapso\r\n````\r\nOr from source:\r\n```bash\r\ngit clone https://github.com/smohamadabedy/pyapso.git\r\ncd pyapso\r\npip install .\r\n```\r\n\r\n## Features\r\nADAPTIVE - key parameters: (inertia weight, avg weight)\r\nContinuous optimization support\r\nSingle and multi-objective fitness evaluation\r\nConstraint-aware evolution\r\nBatch evaluation and parallel execution\r\nExcel and JSON logging\r\nCustom callbacks and visualizations\r\n\r\n## Usage\r\n\r\n```python\r\nfrom pyapso import APSO\r\nimport numpy as np\r\n\r\ndef fitness(x):\r\n return np.sum(x**2)\r\n\r\nif __name__ == \"__main__\":\r\n best, score, history, hd = APSO(\r\n objective_function=fitness,\r\n dim=1,\r\n bounds=([-10], [10]),\r\n num_particles=100,\r\n max_iter=10,\r\n verbose = 1,live_plot=False,folder=\"results_folder\",save_prefix=\"results_file\"\r\n ).run() \r\n \r\n print(\"Best solution:\", best)\r\n print(\"Best score:\", score)\r\n\r\n # Save optimization history (JSON,CSV)\r\n hd.save()\r\n\r\n # Plot optimization history\r\n hd.plot()\r\n```\r\n## Modes\r\n\r\n```python\r\napso.run(\"avg\", c1=1.8, c2=1.8, w_min=0.5, w_max=0.9)\r\n```\r\n\"avg\" mode adapts the inertia weight dynamically between w_min and w_max using swarm behavior.\r\n\r\n```python\r\napso.run(\"inertia\",c1=1.8, c2=1.8, inertia=0.05)\r\n```\r\n\"inertia\" mode adapts a fixed inertia weight throughout the optimization (default).\r\n\r\n\ud83d\udca1 Tip:\r\n\r\n - A higher c1 encourages particles to explore their own search path.\r\n - A higher c2 encourages convergence to the global best.\r\n - Lower inertia means the swarm is more reactive and less explorative.\r\n\r\n\r\n\r\n## Examples\r\nYou can find runnable demos in the examples/ directory:\r\n\r\n```bash\r\nexamples/\r\n\u251c\u2500\u2500 demo_1.py # 5D Rastrigin function\r\n\u251c\u2500\u2500 demo_2.py # 3D constrained benchmark\r\n\u251c\u2500\u2500 demo_3.py # 2D McCormick function\r\n```\r\n\r\nRun an example:\r\n```bash\r\npython examples/demo_2.py\r\n```\r\n",
"bugtrack_url": null,
"license": null,
"summary": "Adaptive Particle Swarm Optimization for continuous, multi-objective, and multidimensional problems",
"version": "1.1.0",
"project_urls": {
"Documentation": "https://github.com/smohamadabedy/pyapso#readme",
"Homepage": "https://github.com/smohamadabedy/pyapso",
"Issues": "https://github.com/smohamadabedy/pyapso/issues",
"Source": "https://github.com/smohamadabedy/pyapso"
},
"split_keywords": [
"optimization",
" particle swarm optimization",
" apso",
" metaheuristic"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "2a8e9a8067d43f42f7c6e084c4a491f4743a8c4f89a70cd25040fadc18da87b4",
"md5": "b879e96a7cc24078a1451e155bdb57e4",
"sha256": "f72b210f845ab13a6cf478b2af23294cef3a2c2eb4367464313ac15a9c3405b6"
},
"downloads": -1,
"filename": "pyapso-1.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b879e96a7cc24078a1451e155bdb57e4",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 7967,
"upload_time": "2025-07-29T20:34:28",
"upload_time_iso_8601": "2025-07-29T20:34:28.551393Z",
"url": "https://files.pythonhosted.org/packages/2a/8e/9a8067d43f42f7c6e084c4a491f4743a8c4f89a70cd25040fadc18da87b4/pyapso-1.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "8ec99543f66238597358216069565826780f3194049ebe7fb345cab7d1039965",
"md5": "f977142f4ce2fecd5242736f84624c5c",
"sha256": "be4dec5f9dacde055e05e59858973a383c5aafe148d532a842d96f20c3e49986"
},
"downloads": -1,
"filename": "pyapso-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "f977142f4ce2fecd5242736f84624c5c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 8685,
"upload_time": "2025-07-29T20:34:30",
"upload_time_iso_8601": "2025-07-29T20:34:30.337519Z",
"url": "https://files.pythonhosted.org/packages/8e/c9/9543f66238597358216069565826780f3194049ebe7fb345cab7d1039965/pyapso-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-29 20:34:30",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "smohamadabedy",
"github_project": "pyapso",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "numpy",
"specs": []
},
{
"name": "matplotlib",
"specs": []
},
{
"name": "tqdm",
"specs": []
}
],
"lcname": "pyapso"
}