簡體   English   中英

Alloy Analyzer 4.2(Mac)與Alloy API

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

我目前正在制作一個程序,該程序在Java中處理一些注釋,然后構建一個合金模型,使用Alloy api對其進行解析,然后運行一些Alloy命令。 當我在Alloy應用程序中測試生成的合金模型時,它可以正常工作,並給了我預期的結果。 但是,當我通過API運行生成的合金模型時,它會告訴我:“您必須為該this / ObjectName指定一個范圍”。 我從這樣的字符串中讀取合金代碼。

world = CompUtil.parseOneModule(String model);

我使用的唯一選項是SAT4J解算器,並且skolemdepth為1。

然后,我遍歷世界上的命令,將其轉換為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);
        }
}

我的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

那么,有人對我該如何解決這個問題有任何想法,因為我認為1配置8元素將為所有擴展信號設置范圍。

編輯*

我用建議更新了我的合金模型,但仍然出現相同的錯誤:“您必須為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.

您的Alloy模型包含語法錯誤,因此您也無法使用Alloy Analyzer運行它。

首先,指定測試控制器檢查范圍的正確方法是

check testcontroller for 8 but 1 Configuration

這意味着“對於所有事物的8個原子,但對於配置1個原子”,而您編寫的內容不是事件解析的。

接下來,未定義mvc_controller_style謂詞,這也會導致您遇到問題。

至於您的API使用情況,只需將parseOneModule更改為parseEverything_fromFile ,它應該可以工作。 我也希望parseOneModule在這種情況下可以工作(因為您的模型中只有一個模塊),但實際上卻沒有,因為某些原因,某些名稱無法正確解析。 我不確定這是一個錯誤還是該方法不應該成為公共API的一部分。 無論如何,這是我的代碼可以正確地用於您的示例:

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