1

I wrote a piece of code representing an agent using jade library 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.

/*
* 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;
        }
    }
}
}

is there anyone know why this code doesn't work? thank you! :)

Hadi
  • 5,328
  • 11
  • 46
  • 67

1 Answers1

0

You made a spelling mistake in the Default Switch statement:

destination.setName("Main-Contianer");

Should be:

destination.setName("Main-Container");