我正在研究一个非常简单的promela模型。它使用两个不同的模块,充当人行横道/交通灯。第一个模块是输出当前信号的交通灯(绿色、红色、黄色、挂起)。该模块还接收一个称为“行人”的信号作为输入,该信号作为一个指示符,表示有行人想要过马路。第二个模块充当人行横道。它接收来自交通灯模块(绿色、黄色、绿色)的输出信号。它将行人信号输出到交通灯模块。这个模块简单地定义了行人是否在过路、等待或不存在。我的问题是,一旦计数值变为60,就会发生超时。我相信"SigG_out!1“是导致错误的原因,但我不知道原因。我已经附加了从命令行接收到的跟踪的图像。我对Spin和Promela完全陌生,所以我不知道如何使用跟踪中的信息在代码中找到我的问题。任何帮助都是非常感谢的。
以下是完整模型的代码:
mtype = {red, green, yellow, pending, none, crossing, waiting};
mtype traffic_mode;
mtype crosswalk_mode;
int 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 }
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;
:: else -> skip;
fi
::(traffic_mode == green) ->
if
::(count < 60) ->
count = count + 1;
::(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;
if
::(count >= 60) ->
sigY_out ! 1;
count = 0;
traffic_mode = yellow;
::else -> skip;
fi
::(traffic_mode == yellow) ->
count = count + 1;
if
::(count >= 5) ->
sigR_out ! 1;
count = 0;
traffic_mode = red;
:: else -> skip;
fi
fi
od
}
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);
}
}

发布于 2017-04-07 10:57:13
您使用channels是错误的,特别是这一行,我甚至不知道如何解释它:
:: (sigG_in == 1) ->0。使用三个不同的通道发送不同的信号似乎有点毫无意义。使用三个不同的值怎么样?
mtype = { RED, GREEN, YELLOW };
chan c = [0] of { mtype };
...
c!RED
...
// (some other process)
...
mtype var;
c?var;
// here var contains RED
...https://stackoverflow.com/questions/43266171
复制相似问题