# artificial intelligence university politehnica of bucharest 2007-2008 adina magda florea

Post on 18-Jan-2016

215 views

Embed Size (px)

TRANSCRIPT

Artificial IntelligenceUniversity Politehnica of Bucharest2007-2008

Adina Magda Floreahttp://turing.cs.pub.ro/ai_07

Lecture No. 2Problem solving strategiesRepresenting problem solutionBasic search strategiesInformed search strategies

1. Representing problem solutionSymbolic structureComputational instrumentsPlanning method / approach

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

8-puzzle

1.2 AND/OR graph representationProblem decomposition into sub-problems(Pi, O, Pe)AND/OR graphSolved nodeUnsolvable nodeProblem solution

AND/OR graphORAND

Towers of Hanoi

1.3 Equivalence of representationsState spaceProblem decomposition

2. Basic search strategiesCriteriaCompletenessOptimalityComplexityPossibility to backtrackInformedness

Conventions: unknown node, evaluated node, expanded node, OPEN, CLOSED

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 S4.1.Generate all direct successors Sj of node S4.2.for each successor Sj of S do4.2.1.Make link Sj S4.2.2.if Sj is final statetheni.Solution is (Sj, S, .., Si)ii.return SUCCESS4.2.3.Insert Sj in OPEN, at the end5.repeat from 2end.

Features of breadth first searchPrevious algorithm for tree space not graphFor graphs - Insert step 33.if S OPEN CLOSED then repeat from 2

Depth first search in state spaceDepth of a nodeAd(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 S4.1.Generate all successors Sj of node S4.2.for each succesor Sj of S do4.2.1.Set link Sj S4.2.2.if Sj is final statetheni.Solution is (Sj,.., Si)ii.return SUCCESS4.2.3.Insert Sj in OPEN, at the beginning5.repeat from 2end.

Features of depth first search

Iterative deepeningfor AdMax=1, Val doDEPTH(AdMax)

Features of iterative deepening

Bidirectional search

Which strategy to choose ?

2.2. Uninformed search in AND/OR graphsDepth of a nodeAd(Si) = 0, where , Si is the node of the initial problemAd(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 trees1.Init lists OPEN {Si}, CLOSED {}2.Remove first node S from OPEN and insert it into CLOSED3.Expand node S3.1.Generate all direct successors Sj of node S3.2.for each successor Sj of S do3.2.1.Make link Sj S3.2.2.if Sj is a set of at least 2 sub-problemsthen/* is an AND node*/i.Generate all successors sub-problems Skj of Sj ii.Set link Skj Sjiii.Insert nodes Skj in OPEN, at the end3.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 unsolvablethen 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 solvedtheni. 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 predecessors5.repeat from 2end.

2.3. Complexity of search strategies B branching factor of the search space8-puzzleNumber of moves:2 m for corners = 83 m for laterals = 124m for center 24 movesB = no. moves / no. pozitions of free square = 2.67Number of moves :1 m for corners = 42 m for laterals = 83m for center 15 moves B = 1.67

Complexity of search strategiesB - branching factor

Root B nodes, B2 on level 2, etc.Number of states possible to be generated on a search level d is BdT total number of states generated during a search, d depth of solution nodeT = B + B2 + + Bd = O(Bd)

Number of generated nodes Breadth first searchB + B2 + + Bd + (Bd+1-B) = O(Bd+1)B branching factor, d depth of solutionDepth first searchB - branching factor, m maximum depthB*m+1Iterative deepening searchd*B+(d-1)*B2+ + (1)*Bd = O(Bd)

Complexity of search strategiesB branching factor, d solution depth,m maximum depth of the tree, l limit of search (AdMax)

CriterionLevelDepthLimited depthIterative deepeningBidirectionalTimeBdBmBlBdBd/2

SpaceBdB*mB*lBdBd/2Optimality?YesNoNoYesYesCompletenessYesNoYes if ldYesYes

3. Informed search strategiesUse heuristic knowledge to incraese efficiency of search:Select which node to expand nex during searchWhile expanding a node decide which successors to generate and which to ignoreRemove 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 searchThe quality of a node is estimated by the heuristic search function w(n) for node nhill climbing strategybest-first strategy

Algorithm BFS:Best-first in state space1.Init lists OPEN {Si}, CLOSED {}2.Compute w(Si) and associate this value to Si3.if OPEN = {}then return FAIL4. Remove node S with minimum w(S) from OPEN and insert it in CLOSED5.if S is final statetheni.Solution is (S,.., Si)ii.return SUCCESS6.Expand node S6.1. Generate all successors Sj of node S6.2. for each succesor Sj of S do6.2.1Compute w(Sj) and associate it to Sj6.2.2.Set link Sj S

6.2.3.if Sj OPEN CLOSEDthen insert Sj in OPEN with associated w(Sj) 6.2.5.elsei. Be Sj the copy of Sj from OPEN or CLOSEDii. if w(Sj) < w(Sj) then- Remove link Sj Sp, with Sp pred. of Sj- Set link Sj S, and update cost of Sj to w(Sj) - if Sj is in CLOSED- then remove Sj from CLOSED and insert Sj in OPENiii. else ignore node Sj7.repeat from 3end.

CasesBest-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

3.2 Optimal solutions: A*Algorithmw(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)

Components of A*

Computing f(S)Computation of g(S)

Computation of h(S)Must be admissibleA 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*.

A* admissibilityConsider 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 finitethen A* algorithm is admissible, i.e., is guaranteed to find the path of minimal cost to solution.Completeness

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 Si3.if OPEN = {}then return FAIL - unmodified4. Remove node S with w(S) minimum from OPEN and insert it into CLOSED - unmodified..6.2.5.elsei. Be Sj the copy of Sj from OPEN or CLOSEDii. if g(Sj) < g(Sj) 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 SSfWe say that h2 dominates h1monotony

How we compute f 8-puzzle

Traveling salesman

h2(S) = the cost of the minimum spanning tree of unvisited cities until S

Missionaries and cannibals

Missionaries and cannibals

Relaxing the admissibility condition of A* An heuristic function h is called -admissible ifwith > 0An 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.

Relaxing the admisibility condition of A* 8-puzzle

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

S1S3S8S5S2S6S7S4S12S13447447449inf393646415526417450591417

S1S3S8S5S2S6S7S4S9S10S11447447449inf393646450526417526417553447S14S15615418S16607447BestFR(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_lim2. Generate all successors Sj of S3. if there are no successors then re