Similar presentations

2 Initial State OperatorProblem Definition - 1Initial StateThe initial state of the problem, defined in some suitable mannerOperatorA set of actions that moves the problem from one state to another

3 Neighbourhood (Successor Function)Problem Definition - 1Neighbourhood (Successor Function)The set of all possible states reachable from a given stateState SpaceThe set of all states reachable from the initial state

4 Problem Definition - 2Goal TestA test applied to a state which returns if we have reached a state that solves the problemPath CostHow much it costs to take a particular path

9 Does our search method actually find a solution?How Good is a Solution?Does our search method actually find a solution?Is it a good solution?Path CostSearch Cost (Time and Memory)Does it find the optimal solution?But what is optimal?

10 Completeness Time ComplexityEvaluating a SearchCompletenessIs the strategy guaranteed to find a solution?Time ComplexityHow long does it take to find a solution?

11 Space Complexity OptimalityEvaluating a SearchSpace ComplexityHow much memory does it take to perform the search?OptimalityDoes the strategy find the optimal solution where there are several solutions?

13 ISSUES Search trees grow very quicklyThe size of the search tree is governed by the branching factorEven this simple game has a complete search tree of 984,410 potential nodesThe search tree for chess has a branching factor of about 35

14 Implementing a Search - What we need to storeStateThis represents the state in the state space to which this node correspondsParent-NodeThis points to the node that generated this node. In a data structure representing a tree it is usual to call this the parent node

15 Implementing a Search - What we need to storeOperatorThe operator that was applied to generate this nodeDepthThe number of nodes from the root (i.e. the depth)Path-CostThe path cost from the initial state to this node

17 Using a Tree – The Obvious Solution?AdvantagesIt’s intuitiveParent’s are automatically catered for

18 Using a Tree – The Obvious Solution?ButIt can be wasteful on spaceIt can be difficult the implement, particularly if there are varying number of children (as in tic-tac-toe)It is not always obvious which node to expand next. We may have to search the tree looking for the best leaf node (sometimes called the fringe or frontier nodes). This can obviously be computationally expensive

19 Using a Tree – Maybe not so obviousThereforeIt would be nice to have a “simpler” data structure to represent our treeAnd it would be nice if the next node to be expanded was an O(1) operation

28 Blind Searches - CharacteristicsSimply searches the State SpaceCan only distinguish between a goal state and a non-goal stateSometimes called an uninformed search as it has no knowledge about its domain

29 Blind Searches - CharacteristicsBlind Searches have no preference as to which state (node) that is expanded nextThe different types of blind searches are characterised by the order in which they expand the nodes.This can have a dramatic effect on how well the search performs when measured against the four criteria we defined in an earlier lecture

31 Breadth First Search - ImplementationUse a queueing function that adds nodes to the end of the queueFunction BREADTH-FIRST-SEARCH(problem) returns a solution or failureReturn GENERAL-SEARCH(problem,ENQUEUE-AT-END)

33 Evaluating Breadth First SearchObservationsVery systematicIf there is a solution breadth first search is guaranteed to find itIf there are several solutions then breadth first search will always find the shallowest goal state first and if the cost of a solution is a non-decreasing function of the depth then it will always find the cheapest solution

34 Evaluating Breadth First SearchEvaluating against four criteriaComplete? : YesOptimal? : YesSpace Complexity : 1 + b + b2 + b bd i.e O(bd)Time Complexity : 1 + b + b2 + b bd i.e. O(bd)Where b is the branching factor and d is the depth of the search treeNote : The space/time complexity could be less as the solution could be found anywhere on the dth level.

37 Exponential Growth - ObservationsSpace is more of a factor to breadth first search than timeTime is still an issue. Who has 35 years to wait for an answer to a level 12 problem (or even 128 days to a level 10 problem)It could be argued that as technology gets faster then exponential growth will not be a problem. But even if technology is 100 times faster we would still have to wait 35 years for a level 14 problem and what if we hit a level 15 problem!

38 Uniform Cost Search (vs BFS)BFS will find the optimal (shallowest) solution so long as the cost is a function of the depthUniform Cost Search can be used when this is not the case and uniform cost search will find the cheapest solution provided that the cost of the path never decreases as we proceed along the pathUniform Cost Search works by expanding the lowest cost node on the fringe.

39 Uniform Cost Search - ExampleBGCA110515BFS will find the path SAG, with a cost of 11, but SBG is cheaper with a cost of 10Uniform Cost Search will find the cheaper solution (SBG). It will find SAG but will not see it as it is not at the head of the queue

40 Depth First Search - MethodExpand Root Node FirstExplore one branch of the tree before exploring another branch

41 Depth First Search - ImplementationUse a queueing function that adds nodes to the front of the queueFunction DEPTH-FIRST-SEARCH(problem) returns a solution or failureReturn GENERAL-SEARCH(problem,ENQUEUE-AT-FRONT)

42 Depth First Search - ObservationsOnly needs to store the path from the root to the leaf node as well as the unexpanded nodes. For a state space with a branching factor of b and a maximum depth of m, DFS requires storage of bm nodesTime complexity for DFS is bm in the worst case

43 Depth First Search - ObservationsIf DFS goes down a infinite branch it will not terminate if it does not find a goal state.If it does find a solution there may be a better solution at a lower level in the tree. Therefore, depth first search is neither complete nor optimal.

44 Depth Limited Search (vs DFS)DFS may never terminate as it could follow a path that has no solution on itDLS solves this by imposing a depth limit, at which point the search terminates that particular branch

45 Depth Limited Search - ObservationsCan be implemented by the general search algorithm using operators which keep track of the depthChoice of depth parameter is importantToo deep is wasteful of time and spaceToo shallow and we may never reach a goal state

46 Depth Limited Search - ObservationsIf the depth parameter, l, is set deep enough then we are guaranteed to find a solution if one existsTherefore it is complete if l>=d (d=depth of solution)Space requirements are O(bl)Time requirements are O(bl)DLS is not optimal

47 Map of RomaniaBucharestZerindAradTimisoaraLugojMehadiaDobretaCraiovaRimnicu VilceaSibiuPitestiGiurguiUrziceniHirsovaEforieVasluiIasiNeamtOdareaFararasOn the Romania map there are 20 towns so any town is reachable in 19 stepsIn fact, any town is reachable in 9 steps

48 Iterative Deepening Search (vs DLS)The problem with DLS is choosing a depth parameterSetting a depth parameter to 19 is obviously wasteful if using DLSIDS overcomes this problem by trying depth limits of 0, 1, 2, …, n. In effect it is combining BFS and DFS

49 Iterative Deepening Search - ObservationsIDS may seem wasteful as it is expanding the same nodes many times. In fact, when b=10 only about 11% more nodes are expanded than for a BFS or a DLS down to level dTime Complexity = O(bd)Space Complexity = O(bd)For large search spaces, where the depth of the solution is not known, IDS is normally the preferred search method

50 Repeated States - Three MethodsDo not generate a node that is the same as the parent node Or Do not return to the state you have just come fromDo not create paths with cycles in them. To do this we can check each ancestor node and refuse to create a state that is the same as this set of nodes

51 Repeated States - Three MethodsDo not generate any state that is the same as any state generated before. This requires that every state is kept in memory (meaning a potential space complexity of O(bd))The three methods are shown in increasing order of computational overhead in order to implement them