jill/src/main/java/io/github/agentsoz/jill/core/IntentionSelector.java
private boolean manageGoal(int agentIndex, Agent agent, Stack255 agentExecutionStack, Goal node) {
    // Get the goal type for this goal
    GoalType gtype = (GoalType) GlobalState.goalTypes.find(node.getClass().getName());
    byte[] ptypes = gtype.getChildren();
    assert (ptypes != null);
    // Clear any previous plan bindings before adding any new ones
    bindings.clear();
    for (int p = 0; p < ptypes.length; p++) {
      PlanType ptype = (PlanType) GlobalState.planTypes.get(ptypes[p]);

      try {
        // Create an object of this Plan type, so we can
        // access its context condition
        Plan planInstance =
            (Plan) (ptype.getPlanClass().getConstructor(Agent.class, Goal.class, String.class)
                .newInstance(GlobalState.agents.get(agentIndex), node, "p"));
        // Clear previously buffered context results if any
        agent.clearLastResults();
        // Evaluate the context condition
        if (planInstance.context()) {
          // Get the results of context query just performed
          Set<Belief> results = agent.getLastResults();
          // Add the results to the bindings
          bindings.add(planInstance, (results == null) ? null : new LinkedHashSet<Belief>(results));
        }
      } catch (NoSuchMethodException | SecurityException | InstantiationException
          | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        logger.error("Could not create plan object of type " + ptype.getClass().getName(), e);
      }
    }
    int numBindings = bindings.size();
    if (numBindings == 0) {
      // No plan options for this goal at this point in time, so move to the next agent
      logger.debug(Log.logPrefix(agent.getId()) + " has no applicable plans for goal " + gtype
          + " and will continue to wait indefinitely");
      return false;
    }
    // Call the meta-level planning prior to plan selection
    agent.notifyAgentPrePlanSelection(bindings);
    // Pick a plan option using specified policy
    Plan planInstance = bindings.selectPlan(GlobalConstant.PLAN_SELECTION_POLICY);
    // Now push the plan on to the intention stack
    synchronized (agentExecutionStack) {
      logger.debug(Log.logPrefix(agent.getId()) + " choose an instance of plan "
          + planInstance.getClass().getSimpleName() + " to handle goal "
          + node.getClass().getSimpleName());
      agentExecutionStack.push(planInstance);
    }
    return true;
  }
private boolean manageGoal(int agentIndex, Agent agent, Stack255 agentExecutionStack, Goal node) {
    // Get the goal type for this goal
    GoalType gtype = (GoalType) GlobalState.goalTypes.find(node.getClass().getName());
    byte[] ptypes = gtype.getChildren();
    assert (ptypes != null);
    // Clear any previous plan bindings before adding any new ones
    bindings.clear();
    for (int p = 0; p < ptypes.length; p++) {
      PlanType ptype = (PlanType) GlobalState.planTypes.get(ptypes[p]);

      try {
        // Create an object of this Plan type, so we can
        // access its context condition
        Plan planInstance =
            (Plan) (ptype.getPlanClass().getConstructor(Agent.class, Goal.class, String.class)
                .newInstance(GlobalState.agents.get(agentIndex), node, "p"));
        // Clear previously buffered context results if any
        agent.clearLastResults();
        // Evaluate the context condition
        if (planInstance.context()) {
          // Get the results of context query just performed
          Set<Belief> results = agent.getLastResults();
          // Add the results to the bindings
          bindings.add(planInstance, (results == null) ? null : new LinkedHashSet<Belief>(results));
        }
      } catch (NoSuchMethodException | SecurityException | InstantiationException
          | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        logger.error("Could not create plan object of type " + ptype.getClass().getName(), e);
      }
    }
    int numBindings = bindings.size();
    if (numBindings == 0) {
      // No plan options for this goal at this point in time, so move to the next agent
      logger.debug(Log.logPrefix(agent.getId()) + " has no applicable plans for goal " + gtype
          + " and will continue to wait indefinitely");
      return false;
    }
    // Call the meta-level planning prior to plan selection
    agent.notifyAgentPrePlanSelection(bindings);
    // Pick a plan option using specified policy
    Plan planInstance = bindings.selectPlan(GlobalConstant.PLAN_SELECTION_POLICY);
    // Now push the plan on to the intention stack
    synchronized (agentExecutionStack) {
      logger.debug(Log.logPrefix(agent.getId()) + " choose an instance of plan "
          + planInstance.getClass().getSimpleName() + " to handle goal "
          + node.getClass().getSimpleName());
      agentExecutionStack.push(planInstance);
    }
    return true;
  }
private boolean manageGoal ( int agentIndex , Agent agent , Stack255 agentExecutionStack , Goal node ) { // Get the goal type for this goal GoalType gtype = ( GoalType ) GlobalState . goalTypes . find ( node . getClass ( ) . getName ( ) ) ; byte [ ] ptypes = gtype . getChildren ( ) ; assert ( ptypes != null ) ; // Clear any previous plan bindings before adding any new ones bindings . clear ( ) ; for ( int p = 0 ; p < ptypes . length ; p ++ ) { PlanType ptype = ( PlanType ) GlobalState . planTypes . get ( ptypes [ p ] ) ; try { // Create an object of this Plan type, so we can // access its context condition Plan planInstance = ( Plan ) ( ptype . getPlanClass ( ) . getConstructor ( Agent . class , Goal . class , String . class ) . newInstance ( GlobalState . agents . get ( agentIndex ) , node , "p" ) ) ; // Clear previously buffered context results if any agent . clearLastResults ( ) ; // Evaluate the context condition if ( planInstance . context ( ) ) { // Get the results of context query just performed Set < Belief > results = agent . getLastResults ( ) ; // Add the results to the bindings bindings . add ( planInstance , ( results == null ) ? null : new LinkedHashSet < Belief > ( results ) ) ; } } catch ( NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) { logger . error ( "Could not create plan object of type " + ptype . getClass ( ) . getName ( ) , e ) ; } } int numBindings = bindings . size ( ) ; if ( numBindings == 0 ) { // No plan options for this goal at this point in time, so move to the next agent logger . debug ( Log . logPrefix ( agent . getId ( ) ) + " has no applicable plans for goal " + gtype + " and will continue to wait indefinitely" ) ; return false ; } // Call the meta-level planning prior to plan selection agent . notifyAgentPrePlanSelection ( bindings ) ; // Pick a plan option using specified policy Plan planInstance = bindings . selectPlan ( GlobalConstant . PLAN_SELECTION_POLICY ) ; // Now push the plan on to the intention stack synchronized ( agentExecutionStack ) { logger . debug ( Log . logPrefix ( agent . getId ( ) ) + " choose an instance of plan " + planInstance . getClass ( ) . getSimpleName ( ) + " to handle goal " + node . getClass ( ) . getSimpleName ( ) ) ; agentExecutionStack . push ( planInstance ) ; } return true ; }
Manages the goal at the top of the execution stack of an agent. All relevant plans are
evaluated to see if their context conditions hold. Plans deemed applicable are then added to
the list of bindings from which a plan instane will be eventually selected.

@param agentIndex the agent's index
@param agent the agent in question
@param agentExecutionStack the agent's execution stack
@param node the goal at the top of the xecution stack
@return false if something went wrong, true otherwise
Manages the goal at the top of the execution stack of an agent . All relevant plans are evaluated to see if their context conditions hold . Plans deemed applicable are then added to the list of bindings from which a plan instane will be eventually selected .