Constraint Satisfaction Problems: Basic Algorithms
Constraint Satisfaction Problems: Basic Algorithms
Basic Algorithms
When we try to give a value to the next variable SA, we find out that all
possible values violate constraints
Dead end!
BT will backtrack to try a new value for variable Τ!
Not a good idea!
The operation of FC means that the following holds for each step of
the search:
All values of each future variable are compatible with all the values that
have been assigned to past variables
function FC (unlabelled,compound_label,doms,cons)
returns a solution or NIL
if unlabelled = Ø then return compound_label
else pick a variable x from unlabelled
repeat
pick a value v from Dx; delete v from Dx
doms’ UPDATE(unlabelled-{x},doms,cons,compound_label + {(x,v)})
if no domain in doms’ is empty then
result FC(unlabelled - {x}, compound_label +
{(x,v)}, doms’,cons)
if result NIL then return result
end
until Dx = Ø
return NIL
end
ΑΝΑΠΑΡΑΣΤΑΣΗ ΓΝΩΣΗΣ - Lecture 1 10
Forward Checking
WA NT Q NSW V SA T
initial domains RGB RGB RGB RGB RGB RGB RGB
after WA=R R GB RGB RGB RGB GB RGB
after Q=G R B G RB RGB B RGB
after V=B R B G R B RGB
nodes = variables
A>5
edges = constraints
A>5
C
B B=C
Definition:
A variable X is arc consistent iff for each other variable Y the
following holds: For each value a of Χ there is at least one value b
of Υ such that a and b are compatible
a a a
b b b
c c c
X Y Z
1 2
1 2
Y
Y
1 2
1 2 Z
Z
4
5 ….No more changes!
X1 X2 X4
Arc consistency can be enforced with Ο(ed2) optimal worst case time
complexity
AC-4, AC-6, AC-7, AC-2001
AC-3: non-optimal, but simple AC algorithm
x<y
x>y
Question:
Are there cases where we can guarantee that solubility (or insolubility)
will be determined by applying arc consistency?
1 2
Y
Z
1 2
…
These are stronger than arc consistency (i.e. they delete more
inconsistent values when they are applied)
But they are more expensive (higher time complexity)
Labelling order
b b b
still conflict
labelling order
partial look ahead (PLA)
DAC
(full) look ahead (LA)
Arc Consistency
Path Consistency
Problem:
X::{1,2}, Y::{1,2}, Z::{1,2}
X = Y, X Z, Y > Z
X Y Z action result
1 labelling
{1} {} propagation fail
2 labelling
{2} {1} propagation solution
Q1 Q2 Q3 Q4
1
2
3
4
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
1 1
2 2
3 3
4 4
ΑΝΑΠΑΡΑΣΤΑΣΗ ΓΝΩΣΗΣ - Lecture 1 35
4-queen problem, FC algorithm
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
1 1
2 2
3 3
4 4
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
1 1
2 2
3 3
4 4
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
1 1 1
2 2 2
3 3 3
4 4 4
ΑΝΑΠΑΡΑΣΤΑΣΗ ΓΝΩΣΗΣ - Lecture 1 36
4-queen problem, MAC algorithm
Q1 Q2 Q3 Q4
1
x
Value 3 of Q2 is unsupported in Q3,
2
3 x Value 4 of Q3 is unsupported in Q2,
4 x Value 2 of Q3 is unsupported in Q4,
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
1 1 1
2 2 2
3 3 3
4 4 4
MAC-BJ
MAC-CBJ
…
cpu times
CPU times ?
The decisions that the algorithm takes at each step have a drastic
effect on the search space (and the efficiency of the algorithm)
Especially decision (1)
Minimum Width
The width of a variable x is the number of variables that are before x,
according to a given ordering, and are constrained with x
The width of an ordering is the maximum width of all the variables
under that ordering
The width of a constraint graph is the minimum width of all possible
orderings
Variables are ordered in descending width
Maximum Degree
Variables are ordered in decreasing order of their degree in the constraint
graph
degree is the number of adjacent variables in the graph
Heuristic to find a minimum width ordering
Maximum Cardinality
Selects the first variable arbitrarily
Then, at each stage, selects the variable that is adjacent to the largest set
of already selected variables.
Minimum Bandwidth
The bandwidth of a variable x, according to a given ordering, is the
maximum distance between x and any other variable which is adjacent to
x
The bandwidth of an ordering is the maximum bandwidth of all the
variables under that ordering
The bandwidth of a constraint graph is the minimum bandwidth of all
possible orderings
Idea: The closer the variables involved in a constraint are placed to each
other the less backtracking will be required
Problem: Computing the minimum bandwidth is NP-complete
Select the variable with the highest future degree (i.e. the one involved
in the maximum number of constraints with future variables). This is
called the Brelaz heuristic
Min-Conflicts
Associate with each value a the total number of values in future
variables that are incompatible with a
Select the value with lowest sum
Geelen’s Promise
For each value a count the total number of values in each future variable
that are compatible with a
Take the product of the counts. This is called the promise of value a
Try to repair it
change the value assignment that resolves the greatest numbers of
constraints
local optima can be escaped using random restarts
Otherwise:
Simulated annealing
Tabu search
Random walk