在 Alloy 中强加一个单独的属性为空

Impose a lone attribute to be empty in Alloy

我想知道实际上是否有办法强制签名的属性为空。我尝试过这种方式,但它似乎不起作用:

sig C {
 myattribute: lone Type
}

信号类型{ att1: 整数 att2:......等.. }

fact {
    all c: C| 
        (my condition) 
        <=>
        (
            no c.myattribute
        )
}

至于现在我们可以考虑这样定义一个带有抽象签名的结构:

abstract sig GeneralType {}
one sig Empty extends GeneralType {}
sig NotEmpty extends GeneralType {...arguments (att1,2....}

如果权限 my condition,现有代码应该已经可以工作了。 (wmeyer 的建议确实是正确的。)

您可以测试您的约束以确保它的行为符合您的预期:

sig Type { }

sig C {
    myattribute: lone Type
}

fact {
    all c: C | no c.myattribute
}

run { } for 5

check {
    all c: C | no c.myattribute
} for 5