Jade: how to run the same agent multiple times?

806 views Asked by At

I need to run my agents multiple times. Each time all the agents should be

  • created
  • perform their behaviour and
  • be removed from the platform.

My problem is with the last step.

How can I remove the agents from the platform or how can I shut the platform down to execute another one later?

I tried this code but I still can't shut down the RMA:

for( int i=0; i<10;i++)
{
    System.out.println("******************************iteration************************"+i);
    // Récupération du conteneur (Main Container) en cours d'execution de Jade                  
    Runtime rt = Runtime.instance();
    // Création du profil par défault
    ProfileImpl p = new ProfileImpl(false);
    AgentContainer container =rt.createAgentContainer(p);
    AgentController Agent=null;     


    for (int j=0; j<Ag.length;j++)
    {//loop to create all the existing agents in Ag (array).
        try { System.out.println("creation de l'agent"+j);
            Agent = container.createNewAgent(Ag[j], "jade.project."+Ag[j], null);
            Agent.start();  

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


    //shut down
    System.out.println("******************************Fin iteration************************"+i);

}

How can I shut down the maincontainer each time ? thanks

2

There are 2 answers

0
nikelyn On

You can probably try container.kill() to shut down the platform.

0
Just_Alex On

I typically use the Agent Managements System. Using the AMS is alot more code and and admin but it allows you to act on the response (inform/failure).

public void destroyAgent(final AID AgentName) {
    log("kill agent initiated by " + this.getLocalName());
    KillAgent ka = new KillAgent();
    ka.setAgent(AgentName);

    Action actExpr = new Action(this.getAMS(), ka);
    ACLMessage AMSRequest = new ACLMessage(ACLMessage.REQUEST);
    AMSRequest.addReceiver(this.getAMS());

    AMSRequest.setOntology(JADEManagementOntology.getInstance().getName());
    AMSRequest.setLanguage(FIPANames.ContentLanguage.FIPA_SL);
    AMSRequest.setProtocol(FIPANames.InteractionProtocol.FIPA_REQUEST);
    try {
        getContentManager().fillContent(AMSRequest, actExpr);

        addBehaviour(new AchieveREInitiator(this, AMSRequest) {

            protected void handleInform(ACLMessage inform) {
                log(Level.INFO, "Agent successfully Destroyed name:" + AgentName);
            }

            protected void handleFailure(ACLMessage failure) {
                log(Level.SEVERE, "Agent kill failed name: " + AgentName);
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }

}