Fish schools based on the boids algorithm that evolve through an evolutionary algorithm.
The goal of this project was to evolve species of fish in a hostile environment consisting of sharks. In order to accomplish this evolution, it was developed an evolutionary algorithm that prioritizes the number of living individuals in each group of fish.
To simulate the behavior of a fish school, each specie was implemented based on the boids algorithm developed by Craig Reynolds. In short, the boids algorithm is ruled by three conditions : alignment, cohesion and separation.
The alignment rule states that an individual should point to the average direction of its neighbors. The following gif shows a fish school that only has the alignment behavior. The gray semi-circle represents the observable range of the black fish and the black lines at front of each fish represents the direction it is pointing towards.
The cohesion rule states that an individual should go towards the mass center of its neighbors. The following gif shows a fish school that only has the cohesion behavior and the red circle represents the mass center of the black fish's neighbors.
The separation rule states that an individual should avoid its neighbors when they are close. The following gif shows a fish school that only has the separation behavior and the red area represents the avoidance range of the black fish. For this specific project, the avoidance range was developed to be small than the visual range of each fish.
In this way, it is possible to simulate a similar behavior of fish schools using the alignment, cohesion and separation rules.
The population is composed by species of fish. Each specie is represented by a class named Boid
, which has the following main characterists :
alignmentWeigh
cohesionWeigh
separationWeigh
avoidSharkWeigh
These variables range from 5 to 100 and they represent the genes of a specie.
There are also other variables that define the color of the fish in the Boid
class, but they are only for aesthetic purpose and don't influence on the boid's behavior.
The fitness score is the sum of seconds that each fish survived. More specifically, a boid fitness score is calculated by the following equation :
Fitness Score = ∑ seconds fish_i survived
in which fish_i represents the i-th fish of the boid.
For this project, it was used the elitism, variable mutation and random predation techniques to evolve the population.
The elitism consists of taking the best individual (boid) of a generation and crossover it with every other individual. To perform the crossover between two individuals A and B, it is only necessary to calculate the mean values between each gene of A and B.
A normal mutation vary some or all genes of an individual by a fixed percentage value. Meanwhile, a variable mutation is basically a normal mutation that can change this percentage value depending on some situations.
The random predation consists of taking the worst individual (boid) of a generation and substitute it with a complete random individual.
For details about the evolution analysis and a better explanation of the evolutionary methods : analysis
For details about the installation : installation
Here is a video briefly explaining the whole project (in Portuguese) : video