【问题标题】:Java JADE add Cyclic BehaviourJava JADE 添加循环行为
【发布时间】: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


【解决方案1】:

您必须删除myAgent.doDelete(); 语句并删除并重新添加新的TickerBehaviolur(...)CyclicBehaviour(...),以便适当地管理代理的控制流。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-12
    • 2012-10-17
    • 1970-01-01
    • 1970-01-01
    • 2020-10-05
    • 1970-01-01
    • 2015-03-14
    相关资源
    最近更新 更多