SlideShare a Scribd company logo
1 of 66
Download to read offline
CMU 15-7/381
CSPs
Teachers:
Ariel Procaccia
Emma Brunskill (THIS TIME)
With thanks to Ariel
Procaccia and other prior
instructions for slides
Class Scheduling Woes
• 4 more required classes to graduate
o A: Algorithms B: Bayesian Learning
o C: Computer Programming D: Distributed Computing
• A few restrictions
o Algorithms must be taken same semester as distributed
computing
o Computer programming is a prereq for distributed computing
and Bayesian learning, so it must be taken in an earlier
semester
o Advanced algorithms and Bayesian Learning are always offered
at the same time, so they cannot be taken the same semester
• 3 semesters (semester 1,2,3) when can take classes
2
Constraint Satisfaction
Problems (CSPs)
• Variables: V = {V1,..,VN}
• Domain: Set of d possible values for each variable
• Constraints: C = {C1,..,CK}
• A constraint consists of
o variable tuple
o list of possible values for tuple (ex.[(V2,V3),{(R,B),(R,G)])
o Or function that describes possible values (ex. V2 ≠ V3)
• Allows useful general-purpose algorithms with more power
than standard search algorithms
3
Overview
• Real world CSPs
• Basic algorithms for solving CSPs
• Pruning space through propagating
information
4
Overview
• Real world CSPs
• Basic algorithms for solving CSPs
• Pruning space through propagating
information
5
Example: Map Coloring
Color a map so that adjacent areas are
different colors
6
Map Coloring
Variables
Domain
Constraints
Solutions
7
Example: Suduko
• Variables:
• Domain:
• Constraints:
8
Example: Suduko
• Variables:
o Each open sqr
• Domain:
o {1:9}
• Constraints:
o 9-way all diff col
o 9-way all diff row
o 9-way all diff box
9
Scheduling (Important Ex.)
• Many industries. Many multi-million $ decisions. Used
extensively for space mission planning. Military uses.
• People really care about improving scheduling
algorithms! Problems with phenomenally huge state
spaces. But for which solutions are needed very quickly
• Many kinds of scheduling problems e.g.:
o Job shop: Discrete time; weird ordering of operations
possible; set of separate jobs.
o Batch shop: Discrete or continuous time; restricted
operation of ordering; grouping is important.
10
Job Scheduling
• A set of N jobs, J1,…, Jn.
• Each job j is a seq of operations Oj
1,..., Oj
Lj
• Each operation may use resource R, and
has a specific duration in time.
• A resource must be used by a single
operation at a time.
• All jobs must be completed by a due time.
• Problem: assign a start time to each job.
11
Exercise: Define CSP
• 4 more required classes to graduate: A, B, C, D
• A must be taken same semester as D
• C is a prereq for D and B so must take C earlier than D &
B
• A & B are always offered at the same time, so they
cannot be taken the same semester
• 3 semesters (semester 1,2,3) when can take classes
• Variables: A,B,C,D
• Domain: {1,2,3}
• Constraints: A ≠ B, A=D, C < B, C < D
12
Overview
• Real world CSPs
• Basic algorithms for solving CSPs
• Pruning space through propagating
information
13
Why not just do basic
search algorithms from
last time?
14
Backtracking
• Only consider a single variable at each point
• Don’t care about path!
15
Backtracking
• Only consider a single variable at each point
• Don’t care about path!
• Order of variable assignment doesn’t matter, so fix
ordering
16
Backtracking
• Only consider a single variable at each point
• Don’t care about path!
• Order of variable assignment doesn’t matter, so fix
ordering
• Only consider values which do not conflict with
assignment made so far
17
Backtracking
• Only consider a single variable at each point
• Don’t care about path!
• Order of variable assignment doesn’t matter, so fix
ordering
• Only consider values which do not conflict with
assignment made so far
• Depth-first search for CSPs with these two
improvements is called backtracking search
18
Backtracking
• Function Backtracking(csp) returns soln or fail
o Return Backtrack({},csp)
• Function Backtrack(assignment,csp) returns soln or fail
o If assignment is complete, return assignment
o Viß select_unassigned_var(csp)
o For each val in order-domain-values(var,csp,assign)
If value is consistent with assignment
Add [Vi = val] to assignment
Result ß Backtrack(assignment,csp)
If Result ≠ fail, return result
Remove [Vi = val] from assignments
o Return fail
19
Backtracking Example
• Variables: A,B,C,D
• Domain: {1,2,3}
• Constraints:
o A ≠ B, A=D, C < B, C < D
• Variable order: ?
• Value order: ?
20
Backtracking
• Function Backtracking(csp) returns soln or fail
o Return Backtrack({},csp)
• Function Backtrack(assignment,csp) returns soln or fail
o If assignment is complete, return assignment
o Viß select_unassigned_var(csp)
o For each val in order-domain-values(var,csp,assign)
If value is consistent with assignment
Add [Vi = val] to assignment
Result ß Backtrack(assignment,csp)
If Result ≠ fail, return result
Remove [Vi = val] from assignments
o Return fail
21
Think and discuss
• Does the value order used affect how long
backtracking takes to find a solution?
• Does the value order used affect the
solution found by backtracking?
22
Example
Variables: A,B,C,D Domain: {1,2,3}
Constraints: A ≠ B, A=D, C < B, C < D
Variable order: alphabetical Value order: Descending
• (A=3)
23
Example
Variables: A,B,C,D Domain: {1,2,3}
Constraints: A ≠ B, A=D, C < B, C < D
Variable order: alphabetical Value order: Descending
• (A=3)
• (A=3, B=3) inconsistent with A ≠ B
• (A=3, B=2)
• (A=3, B=2, C=3) inconsistent with C < B
• (A=3, B=2, C=2) inconsistent with C < B
• (A=3, B=2, C=1)
• (A=3, B=2, C=1,D=3) VALID
24
Example
Variables: A,B,C,D Domain: {1,2,3}
Constraints: A ≠ B, A=D, C < B, C < D
Variable order: alphabetical Value order: Ascending
• (A=1)
25
Example
Variables: A,B,C,D Domain: {1,2,3}
Constraints: A ≠ B, A=D, C < B, C < D
Variable order: alphabetical Value order: Ascending
• (A=1)
• (A=1,B=1) inconsistent with A ≠ B
• (A=1,B=2)
• (A=1,B=2,C=1)
• (A=1,B=2,C=1,D=1) inconsistent with C < D
• (A=1,B=2,C=1,D=2) inconsistent with A=D
• (A=1,B=2,C=1,D=3) inconsistent with A=D
26
Example
Variables: A,B,C,D Domain: {1,2,3}
Constraints: A ≠ B, A=D, C < B, C < D
Variable order: alphabetical Value order: Ascending
27
§ (A=1)
§ (A=1,B=1) inconsistent with A ≠ B
§ (A=1,B=2)
§ (A=1,B=2,C=1)
§ (A=1,B=2,C=1,D=1) inconsistent with C < D
§ (A=1,B=2,C=1,D=2) inconsistent with A=D
§ (A=1,B=2,C=1,D=3) inconsistent with A=D
§ No valid assignment for D, return result = fail
§ Backtrack to (A=1,B=2,C=)
§ Try (A=1,B=2,C=2) but inconsistent with C < B
§ Try (A=1,B=2,C=3) but inconsistent with C < B
§ No other assignments for C, return result= fail
§ Backtrack to (A=1,B=)
§ (A=1,B=3)
§ (A=1,B=3,C=1)
§ (A=1,B=3,C=1,D=1) inconsistent with C < D
§ (A=1,B=3,C=1,D=2) inconsistent with A = D
§ (A=1,B=3,C=1,D=3) inconsistent with A = D
§ Return result = fail
§ Backtrack to (A=1,B=3,C=)
§ (A=1,B=3,C=2) inconsistent with C < B
§ (A=1,B=3,C=3) inconsistent with C < B
§ No remaining assignments for C, return fail
§ Backtrack to (A=1,B=)
§ No remaining assignments for B, return fail
§ Backtrack to A
§ (A=2)
§ (A=2,B=1)
§ (A=2,B=1,C=1) inconsistent with C < B
§ (A=2,B=1,C=2) inconsistent with C < B
§ (A=2,B=1,C=3) inconsistent with C < B
§ No remaining assignments for C, return fail
§ Backtrack to (A=2,B=?)
§ (A=2,B=2) inconsistent with A ≠ B
§ (A=2,B=3)
§ (A=2,B=3,C=1)
§ (A=2,B=3,C=1,D=1) inconsistent with C < D
§ (A=2,B=3,C=1,D=2) ALL VALID
Ordering Matters!
• Function Backtracking(csp) returns soln or fail
o Return Backtrack({},csp)
• Function Backtrack(assignment,csp) returns soln or fail
o If assignment is complete, return assignment
o Viß select_unassigned_var(csp)
o For each val in order-domain-values(var,csp,assign)
If value is consistent with assignment
Add [Vi = val] to assignment
Result ß Backtrack(assignment,csp)
If Result ≠ fail, return result
Remove [Vi = val] from assignments
o Return fail
28
Min Remaining Values
(MRV)
• Choose variable with minimum number of
remaining values in its domain
• Why min rather than max?
29
Min Remaining Values
(MRV)
• Choose variable with minimum number of
remaining values in its domain
• Most constrained variable
• “Fail-fast” ordering
30
Least Constraining Value
• Given choice of variable:
o Choose least constraining value
o Aka value that rules out the least values in
the remaining variables to be assigned
o May take some computation to find this
• Why least rather than most?
31
Click! Cost of Backtracking?
• d values per variable
• n variables
• Possible number of CSP assignments?
• A) O(dn)
• B) O(nd)
• C) O(nd)
32
Overview
• Real world CSPs
• Basic algorithms for solving CSPs
• Pruning space through propagating
information
33
Limitations of Backtracking
• Function Backtracking(csp) returns soln or fail
o Return Backtrack({},csp)
• Function Backtrack(assignment,csp) returns soln or fail
o If assignment is complete, return assignment
o Viß select_unassigned_var(csp)
o For each val in order-domain-values(var,csp,assign)
If value is consistent with assignment
Add [Vi = val] to assignment
Result ß Backtrack(assignment,csp)
If Result ≠ fail, return result
Remove [Vi = val] from assignments
o Return fail
34
Constraint Graphs
• Nodes are variables
• Arcs show constraints
35
Propagate Information
• If we choose a value for one variable, that
affects its neighbors
• And then potentially those neighbors…
• Prunes the space of
solutions
36
Arc Consistency
• Definition:
o An “arc” (connection between two variables
X à Y in constraint graph) is consistent if:
o For every value could assign to X
There exists some value of Y that could be
assigned without violating a constraint
37
AC-3 (Assume binary constraints)
• Input: CSP
• Output: CSP, possible with reduced domains for variables, or inconsistent
• Local variables: stack, initially stack of all arcs (binary constraints in csp)
• While stack is not empty
• (Xi,Xj) = Remove-First(stack)
• [domainXi, anyChangeToDomainXi] = Revise(csp,Xi,Xj)
• if anyChangeToDomainXi == true
• if size(domainXi) = 0, return inconsistent
• else
• for each Xk in Neighbors(Xi) except Xj
• add (Xk,Xi) to stack
• Return csp
• -------------------------------------------------------------------------------------------------------------------
• Function Revise(csp,Xi,Xj) returns DomainXi and anyChangeToDomainXi
• anyChangeToDomainXi = false
• for each x in Domain(Xi)
• if no value y in Domain(Xj) allows (x,y) to satisfy constraint between (Xi,Xj)
• delete x from Domain(Xi)
• anyChangeToDomainXi = true
38
Have to add in
arc for (Xi,Xj) and
(Xj,Xi)
for i,j constraint
AC-3 (Assume binary constraints)
• Input: CSP
• Output: CSP, possible with reduced domains for variables, or inconsistent
• Local variables: stack, initially stack of all arcs (binary constraints in csp)
• While stack is not empty
• (Xi,Xj) = Remove-First(stack)
• [domainXi, anyChangeToDomainXi] = Revise(csp,Xi,Xj)
• if anyChangeToDomainXi == true
• if size(domainXi) = 0, return inconsistent
• else
• for each Xk in Neighbors(Xi) except Xj
• add (Xk,Xi) to stack
• Return csp
• -------------------------------------------------------------------------------------------------------------------
• Function Revise(csp,Xi,Xj) returns DomainXi and anyChangeToDomainXi
• anyChangeToDomainXi = false
• for each x in Domain(Xi)
• if no value y in Domain(Xj) allows (x,y) to satisfy constraint between (Xi,Xj)
• delete x from Domain(Xi)
• anyChangeToDomainXi = true
39
Have to add in
arc for (Xi,Xj) and
(Xj,Xi)
for i,j constraint
AC-3 Computational Complexity?
• Input: CSP
• Output: CSP, possible with reduced domains for variables, or inconsistent
• Local variables: stack, initially stack of all arcs (binary constraints in csp)
• While stack is not empty
• (Xi,Xj) = Remove-First(stack)
• [domainXi, anyChangeToDomainXi] = Revise(csp,Xi,Xj)
• if anyChangeToDomainXi == true
• if size(domainXi) = 0, return inconsistent
• else
• for each Xk in Neighbors(Xi) except Xj
• add (Xk,Xi) to stack
• Return csp
• ------------------------------------------------------------------------------------------------------------
• Function Revise(csp,Xi,Xj) returns DomainXi and anyChangeToDomainXi
• anyChangeToDomainXi = false
• for each x in Domain(Xi)
• if no value y in Domain(Xj) allows (x,y) to satisfy constraint between (Xi,Xj)
• delete x from Domain(Xi)
• anyChangeToDomainXi = true
40
Have to add in arc for
(Xi,Xj) and (Xj,Xi)
for i,j constraint
D domain values
C binary constraints
Complexity of revise
function? D2
AC-3 Computational Complexity?
• Input: CSP
• Output: CSP, possible with reduced domains for variables, or inconsistent
• Local variables: stack, initially stack of all arcs (binary constraints in csp)
• While stack is not empty
• (Xi,Xj) = Remove-First(stack)
• [domainXi, anyChangeToDomainXi] = Revise(csp,Xi,Xj)
• if anyChangeToDomainXi == true
• if size(domainXi) = 0, return inconsistent
• else
• for each Xk in Neighbors(Xi) except Xj
• add (Xk,Xi) to stack
• Return csp
• ------------------------------------------------------------------------------------------------------------
• Function Revise(csp,Xi,Xj) returns DomainXi and anyChangeToDomainXi
• anyChangeToDomainXi = false
• for each x in Domain(Xi)
• if no value y in Domain(Xj) allows (x,y) to satisfy constraint between (Xi,Xj)
• delete x from Domain(Xi)
• anyChangeToDomainXi = true
41
Have to add in arc for
(Xi,Xj) and (Xj,Xi)
for i,j constraint
D domain values
C binary
constraints
Complexity of
revise function?
D2
Number of times
can put a
constraint in
stack?
AC-3 Computational Complexity?
• Input: CSP
• Output: CSP, possible with reduced domains for variables, or inconsistent
• Local variables: stack, initially stack of all arcs (binary constraints in csp)
• While stack is not empty
• (Xi,Xj) = Remove-First(stack)
• [domainXi, anyChangeToDomainXi] = Revise(csp,Xi,Xj)
• if anyChangeToDomainXi == true
• if size(domainXi) = 0, return inconsistent
• else
• for each Xk in Neighbors(Xi) except Xj
• add (Xk,Xi) to stack
• Return csp
• ------------------------------------------------------------------------------------------------------------
• Function Revise(csp,Xi,Xj) returns DomainXi and anyChangeToDomainXi
• anyChangeToDomainXi = false
• for each x in Domain(Xi)
• if no value y in Domain(Xj) allows (x,y) to satisfy constraint between (Xi,Xj)
• delete x from Domain(Xi)
• anyChangeToDomainXi = true
42
Have to add in arc for
(Xi,Xj) and (Xj,Xi)
for i,j constraint
D domain values
C binary
constraints
Complexity of
revise function?
D2
Number of times
can put a
constraint in
stack?
D
Total:
CD3
AC-3 Example
• Variables: A,B,C,D
• Domain: {1,2,3}
• Constraints: A ≠ B, C < B, C < D (subset of constraints from before)
44
AC-3 Example
• Variables: A,B,C,D
• Domain: {1,2,3}
• Constraints: A ≠ B, C < B, C < D (subset of constraints from before)
• Constraints both ways: A≠ B, B≠ A, C < B, B > C, C < D, D > C
45
AC-3 Example
• Variables: A,B,C,D
• Domain: {1,2,3}
• Constraints: A ≠ B, C < B, C < D (subset of constraints from before)
• Constraints both ways: A≠ B, B≠ A, C < B, B > C, C < D, D > C
• stack: AB, BA, BC, CB, CD, DC
46
AC-3 Example
• Variables: A,B,C,D
• Domain: {1,2,3}
• Constraints: A ≠ B, C < B, C < D (subset of constraints from before)
• Constraints both ways: A≠ B, B≠ A, C < B, B > C, C < D, D > C
• stack: AB, BA, BC, CB, CD, DC
• Pop AB:
• for each x in Domain(A)
if no value y in Domain(B) that allows (x,y) to satisfy
constraint between (A,B), delete x from Domain(A)
• No change to domain of A
47
AC-3 Example
• Variables: A,B,C,D
• Domain: {1,2,3}
• Constraints: A ≠ B, C < B, C < D (subset of constraints from before)
• Constraints both ways: A≠ B, B≠ A, C < B, B > C, C < D, D > C
• stack: AB, BA, BC, CB, CD, DC
• Pop AB
• stack: BA, BC, CB, CD, DC
48
AC-3 Example
• Variables: A,B,C,D
• Domain: {1,2,3}
• Constraints: A ≠ B, C < B, C < D (subset of constraints from before)
• Constraints both ways: A≠ B, B≠ A, C < B, B > C, C < D, D > C
• stack: AB, BA, BC, CB, CD, DC
• Pop AB
• stack: BA, BC, CB, CD, DC
• Pop BA
• for each x in Domain(B)
if no value y in Domain(A) that allows (x,y) to satisfy
constraint between (B,A), delete x from Domain(B)
• No change to domain of B
49
AC-3 Example
• Variables: A,B,C,D
• Domain: {1,2,3}
• Constraints: A ≠ B, C < B, C < D (subset of constraints from before)
• Constraints both ways: A≠ B, B≠ A, C < B, B > C, C < D, D > C
• stack: AB, BA, BC, CB, CD, DC
• stack: BA, BC, CB, CD, DC
• stack: BC, CB, CD, DC
• Pop BC
• for each x in Domain(B)
if no value y in Domain(C) that allows (x,y) to satisfy constraint between
(B,C), delete x from Domain(B)
• If B is 1, constraint B >C cannot be satisfied. So delete 1 from B’s domain, B={2,3}
• Also have to add neighbors of B (except C) back to stack: AB
• stack: AB, CB, CD, DC
50
AC-3 Example
• stack: AB, BA, BC, CB, CD, DC A-D = {1,2,3}
• stack: BA, BC, CB, CD, DC A-D = {1,2,3}
• stack: BC, CB, CD, DC A-D = {1,2,3}
• stack: AB, CB, CD, DC B={2,3}, A/C/D = {1,2,3}
• Pop AB
o For every value of A is there a value of B such that A ≠ B?
o Yes, so no change
51
Variables: A,B,C,D
Domain: {1,2,3}
Constraints: A ≠ B, C < B, C < D
AC-3 Example
• stack: AB, BA, BC, CB, CD, DC, A-D = {1,2,3}
• stack: BA, BC, CB, CD, DC A-D = {1,2,3}
• stack: BC, CB, CD, DC A-D = {1,2,3}
• stack: AB, CB, CD, DC B={2,3}, A/C/D = {1,2,3}
• stack: CB, CD, DC B={2,3}, A/C/D = {1,2,3}
• Pop CB
o For every value of C is there a value of B such that C < B
o If C = 3, no value of B that fits
o So delete 3 from C’s domain, C = {1,2}
o Also have to add neighbors of C (except B) back to stack: no change
because already in
52
Variables: A,B,C,D
Domain: {1,2,3}
Constraints: A ≠ B, C < B, C < D
AC-3 Example
• stack: AB, BA, BC, CB, CD, DC, A-D = {1,2,3}
• stack: BA, BC, CB, CD, DC A-D = {1,2,3}
• stack: BC, CB, CD, DC A-D = {1,2,3}
• stack: AB, CB, CD, DC B={2,3}, A/C/D = {1,2,3}
• stack: CB, CD, DC B={2,3}, A/C/D = {1,2,3}
• stack: CD, DC B={2,3}, C = {1,2} A,D = {1,2,3}
• Pop CD
o For every value of C, is there a value of D such that C < D?
o Yes, so no change
53
Variables: A,B,C,D
Domain: {1,2,3}
Constraints: A ≠ B, C < B, C < D
AC-3 Example
• stack: AB, BA, BC, CB, CD, DC A-D = {1,2,3}
• stack: BA, BC, CB, CD, DC A-D = {1,2,3}
• stack: BC, CB, CD, DC A-D = {1,2,3}
• stack: AB, CB, CD, DC B={2,3}, A/C/D = {1,2,3}
• stack: CB, CD, DC B={2,3}, A/C/D = {1,2,3}
• stack: CD, DC B={2,3}, C = {1,2} A,D = {1,2,3}
• stack: DC B={2,3}, C = {1,2} A,D = {1,2,3}
• For every value of D is there a value of C such that D > C?
o Not if D = 1
o So D = {2,3}
54
Variables: A,B,C,D
Domain: {1,2,3}
Constraints: A ≠ B, C < B, C < D
AC-3 Example
• stack: AB, BA, BC, CB, CD, DC A-D = {1,2,3}
• stack: BA, BC, CB, CD, DC A-D = {1,2,3}
• stack: BC, CB, CD, DC A-D = {1,2,3}
• stack: AB, CB, CD, DC B={2,3}, A/C/D = {1,2,3}
• stack: CB, CD, DC B={2,3}, A/C/D = {1,2,3}
• stack: CD, DC B={2,3}, C = {1,2} A,D = {1,2,3}
• stack: DC B={2,3}, C = {1,2} A,D = {1,2,3}
• A = {1,2,3} B={2,3}, C = {1,2} D = {2,3}
55
Variables: A,B,C,D
Domain: {1,2,3}
Constraints: A ≠ B, C < B, C < D
Forward Checking
• When assign a variable, make all of its
neighbors arc-consistent
56
Backtracking + Forward
Checking
• Function Backtrack(assignment,csp) returns soln or fail
o If assignment is complete, return assignment
o Viß select_unassigned_var(csp)
o For each val in order-domain-values(var,csp,assign)
If value is consistent with assignment
Add [Vi = val] to assignment
Make domains of all neighbors of Vi arc-consistent with [Vi = val]
Result ß Backtrack(assignment,csp)
If Result ≠ fail, return result
Remove [Vi = val] from assignments
o Return fail
57
Maintaining Arc
Consistency
• Forward checking doesn’t ensure all arcs
are consistent
• AC-3 detects failure faster than forward
checking
• What’s the downside? Computation
58
Maintaining Arc Consistency
(MAC)
• Function Backtrack(assignment,csp) returns soln or fail
o If assignment is complete, return assignment
o Viß select_unassigned_var(csp)
o For each val in order-domain-values(var,csp,assign)
If value is consistent with assignment
Add [Vi = val] to assignment
Run AC-3 to make all variables arc-consistent with [Vi = val].
Initial stack is arcs (Xj,Vi) of neighbors of Vi that are
unassigned, but add other arcs if these vars change domains.
Result ß Backtrack(assignment,csp)
If Result ≠ fail, return result
Remove [Vi = val] from assignments
o Return fail
59
Sufficient to Avoid
backtracking?
• If we maintain arc consistency, we will
never have to backtrack while solving a
CSP
• A) True
• B) False
60
AC-3 Limitations
• After running AC-3
o Can have one solution left
o Can have multiple solutions left
o Can have no solutions left (and not know it)
61
AC-3 Limitations
• After running AC-3
o Can have one solution left
o Can have multiple solutions left
o Can have no solutions left (and not know it)
62
What went
wrong here?
Complexity
• CSP in general are NP-hard
• Some structured domains are easier
63
Constraint Trees
64
• Constraint tree
o Any 2 variables in constraint graph connected by <= 1 path
• Can be solved in time linear in # of variables
Figure from Russell & Norvig
1) Choose any var as root and order vars such that every
var’s parents in constraint graph precede it in ordering
2) Let Xi be the parent of Xj in the new ordering
3) For j=n:2, run arc consistency to arc (Xi,Xj)
4) For j=1:n, assign val for Xj consistent w/val assigned for Xi
Algorthm for CSP Trees
65
Figure from Russell & Norvig
1) Choose any var as root and order vars such that every
var’s parents in constraint graph precede it in ordering
2) Let Xi be the parent of Xj in the new ordering
3) For j=n:2, run arc consistency to arc (Xi,Xj)
4) For j=1:n, assign val for Xj consistent w/val assigned for Xi
Computational Complexity?
66
Figure from Russell & Norvig
Summary
• Be able to define real world CSPs
• Understand basic algorithm (backtracking)
o Complexity relative to basic search algorithms
o Doesn’t require problem specific heuristics
o Ideas shaping search (LCV, etc)
• Pruning space through propagating information
o Arc consistency
o Tradeoffs: + reduces search space, - costs computation
• Computational complexity and special cases (tree)
• Relevant reading: R&N Chapter 6
67

