smart.rockets

 

At FlashBelt in June, I demoed a Flash application in which a population of rockets evolved to find the best path towards a target. I've polished that example up a bit and put it up for everyone to play with.

The rockets in this simulation have 5 engines, which, initially are positioned randomly around each rocket. The engines have a random strength, a random rotation, and also a random firing pattern – determining when the rocket will fire. A sample rocket might have a rotation of 90 degrees, a strength of 0.1, and a firing pattern of '1010101010101'. 

The rockets are trying to get to the target, using the least possible amount of fuel. Fitness is determined, then, by a combination of proximity to the target and leftover fuel. The fittest individuals from each generation are selected and hybridized to create a new batch of rockets.

Over generations, you'll see the rockets start to find the best path. If you leave it long enough, they should find the best possible path that uses the least amount of fuel.

You can control a variety of parameters for the simulation, through the text fields at the bottom left. The most important of these is mutation rate – see if you can figure out what the best rate of mutation is for optimizing the system.

I am going to have the source cleaned up for this before FFWD in September. If you want to get a crack at it sooner, please let me know and I can get you a .ZIP file.

I'd love to hear feedback, and suggestions for improvement… this was a fun project to build. 

Share:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Reddit
  • StumbleUpon
  • Tumblr
Bookmark the permalink. Follow any comments here with the RSS feed for this post. Post a comment or leave a trackback: Trackback URL.

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

3 Comments

  1. unknown
    Posted August 17, 2006 at 1:55 pm | Permalink

    haaa.. this is really fun to
    haaa.. this is really fun to watch.. and it would make a good screen-saver: back from the coffee break and see how smart the rockets became..

  2. unknown
    Posted August 23, 2006 at 11:34 am | Permalink

    Source code
    Quick question about the source code: While I'd love to see it all, what I really want to know is how you drew the paths of each rocket. I'm willing to wade thru the source if that's easier for you.

  3. unknown
    Posted August 23, 2006 at 12:08 pm | Permalink

    There are two parts to the
    There are two parts to the path-drawing:

    1) Actually drawing the rocket paths, using the drawing API
    2) Dumping the paths to a bitmap object periodically to prevent memory drain
    3) Slowly changing the colour of the paths to get some distinction between generations.

    1: In order for the rockets to draw their paths, they simply draw a line using the drawing API from their last known position to their current position. All of the rocket paths are drawn to the same MC, named ‘thecanvas_mc’. This code is, of course, called once per frame.


    _root.thecanvas_mc.moveTo(lastx, lasty);
    _root.thecanvas_mc.lineTo(_x, _y);
    lastx = _x;
    lasty = _y;

    2: With 25 rockets drawing a line once per frame, the sheer number of lines rises very quicky. Within a second, we have 750 lines. This will get out of control fast, draggin down the speed of our program. To remedy this, we ‘dump’ the line data from thecanvas_mc into a BitmapData object. This BitmapData object is rendered to screen.

    I am using an instance of my Canvas Class, which is available here.


    //setup:
    var can = new Canvas(_root);

    //drawing:
    doDraw = function() {
    can.etch(thecanvas_mc);
    thecanvas_mc.clear();
    };

    setInterval(doDraw, 100);

    3: To create a color gradient in the lines that are drawn, I simply adjust the values of R,G & B in the lines that are being drawn:


    //setup:
    r = 0;
    g = 0;
    b = 0;
    rv = Math.random() / 10;
    gv = Math.random() /10;
    bv = Math.random() /10;

    //drawing:
    doDraw = function() {
    can.etch(thecanvas_mc);
    thecanvas_mc.clear();

    r += rv;
    g += gv;
    b += bv;

    var c = argbtohex(25,r,g,b);
    thecanvas_mc.lineStyle(1, c, 10);
    };

    Hopefully this helps. If you still want to see the whole source, let me know.

    -Jer

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*