Date post: | 03-Jan-2016 |
Category: |
Documents |
Upload: | alan-phelps |
View: | 224 times |
Download: | 1 times |
PSUCS 370 – Introduction to Artificial Intelligence2
Outline
Constraint Satisfaction Problems (CSP) Backtracking search for CSPs Local search for CSPs
PSUCS 370 – Introduction to Artificial Intelligence
Intro Example: 8-QueensIntro Example: 8-Queens
• Purely generate-and-test• The “search” tree is only used to enumerate all possible 648 combinations
PSUCS 370 – Introduction to Artificial Intelligence
Intro Example: 8-QueensIntro Example: 8-Queens
Another form of generate-and-test, with noredundancies “only” 88 combinations
PSUCS 370 – Introduction to Artificial Intelligence
What is Needed?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
PSUCS 370 – Introduction to Artificial Intelligence
Constraint Satisfaction Constraint Satisfaction ProblemProblem 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
PSUCS 370 – Introduction to Artificial Intelligence
Constraint Satisfaction Constraint Satisfaction ProblemProblem 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
PSUCS 370 – Introduction to Artificial Intelligence
Example: 8-Queens Example: 8-Queens ProblemProblem 64 variables Xij, i = 1 to 8, j = 1 to 8 Domain for each variable {yes,no} Constraints are of the forms:
Xij = yes Xik = no for all k = 1 to 8, kj Xij = yes Xkj = no for all k = 1 to 8, kI Similar constraints for diagonals
PSUCS 370 – Introduction to Artificial Intelligence
Example: 8-Queens Example: 8-Queens ProblemProblem 8 variables Xi, i = 1 to 8 Domain for each variable {1,2,…,8} Constraints are of the forms:
Xi = k Xj k for all j = 1 to 8, ji Similar constraints for diagonals
PSUCS 370 – Introduction to Artificial Intelligence
Example: Map ColoringExample: Map Coloring
• 7 variables {WA,NT,SA,Q,NSW,V,T}
• Each variable has the same domain {red, green, blue}• No two adjacent variables have the same value: WANT, WASA, NTSA, NTQ, SAQ, SANSW, SAV,QNSW, NSWV
WA
NT
SA
Q
NSWV
T
WA
NT
SA
Q
NSWV
T
PSUCS 370 – Introduction to Artificial Intelligence
Example: Street PuzzleExample: Street Puzzle
1 2 3 4 5
Ni = {English, Spaniard, Japanese, Italian, Norwegian}Ci = {Red, Green, White, Yellow, Blue}Di = {Tea, Coffee, Milk, Fruit-juice, Water}Ji = {Painter, Sculptor, Diplomat, Violonist, Doctor}Ai = {Dog, Snails, Fox, Horse, Zebra}
PSUCS 370 – Introduction to Artificial Intelligence
Example: Street PuzzleExample: Street Puzzle
1 2 3 4 5Ni = {English, Spaniard, Japanese, Italian, Norwegian}Ci = {Red, Green, White, Yellow, Blue}Di = {Tea, Coffee, Milk, Fruit-juice, Water}Ji = {Painter, Sculptor, Diplomat, Violonist, Doctor}Ai = {Dog, Snails, Fox, Horse, Zebra}
The Englishman lives in the Red houseThe Spaniard has a DogThe Japanese is a PainterThe Italian drinks TeaThe Norwegian lives in the first house on the leftThe owner of the Green house drinks CoffeeThe Green house is on the right of the White houseThe Sculptor breeds SnailsThe Diplomat lives in the Yellow houseThe owner of the middle house drinks MilkThe Norwegian lives next door to the Blue houseThe Violonist drinks Fruit juiceThe Fox is in the house next to the Doctor’sThe Horse is next to the Diplomat’s
Who owns the Zebra?Who drinks Water?
PSUCS 370 – Introduction to Artificial Intelligence
Example: Task SchedulingExample: Task Scheduling
T1 must be done during T3T2 must be achieved before T1 startsT2 must overlap with T3T4 must start after T1 is complete
• Are the constraints compatible?• Find the temporal relation between every two tasks
T1
T2
T3
T4
PSUCS 370 – Introduction to Artificial Intelligence
Finite vs. Infinite CSPFinite vs. Infinite CSP
Finite domains of values finite CSP Infinite domains infinite CSP
PSUCS 370 – Introduction to Artificial Intelligence
Finite vs. Infinite CSPFinite vs. Infinite CSP
Finite domains of values finite CSP Infinite domains infinite CSP We will only consider finite CSP
PSUCS 370 – Introduction to Artificial Intelligence
Constraint GraphConstraint GraphBinary constraints
T
WA
NT
SA
Q
NSW
V
Two variables are adjacent or neighbors if theyare connected by an edge or an arc
T1
T2
T3
T4
PSUCS 370 – Introduction to Artificial Intelligence
CSP as a Search ProblemCSP as a Search Problem
Initial state: empty assignment Successor function: a value is assigned to any
unassigned variable, which does not conflict with the currently assigned variables
Goal test: the assignment is complete Path cost: irrelevant
PSUCS 370 – Introduction to Artificial Intelligence
CSP as a Search ProblemCSP as a Search Problem Initial state: empty assignment Successor function: a value is assigned to
any unassigned variable, which does not conflict with the currently assigned variables
Goal test: the assignment is complete Path cost: irrelevant
n variables of domain size d O(dn) distinct complete assignments
PSUCS 370 – Introduction to Artificial Intelligence
RemarkRemark
Finite CSP include 3SAT as a special case (see class of CS311)
3SAT is known to be NP-complete So, in the worst-case, we cannot expect to solve
a finite CSP in less than exponential time
PSUCS 370 – Introduction to Artificial Intelligence
Commutativity of CSPCommutativity of CSP
1. Generate successors of a node by considering assignments for only one variable
2. Do not store the path to node
PSUCS 370 – Introduction to Artificial Intelligence
Backtracking SearchBacktracking Search
empty assignment
1st variable
2nd variable
3rd variable
Assignment = {}
PSUCS 370 – Introduction to Artificial Intelligence
Backtracking SearchBacktracking Search
empty assignment
1st variable
2nd variable
3rd variable
Assignment = {(var1=v11)}
PSUCS 370 – Introduction to Artificial Intelligence
Backtracking SearchBacktracking Search
empty assignment
1st variable
2nd variable
3rd variable
Assignment = {(var1=v11),(var2=v21)}
PSUCS 370 – Introduction to Artificial Intelligence
Backtracking SearchBacktracking Search
empty assignment
1st variable
2nd variable
3rd variable
Assignment = {(var1=v11),(var2=v21),(var3=v31)}
PSUCS 370 – Introduction to Artificial Intelligence
Backtracking SearchBacktracking Search
empty assignment
1st variable
2nd variable
3rd variable
Assignment = {(var1=v11),(var2=v21),(var3=v32)}
PSUCS 370 – Introduction to Artificial Intelligence
Backtracking SearchBacktracking Search
empty assignment
1st variable
2nd variable
3rd variable
Assignment = {(var1=v11),(var2=v22)}
PSUCS 370 – Introduction to Artificial Intelligence
Backtracking SearchBacktracking Search
empty assignment
1st variable
2nd variable
3rd variable
Assignment = {(var1=v11),(var2=v22),(var3=v31)}
PSUCS 370 – Introduction to Artificial Intelligence29
Backtracking search
Variable assignments are commutative}, i.e.,[ WA = red then NT = green ] same as [ NT = green then WA =
red ]
Only need to consider assignments to a single variable at each node b = d and there are dn leaves
Depth-first search for CSPs with single-variable assignments is called backtracking search
Backtracking search is the basic uninformed algorithm for CSPs
Can solve n-queens for n ≈ 25
PSUCS 370 – Introduction to Artificial Intelligence35
Improving backtracking efficiency
General-purpose methods can give huge gains in speed: Which variable should be assigned next? In what order should its values be tried? Can we detect inevitable failure early?
PSUCS 370 – Introduction to Artificial Intelligence36
Most constrained variable
Most constrained variable:choose the variable with the fewest legal values
a.k.a. minimum remaining values (MRV) heuristic
PSUCS 370 – Introduction to Artificial Intelligence37
Most constraining variable
Tie-breaker among most constrained variables Most constraining variable:
choose the variable with the most constraints on remaining variables
PSUCS 370 – Introduction to Artificial Intelligence38
Least constraining value
Given a variable, choose the least constraining value: the one that rules out the fewest values in the
remaining variables
Combining these heuristics makes 1000 queens feasible
PSUCS 370 – Introduction to Artificial Intelligence39
Forward checking
Idea: Keep track of remaining legal values for unassigned variables Terminate search when any variable has no legal values
PSUCS 370 – Introduction to Artificial Intelligence40
Forward checking
Idea: Keep track of remaining legal values for unassigned variables Terminate search when any variable has no legal values
PSUCS 370 – Introduction to Artificial Intelligence41
Forward checking
Idea: Keep track of remaining legal values for unassigned variables Terminate search when any variable has no legal values
PSUCS 370 – Introduction to Artificial Intelligence42
Forward checking
Idea: Keep track of remaining legal values for unassigned variables Terminate search when any variable has no legal values
PSUCS 370 – Introduction to Artificial Intelligence43
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
PSUCS 370 – Introduction to Artificial Intelligence44
Arc consistency algorithm AC-3
Time complexity: O(n2d3)
PSUCS 370 – Introduction to Artificial Intelligence
Backtracking AlgorithmBacktracking Algorithm
CSP-BACKTRACKING({})
CSP-BACKTRACKING(a) If a is complete then return a X select unassigned variable D select an ordering for the domain of X For each value v in D do
– If v is consistent with a then Add (X= v) to a result CSP-BACKTRACKING(a) If result failure then return result
Return failure
partial assignment of variables
PSUCS 370 – Introduction to Artificial Intelligence
Map ColoringMap Coloring
{}
WA=red WA=green WA=blue
WA=redNT=green
WA=redNT=blue
WA=redNT=greenQ=red
WA=redNT=greenQ=blue
WA
NT
SA
Q
NSWV
T
PSUCS 370 – Introduction to Artificial Intelligence
QuestionsQuestions1. Which variable X should be assigned a value
next?2. In which order should its domain D be sorted?
PSUCS 370 – Introduction to Artificial Intelligence
QuestionsQuestions
1. Which variable X should be assigned a value next?
2. In which order should its domain D be sorted?3. What are the implications of a partial
assignment for yet unassigned variables? ( Constraint Propagation)
PSUCS 370 – Introduction to Artificial Intelligence
Choice of VariableChoice of Variable
Map coloring
WA
NT
SA
Q
NSWV
T
WA
NT
SA
PSUCS 370 – Introduction to Artificial Intelligence
Choice of VariableChoice of Variable
#1: Minimum Remaining Values (aka Most-constrained-variable heuristic):
Select a variable with the fewest remaining
values
PSUCS 370 – Introduction to Artificial Intelligence
Choice of VariableChoice of Variable
#2: Degree Heuristic (aka Most-constraining-variable heuristic):
Select the variable that is involved in the largest number of constraints on other unassigned variables
WA
NT
SA
Q
NSWV
T
SA
PSUCS 370 – Introduction to Artificial Intelligence
{}
Choice of ValueChoice of Value
WA
NT
SA
Q
NSWV
T
WA
NT
PSUCS 370 – Introduction to Artificial Intelligence
Choice of ValueChoice of Value
#3: Least-constraining-value heuristic: Prefer the value that leaves the largest subset
of legal values for other unassigned variables
{blue}
WA
NT
SA
Q
NSWV
T
WA
NT
PSUCS 370 – Introduction to Artificial Intelligence
Constraint Propagation …Constraint Propagation …
… is the process of determining how the possible values of one variable affect the possible values of other variables
PSUCS 370 – Introduction to Artificial Intelligence
Forward CheckingForward 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
PSUCS 370 – Introduction to Artificial Intelligence
Map ColoringMap Coloring
WA NT Q NSW V SA T
RGB RGB RGB RGB RGB RGB RGB
TWA
NT
SA
Q
NSW
V
PSUCS 370 – Introduction to Artificial Intelligence
Map ColoringMap Coloring
WA NT Q NSW V SA T
RGB RGB RGB RGB RGB RGB RGB
R GB RGB RGB RGB GB RGB
TWA
NT
SA
Q
NSW
V
PSUCS 370 – Introduction to Artificial Intelligence
WA NT Q NSW V SA T
RGB RGB RGB RGB RGB RGB RGB
R GB RGB RGB RGB GB RGB
R B G RB RGB B RGB
Map ColoringMap Coloring
TWA
NT
SA
Q
NSW
V
PSUCS 370 – Introduction to Artificial Intelligence
Map ColoringMap Coloring
WA NT Q NSW V SA T
RGB RGB RGB RGB RGB RGB RGB
R GB RGB RGB RGB GB RGB
R B G RB RGB B RGB
R B G R B RGB
Impossible assignments that forward checking do not detect
TWA
NT
SA
Q
NSW
V
PSUCS 370 – Introduction to Artificial Intelligence
4-Queens Problem4-Queens Problem
1
3
2
4
32 41
X1{1,2,3,4}
X3{1,2,3,4}
X4{1,2,3,4}
X2{1,2,3,4}
PSUCS 370 – Introduction to Artificial Intelligence
4-Queens Problem4-Queens Problem
1
3
2
4
32 41
X1{1,2,3,4}
X3{1,2,3,4}
X4{1,2,3,4}
X2{1,2,3,4}
PSUCS 370 – Introduction to Artificial Intelligence
4-Queens Problem4-Queens Problem
1
3
2
4
32 41
X1{1,2,3,4}
X3{1,2,3,4}
X4{1,2,3,4}
X2{1,2,3,4}
PSUCS 370 – Introduction to Artificial Intelligence
4-Queens Problem4-Queens Problem
1
3
2
4
32 41
X1{1,2,3,4}
X3{1,2,3,4}
X4{1,2,3,4}
X2{1,2,3,4}
PSUCS 370 – Introduction to Artificial Intelligence
4-Queens Problem4-Queens Problem
1
3
2
4
32 41
X1{1,2,3,4}
X3{1,2,3,4}
X4{1,2,3,4}
X2{1,2,3,4}
PSUCS 370 – Introduction to Artificial Intelligence
4-Queens Problem4-Queens Problem
1
3
2
4
32 41
X1{1,2,3,4}
X3{1,2,3,4}
X4{1,2,3,4}
X2{1,2,3,4}
PSUCS 370 – Introduction to Artificial Intelligence
4-Queens Problem4-Queens Problem
1
3
2
4
32 41
X1{1,2,3,4}
X3{1,2,3,4}
X4{1,2,3,4}
X2{1,2,3,4}
PSUCS 370 – Introduction to Artificial Intelligence
4-Queens Problem4-Queens Problem
1
3
2
4
32 41
X1{1,2,3,4}
X3{1,2,3,4}
X4{1,2,3,4}
X2{1,2,3,4}
PSUCS 370 – Introduction to Artificial Intelligence
4-Queens Problem4-Queens Problem
1
3
2
4
32 41
X1{1,2,3,4}
X3{1,2,3,4}
X4{1,2,3,4}
X2{1,2,3,4}
PSUCS 370 – Introduction to Artificial Intelligence
4-Queens Problem4-Queens Problem
1
3
2
4
32 41
X1{1,2,3,4}
X3{1,2,3,4}
X4{1,2,3,4}
X2{1,2,3,4}
PSUCS 370 – Introduction to Artificial Intelligence71
Arc consistency
Simplest form of propagation makes each arc consistent X Y is consistent iff
for every value x of X there is some allowed y
PSUCS 370 – Introduction to Artificial Intelligence72
Arc consistency
Simplest form of propagation makes each arc consistent X Y is consistent iff
for every value x of X there is some allowed y
PSUCS 370 – Introduction to Artificial Intelligence73
Arc consistency
Simplest form of propagation makes each arc consistent X Y is consistent iff
If X loses a value, neighbors of X need to be rechecked
for every value x of X there is some allowed y
PSUCS 370 – Introduction to Artificial Intelligence74
Arc consistency
Simplest form of propagation makes each arc consistent X Y is consistent iff
If X loses a value, neighbors of X need to be rechecked Arc consistency detects failure earlier than forward checking
Can be run as a preprocessor or after each assignment
for every value x of X there is some allowed y
PSUCS 370 – Introduction to Artificial Intelligence
Local Search for CSPLocal Search for CSP
12
33223
22
22
202
Pick initial complete assignment (at random)Repeat
• Pick a conflicted variable var (at random)• Set the new value of var to minimize the number of conflicts• If the new assignment is not conflicting then return it
(min-conflicts heuristics)
PSUCS 370 – Introduction to Artificial Intelligence
RemarkRemark
Local search with min-conflict heuristic works extremely well for million-queen problems
The reason: Solutions are densely distributed in the O(nn) space, which means that on the average a solution is a few steps away from a randomly picked assignment
PSUCS 370 – Introduction to Artificial Intelligence
Infinite-Domain CSPInfinite-Domain CSP
Variable domain is the set of the integers (discrete CSP) or of the real numbers (continuous CSP)
Constraints are expressed as equalities and inequalities
Particular case: Linear-programming problems
PSUCS 370 – Introduction to Artificial Intelligence
ApplicationsApplications
CSP techniques allow solving very complex problems
Numerous applications, e.g.: Crew assignments to flights Management of transportation fleet Flight/rail schedules Task scheduling in port operations Design Brain surgery
Timetabling problems Factory scheduling See www.ilog.com Transportation scheduling
PSUCS 370 – Introduction to Artificial Intelligence
Stereotaxic Brain Surgery
• 2000 < Tumor < 22002000 < B2 + B4 < 22002000 < B4 < 22002000 < B3 + B4 < 22002000 < B3 < 22002000 < B1 + B3 + B4 < 22002000 < B1 + B4 < 22002000 < B1 + B2 + B4 < 22002000 < B1 < 22002000 < B1 + B2 < 2200
• 0 < Critical < 5000 < B2 < 500
T
C
B1
B2
B3B4
T
PSUCS 370 – Introduction to Artificial Intelligence
Constraint ProgrammingConstraint Programming
“Constraint programming represents one of the closest approaches computer science has yet made to the Holy Grail of programming: the user states the problem, the computer solves it.”Eugene C. Freuder, Constraints, April 1997
PSUCS 370 – Introduction to Artificial Intelligence
When to Use CSP When to Use CSP Techniques?Techniques?
When the problem can be expressed by a set of variables with constraints on their values
When constraints are relatively simple (e.g., binary)
When constraints propagate well
PSUCS 370 – Introduction to Artificial Intelligence83
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
Iterative min-conflicts is usually effective in practice
PSUCS 370 – Introduction to Artificial Intelligence
Additional ReferencesAdditional References
Surveys: Kumar, AAAI Mag., 1992; Dechter and Frost, 1999
Text: Marriott and Stuckey, 1998; Russell and Norvig, 2nd ed.
Applications: Freuder and Mackworth, 1994
Conference series: Principles and Practice of Constraint Programming (CP)
Journal: Constraints (Kluwer Academic Publishers)
Internet Constraints Archive http://www.cs.unh.edu/ccc/archive