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

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

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

protected BDIAgent translateAgent; @AgentBody

publicvoid body(){

TranslatePlan transPlan = new TranslatePlan(); translateAgent.adoptPlan(transPlan); } }

两点需要主要,首先要在Agent类的开始部分加上可能要使用的Plan,就是

@Plans(@Plan(body=@Body(TranslatePlan.class)))这一行。主要了,agent体中得body方法是在启动JCC的时候,自动被调用的。然后adopt这个Plan。 输出:Translated: teacher to Chinese is 老师

3.2 Plan作为一个内部类

package a1;

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

import jadex.bdiv3.BDIAgent;

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

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

protected BDIAgent translateAgent; @Plan

publicclassTranslatePlan {

protected Map wordTable;

public TranslatePlan() {

this.wordTable = new HashMap();

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

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

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

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

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

@PlanBody

publicvoid translateEnglishChinese() { // Here we only test one example

System.out.println(\se is \

+ wordTable.get(\)); } }

@AgentBody

publicvoid body() {

TranslatePlan transPlan = new TranslatePlan(); translateAgent.adoptPlan(transPlan); }

}

不太建议把Plan作为内部类进行使用,懂编程的人,都知道为什么。对吧?可能我的经验不足,还是比较讨厌这种使用方法。

3.3 Plan作为方法使用

package a1;

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

import jadex.bdiv3.BDIAgent;

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

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

protected BDIAgent translateAgent; protected Map wordTable;