Parallele_Verteilte_Systeme/mCRL2/TrafficLights/v4/v4_spec.mcrl2

88 lines
2.1 KiB
Plaintext
Raw Normal View History

2020-05-08 19:42:15 +02:00
%-----------------------------------------------------------------------
sort
CardinalDirection = struct north | east | south | west;
map
oppositeDirection: CardinalDirection -> CardinalDirection;
nextDirection: CardinalDirection -> CardinalDirection;
eqn
oppositeDirection(north) = south;
oppositeDirection(south) = north;
oppositeDirection(east) = west;
oppositeDirection(west) = east;
nextDirection(north) = east;
nextDirection(east) = south;
nextDirection(south) = west;
nextDirection(west) = north;
%-----------------------------------------------------------------------
sort
Colour = struct red | green | yellow;
map
nextColour: Colour -> Colour;
eqn
nextColour(red) = green;
nextColour(green) = yellow;
nextColour(yellow) = red;
%------------------------------------------------------------------------
act
show : CardinalDirection # Colour;
changeLight: Colour;
changedLight: Colour;
changeDirection: CardinalDirection;
changedDirection: CardinalDirection;
emptyAct;
%------------------------------------------------------------------------
proc
2020-05-10 10:19:29 +02:00
TrafficLight(direction : CardinalDirection) = TL(direction, red, true);
2020-05-08 19:42:15 +02:00
2020-05-10 10:19:29 +02:00
TL(direction : CardinalDirection, colour : Colour, firstStart : Bool) =
(firstStart)
-> changeDirection(direction) . ChangeLight(direction, colour)
<>
show(direction, colour) .
(colour == red)
-> ChangeDirection(direction) . ChangeLight(direction, colour)
<> ChangeLight(direction, colour)
;
ChangeDirection(direction : CardinalDirection) =
changeDirection(nextDirection(direction)) . changeDirection(direction)
2020-05-08 19:42:15 +02:00
;
2020-05-09 19:33:04 +02:00
ChangeLight(direction : CardinalDirection, colour : Colour) =
2020-05-10 10:19:29 +02:00
changeLight(nextColour(colour)) . TL(direction, nextColour(colour), false)
2020-05-09 19:33:04 +02:00
;
2020-05-08 19:42:15 +02:00
System =
allow({
show,
%changeLight,
changedLight,
%changeDirection,
changedDirection,
emptyAct
},
comm({
changeDirection | changeDirection -> changedDirection,
changeLight | changeLight -> changedLight
},
2020-05-09 19:33:04 +02:00
TrafficLight(north) || TrafficLight(east) || TrafficLight(south) || TrafficLight(west) || changeDirection(north) || changeDirection(south)
2020-05-08 19:42:15 +02:00
));
init
System
;