More Related Content

Similar to nlp2.pdf

Unit-1 Basic Concept of Algorithm.pptx
Unit-1 Basic Concept of Algorithm.pptxUnit-1 Basic Concept of Algorithm.pptx
Unit-1 Basic Concept of Algorithm.pptxssuser01e301
 
Undecidable Problems and Approximation Algorithms
Undecidable Problems and Approximation AlgorithmsUndecidable Problems and Approximation Algorithms
Undecidable Problems and Approximation AlgorithmsMuthu Vinayagam
 
Backtracking & branch and bound
Backtracking & branch and boundBacktracking & branch and bound
Backtracking & branch and boundVipul Chauhan
 
Matlab tutorial and Linear Algebra Review.ppt
Matlab tutorial and Linear Algebra Review.pptMatlab tutorial and Linear Algebra Review.ppt
Matlab tutorial and Linear Algebra Review.pptIndra Hermawan
 
Lecture 5 - Gradient Descent, a lecture in subject module Statistical & Machi...
Lecture 5 - Gradient Descent, a lecture in subject module Statistical & Machi...Lecture 5 - Gradient Descent, a lecture in subject module Statistical & Machi...
Lecture 5 - Gradient Descent, a lecture in subject module Statistical & Machi...Maninda Edirisooriya
 
