1) European Traffic Light

Traffic lights consist of three signals, transmitting meaningful information to road users through colours which are red to stop traffic, orange for traffic change, and green to allow traffic to proceed. In Europe, they follow the cycle: green, orange, red, green, orange, red, ...

Fig.1 - A simple example of a european traffic light (colours diagram are given for information purposes only).

The constants tG, tO, tR define the time allocated for the colours green, orange and red.

// C++ corresponding code, compile then run
// dot EuropeanTrafficLight.dot -Tpdf > EuropeanTrafficLight.pdf

Regular_Automaton EuropeanTrafficLight(3, 2, std::string("EuropeanTrafficLight"));
HillsAutomatonBuilder HA_Builder(EuropeanTrafficLight);

AutomatonPhase Red(Normal_Phase, std::string("currentColour=Red"), std::string(""), std::string("Tr"), std::string("red"));
AutomatonPhase Orange(Normal_Phase, std::string("currentColour=Orange"), std::string(""), std::string("To"), std::string("orange"));
AutomatonPhase Green(Normal_Phase, std::string("currentColour=Green"), std::string(""), std::string("Tg"), std::string("green"));
HA_Builder.addPhase(Green, Initial_Phase);
HA_Builder.addPhase(Orange);
HA_Builder.addPhase(Red);
HA_Builder.setTransition(Green, Orange, Internal_Transition, std::string("out ! Cars_STOP"));
HA_Builder.setTransition(Orange, Red, Internal_Transition, std::string("out ! Cars_STOP"));
HA_Builder.setTransition(Red, Green, Internal_Transition, std::string("out ! Cars_GO"));

std::string f2 = "./dot/" + EuropeanTrafficLight.getName() + ".dot";
std::ofstream ofs2(f2.c_str());
EuropeanTrafficLight.dumpGraphviz(ofs2, EuropeanTrafficLight.getName());
ofs2.close();

2) European Traffic Light with Failure

In this example, when the failure occurs, we need to switch off the traffic light and send a message warning the vehicles. To do so, we create a transient phase with its null sojourn time. The same thing happens when the failure is over. We insert another transient phase to switch on the traffic light and send a message saying that the cars can move forward safely again.

Fig.3 - An example of an european traffic light with a failure management (colours diagram are given for information purposes only).

// C++ corresponding code, compile then run
// dot EuropeanTrafficLightWithFailure.dot -Tpdf > EuropeanTrafficLightWithFailure.pdf

Regular_Automaton EuropeanTrafficLightWithFailure(6, 5, std::string("EuropeanTrafficLightWithFailure"));
HillsAutomatonBuilder HA_Builder(EuropeanTrafficLightWithFailure);

AutomatonPhase Red(Normal_Phase, std::string("currentColour=Red"), std::string(""), std::string("Tr"), std::string("red"));
AutomatonPhase Orange(Normal_Phase, std::string("currentColour=Orange"), std::string(""), std::string("To"), std::string("orange"));
AutomatonPhase Green(Normal_Phase, std::string("currentColour=Green"), std::string(""), std::string("Tg"), std::string("green"));
AutomatonPhase Prefailure(Transient_Phase, std::string("Pre-failure"), std::string(""), std::string(""), std::string("black"));
AutomatonPhase Failure(Passive_Phase, std::string("currentColour=Black"), std::string(""), std::string(""), std::string("black"));
AutomatonPhase Postfailure(Transient_Phase, std::string("Post-failure"), std::string(""), std::string(""), std::string("black"));

