Consider a simple intersection with two crossing roads and four traffic lights. Assume a simple algorithm for switching lights, so that the traffic on one road can proceed while the traffic on the other road is stopped. Model each traffic light as an instance of a TrafficLight class with a state attribute that can be either red, yellow, or green. Write invariants in OCL on the state attribute of the TrafficLight class that guarantee that the traffic cannot proceed on both roads simultaneously. Add associations to the model to navigate the system, if necessary. Note that OCL constraints are written on classes (as opposed to instances).

What will be an ideal response?


We add an association called right to denote the traffic light on the road to the right. Hence, the expression
right.right denotes the opposing light.

/* Opposing lights have always the same state */
context TrafficLight inv:
state = right.right.state
/* If the current light is green or yellow, the light on the right must be red */
context TrafficLight inv:
(state = #green or state = #yellow) implies right.state = #red

Computer Science & Information Technology

You might also like to view...

Distinguish the use of the square brackets [] in a definition of an array and their use for access to some indexed variable of the array.

What will be an ideal response?

Computer Science & Information Technology

Define fragmentation and explain why it is used.

What will be an ideal response?

Computer Science & Information Technology

It's important to remember that Twitter is a(n) ________ social network

Fill in the blank(s) with correct word

Computer Science & Information Technology

If you need to make changes to an existing hyperlink, right-click the link in Design view, thenselect Hyperlink ____________________ from the shortcut menu.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology