CPSC 333: Traffic Light Simulator

Location: [CPSC 333] [Ongoing Examples] Traffic Light Simulator

This page was most recently modified on February 10, 1997


Problem Statement

This system will simulate a traffic light (in one direction only). The user, a ``Traffic Light Manager,'' can request that the light be activated (turned on), that it change colour, or that it be deactivated.

When asked by the user to activate the light, the system will attempt to turn it on; if the light is off when this attempt is made then the light will be turned on. However, if the light was already on, this attempt will turn the light off.

Similarly, a request to deactivate the light will cause the light to be turned off it is currently on, and to turn it on if it is currently off.

In either of these cases, the system should return a brief ``status message'' to the user, informing the user of the state of the traffic light resulting from the system's attempt to activate or deactivate the light.

The user can also ask that the light change colour. On such an attempt, this should cause the light to change from red to green, or from green to yellow, or from yellow to red. If the light is off, then an attempt to ``change its colour'' should have no effect.

The system should report the light's new colour to the user after an attempt to change its colour, if the light was on, and the system should use a ``status message'' to report the problem to the user, after an attempt to change the light's colour when the light was off.

When the system is activated, the light will initially be off. Whenever a light is turned on, the colour it initially shows will be red.


References in Lectures

This system was considered in several lab exercises.


Requirements Specification

State-Transition Diagram

This diagram serves as the ``specification'' for the control process (#4) on the data flow diagram which follows it.

Picture of STD

Data Flow Diagram

This system is so small that we'll use only one data flow diagram to specify it:

Picture of DFD


Data Dictionary

Name: activate
Kind: CF
Type:
Description: Used by ``Traffic Manager'' to ask that the light be turned on
Name: change
Kind: CF
Type:
Desription: Used by system functions to request that the colour of the traffic light be changed
Name: change colour
Kind: CF
Type:
Description: Used by ``Traffic Manager'' to ask that the colour of the light be changed
Name: colour
Kind: DF
Type: [ `red' | `green' | `yellow' ]
Description: Used to report the new colour of the light to the ``Traffic Manager'' after a successful attempt to change it
Name: deactivate
Kind: CF
Type:
Description: Used by the ``Traffic Manager'' to ask that the light be turned off
Name: is green
Kind: CF
Type:
Description: Used to report (to system functions) that the traffic light is currently green
Name: is off
Kind: CF
Type:
Description: Used to report (to system functions) that the traffic light is currently off
Name: is red
Kind: CF
Type:
Description: Used to report (to system functions) that the traffic light is currently red
Name: is yellow
Kind: CF
Type:
Description: Used to report (to system functions) that the traffic light is currently yellow
Name: on/off
Kind: CF
Type:
Description: Used (by system functions) to switch the light on or off
Name: status message
Kind: DF
Type: string
Description: Used to report error messages and completion of operations to the ``Traffic Manager.''

[Problem Statement] [References in Lectures] [State-Transition Diagram] [Data Flow Diagram] [Data Dictionary]

Location: [CPSC 333] [Ongoing Examples]


Department of Computer Science
University of Calgary

Office: (403) 220-5073
Fax: (403) 284-4707

eberly@cpsc.ucalgary.ca