Parallele_Verteilte_Systeme/mCRL2/TrafiicLights/v2/v2_spec.mcrl2

104 lines
2.0 KiB
Plaintext

%-----------------------------------------------------------------------
sort
CardinalDirection = struct north | east | south | west;
map
otherDirection : CardinalDirection -> CardinalDirection;
eqn
otherDirection(north) = south;
otherDirection(south) = north;
otherDirection(east) = west;
otherDirection(west) = east;
%-----------------------------------------------------------------------
sort
Colour = struct red | green | yellow;
map
nextColour: Colour -> Colour;
safeColour: Colour -> Colour;
eqn
nextColour(red) = green;
nextColour(green) = yellow;
nextColour(yellow) = red;
safeColour(green) = red;
safeColour(red) = green;
safeColour(yellow) = red;
%------------------------------------------------------------------------
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;
%------------------------------------------------------------------------
act
show : CardinalDirection # Colour;
seeColour : CardinalDirection # Colour;
colourSeen : CardinalDirection # Colour;
crossingUnsafe : Colour # Colour # Colour # Colour;
%------------------------------------------------------------------------
proc
TrafficLight(direction : CardinalDirection) = TL(direction, red);
TL(direction : CardinalDirection, colour : Colour) =
show(direction, colour) . TL(direction, nextColour(colour))
;
Monitor(status : Map) =
((status(north) in {green, yellow} || status(south) in {green, yellow}) && (status(east) in {green, yellow} || status(west) in {green, yellow}))
-> crossingUnsafe(status(north), status(east), status(south), status(west)) . delta
<>
sum direction : CardinalDirection.(
sum c : Colour .
seeColour(direction, c) .
Monitor(status= status[direction -> c])
);
System =
allow({
colourSeen,
crossingUnsafe
},
comm({
show | seeColour -> colourSeen
},
TrafficLight(north) || TrafficLight(east) || TrafficLight(south) || TrafficLight(west) || Monitor(_Map(red))
));
init
System
;