• No results found

4.1 Readylog Semantics

4.1.3 Trans and Final

In the following we define the semantics for the core language. We make use of the weighted transition semantics introduced by (Grosskreutz 2002). We omit the somewhat lengthy second order definition of the transition semantics with procedures and refer to (Grosskreutz 2002) for details. Other resources for the definition of procedures in the transition semantics context are (De Giacomo et al. 1997; De Giacomo et al. 2000)

Instead of using macro expansion as GOLOGdoes, we use a transition semantics introduced by (De Giacomo et al. 2000). It defines program execution by a one step transition between

4.1. READYLOG SEMANTICS 67

program configurations. A configuration is a tuplehγ, si, where γ is a program and s a situation. The special predicate trans(γ, s, δ, s′) transforms program γ in the situation s into the program

δ resulting in the situation s′. To denote final configurations, i.e. such configuration where the

computation of a statement is finished, a predicate Final(γ, s) exists. Originally, (De Giacomo et al. 2000) defined trans as a predicate. Grosskreutz (Grosskreutz 2002) extended program transitions to return the probability of a step in program execution to account for probabilistic program execution. He defined a weighted transition semantics forPGOLOGconstructs. Thus, trans : program × situation × program × situation → [0, 1] is a function which maps pairs of configurations to probabilities. READYLOGintegratesPGOLOGand the possibility to weight programs with probabilities. Therefore, the semantics of the READYLOGconstructs make also use of the weighted transition semantics proposed in (Grosskreutz 2002). For readability, we write

f (~y) = if (∃~y).ϕ(~x, ~y) then g(~x, ~y) else h(~x) as an abbreviation for

f (~x) = p ≡ (∃~y).ϕ(~x, ~y) ∧ p = g(~x, ~y) ∨ ¬(∃~y).ϕ(~x, ~y) ∧ p = h(~x)

whereϕ(~x, ~y) is a first-order formula with free variables among ~x ∪ ~y, and similarly g(~x, ~y) and h(~x) are functions whose arguments range over ~x ∪ ~y and ~x, resp. Similarly,

f (~x) = if (∃ ~y1).ϕ1(~x, ~y1) then g1(~x, ~y1) elseif (∃ ~y2).ϕ2(~x, ~y2) then g2(~x, ~y2) else h(~x)

is an abbreviation for

f (~x) = p ≡ (∃ ~y1).ϕ1(~x, ~y1) ∧ p = g1(~x, ~y1) ∨ (∃ ~y2).ϕ2(~x ~y2) ∧ p = g2(~x ~y2)∨

¬((∃ ~y1.ϕ1(~x, ~y1) ∨ (∃ ~y2).ϕ2(~x, ~y2)) ∧ p = h(~x)

Figure 4.1 gives an overview of the READYLOGconstructs which we will present in the fol- lowing.

Empty Program

trans(nil , s, δ, s′) = 0

Final(nil , s) ≡ true

The empty program contributes a probability of 0 to the current total probability of the program branch. Intuitively this means that no further transition is possible. At the same time the empty program reaches a final configuration.

Primitive Action

trans(α, s, δ, s′) = if Poss(α[s], s) ∧ δ = nil ∧ s′= do(α[s], s) then 1 else 0 Final(α, s) ≡ false

If the program consists of a primitive actionα, it is checked whether the action is possible w.r.t. the background action theory denoted by Poss(α[s], s). If this holds, the program is transformed to the successor configurationhnil, do(α[s], s)i. The probability for this transition is obviously 1. If the primitive actionα is not possible this transition gets the value 0 which is equivalent to false.

nil empty program

α primitive action

ϕ? wait/test action

waitF or(τ ) event-interrupt

[σ1; σ2] sequence

ifϕ then σ1elseσ2endif conditional

whileϕ do σ endwhile loop

withCtrlϕ do σ endwithCtrl guarded execution

σ1|| σ2 prioritized execution

forever doσ endforever infinite loop

whenever(τ, σ) interrupt triggered by continuous function withPol(σ1, σ2) prioritized execution untilσ2ends

prob(p, σ1, σ2) probabilistic execution of eitherσ1orσ2

interrupt interrupts

pproj(c, σ) probabilistic (off-line) projection

{proc P1(~ϑ1)σ1endproc; · · · ; proc Pn(~ϑn)σnendproc}; σ0 procedures

solve(σ, h) initiate decision-theoretic optimization overσ

σ1| σ2 nondeterministic (dt) choice of programs

pickBest(~x, σ, h) nondeterministic (dt) choice of arguments Figure 4.1: Overview of Readylog constructs

Test Action

trans(ϕ?, s, δ, s′) = if ϕ[s] ∧ δ = nil ∧ s′= s then 1 else 0 Final(ϕ?, s) ≡ false

Similar as for primitive actions, the remaining program isδ = nil . Note that unlike primitive actions the successor situation remains the same as a test does not change the environment. The transition returns the value 1 or 0, resp., depending on whether the test conditionϕ[s] holds. A test action does not reach a final configuration.

Event-Interrupt

To achieve event-driven behavior a notion of time must be integrated into the language. This was introduced by Grosskreutz (2002, Chpt. 4) and discussed in Chapter 3.3.4. To represent the value of continuous fluents so-calledt-f unction have been introduced which represents functions of time. These are needed to project the value of continuous fluents w.r.t. the time that has passed. The argumentτ of a waitF or(τ ) statement is restricted to t-f orms. The idea behind waitF or(τ ) is that actions should happen as soon as possible. Thus, the notion of a least time pointltp(τ, s, t) is needed. It is an abbreviation for the formula

τ [s, t] ∧ t ≥ start(s) ∧ ∀t′.start(s) ≤ t< t ⊃ ¬[s, t]

which means thatt in ltp(τ, s, t) is the least point in time after the start of s where τ becomes true. To evaluate at-form in a situation s at a time t we write τ [s, t] which results in a formula which

4.1. READYLOG SEMANTICS 69

is likeτ except that every continuous fluent F is replaced by val(F (s), t), which stands for the t-function assigned to fluent F . trans and F inal is then defined as

trans(waitF or(τ ), s, δ, s′) = p ≡

p = 1 ∧ (online[s] ∧ τ[s, t] ∧ s′= s ∧ δ = nil ∨

¬online[s] ∧ ltp(τ, s, t) ∧ s′= do(setT ime(t), s) ∧ δ = nil)

F inal(waitF or(τ ), s) ≡ false

This definition means that in the on-line case1thet-form is evaluated. No further transition is

taken. Ifτ [s, t] does not hold, the interpreter will wait forever. In the off-line case (projection) the least time point is calculated and the time is advanced accordingly.

Sequence

trans(σ1; σ2, s, δ, s′) =

if(∃γ).δ = γ; σ1∧ trans(σ1, s, γ, s′) > 0 then trans(σ1, s, γ, s′)

elseifFinal(σ1, s) ∧ trans(σ2, s, δ, s′) > 0 then trans(σ2, s, δ, s) else 0

Final(σ1; σ2, s) ≡ Final(σ1, s) ∧ Final(σ2, s)

Sequences of actions are transformed in the following way: either there is a successor configura- tion forσ1(with positive weight) orσ1has already become final. In the latter case the programσ2

must be further transformed. A sequence of programs is regarded as final if both programs reach a final configuration.

Conditional

trans(if ϕ then σ1elseσ2endif, s, δ, s′) =

ifϕ[s] then trans(σ1, s, δ, s′) else trans(σ2, s, δ, s′)

Final(if ϕ then σ1elseσ2endif, s) ≡

ϕ[s] ∧ Final(σ1, s) ∨ ¬ϕ[s] ∧ Final(σ2, s)

Depending on the conditionϕ the remaining program σ1orσ2, resp., is executed. The function

value (probability) of this transition depends on the return value of eitherσ1orσ2. A conditional

is final when the respective branch to be executed reaches a final configuration.

Loop

trans(while ϕ do σ endwhile, s, δ, s′) =

if(∃γ).ϕ[s] ∧ δ = γ; while ϕ do σ endwhile then trans(σ, s, γ, s′) else 0

Final(while ϕ do σ endwhile, s) ≡ ¬ϕ[s] ∨ Final(σ, s)

A loop is transformed by first testing the loop conditionϕ. If there is a configuration γ which results from the successor configuration of the loop bodyσ, the remaining program to be further transformed is the successor programγ with the loop attached. This ensures that the loop is being executed as long as the conditionϕ holds. A loop reaches a final configuration if the condition does not hold or the loop body reaches a final configuration.

Guarded Execution

trans(withCtrl ϕ do σ endwithCtrl, s, δ, s′) =

if(∃γ).ϕ[s] ∧ δ = withCtrl ϕ do γ endwithCtrl thentrans(σ, s, γ, s′) else 0

Final(withCtrl ϕ do σ endwithCtrl, s) ≡ ϕ[s] ∧ Final(σ, s)

The idea behind guarded execution is to execute programσ, the body of the guard, as long as the guard conditionϕ holds. It is final when the body reaches a final condition and at the same time the condition holds.

Prioritized Execution

trans(σ1|| σ2, s, δ, s′) =

if¬Final(σ1, s) ∧ ¬Final(σ2, s) ∧ ∃γ1.trans(σ1, s, γ1, s′) > 0 ∧ δ = γ1|| σ2∧

(∀γ2, s2).trans(σ2, s, γ2, s2) > 0 ⊃ start(s′) ≤ start(s2)

thentrans(σ1, s, γ1, s′)

elseif¬Final(σ1, s) ∧ ¬Final(σ2, s) ∧ (∃γ2).trans(σ2, s, γ2, s′) > 0 ∧ δ = σ1|| γ2) ∧

