DEV Community

Cover image for Self-Parking Car in <500 Lines of Code

Self-Parking Car in <500 Lines of Code

Oleksii Trekhleb on September 28, 2021

Training the car to do self-parking using a genetic algorithm TL;DR In this article, we'll train the car to do self-parking using a g...
Collapse
 
aguilera51284 profile image
Arturo Aguilera

finally a post that is not about react :O!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Collapse
 
trekhleb profile image
Oleksii Trekhleb

Haha :D But! The Evolution Simulator is still built on top of React :D

Collapse
 
adi518 profile image
Adi Sahar

This is probably the sickest post I've seen on this site.

Collapse
 
jrgrenoble profile image
Jean-Rene Bouvier

Just brilliant! Out of curiosity, how long dit it take you to write this post (ideally, can you give elapsed time - to mature ideas - and actual time spent on writing) ?

Thanks a lot for taking the time to write this insightful article!

Collapse
 
trekhleb profile image
Oleksii Trekhleb

The issue is that the work on the article has happened in a "spare" from the main work time. So, it took ~5 month in a background to learn about Genetic Algorithm basics, learn about Three.js basics, implement the Evolution Simulator, experiment with parameters, optimise the algorithm and performance. And after that it took ~2 weeks to write the article.

Collapse
 
ben profile image
Ben Halpern

Wow, this is a fascinating read.

Collapse
 
trekhleb profile image
Oleksii Trekhleb

Thanks for kind words!

Collapse
 
jaytonic profile image
Jaytonic • Edited

Genetic algorithm is so interesting. I'm curious, on such example, do you spend more time on the genetic algorithm side or on the simulation side? I'm just wondering if there are some framework available for developing such solution, to have out-of-the-box things like you have below your simulator? Also, shouldn't we have the parking spot distance as a sensor? How would the car know to move forward or backward when not having a free spot in it's sensors?

Collapse
 
trekhleb profile image
Oleksii Trekhleb

Julien, I've spent most of the time to come up with the Evolution Simulator. The Genetic Algorithm basics andwriting the article took approximatelly ~1 month of background work.

The issue is that the work on the article has happened in a "spare" from the main work time. So, it took ~5 month in a background to learn about Genetic Algorithm basics, learn about Three.js basics, implement the Evolution Simulator, experiment with parameters, optimise the algorithm and performance. And after that it took ~2 weeks to write the article.

How would the car know to move forward or backward when not having a free spot in it's sensors

Current implementation of the parking function is really primitive, so it hardly adapts to the parking lot that is different from the one that you see in the Evolution Simulator. It also hardly adapts to the new initial car position. But, still, I belive what trained cars will do is they will move beckwards all the time until they find a free space. But again, to have a more sophisticated behavior of the cars we would probably need to use a Multilayer Perseptron as a brain function instead of over-simplified linear equation.

Collapse
 
jaytonic profile image
Jaytonic

Thanks, those domain are so interessant! Are you working in this field?

Thread Thread
 
trekhleb profile image
Oleksii Trekhleb

Yeah, the domain is pretty interesting. No, I don't work in this field. It is just a hobby for me.

Collapse
 
05bmckay profile image
05bmckay

Awesome work.

Collapse
 
trekhleb profile image
Oleksii Trekhleb

Thanks!

Collapse
 
haidarknightfury profile image
Haidar

Hello do you mind giving the roadmap to learn about it?

Collapse
 
trekhleb profile image
Oleksii Trekhleb

The article itself supposed to be kind of a roadmap about applying a genetic algorithm to a bit artificial but yet pretty fun task :)

Collapse
 
miqwit profile image
Mickaël A

Really cool, thanks!

Collapse
 
maurycyszmurlo profile image
Maurycy Szmurlo

Brilliant post!

Collapse
 
trekhleb profile image
Oleksii Trekhleb

Glad that you liked it!

Collapse
 
squidbe profile image
squidbe

Wow, this was fun, and I learned some things!

stand steel

I think you meant "stand still"

Collapse
 
trekhleb profile image
Oleksii Trekhleb

Fixed the text. Thanks for checking!

Collapse
 
lucianoborges profile image
Luciano Borges

Dude! That's an awesome post! It's the most complete that I have ever seen! Congratulations & thanks so much for it!

Collapse
 
trekhleb profile image
Oleksii Trekhleb

Thanks for such a response!

Collapse
 
john_canessa profile image
John Canessa

Very nice and informative. Keep them coming!

Collapse
 
trekhleb profile image
Oleksii Trekhleb

Gald that you liked it!

Collapse
 
smhnaji profile image
Mohammad Naji

Great article @trekhleb , when I was younger!, I had done some practices to schedule students and teachers times with PHP using GA.

Agian, thanks for sharing.

Collapse
 
trekhleb profile image
Oleksii Trekhleb

Thanks for the feedback 👍🏻