School of Computer Studies Research Report Series A

School of Computer Studies Research Report Series A

University of Leeds SCHOOL OF COMPUTER STUDIES RESEARCH REPORT SERIES Rep ort A Tutorial on Constraint Programming by Barbara M Smith Division of Articial Intelligence April Abstract A constraint satisfaction problem CSP consists of a set of variables for each variable a nite set of p ossible values its domain and a set of con straints restricting the values that the variables can simultaneously take A solution to a CSP is an assignment of a value from its domain to every vari able in such a way that every constraint is satised Many problems arising in OR in particular scheduling timetabling and other combinatorial prob lems can b e represented as CSPs Constraint programming to ols now exist which allow CSPs to b e expressed easily and provide standard strategies for nding solutions This tutorial is intended to give a basic grounding in con straint satisfaction problems and some of the algorithms used to solve them including the techniques commonly used in constraint programming to ols In particular it covers arc and path consistency simple backtracking and forward checking as examples of search algorithms and the use of heuristics to guide the search A simple example is considered in detail to show the eect of dierent choices of formulation and search strategy Finding optimal solutions to CSPs is also discussed Intro duction Constraint satisfaction problems CSPs have b een a sub ject of research in AI for many years It has b een recognised that CSPs have practical sig nicance b ecause many problems arising in OR in particular scheduling timetabling and other combinatorial problems can b e represented as CSPs This tutorial is intended to intro duce the research into CSPs which is neces sary to make use of constraint programming to ols it is not intended to b e a comprehensive survey of the eld Briey a constraint satisfaction problem CSP consists of a set of variables X fx x g 1 n for each variable x a nite set D of p ossible values its domain i i and a set of constraints restricting the values that the variables can simultaneously take Note that the values need not b e a set of consecutive integers although often they are they need not even b e numeric A solution to a CSP is an assignment of a value from its domain to every variable in such a way that every constraint is satised We may want to nd just one solution with no preference as to which one all solutions an optimal or at least a go o d solution given some ob jective function dened in terms of some or all of the variables As describ ed b elow solutions to CSPs are found by searching systemati cally through the p ossible assignments of values to variables usually guided by heuristics The reasons for cho osing to represent and solve a problem as a CSP rather than say as a mathematical programming problem are two fold Firstly the representation is often much closer to the original prob lem the variables of the CSP directly corresp ond to problem entities and the constraints can b e expressed without having to b e translated into lin ear inequalities This makes the formulation simpler the solution easier to understand and the choice of go o d heuristics to guide the solution strategy more straightforward Secondly although CSP algorithms are essentially very simple they can sometimes nd solutions more quickly than if integer programming metho ds are used In recent years with the development of constraint programming to ols it has b ecome easier to express and solve constraint satisfaction problems The rst commercial constraint programming to ols were those based on exten sions of Prolog in particular CHIP Constraint Handling in Prolog Cur rently ICLs DecisionPower incorp orates CHIP and it is also available from Cosytec PrologI I I is an alternative constraint programming language based on Prolog available from Prologia Constraint logic programming ie the extension of logic programming languages like Prolog to supp ort the handling of constraints is now a signicant area of research in the logic programming community Logic programming is not however an essential basis for constraint pro gramming and other to ols have b een built notably Solver from ILOG which is a C library It is worth mentioning that the French computer com pany Bull which had its own constraint programming to ol called Charme develop ed from CHIP has now abandoned this in favour of a version of ILOG Solver Where necessary examples in this tutorial will refer to ILOG Solver which is the to ol that I am most familiar with However examples could equally well have b een presented in terms of CHIP or another to ol Constraints The constraints of a CSP are usually represented by an expression involving the aected variables eg x x 1 2 x x x 1 2 3 x x x 1 2 3 or in ILOG Solver CtNeqxx CtEqx x x CtLtx x x It is useful also to b e aware of the formal denition of a constraint a p ossible constraint C b etween the variables x x x is any subset of ij k i j k 1 the p ossible combinations of values of x x x The subset sp ecies the i j k combinations of values which the constraint allows For example if variable x has the domain f g and variable y has the domain f g then any subset of f g is a valid constraint b etween x and y The constraint x y would b e represented by the subset f g Although the constraints of real problems are not represented this way in practice the denition do es emphasise that constraints need not corresp ond to simple expressions and in particular they need not b e linear inequalities or equations although they can b e A constraint can aect any numb er of variables from to n n is the numb er of variables in the problem The numb er of aected variables is the arity of the constraint It is useful to distinguish two particular cases Unary constraints aect just one variable The constraint can b e used to remove any value which do es not satisfy the constraint from the domain of the variable at the outset For instance if there is a constraint x 1 the value can b e removed from the domain of x and the constraint will 1 then b e satised Since unary constraints are dealt with by prepro cessing the domains of the aected variable they can b e ignored thereafter Binary Constraints aect two variables If all the constraints of a CSP are binary the variables and constraints can b e represented in a constraint graph the no des of the graph represent the variables and there is an edge joining two no des if and only if there is a constraint b etween the corresp ond ing variables 1 The p ossible combinations of values of x x x are given by the crosspro duct of i j k the domains D D D so C is a p ossible constraint if i j k ij k C D D D ij k i j k In fact any constraint of higher arity can b e expressed in terms of binary constraints although in practice this is not likely to b e worth doing Hence in some sense binary CSPs are representative of all CSPs An individual binary constraint b etween two variables with domain sizes m and m can b e represented by an m m matrix of values where 1 2 1 2 signies that the constraint allows the corresp onding pair of values and that it do es not Although this is not a practical way of dening real constraints it means that a random matrix can represent a binary con straint and this allows exp erimenters who need a large numb er of CSPs to pro duce randomlygenerated problems The pairs of variables which have constraints b etween them are also selected randomly describ es in more detail two p ossible mo dels for randomlygenerated CSPs A great deal of exp erimental work on CSPs comparing the p erformance of dierent algo rithms for instance has b een done using p opulations of randomlygenerated binary CSPs Example Cryptarithmetic puzzles like the following can b e expressed as CSPs Each letter in the following sum stands for a dierent digit nd their values D O N A L D G E R A L D R O B E R T The variables are the letters D O N A L G E R B T and their domains are the set of digits f g except that D G and R cannot b e This expressed in ILOG Solver by creating a set of constrained integer variables CtIntVar DONAL GERBT It is convenient to form an array containing p ointers to these variables CtIntVar AllVars DONALGERBT The constraints are the ten variables must all b e assigned a dierent value Technically this means that there is a notequal constraint b etween every pair of variables giving binary constraints In practice to ols such as ILOG Solver allow an easy way of stating that all variables in a sp ecied set must set have dierent values CtAllNeq AllVars the sum given must work out CtEqDONALD GERALD ROBERT There are alternative ways of formulating this problem which are b etter from the p oint of view of nding a solution This will b e discussed later Arc Consistency If there is a binary constraint C b etween the variables x and x then the ij i j 2 arc x x is arc consistent if for every value a D there is a value b D i j i j such that the assignments x a and x b satisfy the constraint C i j ij Any value a D for which this is not true ie no such value b exists can i safely b e removed from D since it cannot b e part of any consistent solution i removing all such values makes the arc x x arc consistent Note that we i j have only checked the values of x there may still b e values in the domain i of x which could b e removed if we reverse the op eration and make the arc j x x arc consistent j i Figure a shows the original domains of x and y In b x y has b een made arc consistent in c b

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    22 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us