uppaal
介绍
/*
-
Four vikings are about to cross a damaged bridge in the middle of the
-
night. The bridge can only carry two of the vikings at the time and to
-
find the way over the bridge the vikings need to bring a torch. The
-
vikings need 5, 10, 20 and 25 minutes (one-way) respectively to cross
-
the bridge.
-
Does a schedule exist which gets all four vikings over the bridge
-
within 60 minutes?
*/
四名维京人将要穿过一座受损的桥夜晚。这座桥当时只能载两个维京人去
在桥上找到维京人需要带火炬的路。这个维京人需要5分钟、10分钟、20分钟和25分钟(单程)才能穿越这座桥。
有没有把四个维京人都送到桥上的时间表?
60分钟内?
全局变量
chan take, release; // Take and release chan通道的意思
int[0,1] L; // The side the torch is on
clock time; // Global time
全局声明
const int fastest = 5;
const int fast = 10;
const int slow = 20;
const int slowest = 25;
Viking1 = Soldier(fastest);
Viking2 = Soldier(fast);
Viking3 = Soldier(slow);
Viking4 = Soldier(slowest);
system Viking1, Viking2, Viking3, Viking4, Torch;
模板-solidier
声明
clock y;
状态转化图
开始维京人未过河,处于不安全状态
- 如果可以拿起火把且L ==0,此时y初始化,进入下一个状态,此时y一直增加
- 当y = _delay这个临界点时候,维京人已经到达,处于安全状态,释放火把,此时火把状态为1
维京人此刻在对岸
- 火把可以被拿地 且L ==1,此时此时说明要回去。过程类似。
模板-Torch
声明
无
状态转化图
火把初始状态为free
接受到take时候,进入紧急状态,要么马上走人(一个人),要不然可以马上接受到第二个take信号走人(两个人,最多情况下)。
double_men走完之后,只能得realse。一次realse操作变成一个人,接着再realse一次,到达free状态,且更新L
个人理解:这部分只是考虑火把状态,不考虑从一个状态迁移到另一个状态考虑,人经历了什么。人和火把的状态通过通道保持同步。不可否认,形式化验证本身同样是可能存在问题的
性质验证
E<> Solidier1.safe and Solidier2.safe and Solidier3.safe and Solidier4.safe and time<=60