【发布时间】:2017-01-15 17:11:49
【问题描述】:
当handleElapsedTimeout()(超时)时如何添加CyclicBehaviour 并重新开始?这是我在学校的任务。如果有人给我建议,我将不胜感激。
这是我的代码:
package test3;
import jade.core.Agent;
import jade.core.behaviours.CyclicBehaviour;
import jade.core.behaviours.OneShotBehaviour;
import jade.core.behaviours.ParallelBehaviour;
import jade.core.behaviours.TickerBehaviour;
import jade.core.behaviours.WakerBehaviour;
public class test3 extends Agent {
protected void setup(){
ParallelBehaviour pb = new ParallelBehaviour(ParallelBehaviour.WHEN_ANY);
pb.addSubBehaviour(new WakerBehaviour(this,5000){
@Override
protected void handleElapsedTimeout() {
System.out.println("timeout");
myAgent.doDelete();
}
});
/*
pb.addSubBehaviour(new CyclicBehaviour(this){
public void action (){
System.out.println("Cycling");
}
}
);
*/
pb.addSubBehaviour(new TickerBehaviour(this,100){
int random;
@Override
protected void onTick() {
random = (int) (Math.random() * 100);
System.out.println("random number = " + random);
if(random == 5)
{
System.out.println("I found it!");
myAgent.doDelete();
}
}
});
addBehaviour(pb);
}
}
【问题讨论】:
-
您确定所有的拼写都正确吗?通常语言使用美国英语(例如
behaviour->behavior)。 -
在这种情况下(JADE)是行为。用过很多次了。
标签: java eclipse agent agents-jade