Skip to content

A genetic algorithm that attempts to get a swarm of dots from the start point to the end goal in the least number of steps

License

Notifications You must be signed in to change notification settings

UvinduW/Smart-Dots

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Smart Dots

A genetic algorithm that attempts to get a swarm of dots from the start point to the end goal in the least number of steps

This code is a Python implementation of the "Smart Dots" example/tutorial done by Code Bullet. He used the Processing language to build his version. You can view his detailed tutorial and project at:

YouTube: https://www.youtube.com/watch?v=BOZfhUcNiqk&index=19&list=WL&t=0s

GitHub: https://github.com/Code-Bullet/Smart-Dots-Genetic-Algorithm-Tutorial

A genetic algorithm that attempts to get a swarm of dots from the start point to the end goal in the least number of steps.

In each iteration of the algorithm, a new generation of dots are bred from the previous generation and mutations are introduced in the process to enhance genetic variety. Each parent dot will have a fitness value which is a measure of its performance and the offspring are more likely to get their "genes" from a parent with a higher fitness than a lower fitness. The offspring dot is generated by cloning a selected parent dot, and then introducing mutations with a specified probability.

The "genes" are actually acceleration vectors. Each dot has a "brain" which holds 400 acceleration vectors which specify the direction should accelerate in at each step. It's these vectors that get cloned, mutated and eventually optimised by the algorithm so that they end up holding the necessary vectors to direct the dot from start to finish. The algorithm rewards dots with a fitness score such that the highest rewards are achieved by dots that get to the goal (with a higher reward for fewer steps). For the dots that didn't get there, the dots that got closest get a higher score, but they won't be higher than dots that managed to reach the goal.

The Population class holds all the dots in the swarm. Each dot is an instantiation of the Dot class, which holds the attributes for each dot. Each dot has a brain, which is an instantiation of the Brain class. The brain holds all the direction vectors for that specific dot and a keeps track of the number of steps the dot has taken (and therefore which direction it needs to retrieve next from its list of direction vectors). The brain holds 400 direction vectors.

Usage:

Simply run the script and watch the swarm improve in each iteration. You can alter the configurables given to alter the behaviour of the script and algorithm.

About

A genetic algorithm that attempts to get a swarm of dots from the start point to the end goal in the least number of steps

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages