Using Genetic Evolutionary Algorithm for self parallel parking in Unity from scratch.
-
Create movement to the car: engine & steering wheel
-
Give sensor that calculate distance near the car
-
Give Brain to the car that takes in the sensor values and outputs the engine & steering wheel strength
-
Run the Genetic Algorithm (GA) for training and save the best Genome
- ⏰ Agent Life time
- 👾 Mutation probability, %
- 💪 Long-living champions, %
- 👩👨👧👦 Max Group size
- 📅 Max number of generations
- Initialization: Create diverse sets of genes representing 9 initial weights for engine and steering (Both in 10-bit structure: 1 sign bit, 4 exponent bits, and 5 mantissa bits).
- Fitness Evaluation: After reaching the
Agent Life time
, stop the movement and calculate theloss
(Distance to the target parking spot). - Selection: Sort the agent based on the loss and remove agents based on the
Long-living champions
(%). - Crossover (Mating): For the remaining agent, combine the genomes of selected parent cars in a 50/50 manner, allowing for the exchange of genetic material. This aims to produce improved offspring by inheriting the best features from their parents.
- Mutation: Introduce random mutations during mating, randomly flipping bits in the child genomes. This introduces variability, potentially leading to novel car behaviors.
Iteration: Repeat steps 2 to 5 until a stopping condition is met, such as reaching Max number of generations
or achieving the desired proximity to the parking spot (e.g., within 1 meter). If the condition is met, stop; otherwise, continue iterating to refine the car's self-parking abilities.
- Download the repository
- Open Scenes/Parallel Parking.unity scene
- Set the simulation setting you desire and run it.
- After training, Copy the best genome into AgentOptimal for testing.
Credit: 3D Model: https://assetstore.unity.com/packages/3d/vehicles/land/arcade-free-racing-car-161085#publisher