Rodin HandbookThis work is sponsored by the Deploy Project This work is sponsored by the ADVANCE Project This work is licensed under a Creative Commons Attribution 3.0 Unported License |
2.4.4 Building the ModelBack to the problem: Our objective is to build a simplified traffic light controller as described in 2.4. We start with the model state. Two traffic lights will be modelled, and we will therefore create two variables called cars_go and peds_go. 2.4.4.1 Creating VariablesUnder the MACHINE heading, you see the machine name mac. There is a small green arrow ( ) to the right of this label. Place your cursor directly to the left of the green arrow, right click, and select Add Child Event-B Variable to add a new variable. Optionally, you can also use the New Variable Wizard (the button ) to create your variable. By default, the variable is named var1. Place your cursor inside the var1 label. The label will then turn into a textbox. Change the name to cars_go. You can add a comment to the variable by placing your cursor to the right of the little green arrow and typing into the text box that appears.
Create the second variable (peds_go) in the same way, or place your cursor directly to the left of the small green arrow next to the label cars_go and hit either CTRL-T or right click and select Add Sibling from the menu. Upon saving, the variables will be underlined in red which indicates that an error is present as shown in Figure 2.7. The Rodin Problems view (3.1.2.5) shows corresponding error messages. In this case, the error message is “Variable cars_go does not have a type”. Invariants are needed in order to specify the type of variables. Use the method described above to add invariants to your machine (except this time select Add Child Event-B Invariant from the menu or click the button to open up the New Invariant Wizard). Add two invariants (which will automatically be labelled inv1 and inv2). The actual invariant appears to the left of the label and is prepopulated with the symbol , which represents the logical value “true”. Placing your cursor inside the invariant field will change it to a text field and allow editing. Change the first invariant (the symbol , not the label inv1) to and the second invariant to . Event-B provides the build-in datatype BOOL among others (3.3.1.1).
After saving, you should see that the INITIALISATION event is underlined in yellow with a small warning sign to the left as demonstrated in Figure 2.8. Again, the Rodin Problems view displays the error message: “Variable cars_go is not initialized”. Every variable must be initialized in a way that is consistent with the model. To fix this problem, place your cursor to the left of the small green arrow next to the label INITIALISATION. Right click and add an Event-B Action. Repeat to add another event. In the action fields, enter and . 2.4.4.2 State Transitions with EventsOur traffic light controller cannot yet change its state. To make this possible, we create two events (3.2.4.4) in the manner described above and name them set_peds_go and set_peds_stop. This will model the traffic light for the pedestrians, and for each of these, we will add an Event-B action to each of the events. These actions will change peds_go to TRUE or FALSE, which simulates the changing of the traffic light.
The two events will look as follows:
2.4.4.3 Event parametersFor the traffic light for the cars, we present a different approach and use only one event with a parameter. The event will use the new traffic light state as the argument. For this, we need to add an Event-B Event Parameter, which will appear under the heading ANY, and an Event-B Guard, which will appear under the heading WHERE:
Note how the parameter is used in the action block to set the new state. 2.4.4.4 InvariantsIf this model was actually in control of a traffic light, we would have a problem because nothing is preventing the model from setting both traffic lights to TRUE. The reason is that so far we only modeled the domain (the traffic lights and their states) and not the requirements. We have the following safety requirement: We can model this requirement with the following invariant: Please add this invariant with the label inv3 to the model (Use the ASCII codes not and & to get the symbols and ). Obviously, this invariant can be violated, and Rodin informs us of this. The Event-B Explorer (3.1.2.7) provides this information in various ways. Go to the explorer and expand the project (tutorial-03), the machine (mac) and the entry “Proof Obligations”. You should see four proof obligations, two of which are discharged (marked with ) and two of which are not discharged (marked with ).
To prevent the invariant from being violated (and therefore to allow all proof obligations to be discharged), we need to strengthen the guards (3.2.4.4.2) of the events.
2.4.4.5 Finding Invariant Violations with ProB
|