Download presentation
Presentation is loading. Please wait.
1
CAP 492 Course Dr. Souham Meshoul 1 CONSTRAINT SATISFACTION PROBLEMS Chapter 5
2
CAP 492 Course Dr. Souham Meshoul 2 CONSTRAINT SATISFACTION PROBLEMS Introduction Standard search problem: state is a black box supporting goal test, successor function and heuristic function. The internal structure of a state is problem specific. Constraint Satisfaction Problems (CSP) are a kind of problems where states and goal test conform to a standard, structured, and very simple representation. This representation allows defining general purpose heuristics rather than problem-specific ones.
3
CAP 492 Course Dr. Souham Meshoul 3 CONSTRAINT SATISFACTION PROBLEMS Some Definitions A CSP is defined by: a set of variables X1, X2,…,Xn where each variable Xi has a nonempty domain Di of possible values. a set of constraint C1, C2,…,Cn where each constraint Ci involves some subset of the variables and specifies the allowable combinations of values for that subset. A state in a CSP: is defined by an assignment of values to some or all the variables. {Xi = vi, Xj=vj,…} Consistent assignment: the one that does not violate any constraint (also called legal assignment). Complete assignment Complete assignment: the one in which every variable is mentioned.
4
CAP 492 Course Dr. Souham Meshoul 4 CONSTRAINT SATISFACTION PROBLEMS Some definitions Solution in CSP: It is a complete assignment that satisfies all the constraints. Some CSPs also require a solution that maximizes an objective function. Constraint graph: a CSP can be visualized by a constraint graph where nodes correspond to variables and arc to constraints. Benefits Successor function and goal test can be written in a generic way that applies to all CSPs. It is possible to develop effective, generic heuristics that require no additional, domain specific expertise. The structure of the constraint graph can be used to simplify the solution process.
5
CAP 492 Course Dr. Souham Meshoul 5 CONSTRAINT SATISFACTION PROBLEMS Map coloring Example Color a map so that no adjacent regions have same color using three colors. Variables: Regions Ci, i=1 to i=6 Domains {Red, Blue, Green} Constraint C1≠C2, C1≠C3, C1≠C5, C5≠C6, etc Constraint Graph C1C1 C2C2 C3C3 C5 C6C6 C4C4
6
CAP 492 Course Dr. Souham Meshoul 6 CONSTRAINT SATISFACTION PROBLEMS Real world CSPs Assignment problems: e.g. who teaches what class? Timetabling problems: e.g. which class is offered, when and where? Transportation scheduling. Hardware configuration. Planning problems Etc …
7
CAP 492 Course Dr. Souham Meshoul 7 CONSTRAINT SATISFACTION PROBLEMS CSP formulation Incremental formulation Initial state: empty assignment {}, in which all variables are unassigned. Successor function: a value can be assigned to any unassigned variable provided that it does not conflict with previously assigned variables. Goal test: the current assignment is complete. Path cost: a constant cost for every step Questions: What is the depth of the search tree in this case? Which strategy is suitable?
8
CAP 492 Course Dr. Souham Meshoul 8 CONSTRAINT SATISFACTION PROBLEMS Complete formulation Every state is a complete assignment that might or might not satisfy the constraints. CSPs Varieties Discrete variables with finite domains e.g. Map coloring and Boolean CSPs where variables can be either true of false. If d is the maximum domain size for any variable, then the number of possible complete assignments is O(d n ) With infinite domains e.g. job scheduling Continuous variables
9
CAP 492 Course Dr. Souham Meshoul 9 CONSTRAINT SATISFACTION PROBLEMS Constraints varieties Unary constraint: involves a single variable. e.g. C1 ≠ green Binary constraint: involve pairs of variables. e.g. C1 ≠ C3 High order variables: involve 3 or more variables. Preferences (soft constraints): e.g red is better than blue Often representable by a cost for each variable assignment → constrained optimization problems
10
CAP 492 Course Dr. Souham Meshoul 10 CONSTRAINT SATISFACTION PROBLEMS Backtraking search for CSPs Problem: Let’s consider Map coloring problem with 3 regions and 3 colors.
11
CAP 492 Course Dr. Souham Meshoul 11 CONSTRAINT SATISFACTION PROBLEMS The state space using the generic CSP incremental formulation has the following properties: maximum depth is n (number of variables). The depth of the solution is n. Branching factor at the top is nd ( d: size of the domain). Branching factor at the next level is (n-1)d * nd = n(n-1)d 2 and so on for n levels. Number of leaves is n!d n even though there are only d n possibe complete assignments. Suitable search technique is DFS.
12
CAP 492 Course Dr. Souham Meshoul 12 CONSTRAINT SATISFACTION PROBLEMS This can be improved dramatically by noting the following: The formulation does not take into account one property of CSPs → Commutativity. In CSP Order of assignment is irrelevant so many paths are equivalent. Order of application of any given set of actions has no effect on the outcome. All CSPs search algorithms generate successors by considering possible assignments for only a single variable at each node in the search space. Adding assignments cannot correct a violated constraint.
13
CAP 492 Course Dr. Souham Meshoul 13 CONSTRAINT SATISFACTION PROBLEMS Backtraking search for CSPs Basic idea : backtracking search uses depth first search choosing values for one variable at a time and backtracks when a variable has no legal values left to assign. Backtracking search is the basic uninformed algorithm for CSPs. Policy: when a branch of the search fails, search backs up to the preceding variable and tries a different value for it. This is called chronological backtracking because the most recent decision point is revisited.
14
CAP 492 Course Dr. Souham Meshoul 14 CONSTRAINT SATISFACTION PROBLEMS Function backtracking-search (csp) returns a solution, or failure return recursive-backtracking ({}, csp) Function Recursive-Backtracking(assignment, csp) returns a solution, or failure If assignment is complete return assignment var ← SELECT-UNASSIGNED-VARIABLE (variable [csp], assignment, csp) For each value in ORDER-DOMAIN-VALUES(var, assignment,csp) do if value is consistent with assignment according to Constraint[csp] then add {var = value} to assignment result ← Recursive-backtracking(assignment, csp) if result ≠ failure then return result remove {var = value} from assignment End return failure
15
CAP 492 Course Dr. Souham Meshoul 15 WA NT SA Q NSW V T WA: Western Australia NT: Northern Territory SA: South Australia Q: Queensland NSW: New South Wales V: Victoria T: Tasmania
16
CAP 492 Course Dr. Souham Meshoul 16
17
CAP 492 Course Dr. Souham Meshoul 17
18
CAP 492 Course Dr. Souham Meshoul 18
19
CAP 492 Course Dr. Souham Meshoul 19 CONSTRAINT SATISFACTION PROBLEMS Notice: Standard representation → no need for domain specific initial state, successor funtion or goal test. SELECT-UNASSIGNED-VARIABLE and ORDER-DOMAIN- VALUES can be used to implement the general purpose heuristics. This algorithm is not effective for large problems. Improvements: can be achieved if the following questions are addressed:
20
CAP 492 Course Dr. Souham Meshoul 20 CONSTRAINT SATISFACTION PROBLEMS Questions: 1.Which variable should be assigned next and in what order should its values be tried? 2.What are the implication of the current variable assignments for the other UNASSIGNED variables? 3.When a path fails, can the search avoid repeating this failure in subsquent paths?
21
CAP 492 Course Dr. Souham Meshoul 21 CONSTRAINT SATISFACTION PROBLEMS Variable and value ordering var ← SELECT-UNASSIGNED-VARIABLE (variable [csp], assignment, csp) This statement simply selects the next unassigned variable in the order given by the list variable [csp]. It seldom results in efficient search. Solution: Choose variable with the fewest “legal” values → Minimum Remaining Value (MRV heuristic) also called most constrained variable. Notice: if there is a variable with zero legal values remaining, the MRV heutistic will select X and failure will be detected immediately avoiding pointless search through other variables which always will fail when X is finaly selected.
22
CAP 492 Course Dr. Souham Meshoul 22 Problem: Example WA = red, NT = green → SA = blue rather than assigning Q. After assigning SA, values for Q, NSW and V are all forced. The performance is 3 to 3000 times better than simple backtracking (What is the cost of computing heuristic values).
23
CAP 492 Course Dr. Souham Meshoul 23 Degree heuristic: What is the first region to color? Idea: Choose the variable that is involved in the largest number of constraints on other unassigned variables. Example degree heuristic for SA is 5. (most constraining variable)
24
CAP 492 Course Dr. Souham Meshoul 24 CONSTRAINT SATISFACTION PROBLEMS Least constraining value: Once a variable is selected, how to decide on the order in which to examine the values? Solution: Choose the least constraining value so that to leave maximum flexibility for subsquent variable assignments. Example: WA=red, NT=green, choosing blue for Q is a bad choice because it eliminates the last legal value for SA.
25
CAP 492 Course Dr. Souham Meshoul 25 CONSTRAINT SATISFACTION PROBLEMS
26
CAP 492 Course Dr. Souham Meshoul 26 CONSTRAINT SATISFACTION PROBLEMS Propagating Information through constraints Key Idea: Instead of considering the constraints on a variable only at the time that the variable is chosen by SELECT- UNASSIGNED-VARIABLE, LOOK at some constraint earlier or even before. One alternative Forward Cheking (FC). Forward Checking looks at each unassigned variable Y that is connected to X by a constraint and deletes from Y’s domain any value that is inconsistent with the value chosen for X.
27
CAP 492 Course Dr. Souham Meshoul 27 CONSTRAINT SATISFACTION PROBLEMS
28
CAP 492 Course Dr. Souham Meshoul 28 CONSTRAINT SATISFACTION PROBLEMS
29
CAP 492 Course Dr. Souham Meshoul 29 CONSTRAINT SATISFACTION PROBLEMS
30
CAP 492 Course Dr. Souham Meshoul 30 CONSTRAINT SATISFACTION PROBLEMS
31
CAP 492 Course Dr. Souham Meshoul 31 CONSTRAINT SATISFACTION PROBLEMS Notice: After WA= red and Q= green, NT and SA with simple value. → selection by MRV FC computes the information that the MRV heuristic needs to do its job. After V = blue, FC detects that the partial assignment {WA=red, Q=green, V=blue} is inconsistent → the algorithm will therefore backtracks immediately. Initial domainRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGBRGB After WA=redR GBRGBRGBRGBRGBRGBRGB RGBRGB After Q=greenR B GR BRGBRGB BRGBRGB After V=blueR B GR BRGBRGB WANTQNSWVSAT
32
CAP 492 Course Dr. Souham Meshoul 32 CONSTRAINT SATISFACTION PROBLEMS Constraint propagation Problem with FC: can not detect all inconsistencies. Example: WA=red, Q=green → NT and SA are forced to be blue but they are adjacent. FC does not detect this as an inconsistency. Solution: Implications on one variable onto other variables should be propagated. → Arc consistency. Requirements: 1. do this fast. 2. Time for propagating constraints should not be greater than reducing the amount of search.
33
CAP 492 Course Dr. Souham Meshoul 33 CONSTRAINT SATISFACTION PROBLEMS
34
CAP 492 Course Dr. Souham Meshoul 34 CONSTRAINT SATISFACTION PROBLEMS Arc consistency (AC) : stronger than F.C What is an arc? a directed link between variables in the constraint graph. Definition: Given the current domains of SA and NSW, the arc is consistent if, for every value x of SA there is some value y of NSW that is consistent with x. Example: SA={B}, NSW={R, B} The arc SA→ NSW is consistent The arc NSW→ SA is not consistent. AC can be applied as a preprocessing before the beginning of the search process or during the search as a propagation step after every assignment.
35
CAP 492 Course Dr. Souham Meshoul 35 CONSTRAINT SATISFACTION PROBLEMS
36
CAP 492 Course Dr. Souham Meshoul 36 CONSTRAINT SATISFACTION PROBLEMS
37
CAP 492 Course Dr. Souham Meshoul 37 CONSTRAINT SATISFACTION PROBLEMS
38
CAP 492 Course Dr. Souham Meshoul 38 CONSTRAINT SATISFACTION PROBLEMS
39
CAP 492 Course Dr. Souham Meshoul 39 CONSTRAINT SATISFACTION PROBLEMS Function AC-3 (csp) returns the CSP, possibly with reduced domains inputs: csp,a binary CSP with variables {X 1, X 2,…., X n } local variables: queue, a queue of arcs, initially all the arcs in csp While queue is not empty do (X i, X j ) ← Remove-first (queue) if Remove-Inconsistent-Values (X i, X j ) then for each X k in neighbors [X i ]- {X i } do add (X k, X i ) to queue Function Remove-Inconsistent-Values (X i, X j ) returns true iff we remove a value removed ← false for each x in Domain [X i ] do if no value y in Domain [X j ] allows (x,y) to satisfy the constraint between X i and X j then delete x from Domain [X i ] ; removed ← true; return removed
40
CAP 492 Course Dr. Souham Meshoul 40 CONSTRAINT SATISFACTION PROBLEMS Example: A B C > < ≠ {1,2,3}
41
CAP 492 Course Dr. Souham Meshoul 41 CONSTRAINT SATISFACTION PROBLEMS Local search for CSPs Many CSPs can be solved efficiently using local search algorithms. They use complete-state formulation. Initial state assigns a value to every variable and the successor function works by changing the value of one variable at a time. In choosing a new value for a variable, the most obvious heuristic is to select the value that results in the minimum number of conflicts with other variables: « The Min-Conflicts » heuristic.
42
CAP 492 Course Dr. Souham Meshoul 42 CONSTRAINT SATISFACTION PROBLEMS Function Min-Conflicts(csp, max_steps) returns a solution or failure inputs csp, a constraint satisfaction problem max_steps, the number of steps allowed before giving up. current ← an initial complete assignment for csp For i=1 to max_steps do If current is a solution for csp then return current var ← a randomly chosen, conflicted variable from VARIABLES[csp] value← the value v for var that minimizes CONFLICTS(var, current,csp) Set var=value in current return failure Notice : Local search is very effective for reasonable initial state.
43
CAP 492 Course Dr. Souham Meshoul 43 CONSTRAINT SATISFACTION PROBLEMS Summary CSP : What is? Variables, Domains of values, and Constraints Goal: an assignment that is complete and consistent. How? Perform search using incremental or complete state formulation. Incremental formulation: Backtracking search that can be improved using heuristics like MRV, most constraining variable and least constrained value. using forward checking Using constraint propagation: AC3 algorithm. Complete formulation: Local search can be applied.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.