简体   繁体   English

在Alloy中执行状态时引用错误的sig对象

[英]wrong sig object get referenced to while executing state in Alloy

I am new to Alloy. 我是Alloy的新手。 I am trying to formalize a system using Alloy. 我正在尝试使用Alloy正式化系统。 Here I want to execute certain operations based on the events. 在这里,我想根据事件执行某些操作。 For this, I have a list of events that I want to track using enum Event. 为此,我有一个我想要使用枚举事件跟踪的事件列表。 And I am going through all the State using ordering function of Alloy. 而且我正在使用Alloy的订购功能来完成整个州。 In each state, I am taking the mixture object and running the operation. 在每个州,我正在采取混合物对象并运行操作。

Problem that I am facing currently is - In my system, I have two sig object - ClassA and ClassB. 我目前面临的问题是 - 在我的系统中,我有两个sig对象 - ClassA和ClassB。 After executing the alloy code I am generating the flow diagram. 执行合金代码后,我正在生成流程图。 Unfortunately, I am noticing my ClassB get referenced to ClassA of Mixture object. 不幸的是,我注意到我的ClassB引用了Mixture对象的ClassA。 I am attaching the diagram 我附上图表

在此输入图像描述

I am also attaching my full code here. 我也在这里附上我的完整代码。 Can anyone help me debugging the problem, please? 有人可以帮我调试这个问题吗? I have tried to impose different predicate and logic, but none of them worked. 我试图强加不同的谓词和逻辑,但它们都没有奏效。

open util/ordering[State]


abstract sig Base{
 name: String,
 value : Int
}{
value >= 0
}

sig ClassA extends Base{

}{

name = "Class A"
}

sig ClassB extends Base{


}{
name = "Class B"
}

enum Event {EVENT1, EVENT2}


sig State{

mixture: Mixture
}

sig Mixture{
classA: Base,
classB: Base
} {
    classA != classB
}


fact {
    all s: State, s': s.next{
        s.mixture ! in  s'.*next.mixture
        operation [s.mixture]       

    }
}


pred operation [mixture: Mixture]{
    all ev: Event| ev = EVENT1 => {
        mixture.classA.name = "Class A" => {
                mixture.classA.value = 1    
        }
    }

}

run random {} for 3

You have 你有

sig Mixture{
classA: Base,
classB: Base
}

In your diagram, the relations are named classA and classB . 在图中, 关系名为classAclassB Since each can point to any arbitrary Base , there's nothing stopping classA from pointing to a ClassB instance. 由于每个都可以指向任意Base ,因此没有什么能阻止classA指向ClassB实例。 You probably want something like 你可能想要这样的东西

sig Mixture {
    , classA: ClassA
    , classB: ClassB
}

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

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