Watch cars evolve using genetic algorithm
rednuht.org
rednuht.org
Still runs in the browser thanks to Ruffle:
Or perhaps, 20 years? ;-)
There were a few genetic algorithm "polygons approximate picture" pages back in that era as well.
It happened to crocodiles and it could happen to you too.
Edit, I scrolled down and it covers the genome:
• Shape (8 genes, 1 per vertex)
• Wheel size (2 genes, 1 per wheel)
• Wheel position (2 genes, 1 per wheel)
• Wheel density (2 genes, 1 per wheel) darker wheels mean denser wheels
• Chassis density (1 gene) darker body means denser chassis
It basically lands on a two-wheeled medium-bodied shape and doesn't seem to make much progress after that. Power and speed would be interesting variations.
I wasn't fooling. Think about it for a second, if your process involves a lot of crossover that means large sections of working genome will be passed on. If the ONLY mechanism for changing anything is mutation, then mostly you're just breaking what works.
That's what you're describing, so I'd look at how the genome is constructed to understand why it's not doing more.
The mutation rate (likelihood that g changes) and mutation size (Δg) are fun hyperparameters to tweak while watching the population evolve over time.
It would be interesting to see a gene for "compliance" so the cars could have some kind of suspension. EVerything more or less evolved into a sort of tron-bike shape for most of the runs I tried.
I ran it in the background for a very high mutation rate for a long time and it managed to come up with something very different---a little wheel attached to a big wheel, which bounces around and goes over all the obstacles.
https://news.ycombinator.com/item?id=5942757 (664 points | Jun 2013 | 169 comments)
https://news.ycombinator.com/item?id=10600486 (162 points | Nov 2015 | 57 comments)
The physics simulation clearly uses inelastic collisions, which is wildly unrealistic and why so many otherwise passable 'cars' don't pass the course. Also seems to use a very low coefficient of friction - most of my cars couldn't make it up a two-segement slope.
https://web.archive.org/web/20240428203838/http://boxcar2d.c...
Where I come from, we call two-wheeled automobiles motorbikes. Very cool simulation though!
It inspired me to experiment with a genetic algorithm in "Self-parking car evolution":
I don't know enough about genetic algorithms to say for certain. Anyone have any reference materials for someone that's just started looking into this?
I’ve done a bunch of playing around with NEAT, a variant of GA using NNs, for various things. Typically for GA stuff though you have a genome, aka some set of instructions for an individual, a fitness function for scoring them, and then you generate new individuals from those genomes for the next population.
Original Paper on NEAT here:
https://nn.cs.utexas.edu/downloads/papers/stanley.ec02.pdf
Lots of good resources here.
The new candidate might actually survive because its prior history kept it from ever getting into that particular death state, but I think biasing towards designs that don't immediately die in those hard cases is good anyways, since given a long enough run it would likely encounter a similar state.
One could co-evolve the test case collection by simulating only the best candidates according to the test cases, and then retaining test cases based on a running score for how well they predicted the actual performance.
That, or one BIG wheel, a very tiny second wheel, and almost no "body".
I don't know why they stay that way. My first thought would be that it might be beneficial for the shape to be relatively low for stability, but with the shape between the wheels being concave for clearance. That doesn't quite seem to happen, except for the concave clearance to an extent.
Maybe the rest of the shape doesn't really matter for the simulation, so there's no selective pressure towards not having a spiky shape.
My best guess is sort of adjacent to yours: a lot of cars flip on the initial drop and I think the spikes are helping them land right side up. Overfitting T=[0,1]
Oh, and they can affect the mass. If the grip of the wheels takes into account the normal force, extra weight may help with traction.
Hmm, and a 4th thing: some cars have a spike sticking out back behind the back wheels. These spikes sometimes function like wheelie bars, which are used on drag racers to prevent the car from flipping if the front end lifts off the ground. The wheelie bar kind of braces it but also lifts the traction wheels off the ground so they stop rotating it at the wrong moment.
To do it with a serious model of a genetic algorithm, you need crossover, not mutation. It's fun, but this is sort of a lottery of randomized cars with some capacity for copying winning ones over to successive runs.
Breed the cars ;)
There's a GitHub link at the bottom which gives us this:
https://github.com/red42/HTML5_Genetic_Cars/blob/master/src/...
And that seems to call into createCrossBreed() in here:
https://github.com/red42/HTML5_Genetic_Cars/blob/master/src/...
And that gets a parentChooser callback, which seems to be cw_chooserParent() from here:
https://github.com/red42/HTML5_Genetic_Cars/blob/master/src/...
And that has some swap points and a thing that toggles between parents when some index matches one of two values.
I'm not really a JS programmer or a GA expert, but it looks like crossover to me.