简体   繁体   English

使用#无法实际计数(合金)进行计数

[英]Count using # not working in Fact (Alloy)

I am a beginner in Alloy (The Modelling Language made by MIT). 我是Alloy(麻省理工学院制作的建模语言)的初学者。 I am trying to model the leasing of a 2 bedroom apartment in Alloy. 我正在尝试对Alloy中2居室公寓的租赁进行建模。 I am trying to add a fact such that the number of people in each leased apartment is not more than 4. However the instance generated on running, still shows only one 2 bedroom leased apartment having 10 occupants. 我试图添加一个事实,使得每个租赁公寓中的人数不超过4。但是,在运行时生成的实例仍然显示只有一间2卧室租赁公寓,可容纳10人。 What am I doing wrong? 我究竟做错了什么? Also if possible could someone point to some good resources on learning Alloy apart from the tutorial on the MIT website? 另外,如果可能的话,除了麻省理工学院网站上的教程之外,还有人可以指出一些很好的学习Alloy的资源吗? Thanks. 谢谢。

abstract sig apartment {}

sig twoLeased extends apartment {
occupants: some People
} { #occupants < 5 }

sig twoUnleased extends apartment {

}

sig People {}

run {} for 3 but 4 twoLeased, 10 People

By default the bit width used to represent integers is 4 so your instance contains integers ranging from -8 to 7 . 默认情况下,用于表示整数的位宽为4,因此您的实例包含从-87整数。 In an instance where the number of occupant is 10, an integer overflow thus occur (as 10>8 ), #occupants returning a negative number it is thus inferior to 5 hence satisfying your invariant. 在乘员数量为10的情况下,整数溢出发生( 10>8 ), #occupants返回负数,因此它#occupants 5,因此满足您的不变性。

To fix this issue, you can either forbid integer overflow in the Alloy Analyzer settings or increase the bit width used to represent integers (eg run {} for 6 Int ). 要解决此问题,您可以在Alloy分析器设置中禁止整数溢出,或者增加用于表示整数的位宽度(例如, run {} for 6 Int )。

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

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