• No results found

4.2 Semantics of queries and meta actions

4.3.3 The Exec phase

After the Apply phase, the phase counter is k + 1 and the agent is in the Exec phase. This phase consists of two stages. In the first stage, ρ = k + 1, the state flag stepped is removed from plan instances which were executed at the previous cycle. This guarantees that only plan instances which are executed at the current cycle will have the state flag stepped in the next cycle.

Then, the transition rule for removing the state flag stepped is defined by using the auxiliary function (4.2) as follows:

Π′= {del-flag(p, stepped) ∣ p ∈ Π}

⟨A, Π, k + 1, n⟩ Ð→ ⟨A, Π′, k+ 2, n⟩ (DEL-STEPPED)

In this transition rule, the phase counter is also advanced to k + 2.

In the second stage of the Exec phase, ρ = k + 2, the agent executes intentions which are scheduled in this deliberation cycle. Recall that an intention is scheduled to execute by setting the state flag scheduled. Furthermore, only executable intentions, which have no subgoal, are allowed to execute. This means no intention with a subgoal is executed even if it has the state flag scheduled. If an intention with the flag scheduled is not executed due to having a subgoal, the flag scheduled remains with the intention to the next cycles. When its subgoal is achieved, the intention will be executed.

In the following, we list the transition rules in this stage according to types of actions to be executed.

Executing an external action

External actions are performed in the agent’s environment. Changes to the state of the environment by external actions can only be received by the agent through perceptions

at the Sense phase at the beginning of the next deliberation cycle. Here, we assume that each external action can signal whether the action succeeded or failed. In case of success, the execution of an external action is defined by the following transition rule:

∃p ∈ Π ∶ scheduled ∈ flags(p) ∧ plan(p) = ea; π ea(subs(p)) is performed successfully

Π′= Π ∖ {p} ∪ {update-executing(p, π)}

⟨A, Π, k + 2, n⟩ Ð→ ⟨A, Π′, k+ 2, n⟩ (EXEC-EA)

In EXEC-EA, we use the the auxiliary function update-executing to describe the change of the plan instance p after executed. In particular, the executed external action is removed by replacing that plan of p with the remainder π. Then, update-executing deletes the flag scheduledfrom p (hence, p is not executed again in this phase), and sets the flag stepped for p to indicate that the intention is executed in the current deliberation cycle. In case of failure, the execution of an external action is defined by the following transition rule:

∃p ∈ Π ∶ scheduled ∈ flags(p) ∧ plan(p) = ea; π ea(subs(p)) fails

Π′= Π ∖ {p} ∪ {update-failing(p, π)}

⟨A, Π, k + 2, n⟩ Ð→ ⟨A, Π′, k+ 2, n⟩ (FAIL-EA)

Here, we use the auxiliary function update-failing to replace the flag scheduled by the flag failed.

Executing a test action

Mental state tests are evaluated against the current configuration. If the result is true, the resulting substitution is applied to the rest of the plan of the intention. The transition rule for this case is defined as follows:

∃p ∈ Π ∶ scheduled ∈ flags(p) ∧ plan(p) =?b; π ⟨A, Π, k + 2, n⟩ ⊢ b(subs(p)) ∣ θ

Π′= Π ∖ {p} ∪ {set-subs(update-executing(p, π), θ)}

If the result of a mental state test is false with respect to the current configuration, the execution of the test action fails. This failure is recorded by replacing the flag scheduled with the flag failed. The transition rule for this case is as follows:

∃p ∈ Π ∶ scheduled ∈ flags(p) ∧ plan(p) =?b; π ⟨A, Π, k + 2, n⟩ ⊢ not b(subs(p)) ∣ ∅

Π′= Π ∖ {p} ∪ {update-failing(p, ?b; π)}

⟨A, Π, k + 2, n⟩ Ð→ ⟨A, Π′, k+ 2, n⟩ (EXEC-TEST-2)

In EXEC-TEST-2, we use the auxiliary function update-failing to specify the replacement of the flag scheduled with the flag failed. When a plan instance has the state flag failed, agent programmers are responsible to write meta rules to handle it since meta-APL does not implement any mechanism to deal with failed plan instances.

Executing mental state actions

Mental state actions are performed to update the mental state of the current configuration. They can be either primitive mental state actions (add-atom and delete-atom) or user- defined ones. The effect of executing mental state actions is the same as they are executed when applying a meta rule. The transition rule for executing them is defined as follows:

∃p ∈ Π ∶ scheduled ∈ flags(p) ∧ plan(p) = ma; π Π′= Π ∖ {p} ∪ {update-executing(p, π)}

⟨A, Π′, k+ 2, n⟩ÐÐÐÐÐÐÐ→ ⟨Ama(subs(p)) ′, Π′′, k+ 2, n⟩

⟨A, Π, k + 2, n⟩ Ð→ ⟨A′, Π′′, k+ 2, n⟩ (EXEC-META)

Similar to the execution of external actions, the auxiliary function update-executing is also used in EXEC-META to update the plan instance p where the plan of p is replaced with the remainder π and the state flag scheduled is replaced with stepped.

Executing a sub-goal action

The execution of a subgoal action in an intention results in the creation of a new atom instance of the goal atom. The transition rule for executing a subgoal action is defined as

follows:

∃p ∈ Π ∶ scheduled ∈ flags(p) ∧ plan(p) =!g; π inew∈ ID ∖ (IDA∪ IDΠ)

A′= A ∪ {(inew, g(subs(p)), id(p), n)}

Π′= Π ∖ {p} ∪ {update-executing(p, π)}

⟨A, Π, k + 2, n⟩ Ð→ ⟨A′, Π, k+ 2, n⟩ (EXEC-GOAL)

In EXEC-GOAL, the new atom instance (inew, g,id(p), n) of the goal atom g is related to

the intention by storing the id of p in the parental component of the atom instance. This creates a subgoal relation between the plan instance p with the new atom instance.

Finishing the Exec phase

When no more intentions from the plan state can be executed, i.e., no executable intention with the state flag scheduled, the phase counter is reverted to 0 and the cycle counter is advanced to n + 1:

∀p ∈ Π ∶ scheduled ∈ flags(p) Ô⇒ ∃α ∈ A ∶ par(α) = id(p)

⟨A, Π, k + 2, n⟩ Ð→ ⟨A, Π, 0, n + 1⟩ (NEW-CYCLE)

In NEW-CYCLE, the condition specifies that the rule is applicable if all intentions which have been scheduled to be executed (i.e., with the flag scheduled) have been executed (i.e., their flag scheduled is replaced by the flag stepped) except those which have subgoals. In other words, we do not execute plan instances which have subgoals even if they are scheduled to be executed. When NEW-CYCLE is applied, the resulting configuration is the beginning one of the next deliberation cycle as its phase counter is 0 and its cycle counter is n + 1.