Class AplibEDSL
GoalStructure and
Tactic.- Author:
- wish
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ActionAbort()Creating an Abort action ()static Tactic.PrimitiveTacticABORT()Creating aTactic.PrimitiveTacticthat wraps over an Abort action.static Actionaction()Create a blankAction.static ActionCreate a blankActionwith the given name.static <AgentState extends SimpleState>
ActionaddAfter(Function<AgentState,GoalStructure> fgoal)Construct an action that inserts the goal-structure G as the next direct sibling of the current goal.static <AgentState extends SimpleState, Proposal>
ActionaddAfter(Function<AgentState,GoalStructure> fgoal, Proposal v)LikeaddAfter(Function), but allows the returned proposal to be specified, rather than just null.static <AgentState extends SimpleState>
ActionaddBefore(Function<AgentState,GoalStructure> fgoal)Construct an action that inserts the goal-structure G as a sibling before the current goal.static <AgentState extends SimpleState, Proposal>
ActionaddBefore(Function<AgentState,GoalStructure> fgoal, Proposal v)LikeaddBefore(Function), but allows the returned proposal to be specified, rather than just null.static TacticTo construct a ANYofTactic.static <State> GoalStructureA goal structure that does nothing but printing a message for debugging purpose.static <AgentState>
GoalStructureDEPLOY(BasicAgent agent, Function<AgentState,GoalStructure> dynamicgoal)The combinator will "dynamically" deploy a goal to be executed/adopted after executing this combinator.static <AgentState>
GoalStructureDEPLOYonce(BasicAgent agent, Function<AgentState,GoalStructure> dynamicgoal)The combinator will "dynamically" deploy a goal to be executed/adopted after executing this combinator.static <State> GoalStructureFAIL()This goal will always fail.static <State> GoalStructureThis goal will always fail.static GoalStructureFIRSTof(GoalStructure... subgoals)Create a FIRSTof typeGoalStructure.static TacticTo construct a FIRSTofTactic.static GoalCreate a blank instance ofGoalwith the given name.static <State> Pair<Predicate<State>,GoalStructure>HANDLE(Predicate<State> p, GoalStructure handler)Just for representing a pair (p,G) of state-predicate and a goal structure.static <AgentState extends SimpleState, QueryResult>
GoalStructureIF(Function<AgentState,QueryResult> q, Function<QueryResult,GoalStructure> g1, GoalStructure g2)When this goal structure is executed, it first apply the query function q on the current agent state S to obtain a value a.static <AgentState extends SimpleState>
GoalStructureIF(Predicate<AgentState> p, GoalStructure g1, GoalStructure g2)When this goal structure is executed, it evaluates p on the current state.static <State> GoalStructureIFELSE(Predicate<State> p, GoalStructure g1, GoalStructure g2)Deprecated.static <State> GoalStructureINTERRUPTIBLE(Goal g, Pair<Predicate<State>,GoalStructure>... handlers)Construct a goal that will be interrupted on a certain conditions.static <State> GoalStructureTurn a predicate over state to become a goal.static <AgentState, Proposal>
GoalStructureTurn an action into a goal.static <State> GoalStructurestatic GoalStructureREPEAT(GoalStructure subgoal)Create a REPEAT typeGoalStructure.static <AgentState extends SimpleState>
GoalStructureREPEAT(GoalStructure subgoal, Predicate<AgentState> g)REPEAT(a,G,p) implements repeat-until.static GoalStructureSEQ(GoalStructure... subgoals)Create a SEQ typeGoalStructure.static TacticTo construct a SEQTactic.static <State> GoalStructureSUCCESS()This goal will always succeeds.static <State> GoalStructureThis goal will always succeeds.static <State> GoalStructureTRYIF(Predicate<State> p, GoalStructure g1, GoalStructure g2)If this goal becomes current, it will evaluate the current state.static <AgentState extends SimpleState>
GoalStructureWHILE(Predicate<AgentState> g, GoalStructure subgoal)WHILE(a,p,G) will repeatedly try G, while p is true.static <State> GoalStructureWHILEDO(Predicate<State> p, GoalStructure subgoal)Deprecated.
-
Constructor Details
-
AplibEDSL
public AplibEDSL()
-
-
Method Details
-
SEQ
Create a SEQ typeGoalStructure. -
FIRSTof
Create a FIRSTof typeGoalStructure. -
REPEAT
Create a REPEAT typeGoalStructure. Let H be the goal structure created by REPEAT(G). Executing H will repeatedly try G until it succeeds. Then H succeeds. H fails if it runs out of budget. -
REPEAT
public static <AgentState extends SimpleState> GoalStructure REPEAT(GoalStructure subgoal, Predicate<AgentState> g)REPEAT(a,G,p) implements repeat-until. It will repeatedly try G, while p is true. Unlike the standard REPEAT, we do not stops when G succeeds. The iteration stops when at the end of G, g is false on the resulting state. -
lift
Turn a predicate over state to become a goal. When this goal becomes current, the agent will test the predicate on its state; if the predicate holds on the state, the goal is solved, and else the goal is declared as failed. -
lift
-
lift
Turn an action into a goal. The goal itself will always succeeds. If the action is enabled, the action will be executed (once), that would then automatically solves this goal. If the action is not enabled, then nothing happens (the goal is kept, and it is not solved). -
SUCCESS
This goal will always succeeds. -
SUCCESS
This goal will always succeeds. The goal name can be configured as given. -
DEBUG
A goal structure that does nothing but printing a message for debugging purpose. -
FAIL
This goal will always fail. -
FAIL
This goal will always fail. The goal name can be configured as given. -
WHILEDO
Deprecated. -
WHILE
public static <AgentState extends SimpleState> GoalStructure WHILE(Predicate<AgentState> g, GoalStructure subgoal)WHILE(a,p,G) will repeatedly try G, while p is true. The guard p is checked at the start of every iteration. Unlike the standard REPEAT, we do not stops when G succeeds. The iteration stops when at the end of G, g holds on the resulting state. -
IF
public static <AgentState extends SimpleState, QueryResult> GoalStructure IF(Function<AgentState,QueryResult> q, Function<QueryResult,GoalStructure> g1, GoalStructure g2)When this goal structure is executed, it first apply the query function q on the current agent state S to obtain a value a. This value can be null to indicate that the query is not successful.If a is not null, g1(a) will be deployed as the next goal to solve. Else g2 is deployed.
-
IF
public static <AgentState extends SimpleState> GoalStructure IF(Predicate<AgentState> p, GoalStructure g1, GoalStructure g2)When this goal structure is executed, it evaluates p on the current state. If it is true, g1 will be deployed as the next goal. Else g2 is deployed as the next goal. -
IFELSE
@Deprecated public static <State> GoalStructure IFELSE(Predicate<State> p, GoalStructure g1, GoalStructure g2)Deprecated. -
TRYIF
If this goal becomes current, it will evaluate the current state.- If p holds on the current state, the agent will then try the goal g1. If g1 is solved we are done. If g1 fails, g2 is tried.
- If p does not hold, we do g2.
-
DEPLOYonce
public static <AgentState> GoalStructure DEPLOYonce(BasicAgent agent, Function<AgentState,GoalStructure> dynamicgoal)The combinator will "dynamically" deploy a goal to be executed/adopted after executing this combinator. The parameter dynamic goal takes the agent current state and constructs a goal H based on it, and this H is the one that is deployed. Notice that the kind of H produced can thus be made dependent on the current agent state.The new goal H is only deployed once; so if this structure is iterated, it will not deploy another new goal.
-
DEPLOY
public static <AgentState> GoalStructure DEPLOY(BasicAgent agent, Function<AgentState,GoalStructure> dynamicgoal)The combinator will "dynamically" deploy a goal to be executed/adopted after executing this combinator. The paramerter dynamic goal takes the agent current state and constructs a goal H based on it, and this H is the one that is deployed. Notice that the kind of H produced can thus be made dependent on the current agent state. After H is executed, it is removed from the goal-tree. -
INTERRUPTIBLE
public static <State> GoalStructure INTERRUPTIBLE(Goal g, Pair<Predicate<State>,GoalStructure>... handlers)Construct a goal that will be interrupted on a certain conditions. The goal is aborted, and a new goal is launched. When the new goal is done (success or fail), the execution continues with the original goal.For example:
INTERRUPTIBLE(g, HANDLER(c1,H1), HANDLER(c2,H2))
Will abort the execution of g when the condition c1 or c2 becomes true. If c1 is true, we then proceed with the goal H1. When H1 is done, either in success or failure, the execution of g is resumed.
The goal structure constructed with INTERRUPTIBLE, if it terminates within budget, always terminate successfully, even if g itself fails. To check if g was actually successful, you can check its predicate again after the INTERRUPTIBLE.
-
HANDLE
public static <State> Pair<Predicate<State>,GoalStructure> HANDLE(Predicate<State> p, GoalStructure handler)Just for representing a pair (p,G) of state-predicate and a goal structure. -
goal
Create a blank instance ofGoalwith the given name. -
action
Create a blankActionwith the given name. -
addBefore
public static <AgentState extends SimpleState> Action addBefore(Function<AgentState,GoalStructure> fgoal)Construct an action that inserts the goal-structure G as a sibling before the current goal. However, if the parent of this goal-structure is REPEAT (which can only have one child), a SEQ node will first be inserted in-between, and the G is added as the pre-sibling of this goal-structure.G will be marked as auto-remove (it will be automatically removed after it is achieved or failed).
Note that this action returns a null proposal, so it won't solve a goal on its own.
Fail if the current goal is null or if it is the top-goal.
-
addBefore
public static <AgentState extends SimpleState, Proposal> Action addBefore(Function<AgentState,GoalStructure> fgoal, Proposal v)LikeaddBefore(Function), but allows the returned proposal to be specified, rather than just null. -
addAfter
public static <AgentState extends SimpleState> Action addAfter(Function<AgentState,GoalStructure> fgoal)Construct an action that inserts the goal-structure G as the next direct sibling of the current goal. However, if the parent of this goal-structure is REPEAT (which can only have one child), a SEQ node will first be inserted in-between, and the G is added as the next sibling of this goal-structure.G will be marked as auto-remove (it will be automatically removed after it is achieved or failed).
Note that this action returns a null proposal, so it won't solve a goal on its own.
Fail if the current goal is null or if it is the top-goal.
-
addAfter
public static <AgentState extends SimpleState, Proposal> Action addAfter(Function<AgentState,GoalStructure> fgoal, Proposal v)LikeaddAfter(Function), but allows the returned proposal to be specified, rather than just null. -
action
Create a blankAction. -
FIRSTof
To construct a FIRSTofTactic. -
Abort
Creating an Abort action () -
ABORT
Creating aTactic.PrimitiveTacticthat wraps over an Abort action. -
SEQ
To construct a SEQTactic. -
ANYof
To construct a ANYofTactic.
-