SlideShare a Scribd company logo
Artificial Intelligence
1: Constraint Satis-
faction problems
Lecturer: Tom Lenaerts
Institut de Recherches Interdisciplinaires et de
Développements en Intelligence Artificielle
(IRIDIA)
Université Libre de Bruxelles
TLo (IRIDIA) 2October 13, 2015
Outline
 CSP?
 Backtracking for CSP
 Local search for CSPs
 Problem structure and decomposition
TLo (IRIDIA) 3October 13, 2015
Constraint satisfaction
problems
 What is a CSP?
 Finite set of variables V1, V2, …, Vn
 Finite set of constrainsC1, C2, …, Cm
 Nonemtpy domain of possible values for each variable
DV1, DV2, … DVn
 Each constraint Ci limits the values that variables can
take, e.g., V1 ≠ V2
 A state is defined as an assignment of values to some or
all variables.
 Consistent assignment: assignment does not not violate
the constraints.
TLo (IRIDIA) 4October 13, 2015
Constraint satisfaction
problems
 An assignment is complete when every value is
mentioned.
 A solution to a CSP is a complete assignment that
satisfies all constraints.
 Some CSPs require a solution that maximizes an
objective function.
 Applications: Scheduling the time of observations on the
Hubble Space Telescope, Floor planning, Map coloring,
Cryptography
TLo (IRIDIA) 5October 13, 2015
CSP example: map coloring
 Variables: WA, NT, Q, NSW, V, SA, T
 Domains: Di={red,green,blue}
 Constraints:adjacent regions must have different colors.
 E.g. WA ≠ NT (if the language allows this)
 E.g. (WA,NT) ≠ {(red,green),(red,blue),(green,red),…}
TLo (IRIDIA) 6October 13, 2015
CSP example: map coloring
 Solutions are assignments satisfying all constraints, e.g.
{WA=red,NT=green,Q=red,NSW=green,V=red,SA=blue,T=green}
TLo (IRIDIA) 7October 13, 2015
Constraint graph
 CSP benefits
 Standard representation pattern
 Generic goal and successor functions
 Generic heuristics (no domain
specific expertise).
 Constraint graph = nodes are variables, edges show constraints.
 Graph can be used to simplify search.
 e.g. Tasmania is an independent subproblem.
TLo (IRIDIA) 8October 13, 2015
Varieties of CSPs
 Discrete variables
 Finite domains; size d ⇒O(dn
) complete assignments.
 E.g. Boolean CSPs, include. Boolean satisfiability (NP-complete).
 Infinite domains (integers, strings, etc.)
 E.g. job scheduling, variables are start/end days for each job
 Need a constraint language e.g StartJob1 +5 ≤ StartJob3.
 Linear constraints solvable, nonlinear undecidable.
 Continuous variables
 e.g. start/end times for Hubble Telescope observations.
 Linear constraints solvable in poly time by LP methods.
TLo (IRIDIA) 9October 13, 2015
Varieties of constraints
 Unary constraints involve a single variable.
 e.g. SA ≠ green
 Binary constraints involve pairs of variables.
 e.g. SA ≠ WA
 Higher-order constraints involve 3 or more variables.
 e.g. cryptharithmetic column constraints.
 Preference (soft constraints) e.g. red is better than green
often representable by a cost for each variable assignment
→ constrained optimization problems.
TLo (IRIDIA) 10October 13, 2015
Example; cryptharithmetic
TLo (IRIDIA) 11October 13, 2015
CSP as a standard search
problem
 A CSP can easily expressed as a standard search
problem.
 Incremental formulation
 Initial State: the empty assignment {}.
 Successor function: Assign value to unassigned
variable provided that there is not conflict.
 Goal test: the current assignment is complete.
 Path cost: as constant cost for every step.
TLo (IRIDIA) 12October 13, 2015
CSP as a standard search
problem
 This is the same for all CSP’s !!!
 Solution is found at depth n (if there are n variables).
 Hence depth first search can be used.
 Path is irrelevant, so complete state representation can
also be used.
 Branching factor b at the top level is nd.
 b=(n-l)d at depth l, hence n!dn
leaves (only dn
complete
assignments).
TLo (IRIDIA) 13October 13, 2015
Commutativity
 CSPs are commutative.
 The order of any given set of actions has no effect
on the outcome.
 Example: choose colors for Australian territories
one at a time
 [WA=red then NT=green] same as [NT=green then
WA=red]
 All CSP search algorithms consider a single variable
assignment at a time ⇒ there are dn
leaves.
TLo (IRIDIA) 14October 13, 2015
Backtracking search
 Cfr. Depth-first search
 Chooses values for one variable at a time and
backtracks when a variable has no legal values
left to assign.
 Uninformed algorithm
 No good general performance (see table p. 143)
TLo (IRIDIA) 15October 13, 2015
Backtracking search
function BACKTRACKING-SEARCH(csp) return a solution or failure
return RECURSIVE-BACKTRACKING({} , csp)
function RECURSIVE-BACKTRACKING(assignment, csp) return a solution or failure
if assignment is complete then return assignment
var ← SELECT-UNASSIGNED-VARIABLE(VARIABLES[csp],assignment,csp)
for each value in ORDER-DOMAIN-VALUES(var, assignment, csp) do
if value is consistent with assignment according to CONSTRAINTS[csp] then
add {var=value} to assignment
result ← RRECURSIVE-BACTRACKING(assignment, csp)
if result ≠ failure then return result
remove {var=value} from assignment
return failure
TLo (IRIDIA) 16October 13, 2015
Backtracking example
TLo (IRIDIA) 17October 13, 2015
Backtracking example
TLo (IRIDIA) 18October 13, 2015
Backtracking example
TLo (IRIDIA) 19October 13, 2015
Backtracking example
TLo (IRIDIA) 20October 13, 2015
Improving backtracking efficiency
 Previous improvements → introduce heuristics
 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?
 Can we take advantage of problem structure?
TLo (IRIDIA) 21October 13, 2015
Minimum remaining values
var ← SELECT-UNASSIGNED-VARIABLE(VARIABLES[csp],assignment,csp)
 A.k.a. most constrained variable heuristic
 Rule: choose variable with the fewest legal moves
 Which variable shall we try first?
TLo (IRIDIA) 22October 13, 2015
Degree heuristic
 Use degree heuristic
 Rule: select variable that is involved in the largest number of