Support Vector Machines is the the the the the the the the the
Support Vector Machines is the the the the the the the the theSupport Vector Machines is the the the the the the the the the
Support Vector Machines is the the the the the the the the thesanjaibalajeessn
 
Theorem proving 2018 2019
Theorem proving 2018 2019Theorem proving 2018 2019
Theorem proving 2018 2019Emmanuel Zarpas
 
Design of Engineering Experiments Part 5
Design of Engineering Experiments Part 5Design of Engineering Experiments Part 5
Design of Engineering Experiments Part 5Stats Statswork
 
Data Mining Lecture_10(b).pptx
Data Mining Lecture_10(b).pptxData Mining Lecture_10(b).pptx
Data Mining Lecture_10(b).pptxSubrata Kumer Paul
 
Theorem proving 2018 2019
Theorem proving 2018 2019Theorem proving 2018 2019
Theorem proving 2018 2019Emmanuel Zarpas
 
Coordinate Descent method
Coordinate Descent methodCoordinate Descent method
Coordinate Descent methodSanghyuk Chun
 
Matlab Cody 2020 review
Matlab Cody 2020 reviewMatlab Cody 2020 review
Matlab Cody 2020 reviewAkrem Hadji
 
Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...
Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...
Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...DebiPrasadSen
 

Similar to nlp2.pdf (20)

