Fun with genetic algorithms

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


Recent Entries

Comments

Oldest comments listed first.

Posted by: Moldy on December 12, 2008 at 9:58 AM

Has anyone else checked this genetic car out and just stared at it for hours? I am really curious how it works. Does each car only get to drive for a sent amount of time? Which variables are changed and how can I track the changes?


Posted by: biojae on December 12, 2008 at 10:38 PM

@Moldy When ever the dotted red circle touches the ground it reiterates


Posted by: Anonymous on December 14, 2008 at 12:38 AM

More genetic algorithms

The Mona Lisa one reminds me of something I hacked up once:

http://www.soe.ucsc.edu/~mds/genetic_trees/

Never did quite get it to do what I wanted -- but it worked great on synthetic data.


Leave a comment


Subscribe to MAKE!Subscribe to MAKE Magazine!

Subscribe today, save 42% and get web access to MAKE free. MAKE Digital Edition is available only to subscribers.

$34.95 / 1 year
(4 Quarterly Issues)

Subscribe now


Void your warranty, violate a user agreement, fry a circuit, blow a fuse, poke an eye out. Make: The risk-takers, the doers, the makers of things... Welcome to Make: Online!


CRAFT Maker Shed Maker Faire MAKE television
MAKE: en EspaƱol MAKE: Japan


Check out all of the episodes of Make: television

Make: Science Room

Connect with MAKE

Be a MAKE fan on Facebook MAKE on Facebook
Visit our Facebook page and become a fan of MAKE!
MAKE on Twitter MAKE on Twitter
Follow our MAKE tweets!
MAKE Flickr Pool MAKE on Flickr
Join our MAKE Flickr Pool!
    make_tips on Twitter

    MAKE's RSS feed is here.
    Add MAKE to iGoogle - GoogleGoogle.
    How to add MAKE to your RSS reader - Real simple.
    Add MAKE on FriendFeed




    Maker SHED

    Advertise here with FM.

    Why advertise on MAKE?
    Read what folks are saying about us!

    Click here to advertise on MAKE!



    Subscribe to MAKE Magazine!

    Make: Online authors!

    Gareth BranwynGareth Branwyn
    Senior Editor


    Phillip TorronePhillip Torrone
    Senior Editor
    | AIM | Twitter


    Becky SternBecky Stern
    Associate Editor
    | AIM | Twitter


    Marc de VinckMarc de Vinck
    Contributing Writer
    | AIM | Twitter


    John ParkJohn Park
    Contributing Writer
    | Twitter


    Sean RaganSean Ragan
    Contributing Writer
    | Twitter


    Matt MetsMatt Mets
    Contributing Writer
    | AIM | Twitter


    Dale DoughertyDale Dougherty
    Editor & Publisher
    | Twitter


    Shawn ConnallyShawn Connally
    Managing Editor
    | Twitter


    Goli MohammadiGoli Mohammadi
    Associate Managing Editor

    Kip KayKip Kay
    Weekend Projects
    | AIM | Twitter


    Collin CunninghamCollin Cunningham
    Contributing Writer
    | AIM | Twitter

    Adam FlahertyAdam Flaherty
    Contributing Writer
    | AIM | Twitter



    More contributors: Mark Frauenfelder (Editor-in-Chief, MAKE magazine), Kipp Bradford (Technical Consultant/Writer), Chris Connors (Education), Diana Eng (Guest Author), Peter Horvath (Intern), Brian Jepson (O'Reilly Media), Robert Bruce Thompson (Science Room)

    Suggest a Site!

    Current Podcast

    itunesdl.gif Weekend Project: Making Char Cloth Learn how to make a cheap and effective fire starter made from an old t-shirt. To download The Char Cloth video click here and subscribe in iTunes. See Char Cloth in action with the Fire Piston from William Gurstelle.... More...

    Get the Make: Online sent via email
    Enter your email to receive Make: Online each day:



    MAKE Fascination video series brought to you by Dow

    Make: Education

    Important please read


    Subscribe to MAKE Magazine!

    Recent Posts from the Craft: Blog