Skip to content

Revaycolizer/traffic-light-control-algorithm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Traffic Light System with Dynamic Timing

Problem Statement

Modern traffic intersections often suffer from inefficiencies due to static traffic light timings, leading to unnecessary congestion. The goal of this system is to create a dynamic traffic light controller that adapts based on the number of cars waiting at each road. The system should:

  • Detect the number of incoming cars per second on each road.
  • Allocate green light time dynamically based on traffic volume.
  • Ensure fairness and efficiency in managing road congestion.

Approach

This system simulates a smart intersection using an algorithm that:

  1. Tracks the number of cars arriving at each road per second.
  2. Determines which road has the highest traffic congestion.
  3. Allocates a green light dynamically, with a minimum of 5 seconds and a maximum of 30 seconds.
  4. Updates the system continuously as new cars arrive.

Implementation

The system is implemented in TypeScript, using an Intersect class to manage roads and their traffic conditions.

Key Components

1. Class Intersect

  • Manages intersections and their traffic data.
  • Stores historical data for decision-making.
  • Dynamically updates light timing based on traffic conditions.

2. Traffic Data Structure

  • intersects: An array representing each road's queue.
  • totalSumOfCars: Stores the total number of cars per road.
  • lastIndexReserve: Stores information about the last green light decision.

3. Decision Algorithm

  • Finds the road with the highest traffic.
  • Allocates green light based on traffic throughput.
  • Ensures fairness by not keeping any road waiting indefinitely.
green_time: The duration the traffic light stays green (e.g., 30 seconds).

car_length: The physical length of each car, in meters (e.g., 4.5m).

gap: The space between two cars when they are moving through the intersection, also in meters

alpha:  weight for passable cars

beta: weight for total cars

Compile

rustc main.rs

Run

./main

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages