关于多Agent系统的研究 下载本文

boolContext = false; System.out.println(\); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } } }

总结:该篇主要介绍了关于Jadex的Agent的创建方法和Plan的使用。Agent在V3中得使用只需要Java文件就可以,并且,在需要设置为Plan的方法或者类上面添加@Plan就可以声明为Plan,在Agent的body中直接调用使用。Plan的定义方法比较多,但是常用的还是每个Plan定义为一个类文件,比较符合常规的系统开发规范。 这一篇是学习关于Beliefs的使用。

1.Beliefs的简单说明

一个Agent的Belief集是表示这个Agent对这个世界环境的了解。跟人类一样,知识积累的越多,越会处理世界上发生事情,换句话来说,就是你的适应性很强。当然,Agent就是Intelligent的,这样研究的东西才会对人类有所贡献。

Beliefs不仅能够初始化goals或者Plans,从而使agent执行相应的action,而且能够控制正在执行的行为。 Beliefs的表示方法:

作为类的一个成员来使用。这是比较常见的一种方式,并且把这个成员作为这个agent的belief。这个成员可以使任意类型的

Getter/Setter的方法对。为了满足更多的逻辑要求,增加了这两个pair。 未实现的Getter和Setter方法对。

一句话点破Belief的功能:就是让Agent知道这些beliefs的改变。换句话来说,就是一个人肯定知道自己知道什么和不知道什么,当你学了点新东西的时候,肯定会提醒自己的大脑。当belief被重新赋值,那么Agent就能够发现这点变化然后做出相应的动作。

2. Belief触发Plan

和普通的Plan区别就是在@Plan之后增加了相应的信息。

package a1;

import java.util.HashMap; import java.util.Map;

import jadex.bdiv3.BDIAgent;

import jadex.bdiv3.annotation.Belief; import jadex.bdiv3.annotation.Plan;

import jadex.bdiv3.annotation.Trigger; import jadex.micro.annotation.Agent;

import jadex.micro.annotation.AgentCreated; import jadex.micro.annotation.Description; @Agent

@Description(\) // @Plans(@Plan(body=@Body(TranslatePlan.class))) publicclassTranslateEngChBDI { @Agent

protected BDIAgent translateAgent; protectedint i = 1; @Belief

protected Map wordTable;

@AgentCreated publicvoidinit() {

this.wordTable = new HashMap(); // add some examples of word pairs wordTable.put(\, \牛奶\);

wordTable.put(\, \香蕉\);

wordTable.put(\, \学校\);

wordTable.put(\, \老师\);

wordTable.put(\, \科学\); }

@Plan(trigger = @Trigger(factaddeds = \)) publicvoidcheckMacPlan() {

// directly show the automatically triggered.

System.out.println(\ + i++ + \); } }

这个例子是关于静态的Belief的使用,而有些时候,一个Belief依赖于其他的Beliefs,并且任何时候其他Beliefs的其中一个改变时,都会自动被重新评估。下面就是关于动态Belief的例子。

3. 动态的Beliefs

开启动态Beliefs的方法比较简单,相当于一个开关,把Dynamic设置成true即可。

4. Getter and Setter Belief

为了能够进一步动态获取和设定Beliefs,那么需要使用Getter和Setter的方法。当然,这个也不是很确切的说法。用一个简单的例子来说明一下。

package a1;

import java.text.SimpleDateFormat;

import jadex.bdiv3.BDIAgent;

import jadex.bdiv3.annotation.Belief; import jadex.bdiv3.annotation.Plan; import jadex.bdiv3.annotation.Trigger; import jadex.micro.annotation.Agent; import jadex.micro.annotation.AgentBody; import jadex.micro.annotation.Description; @Agent

@Description(\) publicclassClockBDI { @Agent