Heuristics for planning with penalties and rewards formulated in logic and computed through circuits The automatic derivation of heuristic functions for guiding the search for plans is a fundamental technique in planning. The type of heuristics that have been considered so far, however, deal only with simple planning models where costs are associated with actions but not with states. In this work we address this limitation by formulating a more expressive planning model and a corresponding heuristic where preferences in the form of penalties and rewards are associated with fluents as well. The heuristic, that is a generalization of the well-known delete-relaxation heuristic, is admissible, informative, but intractable. Exploiting a correspondence between heuristics and preferred models, and a property of formulas compiled in d-DNNF, we show however that if a suitable relaxation of the domain, expressed as the strong completion of a logic program with no time indices or horizon is compiled into d-DNNF, the heuristic can be computed for any search state in time that is linear in the size of the compiled representation. This representation defines an evaluation network or circuit that maps states into heuristic values in linear-time. While this circuit may have exponential size in the worst case, as for OBDDs, this is not necessarily so. We report empirical results, discuss the application of the framework in settings where there are no goals but just preferences, and illustrate the versatility of the account by developing a new heuristic that overcomes limitations of delete-based relaxations through the use of valid but implicit plan constraints. In particular, for the Traveling Salesman Problem, the new heuristic captures the exact cost while the delete-relaxation heuristic, which is also exponential in the worst case, captures only the Minimum Spanning Tree lower bound. The automatic derivation of heuristic functions from problem descriptions in Strips and other action languages has been one of the key developments in recent planning research [14, 51] . Provided with these heuristics, the search for plans becomes more focused, and if the heuristics are admissible (do not overestimate), the optimality of plans can be ensured [55] . The type of heuristics that have been considered so far, however, have serious limitations. Basically they are either non-admissible [12, 40] or not sufficiently informative [39] , and in either case they are restricted to cost functions where plan costs depend on actions but not on states. As a result, the tradeoffs that can be expressed are limited; in particular, it is not possible to state a preference for achieving or avoiding an atom p in the way to the goal, or take this preference into account when searching for plans.. In this work, we address these limitations by formulating the derivation of heuristic functions in a logical framework. We have shown elsewhere that the heuristic represented by the planning graph [11] can be understood as a precise form of deductive inference over the stratified theory that encodes the problem [31] . Here our goal is not to reconstruct an existing heuristic but to use a logical formulation for producing a new one. The advantages of a logical framework are two: the derivation of heuristic information is an inference problem that can be made transparent with the tools of logic, and powerful algorithms have been developed that make certain types of logical inferences particularly effective. The latter includes algorithms for checking satisfiability [52] , computing answer sets [61] , and compiling CNF formulas into tractable representations [25] .. Here we consider preferences over actions a and fluents p that are expressed in terms of real costs c(a) and c(p). Action costs are assumed to be non-negative, while fluent costs can be positive or negative. Negative costs express rewards. The cost of a plan is assumed to be given by the sum of the action costs plus the sum of the atom costs for the atoms made true by the plan. We are interested in computing a plan with minimum cost. This is a well defined task, which as we will see, remains well-defined even when there are no goals but just preferences. In such a case, the best plans simply try to collect rewards while avoiding penalties, and if there are no rewards, since action costs are non-negative, the best plan is empty.. The cost model is not fully general but is considerably more expressive than the one underlying classical planning. As we will see, the model generalizes recent formulations that deal with over-subscription or soft goals [60, 64] , which in our setting can be modeled as terminal rewards, rewards that are collected when the propositions hold at the end of the plan. On the other hand, the costs and rewards are combined additively, so unlike other recent frameworks [8] , partially-ordered preferences are not handled.. The definition of the planning model is motivated by the desire to have additional expressive power and a principled and feasible computational approach for dealing with it. For this, we want a useful heuristic, with a clear semantics, capable of capturing interesting cost tradeoffs, and a feasible algorithm for computing it. We will be able to express in the model, for example, navigation problems where coins of different values are to be collected by avoiding as much as possible certain cells, or blocks-world problems where a tallest tower is to be constructed, or where the number of blocks that touch the table is to be minimized. In order to test the effectiveness of the approach we will also consider classical planning tasks where we will assess the approach empirically in relation to existing heuristics and planners.. The heuristic h + c that we develop is simple and corresponds to the optimal cost of the relaxed problem where the delete-lists of all actions are ignored [12] . Since searching with this heuristic, even in the classical setting, involves an intractable computation in every state s visited [15] , planners such as HSP and FF resort to polynomial but non-admissible approximations [12, 40] . In this work, while considering the more general cost structure, we take a different approach: we compute the heuristic h + c for each search state, but pay the price of an intractable computation only once, as preprocessing. This preprocessing yields what can be deemed as an evaluation network or circuit where we can plug any search state and obtain its heuristic value in linear time. Of course, the time to construct this evaluation network and the size of the network may both be exponential, yet this is not necessarily so. The evaluation network, indeed, is nothing else but the directed acyclic graph that results from compiling a relaxation of the planning theory into d-DNNF, a form akin to OBDDs introduced in [21, 22] that renders efficient a number of otherwise intractable queries and transformations [25] . The heuristic values are then obtained as the cost of the 'best' models, which can be computed in linear time once the relaxed theory is compiled into d-DNNF [26] .. The framework defined by the formulation of the heuristic h + c in terms of logic and their computation in terms of compiled d-DNNF representations is then evaluated empirically over a broad set of problems, where the heuristic is used to guide the search for optimal plans.. An important characteristic of the logical encoding of the delete-relaxation heuristic is that unlike the standard logical encodings of planning problem [44] , no explicit temporal stratification in the form of time indices or horizons is needed. This follows from the use of positive logic programs for expressing the effects of the actions as an intermediate representation, and the focus on the models that are minimal in the sense that true fluents must have a well-founded justification. Such minimal models capture an implicit stratification that is in correspondence with the explicit temporal stratification adopted by the standard logical approaches to planning. A concrete result of this implicit stratification is that the resulting heuristic estimates the true optimal cost of the problem, and not the optimal cost given a specific temporal horizon.. The paper is a revised version of [13] where the results are extended to a new class of heuristics that complement the use of the delete-relaxation with valid plan constraints. 1 Valid plan constraints are formulas defined over the set of action and fluent symbols that are satisfied by some optimal plan. Making valid plan constraints explicit in a problem hence does not affect the true cost of a problem but can boost the value of the heuristic while keeping it admissible. We show for example the new heuristic is optimal for problems like the Traveling Salesman Problem (TSP), where the delete-relaxation heuristic h + c , which is also exponential in the worst case (unless P = NP), yields only the Minimum Spanning Tree (MST) lower bound (for references on the TSP and MST; see [18, 48, 56] ).. The plan for the paper is the following: we present in order the cost model, the heuristic h + c , the correspondence between h + c and the rank of a suitable propositional theory, and the computation of the heuristic for any state in terms of a suitable d-DNNF compilation of the theory. We then deal with the search algorithm, that must handle negative costs, present the experimental results, and consider the more powerful heuristic that arises when plan constraints are taken into account. We then summarize the main contributions, and discuss related work and open problems. We have combined ideas from a number of areas, including search, planning, knowledge compilation, and answer set programming to develop 1. a cost model for planning that accommodates fluent penalties and rewards, 2. a generalization of the admissible delete-relaxation heuristic h + c for informing the search in the model, 3. an account of the heuristic in terms of the rank of the best models of a suitable propositional theory obtained from the strong completion of a logic program that does not require time indices or horizons, 4. an approach that exploits this formulation along with the properties of d-DNNF formula for computing all heuristic values h + c needed in the search in time linear in the size of the compilation, 5. a best-first algorithm able to use this heuristic, capable of handling negative heuristics and costs while ensuring optimality, and 6. an extension of the framework based on the use of valid plan constraints for boosting the values of the heuristic, overcoming some of the limitations of the delete-based relaxation.. We have also analyzed some of the properties of the resulting heuristics such as admissibility and monotonicity, as well as some of the semantic differences between the heuristic h + c (P ) and constrained heuristic h + c (P , C ), showing for example that the latter produces optimal costs in problems such as the Traveling Salesman Problem where the former yields only the Minimum Spanning Tree lower bound, even if both heuristics are exponential in the worst case. We have also implemented these ideas in a planner that we tested on a number of problems, producing non-trivial results, including the best results we are aware of in some domains. The computational bottleneck in this approach is the compilation of the CNF translation of the logic program into a d-DNNF formula. In [58] and [57] , we report preliminary results of an additional relaxation method that maps the CNF formula into a weaker formula of bounded treewidth that can be compiled efficiently.. The results above do not have to be taken as a single package, and in particular it is possible to replace the compilation step by an explicit computation of the best models for each of the states that arise in the search, using a Weighted SAT or ASP solver. The appeal of the compilation-based approach, however, is that it yields what can be deemed as a circuit or evaluation network whose input is a situation and whose output, produced in linear-time, is an appraisal of the situation in the form of its heuristic value. Some authors have associated evaluations of this type with the role played by emotions in real agents [20, 28] .. to parallelize the plan π into sets of actions A 0 , . . . , A n , defining F 0 as the set of fluents p true in s and F i+1 as the set of fluents that become true after an action in A i is applied.. Since for each plan π of the problem P [I = s, G = g] we can find a model of the theory wffc(L(P )) ∪ I(s) ∪ g with the same cost, and vice versa, the cost of the problem is equal to the cost of the theory. 2. Proof of Theorem 7. Direct from Theorem 3 and Proposition 6. 2. Proof of Proposition 8. Let n = s, t and n = s , t be two nodes such that n is the successor of n upon the application of action a. Let t be the set t − t of fluents. Then, monotonicity means Proof of Proposition 9. We need to show that A* with a monotone heuristic and the revised termination condition produces optimal plans even in the presence of negative costs. Monotonicity implies that the evaluation function f (n) = g(n) + h(n) does not decrease along any search path n 1 , n 2 , n 3 , . . .; i.e., f (n 1 ) f (n 2 ) f (n 2 ) · · ·, and hence, that no node is expanded twice. (Otherwise, if n i is expanded along a path with evaluation function f (n i ) = C , when there is second path n 0 , n 1 , . . . ,n i with strictly less cost to n i that has not been fully expanded yet, there must be some node n k along this path in OPEN with f (n k ) < C due to monotonicity, that should have been expanded instead.) Then, since the number of nodes is finite, the revised A* algorithm must eventually terminate with a solution (if the problem has a solution). From the definition of the termination condition, this solution has the best cost among all the solutions found so far, and due to monotonicity, it has cost as good as the best solutions that can be found through the nodes currently in the OPEN list. 2. Proof of Theorem 14. The only non-trivial expression to prove is h + c (P , C ) c * (P , C ), as h + c (P ) h + c (P , C ) is direct, given that C simply pushes the cost of some plans in the relaxation P + to ∞, while c * (P , C ) = c * (P ) follows from the validity of C . For proving h + c (P , C ) c * (P , C ), it suffices to note that any plan π for P that complies with the constraints C is also a plan for the relaxation P + that complies with C and has the same cost, as the set of fluents F (π ) that become true as a result of the application of the plan π is the same in P and P + . Proof of Theorem. 17. We show that every assignment encodes a plan in the relaxation that complies with the constraints and has the same cost, and that every plan in the relaxation that complies with the constraint C and has minimum cost, encodes an assignment with the same cost. So the cost of the best assignment is the cost of the best plan in the relaxation that complies with the constraints. The first statement is direct, the actions map(x, y) for x assigned to y, ordered in any way, form a plan for the relaxation that complies with C . For the second, a best plan in P + that complies with C must have at least one action map(x, y) for each x (due to the goal), no two actions map(x, y) and map(x , y) for the same y (due to C ), and no two actions map(x, y) and map(x, y ) for the same x (as a better plan would be obtained by dropping one of the two actions that are assumed to have positive costs). The result is that every x is mapped into a unique y. 2. Proof of Theorem 18. We show a correspondence between the TSP tours and the plans for P + that comply with the constraints C in the theorem. If the tour is x 0 , x 1 , . . . , x n , x f , the action sequence move(x 0 , x 1 ), . . . , move(x n , x n+1 ) with x n+1 = x f is clearly a plan that complies with C which has the same cost. Indeed, the first action is applicable in the initial state, each action move(x i , x i+1 ) adds the precondition at(x i+1 ) required by following action (the other precondition not-visited(x i+1 ) is initially true and remains so until the first action move(x k , x i+1 ) is applied), and they all add the atoms visited(x) in the goal that no action deletes.. In the other direction, we need to show that the edges (x, y) for the actions move(x, y) in a plan π for P + that complies with C , form a tour. For this let τ stand for the longest path x 0 , x 1 , . . . , x m starting at x 0 such that move(x i , x i+1 ) is in the plan. This path must be unique as the constraint C prevents the path from splitting into two or more paths. We have to show then that 1) this path contains all x i , 2) no vertex x i , for i = 0, . . . ,m appears more than once, and 3) no other move actions are in π . For the first, let us assume that there are vertexes not reached by this path, and let at(x k ) be the first atom made true by π for a vertex x k not in τ . Now, x k is not x 0 (else it would in τ ), and therefore there must be an action move(x i , x k ) in π with precondition at(x i ) such that x i is in τ (else at(x k ) would not be the first atom made true by π not in τ ). Yet if x i ∈ τ , i < m is not possible, as the actions move(x i , x i+1 ) and move(x i , x k ) are incompatible with C , while if i = m, we could append the vertex x k to τ in contradiction with τ being the longest such sequence. So there is no such vertex x k and 1) is proved. For 2), since the path τ is unique and visits all vertices including x f that has no successors, it cannot include a loop. Last for 3), actions move(x i , y) for y = x i+1 , cannot be in π as move(x i , y) and move(x i , x i+1 ) would contradict C . At the same time, x f has no successors, and hence the problem includes no actions move(x f , y). 2. Proof of Theorem 19. We show that there is a correspondence between the Minimum (Directed) Spanning Trees rooted at x 0 for the given graph and the best relaxed plans for the delete-relaxation P + .. The relaxed plan associated with a Directed Spanning Tree rooted at x 0 can be obtained by including the actions move(x, y) for the edges (x, y) in the Spanning Tree, taking the structure of the tree as the partial order among the actions. It is simple to verify that such actions ordered in any way compatible with this partial order renders a plan for P + :. all actions are applicable given the initial situation and the previous actions in the sequence, and all the goals visited(x i ) for all i are achieved at the end.. Likewise, if G = (V , E) is the graph associated with a relaxed plan π for P + by setting V to the set of vertices x i for the atoms at(x i ) achieved by π in P + and E to the edges (x i , x k ) such move(x i , x k ) is in π , it follows that G is a Directed Spanning Graph rooted at x 0 for the original graph, which includes all of its vertexes, and paths to each one of them from x 0 . In addition, if π is an optimal plan for P + , then G must be actually an Spanning Tree for the original graph, as due to the positive costs of the edges, and hence of the actions, π will not accommodate two actions move(x i , x k ) and move(x j , x k ) leading to the same vertex x k . Thus every vertex in the original graph will be reachable from x 0 by a single path.. Finally, since every directed spanning tree translates into a plan for P + of the same cost, and every optimal plan for P + translates into a directed spanning tree with the same cost, then min directed spanning trees rooted at x 0 have the same cost as the best plans for P + . 2 In this work we have used propositional logic in various forms (CNF, Logic Programs, d-DNNF), for defining admissible heuristic for planning in the presence of costs and rewards that are computed by means of circuits that map situations into values in time that is linear in the circuit size. This circuit is a simple transformation of the d-DNNF formula encoding the domain where ANDs and ORs are replaced by Adders and Min Operators, and whose output for any situation encodes the cost of the best model. In the worst case, the d-DNNF formula, and hence the evaluation circuit, can have a size that is exponential in the treewidth of the CNF encoding [21] . While this is a worst-case bound and the experiments show that a number of non-trivial problems can be solved by heuristics defined and computed in this way, it nonetheless expresses the practical limitation of the formulation in its current form. A possible way to overcome this limitation is the use of additional relaxations able to map CNF theories into weaker theories of bounded treewidth that can be then compiled in polynomial time and space. This is the approach we have taken recently in [58] for solving MinCostSAT problems. This type of relaxation in a planning setting results in a family of tractable, admissible heuristics, computable by circuits, that capture information about the delete lists in the problem in the form of valid plan constraints. Preliminary experiments using these heuristics are reported in [57] .. The effective use of propositional logic in classical planning has been championed by Kautz and Selman in [43] [44] [45] , where Strips problems P are mapped into CNF theories T (n) for a planning horizon n that are fed into state-of-the-art SAT solvers. The encoding ensures a correspondence between the logical models of T (n) and the plans for P . A similar approach but in the context of Logic Programming, has been proposed in [27, 46, 62] where CNF encodings of planning problems are replaced by Logic Programs whose Answer Sets, computed by state-of-the-art ASP Solvers, are in correspondence with the target plans. Logic programs allow for more concise encodings although this does not translate necessarily into faster solutions due to speed of current SAT solvers.. The differences between our use of logic for planning and these other approaches are basically three. First, we use logic for defining and computing heuristics for planning, not for computing the plans themselves. This allows us to use more compact encodings that do not require time indices or planning horizons. This is important because, the complexity of the encodings grows exponentially with the horizon, and except for the plan metric defined by the horizon, the optimality of the plans obtained is conditional on the horizon used.. Second, the resulting logical encoding is not solved using a SAT or ASP solver, but using a d-DNNF compiler. Once the problem is compiled, the heuristic values for any search state are found in time that is linear in the compiled representation. Incidentally, the d-DNNF compiler can be thought of as a SAT solver with a suitable form of caching that computes all solutions and leaves a 'trace' behind that enables the solution of other problems as well [38] . Another use of d-DNNF in planning is reported in [54] , where heuristics for planning under incomplete information and no sensing (conformant planning) are obtained using projections and model counts computable in linear-time over d-DNNF representations [25] .. Third, the heuristics handle a richer cost structure where actions can have non-uniform costs, and penalties and rewards may be associated with fluents. The computation of optimal plans in rich cost structures has been pursued recently in [8, 30, 35] where planning problems are mapped into optimization variants of SAT, Answer Sets, or CSPs (Constraint Satisfaction Problems) like Weighted Max-SAT, Weighted ASP, and Weighted CSPs. A serious limitation of these approaches, however, is that the optimality of the resulting plans is conditional on the horizon used. Moreover, increasing the planning horizon one by one is no alternative because it is not clear when to stop, as plans with a larger makespan can potentially decrease the overall cost.. Approaches for planning with preferences in the form of soft goals are reported in [7, 60, 64] . The latter two approaches, however, are not optimal for various reasons: in some cases, heuristic mechanisms are used to select the soft goals to pursue, in others, a fixed planning horizon is assumed, and finally in others, a suboptimal Anytime A * search algorithm is used. The work in [7] , on the other hand, presents an optimal planner for dealing with temporally extended preferences based on a branch-and-bound search, yet the lower bounds utilized are not sufficiently informed, and thus the search cannot be run to completion in general.. The problems of selecting a subset of the soft goals to pursue along with the estimation of the cost for achieving them are tightly coupled. The heuristics developed in this paper tackle them both at the same time: the best model of the theory selects the 'soft goals' that are to be pursued at the same time that it estimates the cost of achieving them. The heuristic is indeed optimal for this task when there are no deletes.

