UPPAAL例子-维京人过河


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
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值