문제

Consider a upgrades relationship:

Incomplete order relationship

I need to make sure that 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 }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top