1
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;
}
}
}
}
誰でもこのコードが動作しない理由を知っていますか? ありがとうございます! :)
あなたがそれを展開するときに何が起こりますか?解明してください – Purushottam