Class Action
- Direct Known Subclasses:
Action.Abort
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
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescription(package private) boolean
(package private) Function<SimpleState,Function<Object,Object>>
The effect part of this Action.(package private) Function<SimpleState,Object>
This Action's guard, which is a query over the agent's state.(package private) int
(package private) String
(package private) long
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionAdd a description string to this Action.(package private) Action
Set the given function as the effect-part of this Action.<AgentSt, T>
ActionSet the given function as the effect-part of this Action.<AgentSt, QueryResult, T>
ActionSet the given function as the effect-part of this Action.exec1(SimpleState agentstate)
Execute the effect part of this Action on the given agent state.boolean
True if the Action has been marked as completed.boolean
isEnabled(SimpleState agentstate)
True if the guard of this Action evaluates to true on the given agent state.lift()
Wrap this Action to become aTactic.PrimitiveTactic
.<AgentSt, QueryResult>
ActionSet the given query function as the guard of this Action.<AgentSt> Action
Set the given predicate as the guard of this Action.(package private) Object
<AgentSt> Action
Normally, when invoked (byexec1(SimpleState)
), at the end of the invocation an Action is marked as completed.(package private) Action
until__(Predicate<SimpleState> myguard)
Normally, when invoked (byexec1(SimpleState)
), at the end of the invocation an Action is marked as completed.
-
Field Details
-
name
String name -
desc
-
completed
boolean completed -
totalRuntime
long totalRuntime -
invocationCount
int invocationCount -
guard
Function<SimpleState,Object> guardThis 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
Function<SimpleState,Function<Object,Object>> effectThe 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
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 itsexec1(SimpleState)
).
-
-
Method Details
-
retrieveQueryResult
Object retrieveQueryResult() -
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_
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
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__
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
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
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__
Normally, when invoked (byexec1(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
Normally, when invoked (byexec1(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
Wrap this Action to become aTactic.PrimitiveTactic
. -
isCompleted
public boolean isCompleted()True if the Action has been marked as completed. -
isEnabled
True if the guard of this Action evaluates to true on the given agent state. -
exec1
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.
-