Unit-1 Basic Concept of Algorithm.pptx
Unit-1 Basic Concept of Algorithm.pptxUnit-1 Basic Concept of Algorithm.pptx
Unit-1 Basic Concept of Algorithm.pptx
 
Undecidable Problems and Approximation Algorithms
Undecidable Problems and Approximation AlgorithmsUndecidable Problems and Approximation Algorithms
Undecidable Problems and Approximation Algorithms
 
Backtracking & branch and bound
Backtracking & branch and boundBacktracking & branch and bound
Backtracking & branch and bound
 
Matlab tutorial and Linear Algebra Review.ppt
Matlab tutorial and Linear Algebra Review.pptMatlab tutorial and Linear Algebra Review.ppt
Matlab tutorial and Linear Algebra Review.ppt
 
Lecture 5 - Gradient Descent, a lecture in subject module Statistical & Machi...
Lecture 5 - Gradient Descent, a lecture in subject module Statistical & Machi...Lecture 5 - Gradient Descent, a lecture in subject module Statistical & Machi...
Lecture 5 - Gradient Descent, a lecture in subject module Statistical & Machi...
 
Support Vector Machines is the the the the the the the the the
Support Vector Machines is the the the the the the the the theSupport Vector Machines is the the the the the the the the the
Support Vector Machines is the the the the the the the the the
 
Theorem proving 2018 2019
Theorem proving 2018 2019Theorem proving 2018 2019
Theorem proving 2018 2019
 
Design of Engineering Experiments Part 5
Design of Engineering Experiments Part 5Design of Engineering Experiments Part 5
Design of Engineering Experiments Part 5
 
Data Mining Lecture_10(b).pptx
Data Mining Lecture_10(b).pptxData Mining Lecture_10(b).pptx
Data Mining Lecture_10(b).pptx
 
Theorem proving 2018 2019
Theorem proving 2018 2019Theorem proving 2018 2019
Theorem proving 2018 2019
 
Lecture1
Lecture1Lecture1
Lecture1
 
Coordinate Descent method
Coordinate Descent methodCoordinate Descent method
Coordinate Descent method
 
Matlab Cody 2020 review
Matlab Cody 2020 reviewMatlab Cody 2020 review
Matlab Cody 2020 review
 
Regression.pptx
Regression.pptxRegression.pptx
Regression.pptx
 
Regression.pptx
Regression.pptxRegression.pptx
Regression.pptx
 
20130523 05 - Cyclomatic complexity
20130523 05 - Cyclomatic complexity20130523 05 - Cyclomatic complexity
20130523 05 - Cyclomatic complexity
 
Machine Learning with R
Machine Learning with RMachine Learning with R
Machine Learning with R
 
5163147.ppt
5163147.ppt5163147.ppt
5163147.ppt
 
2.ppt
2.ppt2.ppt
2.ppt
 
Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...
Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...
Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...
 

More from nyomans1

PPT-UEU-Keamanan-Informasi-Pertemuan-5.ppt
PPT-UEU-Keamanan-Informasi-Pertemuan-5.pptPPT-UEU-Keamanan-Informasi-Pertemuan-5.ppt
PPT-UEU-Keamanan-Informasi-Pertemuan-5.pptnyomans1
 
Template Pertemuan 1 All MK - Copy.pptx
Template Pertemuan 1 All MK - Copy.pptxTemplate Pertemuan 1 All MK - Copy.pptx
Template Pertemuan 1 All MK - Copy.pptxnyomans1
 
Clustering_hirarki (tanpa narasi) (1).pptx
Clustering_hirarki (tanpa narasi) (1).pptxClustering_hirarki (tanpa narasi) (1).pptx
Clustering_hirarki (tanpa narasi) (1).pptxnyomans1
 
slide 7_olap_example.ppt
slide 7_olap_example.pptslide 7_olap_example.ppt
slide 7_olap_example.pptnyomans1
 
PPT-UEU-Keamanan-Informasi-Pertemuan-5.ppt
PPT-UEU-Keamanan-Informasi-Pertemuan-5.pptPPT-UEU-Keamanan-Informasi-Pertemuan-5.ppt
PPT-UEU-Keamanan-Informasi-Pertemuan-5.pptnyomans1
 
Security Requirement.pptx
Security Requirement.pptxSecurity Requirement.pptx
Security Requirement.pptxnyomans1
 
Minggu_1_Matriks_dan_Operasinya.pptx
Minggu_1_Matriks_dan_Operasinya.pptxMinggu_1_Matriks_dan_Operasinya.pptx
Minggu_1_Matriks_dan_Operasinya.pptxnyomans1
 
Matriks suplemen.ppt
Matriks suplemen.pptMatriks suplemen.ppt
Matriks suplemen.pptnyomans1
 
fdokumen.com_muh1g3-matriks-dan-ruang-vektor-3-312017-muh1g3-matriks-dan-ruan...
fdokumen.com_muh1g3-matriks-dan-ruang-vektor-3-312017-muh1g3-matriks-dan-ruan...fdokumen.com_muh1g3-matriks-dan-ruang-vektor-3-312017-muh1g3-matriks-dan-ruan...
fdokumen.com_muh1g3-matriks-dan-ruang-vektor-3-312017-muh1g3-matriks-dan-ruan...nyomans1
 
10-Image-Enhancement-Bagian3-2021.pptx
10-Image-Enhancement-Bagian3-2021.pptx10-Image-Enhancement-Bagian3-2021.pptx
10-Image-Enhancement-Bagian3-2021.pptxnyomans1
 
