+ All Categories
Home > Documents > Using Search in Problem Solving

Using Search in Problem Solving

Date post: 21-Feb-2016
Category:
Upload: idalia
View: 38 times
Download: 0 times
Share this document with a friend
Description:
Using Search in Problem Solving. Part I. Basic Concepts. Initial state Goal/Target state Intermediate states Path from the initial to the target state Operators/rules to get from one state to another All states - search space - PowerPoint PPT Presentation
Popular Tags:
24
Using Search in Using Search in Problem Solving Problem Solving Part I Part I
Transcript
Page 1: Using Search in Problem Solving

Using Search inUsing Search in Problem SolvingProblem Solving

Part IPart I

Page 2: Using Search in Problem Solving

2

Basic ConceptsBasic Concepts Initial state Goal/Target state Intermediate states Path from the initial to the target state Operators/rules to get from one state

to another All states - search space

We search for a path / sequence of operators to go from the initial state to the goal state

Page 3: Using Search in Problem Solving

3

Initial state Target

state

Page 4: Using Search in Problem Solving

4

Search SpaceSearch Space Search problems can be Search problems can be

represented as represented as graphsgraphs, , where the nodes are states where the nodes are states and the arcs correspond to and the arcs correspond to operations.operations.

The set of all states: The set of all states: search search spacespace

Page 5: Using Search in Problem Solving

5

Graphs and Trees 1Graphs and Trees 1

Graph: a set of nodes (vertices) with links (edges) between them.

A link is represented usually as a pair of nodes, connected by the link.

Undirected graphs: the links do not have orientation Directed graphs: the links have

orientation

Page 6: Using Search in Problem Solving

6

Graphs and Trees 2Graphs and Trees 2Path: Sequence of nodes such that each two neighbors represent an edge

Cycle: a path with the first node equal to the last and no other nodes are repeated

Acyclic graph: a graph without cycles

Tree: undirected acyclic graph, where one node is chosen to be the root

Page 7: Using Search in Problem Solving

7

Graphs and Trees 3Graphs and Trees 3

Given a graph and a node:• Out-going edges: all edges that start in that node• In-coming edges : all edges that end up in that node• Successors (Children): the end nodes of all out-going edges• Ancestors (Parents): the nodes that are start points of in-coming edges

Page 8: Using Search in Problem Solving

8

A B

D E

C

G1: Undirected graph

Path: ABDCAE

Cycle: CABECSuccessors of A: E, C, BParents of A: E, C, B

Page 9: Using Search in Problem Solving

9

A B

D E

C

G2: Directed graph

Path: ABDC

Cycle: no cyclesSuccessors of A: C, BParent of A: E

Page 10: Using Search in Problem Solving

10

Search TreesSearch Trees More solutions: More than one path from More solutions: More than one path from

the initial state to a goal statethe initial state to a goal state Different paths may have common arcsDifferent paths may have common arcs The The search processsearch process can be represented can be represented

by a by a search treesearch tree In the search tree the different solutions In the search tree the different solutions

will be represented as different paths from will be represented as different paths from the initial statethe initial state

One and the same state may be One and the same state may be represented by different nodesrepresented by different nodes

Page 11: Using Search in Problem Solving

11

Search methodsSearch methods Basic (uninformed, Basic (uninformed, blind, exhaustiveblind, exhaustive):):

breadth-firstbreadth-first depth-firstdepth-first

Heuristic (informed): Heuristic (informed): hill climbing hill climbing best-first best-first A*A*

Page 12: Using Search in Problem Solving

12

Breadth-First SearchBreadth-First SearchAlgorithm: using a queue

1. Queue = [initial_node] , FOUND = False

2. While queue not empty and FOUND = False do:

Remove the first node NIf N = target node then FOUND = trueElse find all successor nodes of N and put

them into the queue.

In essence this is Dijkstra's algorithm of finding the shortest path between two nodes in a graph.

Page 13: Using Search in Problem Solving

13

Depth-first searchDepth-first searchAlgorithm: using a stack

1. Stack = [initial_node] , FOUND = False

2. While stack not empty and FOUND = False do:

Remove the top node NIf N = target node then FOUND = trueElse find all successor nodes of N and put

them onto the stack.

Page 14: Using Search in Problem Solving

14

Comparison of depth-first Comparison of depth-first and breadth-first searchand breadth-first search

