/** * The plan body. */ public void body() { ParticipantProposal[] proposals = (ParticipantProposal[])getParameterSet("proposals").getValues(); // Accept all proposals >= 5 List acceptables = new ArrayList(); for(int i=0; i<proposals.length; i++) { if(((Number)proposals[i].getProposal()).intValue()>=5) { // Insert acceptable proposal in descending order. int j; for(j=0; j<acceptables.size(); j++) { if(((Number)proposals[i].getProposal()).intValue() > ((Number)((ParticipantProposal)acceptables.get(j)).getProposal()).intValue()) break; } acceptables.add(j, proposals[i]); } } getParameterSet("acceptables").addValues(acceptables.toArray()); } }
/** * The plan body. */ public void body() { ParticipantProposal[] proposals = (ParticipantProposal[])getParameterSet("proposals").getValues(); // Accept all proposals >= 5 List acceptables = new ArrayList(); for(int i=0; i<proposals.length; i++) { if(((Number)proposals[i].getProposal()).intValue()>=5) { // Insert acceptable proposal in descending order. int j; for(j=0; j<acceptables.size(); j++) { if(((Number)proposals[i].getProposal()).intValue() > ((Number)((ParticipantProposal)acceptables.get(j)).getProposal()).intValue()) break; } acceptables.add(j, proposals[i]); } } getParameterSet("acceptables").addValues(acceptables.toArray()); } }
/** * Send cfps to all receivers. * @param cfp The cfp. * @param convid The conversation id. * @param receivers The receivers. */ protected void sendCFP(Object cfp, String convid, List receivers) { // Send CFP. IMessageEvent cfpm = getEventbase().createMessageEvent("da_cfp"); cfpm.getParameterSet(SFipa.RECEIVERS).addValues(receivers.toArray()); cfpm.getParameter(SFipa.CONTENT).setValue(cfp); cfpm.getParameter(SFipa.CONVERSATION_ID).setValue(convid); getLogger().info(getComponentName() + ": cfp(" + cfp + ")"); sendMessage(cfpm); }
/** * Send cfps to all receivers. * @param cfp The cfp. * @param convid The conversation id. * @param receivers The receivers. */ protected void sendCFP(Object cfp, String convid, List receivers) { // Send CFP. IMessageEvent cfpm = getEventbase().createMessageEvent("ea_cfp"); cfpm.getParameterSet(SFipa.RECEIVERS).addValues(receivers.toArray()); cfpm.getParameter(SFipa.CONTENT).setValue(cfp); cfpm.getParameter(SFipa.CONVERSATION_ID).setValue(convid); getLogger().info(getComponentName() + ": cfp(" + cfp + ")"); sendMessage(cfpm); }
/** * Announce the planned auction. * @param auctiondesc the auction description. * @param receivers The receivers. * @param convid The conversation id. */ protected void announceAuction(Object auctiondesc, List receivers, String convid) { // Send the inform_start_auction-message to all receivers. start = getEventbase().createMessageEvent("da_inform_start_auction"); start.getParameterSet(SFipa.RECEIVERS).addValues(receivers.toArray()); start.getParameter(SFipa.CONTENT).setValue(auctiondesc); start.getParameter(SFipa.CONVERSATION_ID).setValue(convid); getLogger().info(getComponentName() + ": inform_start_auction"); getWaitqueue().addReply(start); sendMessage(start); }
/** * Announce the planned auction. * @param auctiondesc the auction description. * @param receivers The receivers. * @param convid The conversation id. */ protected void announceAuction(Object auctiondesc, List receivers, String convid) { // Send the inform_start_auction-message to all receivers. start = getEventbase().createMessageEvent("ea_inform_start_auction"); start.getParameterSet(SFipa.RECEIVERS).addValues(receivers.toArray()); start.getParameter(SFipa.CONTENT).setValue(auctiondesc); start.getParameter(SFipa.CONVERSATION_ID).setValue(convid); getLogger().info(getComponentName() + ":\tinform_start_auction"); getWaitqueue().addReply(start); sendMessage(start); }
/** * Decide about the next iteration. * @param cfp_info The cfp info. * @param history The history. * @return The new cfp and cfp_info as an object array. */ protected Object[] decideIteration(Object cfp_info, Object[] history) { Object[] ret = null; IGoal di = createGoal("da_decide_iteration"); di.getParameter("cfp_info").setValue(cfp_info); di.getParameterSet("history").addValues(history); try { dispatchSubgoalAndWait(di); ret = new Object[2]; ret[0] = di.getParameter("cfp").getValue(); ret[1] = di.getParameter("cfp_info").getValue(); getLogger().info(getComponentName() + "calculated new cfp: "+ret[0]); } catch(BDIFailureException e) { getLogger().fine("No further iteration: "+e); //e.printStackTrace(); } return ret; }
sel.getParameter("cfp").setValue(nr.getCFP()); sel.getParameter("cfp_info").setValue(nr.getCFPInfo()); sel.getParameterSet("participants").addValues(nr.getParticipants()); sel.getParameterSet("proposals").addValues(nr.getProposals()); sel.getParameterSet("history").addValues(getParameterSet("history").getValues()); try
/** * Decide about the next iteration. * @param cfp_info The cfp info. * @param history The history. * @return The new cfp and cfp_info as an object array. */ protected Object[] decideIteration(Object cfp_info, Object[] history) { Object[] ret = null; IGoal di = createGoal("ea_decide_iteration"); di.getParameter("cfp_info").setValue(cfp_info); di.getParameterSet("history").addValues(history); try { dispatchSubgoalAndWait(di); ret = new Object[2]; ret[0] = di.getParameter("cfp").getValue(); ret[1] = di.getParameter("cfp_info").getValue(); } //catch(Throwable e) catch(BDIFailureException e) { getLogger().fine("No further iteration: "+e); //e.printStackTrace(); } return ret; }
end.getParameterSet(SFipa.RECEIVERS).addValues(losers.toArray()); end.getParameter(SFipa.CONVERSATION_ID).setValue(convid); sendMessage(end);
end.getParameterSet(SFipa.RECEIVERS).addValues(losers.toArray()); end.getParameter(SFipa.CONVERSATION_ID).setValue(convid); sendMessage(end);
/** * Plan body. */ public void body() { Object cfp = getParameter("cfp").getValue(); Object cfp_info = getParameter("cfp_info").getValue(); NegotiationRecord[] history = (NegotiationRecord[])getParameterSet("history").getValues(); ParticipantProposal[] proposals = (ParticipantProposal[])getParameterSet("proposals").getValues(); IProposalEvaluator evaluator = (IProposalEvaluator)cfp_info; ParticipantProposal[] acceptables = evaluator.evaluateProposals(cfp, cfp_info, history, proposals); getParameterSet("acceptables").addValues(acceptables); } }
/** * The plan body. */ public void body() { ISpaceObject target = ((ChangeEvent<ChangeInfo<ISpaceObject>>)getReason()).getValue().getValue(); // Todo: multiple spaces by name... AGRSpace agrs = (AGRSpace)EnvironmentService.getSpace(getAgent(), "myagrspace").get(); Group group = agrs.getGroup("mymarsteam"); IComponentIdentifier[] sentries = group.getAgentsForRole("sentry"); IMessageEvent mevent = createMessageEvent("inform_target"); mevent.getParameterSet(SFipa.RECEIVERS).addValues(sentries); mevent.getParameter(SFipa.CONTENT).setValue(target); sendMessage(mevent); // System.out.println("Informing sentries: "+getScope().getAgentName()); } }
/** * The plan body. */ public void body() { ISpaceObject target = ((ChangeEvent<ChangeInfo<ISpaceObject>>)getReason()).getValue().getValue(); // Todo: multiple spaces by name... AGRSpace agrs = (AGRSpace)EnvironmentService.getSpace(getAgent(), "myagrspace").get(); Group group = agrs.getGroup("mymarsteam"); IComponentIdentifier[] sentries = group.getAgentsForRole("sentry"); if(sentries!=null) { IMessageEvent mevent = createMessageEvent("inform_target"); mevent.getParameterSet(SFipa.RECEIVERS).addValues(sentries); mevent.getParameter(SFipa.CONTENT).setValue(target); sendMessage(mevent); } // System.out.println("Informing sentries: "+getScope().getAgentName()); } }
/** * Call carry agents to location. * @param target The target to call carries to. */ protected void callCarryAgent(ISpaceObject target) { // Todo: multiple spaces by name... AGRSpace agrs = (AGRSpace)EnvironmentService.getSpace(getAgent(), "myagrspace").get(); Group group = agrs.getGroup("mymarsteam"); IComponentIdentifier[] carriers = group.getAgentsForRole("carrier"); if(carriers!=null && carriers.length>0) { //System.out.println("Carry Agent: Found Carry Agents: "+carriers.length); RequestCarry rc = new RequestCarry(); rc.setTarget(target); //Action action = new Action(); //action.setAction(rc); //action.setActor(new AID("dummy", true)); // Hack!! What to do with more than one receiver? IMessageEvent mevent = createMessageEvent("request_carries"); mevent.getParameterSet(SFipa.RECEIVERS).addValues(carriers); mevent.getParameter(SFipa.CONTENT).setValue(rc); sendMessage(mevent); //System.out.println("Production Agent sent target to: "+carriers.length); } } }
/** * The plan body. */ public void body() { ChangeEvent<ChangeInfo<ISpaceObject>> ce = (ChangeEvent<ChangeInfo<ISpaceObject>>)getReason(); // if (ce.getValue().getValue() == null) // System.out.println("CE: " + ce + " type: " + ce.getType() + " "); // System.out.println("VAL: " + ce.getValue().getValue()); ISpaceObject target = (ce).getValue().getValue(); // Todo: multiple spaces by name... AGRSpace agrs = (AGRSpace)EnvironmentService.getSpace(getAgent(), "myagrspace").get(); Group group = agrs.getGroup("mymarsteam"); IComponentIdentifier[] sentries = group.getAgentsForRole("sentry"); IMessageEvent mevent = createMessageEvent("inform_target"); mevent.getParameterSet(SFipa.RECEIVERS).addValues(sentries); mevent.getParameter(SFipa.CONTENT).setValue(target.getId()); sendMessage(mevent); // System.out.println("Informing sentries: "+getScope().getAgentName()); } }
/** * The plan body. */ public void body() { ISpaceObject target = ((ChangeEvent<ChangeInfo<ISpaceObject>>) getReason()).getValue().getValue(); // Todo: multiple spaces by name... AGRSpace agrs = (AGRSpace)EnvironmentService.getSpace(getAgent(), "myagrspace").get(); Group group = agrs.getGroup("mymarsteam"); IComponentIdentifier[] sentries = group.getAgentsForRole("sentry"); if(sentries!=null) { IMessageEvent mevent = createMessageEvent("inform_target"); mevent.getParameterSet(SFipa.RECEIVERS).addValues(sentries); mevent.getParameter(SFipa.CONTENT).setValue(target.getId()); sendMessage(mevent); } // System.out.println("Informing sentries: "+getScope().getAgentName()); } }
/** * Call carry agents to location. * @param target The target to call carries to. */ protected void callCarryAgent(ISpaceObject target) { // Todo: multiple spaces by name... AGRSpace agrs = (AGRSpace)EnvironmentService.getSpace(getAgent(), "myagrspace").get(); Group group = agrs.getGroup("mymarsteam"); IComponentIdentifier[] carriers = group.getAgentsForRole("carrier"); if(carriers!=null && carriers.length>0) { //System.out.println("Carry Agent: Found Carry Agents: "+carriers.length); RequestCarry rc = new RequestCarry(); rc.setTarget(target.getId()); //Action action = new Action(); //action.setAction(rc); //action.setActor(new AID("dummy", true)); // Hack!! What to do with more than one receiver? IMessageEvent mevent = createMessageEvent("request_carries"); mevent.getParameterSet(SFipa.RECEIVERS).addValues(carriers); mevent.getParameter(SFipa.CONTENT).setValue(rc); sendMessage(mevent); //System.out.println("Production Agent sent target to: "+carriers.length); } } }
/** * Plan body. */ public void body() { Object cfp = getParameter("cfp").getValue(); Object cfp_info = getParameter("cfp_info").getValue(); NegotiationRecord[] history = (NegotiationRecord[])getParameterSet("history").getValues(); ParticipantProposal[] proposals = (ParticipantProposal[])getParameterSet("proposals").getValues(); IQueryNextroundInfo qnri = (IQueryNextroundInfo)cfp_info; IQueryNextroundInfo.NextroundInfo nri = new IQueryNextroundInfo.NextroundInfo(cfp, cfp_info, history[history.length-1].getParticipants()); boolean iterate = qnri.queryNextroundInfo(nri, history, proposals); getParameter("cfp").setValue(nri.getCfp()); getParameter("cfp_info").setValue(nri.getCfpInfo()); getParameterSet("participants").removeValues(); getParameterSet("participants").addValues(nri.getParticipants()); getParameter("iterate").setValue(Boolean.valueOf(iterate)); } }
/** * Send the cfp message. * @param nr The current negotation record. * @param convid The conversation id. */ protected void sendCFP(NegotiationRecord nr, String convid) { startAtomic(); if(me!=null) { getWaitqueue().removeReply(me); } me = createMessageEvent(getShortProtocolName()+"_cfp"); me.getParameterSet(SFipa.RECEIVERS).addValues(nr.getParticipants()); me.getParameter(SFipa.CONVERSATION_ID).setValue(convid); me.getParameter(SFipa.CONTENT).setValue(nr.getCFP()); if(getParameter(SFipa.LANGUAGE).getValue()!=null) me.getParameter(SFipa.LANGUAGE).setValue(getParameter(SFipa.LANGUAGE).getValue()); if(getParameter(SFipa.ONTOLOGY).getValue()!=null) me.getParameter(SFipa.ONTOLOGY).setValue(getParameter(SFipa.ONTOLOGY).getValue()); getWaitqueue().addReply(me); endAtomic(); getLogger().info(getComponentName()+" (I)CNPPlan initiated: "+convid); sendMessage(me); }