artificial intelligence university politehnica of bucharest 2007-2008 adina magda florea
Embed Size (px)
TRANSCRIPT

Artificial IntelligenceArtificial Intelligence
University Politehnica of Bucharest
2007-2008
Adina Magda Florea
http://turing.cs.pub.ro/ai_07

Lecture No. 2
Problem solving strategies Representing problem solution Basic search strategies Informed search strategies

1. Representing problem solution
Symbolic structure Computational instruments Planning method / approach

1.1. State space representation
state, state space, initial state, final state(s), operators
(Si, O, Sf) Problem solution

2 3
1
7 6
8 4
5
S i
2 31
7 6
8 4
5
S f
(a) Stare initiala (b) Stare finala
SUS - Mutare patrat liber in susSTINGA - Mutare patrat liber la stingaJOS - Mutare patrat liber in josDREAPTA - Mutare patrat liber la dreapta
(c) Operatori
2 3
1
7 6
8 4
5
S i
2 3
1
7 6
8 4
5
2 3
1
7 6
8
4
5
2 3
1
7 6
8 4
5
STINGA JOS DREAPTA
(d) Tranzitii posibile din starea Si
S1 S2 S3
8-puzzle

1.2 AND/OR graph representation
Problem decomposition into sub-problems (Pi, O, Pe) AND/OR graph Solved node Unsolvable node Problem solution

Nod SAU
Noduri SI
Noduri SAU
AND/OR graph
OR
AND

A B C A B C
(a) Stare initiala (b) Stare finala
n = 3A la C
n = 2 n = 2
n = 1
A la B
A la C
B la C
n = 1A la C
n = 1A la B
n = 1C la B
n = 1B la A
n = 1B la C
n = 1A la C
(c) Arborele SI/SAU de descompunere in subprobleme
O - operator de descompunere
Towers of Hanoi

1.3 Equivalence of representations
(a) Spatiul starilor
S k
S j
Tranzitie din in S j S f
S , - stari intermediarej S k S - stare finala f
(b) Descompunerea problemei in subprobleme
Tranzitie din in S j S k Tranzitie din in S k S f
State spaceProblem decomposition

2. Basic search strategies
Criteria Completeness Optimality Complexity Possibility to backtrack Informedness
Conventions: unknown node, evaluated node, expanded node, OPEN, CLOSED

Grad deinformare
CostComputational
Cost total
Cost control(cost evaluare stari)Cost parcurgere
(cost aplicareoperatori)
Neinformat Informat
Computational costs of search

2.1. Uninformed search in state space Algorithm BREADTH: Breadth first search in state space1. Init lists OPEN {Si}, CLOSED {}2. if OPEN = {}
then return FAIL3. Remove first node S from OPEN and insert it in CLOSED4. Expand node S
4.1. Generate all direct successors Sj of node S4.2. for each successor Sj of S do
4.2.1. Make link Sj S4.2.2. if Sj is final state
theni. Solution is (Sj, S, .., Si)ii. return SUCCESS
4.2.3. Insert Sj in OPEN, at the end5. repeat from 2end.

Features of breadth first search Previous algorithm for tree space not graph For graphs - Insert step 3’
3’. if S OPEN CLOSED then repeat from 2
Depth first search in state space Depth of a node Ad(Si) = 0, where Si is the initial state, Ad(S) = Ad(Sp)+1, where Sp is the predecessor
node of S.

Algorithm DEPTH(AdMax): Depth first search in state space1. Init lists OPEN {Si}, CLOSED {}2. if OPEN = {}
then return FAIL3. Remove first node S from OPEN and insert it into CLOSED3’. if Ad(S) = AdMax then repeat from 24. Expand node S
4.1. Generate all successors Sj of node S4.2. for each succesor Sj of S do
4.2.1. Set link Sj S4.2.2. if Sj is final state
theni. Solution is (Sj,.., Si)ii. return SUCCESS
4.2.3. Insert Sj in OPEN, at the beginning5. repeat from 2end.

Features of depth first search
Iterative deepeningfor AdMax=1, Val do
DEPTH(AdMax)
Features of iterative deepening
Bidirectional search
Which strategy to choose ?

2.2. Uninformed search in AND/OR graphs
Depth of a node Ad(Si) = 0, where , Si is the node of the
initial problem Ad(S) = Ad(Sp) + 1 if Sp is node OR
predecesor of node S, Ad(S) = Ad(Sp) if Sp is node AND
predecesor of node S.