O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B B I O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O B O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O


Machine vision technology for agricultural applications Current applications of machine vision in agriculture are briefly reviewed. The requirements and recent developments of hardware and software for machine vision systems are discussed, with emphases on multispectral and hyperspectral imaging for modern food inspection. Examples of applications for detection of disease, defects, and contamination on poultry carcasses and apples are also given. Future trends of machine vision technology applications are discussed. # Many applications using machine vision technology have been developed in agricultural sectors, such as land-based and aerial-based remote sensing for natural resources assessments, precision farming, postharvest product quality and safety detection, classification and sorting, and process automation. This is because machine vision systems not only recognize size, shape, color, and texture of objects, but also provide numerical attributes of the objects or scene being imaged.. Company and product names mentioned are used for clarity only and do not imply any endorsement by USDA to the exclusion of other comparable products.. Besides imaging objects in the visible (VIS) color region, some machine vision systems are also able to inspect these objects in light invisible to humans, such as ultraviolet (UV), near-infrared (NIR), and infrared (IR). The information received from objects in invisible light regions can be very useful in determining preharvest plant maturity, disease, or stress states. It is very useful in determining plant and vegetable variety, maturity, ripeness, and quality. It is also useful in detecting postharvest quality and safety, such as defects, composition, functional properties, diseases and contamination of plants, grains and nuts, vegetables and fruits, and animal products.. Advantages of using imaging technology for sensing are that it can be fairly accurate, nondestructive, and yields consistent results. Applications of machine vision technology will improve industry's productivity, thereby reducing costs and making agricultural operations and processing safer for farmers and processing-line workers. It will also help to provide better quality and safe foods to consumers.. Machine vision discussed here is limited to camera machine vision systems. It holds great potential and benefits for the agricultural industry because of its simplicity, low cost, rapid inspection rate, and broad range of applications. Machine vision can also be performed using X-ray imaging and nuclear magnetic resonant imaging (MRI). X-ray and MRI imaging are widely used in medical applications. Even though they have potential for detecting diseases and defects in agricultural products and food (Chen et al., 1989; Schatzki et al., 1997; Marks et al., 1998) , their applications in the agricultural sector are limited because of the high cost of equipment investment and low operational speed. Machine vision technology has the potential to become very important to the agricultural industry. The use of machine vision technology for land-based and aerial-based remote sensing for natural resources assessments, precision farming, postharvest product quality and safety detection, classification and sorting, and process automation may become routine operations in the near future.. Advances in machine vision technology will make vision systems accurate, robust, and low cost. A real-time operational requirement can be met with a high-speed computer and a frame grabber. The image acquisition board receives imaging data from a camera, performs some processing, and stores the image. It can communicate with the host computer at a speed of 132 Mbytes/second over the PCI bus. These speeds and the data transfer rate are fast enough to meet the real-time needs generally encountered in agricultural applications.. For rapid prototyping of a machine vision system, artificial intelligence programming can be incorporated into the system. Newer tools such as neural networks, fuzzy logic, and expert systems can be applied. For example, Chao et al. (1999) used a color imaging system to classify viscera of wholesome and unwholesome carcasses. They developed a neuro-fuzzy software to enhance the robustness of the classification of the color imaging system.. In order to fully apply machine vision technology, the vision systems for agricultural applications will take full advantage of the fact that vegetation, foods, and agricultural products are biological materials; therefore, the differences in the characteristics of light absorption of the agricultural materials are very important. A hyperspectral imaging technique combines the advantages of spectroscopy and imaging. This technology should find many potential applications in the agricultural industry.. When analyzing hyperspectral image data, the spectral characteristics at each pixel and differences between pixels can be utilized. For example, with hyperspectral imaging of fruits, the specific absorption peaks at chlorophyll and carotenoid bands can be used as a means for the determination of defects, damage, or contamination on the surfaces of fruits. While hyperspectral imaging systems provide important spectral information, they suffer from the incapacity for rapid on-line acquisitions. A common aperture multispectral imaging system with a limited number of wavebands can meet the needs of real-time acquisition and processing. Hyperspectral imaging systems can be used to find optimal bands and develop algorithms for many food commodities. With defined optimal bands, they can be implemented in a common aperture multispectral imaging system for on-line or real-time applications.

