Skip to main content

Implementation and visualization of different swarm optimization algorithms.

Project description

swarmlib

Pypi PyPI - Python Version PyPI - Downloads Stars
PyPI - License Build Status PRs Welcome
Donate

Description

This repository implements several swarm optimization algorithms and visualizes their (intermediate) solutions. To run the algorithms one can either use the command line interface or the API. Currently, the following algorithms are implemented:

Installation

You can install the package with pip from pypi:

pip3 install swarmlib

swarm --version

Usage

To print all available algorithms:

swarm --help

Ant Colony Optimization

This repository includes an ant colony optimization algorithm for the traveling salesman problem (TSP) like Marco Dorigo, Mauro Birattari, and Thomas Stuetzle introduced in the IEEE Computational Intelligence Magazine in November 2006 (DOI: 10.1109/MCI.2006.329691).
The implementation was part of the course Natural computing for learning and optimisation at Charles University Prague in winter 2018/2019.

Features

Enables to apply the ant colony optimization algorithm to a TSP using a TSPLIB95 file and plots the result.

ACO Sample

The algorithm solves the TSP and plots the result all n iterations.
The nodes are plot according to their coordinates read from the TSPLIB95 file. The widths of the edges indicate the amount of pheromone that is associated with this edge. If an edge is blue, it is part of the best found path.

To print all available options execute:

swarm ants -h

API

In addition to the cli you can also use the API:

from swarmlib.aco4tsp.aco_problem import ACOProblem

problem = ACOProblem('/path/to/my/tsp-file.tsp', 10)
if problem.solve():
    problem.show_result()

Firefly Algorithm

This repository includes the firefly algorithm like Xin-She Yang introduced in his paper Firefly Algorithms for Multimodal Optimization in 2009 (DOI: 10.1007/978-3-642-04944-6_14).
The implementation was part of the course Natural computing for learning and optimisation at Charles University Prague in winter 2018/2019.

Features

Enables to apply the firefly algorithm to one of the provided 2D functions. The algorithm tries to find the global minimum of the selected function.

Currently two functions can be selected:

firefly algorithm

To print all available options execute:

swarm fireflies -h

API

In addition to the cli you can also use the API:

from swarmlib.fireflyalgorithm.firefly_problem import FireflyProblem
from swarmlib.util.functions import FUNCTIONS

problem = FireflyProblem(FUNCTIONS['michalewicz'], 14)
problem.solve()

Cuckoo search

This repository also implements the cuckoo search that was introduced by Xin-She Yang and Suash Deb in their paper Cuckoo Search via Lévy flights in 2009 (DOI: 10.1109/NABIC.2009.5393690).

Features

Enables to apply cuckoo search to one of the provided 2D functions. The algorithm tries to find the global minimum of the selected function.

Currently two functions can be selected:

cukoo search

The plot shows all nests of the current cuckoo generation as red markers. The best nests of all (previous) generations are indicated by yellow markers.

To print all available options execute:

swarm cuckoos -h

API

In addition to the cli you can also use the API:

from swarmlib.cuckoosearch.cuckoo_problem import CuckooProblem
from swarmlib.util.functions import FUNCTIONS

problem = CuckooProblem(function=FUNCTIONS['michalewicz'], nests=14)
best_nest = problem.solve()
problem.replay()

Contribution

If you found a bug or are missing a feature do not hesitate to file an issue.
Pull Requests are welcome!

Support

When you like this package make sure to star the repository. I am always looking for new ideas and feedback.
In addition, it is possible to donate via paypal.

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

swarmlib-0.4.1.tar.gz (17.7 kB view hashes)

Uploaded Source

Built Distribution

swarmlib-0.4.1-py3-none-any.whl (24.5 kB view hashes)

Uploaded Python 3

Supported by

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