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. |