977

Handbook of Constraint Programming (Foundations of Artificial Intelligence)

Embed Size (px)

Citation preview

  • FOUNDATIONS OFARTIFICIAL INTELLIGENCE

  • Foundations of Artificial Intelligence

    Series Editors

    J. HendlerH. KitanoB. Nebel

    Cover picture by Helmut Simonis

    ELSEVIERAMSTERDAMBOSTONHEIDELBERGLONDONNEW YORKOXFORD

    PARISSAN DIEGOSAN FRANCISCOSINGAPORESYDNEYTOKYO

  • Handbook of Constraint Programming

    Edited by

    Francesca RossiUniversity of Padova

    Italy

    Peter van BeekUniversity of Waterloo

    Canada

    Toby WalshNational ICTA Australia &

    University of New South WalesAustralia

    ELSEVIERAMSTERDAMBOSTONHEIDELBERGLONDONNEW YORKOXFORD

    PARISSAN DIEGOSAN FRANCISCOSINGAPORESYDNEYTOKYO

  • ElsevierRadarweg 29, PO Box 211, 1000 AE Amsterdam, The NetherlandsThe Boulevard, Langford Lane, Kidlington, Oxford OX5 1GB, UK

    First edition 2006

    Copyright 2006 Elsevier B.V. All rights reserved

    No part of this publication may be reproduced, stored in a retrieval systemor transmitted in any form or by any means electronic, mechanical, photocopying,recording or otherwise without the prior written permission of the publisher

    Permissions may be sought directly from Elseviers Science & Technology RightsDepartment in Oxford, UK: phone (+44) (0) 1865 843830; fax (+44) (0) 1865 853333;email: [email protected]. Alternatively you can submit your request online byvisiting the Elsevier web site at http://elsevier.com/locate/permissions, and selectingObtaining permission to use Elsevier material

    NoticeNo responsibility is assumed by the publisher for any injury and/or damage to personsor property as a matter of products liability, negligence or otherwise, or from any useor operation of any methods, products, instructions or ideas contained in the materialherein. Because of rapid advances in the medical sciences, in particular, independentverification of diagnoses and drug dosages should be made

    Library of Congress Cataloging-in-Publication DataA catalog record for this book is available from the Library of Congress

    British Library Cataloguing in Publication DataA catalogue record for this book is available from the British Library

    ISBN-13: 978-0-444-52726-4ISBN-10: 0-444-52726-5ISSN: 1574-6525

    For information on all Elsevier publicationsvisit our website at books.elsevier.com

    Printed and bound in The Netherlands

    06 07 08 09 10 10 9 8 7 6 5 4 3 2 1

  • Foreword

    Constraints are an ubiquitous concept, which in its broader sense pertains to every dayexperience: they represent the conditions which restrict our freedom of decision. In fact,how much our choices are constrained by the external world is a basic philosophical ques-tion. In the formalized reasoning of scientific disciplines, constraints have been employedextensively, from logic to numerical analysis, from mathematical programming to opera-tions research. In computer science, constraints have been with us from the early days, formodeling, representing and reasoning (see the interesting historical remarks in Chapter 2of this handbook, Constraint Satisfaction: An Emerging Paradigm).

    I see several good reasons for this ubiquity: one is the conceptually clear separationbetween the perfectly declarative problem statements and the often cumbersome enumera-tive efforts for finding solutions. Another reason is the complexity challenge: the classicalconstraint satisfaction problem is NP-complete and in fact tautology checking in propo-sitional calculus (a constraint problem on Boolean variables) has been the touchstone forthis complexity class. A further reason is that large, complex constraint problems oftenoccur in practice, they must be solved in one way or another, and fast, efficient, systematicsolutions have an enormous economic value.

    What I find surprising about constraints is that within artificial intelligence and com-puter science a relatively recent, relatively uniform body of knowledge has emerged whichoften yields decisive advantages over classical, extensively studied and well developedtechniques. As for many success stories within computer science, success is largely dueto a mixture of structures, algorithms, languages, programming techniques and system im-plementations. The aim of this handbook is to present this knowledge in all its facets.Different chapters are largely self contained and all contribute to put the subject into focus,similarly to the Hawaii Keck observatory, where the mirror is composed of 36 hexagonalsegments.

    From the conceptual point of view, the main characteristic features of constraint pro-gramming are constraint propagation, and the identification of various special cases whichmake complexity tractable. The former (see Chapter 3) is an inference technique whichmakes local constraints stronger without changing the global constraint. The latter issueconcerns both the structure (see Chapter 7, Tractable Structures for Constraint SatisfactionProblems) and the kind of constraints (see Chapter 8, The Complexity of Constraint Lan-guages). Less specific, but still very important issues are as follows: Backtracking SearchAlgorithms, in Chapter 4; Local Search, in Chapter 5; Global Constraints, in Chapter 6;Symmetry in Constraint Programming, in Chapter 10; and Modelling, in Chapter 11.

    Another surprising fact about constraint theory is the incredibly close relationship withlogic programming. In a rather precise sense logic programming is a way of expressing,and solving, certain classes of disjunctive, recursive constraints. Furthermore, logic pro-gramming can be very elegantly generalized to constraint logic programming (see Chapter

    v

  • vi Foreword

    12), where the ordinary Herbrand constraint system, and its unification algorithm, are com-plemented with specific constraint solvers. The interaction with the committed choice lan-guages studied in the Japanese projects of the eighties also yielded very interesting modelsof computation based on constraints. Amalgamation with more common (and efficientlyimplemented!) programming languages is also possible (see Chapter 13, Constraints inProcedural and Concurrent Languages).

    Besides and beyond the beauty of its theoretical foundations, what contributes the mostto the practical convenience of constraint programming are: (i) the development of specificresults for important classes of constraints; (ii) the ability of extending the basic theory tovarious additional aspects which are very relevant in practice; and (iii) the flexibility andpotential for integration with other modeling and solving methodologies.

    About the development of specific results, this handbook includes chapters about con-straints on finite (Chapter 14), structured (Chapter 17), temporal (Chapter 19), continuousand interval-based (Chapter 16) domains. The potential to extend the basic theory in evi-dent in the case of soft constraints, considered in Chapter 9. Ordinary constraints are eithersatisfied or not, namely either true or false. Instead soft constraints return a more infor-mative weight. Interestingly enough, the proposed extensions both accommodate severalimportant cases (fuzzy, hierarchical, optimization, probabilistic constraints), and still of-ten exhibit essentially the same solution algorithms. Extensions to random, changing anddistributed/open constraints are treated in Chapters 18, 21 and 20 respectively.

    About the last issue, in addition to the seamless integration with logic and imperativeprogramming languages we mentioned already, quite remarkable are the paradigms result-ing from the integration of constraint programming with operations research (see Chapter15), with scheduling and planning (see Chapter 22), with vehicle routing (see Chapter 23),with component configuration (see Chapter 24), with (electricity, water, oil, data) networks(see Chapter 25), and with bioinformatics (see Chapter 26).

    The global scenario based on service-oriented computing which is now under devel-opment offers additional theoretical and practical challenges to constraint programming.Conditions for service deployment and discovery, both functional and involving differentaspects of quality of service, could be expressed in terms of hard and soft constraints, andthe negotiation phases should involve substantial constraint solving abilities. Transactionsamong the various actors could also require partially backtrackable behavior or at leastprogrammable compensations. Some level of real time, distributed, global constraint solv-ing should be implemented in the middleware, since lots of higher level applications willbe able to take advantage of, and pay for it.

    I think that research and practical development in the area of constraint programmingwill be very active for quite a while in the future, establishing closer and closer connectionswith a variety of other design methodologies and even other disciplines. I consider thishandbook not only a very nice piece of scientific work, but also a contribution quite instru-mental at disseminating advanced knowledge about constraint programming both withinthe inner constraint community and across the much wider audience of potential users.

    UGO MONTANARIDipartimento di Informatica

    Universita di Pisa, Italy

  • Editors

    Francesca RossiUniversity of PadovaItaly

    Peter van BeekUniversity of WaterlooCanada

    Toby WalshNational ICT Australia &University of New South WalesAustralia

    vii

  • This page intentionally left blank

  • Contributors

    Rolf BackofenAlbert-Ludwigs-UniversitatGermany

    Philippe BaptisteCNRS LIX & Ecole PolytechniqueFrance

    Frederic BenhamouUniversite de NantesFrance

    Christian BessiereLIRMM-CNRSFrance

    Kenneth N. BrownCork Constraint Computation Centre &University College Cork, Ireland

    Mats CarlssonSICS ABSweden

    David CohenRoyal Holloway, University of LondonUnited Kingdom

    Rina DechterUniversity of California, IrvineUSA

    Boi FaltingsSwiss Federal Institute of TechnologySwitzerland

    Eugene C. FreuderCork Constraint Computation Centre &University College Cork, Ireland

    Thom FruhwirthUniversitat UlmGermany

    Ian P. GentUniversity of St. AndrewsScotland, United Kingdom

    Carmen GervetBrown UniversityUSA

    David GilbertUniversity of GlasgowScotland, United Kingdom

    Carla GomesCornell UniversityUSA

    Laurent GranvilliersUniversite de NantesFrance

    John N. HookerCarnegie Mellon UniversityUSA

    Holger H. HoosUniversity of British ColumbiaCanada

    ix

  • x Contributors

    Peter JeavonsUniversity of OxfordUnited Kingdom

    Ulrich JunkerILOG SAFrance

    Irit KatrielUniversity of AarhusDenmark

    Philip KilbyThe Australian National UniversityAustralia

    Manolis KoubarakisUniversity of AthensGreece

    Philippe LaborieILOG SAFrance

    Claude Le PapeILOG SAFrance

    Alan K. MackworthUniversity of British ColumbiaCanada

    Kim MarriottMonash UniversityAustralia

    Pedro MeseguerIIIA-CSICSpain

    Laurent MichelUniversity of ConnecticutUSA

    Ian MiguelThe University of St. AndrewsScotland, United Kingdom

    Wim NuijtenILOG SAFrance

    Karen E. PetrieUniversity of St. AndrewsScotland, United Kingdom

    Jean-Francois PugetILOG SAFrance

    Francesca RossiUniversity of PadovaItaly

    Thomas SchiexINRA ToulouseFrance

    Christian SchulteKTH - Royal Institute of TechnologySweden

    Paul ShawILOG SAFrance

    Helmut SimonisCrossCore OptimizationUnited Kingdom

    Barbara M. SmithCork Constraint Computation Centre &University College Cork, Ireland

    Peter J. StuckeyUniversity of MelbourneAustralia

    Edward TsangUniversity of EssexUnited Kingdom

    Peter van BeekUniversity of WaterlooCanada

  • Contributors xi

    Willem-Jan van HoeveCornell UniversityUSA

    Mark WallaceMonash UniversityAustralia

    Toby WalshNational ICT Australia &University of New South WalesAustralia

  • This page intentionally left blank

  • Contents

    Foreword v

    Editors vii

    Contributors ix

    Contents xiii

    I Foundations 1

    1 Introduction 3Francesca Rossi, Peter van Beek, Toby Walsh

    1.1 Purpose of the Handbook . . . . . . . . . . . . . . . . . . . . . . . . . 41.2 Structure and Content . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.3 Future Research . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

    2 Constraint Satisfaction: An Emerging Paradigm 13Eugene C. Freuder and Alan K. Mackworth

    2.1 The Early Days . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132.2 The Constraint Satisfaction Problem: Representation and Reasoning . . 162.3 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

    3 Constraint Propagation 29Christian Bessiere

    3.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303.2 Formal Viewpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333.3 Arc Consistency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373.4 Higher Order Consistencies . . . . . . . . . . . . . . . . . . . . . . . . 503.5 Domain-Based Consistencies Stronger than AC . . . . . . . . . . . . . 573.6 Domain-Based Consistencies Weaker than AC . . . . . . . . . . . . . . 623.7 Constraint Propagation as Iteration of Reduction Rules . . . . . . . . . . 683.8 Specific Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70

    4 Backtracking Search Algorithms 85Peter van Beek

    4.1 Preliminaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 864.2 Branching Strategies . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87

    xiii

  • xiv

    4.3 Constraint Propagation . . . . . . . . . . . . . . . . . . . . . . . . . . 904.4 Nogood Recording . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 964.5 Non-Chronological Backtracking . . . . . . . . . . . . . . . . . . . . . 1024.6 Heuristics for Backtracking Algorithms . . . . . . . . . . . . . . . . . . 1054.7 Randomization and Restart Strategies . . . . . . . . . . . . . . . . . . . 1114.8 Best-First Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1164.9 Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1174.10 Comparing Backtracking Algorithms . . . . . . . . . . . . . . . . . . . 118

    5 Local Search Methods 135Holger H. Hoos and Edward Tsang

    5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1365.2 Randomised Iterative Improvement Algorithms . . . . . . . . . . . . . 1425.3 Tabu Search and Related Algorithms . . . . . . . . . . . . . . . . . . . 1445.4 Penalty-Based Local Search Algorithms . . . . . . . . . . . . . . . . . 1485.5 Other Approaches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1545.6 Local Search for Constraint Optimisation Problems . . . . . . . . . . . 1555.7 Frameworks and Toolkits for Local Search . . . . . . . . . . . . . . . . 1575.8 Conclusions and Outlook . . . . . . . . . . . . . . . . . . . . . . . . . 158

    6 Global Constraints 169Willem-Jan van Hoeve and Irit Katriel

    6.1 Notation and Preliminaries . . . . . . . . . . . . . . . . . . . . . . . . 1706.2 Examples of Global Constraints . . . . . . . . . . . . . . . . . . . . . . 1766.3 Complete Filtering Algorithms . . . . . . . . . . . . . . . . . . . . . . 1826.4 Optimization Constraints . . . . . . . . . . . . . . . . . . . . . . . . . 1896.5 Partial Filtering Algorithms . . . . . . . . . . . . . . . . . . . . . . . . 1936.6 Global Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2006.7 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203

    7 Tractable Structures for Constraint Satisfaction Problems 209Rina Dechter

    7.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2107.2 Structure-Based Tractability in Inference . . . . . . . . . . . . . . . . . 2137.3 Trading Time and Space by Hybrids of Search and Inference . . . . . . 2317.4 Structure-Based Tractability in Search . . . . . . . . . . . . . . . . . . 2397.5 Summary and Bibliographical Notes . . . . . . . . . . . . . . . . . . . 241

    8 The Complexity of Constraint Languages 245David Cohen and Peter Jeavons

    8.1 Basic Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2468.2 Examples of Constraint Languages . . . . . . . . . . . . . . . . . . . . 2478.3 Developing an Algebraic Theory . . . . . . . . . . . . . . . . . . . . . 2518.4 Applications of the Algebraic Theory . . . . . . . . . . . . . . . . . . . 2588.5 Constraint Languages Over an Infinite Set . . . . . . . . . . . . . . . . 2638.6 Multi-Sorted Constraint Languages . . . . . . . . . . . . . . . . . . . . 2648.7 Alternative Approaches . . . . . . . . . . . . . . . . . . . . . . . . . . 269

    Contents

  • xv

    8.8 Future Directions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274

    9 Soft Constraints 281Pedro Meseguer, Francesca Rossi, Thomas Schiex

    9.1 Background: Classical Constraints . . . . . . . . . . . . . . . . . . . . 2829.2 Specific Frameworks . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2839.3 Generic Frameworks . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2879.4 Relations among Soft Constraint Frameworks . . . . . . . . . . . . . . 2919.5 Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2979.6 Inference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3009.7 Combining Search and Inference . . . . . . . . . . . . . . . . . . . . . 3139.8 Using Soft Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . 3169.9 Promising Directions for Further Research . . . . . . . . . . . . . . . . 321

    10 Symmetry in Constraint Programming 329Ian P. Gent, Karen E. Petrie, Jean-Francois Puget

    10.1 Symmetries and Group Theory . . . . . . . . . . . . . . . . . . . . . . 33110.2 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33710.3 Reformulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34010.4 Adding Constraints Before Search . . . . . . . . . . . . . . . . . . . . 34310.5 Dynamic Symmetry Breaking Methods . . . . . . . . . . . . . . . . . . 35010.6 Combinations of Symmetry Breaking Methods . . . . . . . . . . . . . . 36210.7 Successful Applications . . . . . . . . . . . . . . . . . . . . . . . . . . 36310.8 Symmetry Expression and Detection . . . . . . . . . . . . . . . . . . . 36410.9 Further Research Themes . . . . . . . . . . . . . . . . . . . . . . . . . 36610.10 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368

    11 Modelling 377Barbara M. Smith

    11.1 Preliminaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37811.2 Representing a Problem . . . . . . . . . . . . . . . . . . . . . . . . . . 37911.3 Propagation and Search . . . . . . . . . . . . . . . . . . . . . . . . . . 37911.4 Viewpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38111.5 Expressing the Constraints . . . . . . . . . . . . . . . . . . . . . . . . 38211.6 Auxiliary Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38611.7 Implied Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38711.8 Reformulations of CSPs . . . . . . . . . . . . . . . . . . . . . . . . . . 39111.9 Combining Viewpoints . . . . . . . . . . . . . . . . . . . . . . . . . . 39411.10 Symmetry and Modelling . . . . . . . . . . . . . . . . . . . . . . . . . 39811.11 Optimization Problems . . . . . . . . . . . . . . . . . . . . . . . . . . 40011.12 Supporting Modelling and Reformulation . . . . . . . . . . . . . . . . . 401

    II Extensions, Languages, and Applications 407

    12 Constraint Logic Programming 409Kim Marriott, Peter J. Stuckey, Mark Wallace

    Contents

  • xvi

    12.1 History of CLP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41112.2 Semantics of Constraint Logic Programs . . . . . . . . . . . . . . . . . 41312.3 CLP for Conceptual Modeling . . . . . . . . . . . . . . . . . . . . . . . 42512.4 CLP for Design Modeling . . . . . . . . . . . . . . . . . . . . . . . . . 43012.5 Search in CLP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43712.6 Impact of CLP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44212.7 Future of CLP and Interesting Research Questions . . . . . . . . . . . . 444

    13 Constraints in Procedural and Concurrent Languages 453Thom Fruhwirth, Laurent Michel, and Christian Schulte

    13.1 Procedural and Object-Oriented Languages . . . . . . . . . . . . . . . . 45413.2 Concurrent Constraint Programming . . . . . . . . . . . . . . . . . . . 46513.3 Rule-Based Languages . . . . . . . . . . . . . . . . . . . . . . . . . . 47313.4 Challenges and Opportunities . . . . . . . . . . . . . . . . . . . . . . . 48513.5 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486

    14 Finite Domain Constraint Programming Systems 495Christian Schulte and Mats Carlsson

    14.1 Architecture for Constraint Programming Systems . . . . . . . . . . . . 49614.2 Implementing Constraint Propagation . . . . . . . . . . . . . . . . . . . 50614.3 Implementing Search . . . . . . . . . . . . . . . . . . . . . . . . . . . 51314.4 Systems Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51714.5 Outlook . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519

    15 Operations Research Methods in Constraint Programming 527John N. Hooker

    15.1 Schemes for Incorporating OR into CP . . . . . . . . . . . . . . . . . . 52715.2 Plan of the Chapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52815.3 Linear Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53015.4 Mixed Integer/Linear Modeling . . . . . . . . . . . . . . . . . . . . . . 53415.5 Cutting Planes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53615.6 Relaxation of Global Constraints . . . . . . . . . . . . . . . . . . . . . 53915.7 Relaxation of Piecewise Linear and Disjunctive Constraints . . . . . . . 54515.8 Lagrangean Relaxation . . . . . . . . . . . . . . . . . . . . . . . . . . 54715.9 Dynamic Programming . . . . . . . . . . . . . . . . . . . . . . . . . . 55015.10 Branch-and-Price Methods . . . . . . . . . . . . . . . . . . . . . . . . 55415.11 Benders Decomposition . . . . . . . . . . . . . . . . . . . . . . . . . . 55615.12 Toward Integration of CP and OR . . . . . . . . . . . . . . . . . . . . . 560

    16 Continuous and Interval Constraints 571Frederic Benhamou and Laurent Granvilliers

    16.1 From Discrete to Continuous Constraints . . . . . . . . . . . . . . . . . 57416.2 The Branch-and-Reduce Framework . . . . . . . . . . . . . . . . . . . 57516.3 Consistency Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . 57716.4 Numerical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58316.5 Hybrid Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58716.6 First Order Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . 590

    Contents

  • xvii

    16.7 Applications and Software packages . . . . . . . . . . . . . . . . . . . 59316.8 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 595

    17 Constraints over Structured Domains 605Carmen Gervet

    17.1 History and Applications . . . . . . . . . . . . . . . . . . . . . . . . . 60617.2 Constraints over Regular and Constructed Sets . . . . . . . . . . . . . . 60917.3 Constraints over Finite Set Intervals . . . . . . . . . . . . . . . . . . . . 61317.4 Influential Extensions to Subset Bound Solvers . . . . . . . . . . . . . . 61917.5 Constraints over Maps, Relations and Graphs . . . . . . . . . . . . . . . 62817.6 Constraints over Lattices and Hierarchical Trees . . . . . . . . . . . . . 63117.7 Implementation Aspects . . . . . . . . . . . . . . . . . . . . . . . . . . 63117.8 Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63317.9 Further Topics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 633

    18 Randomness and Structure 639Carla Gomes and Toby Walsh

    18.1 Random Constraint Satisfaction . . . . . . . . . . . . . . . . . . . . . . 64018.2 Random Satisfiability . . . . . . . . . . . . . . . . . . . . . . . . . . . 64418.3 Random Problems with Structure . . . . . . . . . . . . . . . . . . . . . 64818.4 Runtime Variability . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65118.5 History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65718.6 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 658

    19 Temporal CSPs 665Manolis Koubarakis

    19.1 Preliminaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66619.2 Constraint-Based Formalisms for Reasoning About Time . . . . . . . . 66919.3 Efficient Algorithms for Temporal CSPs . . . . . . . . . . . . . . . . . 67719.4 More Expressive Queries for Temporal CSPs . . . . . . . . . . . . . . . 68119.5 First-Order Temporal Constraint Languages . . . . . . . . . . . . . . . 68319.6 The Scheme of Indefinite Constraint Databases . . . . . . . . . . . . . . 68519.7 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 691

    20 Distributed Constraint Programming 699Boi Faltings

    20.1 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70120.2 Distributed Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70220.3 Improvements and Variants . . . . . . . . . . . . . . . . . . . . . . . . 71320.4 Distributed Local Search . . . . . . . . . . . . . . . . . . . . . . . . . 71820.5 Open Constraint Programming . . . . . . . . . . . . . . . . . . . . . . 72120.6 Further Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72420.7 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 726

    Contents

  • xviii

    21 Uncertainty and Change 731Kenneth N. Brown and Ian Miguel

    21.1 Background and Definitions . . . . . . . . . . . . . . . . . . . . . . . . 73221.2 Example: Course Scheduling . . . . . . . . . . . . . . . . . . . . . . . 73221.3 Uncertain Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73321.4 Problems that Change . . . . . . . . . . . . . . . . . . . . . . . . . . . 73821.5 Pseudo-dynamic Formalisms . . . . . . . . . . . . . . . . . . . . . . . 75221.6 Challenges and Future Trends . . . . . . . . . . . . . . . . . . . . . . . 75321.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 755

    22 Constraint-Based Scheduling and Planning 761Philippe Baptiste, Philippe Laborie, Claude Le Pape, Wim Nuijten

    22.1 Constraint Programming Models for Scheduling . . . . . . . . . . . . . 76322.2 Constraint Programming Models for Planning . . . . . . . . . . . . . . 77122.3 Constraint Propagation for Resource Constraints . . . . . . . . . . . . . 77822.4 Constraint Propagation on Optimization Criteria . . . . . . . . . . . . . 78522.5 Heuristic Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78922.6 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 794

    23 Vehicle Routing 801Philip Kilby and Paul Shaw

    23.1 The Vehicle Routing Problem . . . . . . . . . . . . . . . . . . . . . . . 80223.2 Operations Research Approaches . . . . . . . . . . . . . . . . . . . . . 80423.3 Constraint Programming Approaches . . . . . . . . . . . . . . . . . . . 80923.4 Constraint Programming in Search . . . . . . . . . . . . . . . . . . . . 81923.5 Using Constraint Programming as a Subproblem Solver . . . . . . . . . 82323.6 CP-VRP in the Real World . . . . . . . . . . . . . . . . . . . . . . . . 82523.7 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 828

    24 Configuration 837Ulrich Junker

    24.1 What Is Configuration? . . . . . . . . . . . . . . . . . . . . . . . . . . 83824.2 Configuration Knowledge . . . . . . . . . . . . . . . . . . . . . . . . . 84424.3 Constraint Models for Configuration . . . . . . . . . . . . . . . . . . . 85324.4 Problem Solving for Configuration . . . . . . . . . . . . . . . . . . . . 86324.5 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 868

    25 Constraint Applications in Networks 875Helmut Simonis

    25.1 Electricity Networks . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87625.2 Water (Oil) Networks . . . . . . . . . . . . . . . . . . . . . . . . . . . 87825.3 Data Networks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87925.4 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 898

    Contents

  • xix

    26 Bioinformatics and Constraints 905Rolf Backofen and David Gilbert

    26.1 What Biologists Want from Bioinformatics . . . . . . . . . . . . . . . . 90626.2 The Central Dogma . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90726.3 A Classification of Problem Areas . . . . . . . . . . . . . . . . . . . . 90826.4 Sequence Related Problems . . . . . . . . . . . . . . . . . . . . . . . . 90826.5 Structure Related Problems . . . . . . . . . . . . . . . . . . . . . . . . 92226.6 Function Related Problems . . . . . . . . . . . . . . . . . . . . . . . . 93526.7 Microarrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 937

    Index 945

    Contents

  • This page intentionally left blank

  • Part I

    Foundations

  • This page intentionally left blank

  • Handbook of Constraint Programming 3Edited by F. Rossi, P. van Beek and T. Walshc 2006 Elsevier B.V. All rights reserved

    Chapter 1

    Introduction

    Francesca Rossi, Peter van Beek, Toby Walsh

    Constraint programming is a powerful paradigm for solving combinatorial search problemsthat draws on a wide range of techniques from artificial intelligence, computer science,databases, programming languages, and operations research. Constraint programming iscurrently applied with success to many domains, such as scheduling, planning, vehiclerouting, configuration, networks, and bioinformatics. The basic idea in constraint pro-gramming is that the user states the constraints and a general purpose constraint solver isused to solve them. Constraints are just relations, and a constraint satisfaction problem(CSP) states which relations should hold among the given decision variables. For exam-ple, in scheduling activities in a company, the decision variables might be the starting timesand the durations of the activities and the resources needed to perform them, and the con-straints might be on the availability of the resources and on their use for a limited numberof activities at a time.

    Constraint solvers take a real-world problem like this, represented in terms of deci-sion variables and constraints, and find an assignment to all the variables that satisfiesthe constraints. Constraint solvers search the solution space either systematically, as withbacktracking or branch and bound algorithms, or use forms of local search which maybe incomplete. Systematic method often interleave search and inference, where inferenceconsists of propagating the information contained in one constraint to the neighboringconstraints. Such inference (usually called constraint propagation) is useful since it mayreduce the parts of the search space that need to be visited.

    While defining a set of constraints may seem a simple way to model a real-world prob-lem, finding a good model that works well with a chosen solver is not always easy. A poorlychosen model may be very hard to solve. Thus much care must be devoted to choosing agood model and also to devising solvers that can exploit the features of the chosen model.

    From this description it may seem that constraint programming is programming inthe sense of mathematical programming: the user declaratively states the constraintson the feasible solutions for a set of decision variables, and an underlying solver solvesthe constraints. However, constraint programming is also programming in the sense ofcomputer programming: the user needs to program a strategy to search for a solution.

  • 4 1. Introduction

    Without this, the solving process would be very inefficient. This is very natural to do inlogic-based programming languages, such as constraint logic programming, but it can alsobe done in other programming paradigms.

    1.1 Purpose of the Handbook

    The aim of this handbook is to capture the full breadth and depth of the constraint pro-gramming field and to be encyclopedic in its scope and coverage. While there are excellentbooks on constraint programming (see, for example, [1, 2, 3, 4, 5, 6, 7, 8]), such booksnecessarily focus on the main notions and techniques and cannot cover also extensions,applications, and languages. The handbook gives a reasonably complete coverage of allthese lines of work, based on constraint programming, so that a reader can have a ratherprecise idea of the whole field and its potential. Of course each line of work is dealt within a survey-like style, where some details may be neglected in favor of broader coverage.However, the extensive bibliography of each chapter will help the interested readers to findsuitable sources for the missing details. Each chapter of the handbook is intended to bea self-contained survey of a topic, and is written by one or more authors who are leadingresearchers in the area.

    The intended audience of the handbook is researchers, graduate students, upper-yearundergraduates, and practitioners who wish to learn about the state-of-the-art in constraintprogramming. No prior knowledge about the field is necessary to be able to read thechapters and gather useful knowledge. Researchers from other fields should find in thishandbook an effective way to learn about constraint programming and to possibly use someof the constraint programming concepts and techniques in their own work, thus providinga means for a fruitful cross-fertilization among different research areas.

    1.2 Structure and Content

    The handbook is organized in two parts. The first part covers the basic foundations ofconstraint programming, including the history, the notion of constraint propagation, basicsearch methods, global constraints, tractability and computational complexity, and impor-tant issues in modeling a problem as a constraint problem. The second part covers con-straint languages and solver, several useful extensions to the basic framework (such asinterval constraints, structured domains, and distributed CSPs), and successful applicationareas for constraint programming.

    Part I: Foundations

    In Chapter 2, Eugene C. Freuder and Alan K. Mackworth survey the emergence of con-straint satisfaction as a new paradigm within artificial intelligence and computer science.Covering the two decades from 1965 to 1985, Freuder and Mackworth trace the devel-opment of two streams of work, which they call the language stream and the algorithmstream. The focus of the language stream was on declarative program languages and sys-tems for developing applications of constraints. The language stream gave many specialpurpose declarative languages and also general programming languages such as constraintlogic programming. The focus of the algorithm stream was on algorithms and heuristics

  • F. Rossi, P. van Beek, T. Walsh 5

    for the constraint satisfaction framework. The algorithm stream gave constraint propa-gation algorithms such as algorithms for arc consistency and also heuristics and constraintpropagation within backtracking search. Ultimately, the language stream and the algorithmstream merged to form the core of the new field of constraint programming.

    In Chapter 3, Christian Bessiere surveys the extensive literature on constraint propa-gation. Constraint propagation is a central conceptperhaps the central conceptin thetheory and practice of constraint programming. Constraint propagation is a form of reason-ing in which, from a subset of the constraints and the domains, more restrictive constraintsor more restrictive domains are inferred. The inferences are justified by local consistencyproperties that characterize necessary conditions on values or set of values to belong toa solution. Arc consistency is currently the most important local consistency property inpractice and has received the most attention in the literature. The importance of constraintpropagation is that it can greatly simplify a constraint problem and so improve the effi-ciency of a search for a solution.

    The main algorithmic techniques for solving constraint satisfaction problems (CSPs)are backtracking search and local search. In Chapter 4, Peter van Beek surveys backtrack-ing search algorithms. A backtracking search algorithm performs a depth-first traversalof a search tree, where the branches out of a node represent alternative choices that mayhave to be examined in order to find a solution, and the constraints are used to prune sub-trees containing no solutions. Backtracking search algorithms come with a guarantee thata solution will be found if one exists, and can be used to show that a CSP does not havea solution or to find a provably optimal solution. Many techniques for improving the ef-ficiency of a backtracking search algorithm have been suggested and evaluated includingconstraint propagation, nogood recording, backjumping, heuristics for variable and valueordering, and randomization and restart strategies.

    In Chapter 5, Holger H. Hoos and Edward Tsang survey local search algorithms forsolving constraint satisfaction problems. A local search algorithm performs a walk in adirected graph, where the nodes represent alternative assignments to the variables that mayhave to be examined and the number of violated constraints is used to guide the search fora solution. Local search algorithms cannot be used to show that a CSP does not have a so-lution or to find a provably optimal solution. However, such algorithms are often effectiveat finding a solution if one exists and can be used to find an approximation to an optimalsolution. Many techniques and strategies for improving local search algorithms have beenproposed and evaluated including randomized iterative improvement, tabu search, penalty-based approaches, and alternative neighborhood and move strategies.

    In Chapter 6, Willem-Jan van Hoeve and Irit Katriel survey global constraints. A globalconstraint is a constraint that can be over arbitrary subsets of the variables. The canonicalexample of a global constraint is the all-different constraint which states that thevariables in the constraint must be pairwise different. The power of global constraints istwo-fold. First, global constraints ease the task of modeling an application using constraintprogramming. The all-different constraint, for example, is a pattern that reoccursin many applications, including rostering, timetabling, sequencing, and scheduling appli-cations. Second, special purpose constraint propagation algorithms can be designed whichtake advantage of the semantics of the constraint and are therefore much more efficient.Van Hoeve and Katriel show that designing constraint propagation algorithms for globalconstraints draws on a wide variety of disciplines including graph theory, flow theory,matching theory, linear programming, and finite automaton.

  • 6 1. Introduction

    A fundamental challenge in constraint programming is to understand the computationalcomplexity of problems involving constraints. In their most general form, constraint satis-faction problems (CSPs) are NP-Hard. To counter this pessimistic result, much work hasbeen done on identifying restrictions on constraint satisfaction problems such that solvingan instance can be done efficiently; that is, in polynomial time in the worst-case. Findingtractable classes of constraint problems is of theoretical interest of course, but also of prac-tical interest in the design of constraint programming languages and effective constraintsolvers. The restrictions on CSPs that lead to tractability fall into two classes: restrict-ing the topology of the underlying graph of the CSP and restricting the type of the allowedconstraints. In Chapter 7, Rina Dechter surveys how the complexity of solving CSPs varieswith the topology of the underlying constraint graph. The results depend on properties ofthe constraint graph, such as the well-known graph parameter tree-width. In Chapter 8,David Cohen and Peter Jeavons survey how the complexity of solving CSPs varies withthe type of allowed constraints. Here, the results depend on algebraic properties of theconstraint relations.

    The first part ends with three chapters concerned with modeling real world problemsas CSPs. In many real world problems, not all constraints are hard. Some constraint maybe soft and express preferences that we would like to satisfy but do not insist upon.Other real world problems may be over-constrained. In both cases, an extension of thebasic framework of constraint satisfaction to soft constraints is useful. In Chapter 9, PedroMeseguer, Francesca Rossi, and Thomas Schiex survey the different formalisms of softconstraints proposed in the literature. They describe the relationship between these differ-ent formalisms. In addition, they discuss how solving methods have been generalized todeal with soft constraints.

    Symmetry occurs in many real world problems: machines in a factory might be iden-tical, nurses might have the same skills, delivery trucks might have the same capacity, etc.Symmetry can also be introduced when we model a problem as a CSP. For example, ifwe introduce a decision variable for each machine, then we can permute those variablesrepresenting identical machines. Such symmetry enlarges the search space and must bedealt with if we are to solve problems of the size met in practice. In Chapter 10, Ian P.Gent, Karen E. Petrie, and Jean-Francois Puget survey the different forms of symmetryin constraint programming. They describe the three basic techniques used to deal withsymmetry: reformulating the problem, adding symmetry breaking constraints, and mod-ifying the search strategy to ignore symmetric states. Symmetry is one example of thesort of issues that need to be considered when modeling a problem as a CSP. In Chapter11, Barbara M. Smith surveys a range of other issues in modeling a problem as a CSP.This includes deciding on an appropriate viewpoint (e.g. if we are scheduling exams, dothe variables represent exams and their values the times, or do the variables represent thetimes and their values the exams?), adding implied constraints to help prune the searchspace, and introducing auxiliary variables to make it easier to state the constraints or toimprove propagation.

    Part II: Extensions, Languages, and Applications

    To increase the uptake, ease of use, extensibility, and flexibility of constraint technology,constraints and search have been integrated into several programming languages and pro-gramming paradigms. In Chapter 12, Kim Marriott, Peter J. Stuckey, and Mark Wallace

  • F. Rossi, P. van Beek, T. Walsh 7

    survey constraint logic programming (CLP), the integration of constraint solving into logicprogramming languages. Constraint solving and logic programming are both declarativeparadigms, so their integration is quite natural. Further, the fact that constraints can be seenas relations or predicates, that a set of constraints can be viewed as the conjunction of theindividual constraints, and that backtracking search is a basic methodology for solving a setof constraints, makes constraint solving very compatible with logic programming, whichis based on predicates, logical conjunctions, and backtracking search. Marriott, Stuckey,and Wallace cover the elegant semantics of CLP, show the power of CLP in modeling con-straint satisfaction problems, and describe how to define specific search routines in CLPfor solving the modeled problem.

    In Chapter 13, Thom Fruhwirth, Laurent Michel, and Christian Schulte survey the inte-gration of constraints into procedural and object-oriented languages, concurrent languages,and rule-based languages. Integrating constraint solving into these more traditional pro-gramming paradigms faces new challenges as these paradigms generally lack support fordeclarative programming. These challenges include (i) allowing the specification of newsearch routines, while maintaining declarativeness, (ii) the design of declarative model-ing languages that are user-friendly and based on well-known programming metaphors,and (iii) the integration of constraint solving into multi-paradigm languages. Fruhwirth,Michel, and Schulte include a discussion of the technical aspects of integrating constraintsinto each programming paradigm, as well as the advantages and disadvantages of eachparadigm.

    In Chapter 14, Christian Schulte and Mats Carlsson survey finite domain constraintprogramming systems. One of the key properties of constraint programming systems isthe provision of widely reusable servicessuch as constraint propagation and backtrack-ing searchfor constructing constraint-based applications. Schulte and Carlsson discusswhich services are provided by constraint programming systems and also the key principlesand techniques in implementing and coordinating these services. For many applications,the constraint propagation, backtracking search, and other services provided by the con-straint programming system are sufficient. However, some applications require more, andmost constraint programming systems are extensible, allowing the user to define, for exam-ple, new constraint propagators or new search strategies. Schulte and Carlsson also providean overview of several well-known finite domain constraint programming systems.

    Operations research (OR) and constraint programming (CP) are complementary frame-works with similar goals. In Chapter 15, John N. Hooker surveys some of the schemes forincorporating OR methods into CP. In constraint programming, constraints are used toreduce the domains of the variables. One method for incorporating an OR method is toapply it to a constraint to reduce the domains. For example, if a subset of the constraintsare linear inequalities, the domain of a variable in the subset can possibly be reduced byminimizing and maximizing the variable using linear programming on the subset of linearconstraints. This example is an instance of a popular scheme for incorporating OR into CP:create a relaxation of the CP problem in the form of an OR model, such as a linear pro-gramming model. Other schemes for creating hybrid OR/CP combinations decompose aproblem so that CP and OR are each used on the parts of the problem to which they are bestsuited. Hooker shows that OR/CP combinations using both relaxation and decompositioncan bring substantial computational benefits.

    Real-world problems often take us beyond finite domain variables. For example, toreason about power consumption, we might want a variable to range over the reals and

  • 8 1. Introduction

    to reason about communication networks we might want a variable to range over pathsin a graph. Constraint programming has therefore been extended to deal with more thanjust finite (or enumerated) domains of values. In Chapter 16, Frederic Benhamou and Lau-rent Granvilliers survey constraints over continuous and interval domains. The extension ofbacktracking search over finite domains to interval constraints is called branch-and-reduce:branching splits an interval and reduce narrows the intervals using a generalization of localconsistency and interval arithmetic. Hybrid techniques combining symbolic reasoning andconstraint propagation have also been designed. Benhamou and Granvilliers also discusssome of the applications of interval constraints and the available interval constraint soft-ware packages. In Chapter 17, Carmen Gervet surveys constraints over structured domains.Many combinatorial search problemssuch as bin packing, set covering, and networkdesigncan be naturally represented in the language of sets, multi-sets, strings, graphsand other structured objects. Constraint propagation has therefore been extended to dealwith constraints over variables which range over such datatypes.

    Early work in empirical comparisons of algorithms for solving constraint satisfactionproblems was hampered by a lack of realistic or hard test problems. The situation im-proved with the discovery of hard random problems that arise at a phase transition andthe investigation of alternative random models of constraint satisfaction, satisfiability, andoptimization problems. Experiments could now be performed which compared the algo-rithms on the hardest problems and systematically explored the entire space of randomproblems to see where one algorithm bettered another. In Chapter 18, Carla Gomes andToby Walsh survey these alternative random models. In addition to their interest as anexperimental testbed, insight gained from the study of hard problems has also led to thedesign of better algorithms. As one example, Gomes and Walsh discuss the technique ofrandomization and restarts for improving the efficiency of backtracking search algorithms.

    In Chapter 19, Manolis Koubarakis surveys temporal constraint satisfaction problemsfor representing and reasoning with temporal information. Temporal reasoning is impor-tant in many application areasincluding natural language understanding, database sys-tems, medical information systems, planning, and schedulingand constraint satisfactiontechniques play a large role in temporal reasoning. Constraint-based temporal reasoningformalisms for representing qualitative, metric, and combined qualitative-metric temporalinformation have been proposed in the literature and many efficient constraint satisfactionalgorithms are known for these formalisms. Koubarakis also demonstrates the application-driven need for more expressive queries over temporal constraint satisfaction (especiallyqueries combining temporal and non-temporal information) and surveys various proposalsthat address this need including the scheme of indefinite constraint databases.

    In Chapter 20, Boi Faltings surveys distributed constraint satisfaction. In distributedconstraint satisfaction, constraint solving happens under the control of different indepen-dent agents, where each agent controls a single variable. The canonical example of theusefulness of this formalism is meeting scheduling, where each person has their own con-straints and there are privacy concerns that restrict the flow of information, but many ap-plications have been identified. Backtracking search and its improvements have been ex-tended to the distributed case. In synchronous backtracking, messages are passed fromagent to agent with only one agent being active at any one time. A message consists of ei-ther a partial instantiation or a message that signals the need to backtrack. In asynchronousbacktracking, all agents are active at once, and messages are sent to coordinate their the as-signments that are made to their individual variables. Asynchronous backtracking has been

  • F. Rossi, P. van Beek, T. Walsh 9

    the focus of most of the work in distributed constraint satisfaction. Faltings also surveysthe literature on open constraint satisfaction, a form of distributed CSP where the domainsof the variables and the constraints may be incomplete or not fully known.

    The basic framework of constraint programming makes two assumptions that do nothold in many real world problems: that the problem being modeled is static and that theconstraints are known with certainty. For example, factory scheduling is inherently dy-namic and uncertain since the full set of jobs may not be known in advance, machines maybreak down, employees may be late or ill, and so on. In Chapter 21, Kenneth N. Brown andIan Miguel survey the uses and extensions of constraint programming for handling prob-lems subject to change and uncertainty. For dynamically changing problems, two of thealternatives are to record information about the problem structure during the solving pro-cess, such as explanation or nogood recording, so that re-solving can be done efficiently;and to search for robust or solutions that anticipate expected changes. For uncertain prob-lems, different types of uncertainty can be identified including: the problem itself is intrin-sically imprecise; there is a set of possible realizations of the problem, one of which willbe the final version, and there are probability distributions over the full realizations. Aswell, many CSP formalisms have been proposed for handling uncertainty including fuzzy,mixed, uncertain, probabilistic, stochastic, and recurrent CSPs.

    Constraint programming has proven usefulindeed, it is often the method of choicein important applications from industry, business, manufacturing, and science. In the lastfive chapters of the handbook, some of these applications of constraint programming arehighlighted. Each of the chapters emphasizes why constraint programming has been suc-cessful in the given application domain. As well, in the best traditions of application-driven research, the chapters describe how focusing on real-world applications has led tobasic discoveries and improvements to existing constraint programming techniques. In afruitful cycle, these discoveries and improvements then led to new and more successfulapplications.

    In Chapter 22, Philippe Baptiste, Philippe Laborie, Claude Le Pape, and Wim Nuijtensurvey constraint programming approaches to scheduling and planning. Scheduling is thetask of assigning resources to a set of activities to minimize a cost function. Schedulingarises in diverse settings including in the allocation of gates to incoming planes at an air-port, crews to an assembly line, and processes to a CPU. Planning is a generalization ofscheduling where the set of activities to be scheduled is not known in advance. Constraintprogramming approaches to scheduling and planning have aimed at generality, with theability to seamlessly handle real-world side constraints. As well, much effort has goneinto improved implied constraints such as global constraints, edge-finding constraints andtimetabling constraints, which lead to powerful constraint propagation. Baptiste et al. showthat one of the reasons for the success of a constraint programming approach is its abilityto integrate efficient special purpose algorithms within a flexible and expressive paradigm.Additional advantages of a constraint propagation approach include the ability to formhybrids of backtracking search and local search and the ease with which domain specificscheduling and planning heuristics can be incorporated within the search routines.

    In Chapter 23, Philip Kilby and Paul Shaw survey constraint programming approachesto vehicle routing. Vehicle Routing is the task of constructing routes for vehicles to visitcustomers at minimum cost. A vehicle has a maximum capacity which cannot be exceededand the customers may specify time windows in which deliveries are permitted. Muchwork on constraint programming approaches to vehicle routing has focused on alternative

  • 10 1. Introduction

    constraint models and additional implied constraints to increase the amount of pruningperformed by constraint propagation. Kilby and Shaw show that constraint programmingis well-suited for vehicle routing because of its ability to handle real-world (or side) con-straints. Vehicle routing problems that arise in practice often have unique constraints thatare particular to a business entity. In non-constraint programming approaches, such sideconstraints often have to be handled in an ad hoc manner. In constraint programming awide variety of side constraints can be handled simply by adding them to the core model.

    In Chapter 24, Ulrich Junker surveys constraint programming approaches to configu-ration. Configuration is the task of assembling or configuring a customized system from acatalog of components. Configuration arises in diverse settings including in the assemblyof home entertainment systems, cars and trucks, and travel packages. Junker shows thatconstraint programming is well-suited to configuration because of (i) its flexibility in mod-eling and the declarativeness of the constraint model, (ii) the ability to explain a failureto find a customized system when the configuration task is over-constrained and to sub-sequently relax the users constraints, (iii) the ability to perform interactive configurationwhere the user makes a sequence of choices and after each choice constraint propagation isused to restrict future possible choices, and (iv) the ability to incorporate reasoning aboutthe users preferences.

    In Chapter 25, Helmut Simonis surveys constraint programming approaches to applica-tions that arise in electrical, water, oil, and data (such as the Internet) distribution networks.The applications include design, risk analysis, and operational control of the networks.Simonis discusses the best alternative formulations or constraint models for these prob-lems. The constraint programming work on networks vividly illustrates the advantagesof application-driven research. The limited success in this domain of classical constraintprogramming approaches, such as backtracking search, led to improvements in hybrid ap-proaches which combine both backtracking and local search or combine both constraintprogramming and operations research methods. A research hurdle that must still be over-come, however, is the complexity and implementation effort that is required to construct asuccessful hybrid system for an application.

    In Chapter 26, Rolf Backofen and David Gilbert survey constraint programming ap-proaches to problems that arise in bioinformatics. Bioinformatics is the study of infor-matics and computational problems that arise in molecular biology, evolution, and genet-ics. Perhaps the first and most well-known example problem in bioinformatics is DNAsequence alignment. More recently, constraint programming approaches have made sig-nificant progress on the important problem of protein structure prediction. The ultimategoals and implications of bioinformatics are profound: better drug design, identification ofgenetic risk factors, gene therapy, and genetic modification of food crops and animals.

    1.3 Future Research

    The field of constraint programming is rapidly progressing. Many new research resultsare being published and new research areas are being opened in the field of constraintreasoning. We conclude this introduction with some speculation on lines of research thatappear interesting and promising to us, and that in the future could be mature enough toconstitute entire chapters in future revisions of this handbook.

  • F. Rossi, P. van Beek, T. Walsh 11

    Quantified constraint problems are a very interesting extension of classical CSPs wheresome variables may be universally quantified. This can help modeling scenarios whereuncertainty does not allow us to decide the values for some variables. Many theoreticalresults on the complexity of such problems have already been developed. We envision afast growth of this area and its applications.

    When using a constraint solver, often it is not easy to understand what went wrong, orwhy a certain solution is returned rather than another one. Explanation tools could greatlyhelp in making constraint technology easy to use in an interactive system. In general, userinteraction in constraint systems deserves much attention and effort. Improvements in thisrespect could greatly widen the usability of constraint-based tools.

    It is rare that all constraints are collected at the same time from the user of a constraintsystem. Usually such constraints, or preferences, are collected some at a time, but thesystem must be able to perform some amount of reasoning also with partial knowledge.Moreover, based on the partial knowledge it has, it should be able to ask the user only forthose constraints or preferences that are useful to make the next inference. The issue ofpreference elicitation is crucial in such situations, and allows users to intelligently interactwith a constraint system without being forced to state all their constraints, or preferences,at the beginning of the interaction. This can also be useful in scenarios where the userswant to avoid revealing all their preferences, for example for privacy reasons.

    Even when the user is willing to state all the information at the beginning of the inter-action, sometimes it may be difficult for him to actually state it in terms of constraints. Forexample, it could be easier to state examples of desirable or unacceptable solutions. In thiscases, machine learning techniques can be helpful to learn the constraints from the partialand possibly imprecise user statements. As for explanation and preference elicitation, thiscan greatly help in easing the interaction between users and constraint solvers.

    Satisfiability is a mature research area with much interaction with constraint reasoning,since a satisfiability problem is just a constraint problem with Boolean variables. Thus,many theoretical results can be adapted from one field to the other one. We hope to seemany such results in the future.

    This handbook contains chapters on just some of the main application areas for con-straint programming. Other application fields, which look very promising, are design, con-straint databases, web services, global computing, and security. We hope to see constraintprogramming to be the base of many useful tools for such applications.

    Acknowledgements

    A project like this, which lasted almost two years and involved about sixty people, wouldnot be possible without the support and encouragement of a great many people withinthe constraint programming community. First, we wish to thank the many authors of thechapters within this handbook. Many of them also helped us by reviewing other chapters.Additionally, we would like to thank Claire Bagley, Roman Bartak, Andrei Bulatov, MartinHenz, Andrea Lodi, Michela Milano, Luis Quesada, Francesco Scarcello, Peter Van Roy,and Roland Yap, who reviewed other chapters. Thanks also to Ugo Montanari, a pioneerof constraint programming, who wrote the foreword for the book.

    We also wish to thank Zeger Karssen, originally at Elsevier and now at Atlantic Press,and Bernhard Nebel, one of the editors of the series where this book will appear. They

  • 12 1. Introduction

    have been very enthusiastic about this project since the very first time we described it tothem in the Summer of 2004. Zeger and his assistants have helped us greatly to put theproject together and to smoothly reach a satisfactory agreement on the format and style ofthe book.

    Finally, we also would like to thank Helmut Simonis, who, besides being an author ofthe handbook, provided the very nice cover picture for this handbook. We think his beauti-ful rose can represent very well the spirit of this handbook: the petals are the many authors,who worked together in cooperation to produce what we hope is a book as beautiful as thisrose.

    Bibliography

    [1] K. R. Apt. Principles of Constraint Programming. Cambridge University Press, 2003.[2] R. Dechter. Constraint Processing. Morgan Kaufmann, 2003.[3] F. Fages. Programmation logique par contraintes. Ellipses Marketing, 1998.[4] T. Fruhwirth and S. Abdennadher. Essentials of Constraint Programming. Springer,

    2003.[5] J. Hooker. Logic-Based Methods for Optimization: Combining Optimization and Con-

    straint Satisfaction. Wiley-Interscience, 2000.[6] K. Marriott and P. J. Stuckey. Programming with Constraints. The MIT Press, 1998.[7] E. P. K. Tsang. Foundations of Constraint Satisfaction. Academic Press, 1993.[8] P. Van Hentenryck. Constraint Satisfaction in Logic Programming. MIT Press, 1989.

  • Handbook of Constraint Programming 13Edited by F. Rossi, P. van Beek and T. Walshc 2006 Elsevier B.V. All rights reserved

    Chapter 2

    Constraint Satisfaction:An Emerging Paradigm

    Eugene C. Freuder and Alan K. Mackworth

    This chapter focuses on the emergence of constraint satisfaction, with constraint languages,as a new paradigm within artificial intelligence and computer science during the periodfrom 1965 (when Golomb and Baumert published Backtrack programming [34]) to 1985(when Mackworth and Freuder published The complexity of some polynomial networkconsistency algorithms for constraint satisfaction problems [55]). The rest of this hand-book will cover much of the material introduced here in more detail, as well as, of course,continuing on from 1986 into 2006.

    2.1 The Early Days

    Constraint satisfaction, in its basic form, involves finding a value for each one of a set ofproblem variables where constraints specify that some subsets of values cannot be usedtogether. As a simple example of constraint satisfaction, consider the task of choosingcomponent parts for the assembly of a bicycle, such as the frame, wheels, brakes, sprocketsand chain, that are all mutually compatible.

    Constraint satisfaction, like most fields of artificial intelligence, can be separated into(overlapping) concerns with representation and reasoning. The former can be divided intogeneric and application-specific concerns, the latter into search and inference. While con-straint satisfaction has often been pigeon-holed as a form of search, its real importancelies in its broad representational scope: it can be used effectively to model many otherforms of reasoning (e.g. temporal reasoning) and applied to many problem domains (e.g.scheduling). For this reason, constraint satisfaction problems are sometimes encounteredin application domains that are unaware that an academic community has been studying thesubject for years: one reason for the importance of a handbook such as this. Furthermore,while heuristic search methods are a major concern, the distinguishing feature of constraintsatisfaction as a branch of artificial intelligence is arguably the emphasis on inference, inthe form of constraint propagation, as opposed to search.

  • 14 2. Constraint Satisfaction: An Emerging Paradigm

    Constraint satisfaction problems have been tackled by a dizzying array of methods,from automata theory to ant algorithms, and are a topic of interest in many fields of com-puter science and beyond. These connections add immeasurably to the richness of thesubject, but are largely beyond the scope of this chapter. Here we will focus on the basicmethods involved in the establishment of constraint satisfaction as a branch of artificialintelligence. This new branch of artificial intelligence, together with related work on pro-gramming languages and systems that we can only touch upon here, laid the groundworkfor the flourishing of interest in constraint programming languages after 1985.

    Constraint satisfaction of course, predates 1965. The real world problems that we nowidentify as constraint satisfaction problems, like workforce scheduling, have naturally al-ways been with us. The toy 8-queens problem, which preoccupied so many of the earlyconstraint satisfaction researchers in artificial intelligence, is said to have been proposed in1848 by the chess player Max Bazzel. Mythology claims that a form of backtrack search,a powerful search paradigm that has become a central tool for constraint satisfaction, wasused by Theseus in the labyrinth in Crete. Backtrack search was used in recreational math-ematics in the nineteenth century [51], and was an early subject of study as computerscience and operations research emerged as academic disciplines after World War II. Bit-ner and Reingold [2] credit Lehmer with first using the term backtrack in the 1950s [50].Various forms of constraint satisfaction and propagation appeared in the computer scienceliterature in the 1960s [16, 15, 34, 75].

    In artificial intelligence interest in constraint satisfaction developed in two streams. Insome sense a common ancestor of both streams is Ivan Sutherlands groundbreaking 1963MIT Ph.D. thesis, Sketchpad: A man-machine graphical communication system [73].

    In one stream, the versatility of constraints led to applications in a variety of domains,and associated programming languages and systems. This stream we can call the languagestream. In 1964 Wilkes proposed that algebraic equations be allowed as constraint state-ments in procedural Algol-like programming languages, with relaxation used to satisfy theconstraints [80]. Around 1967, Elcock developed a declarative language, Absys, based onthe manipulation of equational constraints [22]. Burstall employed a form of constraintmanipulation as early as 1969 in a program for solving cryptarithmetic puzzles [9]. In thevery first issue of Artificial Intelligence in 1970, Fikes described REF-ARF, where the REFlanguage formed part of a general problem-solving system employing constraint satisfac-tion and propagation as one of its methods [23]. Kowalski used a form of constraint prop-agation for theorem proving [48]. Sussman and others at MIT applied a form of constraintpropagation to analysis, synthesis and fault localization for circuits [6, 17, 18, 67, 71], andSussman with Steele developed the CONSTRAINTS language [72]. Borning used con-straints in his ThingLab simulation laboratory [4, 5], whose kernel was an extension of theSmalltalk language; Lauriere used constraints in Alice, a language for solving combina-torial problems [49]. In the planning domain, Eastman did constraint structured spaceplanning with GSP, the General Space Planner [21], Stefik used constraint posting inMOLGEN, which planned gene-cloning experiments in molecular genetics [68, 69], andDescotte and Latombes GARI system, which generated the machining plans of mechani-cal parts, embedded a planner which made compromises among antagonistic constraints[20]. Fox, Allen and Strohm developed ISIS-II [25] a constraint-directed reasoning systemfor factory job-shop scheduling.

    In the other stream, an interest in constraint solving algorithms grew out of the ma-chine vision community; we cite some of the early work here. We refer to this stream as

  • E. C. Freuder, A. K. Mackworth 15

    the algorithm stream. The landmark Waltz filtering (arc consistency) constraint propa-gation algorithm appeared in a Ph.D. thesis on scene labeling [79], building upon workof Huffman [41] and Clowes [10]. Montanari developed path consistency and establisheda general framework for representing and reasoning about constraints in a seminal paperentitled Networks of constraints: fundamental properties and applications to picture pro-cessing [60]. Mackworth exploited constraints for machine vision [52], before providinga general framework for Consistency in networks of relations and new algorithms for arcand path consistency [53]. Freuder generalized arc and path consistency to k-consistency[26] shortly after completing a Ph.D. thesis on active vision. Barrow and Tenenbaum,with MSYS [1] and IGS [74], were also early users of constraints for image interpretation.Rosenfeld, Hummel and Zucker, in Scene labeling by relaxation operations, explored thecontinuous labeling problem, where constraints are not hard, specifying that values canor cannot be used together, but soft specifying degrees of compatibility [65]. Haralick,Davis, Rosenfeld and Milgram discussed Reduction operations for constraint satisfaction[38], and Haralick and Shapiro generalized those results in a two-part paper on The con-sistent labeling problem [36, 37]. Together with J. R. Ullman, they even discussed specialhardware for constraint propagation and parallel search computation in [76].

    The language and algorithm streams diverged, and both became more detached fromspecific application domains. While applications and commercial exploitation did prolif-erate, the academic communities focused more on general methods. While the generalityand scientific rigor of constraint programming is one of its strengths, we face a continu-ing challenge to reconnect these streams more firmly with their semantic problem-solvingroots.

    The language stream became heavily influenced by logic programming, in the form ofconstraint logic programming, and focused on the development of programming languagesand libraries. Hewitts Planner language [40] and its partial implementation as Micro-Planner [70] can be seen as an early logic programming language [3]. The major earlymilestone, though, was the development of Prolog by Colmerauer and others around 1972[14] and the logic as a programming language movement [39, 47]. Prolog can be framed asan early constraint programming language, solving equality constraints over terms (includ-ing variables) using the unification algorithm as the constraint solver. Colmerauer pushedthis view much further in his introduction of Prolog II in 1982 [13, 12]. The integrationof constraint propagation algorithms into interpreters for Planner-like languages was pro-posed by Mackworth [53]. Van Hentenryck developed and implemented CHIP (ConstraintHandling in Prolog) as a fully-fledged constraint logic programming language [77]. In aparallel development Jaffar et al. developed the CLP(X) family of constraint logic pro-gramming languages [42] including CLP(R) [44]. For more on these developments in thelanguage stream see the surveys in [11, 43] and other chapters in this handbook.

    The algorithm stream, influenced by the paradigm of artificial intelligence as search,as exemplified in Nilssons early textbook [61], and by the development of the science ofalgorithms, as exemplified by Knuths The Art of Computer Programming [45], focusedon algorithms and heuristics. The second stream remained more firmly within artificialintelligence, developing as one of the artificial intelligence communities built around rea-soning paradigms: constraint-based reasoning [29], case-based reasoning, and the like. Italso focused increasingly on the simple, but powerful and general, constraint satisfactionproblem (CSP) formulation and its variants. We shall focus primarily on this stream, andthe development of the CSP paradigm, in this chapter.

  • 16 2. Constraint Satisfaction: An Emerging Paradigm

    The challenge then became to reintegrate the language and algorithm streams, alongwith related disciplines, such as mathematical programming and constraint databases, intoa single constraint programming community. This process began in earnest in the 1990swhen Paris Kanellakis, Jean-Louis Lassez, and Vijay Saraswat chaired a workshop thatsoon led to the formation of an annual International Conference on Principles and Practiceof Constraint Programming, and, at the instigation of Zsofia Ruttkay, Gene Freuder estab-lished the Constraints journal, which provides a common forum for the many disciplinesinterested in constraint programming and constraint satisfaction and optimization, and themany application domains in which constraint technology is employed.

    2.2 The Constraint Satisfaction Problem: Representation andReasoning

    Here we consider the representation of constraint satisfaction problems, the varieties ofreasoning used by algorithms to solve them and the analysis of those solution methods.

    2.2.1 Representation

    The classic definition of a Constraint Satisfaction Problem (CSP) is as follows. A CSPP is a triple P = X,D,C where X is an n-tuple of variables X = x1, x2, . . . , xn,D is a corresponding n-tuple of domains D = D1, D2, . . . , Dn such that xi Di, C isa t-tuple of constraints C = C1, C2, . . . , Ct. A constraint Cj is a pair RSj , Sj whereRSj is a relation on the variables in Si = scope(Ci). In other words, Ri is a subset of theCartesian product of the domains of the variables in Si.1

    A solution to the CSP P is an n-tuple A = a1, a2, . . . , an where ai Di andeach Cj is satisfied in that RSj holds on the projection of A onto the scope Sj . In agiven task one may be required to find the set of all solutions, sol(P), to determine ifthat set is non-empty or just to find any solution, if one exists. If the set of solutions isempty the CSP is unsatisfiable. This simple but powerful framework captures a widerange of significant applications in fields as diverse as artificial intelligence, operationsresearch, scheduling, supply chain management, graph algorithms, computer vision andcomputational linguistics, to name but a few.

    The classic CSP paradigm can be both specialized and generalized in a variety of im-portant ways. One important specialization considers the extensionality/intensionality ofthe domains and constraints. If all the domains in D are finite sets, with extensional rep-resentations, then they, and the constraint relations, may be represented and manipulatedextensionally. However, even if the domains and the relations are intensionally represented,many of the techniques described in this chapter and elsewhere in the handbook still ap-ply. If the size of the scope of each constraint is limited to 1 or 2 then the constraintsare unary and binary and the CSP can be directly represented as a constraint graph withvariables as vertices and constraints as edges. If the arity of constraints is not so limitedthen a hypergraph is required with a hyperedge for each p-ary constraint (p > 2) connect-ing the p vertices involved. The satisfiability of propositional formulae, SAT, is another

    1 This is the conventional definition, which we will adhere to here. A more parsimonious definition of a CSPwould dispense with D entirely leaving the role of Di to be played by a unary constraint Cj with scope(Cj) =xi.

  • E. C. Freuder, A. K. Mackworth 17

    specialization of CSP, where the domains are restricted to be {T, F} and the constraintsare clauses. 3-SAT, the archetypal NP-complete decision problem, is a further restrictionwhere the scope of each constraint (clause) is 3 or fewer variables.

    The classic view of CSPs was initially developed by Montanari [60] and Mackworth[53]. It has strong roots in, and links with, SAT [16, 15, 54], relational algebra anddatabase theory [58], computer vision [10, 41, 79] and graphics [73].

    Various generalizations of the classic CSP model have been developed subsequently.One of the most significant is the Constraint Optimization Problem (COP) for which thereare several significantly different formulations, and the nomenclature is not always con-sistent [19]. Perhaps the simplest COP formulation retains the CSP limitation of allowingonly hard Boolean-valued constraints but adds a cost function over the variables, thatmust be minimized. This arises often, for example, in scheduling applications.

    2.2.2 Reasoning: Inference and Search

    We will consider the algorithms for solving CSPs under two broad categories: inferenceand search, and various combinations of those two approaches. If the domains Di are allfinite then the finite search space for putative solutions is = i Di (where is the joinoperator of relational algebra [58]). can, in theory, be enumerated and each n-tuple testedto determine if it is a solution. This blind enumeration technique can be improved uponusing two distinct orthogonal strategies: inference and search. In inference techniques,local constraint propagation can eliminate large subspaces from on the grounds that theymust be devoid of solutions. Search systematically explores , often eliminating subspaceswith a single failure. The success of both strategies hinges on the simple fact that a CSPis conjunctive: to solve it, all of the constraints must be satisfied so that a local failure ona subset of variables rules out all putative solutions with the same projection onto thosevariables. These two basic strategies are usually combined in most applications.

    2.2.3 Inference: Constraint Propagation Using Network Consistency

    The major development in inference techniques for CSPs was the discovery and develop-ment, in the 1970s, of network consistency algorithms for constraint propagation. Herewe will give an overview of that development.

    Analysis of using backtracking to solve CSPs shows that it almost always displayspathological thrashing behaviors [3]. Thrashing is the repeated exploration of failing sub-trees of the backtrack search tree that are essentially identicaldiffering only in assignmentsto variables irrelevant to the failure of the subtree. Because there is typically an exponentialnumber of such irrelevant assignments, thrashing is often the most significant factor in therunning time of backtracking.

    The first key insight behind all the consistency algorithms is that much thrashing be-havior can be identified and eliminated, once and for all, by tightening the constraints,making implicit constraints explicit, using tractable, efficient polynomial-time algorithms.The second insight is that the level, or scope, of consistency, the size of the set of variablesinvolved in the local context, can be adjusted as a parameter from 1 up to n, each increasein level requiring correspondingly more work.

    For simplicity, we will initially describe the development of the consistency algorithmsfor CSPs with finite domains and unary and binary constraints only, though neither restric-

  • 18 2. Constraint Satisfaction: An Emerging Paradigm

    tion is necessary, as we shall see. We assume the reader is familiar with the basic elementsof graph theory, set theory and relational algebra.

    Consider a CSP P = X,D,C as defined above. The unary constraints are Ci= Rxi, xi. We use the shorthand notation Ri to stand for Rxi. Similarly, the binaryconstraints are of the form Cs = Rxi,xj, xi, xj where i 6= j. We use Rij to stand forRxi,xj.

    Node consistency is the simplest consistency algorithm. Node i comprised of vertex irepresenting variable xi with domain Di is node consistent iff Di Ri. If node i is notnode consistent it can be made so by computing:

    Di = Di

    RiDi Di

    A single pass through the nodes makes the network node consistent. The resultingCSP is P = X,D, C where D = D1, D2, . . . , Dn. We say P = NC(P). Clearlysol(P) = sol(P ). Let =i Di then || ||.

    Arc consistency is a technique for further tightening the domains using the binary con-straints. Consider node i with domain Di. Suppose there is a non-trivial relation Rijbetween variables xi and xj . We consider the arcs i, j and j, i separately. Arc i, j isarc consistent iff:

    Di i(Rij Dj)

    where is the projection operator. That is, for every member of Di, there is a correspond-ing element in Dj that satisfies Rij . Arc i, j can be tested for arc consistency and madeconsistent, if it is not so, by computing:

    Di = Di

    i(Rij Dj)Di Di

    (This is a semijoin [58]). In other words, delete all elements of Di that have no correspond-ing element in Dj satisfying Rij . A network is arc consistent iff all its arcs are consistent.If all the arcs are already consistent a single pass through them is all that is needed to ver-ify this. If, however, at least one arc has to be made consistent (i.e. Di 6= Di there is adeletion from Di) then one must recheck some number of arcs. The basic arc consistencyalgorithm simply checks all the arcs repeatedly until a fixed point of no further domainreductions is reached. This algorithm is known as AC-1 [53].

    Waltz [79] realized that a more intelligent arc consistency bookkeeping scheme wouldonly recheck those arcs that could have become inconsistent as a direct result of deletionsfrom Di. Waltzs algorithm, now known as AC-2 [53], propagates the revisions of thedomains through the arcs until, again, a fixed point is reached. AC-3, presented by Mack-worth [53], is a generalization and simplification of AC-2. AC-3 is still the most widelyused and effective consistency algorithm. For each of these algorithms let P = AC(P)be the result of enforcing arc consistency on P . Then clearly sol(P) = sol(P ) and|| ||.

    The best framework for understanding all the network consistency algorithms is to seethem as removing local inconsistencies from the network which can never be part of anyglobal solution. When those inconsistencies are removed they may propagate to cause

  • E. C. Freuder, A. K. Mackworth 19

    inconsistencies in neighboring arcs that were previously consistent. Those inconsistenciesare in turn removed so the algorithm eventually arrives, monotonically, at a fixed pointconsistent network and halts. An inconsistent network has the same set of solutions asthe consistent network that results from applying a consistency algorithm to it; however,if one subsequently applies, say, a backtrack search to the consistent network the resultantthrashing behavior can be no worse and almost always is much better, assuming the samevariable and value ordering.

    Path consistency [60] is the next level of consistency to consider. In arc consistencywe tighten the unary constraints using local binary constraints. In path consistency weanalogously tighten the binary constraints using the implicit induced constraints on triplesof variables.

    A path of length two from node i through node m to node j, i,m, j, is path consistentiff:

    Rij ij(Rim Dm Rmj)

    That is, for every pair of values a, b allowed by the explicit relation Rij there is a valuec for xm such that a, c is allowed by Rim and c, b is allowed by Rmj .

    Path i,m, j can be tested for path consistency and made consistent, if it is not, bycomputing:

    Rij = Rij

    ij(Rim Dm Rmj)Rij Rij

    If the binary relations are represented as Boolean bit matrices then the combination of thejoin and projection operations (which is relational composition) becomes Boolean matrixmultiplication and the

    operation becomes simply pairwise bit operations. In otherwords, for all the values a, b allowed by Rij if there is no value c for xm allowed by Rimand Rmj the path is made consistent by changing that bit value in Rij from 1 to 0. Theway to think of this is that the implicit constraint on i, j imposed by node m throughthe relational composition Rim Rmj is made explicit in the new constraint Rij whenpath i,m, j is made consistent.

    As with arc consistency the simplest algorithm for enforcing path consistency for theentire network is to check and ensure path consistency for each length 2 path i,m, j. Ifany path has to be made consistent then the entire pass through the paths is repeated again.This is algorithm PC-1 [53, 60].

    The algorithm PC-2 [53] determines, when any path is made consistent, the set of otherpaths could have become inconsistent because they use the arc between that pair of verticesand queues those paths, if necessary, for further checking. PC-2 realizes substantial savingsover PC-1 just as AC-3 is more efficient than AC-1 [55].

    Typically, after path consistency is established, there are non-trivial binary constraintsbetween all pairs of nodes. As shown by Montanari [60], if all paths of length 2 are con-sistent then all paths of any length are consistent, so longer paths need not be considered.Once path consistency is established, there is a chain of values along any path satisfyingthe relations between any pair of values allowed at the start and the end of the path. Thisdoes not mean that there is necessarily a solution to the CSP. If a path traverses the entirenetwork with a chain of compatible values, if that path self-intersects at a node the two

  • 20 2. Constraint Satisfaction: An Emerging Paradigm

    values on the path at that node may be different. Indeed, it is a property of both arc consis-tency and path consistency that consistency may be established with non-empty domainsand relations even though there may be no global solution. Low-level consistency, with noempty domains, is a necessary but not sufficient condition for the existence of a solution.So, if consistency does empty any domain or relation there is no global solution.

    Parenthetically, we note that our abstract descriptions of these algorithms, in termsof relational algebra, are specifications not implementations. Implementations can oftenachieve efficiency savings by, for example, exploiting the semantics of a constraint such asthe all different global constraint, alldiff, that requires each variable in its scope to assumea different value.

    Briefly, let us establish that consistency algorithms do not require the finite domainor binary constraint restrictions on the CSP model. As long as we can perform , and

    operations on the domain and relational representations these algorithms are perfectlyadequate.

    Consider, for example, the trivial CSP P = x1, x2, [0, 3], [2, 5], =, x1, x2where x1 and x2 are reals. That is, x1 D1 = [0, 3], x2 D2 = [2, 5]. Arc consistencyon arc