Artificial Intelligence: Adina Magda Florea
Artificial Intelligence: Adina Magda Florea
c
contrar caz in fals
D D R
]) F[U ], (F[U R restrictia exista daca adevarat
= ]) F[U , U ], F[U , (U Relatie
2 1 2 1
2 1
U U U U
2 1 U U
2 2 1 1
Algorithm: Recursive Backtracking
BKT (U, F)
for each value V of X
U
do
1. F[U] V
2. if Verify (U,F) = true
then
2.1. if U < N
then BKT(U+1, F)
2.2. else
2.2.1. Display the values in F
/* F is a solution */
2.2.2. break the for
end.
Verify (U,F)
1. test true
2. I U - 1
3. while I > 0 do
3.1. test Relatie(I, F[I], U, F[U])
3.2. I I - 1
3.3. if test = false
then break the while
4. return test
end.
1.3 Improving the BKT
Algorithms to improve the representation
Local consistency of arcs or paths in the constraint graph
Hybrid algorithm
Reduce no of tests
Look ahead techniques:
- Full look-ahead
- Partial look-ahead
- Forward checking
Look back techniques:
- backjumping
- backmarking
Using heuristics
Algorithms to improve the
representation
Constraint propagation
X
X X
R = {(a,b)} 1 2
3
12
R = {(a,c)}
13
X
X X
R = {(a,b),(b,c)} 1 2
3
12
R = {(a,c),(c,b)}
13 R = {b,c)}
23
(a) (b)
D = D = D = {a, b,c}
X X X
1 2 3
1.4 Local constraint propagation
values x and y for X
i
and X
j
is allowed by
R
ij
(x,y).
An arc (X
i
, X
j
) in a directed constraint graph is
called arc-consistent if and only if for any
value x e D
i
, domain of var X
i
, there is a value
y e D
j
, domain of X
j
, such that R
ij
(x,y).
arc-consistent direct contraint graph
algorithm: AC-3: arc-consistency for a constraint graph
1. make a queue Q { (X
i
, X
j
) | (X
i
, X
j
) e Set of arcs, i=j}
2. while Q is not empty do
2.1. Remove from Q an arc (X
k
, X
m
)
2.2. Check(X
k
, X
m
)
2.3. if Check made any changes in the domain of X
k
then
Q Q { (X
i
, X
k
) | (X
i
, X
k
)e Set of arcs, i=k,m}
end.
Check (X
k
, X
m
)
for each x e D
k
do
1. if there is no value y e D
m
such that R
km
(x,y)
then remove x from D
k
end.
Path consistency
A path of length m through nodes i
0
,,i
m
of a directed
constraint graph is called m-path-consistent if and
only if for any value x e D
i0
, domain of var i
0
and a
value y e D
jm
, domain of var i
m
, for which R
i0im
(x,y),
tehre si a sequence of values z
1
e D
i1
z
m-1
e D
im-1
such that R
i0i1
(x,z
1
), , R
im-1im
(z
m-1
,y)
Directed constraint graph m-path-consistent
Minimal constraint graph
m-path-consistency
Complexity
N no of variables
a - cardinality max of variables domains
e no of constraints
arc-consistency - AC-3: time complexity
O(e*a
3
); space complexity: O(e+N*a)
Even one of O(e*a
2
) AC-4
2-path-consistency - PC-4: time complexity
O(N
3
*a
3
)
1.5 CSP without bkt - conditions
Directed constraint graph
Width of a node
Width of an ordering
Width of a graph
A
B
C
R
AC
R
CB
A
A
A
B B
B
C
C
C
Theorems
if an arc-consistent graph has the width equal
to 1 (i.e. is a tree), then the problem has a
solution without backtracking.
if a 2-path-consistent graph has the width
equal to 2, then the problem has a solution
without backtracking.
1.6 Look-ahead techniques
Conventions
U, N, F (F[U]), T (T[U] X
U
), TNOU
Forward_check
Future_Check
Full look ahead
Partial look ahead
Forward checking