/** * Get the current goals. */ public Collection<IGoal> getGoals() { return (Collection)((BDIAgentInterpreter)getInterpreter()).getCapability().getGoals(); }
/** * Get the goal api representation. */ public IGoal getGoal(Object goal) { return ((BDIAgentInterpreter)getInterpreter()).getCapability().getRGoal(goal); }
/** * Drop a pojo goal. */ public void dropGoal(Object goal) { for(RGoal rgoal: getCapability().getGoals(goal.getClass())) { if(goal.equals(rgoal.getPojoElement())) { rgoal.drop(); } } }
/** * Get the goals of a given type. */ public <T> Collection<T> getGoals(Class<T> clazz) { Collection<RGoal> rgoals = ((BDIAgentInterpreter)getInterpreter()).getCapability().getGoals(clazz); List<T> ret = new ArrayList<T>(); for(RProcessableElement rgoal: rgoals) { ret.add((T)rgoal.getPojoElement()); } return ret; }
public void resultAvailable(Void result) { RPLANS.set(null); ip.getCapability().removePlan(rplan); Object reason = rplan.getReason(); if(reason instanceof RProcessableElement) ((RProcessableElement)reason).planFinished(ia, rplan); }
public IFuture<Void> execute(final IEvent event, final IRule<Void> rule, final Object context, Object condresult) { for(final RGoal goal: getCapability().getGoals(mgoal)) { executeGoalMethod(m, goal, event) .addResultListener(new IResultListener<Boolean>() { public void resultAvailable(Boolean result) { if(result.booleanValue()) { goal.targetConditionTriggered(getInternalAccess(), event, rule, context); } } public void exceptionOccurred(Exception exception) { } }); } return IFuture.DONE; } });
public IFuture<Void> execute(final IEvent event, final IRule<Void> rule, final Object context, Object condresult) { for(final RGoal goal: getCapability().getGoals(mgoal)) { executeGoalMethod(m, goal, event) .addResultListener(new IResultListener<Boolean>() { public void resultAvailable(Boolean result) { if(result.booleanValue()) { goal.targetConditionTriggered(getInternalAccess(), event, rule, context); } } public void exceptionOccurred(Exception exception) { } }); } return IFuture.DONE; } });
/** * Create belief events from a belief name. * For normal beliefs * beliefchanged.belname and factchanged.belname * and for multi beliefs additionally * factadded.belname and factremoved * are created. */ public static void addBeliefEvents(IInternalAccess ia, List<EventType> events, String belname) { events.add(new EventType(new String[]{ChangeEvent.BELIEFCHANGED, belname})); // the whole value was changed events.add(new EventType(new String[]{ChangeEvent.FACTCHANGED, belname})); // property change of a value BDIAgentInterpreter ip = (BDIAgentInterpreter)((BDIAgent)ia).getInterpreter(); MBelief mbel = ((MCapability)ip.getCapability().getModelElement()).getBelief(belname); if(mbel!=null && mbel.isMulti(ia.getClassLoader())) { events.add(new EventType(new String[]{ChangeEvent.FACTADDED, belname})); events.add(new EventType(new String[]{ChangeEvent.FACTREMOVED, belname})); } }
ip.getCapability().addGoal(goal); goal.setLifecycleState(ia, RGoal.GoalLifecycleState.ADOPTED); ret.setResult(null);
/** * Execute the command. * @param args The argument(s) for the call. * @return The result of the command. */ public IFuture<Void> execute(IInternalAccess ia) { Future<Void> ret = new Future<Void>(); BDIAgentInterpreter ip = (BDIAgentInterpreter)((BDIAgent)ia).getInterpreter(); // goal.unobserveGoal(ia); ip.getCapability().removeGoal(goal); goal.setLifecycleState(ia, RGoal.GoalLifecycleState.DROPPED); ret.setResult(null); return ret; } }
RGoal rgoal = interpreter.getCapability().getRGoal(goal); final MGoal mgoal = rgoal.getMGoal(); MethodInfo mi = mgoal.getServiceParameterMapping(sername==null? "": sername);
public IFuture<Void> execute(IEvent event, IRule<Void> rule, Object context, Object condresult) { for(final RGoal goal: getCapability().getGoals(mgoal)) { if(RGoal.GoalLifecycleState.SUSPENDED.equals(goal.getLifecycleState())) { executeGoalMethod(m, goal, event) .addResultListener(new IResultListener<Boolean>() { public void resultAvailable(Boolean result) { if(result.booleanValue()) { // if(goal.getMGoal().getName().indexOf("AchieveCleanup")!=-1) // System.out.println("Goal made option: "+goal); goal.setLifecycleState(getInternalAccess(), RGoal.GoalLifecycleState.OPTION); // setState(ia, PROCESSABLEELEMENT_INITIAL); } } public void exceptionOccurred(Exception exception) { } }); } } return IFuture.DONE; } });
/** * */ public static void performInitWrites(BDIAgent agent) { synchronized(initwrites) { List<Object[]> writes = initwrites.remove(agent); if(writes!=null) { for(Object[] write: writes) { // System.out.println("initwrite: "+write[0]+" "+write[1]+" "+write[2]); // agent.writeField(write[0], (String)write[1], write[2]); BDIAgentInterpreter ip = (BDIAgentInterpreter)agent.getInterpreter(); RuleSystem rs = ip.getRuleSystem(); final String belname = (String)write[1]; Object val = write[0]; rs.addEvent(new Event(ChangeEvent.BELIEFCHANGED+"."+belname, val)); MBelief mbel = ((MCapability)ip.getCapability().getModelElement()).getBelief(belname); observeValue(rs, val, (BDIAgentInterpreter)agent.getInterpreter(), ChangeEvent.FACTCHANGED+"."+belname, mbel); } } } }
public IFuture<Void> execute(IEvent event, IRule<Void> rule, Object context, Object condresult) { // create the complete inhibitorset for a newly adopted goal RGoal goal = (RGoal)event.getContent(); for(RGoal other: getCapability().getGoals()) { // if(other.getLifecycleState().equals(RGoal.GOALLIFECYCLESTATE_ACTIVE) // && other.getProcessingState().equals(RGoal.GOALPROCESSINGSTATE_INPROCESS) if(!other.isInhibitedBy(goal) && other.inhibits(goal, getInternalAccess())) { goal.addInhibitor(other, getInternalAccess()); } } return IFuture.DONE; } });
public IFuture<Void> execute(IEvent event, IRule<Void> rule, Object context, Object condresult) { for(final RGoal goal: getCapability().getGoals(mgoal)) { if(RGoal.GoalLifecycleState.ACTIVE.equals(goal.getLifecycleState()) && RGoal.GoalProcessingState.IDLE.equals(goal.getProcessingState())) { executeGoalMethod(m, goal, event) .addResultListener(new IResultListener<Boolean>() { public void resultAvailable(Boolean result) { if(!result.booleanValue()) { // System.out.println("Goal maintain triggered: "+goal); // System.out.println("state was: "+goal.getProcessingState()); goal.setProcessingState(getInternalAccess(), RGoal.GoalProcessingState.INPROCESS); } } public void exceptionOccurred(Exception exception) { } }); } } return IFuture.DONE; } });
public IFuture<Void> execute(IEvent event, IRule<Void> rule, Object context, Object condresult) { for(final RGoal goal: getCapability().getGoals(mgoal)) { if(RGoal.GoalLifecycleState.ACTIVE.equals(goal.getLifecycleState()) && RGoal.GoalProcessingState.PAUSED.equals(goal.getProcessingState())) { executeGoalMethod(m, goal, event) .addResultListener(new IResultListener<Boolean>() { public void resultAvailable(Boolean result) { if(result.booleanValue()) { goal.setTriedPlans(null); goal.setApplicablePlanList(null); goal.setProcessingState(getInternalAccess(), RGoal.GoalProcessingState.INPROCESS); } } public void exceptionOccurred(Exception exception) { } }); } } return IFuture.DONE; } });
public IFuture<Void> execute(IEvent event, IRule<Void> rule, Object context, Object condresult) for(final RGoal goal: getCapability().getGoals(mgoal))
MBelief mbel = ((MCapability)ip.getCapability().getModelElement()).getBelief(belname);
public IFuture<Void> execute(IEvent event, IRule<Void> rule, Object context, Object condresult) for(final RGoal goal: getCapability().getGoals(mgoal))
public IFuture<Void> execute(IEvent event, IRule<Void> rule, Object context, Object condresult) { RGoal goal = (RGoal)event.getContent(); // if(goal.getId().indexOf("PerformPatrol")!=-1) // System.out.println("addinh: "+goal); MDeliberation delib = goal.getMGoal().getDeliberation(); if(delib!=null) { Set<MGoal> inhs = delib.getInhibitions(); if(inhs!=null) { for(MGoal inh: inhs) { Collection<RGoal> goals = getCapability().getGoals(inh); for(RGoal other: goals) { // if(!other.isInhibitedBy(goal) && goal.inhibits(other, getInternalAccess())) if(!goal.isInhibitedBy(other) && goal.inhibits(other, getInternalAccess())) { other.addInhibitor(goal, getInternalAccess()); } } } } } return IFuture.DONE; } });