使用javajade创建多个代理

使用javajade创建多个代理,java,eclipse,agents-jade,agents,Java,Eclipse,Agents Jade,Agents,我对eclipse中的JADE平台有些陌生。我想创建多个代理,我放置了一个for循环并增加了计数器来创建代理,它过去工作得很好,但是当我添加ThiefAgent时,它不工作。它只创建一个policyagent和一个ThiefAgent。 这段代码工作得很好,但它不会创建很多代理 这是main.java代码: public class Main { public static void main(String[] args) { /***********************

我对eclipse中的JADE平台有些陌生。我想创建多个代理,我放置了一个for循环并增加了计数器来创建代理,它过去工作得很好,但是当我添加ThiefAgent时,它不工作。它只创建一个policyagent和一个ThiefAgent。 这段代码工作得很好,但它不会创建很多代理

这是main.java代码:

 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();
     }
     }

        }
      }
公共类主{
公共静态void main(字符串[]args){
/*********************************************************************/
Runtime rt=Runtime.instance();
ProfileImpl p=newprofileimpl();
p、 setParameter(Profile.MAIN_HOST,“localhost”);
p、 setParameter(Profile.GUI,“true”);
ContainerController cc1=rt.createMainContainer(p);
/**************设立5名警务人员*****************/
对于(int i=1;i
  • 创建策略代理类:

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

    public class ThiefAgent extends Agent{
        @Override
        public void setup()
        {
            System.out.println("Thief agent name is: " +getAID().getName());
        }
    }
    
  • 创建AgentWorker主类:

    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();
               }
            }
       }
    
    }
    
    公共类policyagent{
    公共静态void main(字符串…参数){
    Runtime=Runtime.instance();
    Profile Profile=newprofileimpl();
    profile.setParameter(profile.MAIN_HOST,“localhost”);
    setParameter(profile.GUI,“true”);
    ContainerController ContainerController=runtime.createMainContainer(概要文件);
    对于(int i=1;i