Algorithm BREADTH-ANDOR: Breadth first search in AND/OR trees
1. Init lists OPEN {Si}, CLOSED {}
2. Remove first node S from OPEN and insert it into CLOSED
3. Expand node S
3.1. Generate all direct successors Sj of node S
3.2. for each successor Sj of S do
3.2.1. Make link Sj S
3.2.2. if Sj is a set of at least 2 sub-problems
then /* is an AND node*/
i. Generate all successors sub-problems Skj of Sj
ii. Set link Skj Sj
iii. Insert nodes Skj in OPEN, at the end
3.2.3. else Insert Sj in OPEN, at the end

4. if no successor of S was generated in previous step (3)then4.1. if S is terminal node labeled with a non-elementary problem
then4.1.1. Label S unsolvable4.1.2. Label with unsolvable all nodes predecessor of S which become
unsolvable because of S4.1.3. if node AND is unsolvable
then return FAIL /* no solution */4.1.4. Remove from OPEN all nodes which have unsolvable
predecessors4.2. else /* S is terminal node labeled with a non-solvable problem */
4.2.1. Label S solved4.2.2. Label with solved all nodes predecessor of S which become
unsolvable because of S4.2.3. if node AND is solved
theni. Build solution tree following the linksii. return SUCCESS /* Solution found */
4.2.4. Remove from OPEN all solved nodes and all nodes which have solved predecessors
5. repeat from 2end.

2.3. Complexity of search strategies B – branching factor of the search space8-puzzleNumber of moves: 2 m for corners = 8 3 m for laterals = 12 4m for center 24 moves B = no. moves / no. pozitions of free square = 2.67Number of moves : 1 m for corners = 4 2 m for laterals = 8 3m for center 15 moves B = 1.67

Complexity of search strategies
B - branching factor
Root – B nodes, B2 on level 2, etc. Number of states possible to be generated on a
search level d is Bd
T – total number of states generated during a search, d – depth of solution node
T = B + B2 + … + Bd = O(Bd)

Number of generated nodes
Breadth first search
B + B2 + … + Bd + (Bd+1-B) = O(Bd+1)B – branching factor, d – depth of solution
Depth first searchB - branching factor, m – maximum depth
B*m+1 Iterative deepening search
d*B+(d-1)*B2+ … + (1)*Bd = O(Bd)

Complexity of search strategiesCriterion Level Depth Limited
depthIterative deepening
Bidirectional
Time Bd Bm Bl Bd Bd/2
Space Bd B*m B*l Bd Bd/2
Optimality?
Yes No No Yes Yes
Completeness
Yes No Yes if ld Yes Yes
B – branching factor, d – solution depth,m – maximum depth of the tree, l –limit of search (AdMax)

3. Informed search strategies
Use heuristic knowledge to incraese efficiency of search:
Select which node to expand nex during search
While expanding a node decide which successors to generate and which to ignore
Remove from the search space some nodes that have previously been generated – prune the search space

3.1 Best-first search
Evaluate the information that can be obtained by expanding a node and ist importance in guiding the search
The quality of a node is estimated by the heuristic search function w(n) for node n
hill climbing strategy best-first strategy

Algorithm BFS: Best-first in state space
1. Init lists OPEN {Si}, CLOSED {}
2. Compute w(Si) and associate this value to Si
3. if OPEN = {}
then return FAIL
4. Remove node S with minimum w(S) from OPEN and insert it in CLOSED
5. if S is final state
then
i. Solution is (S,.., Si)
ii. return SUCCESS
6. Expand node S
6.1. Generate all successors Sj of node S
6.2. for each succesor Sj of S do
6.2.1 Compute w(Sj) and associate it to Sj
6.2.2. Set link Sj S

6.2.3. if Sj OPEN CLOSED
then insert Sj in OPEN with associated w(Sj) 6.2.5. else
i. Be S’j the copy of Sj from OPEN or CLOSED
ii. if w(Sj) < w(S’j) then
- Remove link S’j Sp, with Sp pred. of S’j
- Set link S’j S, and update cost of S’j to w(Sj)
- if S’j is in CLOSED
- then remove S’j from CLOSED and insert S’j in OPEN
iii. else ignore node Sj
7. repeat from 3
end.

Cases
Best-first strategy is a generalization of uninformed search strategies- Breadth first search w(S) = Ad(S)- Depth first search w(S) = -Ad(S)
Uniform cost strategy
Minimize the search effort – heuristic searchw(S) = heuristic function
w(S ) = cost_ arc(S ,S )j k k 1k i
j 1

3.2 Optimal solutions: A*Algorithm
w(S) becomes f(S) with 2 components: g(S), estimates the real cost g*(S) of the
search path from Si to S, h(S), estimates the real cost h*(S) of the
search path from S to Sf. f(S) = g(S) + h(S) f*(S) = g*(S) + h*(S)

S i
S
S f
g(S)
h(S)
f(S)
Components of A*

