A browser app that evolves vehicles using genetic algorithms, written in Rust and Bevy

Overview

Vehicle Evolver Deluxe

ko-fi

Demo

This is a simulation that uses AI (to be specific: genetic algorithms) to try to build better and better vehicles. The vehicles have to overcome an obstacle course, starting with some slight hills, followed by steeper hills, and finally some jumps. The vehicles are made out of panels and wheels, connected together, similar to the game Besiege, except in 2D.

Try the live web demo here. (needs a fast computer, on mobile browsers it'll run really slow, although Fennec seems faster than Chrome)

I made an in-depth video explaining how it works here. See the section below for a short summary.

Genetic algorithms

A quick rundown of how it works:

  1. The population of vehicles is initially randomly generated.
  2. The simulation is run on all vehicles. The further a vehicle makes it through the obstacle course, the higher its fitness gets. If the vehicle doesn't leave the starting area, it gets a fitness of 0. If the vehicle makes it all the way to the finish line, its fitness will be about 14 thousand. If the vehicle falls apart, its fitness is divided by 10, to punish it; vehicles should try to remain intact. Additionally, a timer is set, so vehicles only have a set amount of time to reach the finish line.
  3. The vehicles are run through a process of crossover and mutation, with fitter vehicles having a higher chance of being used as parents. The program uses tournament selection to select the parents, and one-point crossover to produce offspring from two parents (that means, given two parent vehicles A and B, the left-hand side of A is smashed together with the right-hand side of B, and vice versa, to create two new vehicles). Additionally, blocks are mutated uniformly (that means blocks are randomly picked and changed to either air, panel, or wheel). The result is a new population of vehicles, entering a new generation.
  4. Go to step 2. Repeat ad infinitum.

Ideally, after repeating these steps often enough, the fitness of the population should increase, and many vehicles should make it to the finish line. Although, due to the low population size, good solutions may not always be found. And, due to non-determinism (see Known Issues), the fitness may actually decrease over time.

Compiling from source

This program uses Rust, so ensure you have rustup and cargo installed, and cargo-make to allow for easy compilation to both native and WASM targets, so ensure you have that installed too. Also, if you want to build the web version, ensure you have the WASM target installed: rustup target add wasm32-unknown-unknown.

To run natively:

cargo make run -p release

To run for web: (connect to localhost:4000 in your browser after it's done compiling)

cargo make serve -p release

Known issues

  • The simulation is non-deterministic, which means the same vehicle can have different fitness scores when run multiple times. I'm not sure if this is an issue with my code or with bevy_rapier2d in general.
  • Due to small population sizes, the simulation may never find a good solution and get stuck in a local minimum. A larger population size is not feasible at the moment due to performance limitations.

License

MIT for now, although the program is based on bevy_webgl2_app_template, which doesn't have a license yet... so keep that in mind.

You might also like...
zine/book about bitmap drawing algorithms and math with code examples in Rust
zine/book about bitmap drawing algorithms and math with code examples in Rust

A Bitmapper's Companion - zine/book about bitmap drawing algorithms and math with code examples in Rust A small zine/book written in LaTeX. In progres

A Rust implementation the HOTP and TOTP Algorithms

xotp A Rust implementation the HOTP and TOTP Algorithms. HOTP was implemented in accordance with RFC4226 TOTP was implemented in accordance with RFC62

This library provides implementations of many algorithms and data structures that are useful for bioinformatics.

This library provides implementations of many algorithms and data structures that are useful for bioinformatics. All provided implementations are rigorously tested via continuous integration.

darwin-rs, evolutionary algorithms with rust
darwin-rs, evolutionary algorithms with rust

darwin-rs This library allows you to write evolutionary algorithms (EA) using the Rust programming language. Written by Willi Kappler, License: MIT -

This crate implements fast route planning algorithms in Rust.

This crate implements fast route planning algorithms in Rust. Algorithms Currently implemented: Contraction Hierarchies: The implementat

"Algorithms for approximate string matching" in Rust, with Python bindings.

ukkonen Implementation of a bounded Levenshtein distance by Esko Ukkonen in "Algorithms for approximate string matching" in Rust, with Python bindings

Algorithms implemented in Rust, explained.

Rusty Algorithms & Data Structures for Learners This repository presents Rust implementations of common algorithms and data structures, many of which

Bandit Algorithms in Rust
Bandit Algorithms in Rust

Multi-armed bandit algorithms in Rust Cargo [dependencies] bandit = "0.12.3" Description and Scope This library currently only implements the annealin

DSP algorithms for embedded. Often integer math.

This crate contains some tuned DSP algorithms for general and especially embedded use.

Comments
  • Max fitness not recorded properly

    Max fitness not recorded properly

    See attached screenshot sequence. First it shows that vehicle 04 in generation 24 scores over 10k. Then it shows that the summary from Generation 24 says the max as 4931, also the plot of the max reflects this lower value. The max should be 10022 or higher.

    Also, it in my case most of the vehicles were getting stuck in the same pit. Some vehicles would go most of the way up the ramp, then fall back into the pit. These vehicles seem closer to being able to get over the hump, but they score about the same fitness as vehicles that just fall into the pit from the left, but make no progress up the hill. It seems like you should score the further a vehicle makes it rather than the final resting spot of the vehicle to help them learn how to go over things better. Or maybe sort by both and take vehicles from the top of both lists for the next generation.

    image

    opened by ggggggggg 0
  • Game slowdowns do not affect timer

    Game slowdowns do not affect timer

    When the game slows down the timer speed seems to be unaffected, making it so that the same vehicle will make it much less far if the framerate begins to drop.

    It would seem more fair if the timer would be based on the speed of the simulation instead of actual time.

    opened by NinovanderMark 1
Owner
I make games and other stuff. Obsessed with Godot at the moment.
null
Radiate is a parallel genetic programming engine capable of evolving solutions to many problems as well as training learning algorithms.

Radiate Coming from Evolutionary Radiation. Evolutionary radiation is a rapid increase in the number of species with a common ancestor, characterized

kalivas 109 Dec 18, 2022
Genetic Algorithms Library

genx genx provides modular building blocks to run simulations of optimization and search problems using Genetic Algorithms (GA). The vision for genx i

Lakshya Singh 29 Aug 9, 2022
Example of a genetic algorithm in Rust and Python

Example of a genetic algorithm in Rust and Python Monkey typewriter Finding the phrase 'To be or not to be. That is the question.' Inspired by the exa

sotrh 2 Jan 27, 2022
Execute genetic algorithm (GA) simulations in a customizable and extensible way.

genevo genevo provides building blocks to run simulations of optimization and search problems using genetic algorithms (GA). The vision for genevo is

Innoave 110 Dec 21, 2022
Genetic Algorithm library in Rust

RsGenetic Summary and Features RsGenetic is a framework for executing genetic algorithms in Rust. It is designed to have a simple but modular API. Exa

Mathieu De Coster 74 Dec 27, 2022
nsga is an opinionated implementation of the NSGA-II (Non-dominated Sorting Genetic Algorithm)

nsga nsga is an opinionated implementation of the NSGA-II (Non-dominated Sorting Genetic Algorithm), a multi-objective genetic optimization algorithm.

Max Kuznetsov 8 Oct 1, 2022
Compare binary files using alignment algorithms

biodiff Compare binary files using alignment algorithms. What is this This is a tool for binary diffing. The tool is able to show two binary files sid

null 483 Dec 22, 2022
A tool used to evaluate the output of retrieval algorithms. Written in Rust.

Rusteval A tool used to evaluate the output of retrieval algorithms. Written in Rust. Building Install Rust with curl -sSf https://static.rust-lang.or

Giorgos Sfikas 17 Mar 22, 2022
Common data structures and algorithms for competitive programming in Rust

algorithm-rs algorithm-rs is common data structures and algorithms for competitive programming in Rust. Contents TBA How To Contribute Contributions a

Chris Ohk 16 Dec 21, 2022