Magentix2  2.1.1
es.upv.dsic.gti_ia.cAgents.protocols.FIPA_CONTRACTNET_Initiator.EVALUATE_PROPOSALS_Method Class Reference
Inheritance diagram for es.upv.dsic.gti_ia.cAgents.protocols.FIPA_CONTRACTNET_Initiator.EVALUATE_PROPOSALS_Method:
Collaboration diagram for es.upv.dsic.gti_ia.cAgents.protocols.FIPA_CONTRACTNET_Initiator.EVALUATE_PROPOSALS_Method:

List of all members.

Public Member Functions

String run (CProcessor myProcessor)

Detailed Description

Definition at line 199 of file FIPA_CONTRACTNET_Initiator.java.


Member Function Documentation

The method to be executed by the action state

Parameters:
myProcessorThe CProcessor of the conversation
Returns:
The name of the next state of the conversation

Implements es.upv.dsic.gti_ia.cAgents.ActionStateMethod.

Definition at line 201 of file FIPA_CONTRACTNET_Initiator.java.

                                                          {
                        ArrayList<ACLMessage> proposes = (ArrayList<ACLMessage>) myProcessor
                                        .getInternalData().get("proposes");
                        ArrayList<ACLMessage> acceptances = new ArrayList<ACLMessage>();
                        ArrayList<ACLMessage> rejections = new ArrayList<ACLMessage>();
                        doEvaluateProposals(myProcessor, proposes, acceptances, rejections);
                        // We create dinamically the send states
                        SendState send;
                        boolean accept = false;
                        boolean reject = false;
                        int i;
                        myProcessor.getInternalData().put("acceptedProposals",
                                        acceptances.size());
                        if (acceptances.size() > 0)
                                accept = true;
                        if (rejections.size() > 0)
                                reject = true;

                        for (i = 0; i < acceptances.size(); i++) {
                                send = new SendState("SEND_ACCEPTANCE_" + i);
                                send.setMethod(new SEND_Method("SEND_ACCEPTANCE_" + i));
                                send.setMessageTemplate(acceptances.get(i));
                                myProcessor.registerState(send);
                                if (i == 0)
                                        myProcessor.addTransition("EVALUATE_PROPOSALS",
                                                        "SEND_ACCEPTANCE_" + i);
                                else
                                        myProcessor.addTransition("SEND_ACCEPTANCE_" + (i - 1),
                                                        "SEND_ACCEPTANCE_" + i);
                        }
                        if (!reject && accept)
                                myProcessor.addTransition("SEND_ACCEPTANCE_" + (i - 1),
                                                "WAIT_FOR_RESULTS");

                        int j;
                        for (j = 0; j < rejections.size(); j++) {
                                send = new SendState("SEND_REJECTION_" + j);
                                send.setMethod(new SEND_Method("SEND_REJECTION_" + j));
                                send.setMessageTemplate(rejections.get(j));

                                myProcessor.registerState(send);
                                if (j == 0)
                                        if (accept) {
                                                System.out.println("SEND_ACCEPTANCE_" + (i - 1));
                                                myProcessor.addTransition("SEND_ACCEPTANCE_" + (i - 1),
                                                                "SEND_REJECTION_" + j);
                                        } else
                                                myProcessor.addTransition("EVALUATE_PROPOSALS",
                                                                "SEND_REJECTION_" + j);
                                else
                                        myProcessor.addTransition("SEND_REJECTION_" + (j - 1),
                                                        "SEND_REJECTION_" + j);
                        }

                        if (reject)
                                if (!accept)
                                        myProcessor.addTransition("SEND_REJECTION_" + (j - 1),
                                                        "FINAL");
                                else
                                        myProcessor.addTransition("SEND_REJECTION_" + (j - 1),
                                                        "WAIT_FOR_RESULTS");

                        if (accept)
                                return "SEND_ACCEPTANCE_0";
                        else if (reject)
                                return "SEND_REJECTION_0";
                        else
                                return "FINAL";
                }

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables