JACK——PaintRobot Exercise5

本文通过一个示例程序展示了在BDI(Belief-Desire-Intention)代理框架下,当某一计划失败时如何尝试其他可用计划直至成功。具体地,文章通过修改PaintSpecifiedNewColour计划使其在执行一次后失败,进而触发了其他备选计划的执行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

来源:http://aosgrp.com/

 

Exercise 5

Illustrate the reposting of events when a plan fails.

 

Introduction

The way that an agent handles an event depends on the type of event. For example, when a normal event is received by an agent, the agent initiates a task to handle the event. This task involves selecting and executing the first plan that is both relevant and applicable to this event. With normal events the initial selection is the only plan that is executed. In the case of BDI events, the agent can apply more sophisticated reasoning to the plan selection, and can also attempt to achieve its goal using other applicable plans if a plan fails.

This exercise illustrates how a BDIGoalEvent will attempt every applicable plan until it succeeds. It will only fail when no more applicable plan instances remain to be tried. The body() method in a plan is the plan's main reasoning method. It is executed whenever a plan is executed. Reasoning methods do not have the same execution structure as ordinary Java methods. Each statement in a reasoning method is treated like a boolean expression, and each semicolon between statements like an AND connector. This means that if any statement fails, then the reasoning method terminates immediately and fails. In this exercise you can make the plan fail by adding the following statement in its body() method:

   false;
 
Instructions

1. Modify the PaintSpecifiedNewColour plan so that it prints the painting message once and then fails (add false; after the first print statement). To illustrate that the plan actually stops at that point, add System.out.println("After false statement"); after the false statement. This print statement should not be executed.

If editing the file as a JACK file, save and close the file before continuing.

2. Save the project.

3. Compile and run the program.

4. Add a fail() reasoning method that prints the string "PaintSpecifiedNewColour plan failed".

If editing the file as a JACK file, save and close the file before continuing.

5. Save the project.

6. Compile and run the program.

 

示例程序

 

运行结果:

(1) test with red

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

(3) PaintSpecifiedNewColour plan failed

(4) painting the part the current colour: red

(5) test with no specified colour

(6) No specified colour. Painting the part red

(7) test with green

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

(9) PaintSpecifiedNewColour plan failed

(10) painting the part the current colour: green

(11) test with green again

(12) painting the part the current colour: green

 

运行结果分析

首先,外部要求Agent绘制红色red(1),搜索可应用的规划PaintSpecifiedNewColour ,在body()方法中将Agent保存的颜色改为红色,并进行第一次输出(1st coat)(2),紧接着的false语句让其推理失败(3)。此时需要重新搜索出当前方案之外的可应用的方案,选择规划PaintSpecifiedCurrentColour ,打印输出绘制当前颜色(4);

其次,外部要求Agent绘制null(5),选择可应用的规划PaintAnyColour,打印输出(6);

再次,外部要求Agent绘制绿色green(7),与绘制红色同(8)(9)(10)。

最后,外部再次要求Agent绘制绿色(11),此时Agent内部保存的颜色为绿色,选择规划PaintSpecifiedCurrentColour ,打印输出(12)。

 

Questions

1. Which plan is now responsible for printing the second paint message that corresponds to the second coat of paint?

 

Answers

1. PaintSpecifiedCurrentColour plan

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值