• No se han encontrado resultados

A CAN BDI agent is created by the specification of a belief baseB, i.e., a set of formulas from

some logical language, and a plan-library Π, i.e., a set of plan-rules. However, since in practice the belief base is a set of ground atoms, and since we need to map belief bases to states in the planning literature (which are sets of ground atoms), we assume that a CAN belief base is a set of ground atoms. The language of the plan-library is the language of first-order logic with equal- ity, excluding functions and universal quantification (therefore, all free variables are existentially quantified). A plan-rule is of the form e : ψ← P, where e is an event-goal and ψ is the context condition. The component P within a plan-rule is called a plan-body or program, which is built

using the following components: primitive actions (act) that the agent can execute directly; oper- ations to add (+b) and remove (−b) beliefs; tests for conditions (?φ); and event-goal programs or (internal) achievement goals (!e). Complex programs can be specified using sequencing (P1; P2)

and parallelism (P1kP2). The user language of CAN, then, is described by the following grammar:

P ::= act | +b | −b |?φ | !e | P1; P2| P1kP2.

In the original version of CAN in (Winikoff et al., 2002), the user language also includes the declarative goal-program constructGoal(φs, P, φf), which, intuitively, states that (declarative) goal

φsshould be achieved using (procedural) program P, failing if φf becomes true. The operational semantics provided in (Winikoff et al., 2002) for goal-programs captures some of the desired properties of declarative goals, such as persistent, possible, and unachieved. For example, if the program P within goal-programGoal(φs, P, φf) has completed execution, but condition φsis still not true, then P will be re-tried; moreover, if φs becomes true during the execution of P, the goal-program will succeed immediately. However, we do not deal with declarative goals in our work, because we are only interested in adding planning to a typical BDI agent programming language. We refer the reader to (Sardina and Padgham, 2007; Sardina et al., 2006) for details on how declarative goals can be incorporated into CANPlan.

In addition to the user language, there are also auxiliary plan forms which are used by CAN internally, when assigning semantics to constructs. These are the programs nil, P1 ⊲ P2, and Lψ1: P1, . . . , ψn: PnM. Intuitively, nil is the empty program—there is nothing left to execute, program Lψ1: P1, . . . , ψn: PnM is a set of relevant plan-rules for some event-goal, and program

P1⊲ P2means that program P1should be executed first, and that program P2should be executed if

and only if P1fails. The full language of CAN is therefore described by the following grammar:

P ::= nil| act | ?φ | +b | −b | !e | P1; P2 | P1⊲ P2| P1kP2| Lψ1: P1, . . . , ψn : PnM.

Since the language of CAN allows variables in certain programs, we frequently make use of notions associated with variable bindings or substitutions.

Definition 2. (Substitution) A substitution θ is a finite set of the form{x1/t1, . . . , xn/tn}, where

x1, . . . , xn are distinct variables, and each ti is a term such that ti , xi. We say that θ is a

ground substitution if t1, . . . , tn are ground terms. Finally, θ is a variable renaming substitution for some expression E if each variable occuring in E is in{x1, . . . , xn} and t1, . . . , tn are distinct

As usual, θθ′ denotes the composition of substitutions θ and θ′, and given an expression E and a substitution θ ={x1/t1, . . . , xn/tn}, we use Eθ to denote the expression obtained from E by simultaneously replacing each occurrence of xi in E with ti, for all i∈ {1, . . . , n}.

The operational semantics of CAN is given by a set of transition rules in the style of Plotkin’s structural single-step operational semantics (Plotkin, 1981). A transition C −→ C′ denotes that

configuration C yields configuration Cin a single execution step. Similarly, C −→ denotes that

there is some configuration C′ that can be reached by performing a single execution step from

C. The relation −→ denotes the reflexive transitive closure of −→. The transition relation on a

configuration is defined using one or more derivation rules. Derivation rules have an antecedent and a conclusion: the antecedent can either be empty, or it can consist of transitions and auxiliary conditions; the conclusion is a single transition.

∆ =iθ : Piθ | e′: ψi ← Pi∈ Π ∧ θ =mgu(e, e′)}

