来源:http://aosgrp.com/

Exercise 9

Modify the behaviour of the robot agent so that painting takes a specific period of time to complete.

Introduction

In the previous exercise, parts were painted the requested colours. However, painting only took the amount of time required to print out a statement indicating that the robot was painting the part a particular colour. We will discover some interesting effects if we allow the plans involved to 'sleep' for a short time while the robot paints the part. To achieve this, we use the reasoning method statement @sleep.

The @sleep statement takes the following form:

@sleep(double timeout);

timeout represents the period of time that the agent must wait before continuing with the plan. The time-out period is specified in 'ticks' on the agent's clock. The actual time depends on the Timer that the agent is using. If the timer is the real-time clock (the default), then it represents a sleep period in seconds.


Note: @sleep only causes the current task to sleep. Any other tasks that the agent is currently executing proceed as normal.


Instructions

1. Modify the 'painting' plans so that they contain an @sleep(5) statement to sleep for 5 seconds after they print the message to indicate that they are painting a part.

If editing the files as JACK files, save and close them before continuing.

2. Save the project.

3. Compile and run the program with the interaction diagram.

示例程序

运行结果:

(1) test with red

(2) test with no specified colour

(3) Painting part the requested colour (1st coat) red

(4) Painting part the requested colour (2nd coat) red

(5) test with green

(6) No specified colour. Painting the part red

(7) test with green again

(8) Painting part the requested colour (1st coat) green

(9) Painting part the requested colour (2nd coat) green

(10) painting the part the current colour: green

(11) part1@%portal has been painted green

(12) part2@%portal has been painted green

(13) part3@%portal has been painted green

(14) part4@%portal has been painted green

运行结果分析:

运行结果与例8大致相同,不同之处在于最后4条(11)、(12)、(13)、(14),这是语句@sleep(5) 产生的效果,即在规划完成后阻塞5秒,由于sleep语句只阻塞当前的任务,所以其他任务照常执行,5秒钟足够让其他任务执行完成。

Questions

1. How do you explain the output?

2. How can you ensure that the robot does not begin a new task to start painting another part while it is still 'busy'?

Answers

1. 分析结果参考上述运行结果分析

2.  (1)在Robot Agent中添加boolean类型的busy字段,用来标识Robot Agent是否处于忙的状态,初始值设为false,即空闲状态。

(2)在body()的推理方法中增加while语句,不断轮询判断当前Robot Agent的状态,如果为忙的状态,则阻塞1秒,形式如下:

while(self.busy)

{

System.out.println("wait for a moment");

@sleep(1);

}

修改原来的sleep时间为2秒,这样结果出来更快一些(也可不修改)

顺序执行示例程序

运行结果:

test with red

test with no specified colour

Painting part the requested colour (1st coat) red

Painting part the requested colour (2nd coat) red

test with green

part1@%portal has been painted red

wait for a moment

test with green again

wait for a moment

wait for a moment

wait for a moment

wait for a moment

wait for a moment

No specified colour. Painting the part red

wait for a moment

wait for a moment

part2@%portal has been painted red

wait for a moment

wait for a moment

Painting part the requested colour (1st coat) green

Painting part the requested colour (2nd coat) green

wait for a moment

part3@%portal has been painted green

wait for a moment

Painting part the requested colour (1st coat) green

Painting part the requested colour (2nd coat) green

part4@%portal has been painted green

由上可见,交给Robot Agent的任务是串行执行。

转载于:https://www.cnblogs.com/6DAN_HUST/archive/2011/06/13/2079725.html