constraints on other unassigned variables.
 Degree heuristic is very useful as a tie breaker.
 In what order should its values be tried?
TLo (IRIDIA) 23October 13, 2015
Least constraining value
 Least constraining value heuristic
 Rule: given a variable choose the least constraing value i.e. the one
that leaves the maximum flexibility for subsequent variable
assignments.
TLo (IRIDIA) 24October 13, 2015
Forward checking
 Can we detect inevitable failure early?
 And avoid it later?
 Forward checking idea: keep track of remaining legal values for
unassigned variables.
 Terminate search when any variable has no legal values.
TLo (IRIDIA) 25October 13, 2015
Forward checking
 Assign {WA=red}
 Effects on other variables connected by constraints with WA
 NT can no longer be red
 SA can no longer be red
TLo (IRIDIA) 26October 13, 2015
Forward checking
 Assign {Q=green}
 Effects on other variables connected by constraints with WA
 NT can no longer be green
 NSW can no longer be green
 SA can no longer be green
 MRV heuristic will automatically select NT and SA next, why?
TLo (IRIDIA) 27October 13, 2015
Forward checking
 If V is assigned blue
 Effects on other variables connected by constraints with WA
 SA is empty
 NSW can no longer be blue
 FC has detected that partial assignment is inconsistent with the constraints
and backtracking can occur.
TLo (IRIDIA) 28October 13, 2015
Example: 4-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}
[4-Queens slides copied from B.J. Dorr CMSC 421 course on AI]
TLo (IRIDIA) 29October 13, 2015
Example: 4-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}
TLo (IRIDIA) 30October 13, 2015
Example: 4-Queens Problem
1
3
2
4
32 41
X1
{1,2,3,4}
X3
{ ,2, ,4}
X4
{ ,2,3, }
X2
{ , ,3,4}
TLo (IRIDIA) 31October 13, 2015
Example: 4-Queens Problem
1
3
2
4
32 41
X1
{1,2,3,4}
X3
{ ,2, ,4}
X4
{ ,2,3, }
X2
{ , ,3,4}
TLo (IRIDIA) 32October 13, 2015
Example: 4-Queens Problem
1
3
2
4
32 41
X1
{1,2,3,4}
X3
{ , , , }
X4
{ ,2,3, }
X2
{ , ,3,4}
TLo (IRIDIA) 33October 13, 2015
Example: 4-Queens Problem
1
3
2
4
32 41
X1
{ ,2,3,4}
X3
{1,2,3,4}
X4
{1,2,3,4}
X2
{1,2,3,4}
TLo (IRIDIA) 34October 13, 2015
Example: 4-Queens Problem
1
3
2
4
32 41
X1
{ ,2,3,4}
X3
{1, ,3, }
X4
{1, ,3,4}
X2
{ , , ,4}
TLo (IRIDIA) 35October 13, 2015
Example: 4-Queens Problem
1
3
2
4
32 41
X1
{ ,2,3,4}
X3
{1, ,3, }
X4
{1, ,3,4}
X2
{ , , ,4}
TLo (IRIDIA) 36October 13, 2015
Example: 4-Queens Problem
1
3
2
4
32 41
X1
{ ,2,3,4}
X3
{1, , , }
X4
{1, ,3, }
X2
{ , , ,4}
TLo (IRIDIA) 37October 13, 2015
Example: 4-Queens Problem
1
3
2
4
32 41
X1
{ ,2,3,4}
X3
{1, , , }
X4
{1, ,3, }
X2
{ , , ,4}
TLo (IRIDIA) 38October 13, 2015
Example: 4-Queens Problem
1
3
2
4
32 41
X1
{ ,2,3,4}
X3
{1, , , }
X4
{ , ,3, }
X2
{ , , ,4}
TLo (IRIDIA) 39October 13, 2015
Example: 4-Queens Problem
1
3
2
4
32 41
X1
{ ,2,3,4}
X3
{1, , , }
X4
{ , ,3, }
X2
{ , , ,4}
TLo (IRIDIA) 40October 13, 2015
Constraint propagation
 Solving CSPs with combination of heuristics plus forward checking
is more efficient than either approach alone.
 FC checking propagates information from assigned to unassigned
variables but does not provide detection for all failures.
 NT and SA cannot be blue!
 Constraint propagation repeatedly enforces constraints locally
TLo (IRIDIA) 41October 13, 2015
Arc consistency
 X → Y is consistent iff
for every value x of X there is some allowed y
 SA → NSW is consistent iff
SA=blue and NSW=red
TLo (IRIDIA) 42October 13, 2015
Arc consistency
 X → Y is consistent iff
for every value x of X there is some allowed y
 NSW → SA is consistent iff
NSW=red and SA=blue
NSW=blue and SA=???
Arc can be made consistent by removing blue from NSW
TLo (IRIDIA) 43October 13, 2015
Arc consistency
 Arc can be made consistent by removing blue from NSW
 RECHECK neighbours !!
 Remove red from V
TLo (IRIDIA) 44October 13, 2015
Arc consistency
 Arc can be made consistent by removing blue from NSW
 RECHECK neighbours !!
 Remove red from V
 Arc consistency detects failure earlier than FC
 Can be run as a preprocessor or after each assignment.
 Repeated until no inconsistency remains
TLo (IRIDIA) 45October 13, 2015
Arc consistency algorithm
function AC-3(csp) return the CSP, possibly with reduced domains
inputs: csp, a binary csp with variables {X1, X2, …, Xn}
local variables: queue, a queue of arcs initially the arcs in csp
while queue is not empty do
(Xi, Xj) ← REMOVE-FIRST(queue)
if REMOVE-INCONSISTENT-VALUES(Xi, Xj) then
for each Xk in NEIGHBORS[Xi ] do
add (Xi, Xj) to queue
function REMOVE-INCONSISTENT-VALUES(Xi, Xj) return true iff we remove a value
removed ← false
for each x in DOMAIN[Xi] do
if no value y in DOMAIN[Xi] allows (x,y) to satisfy the constraints between Xi and Xj
then delete x from DOMAIN[Xi]; removed ← true
return removed
TLo (IRIDIA) 46October 13, 2015
K-consistency
 Arc consistency does not detect all inconsistencies:
 Partial assignment {WA=red, NSW=red} is inconsistent.
 Stronger forms of propagation can be defined using the
notion of k-consistency.
 A CSP is k-consistent if for any set of k-1 variables and
