道路急转弯。
速度限制是40。
宝马可以轻松转弯。卡车可以转弯,还是会离开公路?
使用Alloy创建模型。
断言:所有车辆都可以转弯。
邀请合金分析仪查看该断言是否存在反例。
...
这是合金能做的吗?
如果是,请提供有关如何创建模型的提示,
答案 0 :(得分:1)
所有内容都可以在Alloy中建模,问题在于您是否正在尝试解决问题的正确抽象级别。
以下是一个示例,您可以如何抽象地模拟汽车制造急转弯并检查有关模型的各种断言:
enum Angle { a45, a90, a135 }
sig Turn {
angle: one Angle
}
sig Speed in Int {}
abstract sig Car {
canMake: Turn -> Speed
}
sig SportsCar extends Car {}
sig Truck extends Car {}
pred isSharpTurn[t: Turn] {
t.angle = a45
}
fun speedsUnder[limit: Int]: set Speed {
{s: Speed | s <= limit}
}
fact {
// speeds must be non-negative
Speed in {i: Int | i >= 0}
// sports cars can make any turn if going below 40
SportsCar -> Turn -> speedsUnder[40] in canMake
// any car can make any non-sharp turn if going below 40
Car -> {t: Turn | !isSharpTurn[t]} -> speedsUnder[40] in canMake
// any car can make any turn if going below 20
Car -> Turn -> speedsUnder[20] in canMake
}
pred allCarsCanMakeAllTurnsAtAllSpeeds {
all c: Car, t: Turn, s: Speed | c -> t -> s in canMake
}
// counterexample: car = Truck1, turn.angle = 45, speed = 127
check AllCarsCanMakeAllTurnsAtAllSpeeds {
allCarsCanMakeAllTurnsAtAllSpeeds
} for 3 but 8 Int
// counterexample: car = SportsCar1, turn.angle = 45, speed = 127
check GivenNoTrucks_AllCarsCanMakeAllTurnsAtAllSpeeds {
no Truck
implies allCarsCanMakeAllTurnsAtAllSpeeds
} for 3 but 8 Int
// counterexample: car = Truck1, turn.angle = 45, speed = 32
check GivenSpeedLimit40_AllCarsCanMakeAllTurnsAtAllSpeeds {
(all s: Speed | s <= 40)
implies allCarsCanMakeAllTurnsAtAllSpeeds
} for 3 but 8 Int
// no counterexample found
check GivenNoTrucksAndSpeedLimit40_AllCarsCanMakeAllTurnsAtAllSpeeds {
(no Truck and (all s: Speed | s <= 40))
implies allCarsCanMakeAllTurnsAtAllSpeeds
} for 3 but 8 Int
// no counterexample found
check GivenNoSharpTurnsAndSpeedLimit40_AllCarsCanMakeAllTurnsAtAllSpeeds {
((no t: Turn | isSharpTurn[t]) and (all s: Speed | s <= 40))
implies allCarsCanMakeAllTurnsAtAllSpeeds
} for 3 but 8 Int