Revision 2c7c650b4a5f752eb4ebd62b74ecd39cf13ad599 (click the page title to view the current version)
Traffic Light
This example demonstrates modeling of a simple Traffic Light state machine. Based on slide no. 3 from lecture presentation
The most simple example
- no concurrency,
- no forks,
- deterministic,
- no events,
- no time.
Traffic light model with transitions only
The constructs mean the following:
on -->> off:onlasts any number of steps, but must eventually becomeoff.off --> on:offlasts exactly one step.initial xor normal: every timeonstarts, it starts innormal, andinitial greenmakes it start ingreen. Re-enteringonstarts it again.normalhas no transition, because we do not want to force flashing:normalmay stay or switch toflashingat any step.flashing -->> normal:flashinglasts at least one step and must eventually end.green --> yellowand the others: the strict cycles inside a state.
Scenarios
A scenario is a concrete traffic light with a constraint on its
trace. A chain of transitions is a sequence, read from left to right,
and initially anchors it to the start of the trace. Without
initially, the chain would have to hold in every state of
the trace.
The scenario below is active on this page: the normal cycle, then flashing, then off.
It desugars to
[ initially (green && X (yellow && X (red && X (green && X (yellow_on && X (yellow_off && X off)))))) ]
All the Clafer code on a page forms one model, and all its concrete clafers exist at the same time. Therefore, the other scenarios are not part of the model of this page. To try one, open the model in the IDE and use it to replace the scenario above.
On, eventually flashing, and the flashing cycle:
t1 : TrafficLight_1
[ initially (on -->> flashing -->> yellow_on -->> yellow_off -->> yellow_on) ]
On, then flashing at the next step:
t2 : TrafficLight_1
[ initially (on --> yellow_on --> yellow_off --> yellow_on) ]
It desugars to
[ initially (on => X (yellow_on && X (yellow_off && X yellow_on))) ]
Observe, that the state after on is
yellow_on, and not flashing followed by
yellow_on. flashing starts in
yellow_on, so
on --> flashing --> yellow_on would require
yellow_on twice in a row, which
yellow_on --> yellow_off forbids.
On until yellow_off, then the flashing cycle step by
step:
t3 : TrafficLight_1
[ initially (on -->> yellow_off --> yellow_on --> yellow_off) ]