SkillAgentSearch skills...

SwarmPackagePy

Library of swarm optimization algorithms.

Install / Use

/learn @SISDevelop/SwarmPackagePy
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

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

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 &nbsp;Initialize randomly the bacteria foraging optimization population &nbsp;Calculate the fitness of each agent &nbsp;Set global best agent to best agent &nbsp;FOR number of iterations &nbsp;&nbsp;FOR number of chemotactic steps &nbsp;&nbsp;&nbsp;FOR each search agent &nbsp;&nbsp;&nbsp;&nbsp;Move agent to the random direction &nbsp;&nbsp;&nbsp;&nbsp;Calculate the fitness of the moved agent &nbsp;&nbsp;&nbsp;&nbsp;FOR swimming length &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IF current fitness is better than previous &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Move agent to the same direction &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ELSE &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Move agent to the random direction &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;END IF &nbsp;&nbsp;&nbsp;&nbsp;END FOR &nbsp;&nbsp;&nbsp;END FOR &nbsp;&nbsp;&nbsp;Calculate the fitness of each agent &nbsp;&nbsp;END FOR &nbsp;&nbsp;Compute and sort sum of fitness function of all chemotactic loops (health of agent) &nbsp;&nbsp;Let live and split only half of the population according to their health &nbsp;&nbsp;IF not the last iteration &nbsp;&nbsp;&nbsp;FOR each search agent &nbsp;&nbsp;&nbsp;&nbsp;With some probability replace agent with new random generated &nbsp;&nbsp;&nbsp;END FOR &nbsp;&nbsp;END IF &nbsp;&nbsp;Update the best search agent &nbsp;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.

Algorithm

<pre> BEGIN &nbsp;&nbsp;Initialize randomly the gray wolf population &nbsp;&nbsp;Find 1st, 2nd and 3rd best agents (&alpha;, &beta;, &delta;) &nbsp;&nbsp;Set global best agent to the 1st best agent &nbsp;&nbsp;Calculate the fitness of each search agent &nbsp;&nbsp;WHILE count &lt; max number of iterations &nbsp;&nbsp;&nbsp;&nbsp;FOR each search agent &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Update te position of the current search agent &nbsp;&nbsp;&nbsp;&nbsp;END FOR &nbsp;&nbsp;&nbsp;&nbsp;Update &alpha;, &beta; and &delta; &nbsp;&nbsp;&nbsp;&nbsp;Calculate the fitness of all search agents &nbsp;&nbsp;&nbsp;&nbsp;Update the best search agent, the 2nd best serach agent, and the 3rd best search agent &nbsp;&nbsp;&nbsp;&nbsp;ADD 1 to count &nbsp;&nbsp;END WHILE &nbsp;&nbsp;RETURN the best search agent END </pr
View on GitHub
GitHub Stars139
CategoryDevelopment
Updated10d ago
Forks79

Languages

Python

Security Score

80/100

Audited on Mar 27, 2026

No findings