You will need the following libraries installed:
numpy
: Used for numerical operations. Install withpip install numpy
.imageio
: Provides an easy interface to read and write a wide range of image data. Install withpip install imageio
.matplotlib
: A plotting library which offers similar functionality to MATLAB. Install withpip install matplotlib
.scikit-learn
: Machine learning library used in this script for calculating euclidean distances. Install withpip install scikit-learn
.opencv-python
: Open Source Computer Vision Library, used here for image processing tasks. Install withpip install opencv-python
.Shapely
: Used for manipulation and analysis of planar geometric objects. Install withpip install Shapely
.
Ensure you have the latest versions of these libraries to avoid any compatibility issues.
To run the script, you will need to define six variables.
In the genetic algorithm
itself:
iterations
: The number of iterations the genetic algorithm will run for. We have selected200
as a benchmark.swarm_size
: The population size used by the genetic algorithm to position a single worm within the image.20
is our benchmark.n_worms
: The number of worms to go into the image.200
is our benchmark.
In the cost function within the Fitness
class:
internal_weight
: The influence of the internal factors of the worm.group_weight
: The influence of group factors of the worm.environmental_weight
: The influence of environmental factors of the worm. All of these weight values default to 1, and produce decent results at this value.
-
Run through the notebook running each of the classes until you reach
Fitness
. At the bottom of the fitness class you will see:Wi = 1 Wg = 1 We = 1
tweak these values with your desired driver weights.
-
Keep running through the notebook until you reach
The Genetic Algorithm
. Towards the top you will see:iterations = 200 swarm_size = 30 num_swarms = 10
tweak these values to your liking.
-
Run
The Genetic Algorithm
code block and watch as the algorithm prints out its progress, yielding a final result.