two traffic lights

How can we coordinate two traffic lights in a particular application?

Let’s consider the following deployment:

Two traffic light deployment

So, we need two lights configured such that the east-west light has a left green arrow but the west-east light does not.

To be able to do that, we need to make the TrafficLight into an abstraction and instantiate it twice with different options:

EastWest : TrafficLight
WestEast : TrafficLight

We group remaining options for the entire deployment:

Here’s the new version of the TrafficLight concept.

Now, TrafficLight is an abstraction, which has it’s own local lamps and signals.

abstract TrafficLight
red : Lamp
yellow : Lamp
green : Lamp
leftGreenArrow : Lamp ?
rightGreenArrow : Lamp ?
arrowsOff ?
emergencyVehicle ?
xor TrafficSignals
[ emergencyVehicle => if allWayYellow then some allYellow else some warning ]
prepareToStop
[ red.off ]
[ yellow.on ]
[ green.off ]
stop
[ red.on ]
[ yellow.off ]
[ green.off ]
warning
[ red.off ]
[ green.off ]
prepareToGo
[ red.on ]
[ yellow.on ]
[ green.off ]
allYellow
[ red.off ]
[ green.off ]

How can we coordinate the traffic lights? What are the rules?

Simple traffic light coordination could be done by pairing the lights as opposites. From the point of view of EastWest, what should the opposite light show per signal in our particular application?

  • proceed: the same
  • prepareToStop: the same
  • stop: the same
  • warning: the same
  • prepareToGo: the same
  • allStop: the same
  • allYellow: the same
  • advancedLeft: stop
  • extendedLeft: stop

We can express these using rules:

Let’s check the allowed states of our system in our application:



Module Statistics: | All clafers: 53 | Abstract: 2 | Concrete: 51 | Reference: 0 | Constraints: 82 | Goals: 0 | Global scope: 1..* | Can skip name resolver: no |

Module Downloads: | [.cfr] | [.html] |

Exercise 3

So far, we only covered the coordination of opposite lights in our concrete two-light deployment example. The next step is to generalize these coordination rules to arbitrary deployments. The opposite relationship can be modeled using reference clafers. See opposite traffic lights sketch. Then the rules can be expressed using the opposite reference instead of the concrete WestEast or EastWest clafers.

Model the opposite light coordination according to the sketch.

Exercise 4

In a general, we must also coordinate crossing lights.

four-way intersection

Elicit and express the crossing lights coordination rules. First, express the rules on the concrete example. Next, similarly to the opposite traffic lights sketch, generalize the rules.

Conclusion of Part III

In this part, we configured an example two light application and formulated traffic lights coordination rules. Now that the concepts and behavior of the individual traffic lights and various deployment configurations are understood, we can proceed towards the implementation.

This concludes the tutorial.

Back to Front Page.

Complete Model

Part I: Domain Features

TrafficLightSystem
Lamps
Red
Yellow
Green
LeftGreenArrow ?
RightGreenArrow ?
countdownTimer ?
[ no USA ]
redAndYellowToGreen ?
allWayFlashingRedAsStop ?
allWayYellow ?
[ no USA ]
or advancedOrExtendedLeft ?
greenFlashing
leftArrow
xor mountLocation
inFront
behind
xor orientation
vertical
horizontal
xor Jurisdiction
Europe
UK ?
mux NorthAmerica
USA
Canada
Quebec ?
Australia
NewZealand

Part II: Domain Concepts

abstract xor Lamp
on
off
flashing