2

I am kind of new with JADE platform in eclipse. I want to create multiple agents, I have put a for loop and incremented the counter to create the agents, It used to work well but when I added the ThiefAgent, it didn't work. It only creates one PoliceAgent and one ThiefAgent. The code works perfectly but it does not create many agents.

this is the main.java code:

 public class Main {

   public static void main(String[] args) {

    /*********************************************************************/
    Runtime rt=Runtime.instance();
    ProfileImpl p=new ProfileImpl();
    p.setParameter(Profile.MAIN_HOST, "localhost");
    p.setParameter(Profile.GUI, "true");


    ContainerController cc1=rt.createMainContainer(p);


    /**************creation of 5 police agents*****************/

    for(int i=1; i<6; i++)
    {

       AgentController ac1;
    try {



        ac1=cc1.createNewAgent("PoliceAgent"+i, "Agents.PoliceAgent", null);


        ac1.start();    

    } catch (StaleProxyException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    }



         /**************creation of 3 thief agents*****************/

        for(int j=1; j<4; j++)
        {

       AgentController ac2;
    try {


        ac2=cc1.createNewAgent("ThiefAgent"+j, "Agents.ThiefAgent",    null);


        ac2.start();    

    } catch (StaleProxyException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
     }
     }

        }
      }

I tried to put one For loop for both agents but nothing changed. What's the mistake? Thanks in advance.

Mike Causer
  • 8,196
  • 2
  • 43
  • 63
Rii933
  • 69
  • 8

1 Answers1

0
  1. Create PoliceAgent class:

    public class PoliceAgent extends Agent{
        @Override
        public void setup()
        {
            System.out.println("Police agent name is: " +getAID().getName());
        }
    }       
    
  2. Create ThiefAgent class:

    public class ThiefAgent extends Agent{
        @Override
        public void setup()
        {
            System.out.println("Thief agent name is: " +getAID().getName());
        }
    }
    
  3. Create AgentWorker main class:

    public class PoliceAgent{
    
       public static void main(String... args){
           Runtime runtime = Runtime.instance();
           Profile profile = new ProfileImpl();
           profile.setParameter(Profile.MAIN_HOST, "localhost");
           profile.setParameter(Profile.GUI, "true");
           ContainerController containerController = runtime.createMainContainer(profile);
    
           for(int i=1; i<6; i++){
               AgentController policeAgentController;
               try {
                   policeAgentController = containerController.createNewAgent("PoliceAgent"+i, "ua.agent.PoliceAgent", null);
                   policeAgentController.start();    
               } catch (StaleProxyException e) {
                   e.printStackTrace();
               }
           }
    
           for(int i=1; i<4; i++){
               AgentController thiefAgentController;
               try {
                   thiefAgentController = containerController.createNewAgent("ThiefAgent"+i, "ua.agent.ThiefAgent", null);
                   thiefAgentController.start();    
               } catch (StaleProxyException e) {
                   e.printStackTrace();
               }
            }
       }
    
    }
    

I don't see mistakes in this code, but i write 3 classes an they work. Since I don't see the whole picture, so I can only say that the problem could be in the class of agents and the problem of Jade.

Tomas
  • 1,567
  • 3
  • 21
  • 38