Skip to content

jeffersonfs/traffic-lights-control

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

86 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#Traffic lights control simulator

Project proposed and implemented during Scala Hackaton in Berlin

##Backlog

##Requirements:

  • models behaviour of traffic lights
  • works in real-time
  • can optimise throughput using different kinds of detectors
  • street layout is configurable

##Technologies:

  • Scala
  • Akka (main logic flow)
  • Spray (http service)
  • Html5 + AngularJs (frontend)
  • ScalaTest (tests)
  • Akka TestKit (tests)
  • SBT (build)

##Design:

  • all main components are Actors:

    • traffic lights TrafficLight models single traffic lights box with red, orange and green colours,
    • lights groups LightsGroupWithOnlyOneIsGreenStrategy groups traffic lights and governs them with "Only one may be green at the same time" strategy,
    • detectors TrafficDetector provides size of the queue on the lane
    • route directors TrafficDirector analyzes traffic and initializes lights change,
    • demo traffic system DemoTrafficSystem models simple crossroad with 4 directions,
    • http service HttpServiceActor provides /status resource with current traffic system state and index page with crossroad visualization.
  • all kinds of logic are implemented via messages flow (commands,querries,events)

##How to run demo app?

run command: $sbt re-start

open url in browser

##Description

Traffic control app uses message passing between asynchronous actors as a tool to model real-time traffic lights system. Few commands, querries and events forms control and supervision protocol. Demo implemented at hackaton represents simple crossroad but we took approach that allows design systems of a larger scale.

The innermost primitive component of a traffic system is a TrafficLight actor simulating red/orange/green signals using finite state machine. TrafficLight processes ChangeToRed, ChangeToGreen and GetStatusQuery. Light switching with orange blink phase is handled internally with scheduler. Externally are exposed ACK events: ChangedToRedEvent and ChangedToGreenEvent. StatusEvent is used by MonitoringActor to report system state via http service. TrafficLights are intended to be grouped by outer components like groups, managers, directors, etc.

About

Traffic lights control simulator (Akka)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Scala 91.0%
  • CSS 4.7%
  • HTML 4.3%