tired and bored dev
tired and bored dev

Reputation: 693

How to set AID for JADE Agent?

I'm just starting with JADE agent based modeling. My hello world example looks like this -

public class HelloWorldAgent extends Agent {
 protected void setup() {
  System.out.println("Hello World! My AID is "+this.getAID());
 }
}

And I call this outside like this -

public class Main {
  public static void main(String[] args) {
    HelloWorldAgent helloWorldAgent = new HelloWorldAgent();
    helloWorldAgent.setup();
  }
}

And the output I'm seeing is -

Hello World! My AID is null

Now, my question is how do I set AID as there is only get method and no "set" method. As it's not available, I suspect there AID is something that's automatically assigned. Is it so? If yes, how do I make sure that Agent gets an AID? Thanks.

Upvotes: 2

Views: 1133

Answers (2)

Just_Alex
Just_Alex

Reputation: 558

From what I can see you are not acutally using the JADE framework. You are just calling the helloWorldAgent.setup() method. Try this to launch JADE note only boot options 0,1 and 2 are neccesary.

public static void main(String[] args) {
        // TODO code application logic here
        String[] bootOptions = new String[7]; 
        bootOptions[0] = "-gui"; 
        bootOptions[1] = "-local-port";
        bootOptions[2] = "1111";
        bootOptions[3] = "-container-name";
        bootOptions[4] = "Launch container";
        bootOptions[5] = "-agents";
        bootOptions[6] = "myFirstAgent:package.HelloWorldAgent";
        jade.Boot.main(bootOptions);


    }

Upvotes: 0

Cleber Jorge Amaral
Cleber Jorge Amaral

Reputation: 1452

I suggest you, firstly, to create a container. You can try this way in your main method:

public static void main(String[] args) throws Exception {
    ProfileImpl p = new ProfileImpl();
    p.setParameter(Profile.MAIN_HOST, "localhost");
    p.setParameter(Profile.GUI, "true");

    ContainerController cc = Runtime.instance().createMainContainer(p);

    AgentController ac = cc.createNewAgent("myAgent", "HelloWorldAgent", new Object[] { });
    ac.start();
}

getAID().getLocalName() will return "myAgent" in this case.

Upvotes: 3

Related Questions