JACK——PaintRobot Exercise9相关推荐

  1. JACK——AgentManual5 Events

    来源:http://aosgrp.com/ 5 Events 5.1 What are Events? Events motivate an agent to take action. There a ...

  2. 【心情】期待 Mr. Jack In New York!

    在06版的Mr. Jack里面有八个人物,一个玩家代表Jack,同时也是这八个人之一,只有他自己才知道Jack的真正身份,他的目的是尽快逃出伦敦街区(或者在八个回合里没有被福尔摩斯抓到).另一个玩家代 ...

  3. android 关闭jack_Android7.0 配置JACK支持多用户同时编译

    # Android7.0 配置JACK支持多用户同时编译 reference: 背景 需要在一个Android7平台上进行有关的工作,但是编译的时候发现有问题.记录一下.因为和同事共用一台服务器,因为 ...

  4. html5与原生混合模式开发,HTML5与混合模式开发与Native的关系及其实现[张振华.Jack].pdf...

    H5 与 Native 交互的实现 抛砖引玉让大家有个大致的了解和方向不至于蒙圈 张振华.Jack QQ:494460705 Mail:zhangzhenhua846@126.com 2015年6月 ...

  5. 高性能计算专家Jack Dongarra获2021年图灵奖

    "我是一个数学家,对我来说,一切都是线性代数,但世界也正在看到这一点,"Jack Dongarra在采访中表示."这是我们用来建造其它东西的材料."他说,机器学 ...

  6. 2021年图灵奖,花落高性能计算先驱、田纳西大学教授Jack Dongarra

    来源:智源社区 "我是一个数学家,对我来说,一切都是线性代数,但世界也正在看到这一点,"Jack Dongarra在采访中表示."这是我们用来建造其它东西的材料.&quo ...

  7. 图灵奖公布:高性能计算先驱、为超算铺平道路的Jack Dongarra获奖

    3月30日,美国计算机协会(ACM)将2021年的图灵奖授予美国田纳西大学电气工程和计算机科学系特聘教授.现年71岁的Jack J.Dongarra,表彰他在数值算法和工具库方面的开创性贡献,使高性能 ...

  8. android jack log,Android:JACK编译错误汇总及解决

    jack server交互命令: jack-admin start-server jack-admin kill-server jack-admin list-server jack-admin un ...

  9. bestcoder #67 div2 1003 Black Jack 概率dp

    Black Jack  Accepts: 0  Submissions: 61  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 65536 ...

最新文章

  1. 有用的SAP System Administration T-CODE
  2. Linux入门:部署JavaWeb项目
  3. Ansible自动化运维应用场景分析
  4. Mysql 启动失败没日志,MySQL Server 5.7将无法启动,并且未填充错误日志
  5. 一文读懂YOLOv5 与 YOLOv4
  6. 操作对象_有进取心的机器人学习对象操作的基本原理
  7. linux 连接redis_.NetCore 使用StackExchange.Redis 连接Redis
  8. TI AM335x Linux MUX hacking
  9. 医学统计学计算机操作教程第3版附录答案,医学统计学课后习题集答案解析.doc...
  10. BXP网卡换槽之后就要按“任意键”的问题解决方法!(转)
  11. Java中unicode占几个,Java语言使用的是Unicode字符集,每个字符在内存中占8位。()...
  12. java 里面 todo 作用
  13. 证券交易所--本方最优对手方最优的区别
  14. BRE BRE ProMax 2.0.7047.0 工艺流程模拟软件ProMax\
  15. 既然都有了NS,何不再入一个喷喷(Splatoon 2)【上】
  16. 5G室内覆盖面临四大挑战,如何破?
  17. wu-database-lazy-starter(懒人数据库操作-核心增量式更新)
  18. 防火墙添加ip白名单_宝塔防火墙IP白名单添加/导入云盾YUNDUN高防CDN节点IP段
  19. 成长的旅途,未知的邂逅
  20. c++ 字符串匹配算法Robin-Karp算法

热门文章

  1. 备忘之--apache下为站点添加错误页面
  2. Kubernetes List-Watch
  3. WIN10安装scrapy/channels等不成功的解决方式
  4. Java之IO流学习总结【上】
  5. 常识:佛前三炷香是什么意思
  6. android 中 系统日期时间的获取
  7. Ajax异步请求-简单模版
  8. 用中子与质子组成的二分类系统演化对称性破缺过程
  9. linux中的查找文件夹
  10. 【发布】温度监测报警器v1.1a内测版!