怎么能表达一种关系不能循环?

时间:2010-11-17 16:38:13

标签: alloy

考虑upgrades关系:

Incomplete order relationship

我需要确保upgrades不能是循环的。我怎么能在Alloy中做到这一点?

2 个答案:

答案 0 :(得分:3)

强制传递性和反自反性就足够了。

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
}

答案 1 :(得分:2)

从你的例子中,我推断upgrades关系不是传递的:在这个例子中,一把钻石剑升级一把石剑,一把石剑升级一把木剑,但是这对木剑 - > DiamondSword不在upgrades关系中。

所以你要说的是

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

一些建模者更喜欢在关系方面更简洁的表述:

fact upgrades_acyclic { no ^upgrades & iden }