O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O B O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O B O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O B O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O B O


The Geometry of Generalized Binary Search This paper investigates the problem of determining a binary-valued function through a sequence of strategically selected queries. The focus is an algorithm called Generalized Binary Search (GBS). GBS is a well-known greedy algorithm for determining a binary-valued function through a sequence of strategically selected queries. At each step, a query is selected that most evenly splits the hypotheses under consideration into two disjoint subsets, a natural generalization of the idea underlying classic binary search. This paper develops novel incoherence and geometric conditions under which GBS achieves the information-theoretically optimal query complexity; i.e., given a collection of N hypotheses, GBS terminates with the correct function after no more than a constant times log N queries. Furthermore, a noise-tolerant version of GBS is developed that also achieves the optimal query complexity. These results are applied to learning halfspaces, a problem arising routinely in image processing and machine learning.Index Terms-Binary search, channel coding with feedback, learning theory, query learning, Shannon-Fano coding. T HIS paper studies learning problems of the following form. Consider a finite, but potentially very large, collection of binary-valued functions defined on a domain . In this paper, will be called the hypothesis space and will be called the query space. Each is a mapping from to . Throughout the paper we will let denote the cardinality of . Assume that the functions in are unique and that one function, , produces the correct binary labeling. It is assumed that is fixed but unknown, and the goal is to determine through as few queries from as possible. For each query , the value , possibly corrupted with independently distributed binary noise, is observed. The goal is to strategically select queries in a sequential fashion in order to identify as quickly as possible. If the responses to queries are noiseless, then the problem is related to the construction of a binary decision tree. A sequence of queries defines a path from the root of the tree (corresponding to ) to a leaf (corresponding to a single element of ). There are several ways in which one might define the notion of an optimal tree; e.g., the tree with the minimum average or worst case Manuscript depth. In general the determination of the optimal tree (in either sense above) is a combinatorial problem and was shown by Hyafil and Rivest to be NP-complete [19] . Therefore, this paper investigates the performance of a greedy procedure called generalized binary search (GBS), depicted below in Fig. 1 . At each step GBS selects a query that results in the most even split of the hypotheses under consideration into two subsets responding and , respectively, to the query. The correct response to the query eliminates one of these two subsets from further consideration. We denote the number of hypotheses remaining at step by . The main results of the paper characterize the worst-case number of queries required by GBS in order to identify the correct hypothesis . More formally, we define the notion of query complexity as follows.. Definition 1: The minimum number of queries required by GBS (or another algorithm) to identify any hypothesis in is called the query complexity of the algorithm. The query complexity is said to be near-optimal if it is within a constant factor of , since at least queries are required to specify one of hypotheses. Conditions are established under which GBS (and a noise-tolerant variant) have a near-optimal query complexity. The main contributions of this paper are two-fold. First, incoherence and geometric relations between the pair are studied to bound the number of queries required by GBS. This leads to an easily verifiable sufficient condition that guarantees that GBS terminates with the correct hypothesis after no more than a constant times queries. Second, noise-tolerant versions of GBS are proposed. The following noise model is considered. The binary response to a query is an independent realization of the random variable satisfying , where denotes the underlying probability measure. In other words, the response to is only probably correct. If a query is repeated more than once, then each response is an independent realization of . A new algorithm based on a weighted (soft-decision) GBS procedure is shown to confidently identify after a constant times queries even in the presence of noise (under the sufficient condition mentioned above). An agnostic algorithm that performs well even if is not in the hypothesis space is also proposed. Generalized binary search can be viewed as a generalization of classic binary search, Shannon-Fano coding as noted by Goodman and Smyth [1] , and channel coding with noiseless feedback as studied by Horstein [2] . Problems of this nature arise in many applications, including channel coding (e.g., the work of Horstein [2] and Zigangirov [4] ), experimental design (e.g., as studied by Rényi [5] , [44] , [6] ), disease diagnosis (e.g., see the work of Loveland [7] ), fault-tolerant computing (e.g., the work of Feige et al. [8] ), the scheduling problem considered by Kosaraju et al. [9] , computer vision problems investigated by Geman and Jedynak [13] and Arkin et al. [14] ), image processing problems studied by Korostelev and Kim [10] , [11] , and active learning research; for example the investigations by Freund et al. [15] , Dasgupta [16] , Balcan et al. [17] , and Castro and Nowak [31] .. Past work has provided a partial characterization of this problem. If the responses to queries are noiseless, then selecting the sequence of queries from is equivalent to determining a binary decision tree, where a sequence of queries defines a path from the root of the tree (corresponding to ) to a leaf (corresponding to a single element of ). In general the determination of the optimal (worst-or average-case) tree is NP-complete as shown by Hyafil and Rivest [19] . However, there exists a greedy procedure that yields query sequences that are within a factor of of the optimal search tree depth; this result has been discovered independently by several researchers including Loveland [7] , Garey and Graham [7] , Arkin et al. [20] , and Dasgupta [16] . The greedy procedure is referred to here as Generalized Binary Search (GBS) or the splitting algorithm, and it reduces to classic binary search, as discussed in Section V-A.. The number of queries an algorithm requires to determine is called the query complexity of the algorithm. Since the hypotheses are assumed to be distinct, it is clear that the query complexity of GBS is at most (because it is always possible to find query that eliminates at least one hypothesis at each step). In fact, there are simple examples (see Section V-A) demonstrating that this is the best one can hope to do in general. However, it is also true that in many cases the performance of GBS can be much better, requiring as few as queries. In classic binary search, for example, half of the hypotheses are eliminated at each step (e.g., refer to the textbook by Cormen et al. [21] ). Rényi first considered a form of binary search with noise [5] , [44] and explored its connections with information theory [6] , [44] . In particular, the problem of sequential transmission over a binary symmetric channel with noiseless feedback, as formulated by Horstein [2] and studied by Burnashev and Zigangirov [3] and more recently by Pelc et al. [22] , is equivalent to a noisy binary search problem.. There is a large literature on learning from queries; see the review articles by Angluin [23] , [24] . This paper focuses exclusively on membership queries (i.e., an is the query and the response is ), although other types of queries (equivalence, subset, superset, disjointness, and exhaustiveness) are possible as discussed by Angluin [23] . Arbitrary queries have also been investigated, in which the query is a subset of and the output is if belongs to the subset and otherwise. A finite collection of hypotheses can be successively halved using arbitrary queries, and so it is possible to determine with arbitrary queries, the information-theoretically optimal query complexity discussed by Kulkarni et al. [25] . Membership queries are the most natural in function learning problems, and because this paper deals only with this type we will simply refer to them as queries throughout the rest of the paper. The number of queries required to determine a binary-valued function in a finite collection of hypotheses can be bounded (above and below) in terms of a combinatorial parameter of due to Hegedüs [26] (see the work of Hellerstein et al. [27] for related work). Due to its combinatorial nature, computing such bounds are generally NP-hard. In contrast, the geometric relationship between and developed in this paper leads to an upper bound on the query complexity that can be determined analytically or computed in polynomial time in many cases of interest.. The term GBS is used in this paper to emphasize connections and similarities with classic binary search, which is a special case the general problem considered here. Classic binary search is equivalent to learning a 1-D binary-valued threshold function by selecting point evaluations of the function according to a bisection procedure. Consider the threshold function on the interval for some threshold value. . Throughout the paper we adopt the convention that . Suppose that belongs to the discrete set and let denote the collection of threshold functions . The value of can then determined from a constant times queries using a bisection procedure analogous to the game of twenty questions. In fact, this is precisely what GBS performs in this case (i.e., GBS reduces to classic binary search in this setting). If for some integer , then each point evaluation provides one bit in the -bit binary expansion of . Thus, classic binary search is information-theoretically optimal; see the book by Traub, Wasilkowski and Wozniakowski [28] for a nice treatment of classic bisection and binary search. The main results of this paper generalize the salient aspects of classic binary search to a much broader class of problems. In many (if not most) applications it is unrealistic to assume that the responses to queries are without error. A form of binary search with noise appears to have been first posed by Rényi [5] , [44] . The noisy binary search problem arises in sequential transmission over a binary symmetric channel with noiseless feedback studied by Horstein [2] and Zigangirov [4] , [29] . The survey paper by Pelc et al. [22] discusses the connections between search and coding problems. In channel coding with feedback, each threshold corresponds to a unique binary codeword (the binary expansion of ). Thus, channel coding with noiseless feedback is equivalent to the problem of learning a 1-D threshold function in binary noise, as noted by Burnashev and Zigangirov [3] . The near-optimal solutions to the noisy binary search problem first appear in these two contexts. Discrete versions of Horstein's probabilistic bisection procedure [2] were shown to be information-theoretically optimal (optimal decay of the error probability) in the works of Zigangirov and Burnashev [3] , [4] , [29] . More recently, the same procedure was independently proposed and analyzed in the context of noise-tolerant versions of the classic binary search problem by Karp and Kleinberg [30] , which was motivated by applications ranging from investment planning to admission control in queueing networks. Closely related approaches are considered in the work of Feige et al. [8] . The noisy binary search problem has found important applications in the minimax theory of sequential, adaptive sampling procedures proposed by Korostelov and Kim [10] , [11] for image recovery and binary classification problems studied by Castro and Nowak [31] . We also mention the works of Rivest et al. [32] , Spencer [33] and Aslam and Dhagat [35] , and Dhagat et al. [34] , which consider adversarial situations in which the total number of erroneous oracle responses is fixed in advance.. One straightforward approach to noisy GBS is to follow the GBS algorithm, but to repeat the query at each step multiple times in order to decide whether the response is more probably or . This simple approach has been studied in the context of noisy versions of classic binary search and shown to perform significantly worse than other approaches in the work of Karp and Kleinberg [30] ; perhaps not surprising since this is essentially a simple repetition code approach to communicating over a noisy channel. A near-optimal noise-tolerant version of GBS was developed in this paper. The algorithm can be viewed as a nontrivial generalization of Horstein's probabilistic bisection procedure. Horstein's method relies on the special structure of classic binary search, namely that the hypotheses and queries can be naturally ordered together in the unit interval. Horstein's method is a sequential Bayesian procedure. It begins with uniform distribution over the set of hypotheses. At each step, it queries at the point that bisects the probability mass of the current distribution over hypotheses, and then updates the distribution according to Bayes rule. Horstein's procedure isn't directly applicable to situations in which the hypotheses and queries cannot be ordered togetherl, but the geometric condition developed in this paper provides similar structure that is exploited here to devise a generalized probabilistic bisection procedure.. The key elements of the procedure and the analysis of its convergence are fundamentally different from those in the classic binary search work of Burnashev and Zigangirov [3] and Karp and Kleinberg [30] .

