3.2 Syntax
3.2.4 Primitive operations on plan instances
Plan instances are elements of the plan state of agents. Each plan instance consists of an unique id, an initial plan (the one assigned for the instance when it is generated), a current suffix (the part of the instance still to be executed), one or more justifications, a substitution, and at most one subgoal. As with atom instances, ids are used to distinguish between different plan instances, even if they have syntactically identical plans.
A justification specifies an atom instance. Informally, a justification is a "reason" for executing (this instance of) the plan; e.g., an atom representing a belief, a goal or an event. In general, a plan instance may have multiple justifications, and an atom instance may be the justification of multiple plan instances.
The substitution θ = {X1/t1, . . . , Xn/tn} specifies the current binding of variables of
A subgoal is created by the execution of a subgoal action !g(u1, . . . , um), and is an
instance of the atom g(u1, . . . , um) which shares variables with the term in the subgoal
action of the plan instance.
The substitution of a plan instance is initiated when the plan instance is created as the result of evaluating the head of object level rule against the atom instances and apply- ing the rule (see the next chapter for more detail). However, it is not necessary that all variables in the plan instance are instantiated by its substitution. If (i) this plan instance creates a subgoal which contains one of the non-instantiated variables and (ii) the subgoal gives rise to another plan instance, the non-instantiated variable can be instantiated (such as by executing a test action in the second plan instance). This instantiation is now kept in the substitution of the second plan instance and can be propagated back to the first plan instance by the meta action set-substitution which will be introduced later.
A plan instance also has a set of execution state flags σ. σ is the subset of a set of flags F which includes at least intended, scheduled, stepped and failed, and may contain additional user-defined flags. For example, some deliberation strategies may require a suspendedexecution flag to specify that the execution of a plan instance is suspended. The intended flag indicates the agent is committed to executing this plan instance. The scheduledflag indicates that the plan instance is selected to be executed at the current cycle. The stepped flag indicates that the plan instance was executed at the last cycle. Finally, the failed flag indicates that the plan instance has failed to execute an action.
Plan instances which have the intended flag are called intentions. An intention p may have a subgoal as the result of executing its subgoal action. Then, if the subgoal is the justification of another intention p′, p′ is called the sub-intention of p. Furthermore, the subgoal must be achieved before continuing executing p. Therefore, we call an intention executable iff it has no subgoal.
Plan state queries
For plan instances, meta-APL includes queries for retrieving their plans, their initial plans, their justifications, their subgoals, their substitutions, and their state flags. There is also a query for retrieving the cycle number at which a plan instance was created. These primi- tive queries are listed below:
• plan(i, π): true if there is a plan instance in the plan state of the agent whose id is i and plan is π;
• init-plan(i, π): true if there is a plan instance in the plan state of the agent whose id is i and initial plan is π;
• justification(i, j): true if there is a plan instance whose id is i and there is a justifi- cation of the plan instance whose id is j;
• substitution(i, θ): true if there is a plan instance whose id is i and substitution is θ; • subgoal(i, j): true if there is a plan instance whose id is i and there is a subgoal of
the plan instance whose id is j;
• state(i, s): true if there is a plan instance whose id is i and one of its flags is s; and • cycle(i, n): true if there is a plan instance created at cycle n whose id is i. Here, we
overload the query cycle(i, n) for atom instances. However, no ambiguity can arise as atom instances and plan instances will not share the same identifier.
Plan state actions:
For plan instances, meta-APL provides meta actions for replacing their plans, extending their substitutions, adding and removing their state flags, and deleting plan instances. These meta actions are listed below:
• set-substitution(i, θ): extends the substitution of a plan instance whose id is i with the provided substitution θ,
• set-state(i, s): adds the state flag s to the set of flags of a plan instance whose id is i,
• unset-state(i, s): removes the state flag s from the set of flags of a plan instance whose id is i,
• delete-plan(i): deletes a plan instance whose id is i. This also leads to the deletion of any subgoal of the plan instance.