Package nl.uu.cs.aplib.mainConcepts
Class GoalStructure
java.lang.Object
nl.uu.cs.aplib.mainConcepts.GoalStructure
- Direct Known Subclasses:
GoalStructure.PrimitiveGoal
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:
- SEQ g1,g2,... represents a series of goals that all have to be solved, and solved in the order as they are listed.
- 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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Represent the available types ofGoalStructure
.static class
A special subclass ofGoalStructure
to represent a leaf, wrapping around an instance ofGoal
. -
Field Summary
FieldsModifier and TypeFieldDescription(package private) boolean
A sub-goal-structure that is flagged as auto-remove will be automatically removed when it is achieved or failed.(package private) double
Maximum limit on the budget that can be allocated to this goal structure.(package private) double
The budget that remains for this goal structure.(package private) GoalStructure.GoalsCombinator
(package private) double
Total budget that is spent so far on this goal structure.(package private) long
(package private) GoalStructure
(package private) ProgressStatus
(package private) List<GoalStructure>
-
Constructor Summary
ConstructorsConstructorDescriptionGoalStructure(GoalStructure.GoalsCombinator type, GoalStructure... subgoals)
Construct a new GoalStructure with the specified type of node (SEQ, FIRSTOFF, or PRIMITIVE) and the given subgoals. -
Method Summary
Modifier and TypeMethodDescriptionboolean
(package private) GoalStructure
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.double
Return the remaining budget for this goal structure.Return the type of this GoalStructure (SEQ, FIRSTOF, or PRIMITIVE).(package private) GoalStructure.PrimitiveGoal
double
Return the agent's maximum allowed budget each time the goal is adopted.getName()
If this is a primitive-goal, returns its name.(package private) GoalStructure.PrimitiveGoal
Assuming this goal is closed (that is, it has been solved or failed), this method will return the nextGoalStructure.PrimitiveGoal
to solve.Return the parent of this GoalStructure.Get the status of this GoalStructure.(package private) boolean
Check if this goal structure is a descendant of G.boolean
Check if this goal structure is isomorphic with H.boolean
True is this goal has no parent.(package private) void
maxbudget(double b)
void
Print a summary of the state of this GoalStructure.(package private) void
registerConsumedBudget(double delta)
Register that the agent has consumed the given amount of budget.(package private) void
registerUsedTime(long duration)
(package private) void
setStatusToFail(String reason)
Set the status of this goal to fail, and propagating this accordingly to its ancestors.(package private) void
(package private) void
setStatusToSuccess(String info)
Set the status of this goal to success, and propagating this accordingly to its ancestors.Format a summary of the state of this GoalStructure to a readable string.(package private) String
showGoalStructureStatusWorker(int level)
-
Field Details
-
parent
GoalStructure parent -
subgoals
List<GoalStructure> subgoals -
combinator
GoalStructure.GoalsCombinator combinator -
status
ProgressStatus status -
autoRemove
boolean autoRemoveA 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 bmaxMaximum limit on the budget that can be allocated to this goal structure. -
consumedBudget
double consumedBudgetTotal budget that is spent so far on this goal structure. -
consumedTime
long consumedTime -
budget
double budgetThe budget that remains for this goal structure.
-
-
Constructor Details
-
GoalStructure
GoalStructure() -
GoalStructure
Construct a new GoalStructure with the specified type of node (SEQ, FIRSTOFF, or PRIMITIVE) and the given subgoals.
-
-
Method Details
-
getCombinatorType
Return the type of this GoalStructure (SEQ, FIRSTOF, or PRIMITIVE). -
getSubgoals
-
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
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
Set the status of this goal to success, and propagating this accordingly to its ancestors. -
setStatusToFail
Set the status of this goal to fail, and propagating this accordingly to its ancestors. -
setStatusToFailBecauseBudgetExhausted
void setStatusToFailBecauseBudgetExhausted() -
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
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 nextGoalStructure.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
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
-
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
-
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.
-