Computing f(S) Computation of g(S)
Computation of h(S) Must be admissible A heuristic function is called admissible if for any
state S, h(S) h*(S). This definition gives the admissibility condition
of function h and is used to define the property of admissibility of an algorithm A*.
g(S) = cost_ arc(S ,S )k k 1k i
n

A* admissibility
Consider an algorithm A* which uses g and h compenents of f if
(1) h satisfies the admissibility condition (2) for any 2 states S, S', where c > 0 is a constant and
the cost is finite then A* algorithm is admissible, i.e., is
guaranteed to find the path of minimal cost to solution.
Completeness
cost_ arc(S,S') c

Implementation of A*Modify the algorithm correspnding to the "best-first" strategy
in state space as such:…2. Compute w(Si)=g(Si) + h(Si) and associate this value to Si
3. if OPEN = {}then return FAIL - unmodified
4. Remove node S with w(S) minimum from OPEN and insert it into CLOSED - unmodified
…..6.2.5. else
i. Be S’j the copy of Sj from OPEN or CLOSED
ii. if g(Sj) < g(S’j) then …

The heuristic of A*
Consider 2 algorithms A*, A1 and A2, with evaluation functions h1 and h2 admissibile, g1=g2
It is said that A2 is more informed than A1 if for any state S
with SSf
We say that h2 dominates h1 monotony
h (S) > h (S)2 1
f (S) g (S) h (S)1 1 1 f (S) g (S) h (S)2 2 2
h(S) h(S') + cost_ arc(S,S')

How we compute f 8-puzzle
Traveling salesman
h2(S) = the cost of the minimum spanning tree of unvisited cities until S
h (S) = t (S)1 ii=1
8
h (S) = Distanta(t2 ii=1
8)
h (S) = cost_ arc(S ,S)1 i

Missionaries and cannibals
ESTVEST
n
n
n
n
Em
Vm
Vc
Ec
(S
(S
(S
(Si
i i
i
)=3
)=3)=0
)=0
ESTVEST
n
n
n
n
Em
Vm
Vc
Ec
(S
(S
(S
(Sf
f f
f
)=0
)=0)=3
)=3
(b) Stare finala(a) Stare initiala

Missionaries and cannibals
f (S) g(S) h (S)1 1
f (S) g(S) h (S)2 2
f (S) g(S) h (S)3 3
h (S) = n (S)1E
h (S) n (S) / 22E
0(S)n daca0
0(S)n si EST de malul pe este barca daca1(S)n
0(S)n si VEST de malul pe este barca daca1(S)n
(S)hE
EE
EE
3

Relaxing the admissibility condition of A* An heuristic function h is called -admissible if
with > 0 An A* algorithm which uses an evaluation
function f with a component h -admissible will find a solution which has a cost greater than the cost of the optimal solution with at most .
such an algorithm - an -admissible algorithm and the solutions is called -optimal solution.
h(S) h (S)*

Relaxing the admisibility condition of A*
8-puzzle
f (S) g(S) h (S)3 3 h (S) h (S) 3 T(S)3 2
T(S) = Scor[t (S)]ii 1
8
mozaicului centrul laaflat pentru t 1
centru de diferita tlui a pozitie oricepentru 0
finala stareadin corect succesorul
deurmat estenu S stareain tpatratul daca 2
=(S)]Scor[t
i
i
i
i

Recursive Best First
Best first with linear space Recursive implementation Remembers the value f of the best alternate
path which starts from any precedent node of the current node
Finds the minimum cost solution if h is admissible but has a space complexity of O(B*d)

S1
S3
S8S5
S2
S6 S7
S4
S9 S10 S11
447447 449
inf
393
646 415 526
413
526
417
553
415
S1
S3
S8S5
S2
S6 S7
S4
S12 S13
447447 449
inf
393
646 415 526
417
450591
417

S1
S3
S8S5
S2
S6 S7
S4
S9 S10 S11
447447 449
inf
393
646 450 526
417
526 417 553
447
S14 S15
615418
S16
607
447
BestFR(S) Recursive Best First strategy/* returns the solution or FAIL */
BFR(Si, inf)

Algorithm BFR(S, f_lim): Recursive Best First strategy
/* Returns a solution or FAIL and a new limit f_limit */
1. if S final state then return S, f_lim
2. Generate all successors Sj of S
3. if there are no successors
then return FAIL, inf
4. for each successor Sj do
f(Sj) max(g(Sj) + h(Sj), f(S))
5. Best Sjmin, node with minimal value f(Sj) among successors
6. if f(Best) > f_lim
then return FAIL, f(Best)
7. Alternat f(Sjmin2), the 2nd smallest value f(Sj)
8. Rez, f(Best) BFR(Best, min(f_lim, Alternat)
9. if Rez FAIL then return Rez, f(Best)
10. repeat from step 5
end.