O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I I B I B I B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O B I B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O


Capacitated Arc Stabbing In the Capacitated Arc Stabbing problem (CAS) we are given a set of arcs and a set of points on a circle. We say that a point p covers, or stabs, an arc A if p is contained in A. Each point has a weight and a capacity that determines the number of arcs it may cover. The goal is to find a minimum weight set of points that stabs all the arcs. CAS models a periodic multiitem lot sizing problem in which we are given a set of production requests each with its own periodic release time and deadline. Production takes place in batches of bounded capacity: each time unit t is associated with a capacity c(t) and weight w(t), where c(t) bounds the number of requests that can be manufactured at time t, and w(t) is a fixed cost for manufacturing any positive number of requests up to c(t) at time t. The goal is to find a minimum weight periodic schedule. We present a polynomial time algorithm for CAS that is based on a non-trivial reduction to Capacitated Interval Stabbing. Our approach applies to both hard and soft capacities. We also consider two variants of CAS in which some arcs may remain uncovered: in the partial variant there is a covering requirement g, and the goal is to find a minimum weight set of points that covers at least g arcs; and in the prize collecting variant each arc has a penalty that must be paid if this arc is not covered. In the (uncapacitated) Arc Stabbing problem we are given a set A of n arcs and a set P of m points on a circle. We say that a point p covers or stabs an arc A if p ∈ A. Each point p ∈ P has a weight w(p), and our goal is to find a minimum weight set of points H ⊆ P that covers all arcs in A. Interval Stabbing is the special case of Arc Stabbing, where the circle is not fully covered by arcs, and therefore arcs correspond to intervals on the real line. In other words, in Interval Stabbing we are given a set of intervals and a set of weighted points on the line, and the goal is to find a minimum set of points that covers all the intervals.. In this paper we introduce an extension of Arc Stabbing called Capacitated Arc Stabbing (abbreviated CAS). In CAS each point p ∈ P has a capacity c(p) ∈ N that determines the number of arcs it may cover. In the hard capacities case one may take only one copy of each point, while in the soft capacities case multiple copies of a point may be used to cover additional arcs, provided that the weight of p is counted for each copy. A feasible solution is an assignment of every arc to a point. (Formal definitions are given in Section 2.) Arc Stabbing is the special case where c(p) = ∞ for every point p.. CAS models the following periodic multi-item lot sizing problem. We are given a repeating period consisting of T discrete time units indexed t = 0, . . . , T − 1, and a set of unit size production requests denoted by R 1 , . . . , R n , where each request has periodic release time r i and deadline d i . Production takes place in mixed batches of bounded capacity. Each time unit t is associated with a capacity c(t) and weight w(t), where the number of requests that can be manufactured at time unit t is at most c(t), and w(t) is a fixed manufacturing cost at time t for any positive number of requests up to c(t). A feasible solution is a periodic production schedule in which R i is produced exactly once during every period within the arc [r i , d i ]. Moreover, R i must be produced at the same time within each period. The goal is to find a minimum weight periodic schedule.. Another possible application of CAS is event coverage by sensors located on a closed fence surrounding a convex area. Events take place outside the perimeter, and each event can be covered by any sensor that has a clear view of the event. Hence, sensors that can cover an event are located on some contiguous segment of the fence. Each sensor has a cap on the number of events that it can cover and an operation cost, and the goal is to cover all events at minimum cost.. We also study two extensions of CAS, in which arcs may remain uncovered. In Partial CAS we are given a covering requirement g, and the goal is to find a minimum weight assignment of at least g arcs to points. (If g = |A|, we return to CAS.) In the periodic lot sizing terminology this means that we would like to find a periodic schedule that satisfies at least r requests. In Prize Collecting CAS we are not obligated to cover all arcs, but must pay penalties for uncovered arcs. More formally, both points and arcs have non-negative weights, and the weight of a feasible solution is the total weight of its points plus the total weight of uncovered arcs. (If all penalties are large enough, say w(A) ≥ max p∈A w(p), the problem reduces to CAS.) Alternatively, we seek a periodic schedule that satisfies a subset of the requests, and the cost of the schedule consists of production cost and penalties for unsatisfied requests.. Our results. We present a polynomial time algorithm for CAS that is based on a reduction to Capacitated Interval Stabbing (CIS) that can be solved in polynomial time [11] . Our reduction is somewhat complicated, and it is based on a characterization of an optimal solution. More specifically, we show that there exists an optimal solution that adheres to a limited and circular version of the earliest due date rule. The reduction applied to both hard and soft capacities.. We note that naive attempts to "break the circle" fail. For instance, "guessing" a point p that participates in an optimal solution works well for Arc Stabbing, but not for CAS. The problem is that, after breaking the circle at p, one has to decide for every arc that contains p whether it should be covered by p, by points on the left side of the resulting line or by points on the right side of this line. (This is relatively easy if no arc is contained in another, namely in proper circular-arc graphs.) Furthermore, in the soft capacities case, preferring cost-effective points (i.e., points with low cost per covered interval) leads to a 2-approximation algorithm even in the case of CIS [12] .. We also present polynomial time algorithms for Partial CAS. The presentation is composed of two parts. First, we provide a polynomial time algorithm that solves Partial CIS that uses dynamic programming and is based on the algorithm for CIS from [11] . Second, we show that the above reduction can be extended to the partial setting. A similar approach is used to design a polynomial time algorithm for Prize Collecting CAS.. Related work. Interval Stabbing is the well known Clique Cover problem in interval graphs that can be solved in polynomial time [17, page 174] . The prize collecting version of Interval Stabbing is solvable in O(n log n) time [21] . Arc Stabbing is a variant of Clique Cover in circular-arc graphs in which one is only allowed to use point-induced cliques, and it can be solved in polynomial time using the above mentioned reduction to Interval Stabbing (i.e., "breaking the circle"). Hochbaum and Levin [22] gave an O(mn + n 2 log n) time algorithm for solving unweighted Arc Stabbing. Hsu and Tsai [23] showed that Clique Cover in circular-arc graphs can be solved in linear time.. In the Circle Cover problem the input is a set of n arcs on a circle, and the goal is to find a minimum number of arcs whose union covers the circle. (i.e., points are covered by arcs). Circle Cover is motivated by a surveillance problem in which one is given a convex area whose outer boundary needs to be watched, and there are a number of sensors each covering a certain range of the boundary faces. An O(n log n) time algorithm was given in [25] , and parallel algorithms where presented in [7, 2] .. Wolsey [30] presented a greedy algorithm for weighted Set Cover with hard capacities that achieves a logarithmic approximation ratio. More recently, several approximation algorithms for Capacitated Vertex Cover were presented: the soft capacities case was studied in [19, 4, 15] , and the hard capacities case was considered in [10, 14, 18] . Berman et al. [6] gave a 1.5-approximation algorithm for the problem of covering points by capacitated arcs. In their model the points may have different demands, but the capacities are uniform and soft.. Even et al. [11] presented a polynomial time dynamic programming algorithm for CIS both with hard and soft capacities. They extended the algorithm to solve a multi-item lot sizing problem in which there are costs for maintaining inventory, or holding costs, that abide by the following constraint: the requests are indexed by increasing order of importance, such that shortening the holding time of the more important requests at the expense of extending the holding time of the less important requests never increases the overall holding costs. Note that if arbitrary request sizes are allowed this problem becomes NP-hard (there is a reduction from knapsack [13] ).. Anily, Tzur and Wolsey [1] proposed a polynomial size linear program that solves a closely related model, in which the requests are not necessarily of unit size, the capacities are uniform, and the holding costs are time-dependent. As opposed to this model, in [11] there are only unit size (or polynomially bounded size) requests, but a more general holding cost structure and nonuniform capacities. Recently Levi, Lodi and Sviridenko [26] have shown that without the relative importance property of the requests, the model from [1] is strongly NP-hard even for unit size requests. The same applies to the model from [11] .. Even et al. [11] also considered the Capacitated d-dimensional rectangle stabbing problem which is the d-dimensional generalization of CIS. In this problem the intervals are replaced by axis parallel d-dimensional rectangles and the points become hyperplanes that are orthogonal to one of the d axes. They presented O(d)-approximation algorithms that rely on LP-rounding. (In the hard capacities case they obtained a bi-criteria algorithm that computes solutions that are O(d)-approximate and use at most two copies of each hyperplane.) We note that the techniques from [11] can also be used to design O(d)-approximation algorithms for the version of CAS in which arcs are replaced by d-arcs, where a d-arc is a union of d disjoint arcs. (Capacitated d-dimensional rectangle stabbing is a special case of this d-dimensional variant of CAS.). Partial Set Cover was first studied by Kearns [24] , who proved that the performance guarantee of the greedy algorithm is at most 2H m + 3, where m is the size of the ground set and H m is the mth harmonic number. Slavík [28] showed that it is actually bounded by H g , where g is the covering requirement. Partial Vertex Cover was studied in [9, 3, 16, 29, 20] . Partial Capacitated Vertex Cover was studied in [27, 5] .. Paper organization. Section 2 contains a formal definition of the problems, notation and terminology, and a short discussion about the earliest due date rule. Section 3 contains our reduction from CAS to CIS. We consider Partial CAS in Section 4 and Prize Collecting CAS in Section 5.

