开发者

How can one express that a relationship must not be cyclic?

Consider a upgrades relationship:

How can one express that a relationship must not be cyclic?

I need to make sure tha开发者_Python百科t upgrades cannot be circular. How can I do that in Alloy?


It is sufficient to enforce transitivity and antireflexivity.

fact {
  no a: Item | a in a.upgrades
}

fact{
  all a,b,c: Item |
  a in b.upgrades and b in c.upgrades implies
  a in c.upgrades
}


From your example, I infer that the upgrades relation is not intended to be transitive: in the example, a diamond sword upgrades a stone sword, and a stone sword upgrades a wooden sword, but the pair WoodSword -> DiamondSword is not in the upgrades relation.

So what you want to say is something like

fact upgrades_acyclic {
  no x : univ | x in x.^upgrades
}

Some modelers prefer the more succinct formulation in terms of relations:

fact upgrades_acyclic { no ^upgrades & iden }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