HA_Builder.addPhase(Green, Initial_Phase);
HA_Builder.addPhase(Orange);
HA_Builder.addPhase(Red);
HA_Builder.addPhase(Prefailure);
HA_Builder.addPhase(Failure);
HA_Builder.addPhase(Postfailure);
HA_Builder.setTransition(Green, Orange, Internal_Transition, std::string("out ! Cars_STOP"));
HA_Builder.setTransition(Green, Prefailure, External_Transition, std::string(" in ? off"));
HA_Builder.setTransition(Orange, Red, Internal_Transition, std::string("out ! Cars_STOP"));
HA_Builder.setTransition(Orange, Prefailure, External_Transition, std::string(" in ? off"));
HA_Builder.setTransition(Red, Green, Internal_Transition, std::string("out ! Cars_GO"));
HA_Builder.setTransition(Red, Prefailure, External_Transition, std::string(" in ? off"));
HA_Builder.setTransition(Prefailure, Failure, Internal_Transition, std::string("out ! Cars_WARNING"));
HA_Builder.setTransition(Failure, Postfailure, External_Transition, std::string(" in ? on"));
HA_Builder.setTransition(Postfailure, Green, Internal_Transition, std::string("out ! Cars_GO"));

std::string f2 = "./dot/" + EuropeanTrafficLightWithFailure.getName() + ".dot";
std::ofstream ofs2(f2.c_str());
EuropeanTrafficLightWithFailure.dumpGraphviz(ofs2, EuropeanTrafficLightWithFailure.getName());
ofs2.close();

3) Pedestrian Traffic Light

A pedestrian traffic light follows the cycle: green, blinking green, red, green, blinking green, red, .... When the pedestrian clicks the button, we need to switch from red to green. To do so, we create a transient phase with its null sojourn time with before, the click input, and after the output message to tell the pedestrians they can move forward.

Fig.4 - A pedestrian traffic light with a click button to switch on the green light (colours diagram are given for information purposes only).

// C++ corresponding code, compile then run
// dot PedestrianTrafficLight.dot -Tpdf > PedestrianTrafficLight.pdf

Regular_Automaton PedestrianTrafficLight(4, 3, std::string("PedestrianTrafficLight"));
HillsAutomatonBuilder HA_Builder(PedestrianTrafficLight);

AutomatonPhase Red(Normal_Phase, std::string("currentColour=Red"), std::string(""), std::string("Tr"), std::string("red"));
AutomatonPhase BlinkingGreen(Normal_Phase, std::string("currentColour=BlinkingGreen"), std::string(""), std::string("Tbg"), std::string("green"));
AutomatonPhase Green(Normal_Phase, std::string("currentColour=Green"), std::string(""), std::string("Tg"), std::string("green"));
AutomatonPhase Click(Transient_Phase, std::string("Click to get green"), std::string(""), std::string(""));
HA_Builder.addPhase(Green, Initial_Phase);
HA_Builder.addPhase(BlinkingGreen);
HA_Builder.addPhase(Red);
HA_Builder.addPhase(Click);
HA_Builder.setTransition(Green, BlinkingGreen, Internal_Transition, std::string("out ! Pedestrians_STOP"));
HA_Builder.setTransition(BlinkingGreen, Red, Internal_Transition, std::string("out ! Pedestrians_STOP"));
HA_Builder.setTransition(Red, Green, Internal_Transition, std::string("out ! Pedestrians_GO"));
HA_Builder.setTransition(Red, Click, External_Transition, std::string("in ? Click"));
HA_Builder.setTransition(Click, Green, Internal_Transition, std::string("out ! Pedestrians_GO"));

std::string f2 = "./dot/" + PedestrianTrafficLight.getName() + ".dot";
std::ofstream ofs2(f2.c_str());
PedestrianTrafficLight.dumpGraphviz(ofs2, PedestrianTrafficLight.getName());
ofs2.close();

4) Cars and Pedestrians Traffic Light 1

In this example, the pedestrian traffic light fully controls the cars traffic light.

Cars and Pedestrians Traffic Light

Fig.5 - A connection is made between both automata when a signal is sent from the pedestrian traffic light to the cars traffic light.

5) Cars and Pedestrians Traffic Light 2

The pedestrian traffic light sends a message to the cars traffic light when a pedestrian clicks the button to be able to cross the road. In this configuration, both lights for pedestrians and cars can be red at the same time.

Cars and Pedestrians Traffic Light

Fig.6 - A connection is made between both automata when a signal is sent from the pedestrian traffic light to the cars traffic light.