Class AplibEDSL

java.lang.Object
nl.uu.cs.aplib.AplibEDSL

public class AplibEDSL extends Object
Provide a set of convenience static methods to be used as operators/combinators for constructing GoalStructure and Tactic.
Author:
wish
  • Constructor Details

    • AplibEDSL

      public AplibEDSL()
  • Method Details

    • SEQ

      public static GoalStructure SEQ(GoalStructure... subgoals)
      Create a SEQ type GoalStructure.
    • FIRSTof

      public static GoalStructure FIRSTof(GoalStructure... subgoals)
      Create a FIRSTof type GoalStructure.
    • REPEAT

      public static GoalStructure REPEAT(GoalStructure subgoal)
      Create a REPEAT type GoalStructure. 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

      public static <State> GoalStructure lift(String goalname, Predicate<State> p)
      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

      public static <State> GoalStructure lift(Predicate<State> p)
    • lift

      public static <AgentState,​ Proposal> GoalStructure lift(String goalname, Action a)
      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

      public static <State> GoalStructure SUCCESS()
      This goal will always succeeds.
    • SUCCESS

      public static <State> GoalStructure SUCCESS(String goalname)
      This goal will always succeeds. The goal name can be configured as given.
    • DEBUG

      public static <State> GoalStructure DEBUG(String debugstring)
      A goal structure that does nothing but printing a message for debugging purpose.
    • FAIL

      public static <State> GoalStructure FAIL()
      This goal will always fail.
    • FAIL

      public static <State> GoalStructure FAIL(String goalname)
      This goal will always fail. The goal name can be configured as given.
    • WHILEDO

      @Deprecated public static <State> GoalStructure WHILEDO(Predicate<State> p, GoalStructure subgoal)
      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

      public static <State> GoalStructure TRYIF(Predicate<State> p, GoalStructure g1, GoalStructure g2)
      If this goal becomes current, it will evaluate the current state.
      1. 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.
      2. 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

      public static Goal goal(String name)
      Create a blank instance of Goal with the given name.
    • action

      public static Action action(String name)
      Create a blank Action with 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)
      Like addBefore(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)
      Like addAfter(Function), but allows the returned proposal to be specified, rather than just null.
    • action

      public static Action action()
      Create a blank Action.
    • FIRSTof

      public static Tactic FIRSTof(Tactic... strategies)
      To construct a FIRSTof Tactic.
    • Abort

      public static Action Abort()
      Creating an Abort action ()
    • ABORT

      public static Tactic.PrimitiveTactic ABORT()
      Creating a Tactic.PrimitiveTactic that wraps over an Abort action.
    • SEQ

      public static Tactic SEQ(Tactic... strategies)
      To construct a SEQ Tactic.
    • ANYof

      public static Tactic ANYof(Tactic... strategies)
      To construct a ANYof Tactic.