for any consistent assignment to those variables, a
consistent value can always be assigned to any kth
variable.
 E.g. 1-consistency or node-consistency
 E.g. 2-consistency or arc-consistency
 E.g. 3-consistency or path-consistency
TLo (IRIDIA) 47October 13, 2015
K-consistency
 A graph is strongly k-consistent if
 It is k-consistent and
 Is also (k-1) consistent, (k-2) consistent, … all the way
down to 1-consistent.
 This is ideal since a solution can be found in time O(nd)
instead of O(n2
d3
)
 YET no free lunch: any algorithm for establishing n-
consistency must take time exponential in n, in the worst
case.
TLo (IRIDIA) 48October 13, 2015
Further improvements
 Checking special constraints
 Checking Alldif(…) constraint
 E.g. {WA=red, NSW=red}
 Checking Atmost(…) constraint
 Bounds propagation for larger value domains
 Intelligent backtracking
 Standard form is chronological backtracking i.e. try different
value for preceding variable.
 More intelligent, backtrack to conflict set.
 Set of variables that caused the failure or set of previously assigned
variables that are connected to X by constraints.
 Backjumping moves back to most recent element of the conflict set.
 Forward checking can be used to determine conflict set.
TLo (IRIDIA) 49October 13, 2015
Local search for CSP
 Use complete-state representation
 For CSPs
 allow states with unsatisfied constraints
 operators reassign variable values
 Variable selection: randomly select any conflicted
variable
 Value selection: min-conflicts heuristic
 Select new value that results in a minimum number of
conflicts with the other variables
TLo (IRIDIA) 50October 13, 2015
Local search for CSP
function MIN-CONFLICTS(csp, max_steps) return solution or failure
inputs: csp, a constraint satisfaction problem
max_steps, the number of steps allowed before giving up
current ← an initial complete assignment for csp
for i = 1 to max_steps do
if current is a solution for csp then return current
var ← a randomly chosen, conflicted variable from VARIABLES[csp]
value ← the value v for var that minimizes CONFLICTS(var,v,current,csp)
set var = value in current
return faiilure
TLo (IRIDIA) 51October 13, 2015
Min-conflicts example 1
 Use of min-conflicts heuristic in hill-climbing.
h=5 h=3 h=1
TLo (IRIDIA) 52October 13, 2015
Min-conflicts example 2
 A two-step solution for an 8-queens problem using min-conflicts
heuristic.
 At each stage a queen is chosen for reassignment in its column.
 The algorithm moves the queen to the min-conflict square breaking
ties randomly.
TLo (IRIDIA) 53October 13, 2015
Problem structure
 How can the problem structure help to find a solution quickly?
 Subproblem identification is important:
 Coloring Tasmania and mainland are independent subproblems
 Identifiable as connected components of constrained graph.
 Improves performance
TLo (IRIDIA) 54October 13, 2015
Problem structure
 Suppose each problem has c variables out of a total of n.
 Worst case solution cost is O(n/c dc
), i.e. linear in n
 Instead of O(d n
), exponential in n
 E.g. n= 80, c= 20, d=2
 280
= 4 billion years at 1 million nodes/sec.
 4 * 220
= .4 second at 1 million nodes/sec
TLo (IRIDIA) 55October 13, 2015
Tree-structured CSPs
 Theorem: if the constraint graph has no loops then CSP can be
solved in O(nd 2
) time
 Compare difference with general CSP, where worst case is
O(d n
)
TLo (IRIDIA) 56October 13, 2015
Tree-structured CSPs
 In most cases subproblems of a CSP are connected as a tree
 Any tree-structured CSP can be solved in time linear in the number of
variables.
 Choose a variable as root, order variables from root to leaves such that
every node’s parent precedes it in the ordering.
 For j from n down to 2, apply REMOVE-INCONSISTENT-VALUES(Parent(Xj),Xj)
 For j from 1 to n assign Xj consistently with Parent(Xj )
TLo (IRIDIA) 57October 13, 2015
Nearly tree-structured CSPs
 Can more general constraint graphs be reduced to trees?
 Two approaches:
 Remove certain nodes
 Collapse certain nodes
TLo (IRIDIA) 58October 13, 2015
Nearly tree-structured CSPs
 Idea: assign values to some variables so that the remaining variables
form a tree.
 Assume that we assign {SA=x} ← cycle cutset
 And remove any values from the other variables that are
inconsistent.
 The selected value for SA could be the wrong one so we have to
try all of them
TLo (IRIDIA) 59October 13, 2015
Nearly tree-structured CSPs
 This approach is worthwhile if cycle cutset is small.
 Finding the smallest cycle cutset is NP-hard
 Approximation algorithms exist
 This approach is called cutset conditioning.
TLo (IRIDIA) 60October 13, 2015
Nearly tree-structured CSPs
 Tree decomposition of the
constraint graph in a set of
connected subproblems.
 Each subproblem is solved
independently
 Resulting solutions are combined.
 Necessary requirements:
 Every variable appears in ar
least one of the subproblems.
 If two variables are connected
in the original problem, they
must appear together in at
least one subproblem.
 If a variable appears in two
subproblems, it must appear in
eacht node on the path.
TLo (IRIDIA) 61October 13, 2015
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 lead to failure.
 Constraint propagation does additional work to constrain values and
detect inconsistencies.
 The CSP representation allows analysis of problem structure.
 Tree structured CSPs can be solved in linear time.
 Iterative min-conflicts is usually effective in practice.

More Related Content

What's hot

DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSGayathri Gaayu
 
Automata theory
Automata theoryAutomata theory
Automata theory
Pardeep Vats
 
Problems, Problem spaces and Search
Problems, Problem spaces and SearchProblems, Problem spaces and Search
Problems, Problem spaces and Search
BMS Institute of Technology and Management
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
Dr. C.V. Suresh Babu
 
AI_Session 7 Greedy Best first search algorithm.pptx
AI_Session 7 Greedy Best first search algorithm.pptxAI_Session 7 Greedy Best first search algorithm.pptx
AI_Session 7 Greedy Best first search algorithm.pptx
Asst.prof M.Gokilavani
 
Minmax Algorithm In Artificial Intelligence slides
Minmax Algorithm In Artificial Intelligence slidesMinmax Algorithm In Artificial Intelligence slides
Minmax Algorithm In Artificial Intelligence slides
SamiaAziz4
 
