Download presentation
Presentation is loading. Please wait.
Published byMoris Mathews Modified over 6 years ago
1
Constraint Satisfaction Problems Lecture # 14, 15 & 16
2
Overview We regularly encounter constraint in our day-to-day lives….
The tasks proposed in the language of constraints are computationally intractable There are two components to every constraint problem: Every constraint problem must include variables. The set of possible values for a given variable is called its domain. Constraints are rules to impose a limitation on the values that a variable may be assigned.
3
Overview A model that includes variables, their domains and constraints is called a constraint network or constraint problem. What is a solution? Anyway! A problem that has one or more solutions is consistent. If there is no solution, then the network is inconsistent.
4
Examples
7
The problem (2/2)
8
Map Colouring Problem Variables - countries (A,B,C,etc.)
red green red yellow green red green yellow yellow green yellow red Map Colouring Problem Variables - countries (A,B,C,etc.) Values - colors (e.g., red, green, yellow) Constraints: C A B D E F G
9
What is Needed? Not just a successor function and goal test
But also a means to propagate the constraints imposed by one queen on the others and an early failure test Explicit representation of constraints and constraint manipulation algorithms
10
Constraint Satisfaction Problem
Set of variables {X1, X2, …, Xn} Each variable Xi has a domain Di of possible values Usually Di is discrete and finite Set of constraints {C1, C2, …, Cp} Each constraint Ck involves a subset of variables and specifies the allowable combinations of values of these variables Assign a value to every variable such that all constraints are satisfied
11
Example: 8-Queens Problem
8 variables Xi, i = 1 to 8 Domain for each variable {1,2,…,8} Constraint: No queen attacks other queen.
12
Example: Map Coloring 7 variables {WA,NT,SA,Q,NSW,V,T}
Each variable has the same domain {red, green, blue} Constraint: No two adjacent variables have the same value: WANT, WASA, NTSA, NTQ, SAQ, SANSW, SAV,QNSW, NSWV
13
Example: Task Scheduling
Constraints: T1 must be done during T3 T2 must be achieved before T1 starts T2 must overlap with T3 T4 must start after T1 is complete
14
Constraint Graph Binary constraints T1 T2 T3 T4
WA NT SA Q NSW V Two variables are adjacent or neighbors if they are connected by an edge or an arc
15
Variables & Domains Discrete variables – Finite domains (size d)
e.g., color-mapping (d colors), Boolean CSPs (variables are either true or false, d=2), etc. Number of complete assignment: O(dn) – Infinite domains (integers, strings, etc.) Job scheduling, variables are start and end days for each job A constraint language is needed, e.g., StartJob1 +5 ≤ StartJob3 Continuous variables e.g. building an airline schedule or class schedule
16
Varieties of constraints
Unary constraints involve a single variable. e.g. SA green Binary constraints involve pairs of variables. e.g. SA WA Higher-order constraints involve 3 or more variables. Professors A, B,and C cannot be on a committee together Can always be represented by multiple binary constraints Preference (soft constraints) e.g. red is better than green often can be represented by a cost for each variable assignment
17
Map Coloring {} WA=red WA=green WA=blue NT=green NT=blue Q=red Q=blue
SA Q NSW V T WA NT SA Q NSW V T
18
CSP as a standard search problem
A CSP can easily be expressed as a standard search problem. Incremental formulation Initial State: the empty assignment {} Successor function: Assign a value to any unassigned variable provided that it does not violate a constraint Goal test: the current assignment is complete (by construction its consistent) Path cost: constant cost for every step (not really relevant) Local search techniques tend to work well
19
Commutativity CSPs are commutative.
The order of any given set of actions has no effect on the outcome. Example: choose colors for Australian territories one at a time [WA=red then NT=green] same as [NT=green then WA=red] All CSP search algorithms can generate successors by considering assignments for only a single variable at each node in the search tree (will need to figure out later which variable to assign a value to at each node)
20
Backtracking search Prune the path if constraints violated
Similar to Depth-first search Chooses values for one variable at a time and backtracks when a variable has no legal values left to assign. Algorithm: – Select the next unassigned variable X – For each value xi # DX * If the value satisfies the constraint, assign X = xi and exit the loop – If an assignment was found, continue with the next variable – If no assignment was found, go back to the preceding variable and try a different value for it.
21
Backtracking example
22
Backtracking example
23
Backtracking example
24
Backtracking example
25
5 Queens Problem
26
CONTD…
27
CONTD…
28
CONTD…
29
EXAMPLE
30
Questions Which variable X should be assigned a value next?
In which order should its domain D be sorted? What are the implications of a partial assignment for yet unassigned variables?
31
Choice of Variable
32
Choice of Variable 3 2 WA NT SA Q NSW V T 3 SA 3 5 2 Most-constraining-variable heuristic: Select the variable that is involved in the largest number of constraints on other unassigned variables
33
Choice of Variable Most-constrained-variable heuristic:
Select a variable with the fewest remaining values – also called Minimum Remaining Values (MRV) heuristic … – Choose the variable with the most constraints (on values) from the remaining variables • If a variable X with zero legal values remained, MRV selects it and causes a failure immediately • The search tree can be therefore pruned MRV doesn’t help at all in choosing the first variable …
34
Choice Of Value
35
Choice of Value {} WA NT SA Q NSW V T
36
Choice of Value {blue} WA NT SA Q NSW V T Least-constraining-value heuristic: Prefer the value that leaves the largest subset of legal values for other unassigned variables
37
Choice of Value Least-Constraining-Value heuristic
– Given a variable, choose the value that rules out the fewest chooses of values for the remaining (neighboring) variables i.e., leave the maximum flexibility for subsequent variable assignments If all the solutions (not just the first one) are needed, the value ordering doesn’t matter
38
Constraint Propagation …
… is the process of determining how the possible values of one variable affect the possible values of other variables Can we detect inevitable failure early? And avoid it later? Forward checking idea: keep track of remaining legal values for unassigned variables. Terminate search when any variable has no legal values.
39
Forward Checking After a variable X is assigned a value v, look 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 v
40
Map Coloring T WA NT SA Q NSW V WA NT Q NSW V SA T RGB
41
Map Coloring T WA NT SA Q NSW V WA NT Q NSW V SA T RGB R GB
42
Map Coloring T WA NT SA Q NSW V WA NT Q NSW V SA T RGB R GB B G RB
43
Map Coloring Impossible assignments that forward
SA Q NSW V Impossible assignments that forward checking do not detect WA NT Q NSW V SA T RGB R GB B G RB Forward checking doesn’t provide early detection for all inconsistency -- NT and SA can’t both be blue
44
Constraint propagation
Forward checking propagates information from assigned to unassigned variables, but doesn't provide early detection for all failures: NT and SA cannot both be blue! Constraint propagation repeatedly enforces constraints locally T WA NT SA Q NSW V
45
Arc consistency An Arc X Y is consistent if
for every value x of X there is some value y consistent with x Consider state of search after WA and Q are assigned: SA NSW is consistent if SA=blue and NSW=red
46
Arc consistency X Y is consistent if
for every value x of X there is some value y consistent with x NSW SA is consistent if NSW=red and SA=blue NSW=blue and SA=???
47
Arc consistency Can enforce arc-consistency:
Arc can be made consistent by removing blue from NSW Continue to propagate constraints…. Check V NSW Not consistent for V = red Remove red from V
48
Continue to propagate constraints…. SA NT is not consistent
Arc consistency Continue to propagate constraints…. SA NT is not consistent and cannot be made consistent Arc consistency detects failure earlier than FC
49
Arc consistency checking
Can be run as a preprocessor or after each assignment Or as preprocessing before search starts AC must be run repeatedly until no inconsistency remains Trade-off Requires some overhead to do, but generally more effective than direct search In effect it can eliminate large (inconsistent) parts of the state space more effectively than search can Need a systematic method for arc-checking If X loses a value, neighbors of X need to be rechecked: i.e. incoming arcs can become inconsistent again (outgoing arcs will stay consistent).
50
Further improvements Intelligent backtracking
Standard form is chronological backtracking i.e. try different value for preceding variable. More intelligent, backtrack to conflict set. Set of variables that caused the failure or set of previously assigned variables that are connected to X by constraints. Backjumping moves back to most recent element of the conflict set. Forward checking can be used to determine conflict set.
51
Summary CSPs are a special kind of problem:
states defined by values of a fixed set of variables goal test defined by constraints on variable values Backtracking = depth-first search with one variable assigned per node Variable ordering and value selection heuristics help significantly Forward checking prevents assignments that guarantee later failure Constraint propagation (e.g., arc consistency) does additional work to constrain values and detect inconsistencies
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.