searching for solutions

60
SEARCHING FOR SOLUTIONS Traversal of the search space from the initial state to a goal state legal sequence of actions as defined by successor function (operators) General procedure check for goal state expand the current state the fringe (frontier) is the set of nodes not yet visited newly generated nodes are added to the fringe select one from the set of reachable states search strategy determines the selection of the next node to be expanded can be achieved by ordering the nodes in the fringe move to the selected state A search tree is generated nodes are added as more states are visited 1

Upload: idania

Post on 10-Feb-2016

33 views

Category:

Documents


0 download

DESCRIPTION

Searching for Solutions. Traversal of the search space from the initial state to a goal state legal sequence of actions as defined by successor function (operators) General procedure check for goal state expand the current state the fringe (frontier) is the set of nodes not yet visited - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Searching for Solutions

SEARCHING FOR SOLUTIONS Traversal of the search space

from the initial state to a goal state legal sequence of actions as defined by successor function

(operators) General procedure

check for goal state expand the current state

the fringe (frontier) is the set of nodes not yet visited newly generated nodes are added to the fringe

select one from the set of reachable states search strategy

determines the selection of the next node to be expanded can be achieved by ordering the nodes in the fringe

move to the selected state A search tree is generated

nodes are added as more states are visited 1

Page 2: Searching for Solutions

EXAMPLE: ROMANIA

2

Page 3: Searching for Solutions

TREE SEARCH EXAMPLE

3

Page 4: Searching for Solutions

GRAPH AND TREE

S3

A4

C2

D3

E1

B2

G0

1 1 1 3

1 3 3 4

5

1

2

2

S3

5

A4

D3

1

1

33

4

2

C2

D3

G0

G0

G0

E1

G0

1

1

3

3

4

2

C2

D3

G0

G0

E1

G0

1

3

B2

1

3

C2

D3

G0

G0

E1

G0

1

3

4 E1

G0

2 4

3 2

4

the tree is generated by traversing the graph

the same node in the graph may appear repeatedly in the tree

the arrangement of the tree depends on the traversal strategy (search method)

the initial state becomes the root node of the tree

in the fully expanded tree, the goal states are the leaf nodes

cycles in graphs may result in infinite branches

4

Page 5: Searching for Solutions

GENERAL TREE SEARCH ALGORITHM

function TREE-SEARCH(problem, fringe) returns solutionfringe := INSERT(MAKE-NODE(INITIAL-STATE[problem]), fringe) loop do

if EMPTY?(fringe) then return failure node := REMOVE-FIRST(fringe) if GOAL-TEST[problem] applied to STATE[node] succeeds then return SOLUTION(node) fringe := INSERT-ALL(EXPAND(node, problem), fringe)

Generate the node from the initial state of the problem Repeat

return failure if there are no more nodes in the fringe examine the current node; if it’s a goal, return the solution expand the current node, and add the new nodes to the fringe

5

Page 6: Searching for Solutions

SEARCH STRATEGIES - EVALUATION CRITERIA Completeness

does it always find a solution if one exists? Time complexity

how long does it take to find the solution number of nodes generated

Space complexity memory required for the search maximum number of nodes in memory

Optimality will the best solution be found does it always find a least-cost solution?

main factors for complexity considerations:branching factor b, depth d of the least-cost goal node, maximum path length m 6

Page 7: Searching for Solutions

SEARCH STRATEGIES

Uninformed Search number of steps, path

cost unknown agent knows when it

reaches a goal

breadth-first depth-first uniform-cost search depth-limited search iterative deepening bi-directional search constraint satisfaction

Informed Search agent has background

information about the problem map, costs of actions

best-first search search with heuristics memory-bounded search iterative improvement

search

7

Page 8: Searching for Solutions

BREADTH-FIRST Expand shallowest unexpanded node

achieved by the TREE-SEARCH method by appending newly generated nodes at the end of the search queue

fringe is a FIFO queue, i.e., new successors go at end

function BREADTH-FIRST-SEARCH(problem) returns solution

return TREE-SEARCH(problem, FIFO-QUEUE())

8

Page 9: Searching for Solutions

BREADTH-FIRST SNAPSHOT 1

1

2 3

Fringe: [] + [2,3] 9

InitialVisitedFringeCurrentVisibleGoal

Page 10: Searching for Solutions

BREADTH-FIRST SNAPSHOT 2

1

2 3

4 5

Fringe: [3] + [4,5] 10

InitialVisitedFringeCurrentVisibleGoal

