Class GoalStructure

java.lang.Object
nl.uu.cs.aplib.mainConcepts.GoalStructure
Direct Known Subclasses:
GoalStructure.PrimitiveGoal

public class GoalStructure extends Object
A GoalStructure is a generalization of a Goal. It is a tree-shaped structure that conceptually represents a more complex goal. The simplest GoalStructure is an object of type GoalStructure.PrimitiveGoal. A GoalStructure.PrimitiveGoal itself is a subclass of GoalTree. Such a GoalStructure represents a single leaf, containing a single instance of Goal, which is the concrete goal represented by this leaf.

More complex GoalStructure can be constructed by combining subgoals. There are two types of nodes available to combine sub-GoalStructure: the SEQ and FIRSTOF nodes:

  1. SEQ g1,g2,... represents a series of goals that all have to be solved, and solved in the order as they are listed.
  2. FIRSTof g1,g2,... represents a series of alternative goals. They will be tried one at a time, starting from g1. If one is solved, the entire ALT is solved. If all subgoals fail, the ALT fails.
Author:
wish
  • Field Details

    • parent

    • subgoals

      List<GoalStructure> subgoals
    • combinator

    • status

    • autoRemove

      boolean autoRemove
      A sub-goal-structure that is flagged as auto-remove will be automatically removed when it is achieved or failed. This flag is by default set to false (so, NO auto-removal). If set to true, then auto-remove applies.

      In principle, only goals dynamically added through agent.addBefore or agent.addAfter could be auto-remove.

    • bmax

      double bmax
      Maximum limit on the budget that can be allocated to this goal structure.
    • consumedBudget

      double consumedBudget
      Total budget that is spent so far on this goal structure.
    • consumedTime

      long consumedTime
    • budget

      double budget
      The budget that remains for this goal structure.
  • Constructor Details

    • GoalStructure

      GoalStructure()
    • GoalStructure

      public GoalStructure(GoalStructure.GoalsCombinator type, GoalStructure... subgoals)
      Construct a new GoalStructure with the specified type of node (SEQ, FIRSTOFF, or PRIMITIVE) and the given subgoals.
  • Method Details

    • getCombinatorType

      public GoalStructure.GoalsCombinator getCombinatorType()
      Return the type of this GoalStructure (SEQ, FIRSTOF, or PRIMITIVE).
    • getSubgoals

      public List<GoalStructure> getSubgoals()
    • getParent

      public GoalStructure getParent()
      Return the parent of this GoalStructure. It returns null if it has no parent.
    • isTopGoal

      public boolean isTopGoal()
      True is this goal has no parent.
    • checkIfWellformed

      public boolean checkIfWellformed()
    • isomorphic

      public boolean isomorphic(GoalStructure H)
      Check if this goal structure is isomorphic with H. This is the case if they have primitive goals with the same names, and they have the same tree-shapes.
    • setStatusToSuccess

      void setStatusToSuccess(String info)
      Set the status of this goal to success, and propagating this accordingly to its ancestors.
    • setStatusToFail

      void setStatusToFail(String reason)
      Set the status of this goal to fail, and propagating this accordingly to its ancestors.
    • setStatusToFailBecauseBudgetExhausted

      void setStatusToFailBecauseBudgetExhausted()
    • getStatus

      public ProgressStatus getStatus()
      Get the status of this GoalStructure. The status is INPROGRESS if the GoalStructure is not solved or failed yet. It is SUCCESS if the GoalStructure was solved, and FAILED if the GoalStructure has been marked as such.
    • getName

      public String getName()
      If this is a primitive-goal, returns its name. Else return the name of the combinator of this goal structure.
    • getNextPrimitiveGoal_andAllocateBudget

      GoalStructure.PrimitiveGoal getNextPrimitiveGoal_andAllocateBudget()
      Assuming this goal is closed (that is, it has been solved or failed), this method will return the next GoalStructure.PrimitiveGoal to solve. The method will traverse up through the parent of this GoalStructure to look for this next goal. If none is found, null is returned.

      If a new GoalStructure.PrimitiveGoal can be found, it will be adopted. So, budget will also be allocated for it. Recursively, all its ancestors that just become current will also get freshly allocated budget.

    • getDeepestFirstPrimGoal_andAllocateBudget

      GoalStructure.PrimitiveGoal getDeepestFirstPrimGoal_andAllocateBudget()
    • get_Concluded_AutoRemove_Subgoal

      GoalStructure get_Concluded_AutoRemove_Subgoal()
      Apply a depth-first=-search, to find the first descedant (child or lower) subgoal G that is concluded and has its auto-remove flag turned on. There should be at most just one such G. Note that this method won't mark "this" goal itself as G (G has to be a child or lower).

      It is an error if auto-removal would cause a goal to have an empty list of subgoals.

    • makeInProgressAgain

      void makeInProgressAgain()
    • isDescendantOf

      boolean isDescendantOf(GoalStructure G)
      Check if this goal structure is a descendant of G. It is it is G itself, or if its parent is a descendant of G.
    • maxbudget

      public GoalStructure maxbudget(double b)
    • registerConsumedBudget

      void registerConsumedBudget(double delta)
      Register that the agent has consumed the given amount of budget. Delta will be subtracted from this goal-structure's budget, as well as that of its ancestors.
    • registerUsedTime

      void registerUsedTime(long duration)
    • getBudget

      public double getBudget()
      Return the remaining budget for this goal structure.
    • getMaxBudgetAllowed

      public double getMaxBudgetAllowed()
      Return the agent's maximum allowed budget each time the goal is adopted.
    • showGoalStructureStatusWorker

      String showGoalStructureStatusWorker(int level)
    • showGoalStructureStatus

      public String showGoalStructureStatus()
      Format a summary of the state of this GoalStructure to a readable string.
    • printGoalStructureStatus

      public void printGoalStructureStatus()
      Print a summary of the state of this GoalStructure.