我写了一段代码,代表一个使用玉库跨容器旅行的代理。我的代理有一个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;
}
}
}
}
有谁知道为什么这段代码不起作用?谢谢你!:)