简体   繁体   English

合金中的 sig 文字

[英]sig literals in Alloy

How can I write out a literal for a sig in Alloy?如何在 Alloy 中为 sig 写出文字? Consider the example below.考虑下面的例子。

sig Foo { a: Int }
fact { #Foo = 1 }

If I execute this, I get如果我执行这个,我得到

| this/Foo | a |
|----------|---|
| Foo⁰     | 7 |

In the evaluator, I know I can get a reference to the Foo instance with Foo$0 but how can I write a literal that represents the same value?在评估器中,我知道我可以使用Foo$0获得对Foo实例的引用,但是如何编写表示相同值的文字?

I've tried {a: 7} , but this is not equal to Foo$0 .我试过{a: 7} ,但这不等于Foo$0 This is intentionally a trivial example, but I'm debugging a more complex model and I need to be able to write out literals of sigs with multiple fields.这是一个简单的例子,但我正在调试一个更复杂的模型,我需要能够写出具有多个字段的 sig 文字。

Ah, this is one of the well hidden secrets!啊,这是深藏不露的秘密之一! :-) Clearly in your model you cannot refer to atoms since the model is defining all possible values of those atoms. :-) 显然在你的模型中你不能引用原子,因为模型定义了这些原子的所有可能值。 However, quite often you need your hands on some atom to reason about it.然而,很多时候你需要你的一些原子上来推理它。 That is, you want to be able to name some objects.也就是说,您希望能够命名一些对象。

The best way to get 'constants' is to create a predicate you call from a run clause.获得“常量”的最佳方法是创建一个从run子句调用的谓词。 In this predicate, you define names for atoms you want to discuss.在这个谓词中,您为要讨论的原子定义名称​​。 You only have to make sure this predicate is true .您只需确保此谓词为true

pred collision[ car1, car2 : Car, road : Road ] {
   // here you can reason about car1 and car2
}
run collision for 10

Another way is to create a quantification whenever you need to have some named objects:另一种方法是在需要一些命名对象时创建量化:

run  {
   some car1, car2 : Car, road : Road {
      // here you can reason about car1 and car2 and road
   }
} for 10

There was a recent discussion to add these kinds of instances to the language so that Kodkod could take advantage of them. 最近有一次讨论将这些类型的实例添加到语言中,以便Kodkod可以利用它们。 (It would allow faster solving and it is extremely useful for test cases of your model.) However, during a discussion this solution I presented came forward and it does not require any new syntax. (它可以更快地解决问题,并且对于模型的测试用例非常有用。)但是,在讨论期间,我提出的这个解决方案出现了,它不需要任何新语法。

try to put a limitation for 'Integer' in the 'run' command.尝试在“运行”命令中限制“整数”。 I mean :我的意思是 :

sig Foo {a : Int}
fact{ #Foo = 1}

pred show {}
run show for 1 Foo, 2 Int

具有 Foo = 1 值的实例

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

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