NuSMV - AND模型

时间:2017-09-25 16:00:26

标签: model-checking nusmv

我试图在NuSMV中编写以下模型

enter image description here

换句话说,只有当x和y处于不良状态时,z才会变坏。这是我写的代码

MODULE singleton
    VAR state: {good, bad};
    INIT state = good
    TRANS (state = good) -> next(state) = bad
    TRANS (state = bad) -> next(state) = bad

MODULE effect(cond)
    VAR state: {good, bad};
    ASSIGN
    init(state) := good;
    next(state) := case
        (state = bad) : bad;
        (state = good & cond) : bad;
        (!cond) : good;
        TRUE : state;
        esac;

MODULE main 
    VAR x : singleton;
    VAR y : singleton;
    VAR z : effect((x.state = bad) & (y.state = bad));

但我只获得了这些可达状态

NuSMV > print_reachable_states -v
######################################################################
system diameter: 3
reachable states: 3 (2^1.58496) out of 8 (2^3)
  ------- State    1 ------
  x.state = good
  y.state = good
  z.state = good
  ------- State    2 ------
  x.state = bad
  y.state = bad
  z.state = bad
  ------- State    3 ------
  x.state = bad
  y.state = bad
  z.state = good
  -------------------------
######################################################################

如何修改我的代码以获取

x.state = good
y.state = bad
z.state = good

x.state = bad
y.state = good
z.state = good

处于可达状态?

此外,我不确定是否要在模型图片中添加或不添加红色箭头:如果x和y处于状态不佳状态,我迟早也希望这样做z变坏了。

非常感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

状态

x.state = good
y.state = bad
z.state = good

x.state = bad
y.state = good
z.state = good

无法访问,因为main的每个子模块都会与其他子模块同时执行转换,因为您强制 确定性转换为您的状态变量;也就是说,在您的模型中,xy同时将状态从good更改为bad。此外,与您的好照片相比,您的smv代码不允许任何自循环,除了最终状态的循环。

要修复您的模型,您只需声明 - 例如x(分别为ygood - 您需要next(x)(相反。 next(y)goodbad,但不强制做出任何决定。的 e.g。

MODULE singleton
VAR
  state: { good, bad };

ASSIGN
  init(state) := good;
  next(state) := case
      state = good : { good, bad };
      TRUE         : bad;
    esac;


MODULE effect(cond)
VAR
  state: { good, bad };

ASSIGN
  init(state) := good;
  next(state) := case
      (state = bad | cond) : bad;
      TRUE                 : state;
    esac;


MODULE main
VAR
    x : singleton;
    y : singleton;
    z : effect((x.state = bad) & (y.state = bad));

注意: 我还简化了模块effect的规则,但这是不必要的。

您可以按如下方式测试模型:

nuXmv > reset; read_model -i test.smv ; go; print_reachable_states -v
######################################################################
system diameter: 3
reachable states: 5 (2^2.32193) out of 8 (2^3)
  ------- State    1 ------
  x.state = good
  y.state = bad
  z.state = good
  ------- State    2 ------
  x.state = good
  y.state = good
  z.state = good
  ------- State    3 ------
  x.state = bad
  y.state = good
  z.state = good
  ------- State    4 ------
  x.state = bad
  y.state = bad
  z.state = bad
  ------- State    5 ------
  x.state = bad
  y.state = bad
  z.state = good
  -------------------------
######################################################################

关于您的第二个问题,我提供的代码示例保证您要验证的属性:

nuXmv > check_ltlspec -p "G ((x.state = bad & y.state = bad) -> F z.state = bad)"
-- specification  G ((x.state = bad & y.state = bad) ->  F z.state = bad)  is true

显然是这种情况,因为图片红边所概述的自循环不存在。如果您考虑一下,那么转换将允许至少一次执行,其中当前状态保持等于

x.state = bad
y.state = bad
z.state = good

无限期地,这将是您的规范的反例。

修改

您也可以通过编写此代码来修复代码:

MODULE singleton
    VAR state: {good, bad};
    INIT state = good
    TRANS (state = bad) -> next(state) = bad

删除第TRANS (state = good) -> next(state) = bad行允许xystate = good时随意更改,这意味着它们可以非确定地保留good或成为{{ 1}}。这完全等同于我提供给你的代码,虽然乍一看不太清楚,因为它隐藏了非确定性而不是明确的。