/** * Get the apl. * @return The apl. */ public APL getApplicablePlanList() { if(apl==null) apl = new APL(this); return apl; }
/** * Select candidates from the list of applicable plans. */ public List<ICandidateInfo> selectCandidates(MCapability mcapa, IInternalAccess ia) { List<ICandidateInfo> ret = new ArrayList<ICandidateInfo>(); MProcessableElement mpe = (MProcessableElement)element.getModelElement(); // todo: include a number of retries... int numcandidates = 1; if(mpe.isPostToAll()) { numcandidates = Integer.MAX_VALUE; } // todo: test if this works with posttoall because getNextCandidate() does not remove a candidate?! for(int i=0; i<numcandidates && candidates!=null && candidates.size()>0; i++) { ret.add(getNextCandidate(mcapa, ia)); } return ret; }
int candprio = getPriority(finals.get(0), mcapa); for(int i=1; i<candidates.size(); i++) int tmpprio = getPriority(tmp, mcapa); if(tmpprio>candprio || (tmpprio == candprio && getRank(tmp)>getRank(finals.get(0)))) candprio = tmpprio; else if(tmpprio==candprio && getRank(tmp)==getRank(finals.get(0)))
col.add(getCandidates()); cand = (ICandidateInfo)m.invoke(element.getPojoElement(), BDIAgentFeature.getInjectionValues(m.getParameterTypes(), m.getParameterAnnotations(), melem, null, null, element, col, ia)); int candprio = getPriority(finals.get(0), mcapa); for(int i=1; i<candidates.size(); i++) int tmpprio = getPriority(tmp, mcapa); if(tmpprio>candprio || (tmpprio == candprio && getRank(tmp)>getRank(finals.get(0)))) candprio = tmpprio; else if(tmpprio==candprio && getRank(tmp)==getRank(finals.get(0)))
if(getApplicablePlanList().isEmpty())
doBuild(ia).addResultListener(new ExceptionDelegationResultListener<List<ICandidateInfo>, Void>(ret) removeTriedCandidates(); ret.setResult(null);
List<ICandidateInfo> cands = element.getApplicablePlanList().selectCandidates(mcapa, ia); List<ICandidateInfo> allcands = apl.getCandidates(); if(allcands.size()==1)
/** * */ public void planFinished(IInternalAccess ia, RPlan rplan) { if(rplan!=null) { addTriedPlan(rplan); if(apl!=null) apl.planFinished(rplan); } }
apl.build(ia).addResultListener(ia.createResultListener(new DelegationResultListener<Void>(ret)
doBuild(ia).addResultListener(new ExceptionDelegationResultListener<List<Object>, Void>(ret)
MCapability mcapa = (MCapability)ip.getCapability().getModelElement(); List<Object> cands = element.getApplicablePlanList().selectCandidates(mcapa); if(cands!=null && !cands.isEmpty())
/** * Create candidates for a matching mplan. * Checks precondition and evaluates bindings (if any). * @return List of plan info objects. */ public static List<ICandidateInfo> createMPlanCandidates(IInternalAccess agent, MPlan mplan, RProcessableElement element) { List<ICandidateInfo> ret = new ArrayList<ICandidateInfo>(); List<Map<String, Object>> bindings = calculateBindingElements(agent, mplan, element); if(bindings!=null) { for(Map<String, Object> binding: bindings) { ret.add(new CandidateInfoMPlan(new MPlanInfo(mplan, binding), element, agent)); } } // No binding: generate one candidate. else { ret.add(new CandidateInfoMPlan(new MPlanInfo(mplan, null), element, agent)); } return ret; }
public void customResultAvailable(Void result) { // System.out.println("find applicable candidates 2: "+element+" "+apl); if(apl.isEmpty()) { element.setState(RProcessableElement.State.NOCANDIDATES); element.planFinished(ia, null); // element.reason(ia); } else { element.setState(RProcessableElement.State.APLAVAILABLE); ia.getExternalAccess().scheduleStep(new SelectCandidatesAction(element)); } ret.setResult(null); } }));
/** * Called when plan execution has finished. */ public void planFinished(IInternalAccess ia, IInternalPlan rplan) { if(rplan!=null) { if(apl!=null) { // do not add tried plan if apl is already reset because procedural // goal semantics is wrong otherwise (isProceduralSucceeded) addTriedPlan(rplan); apl.planFinished(rplan); } } }
apl.build(ia).addResultListener(ia.getComponentFeature(IExecutionFeature.class).createResultListener(new DelegationResultListener<Void>(ret)
/** * Create candidates for a matching mgoal. * Checks precondition and evaluates bindings (if any). * @return List of goal info objects. */ public static List<ICandidateInfo> createMGoalCandidates(IInternalAccess agent, MGoal mgoal, RProcessableElement element) { List<ICandidateInfo> ret = new ArrayList<ICandidateInfo>(); List<Map<String, Object>> bindings = calculateBindingElements(agent, mgoal, element); if(bindings!=null) { for(Map<String, Object> binding: bindings) { ret.add(new CandidateInfoMGoal(new MGoalInfo(mgoal, binding), element, agent)); } } // No binding: generate one candidate. else { ret.add(new CandidateInfoMGoal(new MGoalInfo(mgoal, null), element, agent)); } return ret; }
public void customResultAvailable(Void result) { if(apl.isEmpty()) { // if(element.toString().indexOf("go_home")!=-1) // System.out.println("find applicable candidates 2a: "+element.getId()+" "+apl); element.setState(RProcessableElement.State.NOCANDIDATES); element.planFinished(ia, null); // element.reason(ia); } else { // if(element.toString().indexOf("go_home")!=-1) // System.out.println("find applicable candidates 2b: "+element.getId()+" "+apl); element.setState(RProcessableElement.State.APLAVAILABLE); ia.getComponentFeature(IExecutionFeature.class).scheduleStep(new SelectCandidatesAction(element)); } ret.setResult(null); } public void exceptionOccurred(Exception exception)
/** * Get the apl. * @return The apl. */ public APL getApplicablePlanList() { if(apl==null) apl = new APL(this); return apl; }
/** * */ public List<Object> selectCandidates(MCapability mcapa) { List<Object> ret = new ArrayList<Object>(); MProcessableElement mpe = (MProcessableElement)element.getModelElement(); // todo: include a number of retries... int numcandidates = 1; if(mpe.isPostToAll()) { numcandidates = Integer.MAX_VALUE; } for(int i=0; i<numcandidates && candidates.size()>0; i++) { ret.add(getNextCandidate(mcapa)); } return ret; }
public IFuture<Void> execute(IEvent event, IRule<Void> rule, Object context, Object condresult) { // System.out.println("create: "+create); List<Map<String, Object>> bindings = APL.calculateBindingElements(component, mgoal, null); if(bindings!=null) { for(Map<String, Object> binding: bindings) { RGoal rgoal = new RGoal(component, mgoal, null, null, binding, null, null); dispatchTopLevelGoal(rgoal).addResultListener(goallis); } } // No binding: generate one candidate. else { RGoal rgoal = new RGoal(component, mgoal, null, null, null, null, null); dispatchTopLevelGoal(rgoal).addResultListener(goallis); } return IFuture.DONE; } });