Giter Club home page Giter Club logo

concurrent_traffic_simulator's Introduction

Concurrent Traffic Simulation

This project is part of an advanced course taken at: Udacity C++ Nanodegree Program. The focus of the project is multithreading and thread-safe communication protocols.

In the simulator each intersection, traffic light and vehicle are distinct threads that runs concurrently.
Each vehicle is responsible for adjusting the speed with respect to the position in the street. Reached the intersection a separate task is responsible for adding the vehicle to the intersection queue. At the intersection it waits for authorization from the relative intersection thread before entering.
Each intersection based on the phase of the traffic light add or process the FIFO queue of the vehicles waiting to enter.
Each traffic light is responsible for cycling through a 4 to 6 seconds red or green phase and communicating the status to the relative intersection thread.

Below an overview of the data flow of the program, green dotted lines are thread creations and in the red you have the data exchange between threads.

Pseudo-code Schematic

Main C++ features used in the project are:

  • Object-Oriented-Programming: all the objects cited are inherited of a class trafficObject, each thread is an instance of a specific class
  • Shared pointers: for traking the ownership, and passing it to multiple entities automatically managing the deallocation process from the heap
  • Threads: parallel execution of differect functions; data exchange between threads (promises, futures)
  • Mutex: to avoid data races between threads and having a stable long-term communication channel
  • Condition Variables: to establish a message queue between intersections and traffic light, in order to freeze the execution of a thread till a new traffic light phase is not available

Dependencies for Running Locally

Basic Build Instructions

  1. Clone this repo.
  2. Make a build directory in the top level directory: mkdir build && cd build
  3. Compile: cmake .. && make
  4. Run it: ./traffic_simulation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.