DFsearch returns moody result - behaviour

View: New views
2 Messages — Rating Filter:   Alert me  

DFsearch returns moody result - behaviour

by sahar7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear,
I have 2 question one about DFsearch and other one about addBehaviour().  Let me explain:
1) I face with a moody behaviour of DF search. Actually I have a piece of code as follow :
try {
                                    DFAgentDescription[] result = DFService.search(myAgent, template);
                                    sellerAgents = new AID[result.length];
                                    System.out.println("Found the following seller agents:");                                    
                                       for (int i = 0; i < result.length; ++i) {
                                        sellerAgents[i] = result[i].getName();
                                        System.out.println(sellerAgents[i].getName());
                                    }
                                } catch (FIPAException fe) {
                                    fe.printStackTrace();
                   
 
which some times does returns the result and some times doesn't!
Do you know whats wrong?  and how can I solve it?
 
2) I need to add a behaviour inside another Behaviour and I add it as follow:
                                myAgent.addBehaviour(new Behaviour() {
                                    private int stage = 0;
                                    public void action() {
                                        switch (stage) {
                                        case 0:
                                            // send reportback to coordinator
                                            ACLMessage request = new ACLMessage(ACLMessage.REQUEST);
                                            request.addReceiver(sellerAgent);
                                            try{
                                                request.setContentObject(new Object[]{state,UtilityH [Pcnt], UtilityH [Pcnt-1], UtilityH [Pcnt-2]});
                                                request.setConversationId("Report");
                                                request.setReplyWith("request"+System.currentTimeMillis()); // Unique value
                                                myAgent.send(request);
                                                System.out.println("request sent! : "+state+", "+UtilityH [Pcnt]+", "+UtilityH [Pcnt-1]+", "+UtilityH [Pcnt-2]+"to: "+sellerAgent);
                                            }catch(Exception e){e.printStackTrace();
                                                    System.out.println("can not send reprot back from agent"+getAID().getName() );}
                                            stage++;
                                        break;
                                        case 1:
                                            // receive Inheritance from coordinator                                             MessageTemplate mt = MessageTemplate.MatchPerformative(ACLMessage.CONFIRM);
                                            ACLMessage msg = myAgent.receive(mt);
                                            if(msg!=null){
                                                    Object[] msgContent;
                                                    try {
                                                        msgContent = (Object[]) msg.getContentObject();
                                                        sellerStrategy = msgContent[0].toString();
                                                        lowestUtilityValue = (Double) msgContent[1];
                                                        System.out.println("passe from coo: lowestUtilityValue:"+lowestUtilityValue+"seller strategy:"+sellerStrategy);
                                                    } catch (UnreadableException ex) {
                                                        ex.printStackTrace();
                                                    }
                                            }// if msg not null
                                            else{
                                            block();}
                                            stage++;
                                        break;
                                        }// end of switch
                                        }// end of action
                                        public boolean done() {
                                        return stage == 2;
                                        }// end of done
                                     }  );
But it seems that it jumps this behaviour without executing the behaviour.  I dont know whats wrong.  Do you have any idea?
 
Thank you, in advance.
Sahar.


_______________________________________________
jade-develop mailing list
jade-develop@...
https://avalon.cselt.it/mailman/listinfo/jade-develop
UNSUBSCRIBE INSTRUCTIONS AT
http://jade.tilab.com/community-mailinglist.htm

RE: DFsearch returns moody result - behaviour

by Caire Giovanni-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

HI,

 

1) “Sometimes doesn’t return the result”: what do you mean by that? Can you be more specific?

2) In case 1, stage++ must be put inside the if (msg != null) block as below:

 

case 1:

  ACLMessage msg = myAgent.receive(mt);
  if(msg!=null){

    ...

    stage++;

  }

  else {

    block();

  }

  break;

 

Bye,

 

Giovanni
                                      

 


From: jade-develop-bounces@... [mailto:jade-develop-bounces@...] On Behalf Of sa sa
Sent: mercoledì 4 novembre 2009 6.34
To: jade-develop@...
Subject: [jade-develop] DFsearch returns moody result - behaviour

 

Dear,
I have 2 question one about DFsearch and other one about addBehaviour().  Let me explain:

1) I face with a moody behaviour of DF search. Actually I have a piece of code as follow :

try {
                                    DFAgentDescription[] result = DFService.search(myAgent, template);
                                    sellerAgents = new AID[result.length];
                                    System.out.println("Found the following seller agents:");                                    
                                       for (int i = 0; i < result.length; ++i) {
                                        sellerAgents[i] = result[i].getName();
                                        System.out.println(sellerAgents[i].getName());

                                    }
                                } catch (FIPAException fe) {
                                    fe.printStackTrace();
                   

 

which some times does returns the result and some times doesn't!

Do you know whats wrong?  and how can I solve it?

 

2) I need to add a behaviour inside another Behaviour and I add it as follow:

                                myAgent.addBehaviour(new Behaviour() {
                                    private int stage = 0;
                                    public void action() {
                                        switch (stage) {
                                        case 0:
                                            // send reportback to coordinator
                                            ACLMessage request = new ACLMessage(ACLMessage.REQUEST);
                                            request.addReceiver(sellerAgent);
                                            try{
                                                request.setContentObject(new Object[]{state,UtilityH [Pcnt], UtilityH [Pcnt-1], UtilityH [Pcnt-2]});
                                                request.setConversationId("Report");
                                                request.setReplyWith("request"+System.currentTimeMillis()); // Unique value
                                                myAgent.send(request);
                                                System.out.println("request sent! : "+state+", "+UtilityH [Pcnt]+", "+UtilityH [Pcnt-1]+", "+UtilityH [Pcnt-2]+"to: "+sellerAgent);
                                            }catch(Exception e){e.printStackTrace();
                                                    System.out.println("can not send reprot back from agent"+getAID().getName() );}
                                            stage++;
                                        break;
                                        case 1:
                                            // receive Inheritance from coordinator                                             MessageTemplate mt = MessageTemplate.MatchPerformative(ACLMessage.CONFIRM);
                                            ACLMessage msg = myAgent.receive(mt);
                                            if(msg!=null){
                                                    Object[] msgContent;
                                                    try {
                                                        msgContent = (Object[]) msg.getContentObject();
                                                        sellerStrategy = msgContent[0].toString();
                                                        lowestUtilityValue = (Double) msgContent[1];
                                                        System.out.println("passe from coo: lowestUtilityValue:"+lowestUtilityValue+"seller strategy:"+sellerStrategy);
                                                    } catch (UnreadableException ex) {
                                                        ex.printStackTrace();
                                                    }
                                            }// if msg not null
                                            else{
                                            block();}
                                            stage++;
                                        break;
                                        }// end of switch
                                        }// end of action
                                        public boolean done() {
                                        return stage == 2;
                                        }// end of done
                                     }  );

But it seems that it jumps this behaviour without executing the behaviour.  I dont know whats wrong.  Do you have any idea?

 

Thank you, in advance.

Sahar.

 


_______________________________________________
jade-develop mailing list
jade-develop@...
https://avalon.cselt.it/mailman/listinfo/jade-develop
UNSUBSCRIBE INSTRUCTIONS AT
http://jade.tilab.com/community-mailinglist.htm