08-Image-Enhancement-Bagian1.pptx
08-Image-Enhancement-Bagian1.pptx08-Image-Enhancement-Bagian1.pptx
08-Image-Enhancement-Bagian1.pptxnyomans1
 
03-Pembentukan-Citra-dan-Digitalisasi-Citra.pptx
03-Pembentukan-Citra-dan-Digitalisasi-Citra.pptx03-Pembentukan-Citra-dan-Digitalisasi-Citra.pptx
03-Pembentukan-Citra-dan-Digitalisasi-Citra.pptxnyomans1
 
04-Format-citra-dan-struktur-data-citra-2021.pptx
04-Format-citra-dan-struktur-data-citra-2021.pptx04-Format-citra-dan-struktur-data-citra-2021.pptx
04-Format-citra-dan-struktur-data-citra-2021.pptxnyomans1
 
02-Pengantar-Pengolahan-Citra-Bag2-2021.pptx
02-Pengantar-Pengolahan-Citra-Bag2-2021.pptx02-Pengantar-Pengolahan-Citra-Bag2-2021.pptx
02-Pengantar-Pengolahan-Citra-Bag2-2021.pptxnyomans1
 
03spatialfiltering-130424050639-phpapp02.pptx
03spatialfiltering-130424050639-phpapp02.pptx03spatialfiltering-130424050639-phpapp02.pptx
03spatialfiltering-130424050639-phpapp02.pptxnyomans1
 
Q-Step_WS_02102019_Practical_introduction_to_Python.pptx
Q-Step_WS_02102019_Practical_introduction_to_Python.pptxQ-Step_WS_02102019_Practical_introduction_to_Python.pptx
Q-Step_WS_02102019_Practical_introduction_to_Python.pptxnyomans1
 
BAB 2_TIPE DATA, VARIABEL, DAN OPERATOR (1) (1).pptx
BAB 2_TIPE DATA, VARIABEL, DAN OPERATOR (1) (1).pptxBAB 2_TIPE DATA, VARIABEL, DAN OPERATOR (1) (1).pptx
BAB 2_TIPE DATA, VARIABEL, DAN OPERATOR (1) (1).pptxnyomans1
 
Support-Vector-Machines_EJ_v5.06.pptx
Support-Vector-Machines_EJ_v5.06.pptxSupport-Vector-Machines_EJ_v5.06.pptx
Support-Vector-Machines_EJ_v5.06.pptxnyomans1
 
06-Image-Histogram-2021.pptx
06-Image-Histogram-2021.pptx06-Image-Histogram-2021.pptx
06-Image-Histogram-2021.pptxnyomans1
 
05-Operasi-dasar-pengolahan-citra-2021 (1).pptx
05-Operasi-dasar-pengolahan-citra-2021 (1).pptx05-Operasi-dasar-pengolahan-citra-2021 (1).pptx
05-Operasi-dasar-pengolahan-citra-2021 (1).pptxnyomans1
 

More from nyomans1 (20)

PPT-UEU-Keamanan-Informasi-Pertemuan-5.ppt
PPT-UEU-Keamanan-Informasi-Pertemuan-5.pptPPT-UEU-Keamanan-Informasi-Pertemuan-5.ppt
PPT-UEU-Keamanan-Informasi-Pertemuan-5.ppt
 
Template Pertemuan 1 All MK - Copy.pptx
Template Pertemuan 1 All MK - Copy.pptxTemplate Pertemuan 1 All MK - Copy.pptx
Template Pertemuan 1 All MK - Copy.pptx
 
Clustering_hirarki (tanpa narasi) (1).pptx
Clustering_hirarki (tanpa narasi) (1).pptxClustering_hirarki (tanpa narasi) (1).pptx
Clustering_hirarki (tanpa narasi) (1).pptx
 
slide 7_olap_example.ppt
slide 7_olap_example.pptslide 7_olap_example.ppt
slide 7_olap_example.ppt
 
PPT-UEU-Keamanan-Informasi-Pertemuan-5.ppt
PPT-UEU-Keamanan-Informasi-Pertemuan-5.pptPPT-UEU-Keamanan-Informasi-Pertemuan-5.ppt
PPT-UEU-Keamanan-Informasi-Pertemuan-5.ppt
 
Security Requirement.pptx
Security Requirement.pptxSecurity Requirement.pptx
Security Requirement.pptx
 
Minggu_1_Matriks_dan_Operasinya.pptx
Minggu_1_Matriks_dan_Operasinya.pptxMinggu_1_Matriks_dan_Operasinya.pptx
Minggu_1_Matriks_dan_Operasinya.pptx
 
Matriks suplemen.ppt
Matriks suplemen.pptMatriks suplemen.ppt
Matriks suplemen.ppt
 
fdokumen.com_muh1g3-matriks-dan-ruang-vektor-3-312017-muh1g3-matriks-dan-ruan...
fdokumen.com_muh1g3-matriks-dan-ruang-vektor-3-312017-muh1g3-matriks-dan-ruan...fdokumen.com_muh1g3-matriks-dan-ruang-vektor-3-312017-muh1g3-matriks-dan-ruan...
fdokumen.com_muh1g3-matriks-dan-ruang-vektor-3-312017-muh1g3-matriks-dan-ruan...
 
10-Image-Enhancement-Bagian3-2021.pptx
10-Image-Enhancement-Bagian3-2021.pptx10-Image-Enhancement-Bagian3-2021.pptx
10-Image-Enhancement-Bagian3-2021.pptx
 
08-Image-Enhancement-Bagian1.pptx
08-Image-Enhancement-Bagian1.pptx08-Image-Enhancement-Bagian1.pptx
08-Image-Enhancement-Bagian1.pptx
 
03-Pembentukan-Citra-dan-Digitalisasi-Citra.pptx
03-Pembentukan-Citra-dan-Digitalisasi-Citra.pptx03-Pembentukan-Citra-dan-Digitalisasi-Citra.pptx
03-Pembentukan-Citra-dan-Digitalisasi-Citra.pptx
 
04-Format-citra-dan-struktur-data-citra-2021.pptx
04-Format-citra-dan-struktur-data-citra-2021.pptx04-Format-citra-dan-struktur-data-citra-2021.pptx
04-Format-citra-dan-struktur-data-citra-2021.pptx
 
02-Pengantar-Pengolahan-Citra-Bag2-2021.pptx
02-Pengantar-Pengolahan-Citra-Bag2-2021.pptx02-Pengantar-Pengolahan-Citra-Bag2-2021.pptx
02-Pengantar-Pengolahan-Citra-Bag2-2021.pptx
 
03spatialfiltering-130424050639-phpapp02.pptx
03spatialfiltering-130424050639-phpapp02.pptx03spatialfiltering-130424050639-phpapp02.pptx
03spatialfiltering-130424050639-phpapp02.pptx
 
Q-Step_WS_02102019_Practical_introduction_to_Python.pptx
Q-Step_WS_02102019_Practical_introduction_to_Python.pptxQ-Step_WS_02102019_Practical_introduction_to_Python.pptx
Q-Step_WS_02102019_Practical_introduction_to_Python.pptx
 
BAB 2_TIPE DATA, VARIABEL, DAN OPERATOR (1) (1).pptx
BAB 2_TIPE DATA, VARIABEL, DAN OPERATOR (1) (1).pptxBAB 2_TIPE DATA, VARIABEL, DAN OPERATOR (1) (1).pptx
BAB 2_TIPE DATA, VARIABEL, DAN OPERATOR (1) (1).pptx
 
Support-Vector-Machines_EJ_v5.06.pptx
Support-Vector-Machines_EJ_v5.06.pptxSupport-Vector-Machines_EJ_v5.06.pptx
Support-Vector-Machines_EJ_v5.06.pptx
 
06-Image-Histogram-2021.pptx
06-Image-Histogram-2021.pptx06-Image-Histogram-2021.pptx
06-Image-Histogram-2021.pptx
 
05-Operasi-dasar-pengolahan-citra-2021 (1).pptx
05-Operasi-dasar-pengolahan-citra-2021 (1).pptx05-Operasi-dasar-pengolahan-citra-2021 (1).pptx
05-Operasi-dasar-pengolahan-citra-2021 (1).pptx
 

Recently uploaded

BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxolyaivanovalion
 
Edukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxEdukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxolyaivanovalion
 
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...Suhani Kapoor
 
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130Suhani Kapoor
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptxAnupama Kate
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz1
 
Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxolyaivanovalion
 
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...Suhani Kapoor
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Delhi Call girls
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysismanisha194592
 
CebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxCebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxolyaivanovalion
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改atducpo
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998YohFuh
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationshipsccctableauusergroup
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxolyaivanovalion
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfRachmat Ramadhan H
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% SecurePooja Nehwal
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAroojKhan71
 

Recently uploaded (20)

BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptx
 
Edukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxEdukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFx
 
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
 
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signals
 
Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptx
 
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysis
 
CebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxCebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptx
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptx
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
 

nlp2.pdf

  • 1. CMU 15-7/381 CSPs Teachers: Ariel Procaccia Emma Brunskill (THIS TIME) With thanks to Ariel Procaccia and other prior instructions for slides
  • 2. Class Scheduling Woes • 4 more required classes to graduate o A: Algorithms B: Bayesian Learning o C: Computer Programming D: Distributed Computing • A few restrictions o Algorithms must be taken same semester as distributed computing o Computer programming is a prereq for distributed computing and Bayesian learning, so it must be taken in an earlier semester o Advanced algorithms and Bayesian Learning are always offered at the same time, so they cannot be taken the same semester • 3 semesters (semester 1,2,3) when can take classes 2
  • 3. Constraint Satisfaction Problems (CSPs) • Variables: V = {V1,..,VN} • Domain: Set of d possible values for each variable • Constraints: C = {C1,..,CK} • A constraint consists of o variable tuple o list of possible values for tuple (ex.[(V2,V3),{(R,B),(R,G)]) o Or function that describes possible values (ex. V2 ≠ V3) • Allows useful general-purpose algorithms with more power than standard search algorithms 3
  • 4. Overview • Real world CSPs • Basic algorithms for solving CSPs • Pruning space through propagating information 4
  • 5. Overview • Real world CSPs • Basic algorithms for solving CSPs • Pruning space through propagating information 5
  • 6. Example: Map Coloring Color a map so that adjacent areas are different colors 6
  • 8. Example: Suduko • Variables: • Domain: • Constraints: 8
  • 9. Example: Suduko • Variables: o Each open sqr • Domain: o {1:9} • Constraints: o 9-way all diff col o 9-way all diff row o 9-way all diff box 9
  • 10. Scheduling (Important Ex.) • Many industries. Many multi-million $ decisions. Used extensively for space mission planning. Military uses. • People really care about improving scheduling algorithms! Problems with phenomenally huge state spaces. But for which solutions are needed very quickly • Many kinds of scheduling problems e.g.: o Job shop: Discrete time; weird ordering of operations possible; set of separate jobs. o Batch shop: Discrete or continuous time; restricted operation of ordering; grouping is important. 10
  • 11. Job Scheduling • A set of N jobs, J1,…, Jn. • Each job j is a seq of operations Oj 1,..., Oj Lj • Each operation may use resource R, and has a specific duration in time. • A resource must be used by a single operation at a time. • All jobs must be completed by a due time. • Problem: assign a start time to each job. 11
  • 12. Exercise: Define CSP • 4 more required classes to graduate: A, B, C, D • A must be taken same semester as D • C is a prereq for D and B so must take C earlier than D & B • A & B are always offered at the same time, so they cannot be taken the same semester • 3 semesters (semester 1,2,3) when can take classes • Variables: A,B,C,D • Domain: {1,2,3} • Constraints: A ≠ B, A=D, C < B, C < D 12
  • 13. Overview • Real world CSPs • Basic algorithms for solving CSPs • Pruning space through propagating information 13
  • 14. Why not just do basic search algorithms from last time? 14
  • 15. Backtracking • Only consider a single variable at each point • Don’t care about path! 15
  • 16. Backtracking • Only consider a single variable at each point • Don’t care about path! • Order of variable assignment doesn’t matter, so fix ordering 16
  • 17. Backtracking • Only consider a single variable at each point • Don’t care about path! • Order of variable assignment doesn’t matter, so fix ordering • Only consider values which do not conflict with assignment made so far 17
  • 18. Backtracking • Only consider a single variable at each point • Don’t care about path! • Order of variable assignment doesn’t matter, so fix ordering • Only consider values which do not conflict with assignment made so far • Depth-first search for CSPs with these two improvements is called backtracking search 18
  • 19. Backtracking • Function Backtracking(csp) returns soln or fail o Return Backtrack({},csp) • Function Backtrack(assignment,csp) returns soln or fail o If assignment is complete, return assignment o Viß select_unassigned_var(csp) o For each val in order-domain-values(var,csp,assign) If value is consistent with assignment Add [Vi = val] to assignment Result ß Backtrack(assignment,csp) If Result ≠ fail, return result Remove [Vi = val] from assignments o Return fail 19
  • 20. Backtracking Example • Variables: A,B,C,D • Domain: {1,2,3} • Constraints: o A ≠ B, A=D, C < B, C < D • Variable order: ? • Value order: ? 20
  • 21. Backtracking • Function Backtracking(csp) returns soln or fail o Return Backtrack({},csp) • Function Backtrack(assignment,csp) returns soln or fail o If assignment is complete, return assignment o Viß select_unassigned_var(csp) o For each val in order-domain-values(var,csp,assign) If value is consistent with assignment Add [Vi = val] to assignment Result ß Backtrack(assignment,csp) If Result ≠ fail, return result Remove [Vi = val] from assignments o Return fail 21
  • 22. Think and discuss • Does the value order used affect how long backtracking takes to find a solution? • Does the value order used affect the solution found by backtracking? 22
  • 23. Example Variables: A,B,C,D Domain: {1,2,3} Constraints: A ≠ B, A=D, C < B, C < D Variable order: alphabetical Value order: Descending • (A=3) 23
  • 24. Example Variables: A,B,C,D Domain: {1,2,3} Constraints: A ≠ B, A=D, C < B, C < D Variable order: alphabetical Value order: Descending • (A=3) • (A=3, B=3) inconsistent with A ≠ B • (A=3, B=2) • (A=3, B=2, C=3) inconsistent with C < B • (A=3, B=2, C=2) inconsistent with C < B • (A=3, B=2, C=1) • (A=3, B=2, C=1,D=3) VALID 24
  • 25. Example Variables: A,B,C,D Domain: {1,2,3} Constraints: A ≠ B, A=D, C < B, C < D Variable order: alphabetical Value order: Ascending • (A=1) 25
  • 26. Example Variables: A,B,C,D Domain: {1,2,3} Constraints: A ≠ B, A=D, C < B, C < D Variable order: alphabetical Value order: Ascending • (A=1) • (A=1,B=1) inconsistent with A ≠ B • (A=1,B=2) • (A=1,B=2,C=1) • (A=1,B=2,C=1,D=1) inconsistent with C < D • (A=1,B=2,C=1,D=2) inconsistent with A=D • (A=1,B=2,C=1,D=3) inconsistent with A=D 26
  • 27. Example Variables: A,B,C,D Domain: {1,2,3} Constraints: A ≠ B, A=D, C < B, C < D Variable order: alphabetical Value order: Ascending 27 § (A=1) § (A=1,B=1) inconsistent with A ≠ B § (A=1,B=2) § (A=1,B=2,C=1) § (A=1,B=2,C=1,D=1) inconsistent with C < D § (A=1,B=2,C=1,D=2) inconsistent with A=D § (A=1,B=2,C=1,D=3) inconsistent with A=D § No valid assignment for D, return result = fail § Backtrack to (A=1,B=2,C=) § Try (A=1,B=2,C=2) but inconsistent with C < B § Try (A=1,B=2,C=3) but inconsistent with C < B § No other assignments for C, return result= fail § Backtrack to (A=1,B=) § (A=1,B=3) § (A=1,B=3,C=1) § (A=1,B=3,C=1,D=1) inconsistent with C < D § (A=1,B=3,C=1,D=2) inconsistent with A = D § (A=1,B=3,C=1,D=3) inconsistent with A = D § Return result = fail § Backtrack to (A=1,B=3,C=) § (A=1,B=3,C=2) inconsistent with C < B § (A=1,B=3,C=3) inconsistent with C < B § No remaining assignments for C, return fail § Backtrack to (A=1,B=) § No remaining assignments for B, return fail § Backtrack to A § (A=2) § (A=2,B=1) § (A=2,B=1,C=1) inconsistent with C < B § (A=2,B=1,C=2) inconsistent with C < B § (A=2,B=1,C=3) inconsistent with C < B § No remaining assignments for C, return fail § Backtrack to (A=2,B=?) § (A=2,B=2) inconsistent with A ≠ B § (A=2,B=3) § (A=2,B=3,C=1) § (A=2,B=3,C=1,D=1) inconsistent with C < D § (A=2,B=3,C=1,D=2) ALL VALID
  • 28. Ordering Matters! • Function Backtracking(csp) returns soln or fail o Return Backtrack({},csp) • Function Backtrack(assignment,csp) returns soln or fail o If assignment is complete, return assignment o Viß select_unassigned_var(csp) o For each val in order-domain-values(var,csp,assign) If value is consistent with assignment Add [Vi = val] to assignment Result ß Backtrack(assignment,csp) If Result ≠ fail, return result Remove [Vi = val] from assignments o Return fail 28
  • 29. Min Remaining Values (MRV) • Choose variable with minimum number of remaining values in its domain • Why min rather than max? 29
  • 30. Min Remaining Values (MRV) • Choose variable with minimum number of remaining values in its domain • Most constrained variable • “Fail-fast” ordering 30
  • 31. Least Constraining Value • Given choice of variable: o Choose least constraining value o Aka value that rules out the least values in the remaining variables to be assigned o May take some computation to find this • Why least rather than most? 31
  • 32. Click! Cost of Backtracking? • d values per variable • n variables • Possible number of CSP assignments? • A) O(dn) • B) O(nd) • C) O(nd) 32
  • 33. Overview • Real world CSPs • Basic algorithms for solving CSPs • Pruning space through propagating information 33
  • 34. Limitations of Backtracking • Function Backtracking(csp) returns soln or fail o Return Backtrack({},csp) • Function Backtrack(assignment,csp) returns soln or fail o If assignment is complete, return assignment o Viß select_unassigned_var(csp) o For each val in order-domain-values(var,csp,assign) If value is consistent with assignment Add [Vi = val] to assignment Result ß Backtrack(assignment,csp) If Result ≠ fail, return result Remove [Vi = val] from assignments o Return fail 34
  • 35. Constraint Graphs • Nodes are variables • Arcs show constraints 35
  • 36. Propagate Information • If we choose a value for one variable, that affects its neighbors • And then potentially those neighbors… • Prunes the space of solutions 36
  • 37. Arc Consistency • Definition: o An “arc” (connection between two variables X à Y in constraint graph) is consistent if: o For every value could assign to X There exists some value of Y that could be assigned without violating a constraint 37
  • 38. AC-3 (Assume binary constraints) • Input: CSP • Output: CSP, possible with reduced domains for variables, or inconsistent • Local variables: stack, initially stack of all arcs (binary constraints in csp) • While stack is not empty • (Xi,Xj) = Remove-First(stack) • [domainXi, anyChangeToDomainXi] = Revise(csp,Xi,Xj) • if anyChangeToDomainXi == true • if size(domainXi) = 0, return inconsistent • else • for each Xk in Neighbors(Xi) except Xj • add (Xk,Xi) to stack • Return csp • ------------------------------------------------------------------------------------------------------------------- • Function Revise(csp,Xi,Xj) returns DomainXi and anyChangeToDomainXi • anyChangeToDomainXi = false • for each x in Domain(Xi) • if no value y in Domain(Xj) allows (x,y) to satisfy constraint between (Xi,Xj) • delete x from Domain(Xi) • anyChangeToDomainXi = true 38 Have to add in arc for (Xi,Xj) and (Xj,Xi) for i,j constraint
  • 39. AC-3 (Assume binary constraints) • Input: CSP • Output: CSP, possible with reduced domains for variables, or inconsistent • Local variables: stack, initially stack of all arcs (binary constraints in csp) • While stack is not empty • (Xi,Xj) = Remove-First(stack) • [domainXi, anyChangeToDomainXi] = Revise(csp,Xi,Xj) • if anyChangeToDomainXi == true • if size(domainXi) = 0, return inconsistent • else • for each Xk in Neighbors(Xi) except Xj • add (Xk,Xi) to stack • Return csp • ------------------------------------------------------------------------------------------------------------------- • Function Revise(csp,Xi,Xj) returns DomainXi and anyChangeToDomainXi • anyChangeToDomainXi = false • for each x in Domain(Xi) • if no value y in Domain(Xj) allows (x,y) to satisfy constraint between (Xi,Xj) • delete x from Domain(Xi) • anyChangeToDomainXi = true 39 Have to add in arc for (Xi,Xj) and (Xj,Xi) for i,j constraint
  • 40. AC-3 Computational Complexity? • Input: CSP • Output: CSP, possible with reduced domains for variables, or inconsistent • Local variables: stack, initially stack of all arcs (binary constraints in csp) • While stack is not empty • (Xi,Xj) = Remove-First(stack) • [domainXi, anyChangeToDomainXi] = Revise(csp,Xi,Xj) • if anyChangeToDomainXi == true • if size(domainXi) = 0, return inconsistent • else • for each Xk in Neighbors(Xi) except Xj • add (Xk,Xi) to stack • Return csp • ------------------------------------------------------------------------------------------------------------ • Function Revise(csp,Xi,Xj) returns DomainXi and anyChangeToDomainXi • anyChangeToDomainXi = false • for each x in Domain(Xi) • if no value y in Domain(Xj) allows (x,y) to satisfy constraint between (Xi,Xj) • delete x from Domain(Xi) • anyChangeToDomainXi = true 40 Have to add in arc for (Xi,Xj) and (Xj,Xi) for i,j constraint D domain values C binary constraints Complexity of revise function? D2
  • 41. AC-3 Computational Complexity? • Input: CSP • Output: CSP, possible with reduced domains for variables, or inconsistent • Local variables: stack, initially stack of all arcs (binary constraints in csp) • While stack is not empty • (Xi,Xj) = Remove-First(stack) • [domainXi, anyChangeToDomainXi] = Revise(csp,Xi,Xj) • if anyChangeToDomainXi == true • if size(domainXi) = 0, return inconsistent • else • for each Xk in Neighbors(Xi) except Xj • add (Xk,Xi) to stack • Return csp • ------------------------------------------------------------------------------------------------------------ • Function Revise(csp,Xi,Xj) returns DomainXi and anyChangeToDomainXi • anyChangeToDomainXi = false • for each x in Domain(Xi) • if no value y in Domain(Xj) allows (x,y) to satisfy constraint between (Xi,Xj) • delete x from Domain(Xi) • anyChangeToDomainXi = true 41 Have to add in arc for (Xi,Xj) and (Xj,Xi) for i,j constraint D domain values C binary constraints Complexity of revise function? D2 Number of times can put a constraint in stack?
  • 42. AC-3 Computational Complexity? • Input: CSP • Output: CSP, possible with reduced domains for variables, or inconsistent • Local variables: stack, initially stack of all arcs (binary constraints in csp) • While stack is not empty • (Xi,Xj) = Remove-First(stack) • [domainXi, anyChangeToDomainXi] = Revise(csp,Xi,Xj) • if anyChangeToDomainXi == true • if size(domainXi) = 0, return inconsistent • else • for each Xk in Neighbors(Xi) except Xj • add (Xk,Xi) to stack • Return csp • ------------------------------------------------------------------------------------------------------------ • Function Revise(csp,Xi,Xj) returns DomainXi and anyChangeToDomainXi • anyChangeToDomainXi = false • for each x in Domain(Xi) • if no value y in Domain(Xj) allows (x,y) to satisfy constraint between (Xi,Xj) • delete x from Domain(Xi) • anyChangeToDomainXi = true 42 Have to add in arc for (Xi,Xj) and (Xj,Xi) for i,j constraint D domain values C binary constraints Complexity of revise function? D2 Number of times can put a constraint in stack? D Total: CD3
  • 43. AC-3 Example • Variables: A,B,C,D • Domain: {1,2,3} • Constraints: A ≠ B, C < B, C < D (subset of constraints from before) 44
  • 44. AC-3 Example • Variables: A,B,C,D • Domain: {1,2,3} • Constraints: A ≠ B, C < B, C < D (subset of constraints from before) • Constraints both ways: A≠ B, B≠ A, C < B, B > C, C < D, D > C 45
  • 45. AC-3 Example • Variables: A,B,C,D • Domain: {1,2,3} • Constraints: A ≠ B, C < B, C < D (subset of constraints from before) • Constraints both ways: A≠ B, B≠ A, C < B, B > C, C < D, D > C • stack: AB, BA, BC, CB, CD, DC 46
  • 46. AC-3 Example • Variables: A,B,C,D • Domain: {1,2,3} • Constraints: A ≠ B, C < B, C < D (subset of constraints from before) • Constraints both ways: A≠ B, B≠ A, C < B, B > C, C < D, D > C • stack: AB, BA, BC, CB, CD, DC • Pop AB: • for each x in Domain(A) if no value y in Domain(B) that allows (x,y) to satisfy constraint between (A,B), delete x from Domain(A) • No change to domain of A 47
  • 47. AC-3 Example • Variables: A,B,C,D • Domain: {1,2,3} • Constraints: A ≠ B, C < B, C < D (subset of constraints from before) • Constraints both ways: A≠ B, B≠ A, C < B, B > C, C < D, D > C • stack: AB, BA, BC, CB, CD, DC • Pop AB • stack: BA, BC, CB, CD, DC 48
  • 48. AC-3 Example • Variables: A,B,C,D • Domain: {1,2,3} • Constraints: A ≠ B, C < B, C < D (subset of constraints from before) • Constraints both ways: A≠ B, B≠ A, C < B, B > C, C < D, D > C • stack: AB, BA, BC, CB, CD, DC • Pop AB • stack: BA, BC, CB, CD, DC • Pop BA • for each x in Domain(B) if no value y in Domain(A) that allows (x,y) to satisfy constraint between (B,A), delete x from Domain(B) • No change to domain of B 49
  • 49. AC-3 Example • Variables: A,B,C,D • Domain: {1,2,3} • Constraints: A ≠ B, C < B, C < D (subset of constraints from before) • Constraints both ways: A≠ B, B≠ A, C < B, B > C, C < D, D > C • stack: AB, BA, BC, CB, CD, DC • stack: BA, BC, CB, CD, DC • stack: BC, CB, CD, DC • Pop BC • for each x in Domain(B) if no value y in Domain(C) that allows (x,y) to satisfy constraint between (B,C), delete x from Domain(B) • If B is 1, constraint B >C cannot be satisfied. So delete 1 from B’s domain, B={2,3} • Also have to add neighbors of B (except C) back to stack: AB • stack: AB, CB, CD, DC 50
  • 50. AC-3 Example • stack: AB, BA, BC, CB, CD, DC A-D = {1,2,3} • stack: BA, BC, CB, CD, DC A-D = {1,2,3} • stack: BC, CB, CD, DC A-D = {1,2,3} • stack: AB, CB, CD, DC B={2,3}, A/C/D = {1,2,3} • Pop AB o For every value of A is there a value of B such that A ≠ B? o Yes, so no change 51 Variables: A,B,C,D Domain: {1,2,3} Constraints: A ≠ B, C < B, C < D
  • 51. AC-3 Example • stack: AB, BA, BC, CB, CD, DC, A-D = {1,2,3} • stack: BA, BC, CB, CD, DC A-D = {1,2,3} • stack: BC, CB, CD, DC A-D = {1,2,3} • stack: AB, CB, CD, DC B={2,3}, A/C/D = {1,2,3} • stack: CB, CD, DC B={2,3}, A/C/D = {1,2,3} • Pop CB o For every value of C is there a value of B such that C < B o If C = 3, no value of B that fits o So delete 3 from C’s domain, C = {1,2} o Also have to add neighbors of C (except B) back to stack: no change because already in 52 Variables: A,B,C,D Domain: {1,2,3} Constraints: A ≠ B, C < B, C < D
  • 52. AC-3 Example • stack: AB, BA, BC, CB, CD, DC, A-D = {1,2,3} • stack: BA, BC, CB, CD, DC A-D = {1,2,3} • stack: BC, CB, CD, DC A-D = {1,2,3} • stack: AB, CB, CD, DC B={2,3}, A/C/D = {1,2,3} • stack: CB, CD, DC B={2,3}, A/C/D = {1,2,3} • stack: CD, DC B={2,3}, C = {1,2} A,D = {1,2,3} • Pop CD o For every value of C, is there a value of D such that C < D? o Yes, so no change 53 Variables: A,B,C,D Domain: {1,2,3} Constraints: A ≠ B, C < B, C < D
  • 53. AC-3 Example • stack: AB, BA, BC, CB, CD, DC A-D = {1,2,3} • stack: BA, BC, CB, CD, DC A-D = {1,2,3} • stack: BC, CB, CD, DC A-D = {1,2,3} • stack: AB, CB, CD, DC B={2,3}, A/C/D = {1,2,3} • stack: CB, CD, DC B={2,3}, A/C/D = {1,2,3} • stack: CD, DC B={2,3}, C = {1,2} A,D = {1,2,3} • stack: DC B={2,3}, C = {1,2} A,D = {1,2,3} • For every value of D is there a value of C such that D > C? o Not if D = 1 o So D = {2,3} 54 Variables: A,B,C,D Domain: {1,2,3} Constraints: A ≠ B, C < B, C < D
  • 54. AC-3 Example • stack: AB, BA, BC, CB, CD, DC A-D = {1,2,3} • stack: BA, BC, CB, CD, DC A-D = {1,2,3} • stack: BC, CB, CD, DC A-D = {1,2,3} • stack: AB, CB, CD, DC B={2,3}, A/C/D = {1,2,3} • stack: CB, CD, DC B={2,3}, A/C/D = {1,2,3} • stack: CD, DC B={2,3}, C = {1,2} A,D = {1,2,3} • stack: DC B={2,3}, C = {1,2} A,D = {1,2,3} • A = {1,2,3} B={2,3}, C = {1,2} D = {2,3} 55 Variables: A,B,C,D Domain: {1,2,3} Constraints: A ≠ B, C < B, C < D
  • 55. Forward Checking • When assign a variable, make all of its neighbors arc-consistent 56
  • 56. Backtracking + Forward Checking • Function Backtrack(assignment,csp) returns soln or fail o If assignment is complete, return assignment o Viß select_unassigned_var(csp) o For each val in order-domain-values(var,csp,assign) If value is consistent with assignment Add [Vi = val] to assignment Make domains of all neighbors of Vi arc-consistent with [Vi = val] Result ß Backtrack(assignment,csp) If Result ≠ fail, return result Remove [Vi = val] from assignments o Return fail 57
  • 57. Maintaining Arc Consistency • Forward checking doesn’t ensure all arcs are consistent • AC-3 detects failure faster than forward checking • What’s the downside? Computation 58
  • 58. Maintaining Arc Consistency (MAC) • Function Backtrack(assignment,csp) returns soln or fail o If assignment is complete, return assignment o Viß select_unassigned_var(csp) o For each val in order-domain-values(var,csp,assign) If value is consistent with assignment Add [Vi = val] to assignment Run AC-3 to make all variables arc-consistent with [Vi = val]. Initial stack is arcs (Xj,Vi) of neighbors of Vi that are unassigned, but add other arcs if these vars change domains. Result ß Backtrack(assignment,csp) If Result ≠ fail, return result Remove [Vi = val] from assignments o Return fail 59
  • 59. Sufficient to Avoid backtracking? • If we maintain arc consistency, we will never have to backtrack while solving a CSP • A) True • B) False 60
  • 60. AC-3 Limitations • After running AC-3 o Can have one solution left o Can have multiple solutions left o Can have no solutions left (and not know it) 61
  • 61. AC-3 Limitations • After running AC-3 o Can have one solution left o Can have multiple solutions left o Can have no solutions left (and not know it) 62 What went wrong here?
  • 62. Complexity • CSP in general are NP-hard • Some structured domains are easier 63
  • 63. Constraint Trees 64 • Constraint tree o Any 2 variables in constraint graph connected by <= 1 path • Can be solved in time linear in # of variables Figure from Russell & Norvig
  • 64. 1) Choose any var as root and order vars such that every var’s parents in constraint graph precede it in ordering 2) Let Xi be the parent of Xj in the new ordering 3) For j=n:2, run arc consistency to arc (Xi,Xj) 4) For j=1:n, assign val for Xj consistent w/val assigned for Xi Algorthm for CSP Trees 65 Figure from Russell & Norvig
  • 65. 1) Choose any var as root and order vars such that every var’s parents in constraint graph precede it in ordering 2) Let Xi be the parent of Xj in the new ordering 3) For j=n:2, run arc consistency to arc (Xi,Xj) 4) For j=1:n, assign val for Xj consistent w/val assigned for Xi Computational Complexity? 66 Figure from Russell & Norvig
  • 66. Summary • Be able to define real world CSPs • Understand basic algorithm (backtracking) o Complexity relative to basic search algorithms o Doesn’t require problem specific heuristics o Ideas shaping search (LCV, etc) • Pruning space through propagating information o Arc consistency o Tradeoffs: + reduces search space, - costs computation • Computational complexity and special cases (tree) • Relevant reading: R&N Chapter 6 67