【问题标题】:Jade Library- Agent mobility between containersJade Library - 容器之间的代理移动性
【发布时间】:2012-03-22 12:06:12
【问题描述】:

我使用jade library 编写了一段代表代理的代码,用于跨容器旅行。我的代理有一个Cyclic Behavior,它使用一个简单的switch-case 语句来跨容器旅行。它在“Main-Container”运行,然后转到“Container-1”,然后转到“Container-2”,然后转到“Container-1”,依此类推! 当它想回来时,问题就在这里,它没有!没有关于未知Container 或类似的错误。

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package MyAgentPool;

import jade.core.Agent;
import jade.core.ContainerID;
import jade.core.behaviours.CyclicBehaviour;

/**
 *
 * @author King Hadi
*/
public class MyAgent00 extends Agent {       
@Override
protected void takeDown() {
    // TODO Auto-generated method stub
    super.takeDown();
    System.out.print("goodbye!");
}

@Override
protected void setup() {
    // TODO Auto-generated method stub
    super.setup();
    System.out.println("Hello I'm " + this.getLocalName());
    this.addBehaviour(new MyBehaviour());
   }
}

class MyBehaviour extends CyclicBehaviour {

private int step = 0;

@Override
public void action() {
    // TODO Auto-generated method stub
    switch (step) {
        case 0: {
            System.out.println("step variable is: "+ step);
            step++;
            ContainerID destination = new ContainerID();
            destination.setName("Container-2");                                
            System.out.println("waiting 2 seconds! before traveling ... ");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }                

            myAgent.doMove(destination);
            break;
        }
        case 1: {
            System.out.println("step variable is: "+ step);
            step++;
            ContainerID destination1 = new ContainerID();
            destination1.setName("Container-1");                
            System.out.println("waiting 2 seconds! before traveling ... ");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }                

            myAgent.doMove(destination1);
            break;
        }
        case 2: {
            System.out.println("step variable is: "+ step);
            step--;
            ContainerID destination2 = new ContainerID();
            destination2.setName("Container-2");                                
            System.out.println("waiting 2 seconds! before traveling ...");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }                                
            myAgent.doMove(destination2);
            break;
        }
        default: {
            System.out.println("step variable is: "+ step);
            step = 0;
            ContainerID destination = new ContainerID();
            destination.setName("Main-Contianer");
            myAgent.doMove(destination);
            System.out.println("waiting 2 seconds! before traveling ...");

            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }                
            break;
        }
    }
}
}

有谁知道为什么这段代码不起作用? 谢谢你! :)

【问题讨论】:

  • 部署它时会发生什么?请说明

标签: java containers agent agents-jade mobility


【解决方案1】:

您在 Default Switch 语句中犯了拼写错误:

destination.setName("Main-Contianer");

应该是:

destination.setName("Main-Container");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-22
    • 2017-10-12
    • 1970-01-01
    • 1970-01-01
    • 2017-03-11
    • 1970-01-01
    • 2013-05-05
    • 1970-01-01
    相关资源
    最近更新 更多