Page 11: Searching for Solutions

BREADTH-FIRST SNAPSHOT 3

1

2 3

4 5 6 7

Fringe: [4,5] + [6,7] 11

InitialVisitedFringeCurrentVisibleGoal

Page 12: Searching for Solutions

BREADTH-FIRST SNAPSHOT 4

1

2 3

4 5 6 7

8 9

Fringe: [5,6,7] + [8,9] 12

InitialVisitedFringeCurrentVisibleGoal

Page 13: Searching for Solutions

BREADTH-FIRST SNAPSHOT 5

1

2 3

4 5 6 7

8 9 10 11

Fringe: [6,7,8,9] + [10,11] 13

InitialVisitedFringeCurrentVisibleGoal

Page 14: Searching for Solutions

BREADTH-FIRST SNAPSHOT 6

1

2 3

4 5 6 7

8 9 10 11 12 13

Fringe: [7,8,9,10,11] + [12,13] 14

InitialVisitedFringeCurrentVisibleGoal

Page 15: Searching for Solutions

BREADTH-FIRST SNAPSHOT 7

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

Fringe: [8,9.10,11,12,13] + [14,15] 15

InitialVisitedFringeCurrentVisibleGoal

Page 16: Searching for Solutions

BREADTH-FIRST SNAPSHOT 8

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17

Fringe: [9,10,11,12,13,14,15] + [16,17] 16

InitialVisitedFringeCurrentVisibleGoal

Page 17: Searching for Solutions

BREADTH-FIRST SNAPSHOT 9

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19

Fringe: [10,11,12,13,14,15,16,17] + [18,19] 17

InitialVisitedFringeCurrentVisibleGoal

Page 18: Searching for Solutions

BREADTH-FIRST SNAPSHOT 10

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21

Fringe: [11,12,13,14,15,16,17,18,19] + [20,21] 18

InitialVisitedFringeCurrentVisibleGoal

Page 19: Searching for Solutions

BREADTH-FIRST SNAPSHOT 11

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23

Fringe: [12, 13, 14, 15, 16, 17, 18, 19, 20, 21] + [22,23] 19

InitialVisitedFringeCurrentVisibleGoal

Page 20: Searching for Solutions

BREADTH-FIRST SNAPSHOT 12

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25

Fringe: [13,14,15,16,17,18,19,20,21] + [22,23]

Note: The goal node is “visible” here, but we can not perform the goal test yet.

20

InitialVisitedFringeCurrentVisibleGoal

Page 21: Searching for Solutions

BREADTH-FIRST SNAPSHOT 13

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25 26 27

Fringe: [14,15,16,17,18,19,20,21,22,23,24,25] + [26,27] 21

InitialVisitedFringeCurrentVisibleGoal

Page 22: Searching for Solutions

BREADTH-FIRST SNAPSHOT 14

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25 26 27 28 29

Fringe: [15,16,17,18,19,20,21,22,23,24,25,26,27] + [28,29] 22

InitialVisitedFringeCurrentVisibleGoal

Page 23: Searching for Solutions

BREADTH-FIRST SNAPSHOT 15

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Fringe: [15,16,17,18,19,20,21,22,23,24,25,26,27,28,29] + [30,31]23

InitialVisitedFringeCurrentVisibleGoal

Page 24: Searching for Solutions

BREADTH-FIRST SNAPSHOT 16

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Fringe: [17,18,19,20,21,22,23,24,25,26,27,28,29,30,31] 24

InitialVisitedFringeCurrentVisibleGoal

Page 25: Searching for Solutions

BREADTH-FIRST SNAPSHOT 17

InitialVisitedFringeCurrentVisibleGoal

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Fringe: [18,19,20,21,22,23,24,25,26,27,28,29,30,31] 25

Page 26: Searching for Solutions

BREADTH-FIRST SNAPSHOT 18

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Fringe: [19,20,21,22,23,24,25,26,27,28,29,30,31] 26

InitialVisitedFringeCurrentVisibleGoal

Page 27: Searching for Solutions

BREADTH-FIRST SNAPSHOT 19

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Fringe: [20,21,22,23,24,25,26,27,28,29,30,31] 27

InitialVisitedFringeCurrentVisibleGoal

Page 28: Searching for Solutions

BREADTH-FIRST SNAPSHOT 20

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Fringe: [21,22,23,24,25,26,27,28,29,30,31] 28

InitialVisitedFringeCurrentVisibleGoal

