State Transitions: 4-Way Traffic Lights

 

The Model-View-Controller (MVC) pattern for software design can be employed to advantage in this context. Separating the data model from both the code and view frees the developer to focus the analysis of the problem at the lowest level.

A reasonable data model for the 4-way traffic light simulation is a state table. The entries in the table summarize the sequence of discrete data points and the most basic additional characteristics. Furthermore, close inspection of a finalized state table typically reveals efficiencies that inform controller development.

State RNS ANS GNS REW AEW GEW Binary Duration
0 HIGH=1 LOW=0 0 0 0 1 B100001 base
1 1 0 0 0 1 0 B100010 base/4 ?
2 1 0 0 1 0 0 B100100 base/2 ?
3 0 0 1 1 0 0 B001100 base
4 0 1 0 1 0 0 B010100 base/4 ?
5 1 0 0 1 0 0 B100100 base/2 ?