Game Playing in Artificial Intelligence
Game Playing in Artificial IntelligenceGame Playing in Artificial Intelligence
Game Playing in Artificial Intelligence
lordmwesh
 
State Space Search in ai
State Space Search in aiState Space Search in ai
State Space Search in ai
vikas dhakane
 
Adversarial search
Adversarial searchAdversarial search
Adversarial searchNilu Desai
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardP, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-Hard
Animesh Chaturvedi
 
AI_Session 11: searching with Non-Deterministic Actions and partial observati...
AI_Session 11: searching with Non-Deterministic Actions and partial observati...AI_Session 11: searching with Non-Deterministic Actions and partial observati...
AI_Session 11: searching with Non-Deterministic Actions and partial observati...
Asst.prof M.Gokilavani
 
Forward and Backward chaining in AI
Forward and Backward chaining in AIForward and Backward chaining in AI
Forward and Backward chaining in AI
Megha Sharma
 
I.BEST FIRST SEARCH IN AI
I.BEST FIRST SEARCH IN AII.BEST FIRST SEARCH IN AI
I.BEST FIRST SEARCH IN AI
vikas dhakane
 
AI_Session 10 Local search in continious space.pptx
AI_Session 10 Local search in continious space.pptxAI_Session 10 Local search in continious space.pptx
AI_Session 10 Local search in continious space.pptx
Asst.prof M.Gokilavani
 
Stuart russell and peter norvig artificial intelligence - a modern approach...
Stuart russell and peter norvig   artificial intelligence - a modern approach...Stuart russell and peter norvig   artificial intelligence - a modern approach...
Stuart russell and peter norvig artificial intelligence - a modern approach...
Lê Anh Đạt
 
First Order Logic resolution
First Order Logic resolutionFirst Order Logic resolution
First Order Logic resolution
Amar Jukuntla
 
Artificial Intelligence Notes Unit 1
Artificial Intelligence Notes Unit 1 Artificial Intelligence Notes Unit 1
Artificial Intelligence Notes Unit 1
DigiGurukul
 
A* Algorithm
A* AlgorithmA* Algorithm
A* Algorithm
Dr. C.V. Suresh Babu
 
Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}
FellowBuddy.com
 
2. forward chaining and backward chaining
2. forward chaining and backward chaining2. forward chaining and backward chaining
2. forward chaining and backward chaining
monircse2
 

What's hot (20)

DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
 
Automata theory
Automata theoryAutomata theory
Automata theory
 
Problems, Problem spaces and Search
Problems, Problem spaces and SearchProblems, Problem spaces and Search
Problems, Problem spaces and Search
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
 
AI_Session 7 Greedy Best first search algorithm.pptx
AI_Session 7 Greedy Best first search algorithm.pptxAI_Session 7 Greedy Best first search algorithm.pptx
AI_Session 7 Greedy Best first search algorithm.pptx
 
Minmax Algorithm In Artificial Intelligence slides
Minmax Algorithm In Artificial Intelligence slidesMinmax Algorithm In Artificial Intelligence slides
Minmax Algorithm In Artificial Intelligence slides
 
Game Playing in Artificial Intelligence
Game Playing in Artificial IntelligenceGame Playing in Artificial Intelligence
Game Playing in Artificial Intelligence
 
State Space Search in ai
State Space Search in aiState Space Search in ai
State Space Search in ai
 
Adversarial search
Adversarial searchAdversarial search
Adversarial search
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardP, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-Hard
 
AI_Session 11: searching with Non-Deterministic Actions and partial observati...
AI_Session 11: searching with Non-Deterministic Actions and partial observati...AI_Session 11: searching with Non-Deterministic Actions and partial observati...
AI_Session 11: searching with Non-Deterministic Actions and partial observati...
 
Forward and Backward chaining in AI
Forward and Backward chaining in AIForward and Backward chaining in AI
Forward and Backward chaining in AI
 
I.BEST FIRST SEARCH IN AI
I.BEST FIRST SEARCH IN AII.BEST FIRST SEARCH IN AI
I.BEST FIRST SEARCH IN AI
 
AI_Session 10 Local search in continious space.pptx
AI_Session 10 Local search in continious space.pptxAI_Session 10 Local search in continious space.pptx
AI_Session 10 Local search in continious space.pptx
 
Stuart russell and peter norvig artificial intelligence - a modern approach...
Stuart russell and peter norvig   artificial intelligence - a modern approach...Stuart russell and peter norvig   artificial intelligence - a modern approach...
Stuart russell and peter norvig artificial intelligence - a modern approach...
 
First Order Logic resolution
First Order Logic resolutionFirst Order Logic resolution
First Order Logic resolution
 
Artificial Intelligence Notes Unit 1
Artificial Intelligence Notes Unit 1 Artificial Intelligence Notes Unit 1
Artificial Intelligence Notes Unit 1
 
A* Algorithm
A* AlgorithmA* Algorithm
A* Algorithm
 
Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}
 
2. forward chaining and backward chaining
2. forward chaining and backward chaining2. forward chaining and backward chaining
2. forward chaining and backward chaining
 

Similar to 5 csp

3 problem-solving-
3 problem-solving-3 problem-solving-
3 problem-solving-
Mhd Sb
 
SDRule-L: Managing Semantically Rich Business Decision Processes
SDRule-L: Managing Semantically Rich Business Decision ProcessesSDRule-L: Managing Semantically Rich Business Decision Processes
SDRule-L: Managing Semantically Rich Business Decision Processes
Christophe Debruyne
 
03 hdrf presentation
03 hdrf presentation03 hdrf presentation
03 hdrf presentation
AndreaCingolani
 
Node Unique Label Cover
Node Unique Label CoverNode Unique Label Cover
Node Unique Label Cover
msramanujan
 
Vanna volga method
Vanna volga methodVanna volga method
Vanna volga methodQuan Risk
 
Laser 1-background
Laser 1-backgroundLaser 1-background
Laser 1-background
Carlo Ghezzi
 
smtlecture.3
smtlecture.3smtlecture.3
smtlecture.3
Roberto Bruttomesso
 
QVT Traceability: What does it really mean?
QVT Traceability: What does it really mean?QVT Traceability: What does it really mean?
QVT Traceability: What does it really mean?
Edward Willink
 
