Fun with genetic algorithms

Science Technology

galisa_20081210.jpg

A genetic algorithm provides a simple way to search for an approximately optimal solution for an otherwise difficult and complex problem. By simulating the process of evolution, random mutation, breeding and selective pressure, a program can evolve a solution to a problem.

Seth Just wrote in with a simple and customizable genetic algorithm written in Perl. Given a problem set, you can define a function to randomly initialize each “individual”, a mutation function to alter an individual, a breeding function that combines individuals with the strongest members, and a fitness function that computes the strength of an individual. His code is well documented and you can adapt it for your own problems fairly easily.

He also points us to a couple of interesting projects that are worth mentioning. The evolution of the Mona Lisa, pictured above, is an example genetic algorithm written by Roger Alsing. Given only 50 semi-transparent polygons and over 900 thousand mutations, his program is able to optimize their placement and color to produce an incredible likeness of the Mona Lisa.

geneticcar_20081210.jpg

Another cool example is this Flash vehicle simulator. A car with two wheels and two passengers is randomly constructed and its fitness is defined by how far it is able to drive without the passengers touching the ground. At first, most iterations don’t even get past go, but as the evolution proceeds, a more robust vehicle is formed which is capable of navigating the terrain.

Genetic Algorithms in Perl
Genetic Programming: Evolution of Mona Lisa
Genetic Car

What will the next generation of Make: look like? We’re inviting you to shape the future by investing in Make:. By becoming an investor, you help decide what’s next. The future of Make: is in your hands. Learn More.

Tagged
Discuss this article with the rest of the community on our Discord server!

ADVERTISEMENT

Escape to an island of imagination + innovation as Maker Faire Bay Area returns for its 16th iteration!

Prices Increase in....

Days
Hours
Minutes
Seconds
FEEDBACK