Class Action

java.lang.Object
nl.uu.cs.aplib.mainConcepts.Action
Direct Known Subclasses:
Action.Abort

public class Action extends Object
Actions are the building blocks for to build a Tactic. To solve a Goal an agent would need a Tactic. An Action is the simplest form of Tactic. Multiple Actions can be combined to form a more complex strategy. When a Strategy is given to an agent to solve a Goal, we say that the strategy is bound to the agent. Likewise, all Actions in the Strategy are then bound to this agent. Each Action is essentially a stateful program that may produce a proposal to be proposed to the Goal. Conceptually, an Action can be seen as a pair (g,e) of guard and effect. The guard is a predicate ove the agent's state, and the effect part e is a program that reads the agent's state and the Action's own state to produce a proposal (which may be null). In doing so, e may also change both the agent's and the Action's states. Producing a proposal is not mandatory, e.g. if the Action thinks it is not ready to produce one, or if its role is dedicated on inferring more information to be added to the agent's state.

The agent invokes the Action's behavior by invoking the method exec1(SimpleState), passing to it its (the Agent's) state. This method should only be invoked if the Action's guard evaluates to true on the current agent's state. This requirement is not imposed by this implementation of Action. However the implementation of BasicAgent does impose this.

Author:
wish
  • Field Details

    • name

      String name
    • desc

      public String desc
    • completed

      boolean completed
    • totalRuntime

      long totalRuntime
    • invocationCount

      int invocationCount
    • guard

      This Action's guard, which is a query over the agent's state. This action is considered as executable if the query results in a non-null value. Else the action is not executable. Note: by 'the agent' we mean the agent to which this Action becomes bound to.
    • effect

      The effect part of this Action. It is a function that takes: (1) the agent's state as parameter, and (2) the query-result of this action's guard (assumed to be non-null). The function then produces a proposal. Returning a null is interpreted as producing no proposal. By 'the agent' we mean the agent to which this Action becomes bound to.
  • Constructor Details

    • Action

      Action()
    • Action

      public Action(String name)
      Create a blank action with the given name. The effect part of this agent is set to null (so it will crash if you try to call its exec1(SimpleState)).
  • Method Details

    • retrieveQueryResult

      Object retrieveQueryResult()
    • desc

      public Action desc(String desc)
      Add a description string to this Action. It returns the Action itself so that it can be used in the Fluent Interface style.
    • on_

      public <AgentSt> Action on_(Predicate<AgentSt> guard)
      Set the given predicate as the guard of this Action. The method returns the Action itself so that it can be used in the Fluent Interface style.
    • on

      public <AgentSt,​ QueryResult> Action on(Function<AgentSt,​QueryResult> myguard)
      Set the given query function as the guard of this Action. The method returns the Action itself so that it can be used in the Fluent Interface style.
    • do__

      Action do__(Function<SimpleState,​Function<Object,​Object>> action)
      Set the given function as the effect-part of this Action. The method returns the Action itself so that it can be used in the Fluent Interface style.
    • do2

      public <AgentSt,​ QueryResult,​ T> Action do2(Function<AgentSt,​Function<QueryResult,​T>> action)
      Set the given function as the effect-part of this Action. This effect function takes two arguments: the state of the agent, and the value which was the result of this action's guard execution/query.

      The method returns the Action itself so that it can be used in the Fluent Interface style.

    • do1

      public <AgentSt,​ T> Action do1(Function<AgentSt,​T> action)
      Set the given function as the effect-part of this Action. This effect function takes one argument: the state of the agent.

      The method returns the Action itself so that it can be used in the Fluent Interface style.

    • until__

      Action until__(Predicate<SimpleState> myguard)
      Normally, when invoked (by exec1(SimpleState)), at the end of the invocation an Action is marked as completed. So, the next turn the Agent can choose to execute another Action. With this method we force the Agent to keep executing this Action over multiple turns, until the given predicate becomes true. The Action is also considered to be always enabled (it can be executed in any agent's state).

      The method returns the Action itself so that it can be used in the Fluent Interface style.

    • until

      public <AgentSt> Action until(Predicate<AgentSt> myguard)
      Normally, when invoked (by exec1(SimpleState)), at the end of the invocation an Action is marked as completed. So, the next turn the Agent can choose to execute another Action. With this method we force the Agent to keep executing this Action over multiple turns, until the given predicate becomes true. The Action is also considered to be always enabled (it can be executed in any agent's state).

      The method returns the Action itself so that it can be used in the Fluent Interface style.

    • lift

      public Tactic.PrimitiveTactic lift()
      Wrap this Action to become a Tactic.PrimitiveTactic.
    • isCompleted

      public boolean isCompleted()
      True if the Action has been marked as completed.
    • isEnabled

      public boolean isEnabled(SimpleState agentstate)
      True if the guard of this Action evaluates to true on the given agent state.
    • exec1

      public Object exec1(SimpleState agentstate)
      Execute the effect part of this Action on the given agent state. The method will also retrieve the stored result of the guard evaluation, and pass it to the effect-function. This method does not check whether the guard is true on that state. The agent that calls this method is responsible for guaranteeing this.

      Note: calling this method will clear the stored guard's query result.