Introduction to Max-SAT and Max-SAT Evaluation
Introduction to Max-SAT and Max-SAT EvaluationIntroduction to Max-SAT and Max-SAT Evaluation
Introduction to Max-SAT and Max-SAT Evaluation
Masahiro Sakai
 
smtlecture.10
smtlecture.10smtlecture.10
smtlecture.10
Roberto Bruttomesso
 
Cari2020 Parallel Hybridization for SAT: An Efficient Combination of Search S...
Cari2020 Parallel Hybridization for SAT: An Efficient Combination of Search S...Cari2020 Parallel Hybridization for SAT: An Efficient Combination of Search S...
Cari2020 Parallel Hybridization for SAT: An Efficient Combination of Search S...
Mokhtar SELLAMI
 
6 games
6 games6 games
6 games
Mhd Sb
 
SVD and the Netflix Dataset
SVD and the Netflix DatasetSVD and the Netflix Dataset
SVD and the Netflix Dataset
Ben Mabey
 
Wireless Localization: Ranging (first part)
Wireless Localization: Ranging (first part)Wireless Localization: Ranging (first part)
Wireless Localization: Ranging (first part)
Stefano Severi
 
The Need for Async @ ScalaWorld
The Need for Async @ ScalaWorldThe Need for Async @ ScalaWorld
The Need for Async @ ScalaWorld
Konrad Malawski
 
Introduction to Reinforcement Learning for Molecular Design
Introduction to Reinforcement Learning for Molecular Design Introduction to Reinforcement Learning for Molecular Design
Introduction to Reinforcement Learning for Molecular Design
Dan Elton
 
A Polynomial-Space Exact Algorithm for TSP in Degree-5 Graphs
A Polynomial-Space Exact Algorithm for TSP in Degree-5 GraphsA Polynomial-Space Exact Algorithm for TSP in Degree-5 Graphs
A Polynomial-Space Exact Algorithm for TSP in Degree-5 Graphs
京都大学大学院情報学研究科数理工学専攻
 
Cody Roux - Pure Type Systems - Boston Haskell Meetup
Cody Roux - Pure Type Systems - Boston Haskell MeetupCody Roux - Pure Type Systems - Boston Haskell Meetup
Cody Roux - Pure Type Systems - Boston Haskell Meetup
Greg Hale
 
Detecting paraphrases using recursive autoencoders
Detecting paraphrases using recursive autoencodersDetecting paraphrases using recursive autoencoders
Detecting paraphrases using recursive autoencoders
Feynman Liang
 

Similar to 5 csp (20)

3 problem-solving-
3 problem-solving-3 problem-solving-
3 problem-solving-
 
SDRule-L: Managing Semantically Rich Business Decision Processes
SDRule-L: Managing Semantically Rich Business Decision ProcessesSDRule-L: Managing Semantically Rich Business Decision Processes
SDRule-L: Managing Semantically Rich Business Decision Processes
 
03 hdrf presentation
03 hdrf presentation03 hdrf presentation
03 hdrf presentation
 
Node Unique Label Cover
Node Unique Label CoverNode Unique Label Cover
Node Unique Label Cover
 
Vanna volga method
Vanna volga methodVanna volga method
Vanna volga method
 
Laser 1-background
Laser 1-backgroundLaser 1-background
Laser 1-background
 
smtlecture.3
smtlecture.3smtlecture.3
smtlecture.3
 
QVT Traceability: What does it really mean?
QVT Traceability: What does it really mean?QVT Traceability: What does it really mean?
QVT Traceability: What does it really mean?
 
Introduction to Max-SAT and Max-SAT Evaluation
Introduction to Max-SAT and Max-SAT EvaluationIntroduction to Max-SAT and Max-SAT Evaluation
Introduction to Max-SAT and Max-SAT Evaluation
 
smtlecture.10
smtlecture.10smtlecture.10
smtlecture.10
 
Cari2020 Parallel Hybridization for SAT: An Efficient Combination of Search S...
Cari2020 Parallel Hybridization for SAT: An Efficient Combination of Search S...Cari2020 Parallel Hybridization for SAT: An Efficient Combination of Search S...
Cari2020 Parallel Hybridization for SAT: An Efficient Combination of Search S...
 
6 games
6 games6 games
6 games
 
SVD and the Netflix Dataset
SVD and the Netflix DatasetSVD and the Netflix Dataset
SVD and the Netflix Dataset
 
Wireless Localization: Ranging (first part)
Wireless Localization: Ranging (first part)Wireless Localization: Ranging (first part)
Wireless Localization: Ranging (first part)
 
The Need for Async @ ScalaWorld
The Need for Async @ ScalaWorldThe Need for Async @ ScalaWorld
The Need for Async @ ScalaWorld
 
Introduction to Reinforcement Learning for Molecular Design
Introduction to Reinforcement Learning for Molecular Design Introduction to Reinforcement Learning for Molecular Design
Introduction to Reinforcement Learning for Molecular Design
 
A Polynomial-Space Exact Algorithm for TSP in Degree-5 Graphs
A Polynomial-Space Exact Algorithm for TSP in Degree-5 GraphsA Polynomial-Space Exact Algorithm for TSP in Degree-5 Graphs
A Polynomial-Space Exact Algorithm for TSP in Degree-5 Graphs
 
Cody Roux - Pure Type Systems - Boston Haskell Meetup
Cody Roux - Pure Type Systems - Boston Haskell MeetupCody Roux - Pure Type Systems - Boston Haskell Meetup
Cody Roux - Pure Type Systems - Boston Haskell Meetup
 
Detecting paraphrases using recursive autoencoders
Detecting paraphrases using recursive autoencodersDetecting paraphrases using recursive autoencoders
Detecting paraphrases using recursive autoencoders
 
Sat
SatSat
Sat
 

More from Mhd Sb

AI ch6
AI ch6AI ch6
AI ch6
Mhd Sb
 
AI ch5
AI ch5AI ch5
AI ch5
Mhd Sb
 
AI ch4
AI ch4AI ch4
AI ch4
Mhd Sb
 
AI ch3
AI ch3AI ch3
AI ch3
Mhd Sb
 
Ai ch2
Ai ch2Ai ch2
Ai ch2
Mhd Sb
 
Ai ch1
Ai ch1Ai ch1
Ai ch1
Mhd Sb
 
4 informed-search
4 informed-search4 informed-search
4 informed-search
Mhd Sb
 