Page 29: Searching for Solutions

BREADTH-FIRST SNAPSHOT 21

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Fringe: [22,23,24,25,26,27,28,29,30,31] 29

InitialVisitedFringeCurrentVisibleGoal

Page 30: Searching for Solutions

BREADTH-FIRST SNAPSHOT 22

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Fringe: [23,24,25,26,27,28,29,30,31] 30

InitialVisitedFringeCurrentVisibleGoal

Page 31: Searching for Solutions

BREADTH-FIRST SNAPSHOT 23

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Fringe: [24,25,26,27,28,29,30,31] 31

InitialVisitedFringeCurrentVisibleGoal

Page 32: Searching for Solutions

BREADTH-FIRST SNAPSHOT 24

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Fringe: [25,26,27,28,29,30,31]

Note: The goal test is positive for this node, and a solution is found in 24 steps.

32

InitialVisitedFringeCurrentVisibleGoal

Page 33: Searching for Solutions

PROPERTIES OF BREADTH-FIRST SEARCH Complete? Yes (if b is finite)

Time? 1+b+b2+b3+… +bd + b(bd-1) = O(bd+1)

Space? O(bd+1) (keeps every node in memory)

Optimal? Yes (if cost = 1 per step)

Space is the bigger problem (more than time)b branching factor

d depth of the tree

Page 34: Searching for Solutions

UNIFORM-COST -FIRST The nodes with the lowest cost are explored

first similar to BREADTH-FIRST, but with an evaluation of

the cost for each reachable node g(n) = path cost(n) = sum of individual edge costs

to reach the current node from the root fringe = queue ordered by path cost Equivalent to breadth-first if step costs all equal

function UNIFORM-COST-SEARCH(problem) returns solution

return TREE-SEARCH(problem, COST-FN, FIFO-QUEUE())Time Complexity bC*/e

Space Complexity bC*/e

Completeness yes (finite b)

Optimality yes

b branching factor

C* cost of the optimal solution

e minimum cost per action

34

Page 35: Searching for Solutions

UNIFORM-COST SNAPSHOT

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

4 3

7

2

2 2 4

5 4 4 4 3 6 9

3 4 7 2 4 8 6 4 3 4 2 3 9 25 8

Fringe: [27(10), 4(11), 25(12), 26(12), 14(13), 24(13), 20(14), 15(16), 21(18)] + [22(16), 23(15)]

Edge Cost 9

35

InitialVisitedFringeCurrentVisibleGoal

Page 36: Searching for Solutions

UNIFORM COST FRINGE TRACE1. [1(0)]2. [3(3), 2(4)]3. [2(4), 6(5), 7(7)]4. [6(5), 5(6), 7(7), 4(11)]5. [5(6), 7(7), 13(8), 12(9), 4(11)]6. [7(7), 13(8), 12(9), 10(10), 11(10), 4(11)]7. [13(8), 12(9), 10(10), 11(10), 4(11), 14(13), 15(16)]8. [12(9), 10(10), 11(10), 27(10), 4(11), 26(12), 14(13), 15(16)]9. [10(10), 11(10), 27(10), 4(11), 26(12), 25(12), 14(13), 24(13), 15(16)]10. [11(10), 27(10), 4(11), 25(12), 26(12), 14(13), 24(13), 20(14), 15(16), 21(18)]11. [27(10), 4(11), 25(12), 26(12), 14(13), 24(13), 20(14), 23(15), 15(16), 22(16),

21(18)]12. [4(11), 25(12), 26(12), 14(13), 24(13), 20(14), 23(15), 15(16), 23(16), 21(18)]13. [25(12), 26(12), 14(13), 24(13),8(13), 20(14), 23(15), 15(16), 23(16), 9(16), 21(18)]14. [26(12), 14(13), 24(13),8(13), 20(14), 23(15), 15(16), 23(16), 9(16), 21(18)]15. [14(13), 24(13),8(13), 20(14), 23(15), 15(16), 23(16), 9(16), 21(18)]16. [24(13),8(13), 20(14), 23(15), 15(16), 23(16), 9(16), 29(16),21(18), 28(21)]

Goal reached!

Notation: [Bold+Orange: Current Node; Black: Old Fringe Node; Green: New Fringe Node].

Assumption: New nodes with the same cost as existing nodes are added after the existing node. 36

Page 37: Searching for Solutions

BREADTH-FIRST VS. UNIFORM-COST Breadth-first always expands the shallowest

node only optimal if all step costs are equal

