Parallele_Verteilte_Systeme/mCRL2/TrafficLights/v2/v2_spec.mcrl2

120 lines
2.7 KiB
Plaintext
Raw Normal View History

2020-04-27 17:42:44 +02:00
%-----------------------------------------------------------------------
sort
CardinalDirection = struct north | east | south | west;
2020-05-17 11:28:29 +02:00
map
nextDirection: CardinalDirection -> CardinalDirection;
oppositeDirection : CardinalDirection -> CardinalDirection;
eqn
nextDirection(north) = east;
nextDirection(east) = south;
nextDirection(south) = west;
nextDirection(west) = north;
oppositeDirection(north) = south;
oppositeDirection(south) = north;
oppositeDirection(east) = west;
oppositeDirection(west) = east;
2020-04-27 17:42:44 +02:00
%-----------------------------------------------------------------------
sort
Colour = struct red | green | yellow;
map
nextColour: Colour -> Colour;
eqn
nextColour(red) = green;
nextColour(green) = yellow;
nextColour(yellow) = red;
2020-04-30 14:40:28 +02:00
%------------------------------------------------------------------------
2020-05-08 19:42:15 +02:00
%die aktuellen Werte f<>r die verschiedenen Ampeln werden in einer KeyValue Map gespeichert.
2020-04-30 14:40:28 +02:00
sort
Map = K -> V;
map
_Map: V -> Map;
var
k: K;
v: V;
eqn
_Map(v)(k) = v;
sort
K = CardinalDirection;
V = Colour;
map
combinations: Map;
2020-05-17 11:28:29 +02:00
%------------------------------------------------------------------------
map
unsafe : Map # CardinalDirection -> Bool;
2020-04-30 14:40:28 +02:00
2020-05-17 11:28:29 +02:00
var
status: Map;
direction: CardinalDirection;
eqn
unsafe(status, direction) = ((status(direction) in {green, yellow} || status(oppositeDirection(direction)) in {green, yellow})
&& (status(nextDirection(direction)) in {green, yellow}
|| status(oppositeDirection(nextDirection(direction))) in {green, yellow}));
2020-04-27 17:42:44 +02:00
%------------------------------------------------------------------------
act
show : CardinalDirection # Colour;
2020-04-30 14:40:28 +02:00
seeColour : CardinalDirection # Colour;
colourSeen : CardinalDirection # Colour;
2020-04-27 17:42:44 +02:00
crossingUnsafe : Colour # Colour # Colour # Colour;
%------------------------------------------------------------------------
proc
2020-04-30 14:40:28 +02:00
TrafficLight(direction : CardinalDirection) = TL(direction, red);
2020-04-27 17:42:44 +02:00
2020-04-30 14:40:28 +02:00
TL(direction : CardinalDirection, colour : Colour) =
show(direction, colour) . TL(direction, nextColour(colour))
2020-04-27 17:42:44 +02:00
;
2020-04-30 14:40:28 +02:00
Monitor(status : Map) =
2020-05-17 11:28:29 +02:00
(unsafe(status, north)) %ist aktueller Zustand unsicher ?
2020-05-08 19:42:15 +02:00
-> crossingUnsafe(status(north), status(east), status(south), status(west)) . delta %unsicherer Zustand, deadlock
2020-04-30 14:40:28 +02:00
2020-05-08 19:42:15 +02:00
<>%wenn aktueller Zustand sicher:
2020-04-30 14:40:28 +02:00
sum direction : CardinalDirection.(
sum c : Colour .
2020-05-08 19:42:15 +02:00
seeColour(direction, c) . %jede m<>gliche Kombination anbieten
Monitor(status= status[direction -> c])%und entsprechend speichern
);
2020-04-30 14:40:28 +02:00
System =
allow({
colourSeen,
crossingUnsafe
},
comm({
show | seeColour -> colourSeen
},
TrafficLight(north) || TrafficLight(east) || TrafficLight(south) || TrafficLight(west) || Monitor(_Map(red))
));
2020-04-27 17:42:44 +02:00
init
2020-04-30 14:40:28 +02:00
System
2020-04-27 17:42:44 +02:00
;