2-Agents- Artificial Intelligence
2-Agents- Artificial Intelligence2-Agents- Artificial Intelligence
2-Agents- Artificial Intelligence
Mhd Sb
 
Artificial Intelligence
Artificial IntelligenceArtificial Intelligence
Artificial Intelligence
Mhd Sb
 

More from Mhd Sb (9)

AI ch6
AI ch6AI ch6
AI ch6
 
AI ch5
AI ch5AI ch5
AI ch5
 
AI ch4
AI ch4AI ch4
AI ch4
 
AI ch3
AI ch3AI ch3
AI ch3
 
Ai ch2
Ai ch2Ai ch2
Ai ch2
 
Ai ch1
Ai ch1Ai ch1
Ai ch1
 
4 informed-search
4 informed-search4 informed-search
4 informed-search
 
2-Agents- Artificial Intelligence
2-Agents- Artificial Intelligence2-Agents- Artificial Intelligence
2-Agents- Artificial Intelligence
 
Artificial Intelligence
Artificial IntelligenceArtificial Intelligence
Artificial Intelligence
 

Recently uploaded

Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
Vijay Dialani, PhD
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 

Recently uploaded (20)

Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 

5 csp

  • 1. Artificial Intelligence 1: Constraint Satis- faction problems Lecturer: Tom Lenaerts Institut de Recherches Interdisciplinaires et de Développements en Intelligence Artificielle (IRIDIA) Université Libre de Bruxelles
  • 2. TLo (IRIDIA) 2October 13, 2015 Outline  CSP?  Backtracking for CSP  Local search for CSPs  Problem structure and decomposition
  • 3. TLo (IRIDIA) 3October 13, 2015 Constraint satisfaction problems  What is a CSP?  Finite set of variables V1, V2, …, Vn  Finite set of constrainsC1, C2, …, Cm  Nonemtpy domain of possible values for each variable DV1, DV2, … DVn  Each constraint Ci limits the values that variables can take, e.g., V1 ≠ V2  A state is defined as an assignment of values to some or all variables.  Consistent assignment: assignment does not not violate the constraints.
  • 4. TLo (IRIDIA) 4October 13, 2015 Constraint satisfaction problems  An assignment is complete when every value is mentioned.  A solution to a CSP is a complete assignment that satisfies all constraints.  Some CSPs require a solution that maximizes an objective function.  Applications: Scheduling the time of observations on the Hubble Space Telescope, Floor planning, Map coloring, Cryptography
  • 5. TLo (IRIDIA) 5October 13, 2015 CSP example: map coloring  Variables: WA, NT, Q, NSW, V, SA, T  Domains: Di={red,green,blue}  Constraints:adjacent regions must have different colors.  E.g. WA ≠ NT (if the language allows this)  E.g. (WA,NT) ≠ {(red,green),(red,blue),(green,red),…}
  • 6. TLo (IRIDIA) 6October 13, 2015 CSP example: map coloring  Solutions are assignments satisfying all constraints, e.g. {WA=red,NT=green,Q=red,NSW=green,V=red,SA=blue,T=green}
  • 7. TLo (IRIDIA) 7October 13, 2015 Constraint graph  CSP benefits  Standard representation pattern  Generic goal and successor functions  Generic heuristics (no domain specific expertise).  Constraint graph = nodes are variables, edges show constraints.  Graph can be used to simplify search.  e.g. Tasmania is an independent subproblem.
  • 8. TLo (IRIDIA) 8October 13, 2015 Varieties of CSPs  Discrete variables  Finite domains; size d ⇒O(dn ) complete assignments.  E.g. Boolean CSPs, include. Boolean satisfiability (NP-complete).  Infinite domains (integers, strings, etc.)  E.g. job scheduling, variables are start/end days for each job  Need a constraint language e.g StartJob1 +5 ≤ StartJob3.  Linear constraints solvable, nonlinear undecidable.  Continuous variables  e.g. start/end times for Hubble Telescope observations.  Linear constraints solvable in poly time by LP methods.
  • 9. TLo (IRIDIA) 9October 13, 2015 Varieties of constraints  Unary constraints involve a single variable.  e.g. SA ≠ green  Binary constraints involve pairs of variables.  e.g. SA ≠ WA  Higher-order constraints involve 3 or more variables.  e.g. cryptharithmetic column constraints.  Preference (soft constraints) e.g. red is better than green often representable by a cost for each variable assignment → constrained optimization problems.
  • 10. TLo (IRIDIA) 10October 13, 2015 Example; cryptharithmetic
  • 11. TLo (IRIDIA) 11October 13, 2015 CSP as a standard search problem  A CSP can easily expressed as a standard search problem.  Incremental formulation  Initial State: the empty assignment {}.  Successor function: Assign value to unassigned variable provided that there is not conflict.  Goal test: the current assignment is complete.  Path cost: as constant cost for every step.
  • 12. TLo (IRIDIA) 12October 13, 2015 CSP as a standard search problem  This is the same for all CSP’s !!!  Solution is found at depth n (if there are n variables).  Hence depth first search can be used.  Path is irrelevant, so complete state representation can also be used.  Branching factor b at the top level is nd.  b=(n-l)d at depth l, hence n!dn leaves (only dn complete assignments).
  • 13. TLo (IRIDIA) 13October 13, 2015 Commutativity  CSPs are commutative.  The order of any given set of actions has no effect on the outcome.  Example: choose colors for Australian territories one at a time  [WA=red then NT=green] same as [NT=green then WA=red]  All CSP search algorithms consider a single variable assignment at a time ⇒ there are dn leaves.
  • 14. TLo (IRIDIA) 14October 13, 2015 Backtracking search  Cfr. Depth-first search  Chooses values for one variable at a time and backtracks when a variable has no legal values left to assign.  Uninformed algorithm  No good general performance (see table p. 143)
  • 15. TLo (IRIDIA) 15October 13, 2015 Backtracking search function BACKTRACKING-SEARCH(csp) return a solution or failure return RECURSIVE-BACKTRACKING({} , csp) function RECURSIVE-BACKTRACKING(assignment, csp) return a solution or failure if assignment is complete then return assignment var ← SELECT-UNASSIGNED-VARIABLE(VARIABLES[csp],assignment,csp) for each value in ORDER-DOMAIN-VALUES(var, assignment, csp) do if value is consistent with assignment according to CONSTRAINTS[csp] then add {var=value} to assignment result ← RRECURSIVE-BACTRACKING(assignment, csp) if result ≠ failure then return result remove {var=value} from assignment return failure
  • 16. TLo (IRIDIA) 16October 13, 2015 Backtracking example
  • 17. TLo (IRIDIA) 17October 13, 2015 Backtracking example
  • 18. TLo (IRIDIA) 18October 13, 2015 Backtracking example
  • 19. TLo (IRIDIA) 19October 13, 2015 Backtracking example
  • 20. TLo (IRIDIA) 20October 13, 2015 Improving backtracking efficiency  Previous improvements → introduce heuristics  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?  Can we take advantage of problem structure?
  • 21. TLo (IRIDIA) 21October 13, 2015 Minimum remaining values var ← SELECT-UNASSIGNED-VARIABLE(VARIABLES[csp],assignment,csp)  A.k.a. most constrained variable heuristic  Rule: choose variable with the fewest legal moves  Which variable shall we try first?
  • 22. TLo (IRIDIA) 22October 13, 2015 Degree heuristic  Use degree heuristic  Rule: select variable that is involved in the largest number of constraints on other unassigned variables.  Degree heuristic is very useful as a tie breaker.  In what order should its values be tried?
  • 23. TLo (IRIDIA) 23October 13, 2015 Least constraining value  Least constraining value heuristic  Rule: given a variable choose the least constraing value i.e. the one that leaves the maximum flexibility for subsequent variable assignments.
  • 24. TLo (IRIDIA) 24October 13, 2015 Forward checking  Can we detect inevitable failure early?  And avoid it later?  Forward checking idea: keep track of remaining legal values for unassigned variables.  Terminate search when any variable has no legal values.
  • 25. TLo (IRIDIA) 25October 13, 2015 Forward checking  Assign {WA=red}  Effects on other variables connected by constraints with WA  NT can no longer be red  SA can no longer be red
  • 26. TLo (IRIDIA) 26October 13, 2015 Forward checking  Assign {Q=green}  Effects on other variables connected by constraints with WA  NT can no longer be green  NSW can no longer be green  SA can no longer be green  MRV heuristic will automatically select NT and SA next, why?
  • 27. TLo (IRIDIA) 27October 13, 2015 Forward checking  If V is assigned blue  Effects on other variables connected by constraints with WA  SA is empty  NSW can no longer be blue  FC has detected that partial assignment is inconsistent with the constraints and backtracking can occur.
  • 28. TLo (IRIDIA) 28October 13, 2015 Example: 4-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} [4-Queens slides copied from B.J. Dorr CMSC 421 course on AI]
  • 29. TLo (IRIDIA) 29October 13, 2015 Example: 4-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}
  • 30. TLo (IRIDIA) 30October 13, 2015 Example: 4-Queens Problem 1 3 2 4 32 41 X1 {1,2,3,4} X3 { ,2, ,4} X4 { ,2,3, } X2 { , ,3,4}
  • 31. TLo (IRIDIA) 31October 13, 2015 Example: 4-Queens Problem 1 3 2 4 32 41 X1 {1,2,3,4} X3 { ,2, ,4} X4 { ,2,3, } X2 { , ,3,4}
  • 32. TLo (IRIDIA) 32October 13, 2015 Example: 4-Queens Problem 1 3 2 4 32 41 X1 {1,2,3,4} X3 { , , , } X4 { ,2,3, } X2 { , ,3,4}
  • 33. TLo (IRIDIA) 33October 13, 2015 Example: 4-Queens Problem 1 3 2 4 32 41 X1 { ,2,3,4} X3 {1,2,3,4} X4 {1,2,3,4} X2 {1,2,3,4}
  • 34. TLo (IRIDIA) 34October 13, 2015 Example: 4-Queens Problem 1 3 2 4 32 41 X1 { ,2,3,4} X3 {1, ,3, } X4 {1, ,3,4} X2 { , , ,4}
  • 35. TLo (IRIDIA) 35October 13, 2015 Example: 4-Queens Problem 1 3 2 4 32 41 X1 { ,2,3,4} X3 {1, ,3, } X4 {1, ,3,4} X2 { , , ,4}
  • 36. TLo (IRIDIA) 36October 13, 2015 Example: 4-Queens Problem 1 3 2 4 32 41 X1 { ,2,3,4} X3 {1, , , } X4 {1, ,3, } X2 { , , ,4}
  • 37. TLo (IRIDIA) 37October 13, 2015 Example: 4-Queens Problem 1 3 2 4 32 41 X1 { ,2,3,4} X3 {1, , , } X4 {1, ,3, } X2 { , , ,4}
  • 38. TLo (IRIDIA) 38October 13, 2015 Example: 4-Queens Problem 1 3 2 4 32 41 X1 { ,2,3,4} X3 {1, , , } X4 { , ,3, } X2 { , , ,4}
  • 39. TLo (IRIDIA) 39October 13, 2015 Example: 4-Queens Problem 1 3 2 4 32 41 X1 { ,2,3,4} X3 {1, , , } X4 { , ,3, } X2 { , , ,4}
  • 40. TLo (IRIDIA) 40October 13, 2015 Constraint propagation  Solving CSPs with combination of heuristics plus forward checking is more efficient than either approach alone.  FC checking propagates information from assigned to unassigned variables but does not provide detection for all failures.  NT and SA cannot be blue!  Constraint propagation repeatedly enforces constraints locally
  • 41. TLo (IRIDIA) 41October 13, 2015 Arc consistency  X → Y is consistent iff for every value x of X there is some allowed y  SA → NSW is consistent iff SA=blue and NSW=red
  • 42. TLo (IRIDIA) 42October 13, 2015 Arc consistency  X → Y is consistent iff for every value x of X there is some allowed y  NSW → SA is consistent iff NSW=red and SA=blue NSW=blue and SA=??? Arc can be made consistent by removing blue from NSW
  • 43. TLo (IRIDIA) 43October 13, 2015 Arc consistency  Arc can be made consistent by removing blue from NSW  RECHECK neighbours !!  Remove red from V
  • 44. TLo (IRIDIA) 44October 13, 2015 Arc consistency  Arc can be made consistent by removing blue from NSW  RECHECK neighbours !!  Remove red from V  Arc consistency detects failure earlier than FC  Can be run as a preprocessor or after each assignment.  Repeated until no inconsistency remains
  • 45. TLo (IRIDIA) 45October 13, 2015 Arc consistency algorithm function AC-3(csp) return the CSP, possibly with reduced domains inputs: csp, a binary csp with variables {X1, X2, …, Xn} local variables: queue, a queue of arcs initially the arcs in csp while queue is not empty do (Xi, Xj) ← REMOVE-FIRST(queue) if REMOVE-INCONSISTENT-VALUES(Xi, Xj) then for each Xk in NEIGHBORS[Xi ] do add (Xi, Xj) to queue function REMOVE-INCONSISTENT-VALUES(Xi, Xj) return true iff we remove a value removed ← false for each x in DOMAIN[Xi] do if no value y in DOMAIN[Xi] allows (x,y) to satisfy the constraints between Xi and Xj then delete x from DOMAIN[Xi]; removed ← true return removed
  • 46. TLo (IRIDIA) 46October 13, 2015 K-consistency  Arc consistency does not detect all inconsistencies:  Partial assignment {WA=red, NSW=red} is inconsistent.  Stronger forms of propagation can be defined using the notion of k-consistency.  A CSP is k-consistent if for any set of k-1 variables and for any consistent assignment to those variables, a consistent value can always be assigned to any kth variable.  E.g. 1-consistency or node-consistency  E.g. 2-consistency or arc-consistency  E.g. 3-consistency or path-consistency
  • 47. TLo (IRIDIA) 47October 13, 2015 K-consistency  A graph is strongly k-consistent if  It is k-consistent and  Is also (k-1) consistent, (k-2) consistent, … all the way down to 1-consistent.  This is ideal since a solution can be found in time O(nd) instead of O(n2 d3 )  YET no free lunch: any algorithm for establishing n- consistency must take time exponential in n, in the worst case.
  • 48. TLo (IRIDIA) 48October 13, 2015 Further improvements  Checking special constraints  Checking Alldif(…) constraint  E.g. {WA=red, NSW=red}  Checking Atmost(…) constraint  Bounds propagation for larger value domains  Intelligent backtracking  Standard form is chronological backtracking i.e. try different value for preceding variable.  More intelligent, backtrack to conflict set.  Set of variables that caused the failure or set of previously assigned variables that are connected to X by constraints.  Backjumping moves back to most recent element of the conflict set.  Forward checking can be used to determine conflict set.
  • 49. TLo (IRIDIA) 49October 13, 2015 Local search for CSP  Use complete-state representation  For CSPs  allow states with unsatisfied constraints  operators reassign variable values  Variable selection: randomly select any conflicted variable  Value selection: min-conflicts heuristic  Select new value that results in a minimum number of conflicts with the other variables
  • 50. TLo (IRIDIA) 50October 13, 2015 Local search for CSP function MIN-CONFLICTS(csp, max_steps) return solution or failure inputs: csp, a constraint satisfaction problem max_steps, the number of steps allowed before giving up current ← an initial complete assignment for csp for i = 1 to max_steps do if current is a solution for csp then return current var ← a randomly chosen, conflicted variable from VARIABLES[csp] value ← the value v for var that minimizes CONFLICTS(var,v,current,csp) set var = value in current return faiilure
  • 51. TLo (IRIDIA) 51October 13, 2015 Min-conflicts example 1  Use of min-conflicts heuristic in hill-climbing. h=5 h=3 h=1
  • 52. TLo (IRIDIA) 52October 13, 2015 Min-conflicts example 2  A two-step solution for an 8-queens problem using min-conflicts heuristic.  At each stage a queen is chosen for reassignment in its column.  The algorithm moves the queen to the min-conflict square breaking ties randomly.
  • 53. TLo (IRIDIA) 53October 13, 2015 Problem structure  How can the problem structure help to find a solution quickly?  Subproblem identification is important:  Coloring Tasmania and mainland are independent subproblems  Identifiable as connected components of constrained graph.  Improves performance
  • 54. TLo (IRIDIA) 54October 13, 2015 Problem structure  Suppose each problem has c variables out of a total of n.  Worst case solution cost is O(n/c dc ), i.e. linear in n  Instead of O(d n ), exponential in n  E.g. n= 80, c= 20, d=2  280 = 4 billion years at 1 million nodes/sec.  4 * 220 = .4 second at 1 million nodes/sec
  • 55. TLo (IRIDIA) 55October 13, 2015 Tree-structured CSPs  Theorem: if the constraint graph has no loops then CSP can be solved in O(nd 2 ) time  Compare difference with general CSP, where worst case is O(d n )
  • 56. TLo (IRIDIA) 56October 13, 2015 Tree-structured CSPs  In most cases subproblems of a CSP are connected as a tree  Any tree-structured CSP can be solved in time linear in the number of variables.  Choose a variable as root, order variables from root to leaves such that every node’s parent precedes it in the ordering.  For j from n down to 2, apply REMOVE-INCONSISTENT-VALUES(Parent(Xj),Xj)  For j from 1 to n assign Xj consistently with Parent(Xj )
  • 57. TLo (IRIDIA) 57October 13, 2015 Nearly tree-structured CSPs  Can more general constraint graphs be reduced to trees?  Two approaches:  Remove certain nodes  Collapse certain nodes
  • 58. TLo (IRIDIA) 58October 13, 2015 Nearly tree-structured CSPs  Idea: assign values to some variables so that the remaining variables form a tree.  Assume that we assign {SA=x} ← cycle cutset  And remove any values from the other variables that are inconsistent.  The selected value for SA could be the wrong one so we have to try all of them
  • 59. TLo (IRIDIA) 59October 13, 2015 Nearly tree-structured CSPs  This approach is worthwhile if cycle cutset is small.  Finding the smallest cycle cutset is NP-hard  Approximation algorithms exist  This approach is called cutset conditioning.
  • 60. TLo (IRIDIA) 60October 13, 2015 Nearly tree-structured CSPs  Tree decomposition of the constraint graph in a set of connected subproblems.  Each subproblem is solved independently  Resulting solutions are combined.  Necessary requirements:  Every variable appears in ar least one of the subproblems.  If two variables are connected in the original problem, they must appear together in at least one subproblem.  If a variable appears in two subproblems, it must appear in eacht node on the path.
  • 61. TLo (IRIDIA) 61October 13, 2015 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 lead to failure.  Constraint propagation does additional work to constrain values and detect inconsistencies.  The CSP representation allows analysis of problem structure.  Tree structured CSPs can be solved in linear time.  Iterative min-conflicts is usually effective in practice.