Uniform-cost considers the overall path cost optimal for any (reasonable) cost function

Positive

Both are complete for non-extreme problems finite number of branches

37

Page 38: Searching for Solutions

DEPTH-FIRST continues exploring newly generated nodes

achieved by the TREE-SEARCH method by appending newly generated nodes at the beginning of the search queue utilizes a Last-In, First-Out (LIFO) queue, or stack

function DEPTH-FIRST-SEARCH(problem) returns solution

return TREE-SEARCH(problem, LIFO-QUEUE())

b branching factor

m maximum path lengthTime Complexity bm

Space Complexity b*m

Completeness no (for infinite branch length)

Optimality no

38

Page 39: Searching for Solutions

DEPTH-FIRST SEARCH

39

Page 40: Searching for Solutions

DEPTH-FIRST SEARCH

40

Page 41: Searching for Solutions

DEPTH-FIRST SEARCH

41

Page 42: Searching for Solutions

DEPTH-FIRST SEARCH

42

Page 43: Searching for Solutions

DEPTH-FIRST SEARCH

43

Page 44: Searching for Solutions

DEPTH-FIRST SEARCH

44

Page 45: Searching for Solutions

DEPTH-FIRST SEARCH

45

Page 46: Searching for Solutions

DEPTH-FIRST SEARCH

46

Page 47: Searching for Solutions

DEPTH-FIRST SEARCH

47

Page 48: Searching for Solutions

DEPTH-FIRST SEARCH

48

Page 49: Searching for Solutions

DEPTH-FIRST SEARCH

49

Page 50: Searching for Solutions

DEPTH-FIRST SEARCH

50

Page 51: Searching for Solutions

DEPTH-FIRST VS. BREADTH-FIRST Depth-first goes off into one branch until it

reaches a leaf node not good if the goal is on another branch neither complete nor optimal uses much less space than breadth-first

much fewer visited nodes to keep track of smaller fringe

Breadth-first is more careful by checking all alternatives complete and optimal

under most circumstances very memory-intensive

51

Page 52: Searching for Solutions

BACKTRACKING SEARCH Variation of depth-first search

only one successor node is generated at a time even better space complexity: O(m) instead of O(b*m)

even more memory space can be saved by incrementally modifying the current state, instead of creating a new one only possible if the modifications can be undone this is referred to as backtracking

frequently used in planning, theorem proving

52

Page 53: Searching for Solutions

DEPTH-LIMITED SEARCH Similar to depth-first, but with a limit L

overcomes problems with infinite paths sometimes a depth limit can be inferred or estimated from

the problem description in other cases, a good depth limit is only known when the problem

is solved based on the TREE-SEARCH method nodes at depth L have no successors

function DEPTH-LIMITED-SEARCH(problem, depth-limit) returns solution

return TREE-SEARCH(problem, depth-limit, LIFO-QUEUE())

b branching factor

l depth limitTime Complexity bl

Space Complexity b*l

Completeness no (goal beyond l)

Optimality no53

Page 54: Searching for Solutions

ITERATIVE DEEPENING applies LIMITED-DEPTH with increasing depth limits

combines advantages of BREADTH-FIRST and DEPTH-FIRST methods

many states are expanded multiple times doesn’t really matter because the number of those nodes is small

in practice, one of the best uninformed search methods for large search spaces, unknown depth

function ITERATIVE-DEEPENING-SEARCH(problem) returns solution for depth := 0 to unlimited do result := DEPTH-LIMITED-SEARCH(problem, depth-limit)

if result != cutoff then return result b branching factor

d tree depthTime Complexity bd

Space Complexity b*d

Completeness yes

Optimality yes (all step costs identical) 54

Page 55: Searching for Solutions

ITERATIVE DEEPENING SEARCH L = 0

55

Page 56: Searching for Solutions

ITERATIVE DEEPENING SEARCH L = 1

56

Page 57: Searching for Solutions

ITERATIVE DEEPENING SEARCH L = 2

57

Page 58: Searching for Solutions

ITERATIVE DEEPENING SEARCH L =3

58

Page 59: Searching for Solutions

SUMMARY OF ALGORITHMS

59

Page 60: Searching for Solutions

IMPROVING SEARCH METHODS Make algorithms more efficient

avoiding repeated states utilizing memory efficiently

Use additional knowledge about the problem properties (“shape”) of the search space

more interesting areas are investigated first pruning of irrelevant areas

areas that are guaranteed not to contain a solution can be discarded

60