简体   繁体   中英

Alloy - # and Int

I am a newbie in Alloy and would like to understand how # works in connection with the restrictions on Int. Consider the following simple model for an undirected graph with no self-loops:

sig Node {
 nearBy : set Node
} 
fact { 
  no iden & nearBy  // irreflexive
  ~nearBy in nearBy // symmetric
}
pred connected[nodes : set Node ] {
  all n: Node | Node in n.*nearBy 
}
pred ringTopology[nodes : set Node ] {
 connected[nodes]
 all n: nodes | #n.nearBy = 2
}
run { // (1)
  ringTopology[Node]
} for exactly 5 Node
run { // (2)
  ringTopology[Node]
} for exactly 5 Node, 5 Int

If I execute (1) shown above some solutions violate the #n.nearBy = 2 restriction in ringTopology, eg 在此处输入图片说明 For the same example, in the evaluator I get #Node4.nearby = -4 (minus 4!). This does not happen with (2), where I get a unique and correct solution (10-node graph with a ring topology).

Thanks, Eduardo

Which version of Alloy are you using? It looks like you are getting that solution due to integer overflows. The latest version of Alloy ( Alloy 4.2_2015-02-22 ) has "Prevent Overflows" option (Options -> Prevent Overflows) which should prevent that from happening.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM