An Extended Query Language for Action Languages (and its Application to Aggregates and Preferences) James P. Delgrande School of Computing Science Simon Fraser University Burnaby, B.C. Canada V5A 1S6 jim@cs.sfu.ca Torsten Schaub * Institut f¨ ur Informatik Universit¨ at Potsdam Postfach 90 03 27 D–14439 Potsdam, Germany torsten@cs.uni-potsdam.de Hans Tompits Institut f ¨ ur Informationssysteme 184/3 Technische Universit¨ at Wien Favoritenstraße 9–11 A–1040 Vienna, Austria tompits@kr.tuwien.ac.at Abstract This paper continues our earlier work in representing arbitrary preferences in causal reasoning and planning systems, albeit in an oblique fashion. Previously, we de- fined a very general query language relative to histories; from this we specified a second language in which pref- erences on histories are defined. This in turn allowed us to define the notion of a most preferred history in a set of histories. In this paper, we extend these languages in two directions. First, we add a conditional construct that al- lows one to select between terms. Second, we add a ca- pability for defining macros. With these two added con- structs, one can now define aggregate quantities, such as the total cost of actions in a history, the maximum value of a fluent in a history, or a count of the number of times a fluent goes to zero in a history. Via the preference lan- guage, one can then express a preference for histories (or, plans) with minimum action cost, maximum value of a fluent, or in which a fluent is most often zero. We argue that this substantially increases the range of con- cepts about which one can express preferences. Introduction The traditional formulation of planning involves deter- mining how a given goal can be attained, beginning from some initial state and by means of a given set of actions which alter the state of the world. A plan suc- ceeds just when it is executable and attains the goal; oth- erwise, it fails. However, in realistic situations, things are not quite so simple. Thus, there may be require- ments specifying that a plan should be as short as pos- sible or that total cost, where costs are associated with actions, be minimised. As well, there may be preferred conditions, that are desirable to attain, but not neces- sary. Thus, in getting to the airport, the goal is to in- deed arrive at the airport in good time; I may prefer to be able to pick up a coffee en route, but this preference is subordinate to the overall goal of getting to the air- port. As well, there may be other preferences, such as preferring to take transit to driving, going by a partic- ular route, etc. Each preference partitions the space of * Affiliated with the School of Computing Science at Si- mon Fraser University, Burnaby, Canada. successful plans into those that satisfy the preference and those that do not. The goal of a planning problem now shifts to determining a preferred plan, in which a maximal set of preferences is satisfied, along with the goal. Such preferences also make sense outside of plan- ning domains, and in fact apply to arbitrary sequences of temporal events. Hence, it is perfectly rational to prefer that one’s favourite sport’s team wins the cham- pionship, even though in the typical course of events one has no control over how the team performs. In earlier work (Delgrande, Schaub, & Tompits 2004; 2005), we considered the problem of using general pref- erences over (fluent and action) formulas to determine preferences among temporal histories, or plans. While we focussed on histories as they are used in action de- scription languages (Gelfond & Lifschitz 1998), our ap- proach was, and is, applicable to any planning formal- ism. A history is defined as an interleaved sequence of states (of the world), and actions that take one state in a sequence to the next. We first specified a query language, Q Σ,n , (over some signature Σ and histories of maximum length n) in which one can determine whether an arbitrary expression is true in a given his- tory. Given this language, we defined a preference- specification language, P Σ,n , that allows the definition of preference relations between histories. Via the lan- guage P Σ,n , we showed how to specify general prefer- ences in temporal, causal, or planning frameworks. As well, the approach provided a very general language in which other “higher-level” constructs could be encoded, and in which other approaches could be expressed and so compared. In the present paper, our motivating interest lies with being able to express preferences over aggregate quantities—that is, quantities that in some sense express a collective property of a set of fluent values. If actions come with a measure of their cost and duration, then two corresponding aggregate quantities of these mea- sures would be the total action cost of a plan and the total duration of a plan. Clearly, in many cases these are quantities that one would want to minimise or, in a preference framework, prefer those plans with the min- imal action cost or duration.