Coder Social home page Coder Social logo

traffic-simulator's Introduction

Traffic

Plot with traffic

The plot, when run, simulates traffic. The colors represent the number of vehicles on the road (albeit with no respect to the length of the road segment), as a percentage of the maximum-count road segment.

Hover events

Roads

Hover over roads to see their weights (the time in minutes it takes to travel across the node when no traffic is present)

Road hover tooltip

Intersections

Hover over intersections to see their latitude/longitude, and the number of vehicles currently queueing at that intersection. They also show an icon representing their type (๐Ÿšฆ: Traffic Light, ๐Ÿ›‘: Stop Sign, โ—ฏ: Roundabout )

Traffic light hover tooltip Stop sign hover tooltip Roundabout hover tooltip

Stop signs will also show which sides have stop signs. EW indicates that North-South traffic is free-flowing, while East-West traffic must stop. NS similarly indicates that East-West traffic is free-flowing, while North-South traffic must stop.

Generators

Hover over generators to see how much traffic is generated from that direction at that intersection.

Generator hover tooltip

Logic

Roads

Road weight increases depending on how many cars are on it following the equation: $w=(cars + 20) / 26.25$

Intersections

๐Ÿ›‘ Stop Signs (All-way)

Stop signs allow one car from one direction every 2 seconds, plus all cars that do not collide with it.

For example, if it's the North-bound traffic's turn, then the first North-bound car can go.

If it turns left, then the East-bound car can go if it is turning right, the South-bound car can go if it is turning left, and the West-bound car can go if it is turning right.

If it goes straight, then the East-bound car can go if it is turning right, the South-bound car can go if it is going straight (if the East-bound car didn't turn right) or turning right, and the West-bound car cannot go.

Etcetera.

Stop sign logic

Scenario 1: Left turn

Allowed:
 - EB right
 - SB left
 - WB right
    โœ“    โœ“
    โ†“ SB โ†‘
@โ†โ†   โ†˜  โ•ฐโ†โ†โ†โœ“
 EB  โ†–   โ†˜ WB
โœ“โ†’โ†’โ†’โ•ฎ  โ†–   โ†’โ†’โœ“
    โ†“ NB โ†‘
    โœ“    @

Scenario 2: Straight

Allowed:
 - SB right
 - EB right
 OR
 - SB straight
    โœ“    @            โœ“    @    
    โ†“ SB โ†‘            โ†“ SB โ†‘    
โœ“โ†โ†โ†โ•ฏ    โ†‘  โ†X     โ†  โ†“    โ†‘  โ†X
 EB      โ†‘ WB      EB โ†“    โ†‘ WB 
โœ“โ†’โ†’โ†’โ•ฎ    โ†‘  โ†’X    Xโ†’  โ†“    โ†‘  โ†’ 
    โ†“ NB โ†‘            โ†“ NB โ†‘    
    โœ“    @            โœ“    @    

Scenario 3: Right

3a: EB right
Allowed:
 - SB right
 - WB right
 OR
 - WB straight
                      X
    โ†“ SB โ†‘            โ†“ SB โ†‘        
 โ†โ†โ†โ•ฏ    โ•ฐโ†โ†โ†      โ†โ†โ†โ†โ†โ†โ†โ†โ†โ†โ†โ†     
 EB        WB      EB        WB     
#โ†’โ†’โ†’โ•ฎ    โ•ญโ†’โ†’โ†’@    #โ†’โ†’โ†’โ•ฎ    โ•ญโ†’โ†’โ†’@    
    โ†“ NB โ†‘            โ†“ NB โ†‘        
    #    @            #    @        
3b: EB left
Allowed:
 - SB right
 - WB left
    โœ“    #
    โ†“ SB โ†‘
โœ“โ†โ†โ†โ•ฏ  โ†—    โ†โœ“
 EB  โ†—  โ†™  WB
#โ†’โ†’   โ†™  โ•ญโ†’โ†’โ†’@
    โ†“ NB โ†‘
    โœ“    @

๐Ÿ›‘ Stop Signs (Tributary)

Stop signs can allow one car from tributaries every 2 seconds, while all cars from the primary roads continue through.

Cars are only allowed to continue through the intersection if they take an action that is not going to collide with present through-traffic.

๐Ÿšฆ Traffic Lights

Traffic lights have phases that can contain the following parts for each direction: left turns, right turns, straights, and left yields. Right yields are always assumed to be on. No phase can contain phase parts that collide with one another.

These phases are rotated through by the active PhaseController.

โ—ฏ Roundabouts

Roundabouts let one car through from each direction every 2 seconds.

Generators

Generators generate, on average (using a normal distribution), the given number of cars per minute.

Vehicles' destinations may be any intersection. Each intersection has a weight, increasing the odds of being selected as a destination.

Run Options

python w/ env

  • Open a Windows Command Prompt
    • Yes...it unfortunately has to be Windows, unless you want to make your own env that matches what I used
  • Run env\Scripts\activate
  • Run python app.py
  • Open localhost:8050

Visual Studio

  • Open Traffic.sln
  • Press Start Without Debugging (or use Ctrl+F5)
  • Open localhost:8050

traffic-simulator's People

Contributors

yodarocks1 avatar

Watchers

 avatar

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.