A2b4: halb fertig

This commit is contained in:
Johannes Theiner 2020-05-08 19:42:15 +02:00
parent 4690707634
commit 1931b23be0
6 changed files with 116 additions and 47 deletions

View File

@ -2,10 +2,12 @@
sort sort
CardinalDirection = struct north | east | south | west; CardinalDirection = struct north | east | south | west;
%-----------------------------------------------------------------------------
sort sort
Colour = struct red | green | yellow; Colour = struct red | green | yellow;
%Definition Farbliche Reihenfolge
map map
nextColour: Colour -> Colour; nextColour: Colour -> Colour;
@ -14,6 +16,7 @@ eqn
nextColour(green) = yellow; nextColour(green) = yellow;
nextColour(yellow) = red; nextColour(yellow) = red;
%------------------------------------------------------------------------------
act act
show : CardinalDirection # Colour; show : CardinalDirection # Colour;
@ -21,12 +24,12 @@ proc
TrafficLight(direction : CardinalDirection) = TF(direction, red); TrafficLight(direction : CardinalDirection) = TF(direction, red);
TF(direction : CardinalDirection, colour : Colour) = TF(direction : CardinalDirection, colour : Colour) =
show(direction, colour). show(direction, colour) . %zeige aktuellen Zustand
TF(direction, nextColour(colour)) TF(direction, nextColour(colour)) %zum nächsten Zustand wechseln
; ;
%-----------------------------------------------------------------------------
%Initialisation der seperaten Ampeln
init init
TrafficLight(north) || TrafficLight(east) || TrafficLight(south) || TrafficLight(west) TrafficLight(north) || TrafficLight(east) || TrafficLight(south) || TrafficLight(west)
; ;

View File

@ -3,14 +3,6 @@
sort sort
CardinalDirection = struct north | east | south | west; CardinalDirection = struct north | east | south | west;
map
otherDirection : CardinalDirection -> CardinalDirection;
eqn
otherDirection(north) = south;
otherDirection(south) = north;
otherDirection(east) = west;
otherDirection(west) = east;
%----------------------------------------------------------------------- %-----------------------------------------------------------------------
@ -19,18 +11,14 @@ sort
map map
nextColour: Colour -> Colour; nextColour: Colour -> Colour;
safeColour: Colour -> Colour;
eqn eqn
nextColour(red) = green; nextColour(red) = green;
nextColour(green) = yellow; nextColour(green) = yellow;
nextColour(yellow) = red; nextColour(yellow) = red;
safeColour(green) = red;
safeColour(red) = green;
safeColour(yellow) = red;
%------------------------------------------------------------------------ %------------------------------------------------------------------------
%die aktuellen Werte für die verschiedenen Ampeln werden in einer KeyValue Map gespeichert.
sort sort
Map = K -> V; Map = K -> V;
@ -72,14 +60,14 @@ proc
; ;
Monitor(status : Map) = Monitor(status : Map) =
((status(north) in {green, yellow} || status(south) in {green, yellow}) && (status(east) in {green, yellow} || status(west) in {green, yellow})) ((status(north) in {green, yellow} || status(south) in {green, yellow}) && (status(east) in {green, yellow} || status(west) in {green, yellow})) %ist aktueller Zustand unsicher ?
-> crossingUnsafe(status(north), status(east), status(south), status(west)) . delta -> crossingUnsafe(status(north), status(east), status(south), status(west)) . delta %unsicherer Zustand, deadlock
<> <>%wenn aktueller Zustand sicher:
sum direction : CardinalDirection.( sum direction : CardinalDirection.(
sum c : Colour . sum c : Colour .
seeColour(direction, c) . seeColour(direction, c) . %jede mögliche Kombination anbieten
Monitor(status= status[direction -> c]) Monitor(status= status[direction -> c])%und entsprechend speichern
); );
System = System =

View File

