如何在handleElapsedTimeout()
(超时)时添加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);
}
}
并重新开始?这是我上学的任务。如果有人给我一个建议,我将非常感激。
这是我的代码:
{{1}}
答案 0 :(得分:0)
您必须删除myAgent.doDelete();
句子并删除并在其位置新添加新TickerBehaviolur(...)
或CyclicBehaviour(...)
,并根据需要方便地管理代理的控制流程。