-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtraffic_lights.pml
189 lines (153 loc) · 6.75 KB
/
traffic_lights.pml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#define RED 0
#define GREEN 1
#define WEST_NORTH_REQUEST 0
#define EAST_WEST_REQUEST 1
#define SOUTH_WEST_REQUEST 2
#define NORTH_SOUTH_REQUEST 3
chan traffic_request_queue = [32] of {int};
int traffic_stoped_signal = -1;
int west_north_light, east_west_light, south_west_light, north_south_light = RED;
int west_north_traffic, east_west_traffic, south_west_traffic, north_south_traffic = 0;
chan lock_chan = [1] of {int};
ltl liveness_1 {[]((west_north_traffic == 1) && (west_north_light == RED) -> <>(west_north_light == GREEN))}
ltl liveness_2 {[]((east_west_traffic == 1) && (east_west_light == RED) -> <>(east_west_light == GREEN))}
ltl liveness_3 {[]((south_west_traffic == 1) && (south_west_light == RED) -> <>(south_west_light == GREEN))}
ltl liveness_4 {[]((north_south_traffic == 1) && (north_south_light == RED) -> <>(north_south_light == GREEN))}
ltl fairness_1 {[]<> !((west_north_light) && west_north_traffic)}
ltl fairness_2 {[]<> !((east_west_light) && east_west_traffic)}
ltl fairness_3 {[]<> !((south_west_light) && south_west_traffic)}
ltl fairness_4 {[]<> !((north_south_light) && north_south_traffic)}
proctype west_north_traffic_light() {
do
//wait until competitive directions are blocked with red light
:: traffic_request_queue ? [WEST_NORTH_REQUEST];
do
:: (east_west_light + south_west_light + north_south_light == 0);
west_north_light = GREEN;
printf("west-north light is green now\n");
break;
od;
traffic_request_queue ? WEST_NORTH_REQUEST;
//wait until traffic is stopped
do
:: (traffic_stoped_signal == WEST_NORTH_REQUEST);
traffic_stoped_signal = -1;
printf("west_north_light is red now\n");
west_north_light = RED;
break;
od;
od;
}
proctype east_west_traffic_light() {
do
//wait until competitive directions are blocked with red light
:: traffic_request_queue ? [EAST_WEST_REQUEST];
do
:: (west_north_light + south_west_light + north_south_light == 0);
east_west_light = GREEN;
printf("east-west light is green now\n");
break;
od;
traffic_request_queue ? EAST_WEST_REQUEST;
//wait until traffic is stopped
do
:: (traffic_stoped_signal == EAST_WEST_REQUEST);
traffic_stoped_signal = -1;
printf("east-west light is red now\n");
east_west_light = RED;
break;
od;
od;
}
proctype south_west_traffic_light() {
do
//wait until competitive directions are blocked with red light
:: traffic_request_queue ? [SOUTH_WEST_REQUEST];
do
:: (west_north_light + east_west_light + north_south_light == 0);
south_west_light = GREEN;
printf("south-west light is green now\n");
break;
od;
traffic_request_queue ? SOUTH_WEST_REQUEST;
//wait until traffic is stopped
do
:: (traffic_stoped_signal == SOUTH_WEST_REQUEST);
traffic_stoped_signal = -1;
printf("south-west light is red now\n");
south_west_light = RED;
break;
od;
od;
}
proctype north_south_traffic_light() {
do
//wait until competitive directions are blocked with red light
:: traffic_request_queue ? [NORTH_SOUTH_REQUEST];
do
:: (west_north_light + east_west_light + south_west_light == 0);
north_south_light = GREEN;
printf("north-south light is green now\n");
break;
od;
traffic_request_queue ? NORTH_SOUTH_REQUEST;
//wait until traffic is stopped
do
:: (traffic_stoped_signal == NORTH_SOUTH_REQUEST);
traffic_stoped_signal = -1;
printf("north-south light is red now\n");
north_south_light = RED;
break;
od;
od;
}
proctype traffic_generator() {
do
:: (west_north_traffic != 1 && west_north_light == RED);
printf("--->west-north traffic was started.\n");
west_north_traffic = 1;
traffic_request_queue ! WEST_NORTH_REQUEST;
:: (east_west_traffic != 1 && east_west_light == RED);
printf("--->east-west traffic was started.\n");
east_west_traffic = 1;
traffic_request_queue ! EAST_WEST_REQUEST;
:: (south_west_traffic != 1 && south_west_light == RED);
printf("--->south-west traffic was started.\n");
south_west_traffic = 1;
traffic_request_queue ! SOUTH_WEST_REQUEST;
:: (north_south_traffic != 1 && north_south_light == RED);
printf("--->north-south traffic was started.\n");
north_south_traffic = 1;
traffic_request_queue ! NORTH_SOUTH_REQUEST;
//--------------------stopping traffic--------------------------
:: (west_north_light == GREEN && west_north_traffic == 1);
printf("west-north traffic was stopped.\n");
west_north_traffic = 0;
traffic_stoped_signal = WEST_NORTH_REQUEST;
:: (east_west_light == GREEN && east_west_traffic == 1);
printf("east-west traffic was stopped.\n");
east_west_traffic = 0;
traffic_stoped_signal = EAST_WEST_REQUEST;
:: (south_west_light == GREEN && south_west_traffic == 1);
printf("south-west traffic was stopped.\n");
south_west_traffic = 0;
traffic_stoped_signal = SOUTH_WEST_REQUEST;
:: (north_south_light == GREEN && north_south_traffic == 1);
printf("north-south traffic was stopped.\n");
north_south_traffic = 0;
traffic_stoped_signal = NORTH_SOUTH_REQUEST;
od;
}
proctype verifier() {
//safety check
assert(west_north_light + east_west_light + south_west_light + north_south_light < 2);
}
init {
lock_chan ! 1;
run west_north_traffic_light();
run east_west_traffic_light();
run south_west_traffic_light();
run north_south_traffic_light();
run verifier();
run traffic_generator();
}