Skip to content

Instantly share code, notes, and snippets.

@y-taka-23
Last active December 3, 2021 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save y-taka-23/c7f8cdd865d53662863d0d2954afdca5 to your computer and use it in GitHub Desktop.
Save y-taka-23/c7f8cdd865d53662863d0d2954afdca5 to your computer and use it in GitHub Desktop.
Traffic signals with Alloy 6's temporal logic
module signal
enum LightState { On, Off, Blink }
abstract sig Light {
var state: one LightState
}
one sig Red, Green extends Light {}
pred stopToGo {
Red.state = On
Green.state = Off
Red.state' = Off
Green.state' = On
}
pred goToCaution {
Red.state = Off
Green.state = On
Red.state' = Off
Green.state' = Blink
}
pred cautionToStop {
Red.state = Off
Green.state = Blink
Red.state' = On
Green.state' = Off
}
pred step {
stopToGo || goToCaution || cautionToStop
}
pred spec {
Red.state = On
Green.state = Off
always step
}
cannotOnInTheSameTime: check {
spec => {
always !(Red.state = On && Green.state = On)
}
}
canGoInfinitelyManyTimes: check {
spec => {
always eventually {
Red.state = Off
Green.state = On
}
}
}
run { spec }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment