Agent mobility between containers

SnehalataS

New Member
I wrote a piece of code representing an agent traveling across containers. my agent has a Cyclic behavior that use a simple switch-case statements to travel across containers. it runs at the 'Main-Container' then goes to 'Container-1' then goes to 'Container-2' and then goes to 'Container-1' and so on! the problem is here when it wants to come back, it doesn't! there is no error about unknown Container or something like that.\[code\]/** 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 { @Overrideprotected void takeDown() { // TODO Auto-generated method stub super.takeDown(); System.out.print("goodbye!");}@Overrideprotected 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;@Overridepublic 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; } }}}\[/code\]is there anyone know why this code doesn't work?thank you! :)
 
Top