(∀γ1, s1).trans(σ1, s, γ1, s1) > 0 ⊃ start(s′) < start(s)

thentrans(σ2, s, γ2, s′) else 0

Final(σ1|| σ2, s) ≡ Final(σ1, s) ∨ Final(σ2, s)

The idea of prioritized execution is that programσ1is executed with priority over programσ2if

σ1can be executed beforeσ2(w.r.t. execution time). In the above definition the special fluent

start encodes when a program started to be executed. When bothσ1andσ2are not in a final

configuration andσ1can be transformed into programγ1and the execution ofσ1can be started

before any of the possible successor configurations ofσ2, the remaining program isγ1|| σ2, i.e.

the first step ofσ1is prioritized overσ2. Otherwise,σ2will be started first. A final configuration

is reached when eitherσ1orσ2becomes final.

Infinite Loop

forever doσ endforeverdef= while true do σ endwhile forever is a useful abbreviation for an infinite loop.

4.1. READYLOG SEMANTICS 71

Interrupt Triggered by Continuous Function

whenever(τ, σ)def= forever([waitF or(τ, σ)])

The whenever statement is an abbreviation for a guarded infinite loop.

Prioritized Execution untilσ2ends

withPol(σ1, σ2) def

= (σ1; false?) || σ2

σ1takes priority overσ2. The test false? averts that σ1becomes final. This means that the whole

construct can only become final ifσ1was executed up to the end andσ2became final.

Probabilistic Execution

trans(prob(p, σ1, σ2), s, δ, s′) =

ifδ = σ1∧ s′= do(tossHead , s) then p

elseifδ = δ2∧ s′= do(tossTail , s) then 1 − p else 0

Final(prob(p, σ1, σ2), s) ≡ false

The prob constructs assigns a success probabilityp to the program σ1(and1 − p to σ2). To

distinguish the two possible successor transitions the dummy actions tossHead and tossTail have been introduced. The statement prob is only for off-line projections. Obviously, it is never final.

Probabilistic Projections

With introducing theprob statement it is possible to project over probabilistic programs. The idea is to find out what the probability is that a formulaϕ holds after execution of program σ. Therefore, a projection is started which ranges over all possible probabilistic traces. The overall probability is weighted over all possible traces. To access the valueP Bel of the belief of the agent aboutϕ when simulating σ, the fluent pproj is introduced:

P Bel(ϕ, σ, s) = p ≡ P

{s′,s∗|ϕ[s∗]}p(s′, s) · doP r(withP ol(llmodel, σ), s′, s∗)

P

s′p(s′, s)

= p.

In the above formulap is a binary functional fluent with the meaning that “in situation s the agent thinks thats′is possible with degree of likelihoodp(s, s)”. This was introduced in the epistemic

situation calculus (cf. (Reiter 2001)). doP r was introduced in Chapter 3.3.4 on page 56 and ’returns’ the probability of a projection; in this case of the low-level modelllmodelwith program

G S Room 1 Room 6 (2,2) (7,5)

Figure 4.2: Maze66 from (Hauskrecht et al. 1998).

Procedures

As stated in the introduction of this section, we leave out the formal definition of procedures here. It demands a second-order definition of trans. The semantic of procedures is like those in common programming languages.

This concludes our definition of the language READYLOGw.r.t. all non-decision-theoretic extensions. These are given in the next section. Examples of applications of READYLOGare de- scribed in Chapters 5 and 6. Next, we concentrate on the decision-theoretic extensions of READY- LOG.