Breadth-first: without backtrackingwithout backtrackingDepth-first : backtracking.backtracking.

Length of path: breadth-first finds the breadth-first finds the shortest path first.shortest path first.

Memory: depth-first uses less memorydepth-first uses less memory

Time: If the solution is on a short path - If the solution is on a short path - breadth first is better, if the path is long - depth breadth first is better, if the path is long - depth first is betterfirst is better.

Page 15: Using Search in Problem Solving

15

Heuristic SearchHeuristic Search

Heuristic search is used to reduce the search space.

Basic idea:Basic idea: explore only promising states/paths.

We need an evaluation function to estimate each state/path.

Page 16: Using Search in Problem Solving

16

Hill climbingHill climbingBasic ideaBasic idea::

always head towards a state which is always head towards a state which is better better than the current one.than the current one.

There is There is no exhaustive searchno exhaustive search, so no node , so no node list is maintained.list is maintained.

Page 17: Using Search in Problem Solving

17

Hill Climbing - AlgorithmHill Climbing - Algorithm Start with current-statecurrent-state = = initial-stateinitial-state. Until Until current-statecurrent-state = = goal-stategoal-state OR there is no OR there is no

change in change in current-statecurrent-state do: do:

Get the successors of the current state and Get the successors of the current state and use the evaluation function to assign a score use the evaluation function to assign a score to each successor. to each successor.

If one of the successors has a better score If one of the successors has a better score than the current-state then set the new than the current-state then set the new current-state to be the successor with the current-state to be the successor with the best score. best score.

Page 18: Using Search in Problem Solving

18

Hill ClimbingHill Climbing Node list is not maintainedNode list is not maintained No problems with loops since we No problems with loops since we

move to a better nodemove to a better node If a solution is found, it is found for a If a solution is found, it is found for a

very short time with minimal very short time with minimal memory requirementsmemory requirements

Finding a solution is not guaranteed – Finding a solution is not guaranteed – the the local maxima problemlocal maxima problem

Page 19: Using Search in Problem Solving

19

Best First SearchBest First Search The node with the The node with the best scorebest score is chosen to be is chosen to be

expanded.expanded. Works in Works in breadth-first mannerbreadth-first manner, keeps a data , keeps a data

structure (called agenda, based on priority structure (called agenda, based on priority queues) of all successors and their scores. queues) of all successors and their scores.

If a node that has been chosen does not lead to If a node that has been chosen does not lead to a solution, the a solution, the next "best" node is chosennext "best" node is chosen, so , so eventually the solution is foundeventually the solution is found

Always finds a solution, not guaranteed to Always finds a solution, not guaranteed to be the optimal one.be the optimal one.

Page 20: Using Search in Problem Solving

20

Best First Search Best First Search AlgorithmAlgorithm

1. Start with agenda = [initial-state]. 2. While agenda is not empty do

A. Pick the best node on agenda.

B. If it is the goal node then return with success. Otherwise find its

successors. C. Assign the successor nodes a

score using the evaluation function and add the scored nodes to the agenda

Page 21: Using Search in Problem Solving

21

Comparison with hill-Comparison with hill-climbingclimbing

Similarities: best-first always best-first always chooses the best nodechooses the best node

Difference: best-first search keeps an best-first search keeps an agenda as in breadth-first search, and in agenda as in breadth-first search, and in case of a dead end it will backtrack, case of a dead end it will backtrack, choosing the next-best node.choosing the next-best node.

Page 22: Using Search in Problem Solving

22

The A* AlgorithmThe A* AlgorithmAn evaluation function that accounts for - the cost of the paths - the score of the nodes

F(Node) = g(Node) + h(Node)

g(Node) - the costs from the initial state to the current node

h(Node) - future costs, i.e. node score

DisadvantageDisadvantage of A* is the memory requirement - the algorithm keeps records for the entire tree.

Page 23: Using Search in Problem Solving

23

The A* AlgorithmThe A* Algorithm

A* always finds the best solution, provided that h(Node) does not overestimate the future costs.

Page 24: Using Search in Problem Solving

24

Example

107

8

8

4

4

6

10

92

4

A

B: 9D : 10

F : 6

H : 5

C: 8E: 7

K: 5

2

G: 0

J: 4 Start: AGoal: G


Recommended