【问题标题】:Why is the promela model timing out?为什么 promela 模型会超时?
【发布时间】:2017-04-06 00:27:18
【问题描述】:

我正在研究一个相当简单的 promela 模型。使用两个不同的模块,它充当人行横道/交通灯。第一个模块是输出当前信号(绿色、红色、黄色、待定)的交通灯。该模块还接收一个称为“行人”的信号作为输入,该信号用作指示有行人想要穿过的信号。第二个模块充当人行横道。它接收来自交通灯模块的输出信号(绿色、黄色、绿色)。它将行人信号输出到交通灯模块。该模块仅定义行人是否正在过马路、等待或不存在。我的问题是,在 Spin 中运行模型时,一旦人行横道开始执行它的前几条语句,它就会超时。我附上了从命令行收到的跟踪图像。我对 Spin 和 Promela 完全陌生,所以我不完全确定如何使用跟踪中的信息在代码中找到我的问题。非常感谢任何帮助。

这是完整模型的代码:

mtype = {red, green, yellow, pending, none, crossing, waiting};
mtype traffic_mode;
mtype crosswalk_mode;
byte count;
chan pedestrian_chan = [0] of {byte};  
chan sigR_chan = [0] of {byte};
chan sigG_chan = [0] of {byte};
chan sigY_chan = [0] of {byte};

ltl l1 {!<> (pedestrian_chan[0] == 1) && (traffic_mode == green || traffic_mode == yellow || traffic_mode == pending)}
ltl l2 {[]<> (pedestrian_chan[0] == 1) -> crosswalk_mode == crossing }

active proctype traffic_controller(chan pedestrian_in, sigR_out, sigG_out, sigY_out)

{

do
    ::if
      ::(traffic_mode == red) -> 
        count = count + 1;
        if
        ::(count >= 60) ->
            sigG_out ! 1;
            count = 0;
            traffic_mode = green;
        fi
      ::(traffic_mode == green) -> 
        if
        ::(count < 60) ->
            count = count + 1;
            traffic_mode = green;
        ::(pedestrian_in == 1 & count < 60) ->
            count = count + 1;
            traffic_mode = pending;
        ::(pedestrian_in == 1 & count >= 60)
            count = 0;
            traffic_mode = yellow;
        fi
      ::(traffic_mode == pending) ->
        count = count + 1;
        traffic_mode = pending;
        if
        ::(count >= 60) ->
            sigY_out ! 1;
            count = 0;
            traffic_mode = yellow;
        fi  
      ::(traffic_mode == yellow) ->
        count = count + 1;
        traffic_mode = yellow;
        if
        ::(count >= 5) ->
            sigR_out ! 1;
            count = 0;
        fi
      fi
od  

}



active proctype crosswalk(chan sigR_in, sigG_in, sigY_in, pedestrian_out)

{
do
    ::if
      ::(crosswalk_mode == crossing) ->
        if
        ::(sigG_in == 1) -> crosswalk_mode = none;
        fi
      ::(crosswalk_mode == none) ->
        if  
        :: (1 == 1) -> crosswalk_mode = none;
        :: (1 == 1) -> 
            pedestrian_out ! 1;
            crosswalk_mode = waiting;
        fi
      ::(crosswalk_mode == waiting) ->
        if
        ::(sigR_in == 1) -> crosswalk_mode = crossing;
        fi
      fi
od   
}   
init

{
    count = 0;
    traffic_mode = red;
    crosswalk_mode = crossing;

    atomic
    {
        run traffic_controller(pedestrian_chan, sigR_chan, sigG_chan, sigY_chan);
        run crosswalk(sigR_chan, sigG_chan, sigY_chan, pedestrian_chan);
    }
}


[![enter image description here][1]][1]

【问题讨论】:

    标签: model-checking spin promela


    【解决方案1】:

    这个问题很容易发现,系统在这里卡在这段代码中:

        if
        ::(count >= 60) ->
            sigG_out ! 1;
            count = 0;
            traffic_mode = green;
        fi
    

    如果count 不大于或等于60 会发生什么?

    进程不能执行(唯一的)分支,因为条件是false,所以它们都停在那里等待它在未来某个时间变成true

    您应该提供一个替代分支,例如 else -&gt; skip,以便进程可以简单地通过 if ... fi 语句。

    【讨论】:

    • 感谢您的回答。这解决了超时。但是,我确实有另一个问题。一旦计数超过 60,它就想做 sigY_out ! 1,但我得到错误,“发送到未初始化的chan。”我猜这个变量所连接的通道在某种程度上是未初始化的。不完全确定如何解决此问题。
    • @Flower 这很可能是因为您的系统中有活动进程,其输入变量被初始化为 0。只需删除 active 关键字。
    • 现在一旦计数达到 60 就会超时。
    • 当我使用选项 -t 运行时,它显示“错误:无效语句”
    • 在您的系统中有 5 个进程之前,现在是 3..可能还有其他依赖于它的东西
    猜你喜欢
    • 1970-01-01
    • 2018-05-20
    • 1970-01-01
    • 1970-01-01
    • 2018-02-05
    • 1970-01-01
    • 2016-04-26
    • 1970-01-01
    • 2019-12-19
    相关资源
    最近更新 更多