Skip to content

Simulation in Pygame of a AI Self-driving car learning how to drive properly in four different tracks with a help of a Genetic Algorithm (Natural Selection, Cross Over and Mutation methods)

License

Notifications You must be signed in to change notification settings

fabioo29/ai-self-driving-car

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


AI self-driving car using a genetic algorithm

Problem Solving Challenges :: Search in Complex Environments :: Fundamentals of AI

Table of Contents

  1. About
  2. Testing
  3. Setup
  4. Simulation
  5. License
  6. Contact

About

Population learning (firsts GENs) Cars driving by itselfs (GEN 173)
Product Name Screen Shot Product Name Screen Shot

Motivation: Academic project for Fundamentals of Artificial Intelligence, M2AI. Use a evolutionary algorithm to learn how to drive a car in a complex environment with the following polynomial function as a controller for the car (w_1a + w_2b + w_3c + w_4ab + w_5ac + w_6bc + w_7a2 + w_8*b2 + w_9*c**2). w_x being the weights the respective agent chromosome genes and 'a,b and c' the distance sensors values.

Implementation: Interface was build using Pygame(2D game package for python). The genetic algorithm process consists in Selection, Cross Over, Mutation and bonus step (Random Agents) to avoid population convergence. Later on, was implemented to the game a car with a different behavior from the others (controlled by a PID controller) in order to swipe out the cars with unwanted behaviors (like spinning cars). There's also a car that can be controlled by the user.

Tested with with four different tracks [Easy, Medium, Medium-Hard and Hard]

Built With Pygame (Python framework for games)

PID Cleaner car

PIDCar cleaning slow cars PIDCar vs Self-driving Agent
Product Name Screen Shot Product Name Screen Shot

Setup

 install Requirements with:
    $ pip install -r requirements.txt

Simulation

usage: main.py [-h] [-t TRACK] [--user-test] [--agent-test] [--show-cleaner]
           [--show-simulation] [-p POPULATION] [-fps FPS] [-gif]

optional arguments:
  -h, --help            show this help message and exit
  -t TRACK, --track TRACK
                        racing track to be used on the simulation. {Default:
                        None(Random track)}
  --user-test           spawn car that can be controlled by user. {Default:
                        False}
  --agent-test          test the simulation with only the best car. {Default:
                        False}
  --show-cleaner        show the car used to draw the Cleaning line. {Default:
                        False}
  --show-simulation     show the population evolving in a simulation.
                        {Default: True}
  -p POPULATION, --population POPULATION
                        how many cars for each generation. {Default: 100}
  -fps FPS              frames per second. {Default: 30}
  -gif, --export-gif    export gif with agent driving in four tracks + bonus.
                        {Default: False}

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Fábio Oliveira - LinkedIn - [email protected]

Project Link: https://github.com/fabioo29/ai-self-driving-car
Project built as a Msc. Applied Artificial Intelligence Student.

About

Simulation in Pygame of a AI Self-driving car learning how to drive properly in four different tracks with a help of a Genetic Algorithm (Natural Selection, Cross Over and Mutation methods)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published