hB, A, !ei −→ hB, A, L∆Mi Event

ψi : Pi ∈ ∆ B |= ψiθ

hB, A, L∆Mi −→ hB, A, Piθ ⊲L∆ \ {ψi: Pi}Mi Sel

hB, A, acti −→ hB, A, nili actt

B |= φθ

hB, A, ?φi −→ hB, A, nili ? hB, A, +bi −→ hB ∪ {b}, A, nili +b hB, A, −bi −→ hB \ {b}, A, nili −b hB, A, (nil ; P)i −→ hB, A, Pi Seqt

hB, A, P1i −→ hB′, A′, P′i hB, A, (P1; P2)i −→ hB′, A′, (P; P2)i Seq hB, A, P1i −→ hB′, A′, P′i hB, A, (P1⊲ P2)i −→ hB′, A′, (P⊲ P2)i ⊲ hB, A, (nil ⊲ P)i −→ hB, A, nilit P1,nil hB, A, P1i 6−→ hB, A, (P1⊲ P2)i −→ hB, A, P2i ⊲f

hB, A, (nil k P)i −→ hB, A, Pi kt1 hB, A, (P k nil)i −→ hB, A, Pi kt2 hB, A, P1i −→ hB′, A′, P′i

hB, A, (P1 k P2)i −→ hB′, A′, (Pk P2)i k1

hB, A, P2i −→ hB′, A′, P′i

hB, A, (P1 k P2)i −→ hB′, A′, (P1 k P′)i k2

Figure 3.2: CAN’s complete set of rules

The derivation rules of CAN are shown in Figure 3.2. In these rules, a configuration, called a basic configuration, is the tuple hB, A, Pi, where B is a belief base, P is a plan-body, and componentA is a sequence of actions, which is used to keep track of the actions executed so far.

The Event rule collects all the relevant plan-bodies for the corresponding event-goal, along with their associated context conditions, and stores them inL∆M. The Sel rule selects an applicable

plan-body fromL∆M, i.e., one whose corresponding context condition is met in the current belief

base, and schedules the plan-body for execution. The +b rule adds belief atom b to the belief base, and similarly, rule−b removes belief atom b from the belief base. Rules Seq and Seqthandle the execution of two programs in a sequence in the usual way: the former rule takes a single step on the program on the left, and the latter rule replaces program nil with the program on the right. Like the Seq rule, the ⊲ rule takes a single step on the program on the left. The ⊲f rule handles the case where the executing program P1has failed – i.e., where P1cannot make a transition – by selecting

and scheduling the alternative program P2for execution. The ⊲trule handles the case where the program on the left has successfully executed, by replacing the entire program with nil. The actt rule states that the execution of any action trivially succeeds.

Rule ? handles the execution of a test condition ?φ: the test condition succeeds if formula φ holds in the current belief base, and it fails otherwise, that is, it cannot make a transition. Observe from the antecedent of this rule that a substitution θ is applied to φ. There are two things to note regarding substitutions. First, although not shown in our semantics, configurations must include a substitution to keep track of bindings obtained so far for variables during the execution of a plan-body, so that the stored bindings can be applied to variables that occur again in the remaining plan-body. Second, observe that variables may be shared among programs occurring in a larger program, and that programs may fail during execution. For example, in program P1 ⊲ P2, the

same variable, say x, may occur in both P1 and P2, and P1 may eventually fail. Therefore, the

semantics should be able to handle the “removal” of bindings given to variables occurring in failed programs, so that variables may be bound once again by the other programs. For example, if a binding is given to variable x when P1is tried, and P1then fails, P2should be allowed to obtain a

different binding for x. However, for legibility, and because reassigning bindings to variables is not necessary for the semantics of our planning framework, we keep substitutions implicit in places where they need to be carried across multiple rules. We refer the reader to (Hindriks et al., 1999; Sardina and Padgham, 2010) for an account of how substitutions can be carried across derivation rules.

Finally, thek1andk2rules handle the execution of two programs in parallel by nondeterminis-

step on the selected program, and ruleskt1 andkt2 remove the program nil from parallel programs.