我正在尝试在Alloy制作交通灯模型。问题是我并不是很了解它。我一直在阅读分析仪发现的红绿灯示例,但出于某种原因它并没有给我任何实例。这是示例代码。
`module chapter4/lights ----- The model from page 127
abstract sig Color {}
one sig Red, Yellow, Green extends Color {}
sig Light {}
sig LightState {color: Light -> one Color}
sig Junction {lights: set Light}
fun redLights [s: LightState]: set Light { s.color.Red }
fun colorSequence: Color -> Color {
Color <: iden + Red->Green + Green->Yellow + Yellow->Red
}
pred mostlyRed [s: LightState, j: Junction] {
lone j.lights - redLights[s]
}
pred trans [s, s': LightState, j: Junction] {
lone x: j.lights | s.color[x] != s'.color[x]
all x: j.lights |
let step = s.color[x] -> s'.color[x] {
step in colorSequence
step in Red->(Color-Red) => j.lights in redLights[s]
}
}
assert Safe {
all s, s': LightState, j: Junction |
mostlyRed [s, j] and trans [s, s', j] => mostlyRed [s', j]
}
check Safe for 3 but 1 Junction`
如果有人可以解释一下,我会非常感激。
答案 0 :(得分:2)
要查看实例,您需要包含运行命令。这里唯一的命令是check命令,如果检查的属性为true,则不会找到反例。