SwarmPackagePy
Library of swarm optimization algorithms.
Install / Use
/learn @SISDevelop/SwarmPackagePyREADME
SwarmPackagePy
SwarmPackagePy is a Library of swarm optimization algorithms. It includes 14 optimization algorithms and each can be used for solving specific optimization problem. You can find the principles they operate on and pseudo codes below.<br>
Provides:<br>
- Swarm optimization algorithms.
- Test functions for swarm algorithms.
- Animation of minimum find process.<br> <br>Every algorithm has arguments listed below:<br>
- n: number of agents
- function: test function
- lb: lower limits for plot axes
- ub: upper limits for plot axes
- dimension: space dimension
- iteration: number of iterations<br> <br>Every algorithm has methods listed below:<br>
- get_agents(): returns a history of all agents of the algorithm
- get_Gbest(): returns the best position of algorithm<br> <br>If an algorithm accepts some additional arguments or methods they will be described in its "Arguments" or "Methods" section.
For all questions and suggestions contact us at swarm.team.dev@gmail.com. For more info you could also write to:<br>
- team leads - vllitskevich@gmail.com, polly.bartoshevic@gmail.com,
- programmers - alexeymaleyko@gmail.com, b317.forinko@gmail.com, vladislaw.kapustin@gmail.com.
Table of contents
- Installation<br>
- Bacterial Foraging Optimization<br>
- Gray Wolf Optimization<br>
- Bat Algorithm<br>
- Artificial Bee Algorithm<br>
- Firefly Algorithm<br>
- Cuckoo Search Optimization<br>
- Whale Swarm Algorithm<br>
- Firework Algorithm<br>
- Particle Swarm Optimization<br>
- Chicken Swarm Optimization<br>
- Social Spider Algorightm<br>
- Cat Algorithm<br>
- Harmony Search<br>
- Gravitational Search Algorithm<br>
- Tests<br>
- Animation<br>
Installation
Requirements
- python (version >= 3.5 if you are going to run tests; for all other actions you can use python any version)<br>
- numpy<br>
- pytest (if you are going to run tests)<br>
- matplotlib (if you are going to watch animation)<br>
- pandas (if you are going to watch 3D animation)<br>
Installation
You can install SwarmPackagePy from PyPI repositories using pip. Command bellow will do this:
pip install SwarmPackagePy
Or you can just clone this repository and at the main folder execute command:
cd SwarmPackagePy/
python setup.py install
Bacterial Foraging Optimization
Description
The Bacterial Foraging Optimization, proposed by Passino is inspired by the social foraging behavior of Escherichia coli (next E.coli).<br> During foraging of the real bacteria, locomotion is achieved by a set of tensile flagella. Flagella help an E.coli bacterium to tumble or swim, which are two basic operations performed by a bacterium at the time of foraging. When they rotate the flagella in the clockwise direction, each flagellum pulls on the cell. That results in the moving of flagella independently and finally the bacterium tumbles with lesser number of tumbling whereas in a harmful place it tumbles frequently to find a nutrient gradient. Moving the flagella in the counterclockwise direction helps the bacterium to swim at a very fast rate. In the above-mentioned algorithm the bacteria undergoes chemotaxis, where they like to move towards a nutrient gradient and avoid noxious environment. Generally the bacteria move for a longer distance in a friendly environment.<br> When they get food in sufficient, they are increased in length and in presence of suitable temperature they break in the middle to from an exact replica of itself. This phenomenon inspired Passino to introduce an event of reproduction in BFO. Due to the occurrence of sudden environmental changes or attack, the chemotactic progress may be destroyed and a group of bacteria may move to some other places or some other may be introduced in the swarm of concern. This constitutes the event of elimination-dispersal in the real bacterial population, where all the bacteria in a region are killed or a group is dispersed into a new part of the environment.<br> Bacterial Foraging Optimization has three main steps:
- Chemotaxis
- Reproduction
- Elimination and Dispersal
Mathematical model
Chemotaxis: This process simulates the movement of an E.coli cell through swimming and tumbling via flagella. Biologically an E.coli bacterium can move in two different ways. It can swim for a period of time in the same direction or it may tumble, and alternate between these two modes of operation for the entire lifetime. Reproduction: The least healthy bacteria eventually die while each of the healthier bacteria (those yielding lower value of the objective function) asexually split into two bacteria, which are then placed in the same location. This keeps the swarm size constant. Elimination and Dispersal: Gradual or sudden changes in the local environment where a bacterium population lives may occur due to various reasons e.g. a significant local rise of temperature may kill a group of bacteria that are currently in a region with a high concentration of nutrient gradients. Events can take place in such a fashion that all the bacteria in a region are killed or a group is dispersed into a new location. To simulate this phenomenon in BFO some bacteria are liquidated at random with a very small probability while the new replacements are randomly initialized over the search space.
Algorithm
<pre> BEGIN Initialize randomly the bacteria foraging optimization population Calculate the fitness of each agent Set global best agent to best agent FOR number of iterations FOR number of chemotactic steps FOR each search agent Move agent to the random direction Calculate the fitness of the moved agent FOR swimming length IF current fitness is better than previous Move agent to the same direction ELSE Move agent to the random direction END IF END FOR END FOR Calculate the fitness of each agent END FOR Compute and sort sum of fitness function of all chemotactic loops (health of agent) Let live and split only half of the population according to their health IF not the last iteration FOR each search agent With some probability replace agent with new random generated END FOR END IF Update the best search agent Calculate the fitness of each agent END </pre>Arguments
The bfo method accepts the following arguments:<br> param Nc number of chemotactic steps<br> param Ns swimming length<br> param C the size of step taken in the random direction specified by the tumble<br> param Ped elimination-dispersal probability<br>
Method invocation
The method can be invoked by passing the arguments in the following order:
SwarmPackagePy.bfo(n, function, lb, ub, dimension, iteration, Nc, Ns, C, Ped)
Gray Wolf Optimization
Description
The Gray Wolf Optimization algorithm mimics the leadership hierarchy and hunting mechanism of gray wolves in nature. Wolves live in a pack. The average pack consists of a family of 5–12 animals. wolves have strict social hierarchy which is represented by the division of a pack into four levels: alpha, beta, delta, and omega.<br> Alpha wolves are the leaders of their pack. They are responsible for making decisions, but sometimes alphas can obey to other wolfes of the pack.<br> Beta wolves help alphas make decisions, every beta is a candidate to become an alpha if an alpha has died or aged. A beta respects an alpha and transfers commands to the pack, ensures discipline among inferior wolves and provides a feedback from the pack to an alpha.<br> Delta wolves have to submit to alphas and betas, but they dominate the omega.<br> Finally, omega wolves have to obey all other wolves. Sometimes they play a role of caretakers.<br><br> Gray wolf hunting has three main phases:
- Tracking, chasing, and approaching the prey
- Pursuing, encircling, and harassing the prey until it stops moving
- Attack towards the prey
Mathematical model
In mathematical model of the social hierarchy of wolves is mapped to the solution fit. The fittest solution is considered to be the alpha. Beta and delta are the second and third best solutions respectively. The rest of the candidate solutions are assumed to be omega.<br> Alpha, beta and delta lead the hunting (optimization) and omega wolves follow these three wolves.
