Upload
amena-calderon
View
33
Download
1
Embed Size (px)
DESCRIPTION
Course: Engineering Artificial Intelligence. Dr. Radu Marinescu. Lecture 4. Today’s class. Constraint satisfaction problems (CSP). Sudoku. Variables: 81 slots Domains = {1,2,3,4,5,6,7,8,9} Constraints: 27 not-equal. Constraint propagation. 2 3 4 6. 2. - PowerPoint PPT Presentation
Citation preview
University College Cork (Ireland) Department of Civil and Environmental Engineering
Course:Engineering Artificial Intelligence
Dr. Radu Marinescu
Lecture 4
University College Cork (Ireland) Department of Civil and Environmental Engineering
Today’s class
o Constraint satisfaction problems (CSP)
R. Marinescu October-2009 page 2
University College Cork (Ireland) Department of Civil and Environmental Engineering
Each row, column and major block must be alldifferent
“Well posed” if it has unique solution: 27 constraints
2 34 62
Constraint propagation
•Variables: 81 slots
•Domains = {1,2,3,4,5,6,7,8,9}
•Constraints: •27 not-equal
Sudoku
University College Cork (Ireland) Department of Civil and Environmental Engineering
Sudoku
Each row, column and major block must be alldifferent
“Well posed” if it has unique solution: 27 constraints
University College Cork (Ireland) Department of Civil and Environmental Engineering
Constraint satisfaction problems
o CSP• state – is defined by variable Xi with values from domain Di
• goal test – is a set of constraints specifying allowable combinations of values for subsets of variables
o Applications for CSPs• Scheduling tasks (transportation, maintenance)• Robot planning tasks• Puzzles• Tail-Gate assignment (airports)• Radio-link frequency assignment (telecom)• …
R. Marinescu October-2009 page 5
University College Cork (Ireland) Department of Civil and Environmental Engineering
Example: map coloring
o variables: WA, NT, Q, SA, NSW, V, To domains: Di = {red, green, blue}o constraints: adjacent regions must have different colors
• e.g., WA ≠ NT or (WA, NT) in {(red, green), (red, blue), (green, red), (green, blue), (blue, red), (blue, green)}
R. Marinescu October-2009 page 6
University College Cork (Ireland) Department of Civil and Environmental Engineering
Example: map coloring
o Solutions are complete and consistent assignments• E.g., WA = red, NT = green, SA = blue, Q = red, NSW = green, V = red, T = green
R. Marinescu October-2009 page 7
University College Cork (Ireland) Department of Civil and Environmental Engineering
Constraint graph
R. Marinescu October-2009 page 8
Binary CSP
variable Vi withvalues in domain Di
General class of problems:
Unary constraint arc
Binaryconstraintarc
(Unary constraintjust cut down domains)
This diagram is called a constraint graph
University College Cork (Ireland) Department of Civil and Environmental Engineering
Constraint graph
R. Marinescu October-2009 page 9
Binary CSP
variable Vi withvalues in domain Di
General class of problems:
Unary constraint arc
Binaryconstraintarc
(Unary constraintjust cut down domains)
This diagram is called a constraint graph
Basic problem:Find dj in Di for each Vi s.t. all constraints satisfied(finding consistent labeling for variables)
University College Cork (Ireland) Department of Civil and Environmental Engineering
N-Queens as CSP
R. Marinescu October-2009 page 10
1 Q
2 Q
3 Q
4 Q
1 2 3 4
Place N queens on an NxNchessboard so that none canattack the other
Classic “benchmark” problem
Variables
Domains
Constraints
are board positions in NxN chessboard
Queen or blank
Two positions on a line (vertical, horizontal,diagonal) cannot both be Q
University College Cork (Ireland) Department of Civil and Environmental Engineering
Scheduling as CSP
R. Marinescu October-2009 page 11
Choose time for activities e.g.,observations on Hubble telescope, or terms to takerequired classes
5
4
3
2
1
time
activity
Variables
Domains
Constraints
are activities
sets of start times (or “chunks” of time)
1. Activities that use the sameresource cannot overlap in time
2. Preconditions satisfied
University College Cork (Ireland) Department of Civil and Environmental Engineering
3-SAT as CSP
R. Marinescu October-2009 page 12
Variables
Domains
Constraints
clauses
Boolean variable assignments that makeclauses trueClauses with shared Boolean variables mustagree on value of variables
Find values for Booleanvariables A, B, C, … thatsatisfy the formula
The original NP-complete problem
...CBACBA
University College Cork (Ireland) Department of Civil and Environmental Engineering
Varieties of CSPs
o Discrete variables• Finite domains
n variables, domain size d → O(dn) complete assignments E.g., map coloring, n-queens, …
• Infinite domains Integers, strings E.g., job scheduling (variables are start/end days of each job)
o Continuous variables• Usually, the domain of the variables are real numbers
R. Marinescu October-2009 page 13
University College Cork (Ireland) Department of Civil and Environmental Engineering
Varieties of constraints
o Unary constraints involve one variable• E.g., SA ≠ green
o Binary constraints involve pairs of variables• E.g., SA ≠ WA
o Higher-order constraints involve 3 or more variables
• E.g., crypt-arithmetic column constraints (see next)
R. Marinescu October-2009 page 14
University College Cork (Ireland) Department of Civil and Environmental Engineering
Example: crypt-arithmetic puzzle
R. Marinescu October-2009 page 15
Variables
Domains
Constraints
F T U O R W X1 X2 X3
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
AllDiff(F, T, U, O, R, W)O + O = R + 10∙X1
X1 + W + W = U + 10∙X2
X2 + T + T = O + 10∙X3
X3 = FF ≠ 0T ≠ 0
University College Cork (Ireland) Department of Civil and Environmental Engineering
Good news / Bad news
o Good news – very general & interesting class problems
o Bad news – includes NP-hard (intractable) problems
So, good behavior is a function of domain not the formulation as a CSP
R. Marinescu October-2009 page 16
University College Cork (Ireland) Department of Civil and Environmental Engineering
CSP example
Given 40 courses (8.01, 8.02, …, 6.840) and 10 terms (Fall 1, Spring 1, ,,, Spring 5). Find a legal schedule
Constraints
Pre-requisites
Courses offered on limited terms
Limited number of courses per term
Avoid time conflicts
Note: CSPs are not for expressing (soft) preferences, e.g. minimize difficulty, balance subject areas, etc
R. Marinescu October-2009 page 17
University College Cork (Ireland) Department of Civil and Environmental Engineering
Choice of variables & values
VARIABLES DOMAINS
R. Marinescu October-2009 page 18
A. Terms? Legal combinations of for example 4courses (but this is huge set of values)
B. Terms Slots? Courses offered during that term
Subdivide terms into slots e.g. 4 of them(Fall 1,1) (Fall 1,2)(Fall 1,3) (Fall 1,3)
C. Courses? Terms or term slots (Term slots allowexpressing constraints on limited numberof courses/term)
University College Cork (Ireland) Department of Civil and Environmental Engineering
Constraints
R. Marinescu October-2009 page 19
Use courses as variables and term slots as values
Prerequisite > 6.001 6.034
Term before
Term after
For pairs of courses thatmust be ordered
Courses offered only in some terms > Filter domain
Avoid time conflicts> 6.001 6.034
Term not equal
For pairs offered at sameor overlapping times
University College Cork (Ireland) Department of Civil and Environmental Engineering
Solving CSPs
o Solving CSPs involve some combination of:
• Constraint propagation, to eliminate values that could not be part of any solution
• Search, to explore valid assignments
R. Marinescu October-2009 page 20
University College Cork (Ireland) Department of Civil and Environmental Engineering
Constraint propagation (aka Arc Consistency)
o Arc consistency eliminates values from domain of variable that can never be part of a consistent solution
o Directed arc (Vi, Vj) is arc consistent if
R. Marinescu October-2009 page 21
ji VV
arc on the constraint by the allowed is y)(x,st , ji DyDx
University College Cork (Ireland) Department of Civil and Environmental Engineering
Constraint propagation (aka Arc Consistency)
o Arc consistency eliminates values from domain of variable that can never be part of a consistent solution
o Directed arc (Vi, Vj) is arc consistent if
o We can achieve consistency on arc by deleting values from Di
(domain of variable at tail of constraint arc) that fail condition
R. Marinescu October-2009 page 22
ji VV
arc on the constraint by the allowed is y)(x,st , ji DyDx
University College Cork (Ireland) Department of Civil and Environmental Engineering
Constraint propagation (aka Arc Consistency)
o Arc consistency eliminates values from domain of variable that can never be part of a consistent solution
o Directed arc (Vi, Vj) is arc consistent if
o We can achieve consistency on arc by deleting values from Di
(domain of variable at tail of constraint arc) that fail condition
o Assume domain size at most d and there are e binary constraints
o A simple algorithm for arc consistency is O(ed3) – note that just verifying arc consistency takes O(ed2) for each arc
R. Marinescu October-2009 page 23
ji VV
arc on the constraint by the allowed is y)(x,st , ji DyDx
University College Cork (Ireland) Department of Civil and Environmental Engineering
Constraint propagation example
R. Marinescu October-2009 page 24
Graph coloringinitial domains are indicated R, G, B
R, G G
V1
V2 V3
different-color constraint
University College Cork (Ireland) Department of Civil and Environmental Engineering
Constraint propagation example
R. Marinescu October-2009 page 25
Graph coloringinitial domains are indicated R, G, B
R, G G
V1
V2 V3
different-color constraint
Arc examined Value deleted
R, G, B
R, G G
V1
V2 V3
Each undirected arc is really two directed constraint arcs, theeffects shown above are from examining BOTH arcs.
University College Cork (Ireland) Department of Civil and Environmental Engineering
Constraint propagation example
R. Marinescu October-2009 page 26
Graph coloringinitial domains are indicated R, G, B
R, G G
V1
V2 V3
different-color constraint
Arc examined Value deleted
V1 – V2 none R, G, B
R, G G
V1
V2 V3
Each undirected arc is really two directed constraint arcs, theeffects shown above are from examining BOTH arcs.
University College Cork (Ireland) Department of Civil and Environmental Engineering
Constraint propagation example
R. Marinescu October-2009 page 27
Graph coloringinitial domains are indicated R, G, B
R, G G
V1
V2 V3
different-color constraint
Arc examined Value deleted
V1 – V2 none
V1 – V3 V1(G)R, B
R, G G
V1
V2 V3
Each undirected arc is really two directed constraint arcs, theeffects shown above are from examining BOTH arcs.
University College Cork (Ireland) Department of Civil and Environmental Engineering
Constraint propagation example
R. Marinescu October-2009 page 28
Graph coloringinitial domains are indicated R, G, B
R, G G
V1
V2 V3
different-color constraint
Arc examined Value deleted
V1 – V2 none
V1 – V3 V1(G)
V2 – V3 V2(G)
R, B
R G
V1
V2 V3
Each undirected arc is really two directed constraint arcs, theeffects shown above are from examining BOTH arcs.
University College Cork (Ireland) Department of Civil and Environmental Engineering
Constraint propagation example
R. Marinescu October-2009 page 29
Graph coloringinitial domains are indicated R, G, B
R, G G
V1
V2 V3
different-color constraint
Arc examined Value deleted
V1 – V2 none
V1 – V3 V1(G)
V2 – V3 V2(G)
V1 – V2 V1(R)
B
R G
V1
V2 V3
Each undirected arc is really two directed constraint arcs, theeffects shown above are from examining BOTH arcs.
University College Cork (Ireland) Department of Civil and Environmental Engineering
Constraint propagation example
R. Marinescu October-2009 page 30
Graph coloringinitial domains are indicated R, G, B
R, G G
V1
V2 V3
different-color constraint
Arc examined Value deleted
V1 – V2 none
V1 – V3 V1(G)
V2 – V3 V2(G)
V1 – V2 V1(R)
V1 – V3 none
B
R G
V1
V2 V3
Each undirected arc is really two directed constraint arcs, theeffects shown above are from examining BOTH arcs.
University College Cork (Ireland) Department of Civil and Environmental Engineering
Constraint propagation example
R. Marinescu October-2009 page 31
Graph coloringinitial domains are indicated R, G, B
R, G G
V1
V2 V3
different-color constraint
Arc examined Value deleted
V1 – V2 none
V1 – V3 V1(G)
V2 – V3 V2(G)
V1 – V2 V1(R)
V1 – V3 none
V2 – V3 none
B
R G
V1
V2 V3
CSP is arc-consistent
University College Cork (Ireland) Department of Civil and Environmental Engineering
But, arc consistency is not enough in general
R. Marinescu October-2009 page 32
R, G
R, G R, G
arc consistent but nosolutions
Graph coloring
University College Cork (Ireland) Department of Civil and Environmental Engineering
But, arc consistency is not enough in general
R. Marinescu October-2009 page 33
R, G
R, G R, G
arc consistent but nosolutions
Graph coloring
B, G
R, G R, G
arc consistent but 2 solutions: B,R,G; B,G,R
University College Cork (Ireland) Department of Civil and Environmental Engineering
But, arc consistency is not enough in general
R. Marinescu October-2009 page 34
R, G
R, G R, G
arc consistent but nosolutions
Graph coloring
B, G
R, G R, G
arc consistent but 2 solutions: B,R,G; B,G,R
B, G
R, G R, G
arc consistent but 1 solutions: B,R,G;
Assume B, R notallowed
University College Cork (Ireland) Department of Civil and Environmental Engineering
But, arc consistency is not enough in general
R. Marinescu October-2009 page 35
R, G
R, G R, G
arc consistent but nosolutions
Graph coloring
B, G
R, G R, G
arc consistent but 2 solutions: B,R,G; B,G,R
B, G
R, G R, G
arc consistent but 1 solutions: B,R,G;
Assume B, R notallowed
Need to search to find solutions (if any)
University College Cork (Ireland) Department of Civil and Environmental Engineering
Searching for solutions – backtracking (BT)
o Standard search formulation• Initial state: the empty assignment {}• Successor function: assign a value to an unassigned variable that
does not conflict with the current assignment fail is no legal assignments
• Goal test: the current assignment is complete
1.This is the same for all CSPs2.Every solution appears at depth n (for n variables)3.Path is irrelevant4.Depth-first search for CSPs is called backtracking5.Variable assignments are commutative (e.g., [WA=red then
NT=blue] is the same as [NT=blue then WA=red]
R. Marinescu October-2009 page 36
University College Cork (Ireland) Department of Civil and Environmental Engineering
Searching for solutions – backtracking (BT)
R. Marinescu October-2009 page 37
When we have too many values in domain (and/or constraints are weak) arc consistency doesn’tdo much, so we need to search. Simplest approach is pure backtracking (depth-first search)
RG
B
R G R G R G
R G R G R G R G
V1 assignments
V2 assignments
V3 assignments
R, G, B
R, G R, G
V1
V2 V3
University College Cork (Ireland) Department of Civil and Environmental Engineering
Searching for solutions – backtracking (BT)
R. Marinescu October-2009 page 38
When we have too many values in domain (and/or constraints are weak) arc consistency doesn’tdo much, so we need to search. Simplest approach is pure backtracking (depth-first search)
RG
B
R G R G R G
R G R G R G R G
V1 assignments
V2 assignments
V3 assignments
R, G, B
R, G R, G
V1
V2 V3
Inconsistentwith V1 = R
Backup atinconsistentassignment
University College Cork (Ireland) Department of Civil and Environmental Engineering
Searching for solutions – backtracking (BT)
R. Marinescu October-2009 page 39
When we have too many values in domain (and/or constraints are weak) arc consistency doesn’tdo much, so we need to search. Simplest approach is pure backtracking (depth-first search)
RG
B
R G R G R G
R G R G R G R G
V1 assignments
V2 assignments
V3 assignments
R, G, B
R, G R, G
V1
V2 V3
Inconsistentwith V1 = R
Backup atinconsistentassignment
University College Cork (Ireland) Department of Civil and Environmental Engineering
Searching for solutions – backtracking (BT)
R. Marinescu October-2009 page 40
When we have too many values in domain (and/or constraints are weak) arc consistency doesn’tdo much, so we need to search. Simplest approach is pure backtracking (depth-first search)
RG
B
R G R G R G
R G R G R G R G
V1 assignments
V2 assignments
V3 assignments
R, G, B
R, G R, G
V1
V2 V3
Inconsistentwith V1 = R
Backup atinconsistentassignment
Inconsistentwith V2 = G
University College Cork (Ireland) Department of Civil and Environmental Engineering
Searching for solutions – backtracking (BT)
R. Marinescu October-2009 page 41
When we have too many values in domain (and/or constraints are weak) arc consistency doesn’tdo much, so we need to search. Simplest approach is pure backtracking (depth-first search)
RG
B
R G R G R G
R G R G R G R G
V1 assignments
V2 assignments
V3 assignments
R, G, B
R, G R, G
V1
V2 V3
Inconsistentwith V1 = R
Backup atinconsistentassignment
Inconsistentwith V2 = G
consistent
University College Cork (Ireland) Department of Civil and Environmental Engineering
Combine backtracking and constraint propagation
o A node in BT tree is partial assignment in which the domain of each variable has been set (tentatively) to singleton set
o Use constraint propagation (arc-consistency) to propagate the effect of this tentative assignment i.e., eliminate values inconsistent with current values
R. Marinescu October-2009 page 42
University College Cork (Ireland) Department of Civil and Environmental Engineering
Combine backtracking and constraint propagation
o A node in BT tree is partial assignment in which the domain of each variable has been set (tentatively) to singleton set
o Use constraint propagation (arc-consistency) to propagate the effect of this tentative assignment i.e., eliminate values inconsistent with current values
o Question: how much propagation to do?
R. Marinescu October-2009 page 43
University College Cork (Ireland) Department of Civil and Environmental Engineering
Combine backtracking and constraint propagation
o A node in BT tree is partial assignment in which the domain of each variable has been set (tentatively) to singleton set
o Use constraint propagation (arc-consistency) to propagate the effect of this tentative assignment i.e., eliminate values inconsistent with current values
o Question: how much propagation to do?o Answer: not much, just local propagations from domains
with unique assignments, which is called forward checking (FC). This conclusion is not necessarily obvious, but it generally holds in practice
R. Marinescu October-2009 page 44
University College Cork (Ireland) Department of Civil and Environmental Engineering
Backtracking with forward checking (BT-FC)
R. Marinescu October-2009 page 45
When examining assignment Vi = dk, remove any values inconsistent with that assignmentFrom neighboring domains in the constraint graph
RV1 assignments
V2 assignments
V3 assignments
R, G, B
R, G R, G
V1
V2 V3
University College Cork (Ireland) Department of Civil and Environmental Engineering
Backtracking with forward checking (BT-FC)
R. Marinescu October-2009 page 46
When examining assignment Vi = dk, remove any values inconsistent with that assignmentFrom neighboring domains in the constraint graph
RV1 assignments
V2 assignments
V3 assignments
R
G G
V1
V2 V3
G
University College Cork (Ireland) Department of Civil and Environmental Engineering
Backtracking with forward checking (BT-FC)
R. Marinescu October-2009 page 47
When examining assignment Vi = dk, remove any values inconsistent with that assignmentFrom neighboring domains in the constraint graph
RV1 assignments
V2 assignments
V3 assignments
R
G
V1
V2 V3
G
We have a conflictwhenever a domainbecomes empty
University College Cork (Ireland) Department of Civil and Environmental Engineering
Backtracking with forward checking (BT-FC)
R. Marinescu October-2009 page 48
When examining assignment Vi = dk, remove any values inconsistent with that assignmentFrom neighboring domains in the constraint graph
V1 assignments
V2 assignments
V3 assignments
When backing up, need torestore domain values,since deletions were done to reach consistency withtentative assignmentsconsidered during search
G
R, G, B
R, G R, G
V1
V2 V3
University College Cork (Ireland) Department of Civil and Environmental Engineering
Backtracking with forward checking (BT-FC)
R. Marinescu October-2009 page 49
When examining assignment Vi = dk, remove any values inconsistent with that assignmentFrom neighboring domains in the constraint graph
V1 assignments
V2 assignments
V3 assignments
G
G
R R
V1
V2 V3
University College Cork (Ireland) Department of Civil and Environmental Engineering
Backtracking with forward checking (BT-FC)
R. Marinescu October-2009 page 50
When examining assignment Vi = dk, remove any values inconsistent with that assignmentFrom neighboring domains in the constraint graph
V1 assignments
V2 assignments
V3 assignments
G
G
R R
V1
V2 V3
R
University College Cork (Ireland) Department of Civil and Environmental Engineering
Backtracking with forward checking (BT-FC)
R. Marinescu October-2009 page 51
When examining assignment Vi = dk, remove any values inconsistent with that assignmentFrom neighboring domains in the constraint graph
V1 assignments
V2 assignments
V3 assignments
G
G
R R
V1
V2 V3
R
University College Cork (Ireland) Department of Civil and Environmental Engineering
Backtracking with forward checking (BT-FC)
R. Marinescu October-2009 page 52
When examining assignment Vi = dk, remove any values inconsistent with that assignmentFrom neighboring domains in the constraint graph
V1 assignments
V2 assignments
V3 assignments
R, G, B
R, G R, G
V1
V2 V3
B
University College Cork (Ireland) Department of Civil and Environmental Engineering
Backtracking with forward checking (BT-FC)
R. Marinescu October-2009 page 53
When examining assignment Vi = dk, remove any values inconsistent with that assignmentFrom neighboring domains in the constraint graph
V1 assignments
V2 assignments
V3 assignments
B
R, G R, G
V1
V2 V3
B
R
University College Cork (Ireland) Department of Civil and Environmental Engineering
Backtracking with forward checking (BT-FC)
R. Marinescu October-2009 page 54
When examining assignment Vi = dk, remove any values inconsistent with that assignmentFrom neighboring domains in the constraint graph
V1 assignments
V2 assignments
V3 assignments
B
R G
V1
V2 V3
B
R
University College Cork (Ireland) Department of Civil and Environmental Engineering
Backtracking with forward checking (BT-FC)
R. Marinescu October-2009 page 55
When examining assignment Vi = dk, remove any values inconsistent with that assignmentFrom neighboring domains in the constraint graph
V1 assignments
V2 assignments
V3 assignments
B
R G
V1
V2 V3
B
R
G
University College Cork (Ireland) Department of Civil and Environmental Engineering
Backtracking with forward checking (BT-FC)
R. Marinescu October-2009 page 56
When examining assignment Vi = dk, remove any values inconsistent with that assignmentFrom neighboring domains in the constraint graph
V1 assignments
V2 assignments
V3 assignments
B
G R
V1
V2 V3
B
G
R
University College Cork (Ireland) Department of Civil and Environmental Engineering
Backtracking with forward checking (BT-FC)
R. Marinescu October-2009 page 57
When examining assignment Vi = dk, remove any values inconsistent with that assignmentFrom neighboring domains in the constraint graph
V1 assignments
V2 assignments
V3 assignments
B
G R
V1
V2 V3
B
G
R
No need to check previous assignments
Generally preferable to pure BT
University College Cork (Ireland) Department of Civil and Environmental Engineering
BT-FC with dynamic ordering
o Traditional backtracking uses fixed ordering of variables & values, e.g., random order or place variables with many constraints first
o We can usually do better by choosing an order dynamically as the search proceeds
R. Marinescu October-2009 page 58
University College Cork (Ireland) Department of Civil and Environmental Engineering
BT-FC with dynamic ordering
o Traditional backtracking uses fixed ordering of variables & values, e.g., random order or place variables with many constraints first
o We can usually do better by choosing an order dynamically as the search proceeds
1. Most constrained variable• When doing forward-checking, pick variable with fewest legal
values to assign next (minimizes branching factor)
R. Marinescu October-2009 page 59
University College Cork (Ireland) Department of Civil and Environmental Engineering
BT-FC with dynamic ordering
o Traditional backtracking uses fixed ordering of variables & values, e.g., random order or place variables with many constraints first
o We can usually do better by choosing an order dynamically as the search proceeds
1. Most constrained variable• When doing forward-checking, pick variable with fewest legal
values to assign next (minimizes branching factor)
2. Least constraining value• Choose value that rules out the fewest values from neighboring
domains
R. Marinescu October-2009 page 60
University College Cork (Ireland) Department of Civil and Environmental Engineering
Constraint optimization problems
o COP formulation• Variables: X1, X2, …, Xn with domains D1, D2, …, Dn
• Constraints: C1, C2, …, Cm
• Objective function: f(X1, …, Xn)
o Goal: find a solution that satisfies all constraints and minimizes the objective function
o Example• Maintenance scheduling in smart buildings: schedule a set of
maintenance tasks (eg, clean rooms, repair outlet) such that there is no overlap between tasks and the sum of costs is minimized
o Solution techniques• Depth-first Branch-and-Bound search
R. Marinescu October-2009 page 61
University College Cork (Ireland) Department of Civil and Environmental Engineering
Local search
o In many problems, the path to the goal is irrelevant; the goal state itself is the solution
o State space = set of "complete" configurationso Find configuration satisfying constraints, e.g., n-
queens
o In such cases, we can use local search algorithms which keep a single "current" state, try to improve it
o Constant space. Good for offline and online search
R. Marinescu October-2009 page 62
University College Cork (Ireland) Department of Civil and Environmental Engineering
Local search for CSPs
o Hill-climbing, simulated annealing typically work with “complete” states, i.e., all variables assigned
o Apply to CSPs• Allow states with unsatisfied constraints• Operators reassign variable values• Variable selection
Randomly select any conflicted variable• Value selection by min-conflict heuristic
Choose value that violates the fewest constraints i.e., hill climbing: h(n) = total number of violated constraints
R. Marinescu October-2009 page 63
University College Cork (Ireland) Department of Civil and Environmental Engineering
Example: 4-Queens problem
o States: 4 queens in 4 columns (44 = 256 states)o Actions: move queen to columno Goal test: no attackso Evaluation: h(n) = number of attacks
o Given random initial state, can solve n-queens in almost constant time for arbitrary n with high probability (e.g., n = 10,000,000)
R. Marinescu October-2009 page 64
University College Cork (Ireland) Department of Civil and Environmental Engineering
Summary
o 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
o Backtracking = depth-first search with one variable assigned per node
o Variable ordering and value selection heuristics help significantly
o Forward checking prevents assignments that guarantee later failure
o Constraint propagation (e.g., arc consistency) does additional work to constrain values and detect inconsistencies
R. Marinescu October-2009 page 65