1

Im trying to make a traffic lights problem with mcrl2. I don't know if my code is 100% correct, but it compiles.

Basically i have 3 colors and 3 traffic lighters and with this code i can switch their colors, however i want to make restritions like, if one traffic light is green the others cannot change to any color, they can only change their color when the traffic light with green color change to yellow.


    sort
        Color = struct green | red | yellow;

    map
        next: Color -> Color;
    
    eqn
        next(green) = yellow;
        next(yellow) = red;
        next(red) = green;
    
    act
        toRed, toGreen,toRedYellow,toYellow;
    
    proc
        Lighter1 (c : Color) = (c == green) -> toYellow.Lighter1(next(c))
                             +(c == yellow) -> toRed.Lighter1(next(c))
                             +(c == red) -> toGreen.Lighter1(next(c));
    
        Lighter2 (c : Color) = (c == green) -> toYellow.Lighter2(next(c))
                             +(c == yellow) -> toRed.Lighter2(next(c))
                             +(c == red) -> toGreen.Lighter2(next(c));
    
        Lighter3 (c : Color) = (c == green) -> toYellow.Lighter3(next(c))
                             +(c == yellow) -> toRed.Lighter3(next(c))
                             +(c == red) -> toGreen.Lighter3(next(c));
    init
        Lighter1(green) || Lighter2(red) || Lighter3(green);
tbotl
  • 23
  • 6

0 Answers0