简体   繁体   English

Alloy Analyzer 4.2(Mac)与Alloy API

[英]Alloy Analyzer 4.2 (mac) versus alloy api

I am currently making a program that processes some annotations in java and then builds an alloy model, parses it using the alloy api and then runs some alloy commands. 我目前正在制作一个程序,该程序在Java中处理一些注释,然后构建一个合金模型,使用Alloy api对其进行解析,然后运行一些Alloy命令。 When I test the generated alloy model in the alloy app it works fine and gives me the expected results. 当我在Alloy应用程序中测试生成的合金模型时,它可以正常工作,并给了我预期的结果。 However, when I run the generated alloy model through the API, it tells me: "You must specify a scope for sig this/ObjectName". 但是,当我通过API运行生成的合金模型时,它会告诉我:“您必须为该this / ObjectName指定一个范围”。 I read the alloy code from a string like this. 我从这样的字符串中读取合金代码。

world = CompUtil.parseOneModule(String model);

The only options I use are the SAT4J solver and a skolemdepth of 1. 我使用的唯一选项是SAT4J解算器,并且skolemdepth为1。

I then iterate over the commands from world, translates them to kodkod, and executes them. 然后,我遍历世界上的命令,将其转换为kodkod并执行它们。

for(Command command: world.getAllCommands()) {
    A4Solution ans = null;
        try {
            ans = TranslateAlloyToKodkod.execute_command(rep, world.getAllReachableSigs(), command, options);
        } catch (Err ex) {
            Logger.getLogger(AlloyTest.class.getName()).log(Level.SEVERE, null, ex);
        }
}

My UPDATED alloy code looks like this: 我的UPDATED Alloy代码如下所示:

module mvc
// General model
abstract sig Configuration { elements: set Element }
abstract sig Element { references: set Element }

// MVC Style
abstract sig Model extends Element { }
abstract sig View extends Element { }
abstract sig Controller extends Element { }

pred mvc_model_style [c: Configuration] {
all m: c.elements & Model | all r: m.references | r not in View
}
pred mvc_view_style [c: Configuration] {
all view: c.elements & View | all ref: view.references | ref not in Model
}

pred mvc_controller_style [c: Configuration] {
    all controller: c.elements & Controller | all ref: controller.references | ref in Model or ref in View or ref in Controller
}

pred mvc_style [c: Configuration]{
 mvc_model_style[c] mvc_view_style[c]
}
one sig testMvc extends Configuration { } {
elements = TestController + ViewTest + TestModel + TestController3
}
one sig TestController extends Controller { } {
references = TestController + TestModel
}
one sig ViewTest extends View { } {
references = TestController
}
one sig TestModel extends Model { } {
references = ViewTest + TestController3
}
one sig TestController3 extends Controller { } {
references = TestController + TestModel
}
assert testcontroller {
mvc_controller_style[testMvc]
}
assert viewtest {
mvc_view_style[testMvc]
}
assert testmodel {
mvc_model_style[testMvc]
}
assert testcontroller3 {
mvc_controller_style[testMvc]
}
check testcontroller for 8 but 1 Configuration
check viewtest for 8 but 1 Configuration
check testmodel for 8 but 1 Configuration
check testcontroller3 for 8 but 1 Configuration

So does anybody have any idea for how I can fix this, as I thought that the for 1 Configuration, 8 Elements would set the scope for all the extending sigs? 那么,有人对我该如何解决这个问题有任何想法,因为我认为1配置8元素将为所有扩展信号设置范围。

Edit* 编辑*

I updated my alloy model with the suggestions and I stil get the same error: "You must specify a scope for sig "this/Controller" The above alloy code works in the Alloy Analyzer and gives this result: 我用建议更新了我的合金模型,但仍然出现相同的错误:“您必须为sig“ this / Controller”指定范围。上面的合金代码在Alloy Analyzer中起作用,并给出以下结果:

Executing "Check testcontroller for 8 but 1 Configuration"
   Solver=sat4j Bitwidth=0 MaxSeq=0 SkolemDepth=1 Symmetry=20
   83 vars. 26 primary vars. 98 clauses. 5ms.
   No counterexample found. Assertion may be valid. 1ms.

Executing "Check viewtest for 8 but 1 Configuration"
   Solver=sat4j Bitwidth=0 MaxSeq=0 SkolemDepth=1 Symmetry=20
   65 vars. 25 primary vars. 75 clauses. 5ms.
   No counterexample found. Assertion may be valid. 0ms.

Executing "Check testmodel for 8 but 1 Configuration"
   Solver=sat4j Bitwidth=0 MaxSeq=0 SkolemDepth=1 Symmetry=20
   65 vars. 25 primary vars. 75 clauses. 5ms.
   found. Assertion is invalid. 6ms.

Executing "Check testcontroller3 for 8 but 1 Configuration"
   Solver=sat4j Bitwidth=0 MaxSeq=0 SkolemDepth=1 Symmetry=20
   83 vars. 26 primary vars. 98 clauses. 6ms.
   No counterexample found. Assertion may be valid. 0ms.

Your Alloy model contains syntax errors, so you couldn't run it using the Alloy Analyzer either. 您的Alloy模型包含语法错误,因此您也无法使用Alloy Analyzer运行它。

First of all, the correct way to specify scope for your testcontroller check is this 首先,指定测试控制器检查范围的正确方法是

check testcontroller for 8 but 1 Configuration

This means "for 8 atoms of everything, but 1 atom of Configuration", whereas what you wrote doesn't event parse. 这意味着“对于所有事物的8个原子,但对于配置1个原子”,而您编写的内容不是事件解析的。

Next, the mvc_controller_style predicate is undefined, which will also cause you problems. 接下来,未定义mvc_controller_style谓词,这也会导致您遇到问题。

As for your API usage, just change parseOneModule to parseEverything_fromFile and it should work. 至于您的API使用情况,只需将parseOneModule更改为parseEverything_fromFile ,它应该可以工作。 I would also expect parseOneModule to work in this case (because there is only one module in your model), but it just doesn't, because, for some reason, some names don't get properly resolved. 我也希望parseOneModule在这种情况下可以工作(因为您的模型中只有一个模块),但实际上却没有,因为某些原因,某些名称无法正确解析。 I'm not sure whether that's a bug or maybe that method is not supposed to be part of the public API. 我不确定这是一个错误还是该方法不应该成为公共API的一部分。 Anyway, here is my code that worked properly for your example: 无论如何,这是我的代码可以正确地用于您的示例:

public static void main(String[] args) throws Exception {
    A4Reporter rep = new A4Reporter();

    Module world = CompUtil.parseEverything_fromFile(rep, null, "mvc.als");
    A4Options options = new A4Options();
    options.solver = A4Options.SatSolver.SAT4J;
    options.skolemDepth = 1;

    for (Command command : world.getAllCommands()) {
        A4Solution ans = null;
        try {
            ans = TranslateAlloyToKodkod.execute_commandFromBook(rep, world.getAllReachableSigs(), command, options);
            System.out.println(ans);
        } catch (Err ex) {
            Logger.getLogger(AlloyTest.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

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

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