O B I O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O


Audio presentation of auto-suggest lists One of the most significant advances behind World Wide Web (Web) 2.0 is the ability to allow parts of a Web page to be updated independently. This can provide an exciting, interactive experience for sighted users, who are used to dealing with complex visual information. For visually impaired users, however, these pages may be confusing: updates are sometimes not recognised by screen readers, while in other cases they may interrupt the user inappropriately. The SASWAT project aims to develop a model of how sighted users interact with dynamic updates, and use this to identify the most effective ways of presenting updates through an audio information stream. Here, we describe a 'thin slice' through this project, focusing on one form of update -the auto-suggest list. These provide the user with suggestions for entry into an input text field, updating with each character typed. Experiments with sighted users suggest that the suggestions receive considerable attention, and appear to offer reassurance that the input is reasonable. Suggestions that are further down the list are less likely to be viewed, and receive fewer and shorter fixations than those at the top. We therefore propose an implementation which presents the first 3 suggestions immediately and allows browsing of the rest. Some of the major technological changes behind 'Web 2.0' are those that allow communication between browser and server such that sections of a Web page may change in isolation, without needing to refresh the whole page. We call these sections 'dynamic micro-content', and the changes 'dynamic updates'. Examples of dynamic micro-content can be seen on pages such as the Yahoo! Web portal 1 . Unfortunately, using these pages is difficult for visually disabled users. Assistive technologies, such as screen readers, are currently unable to deal effectively with dynamic updates. A review of how users of different assistive technologies deal with dynamically updating pages [1] showed that older browser / screen reader combinations did not respond to some updates, in particular those which occurred automatically. Even newer technologies often did not notify the user that the page had changed.. To make Web 2.0 accessible to visually disabled people, we must gain a comprehensive understanding of how users interact with these dynamic streams of information. Despite the prevalence of dynamic content, no previous research has investigated in detail how users respond in either browse, or task, based scenarios. The SASWAT project 2 aims to develop a model of how sighted users interact with dynamic updates, and use this to identify how and why the information is useful, and thus the most effective ways of presenting updating Web pages through an audio information stream. Simply enabling screen readers to detect and relay dynamic updates only solves part of the problem -providing a naïve sensory translation from vision to audio is not necessarily desirable, or even possible; instead we must ask: "Which parts of the changing content should be sent to the screen reader, and in what order?".. Currently, the most significant attempt to tackle the accessibility of dynamic updates is the Accessible Rich Internet Applications Suite (ARIA) [2] . The essence of the ARIA solution is to add semantic metadata, e.g., to mark regions of a page that may update as being 'live'. Tags can give information about an update, including how important it is (its politeness: polite, assertive, or rude). The work described here can be seen as complementing the ARIA ap-proach. We believe that, while the information the ARIA attributes and properties provide can help, it cannot be used in a naïve manner. Thiessen and Chen [4] discuss the difficulties in scaling ARIA for highly active pages; they found using ARIA effectively became problematic when updates occur frequently. Understanding how to use ARIA tags, both from the point of view of the developer (which settings to choose) and from that of the user-agent and assistive technologies (how to use the tags to help determine exactly when and how to present an update), is difficult, and we believe that a good understanding of how sighted users interact with dynamic updates, and why, is essential. This paper describes a 'thin slice' through the SASWAT project, focusing on one particular form of update -the Auto-Suggest List (ASL). An ASL is a list box that provides the user with suggested entries for a text field, based on what they are typing. The suggestions appear when the user starts typing in the box (either after the first character or after a set minimum, e.g., 3), and are refreshed for each change. ASLs are both common and of a relatively consistent form. A brief survey looked at the Alexa global top sites 3 . After removing duplicates (e.g., www.google.com and www.google.de) the remaining top 20 were examined and found to contain 12 instances of ASLs.. We describe an empirical experiment (see § 2) that used eye-tracking to infer how users allocate attention to dynamically updating Web pages. This shows that ASL suggestions are almost universally attended to, irrespective of whether they are actually used, and that participants are less likely to attend to those suggestions that appeared lower down the list (see § 2.1). We describe an approach to mapping ASLs to audio based upon these results (see § 3), and outline an implementation (see § 3.1). The first thing revealed by the results is that people definitely view the ASLs. In almost every case, all the participants viewed the ASL at some point. There is also a reasonably distinct pattern to the way in which results are viewed. The percentage of people viewing a suggestion is greatest if it appears in the top three list positions, and drops markedly after this point. There is also evidence that the first suggestion is regarded by participants as the most important, then the second, then the third, with earlier suggestions receiving more, and longer, fixations. In total ASLs were encountered 90 times in the course of the experiments. This section presents an analysis of these interactions, first describing how users interacted with the dynamic content, then giving some quantitative data.. There was considerable consistency in the manner in which people used the ASLs. On the Kayak site, all 24 participants for whom suggestions appeared selected their destination airport from the list. The majority of participants viewed the Google Suggest ASL when it appeared: 9 selected from it in both tasks; 10 in one task. 6 participants did not select from the list, but did view it extensively for at least one task. Observation of gaze behaviour strongly suggests that the presence of the ASL, whether people select from it or not, is used to correct spellings, or reassure the user that they are typing a reasonable query. Only 3 participants appeared not to view the ASL at all. Of the 4 participants who encountered the ASL on the Yahoo! page, all viewed the list briefly, one of whom selected from it.. To quantify the gaze data for each ASL instance, the input box and each suggestion in the list (up to the sixth, if present) were classified as separate Areas of Interest (AOIs) (see Figure 1) . Note that the AOIs defined refer to the positions of the suggestions in the list, not the content of the suggestion. The data can then be analysed to say, for each AOI: how many people fixated it; how many times they fixated it; the time between the area appearing and the first fixation, and; the mean fixation duration. In order to test the mapping proposed above, a system is being developed for evaluation. This is based on the Fire Vox screen reading extension for the Firefox Web browser 5 . The logic is as follows. When an update is detected, the DOMs from before and after are compared to identify and cluster those nodes that have changed. The user's last action, current location (within the page), and the information contained in the update are used to determine the update type. Roughly speaking, the update is considered as an ASL if the user has recently typed, an input box has focus, and the update involves insertion of a list or a table. Once an ASL update has been identified, the list items are extracted from the list or table, and the first three are spoken. If the user types enter while one is being spoken, the text for that suggestion will be inserted into the input box. If the user wishes to hear a complete list of suggestions, the up and down arrow keys allow traversal of the whole list. If the user continues typing, speech will stop and typing will be inserted into the input box as usual.

