Giter Club home page Giter Club logo

ibrahimztrk / swarmlib Goto Github PK

View Code? Open in Web Editor NEW

This project forked from haaleo/swarmlib

0.0 1.0 0.0 7.58 MB

This repository implements several swarm optimization algorithms and visualizes them. Implemented algorithms: Particle Swarm Optimization (PSO), Firefly Algorithm (FA), Cuckoo Search (CS), Ant Colony Optimization (ACO), Artificial Bee Colony (ABC) and Grey Wolf Optimizer (GWO)

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%

swarmlib's Introduction

swarmlib

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

Description

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

Installation

You can install the package with pip from pypi. Installing the library in a virtual environment is recommended:

# Create virtual environment
python3 -m venv .venv
source .venv/bin/activate

# Install swarmlib
pip install swarmlib

# Verify installation
swarm --version

Usage

To print all available algorithms:

swarm --help

Contribution

If you found a bug or are missing a feature do not hesitate to file an issue.
Do not hesitate to ask questions on gitter.

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.

Algorithms

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 import FireflyProblem, FUNCTIONS

problem = FireflyProblem(function=FUNCTIONS['michalewicz'], firefly_number=14)
best_firefly = problem.solve()
problem.replay()

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. The abandonment of a nest is indicated by a dark grey transition.

To print all available options execute:

swarm cuckoos -h

API

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

from swarmlib import CuckooProblem, FUNCTIONS

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

Particle Swarm Optimization

This repository also implements modified particle swarm optimization that was introduced by Yuhui Shi and Russell C. Eberhart in their paper A modified particle swarm optimizer in 1998 (DOI: 10.1109/ICEC.1998.699146). Their approach introduces a so called inertia weight w. To get the original particle swarm optimization algorithm, just set the parameter --weight=1.

Features

Enables particle swarm optimization 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:

particle swarm optimization

The plot shows all particles and their velocities.

To print all available options execute:

swarm particles -h

API

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

from swarmlib import PSOProblem, FUNCTIONS

problem = PSOProblem(function=FUNCTIONS['michalewicz'], particles=14)
best_particle = problem.solve()
problem.replay()

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 import ACOProblem

problem = ACOProblem(ant_number=10)
path, distance = problem.solve()
problem.replay()

Artificial Bee Colony

The Artificial Bee Colony (ABC) algorithm was initially proposed 2005 by Dervis Karaboga in his paper An Idea Based on Honey Bee Swarm For Numerical Optimization. In his paper Karaboga did not specify how exactly new solutions shall be discovered.

Research has shown that the flight behavior of birds, fruit flies and other insects model properties of Levy flights (Brown, Liebovitch & Glendon, 2007; Pavlyukevich, 2007). Therefore, this library's ABC implementation leverages levy flights to generate new solutions.

Features

Enables the ABC 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:

ABC Sample

The plot shows all employee bees as red markers, the onlooker bees are visualized as blue markers. The best bees of all (previous) iterations are indicated by yellow markers. When an employee bee exceeded its maximum trials the bee is assigned a new random position. This is visualized by a dark grey transition. Since the onlooker bees pick up an employee bee's position randomly visualizing their transitions confuses rather than it helps understanding the algorithm and therefore is omitted.

To print all available options execute:

swarm bees -h

API

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

from swarmlib import ABCProblem, FUNCTIONS

problem = ABCProblem(bees=10, function=FUNCTIONS['michalewicz'])
best_bee = problem.solve()
problem.replay()

Grey Wolf Optimization

The Grey Wolf Optimization (GWO) algorithm was proposed by S. Mirjalili et al. in the paper Grey Wolf Optimizer. The paper proposed a novel algorithm based on the hunting and the hierarchy structure in grey wolves

Features

Enables the GWO 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:

GWO Sample

To print all available options execute:

swarm wolves -h

API

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

from swarmlib import GWOProblem, FUNCTIONS

problem = GWOProblem(wolves=10, function=FUNCTIONS['michalewicz'])
best_wolf = problem.solve()
problem.replay()

swarmlib's People

Contributors

haaleo avatar nimishverma avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.