简体   繁体   English

合金-#和Int

[英]Alloy - # and Int

I am a newbie in Alloy and would like to understand how # works in connection with the restrictions on Int. 我是Alloy的新手,想了解#与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 如果执行上面显示的(1),则某些解决方案违反了ringTopology中的#n.nearBy = 2限制,例如 在此处输入图片说明 For the same example, in the evaluator I get #Node4.nearby = -4 (minus 4!). 对于同一示例,在评估器中,我得到#Node4.nearby = -4(减4!)。 This does not happen with (2), where I get a unique and correct solution (10-node graph with a ring topology). (2)不会发生这种情况,在这里我得到了唯一且正确的解决方案(带有环形拓扑的10节点图)。

Thanks, Eduardo 谢谢,爱德华多

Which version of Alloy are you using? 您正在使用哪个版本的Alloy? 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. 最新版本的Alloy( Alloy 4.2_2015-02-22 )具有“防止溢出”选项(选项->防止溢出),可以防止这种情况的发生。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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