1.51k likes | 1.53k Views
Explore the world of finite constraint domains and discover clever ways to solve complex scheduling, routing, and timetabling problems. This course covers binary CSPs, graph-related concepts, CSP solution techniques, and more.
E N D
Finite Constraint Domains Where we meet the simplest and yet the most difficult constraints, and some clever and not so clever ways to solve them. CSC5240 - Finite Constraint Domains
Finite Constraint Domains • An important class of constraint domains • Modeling constraint problems involving choice: e.g. scheduling, routing and timetabling • The greatest industrial impact of constraint programming has been on these problems CSC5240 - Finite Constraint Domains
Finite Domain CSPs • A FD CSP (or simply CSP hereafter) is a triple áZ,D,Cñ • Z is a finite set of variables {x1,x2,…,xn} • D is a function that maps each variable x to its domain D(x), a finite set of objects • C is a constraint, each primitive constraint of which on an arbitrary subsets of Z • It is understood as the constraint CSC5240 - Finite Constraint Domains
Binary CSPs • A binary CSP is a CSP with unary or binary constraints only • A CSP with more than unary and binary constraints are general CSPs • Theoretically speaking, every general CSP can be transformed to an “equivalent” binary CSP • How?? CSC5240 - Finite Constraint Domains
Graph-Related Concepts • A graph (directed or undirected) is a pair (V,U), where V is a set of nodes and U (VV) is a set of arcs, each of which is a pair of adjacent nodes • For undirected graphs, (j,k) and (k,j) denote the same arc for every pair of adjacent nodes j and k CSC5240 - Finite Constraint Domains
Graph-Related Concepts (cont’d) • A hypergraph is a pair (V,U), where V is a set of nodes and U is a set of hyper-arcs, each of which is a set of nodes • A constraint hypergraph of a CSP áZ,D,Cñ is a hypergraph in which each node denote a variable in Z, and each hyper-arc denote a primitive constraint in C CSC5240 - Finite Constraint Domains
Graph-Related Concepts (cont’d) • A path in a graph (or hypergraph) is a sequence of nodes drawn from the graph, where every pair of adjacent nodes in this sequence forms an arc (or hyper-arc) • A path of lengthn is a path which goes thru n+1 (not necessarily distinct) nodes • Draw the constraint hypergraphs of previous CSP examples CSC5240 - Finite Constraint Domains
CSP Solution Techniques • A CSP-solving algorithm is sound if every answer returned by the algorithm is indeed a solution of the CSP • A CSP-solving algorithm is complete if every solution can be found by the algorithm • Soundness and completeness are desirable properties of CSP-solving algorithms CSC5240 - Finite Constraint Domains
CSP Solution Techniques (cont’d) • CSPs are NP-complete in general • In some real-life problems, an incomplete (and sometimes even unsound) but efficient algorithm is acceptable CSC5240 - Finite Constraint Domains
Domain Specific .vs. General • Encoding domain specific knowledge can gain efficiency: e.g. the N-Queen problem • But … • Tailor-made algorithms are costly • Tailor-made algorithms are not adaptable in (even slight) change of problem specification • General algorithms can often form the basis of specialized algorithms • CSPs are NP-complete anyway!!! CSC5240 - Finite Constraint Domains
Three Classes of Techniques • Generate-and-Test (not really a technique) • Searching • Problem reduction • Solution Synthesis CSC5240 - Finite Constraint Domains
Generate-and-Test • Systematically generating all combinations of values from domains of variables • For each generated valuation , where var() = Z, test whether satisfies all primitive constraints in C • Highly combinatorial and impractical even for small problems CSC5240 - Finite Constraint Domains
Searching - 1 • Searching is fundamental in almost all areas of computer science, including AI • Chronological backtracking search • Labeling a variable • Pick a variable x • Pick an available value v from D(x), making sure that is compatible with the current valuation • Consider an alternative available value in D(x) if current variable labeling violates some constraints CSC5240 - Finite Constraint Domains
Searching - 2 • If all the variables are labelled, then a solution is found • If, at any stage, no available value can be assigned to a variable, the label that was last picked is revised • Repeat until either a solution is found or all possible combinations of labels have been tried CSC5240 - Finite Constraint Domains
A Simple Backtracking Solver • The backtracking solver: • enumerates values for one variable at a time • checks that no primitive constraint is false at each stage • Assume satisfiable(c) returns false when primitive constraint c with no variables is unsatisfiable; and true otherwise CSC5240 - Finite Constraint Domains
Partial Satisfiability • Check if a constraint is made unsatisfiable by a primitive constraint with no variables • partial_satisfiable(C) • for each primitive constraint c in C • if vars(c) is empty then • ifsatisfiable(c) = falsethenreturnfalse • returntrue CSC5240 - Finite Constraint Domains
Backtracking Solve - 1 • back_solve(C,D) • ifvars(C) is empty return partial_satisfiable(C) • choose x in vars(C) • for each value d in D(x) • let C1 be C with x replaced by d • if partial_satisfiable(C1) then • if back_solve(C1,D) then returntrue • returnfalse CSC5240 - Finite Constraint Domains
Backtracking Solve - 2 CSC5240 - Finite Constraint Domains
Backtracking Solve - 2 Choose var X domain {1,2} CSC5240 - Finite Constraint Domains
Backtracking Solve - 2 Choose var X domain {1,2} CSC5240 - Finite Constraint Domains
Backtracking Solve - 2 CSC5240 - Finite Constraint Domains
Backtracking Solve - 2 Choose var Y domain {1,2} CSC5240 - Finite Constraint Domains
Backtracking Solve - 2 Choose var Y domain {1,2} CSC5240 - Finite Constraint Domains
Backtracking Solve - 2 CSC5240 - Finite Constraint Domains
Backtracking Solve - 2 partial_satisfiablefalse CSC5240 - Finite Constraint Domains
Backtracking Solve - 2 Choose var Y domain {1,2} CSC5240 - Finite Constraint Domains
Backtracking Solve - 2 Choose var Y domain {1,2} CSC5240 - Finite Constraint Domains
Backtracking Solve - 2 CSC5240 - Finite Constraint Domains
Backtracking Solve - 2 Choose var Z domain {1,2} CSC5240 - Finite Constraint Domains
Backtracking Solve - 2 Choose var Z domain {1,2} CSC5240 - Finite Constraint Domains
Backtracking Solve - 2 CSC5240 - Finite Constraint Domains
Backtracking Solve - 2 No variables, and false CSC5240 - Finite Constraint Domains
Backtracking Solve - 2 Choose var Z domain {1,2} CSC5240 - Finite Constraint Domains
Backtracking Solve - 2 Choose var Z domain {1,2} CSC5240 - Finite Constraint Domains
Backtracking Solve - 2 CSC5240 - Finite Constraint Domains
Backtracking Solve - 2 No variables, and false CSC5240 - Finite Constraint Domains
Backtracking Solve - 2 Choose var X domain {1,2} CSC5240 - Finite Constraint Domains
Backtracking Solve - 2 Choose var X domain {1,2} CSC5240 - Finite Constraint Domains
Backtracking Solve - 2 CSC5240 - Finite Constraint Domains
Backtracking Solve - 2 Choose var Y domain {1,2} CSC5240 - Finite Constraint Domains
Backtracking Solve - 2 CSC5240 - Finite Constraint Domains
Backtracking Solve - 2 Choose var Y domain {1,2} CSC5240 - Finite Constraint Domains
Backtracking Solve - 2 CSC5240 - Finite Constraint Domains
Searching - 3 • Complexities of chronological backtracking • n: number of variables • e: the number of contraints • a: the size of the largest domain • b: the size of the largest constraint • Time complexity: O(aneb) • Space complexity: O(na+eb) CSC5240 - Finite Constraint Domains
Search Space - 1 • Z={x,y,z}, D(x)={a,b,c,d}, D(y)={e,f,g}, D(Z)={p,q} CSC5240 - Finite Constraint Domains
Search Space - 2 • Fixed variable ordering: x, y, z CSC5240 - Finite Constraint Domains
Search Space - 3 • Fixed variable ordering: z, y, x CSC5240 - Finite Constraint Domains
Characteristics of Search Space • The size of search space is finite • # of leaves: • # of internal nodes: • Variable ordering is important. Why??? • Problem still dominated by • The depth of the tree is fixed • The number of variables with ordering • Twice the number of variables without ordering CSC5240 - Finite Constraint Domains
More Characteristics • Subtrees are similar • With fixed variable ordering, subtrees under each branch of the same level are identical in topology • Experience in searching one subtree may be useful in subsequently searching its siblings CSC5240 - Finite Constraint Domains
Problem Reduction - 1 • Idea: transform a CSP into another which is hopefully easier to solve or recognizable as insoluble. For example: 3X1 + 4X2 = 5 3X1 + 4X2 = 5 4X1 - 2X2 = 7 11X1 = 19 CSC5240 - Finite Constraint Domains