Skip to main content

collection of optimization algorithms, PSO & ABC

Project description

PSO & ABC Optimizer: Comparative Analysis for Financial Optimization

Python License

This repository contains reusable implementations of Particle Swarm Optimization (PSO) and Artificial Bee Colony (ABC) algorithms, along with a real-world case study in corporate financial allocation. Side-by-side comparison is provided for educational, research, and practical applications.


Features

  • Modular Python implementation of PSO and ABC metaheuristics
  • Ready-to-use fitness/objective functions (including Rastrigin and financial cost minimization)
  • Easy configuration: number of variables, bounds, iterations, etc.
  • Visualizations: convergence curves, 2D particle/bee distribution plots
  • Example scripts for rapid testing and benchmarking
  • Professional documentation & code structure

Project Structure

optimize_algorithm/ │ ├── optimize_algorithm/ │ ├── init.py │ ├── pso.py
│ └── abc.py
│ ├── examples/ │ ├── testing_pso.py │ └── testing_abc.py │ ├── README.md ├── setup.py ├── LICENSE └── .gitignore


Algorithms Overview

Particle Swarm Optimization (PSO)

Inspired by bird flocking, PSO explores solutions by updating each particle’s position using both individual and global experience. Suitable for continuous optimization and known for rapid convergence.

  • Inertia, cognitive, and social update rules
  • Easy parameter tuning (w, c1, c2)

Artificial Bee Colony (ABC)

Mimics the foraging behavior of bees. Solution updates come from employed bees (explore), onlooker bees (select via "waggle dance"), and scouts (random exploration). Excels at avoiding local optima in complex landscapes.

  • Employed, onlooker, scout bee phases
  • Adaptive exploration via abandonment and random scouts

Case Study: Financial Allocation Problem

Goal:
Minimize the total corporate expenditure (Marketing, Operational, Salary, Maintenance, Miscellaneous) with:

  • Total ≤ 120,000,000
  • Marketing ≥ 10,000,000

Fitness Function Example:

def cost_function(x):
    ideal_total = 120_000_000
    total = np.sum(x)
    penalty = max(0, total - ideal_total)**2
    underfund_penalty = 0
    if x[0] < 10_000_000:
        underfund_penalty += (10_000_000 - x[0])**2
    return total + 0.1 * penalty + 0.05 * underfund_penalty


**Result Snapshot** 

| Algorithm | Best Fitness | Total Spent | Convergence Speed |
| --------- | ------------ | ----------- | ----------------- |
| PSO       | \~TBD        | \~TBD       | Fast              |
| ABC       | \~TBD        | \~TBD       | Explorative       |


- Both PSO and ABC reach strong feasible solutions.

- PSO typically converges faster; ABC better explores diverse solutions.


**Quickstart**
1. install dependencies
```python
pip install -r requirements.txt

2. run an example
```python
examples/testing_pso.py
examples/testing_abc.py

3. Test on Rastrigin function
```python
examples/testing_rastrigin.py


**References**

Karaboga, D. "An Idea Based on Honey Bee Swarm for Numerical Optimization", 2005

Kennedy, J., Eberhart, R. "Particle Swarm Optimization", 1995

Wikipedia: Artificial Bee Colony

Wikipedia: Particle Swarm Optimization

**License**
This project is licensed under the MIT License.

**Contributing**
Feel free to open issues, pull requests, or suggestions for new features and applications!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

optimize_algorithm-0.1.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

optimize_algorithm-0.1.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file optimize_algorithm-0.1.0.tar.gz.

File metadata

  • Download URL: optimize_algorithm-0.1.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for optimize_algorithm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6efb39407d12ade063ffac7decceef2fe7656f74e4c43d61350219b0bf635798
MD5 eece7ef3cdea7d05ead6d3ef56e77734
BLAKE2b-256 469e875ff1ac8321c37b0ee60b7f4b4536a7d3f025a3e659001daeb415f51d67

See more details on using hashes here.

File details

Details for the file optimize_algorithm-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for optimize_algorithm-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c075b3c0baac4bf56450db7f2900c208928e8d41789b7e4ee4350461492e2940
MD5 dc7819563d6f139a9de922370f802479
BLAKE2b-256 bacf250f9a276b8e2567a7f7f92294a9617e77eda59d57a6f59fb6b342382a61

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page