@ -3,15 +3,6 @@
sort sort
CardinalDirection = struct north | east | south | west; CardinalDirection = struct north | east | south | west;
map
otherDirections : CardinalDirection -> Set(CardinalDirection);
eqn
otherDirections(north) = {east, west};
otherDirections(south) = {east, west};
otherDirections(east) = {north, south};
otherDirections(west) = {north, south};
%----------------------------------------------------------------------- %-----------------------------------------------------------------------
sort sort
@ -19,7 +10,6 @@ sort
map map
nextColour: Colour -> Colour; nextColour: Colour -> Colour;
safeColour: Colour -> Colour;
eqn eqn
nextColour(red) = green; nextColour(red) = green;
@ -71,17 +61,18 @@ proc
sum c : Colour . sum c : Colour .
(c == green) -> (c == green) ->
(direction == north || direction == south) -> (direction == north || direction == south) ->
((status(east) == red && status(west) == red) -> ((status(east) == red && status(west) == red) -> % sind die anderen Ampeln rot ?
seeColour(direction, c) . Monitor(status= status[direction -> c])) seeColour(direction, c) . Monitor(status= status[direction -> c])) % dann darf fortgefahren werden
<> <>
((status(north) == red && status(south) == red) -> ((status(north) == red && status(south) == red) ->
seeColour(direction, c) . Monitor(status= status[direction -> c])) seeColour(direction, c) . Monitor(status= status[direction -> c]))
<> <> %soll nicht grün gezeigt werden kann einfach fortgefahren werden, es wurde ja bereits überprüft
seeColour(direction, c) . seeColour(direction, c) .
Monitor(status= status[direction -> c]) Monitor(status= status[direction -> c])
); );
System = System =
allow({ allow({
colourSeen colourSeen

View File

@ -0,0 +1,4 @@
<root>
<spec>v4_spec.mcrl2</spec>
<properties/>
</root>

View File

@ -0,0 +1,78 @@
%-----------------------------------------------------------------------
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
TrafficLight(direction : CardinalDirection) = TL(direction, red);
TL(direction : CardinalDirection, colour : Colour) =
(colour == red)
-> changeDirection(nextDirection(direction)) . TL(direction, nextColour(colour))
<> changeLight(nextColour(colour)) . show(direction, nextColour(colour)) . TL(direction, nextColour(colour))
;
System =
allow({
show,
%changeLight,
changedLight,
%changeDirection,
changedDirection,
emptyAct
},
comm({
changeDirection | changeDirection -> changedDirection,
changeLight | changeLight -> changedLight
},
TrafficLight(north) || TrafficLight(east) || TrafficLight(south) || TrafficLight(west)
));
init
System
;

View File

@ -67,17 +67,22 @@ act
proc proc
VM(credit : Int) = VM(credit : Int) =
(credit < 200) -> sum c : Coin.accept(c).VM(credit + value(c)) %Coins akzeptieren, solange credit < 2€ (credit < 200) ->
sum c : Coin
.accept(c).VM(credit + value(c)) %Coins akzeptieren, solange credit < 2€
+ (credit > 0) -> returnChange(credit).ReturnChange(credit)%Geld zurückgeben wenn credit > 0 + (credit > 0) ->
returnChange(credit).ReturnChange(credit)%Geld zurückgeben wenn credit > 0
+ sum p : Product.( + sum p : Product.(
(credit >= price(p)) -> offer(p).serve(p).VM(credit - price(p))%Produkt anbieten, wenn genug credit (credit >= price(p)) ->
offer(p).serve(p).VM(credit - price(p))%Produkt anbieten, wenn genug credit
); );
ReturnChange(credit : Int) = ReturnChange(credit : Int) =
sum c : Coin.((credit >= value(c) && credit < next(c)) -> %größt möglichen Coin ermitteln sum c : Coin.(
(credit >= value(c) && credit < next(c)) -> %größt möglichen Coin ermitteln
return(c).( %diesen zurückgeben return(c).( %diesen zurückgeben
((credit - value(c)) > 0) %wenn noch Geld übrig ((credit - value(c)) > 0) %wenn noch Geld übrig
-> ReturnChange(credit - value(c)) %dieses zurückgeben -> ReturnChange(credit - value(c)) %dieses zurückgeben