%----------------------------------------------------------------------- sort CardinalDirection = struct north | east | south | west; map nextDirection: CardinalDirection -> CardinalDirection; eqn 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; wait; proceed; %------------------------------------------------------------------------ proc TrafficLight(direction : CardinalDirection) = (direction == north || direction == south) -> TL(direction, red) <> changeDirection(direction) . TL(direction, red) ; TL(direction : CardinalDirection, colour : Colour) = show(direction, colour) . %aktuellen Zustand zeigen (colour == red) %wenn rot -> wait . ChangeDirection(direction) %Richtungswechsel, wenn wieder zurück . ChangeLight(direction, colour) % -> zur nächsten Farbe wechseln. <> ChangeLight(direction, colour) %ansonsten zum nächsten Zustand wechseln. ; ChangeDirection(direction : CardinalDirection) = changeDirection(nextDirection(direction)) %nächste Richtung freigeben . changeDirection(direction) % -> warten bis eigene Richtung wieder freigegeben. ; ChangeLight(direction : CardinalDirection, colour : Colour) = changeLight(nextColour(colour)) %zur nächsten Farbe wechseln, wenn beide Richtungen dies autorisieren . TL(direction, nextColour(colour)) %fortfahren ; System = hide({%unnötige Informationen verstecken proceed, changedDirection, changedLight }, allow({ show, changedLight, changedDirection, proceed }, comm({ changeDirection | changeDirection -> changedDirection, changeLight | changeLight -> changedLight, wait | wait -> proceed }, TrafficLight(north) || TrafficLight(east) || TrafficLight(south) || TrafficLight(west) %starten der Prozesse ))); init System ;