O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O


First-class state change in plaid Objects model the world, and state is fundamental to a faithful modeling. Engineers use state machines to understand and reason about state transitions, but programming languages provide little support for building software based on state abstractions. We propose Plaid, a language in which objects are modeled not just in terms of classes, but in terms of changing abstract states. Each state may have its own representation, as well as methods that may transition the object into a new state. A formal model precisely defines the semantics of core Plaid constructs such as state transition and trait-like state composition. We evaluate Plaid through a series of examples taken from the Plaid compiler and the standard libraries of Smalltalk and Java. These examples show how Plaid can more closely model state-based designs, enhancing understandability, enhancing dynamic error checking, and providing reuse benefits. Object-oriented programming provides a rich environment for modeling real-world and conceptual objects within the computer. Fields capture attributes of objects, methods capture their behavior, and subtyping captures specialization * Partially funded by FONDECYT Project 1110051. Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. To copy otherwise, to republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. OOPSLA'11, October 22-27, 2011, Portland, Oregon, USA. Copyright c 2011 ACM 978-1-4503-0940-0/11/10. . . $10.00 relationships among objects. A key element missing from object-oriented programming languages, however, is abstract states and conceptual state change. State change is pervasive in the natural world; as a dramatic example, consider the state transition from egg, to caterpillar, to pupae, to butterfly. Modeling systems with abstract states and transitions between them is also common in many engineering disciplines.. In computer science, state machines are important modeling concepts in the UML. Abstract states are also a critical, though often implicit, part of many library APIs-and any client using that API must be aware of those states to use the API correctly. For example, a file may be in the open or closed state. In the open state, one may read or write to a file, or one may close it, which causes a state transition to the closed state. In the closed state, the only permitted operation is to (re-)open the file.. Files provide a simple example of abstract states, but there are many more. Streams may be open or closed, iterators may have elements available or not, collections may be empty or not, and even lowly exceptions can have their cause set, or not 1 . State spaces may be complex: In ResultSet from the Java JDBC library, we found 33 unique states dealing with different combinations of openness, direction, random access, insertions, etc [7] . States are also common: a recent study of protocols in Java suggests that almost three times as many types define protocols as define type parameters [3] . They also cause significant pain: for instance, in a study of problems developers experienced when using the ASP.NET framework, 3/4 of the issues identified involved temporal constraints such as the state of the framework in various callback functions [16] . All this raises a natural question: why not support abstract states in programming languages?. We previously proposed Typestate-Oriented Programming as a new programming paradigm in which programs are made up of dynamically created objects, each object has a typestate that is changeable, and each typestate has an interface, representation, and behavior [1] . The term typestate refers to a static abstract state checking methodology proposed by Strom and Yemini [25] ; this paper focuses on a dynamically-typed setting, and so we will use the terms (abstract) state and protocol in place of typestate to avoid confusion.. A programming language with abstract states can have many benefits. First, in the case of stateful abstractions, the code will more clearly reflect the intended design. This in turn will make state constraints more salient to developers who need to be aware of them. If state constraints are implicitly enforced by the object model, there is no need to code up explicit checks; thus code implementing states can be more concise. Explicit state models raise the level of error messages; instead of (perhaps) silently corrupting a data structure when an inappropriate method is called, the runtime can signal an error that that method is unavailable in the current state. Finally, explicit modeling of states also exposes new concepts for widespread reuse; candidates may include open/closed resources or positioning (beginning, middle, end) of streams.. Contribution. The contribution of this paper is the concrete design and evaluation of Plaid, an object-oriented programming language that incorporates first-class state change as well as trait-like state composition. Plaid has been implemented, and has proven effective for writing a diverse set of small and medium-sized (up to 10kLOC) programs, including a self-hosted compiler. For the purposes of this paper, Plaid is dynamically typed, though there are plans to add a gradual type system following recent work on gradual typestates [29] .. The most interesting aspects of Plaid's design come from the intersection of state change with support for a trait-like model of composition [12] . Central goals of the language design include supporting the primary state modeling constructs from statecharts [14] , as well as flexible code reuse. Our design includes a hierarchical state space, so that the open state of a stream can be refined into within and eof substates indicating whether there is data left to be processed. Handling real designs in a modular way requires support for multi-dimensional state spaces, as in and-states from [14] ; an example is a separate dimension of a stream's state indicating whether the stream has been marked with a location or not. Modularity further requires reasoning about dimensions separately; for example, the mark() method should affect the marked state dimension but it should not affect whether the stream is at eof. Dimensions also delineate natural points of reuse; we would like to specify them separately and combine them using a trait-like composition operator.. We position Plaid relative to earlier work in the next section. Plaid's design is described by example in section 3. This section validates our design, using a number of carefully chosen examples to concretely illustrate how Plaid provides the potential benefits described above. We also discuss our prototype implementation of Plaid, targeting the JVM.. In order to be precise about Plaid's semantics, Section 4 provides a formal model that includes the semantics of all of Plaid's major features. Section 5 describes how the surface Plaid language is elaborated into the core formal model. The paper concludes with a discussion of ongoing work on Plaid, together with an argument that the concrete benefits validated by example lead to higher-level benefits in software development and evolution.

O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O B O O O O O O O O B O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O B O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O B O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O B O O O O O O O O O O O B O O O O O O O O O O O B O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O