/** * Get the belief base. * @return The belief base. */ public IBeliefbase getBeliefbase() { return scope!=null ? new BeliefbaseWrapper(capa.getBeliefbase(), scope+MElement.CAPABILITY_SEPARATOR) : capa.getBeliefbase(); }
/** * Get the goal base. * @return The goal base. */ public IGoalbase getGoalbase() { return getScope().getGoalbase(); }
/** * Get the event base. * @return The event base. */ public IEventbase getEventbase() { return scope!=null ? new REventbase(agent, scope) : capa.getEventbase(); }
String prefix = scope+MElement.CAPABILITY_SEPARATOR; SimpleValueFetcher fetcher = new SimpleValueFetcher(ret); fetcher.setValue("$beliefbase", new BeliefbaseWrapper(capa.getBeliefbase(), prefix)); fetcher.setValue("$goalbase", new RGoalbase(agent, scope)); fetcher.setValue("$planbase", new PlanbaseWrapper(capa.getPlanbase(), prefix)); fetcher.setValue("$eventbase", new REventbase(agent, scope)); fetcher.setValue("$expressionbase", new ExpressionbaseWrapper(capa.getExpressionbase(), prefix)); if(values!=null)
request.getParameterSet(SFipa.RECEIVERS).addValue(getScope().getComponentIdentifier());
/** * Get the plan base. * @return The plan base. */ public IPlanbase getPlanbase() { return scope!=null ? new PlanbaseWrapper(capa.getPlanbase(), scope+MElement.CAPABILITY_SEPARATOR) : capa.getPlanbase(); }
/** * Get the expression base. * @return The expression base. */ public IExpressionbase getExpressionbase() { return scope!=null ? new ExpressionbaseWrapper(capa.getExpressionbase(), scope+MElement.CAPABILITY_SEPARATOR) : capa.getExpressionbase(); }
/** * The plan body. */ public void body() { // System.out.println("MoveToLocation: "+getComponentIdentifier()); ISpaceObject myself = (ISpaceObject)getBeliefbase().getBelief("myself").getFact(); IVector3 dest = (IVector3)getParameter("destination").getValue(); Map<String, Object> props = new HashMap<String, Object>(); props.put(MoveTask.PROPERTY_DESTINATION, dest); props.put(MoveTask.PROPERTY_SCOPE, getScope().getExternalAccess()); props.put(AbstractTask.PROPERTY_CONDITION, new PlanFinishedTaskCondition(getPlanElement())); IEnvironmentSpace space = (IEnvironmentSpace)getBeliefbase().getBelief("environment").getFact(); Object taskid = space.createObjectTask(MoveTask.PROPERTY_TYPENAME, props, myself.getId()); // move = new MoveTask(dest, res, getExternalAccess()); // myself.addTask(move); Future<Void> fut = new Future<Void>(); space.addTaskListener(taskid, myself.getId(), new DelegationResultListener<Void>(fut)); fut.get(); } }
/** * Process the second answer. */ protected void handleSecondAnswer(IMessageEvent answer) { getLogger().info("Second answer: " + answer +" "+this); if(answer.getType().equals(getShortProtocolName()+"_failure")) { Object content = answer.getParameter(SFipa.CONTENT).getValue(); getLogger().info(getScope().getAgentName() + ": Received failure: " + content); requestFinished(false, new Object[]{answer.getType(), content}); } else if(answer.getType().equals(getShortProtocolName()+"_inform")) { Object content = answer.getParameter(SFipa.CONTENT).getValue(); getLogger().info(getScope().getAgentName() + ": Protocol succeeded."); requestFinished(true, content); } else { assert false: "State should not be reached"; } }
/** * Generate and add a negotiation report. */ protected void generateNegotiationReport(Order order, Tuple2<IBuyBookService, Integer>[] proposals, double acceptable_price) { String report = "Accepable price: "+acceptable_price+", proposals: "; if(proposals!=null) { for(int i=0; i<proposals.length; i++) { report += proposals[i].getSecondEntity()+"-"+proposals[i].getFirstEntity().toString(); if(i+1<proposals.length) report += ", "; } } else { report += "No seller found, purchase failed."; } NegotiationReport nr = new NegotiationReport(order, report, getScope().getTime()); //System.out.println("REPORT of agent: "+getAgentName()+" "+report); getBeliefbase().getBeliefSet("negotiation_reports").addFact(nr); }
final ClassLoader cl = getScope().getClassLoader(); tp.execute(new Runnable()
request.getParameterSet(SFipa.RECEIVERS).addValue(getScope().getComponentIdentifier()); request.getParameter(SFipa.REPLY_WITH).setValue("some reply id"); request.getParameterSet(SFipa.RECEIVERS).addValue(getScope().getComponentIdentifier()); request.getParameter(SFipa.REPLY_WITH).setValue("some other reply id");
/** * Get the plan base. * @return The plan base. */ public IPlanbase getPlanbase() { return getScope().getPlanbase(); }
/** * Get the expression base. * @return The expression base. */ public IExpressionbase getExpressionbase() { return getScope().getExpressionbase(); }
/** * The plan body. */ public void body() { // System.out.println("MoveToLocation: "+getComponentIdentifier()); ISpaceObject myself = (ISpaceObject)getBeliefbase().getBelief("myself").getFact(); IVector2 dest = (IVector2)getParameter("destination").getValue(); Map<String, Object> props = new HashMap<String, Object>(); props.put(MoveTask.PROPERTY_DESTINATION, dest); props.put(MoveTask.PROPERTY_SCOPE, getScope().getExternalAccess()); props.put(AbstractTask.PROPERTY_CONDITION, new PlanFinishedTaskCondition(getPlanElement())); IEnvironmentSpace space = (IEnvironmentSpace)getBeliefbase().getBelief("environment").getFact(); Object rtaskid = space.createObjectTask(RotationTask.PROPERTY_TYPENAME, props, myself.getId()); Future<Void> ret = new Future<Void>(); space.addTaskListener(rtaskid, myself.getId(), new DelegationResultListener<Void>(ret)); ret.get(); Object mtaskid = space.createObjectTask(MoveTask.PROPERTY_TYPENAME, props, myself.getId()); ret = new Future<Void>(); space.addTaskListener(mtaskid, myself.getId(), new DelegationResultListener<Void>(ret)); ret.get(); }
getLogger().info(getScope().getAgentName() + ": Received"+answer.getType() + content); requestFinished(false, new Object[]{answer.getType(), content}); getLogger().info(getScope().getAgentName() + ": Received agree.");
/** * Generate and add a negotiation report. */ protected void generateNegotiationReport(Order order, NegotiationRecord rec, double acceptable_price) { String report = "Accepable price: "+acceptable_price+", proposals: "; if(rec!=null) { ParticipantProposal[] proposals = rec.getProposals(); for(int i=0; i<proposals.length; i++) { report += proposals[i].getProposal()+"-"+proposals[i].getParticipant().getLocalName(); if(i+1<proposals.length) report += ", "; } } else { report += "No seller found, purchase failed."; } NegotiationReport nr = new NegotiationReport(order, report, rec!=null ? rec.getStarttime() : getScope().getTime()); //System.out.println("REPORT of agent: "+getAgentName()+" "+report); getBeliefbase().getBeliefSet("negotiation_reports").addFact(nr); } }
/** * Get the goal base. * @return The goal base. */ public IGoalbase getGoalbase() { return scope!=null ? new RGoalbase(agent, scope) : capa.getGoalbase(); }
/** * Get the beliefbase. * @return The beliefbase. */ public IBeliefbase getBeliefbase() { return getScope().getBeliefbase(); }
public void body() { IComponentManagementService cms = getAgent().getComponentFeature(IRequiredServicesFeature.class) .searchService(IComponentManagementService.class, RequiredServiceInfo.SCOPE_PLATFORM).get(); Environment en = (Environment)getBeliefbase().getBelief("environment").getFact(); Creature[] creatures = en.getCreatures(); Future<Void> destroyed = new Future<Void>(); IResultListener<Map<String, Object>> lis = new CounterResultListener<Map<String, Object>>(creatures.length, new DelegationResultListener<Void>(destroyed)); for(int i = 0; i < creatures.length; i++) { // System.out.println(creatures[i].getAID()); en.removeCreature(creatures[i]); cms.destroyComponent(creatures[i].getAID()).addResultListener(lis); } destroyed.get(); cms.destroyComponent(getScope().getComponentIdentifier().getParent()); } }