• No results found

The static part of the translation

6.2 Translation

6.2.2 The static part of the translation

Defining additional queries

The set Q contains additional queries which will be used to construct meta rules and object-level rules in the translation. In particular, we define queries: “relevant-event” which checks if an atom is relevant; “selected-event” which retrieves the selected event of the current deliberation cycle; “trigger-event” which checks if an event is relevant; “plan-at” and “intention-at” which check if a plan instance or an intention is created at a cycle, respectively; and “executable-intention” which checks if an intention has no sub- goal. These queries are defined below:

relevant-event(E) ← atom(_, relevantEvent(E)) (6.1)

selected-event(I) ← cycle(N ), atom(_, selectedEvent(I, N )) (6.2) trigger-event(I) ← atom(I, E), relevant-event(E), not justification(_, I) (6.3)

plan-at(I, N ) ← plan(I, _), cycle(I, N ) (6.4)

intention-at(I, N ) ← plan-at(I, N ), state(I, intended) (6.5)

executable-intention(I) ← state(I, intended), not subgoal(I, _) (6.6) The query relevant-event is defined by the query (6.1) where an atom E is relevant if there is an an instance of the atom relevantEvent(E). Recall that in Jason an event is relevant if it can be unified with the triggering event of a plan in the plan base. Therefore, in the translation, we transform triggering events of plans in the plan base into instances of atoms relevantEvent(E). This transformation is defined by a translation function call trreldefined in Section 6.2.3.

The query selected-event is defined by clause (6.2) where we first get the number N of the current deliberation cycle by the query cycle(N ) and then check if there is an instance

of the atom selectedEvent(I, N ). The existence of such an instance means that an event with id I is selected in cycle N . This will be encoded by the meta rule (6.12) in R1.

The query trigger-event is defined by clause (6.3) where we use the query relevant-event to check if an event is relevant and the query justification to check that the event has not been used to generate an intention.

The queries plan-at and intention-at are defined by clauses (6.4) and (6.5) where we query the cycle at which a plan instance or an intention is created. They are used to form meta rule (6.13) in R3.

The query executable-intention is defined by clause (6.6) where we use the query state to check if a plan instance is an intention, i.e., it has the flag intended, and the query subgoal to check if this plan instance has no subgoal.

Defining additional meta-actions

We define in the translation two additional meta actions which simulate actions of adding and deleting belief of Jason, i.e., actions of the form +b and −a. Therefore, the transitions (AddBel) and (DelBel) in Jason will be simulated by the transition (EXEC-META) of these two additional meta actions, respectively. These meta actions take the side effects of +b and −a into account where events of belief addition and belief deletion are generated into the event base. They are defined in M as follows:

add-belief(B) = add-atom(I, belief(B)), add-atom(J, +belief(B)) (6.7) del-belief(A) = delete-atom(I, belief(A)), add-atom(J, −belief(A)) (6.8) In macro (6.7), the meta action add-belief(B) add an instance of the atom belief (B) into the atom base in order to simulate that a belief of B is added into the belief base of the Jason agent. Besides, an instance of the event +belief (B) describing the event of adding a belief is also added.

Similarly, in macro (6.8), the meta action del-belief(A) removes instances of atoms belief(A). Also, an instance of the event −belief(B) describing the event of removing

beliefs is also added.

Note that both additional atoms +belief (B) and −belief (A) are added to simulate the belief addition and deletion events in Jason. The role of these events will be finished when they are selected (and deleted) in the operational semantics of Jason (see rule (SelEv-1)). In our translation, the role of these atoms +belief (B) and −belief (A) are finished when they are selected (see rule (6.12)).

Defining meta rules for R1

R1 contains meta rules which are responsible for removing non-intended plan instances

from the previous cycle, clearing completed intentions, and selecting a relevant event for generating a plan instance in this deliberation cycle. These meta rules are defined below:

plan(I, _), not state(I, intended) → delete-plan(I) (6.9)

executable-intention(I), plan(I, ǫ), justification(I, J), not subgoal(_, J)

→ delete-atom(J) (6.10)

executable-intention(I), plan(I, ǫ), justification(I, J), subgoal(K, J),

substitution(I, S) → set-substitution(K, S), delete-atom(J) (6.11) cycle(N ), not selected-event(_), trigger-event(I)

→ add-atom(selectedEvent(I, N)) (6.12)

The meta rule (6.9) is for deleting unintended plan instances. First, it queries plan instances which do not have the flag intended by the query “plan” and “state”. Then, it deletes these plan instances.

The two next meta rules simulate the transition rules (ClrInt-1) and (ClrInt-2) for clear- ing completed intentions, respectively. First, they query completed intentions, i.e., exe- cutable intentions whose plans are empty. Recall that an intention is executable if it does not have any subgoal. If a completed intention with id I is for reacting to an external event, i.e., not a subgoal of another intention, the meta rule (6.10) clears the completed

intention with id I by removing the instance of this external event. In other words, this is a translation for the transition rules (ClrInt-1) where an intention is deleted from the intention base. Otherwise, if a completed intention with id I is for reacting to an an in- ternal event, i.e., a subgoal of another intention with id K, the meta rule (6.11) clears the completed intention by first extending the substitution of the intention with id K with that of the intention with id I and removing the instance of the internal event. This is a translation for the transition rule (ClrInt-2) where the top plan is removed from the in- tention and the substitution (obtained by unifying the triggering event of the top plan and the achievement goal in the next plan in the intention) is applied to this next plan. Here, some variables in the triggering event of the top plan may be instantiated as the result of executing the top plan (such as by some test goals); these instantiations are then propagated into the next plan by applying the substitution to the next plan.

Finally, the meta rule (6.12) is for selecting a relevant event, i.e., it simulates the transi- tion (SelEv-1) in Jason. Here, we assume that the Jason function SE selects events nonde-

terministically, and that (6.12) relies on this assumption. It first queries the number N of the current cycle, makes sure that no relevant event has been selected by using the query “selected-event” defined by (6.2) and queries for a relevant event with id I. The selection is done in (6.12) by adding an instance of the atom selectedEvent(I, N ). Other selection functions SEcan be encoded by modifying (6.12).

Defining meta rules for R3

R3 contains meta rules which select one plan instance to become an intention, select one

intention to execute in this deliberation cycle, and revise a test action to a corresponding subgoal action if it is scheduled to be executed. These meta rules are as follows:

cycle(N ), plan-at(I, N ), not intention-at(_, N )

→ set-state(I, intended) (6.13)

not state(_, scheduled), executable-intention(I), not state(I, failed)

→ set-state(I, scheduled) (6.14)

state(I, scheduled), plan(I, ?q; P ), not q → set-plan(I, !(+test(q)); P ) (6.15) The meta rule (6.13) sets a new intention by first querying a plan instance with id I which is generated in the current cycle via the query “plan-at”. Therefore, it simulates the effect of the sequence of two transitions (SelAppl) and either (IntEv) or (ExtEv), depending on whether the selected event is a subgoal or not. This meta rule also makes sure that no intention has been generated in the current cycle using the query “intention-at”. Then, this meta rule sets the flag intended of the plan instance with id I.

The meta rule (6.14) selects an intention for execution by looking for an executable intention with id I, i.e., having no subgoal. Then, this meta rule sets the flag scheduled of the plan instance with id I. This is equivalent to the transition (SelInt-1) in Jason.

The meta rule (6.15) revises a test action of an intention which is selected to be executed into a subgoal action when the test action fails. This implements the way where Jason deals with failed tests (defined in the transition rule (TestGl-2)) where a failed test goal gives rise to an event of the form +?q. In our translation, such an event is translated into +test(q).