¹ØÓÚ¶àAgentϵͳµÄÑо¿ ÏÂÔØ±¾ÎÄ

ÊÇÓÃGoal×÷ΪÄÚ²¿Àà¡£Ìí¼Ó@Goal±ê¼Ç¡£

package a1;

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

import jadex.bdiv3.BDIAgent;

import jadex.bdiv3.annotation.Belief; import jadex.bdiv3.annotation.Goal; import jadex.bdiv3.annotation.Plan; import jadex.bdiv3.annotation.Trigger; 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;

@Belief

protected Map wordTable;

@AgentCreated publicvoid init() {

this.wordTable = new HashMap(); // add some examples of word pairs

wordTable.put(\, \Å£ÄÌ\);

wordTable.put(\, \Ïã½¶\);

wordTable.put(\, \ѧУ\);

wordTable.put(\, \ÀÏʦ\);

wordTable.put(\, \¿ÆÑ§\); } @Goal

publicclassTranslateEngCh { protected String eword; protected String cword;

public TranslateEngCh(String eword) { this.eword = eword;

}

public String getEword() { return eword; }

publicvoid setEword(String eword) { this.eword = eword; }

public String getCword() { return cword; }

publicvoid setCword(String cword) { this.cword = cword; } }

@Plan(trigger = @Trigger(goals = TranslateEngCh.class)) publicvoid translateEngChPlan(TranslateEngCh goal) { goal.setCword(wordTable.get(goal.getEword())); }

@AgentBody

publicvoid body() {

String ewordString = \;

TranslateEngCh goal = (TranslateEngCh) translateAgent.dispatchTopLevelGoal(

new TranslateEngCh(ewordString)).get();

System.out.println(\·­Òë½á¹û£º\ + ewordString + \\ + goal.getCword()); } }

goal¶¨ÒåÍê³ÉÖ®ºó£¬ÊDZ»agentÀ´µ÷Óõġ£ÎªÁËʵÏÖÕâ¸ögoal£¬ÄÇô¾ÍÐèÒªÓÐPlanÀ´Ö§³Ö£¬×îÖÕÍê³Éij¸öÄ¿µÄ¡£ ¼ÇסÁ½µã£º

1. agent.dispatchTopLevelGoal();

2. µ÷ÓÃgoalÒÔºó£¬ÐèÒªPlanÀ´¶Ôgoal½øÐд¦Àí¡£

ÉÏÊö³ÌÐòµÄ½á¹û£¬ÏÔʾΪÁË´ï³Éij¸öÄ¿±ê£¬¶¨ÒåPlanÀ´´¦Àígoal¡£

ÕâÀïÎÒÃÇÊÇÓÃÁËÀàµÄgetºÍset·½·¨À´²Ù×÷goalµÄ³ÉÔ±±äÁ¿¡£ÈçºÎÄܹ»ÊµÏÖÔÚÀàµÄÍⲿֱ½Ó¶Ô³ÉÔ±±äÁ¿½øÐвÙ×÷ÄØ£¿

3. ʹÓÃGoalµÄ²ÎÊýºÍ½á¹û£¨optionally£©

ʹÓÃÄ¿±êµÄ²ÎÊýºÍ½á¹ûÄܹ»½ÚÊ¡ºÜ¶à´úÂë¡£²¢ÇÒ±£Ö¤Ä¿±êµÄ°²È«ÐÔ¡£ Ö÷ÒªµÄʵÏÖÐÎʽΪ£º@GoalParameter ºÍ@GoalResult

package a1;

import java.util.HashMap;