1 sccs451 artificial intelligence asst. prof. dr. sukanya pongsuparb dr. srisupa palakvangsa na...

91
1 Problem Solving: Search Techniques SCCS451 Artificial Intelligence Asst. Prof. Dr. Sukanya Pongsuparb Dr. Srisupa Palakvangsa Na Ayudhya Dr. Benjarath Pupacdi

Upload: oliver-kennedy

Post on 02-Jan-2016

213 views

Category:

Documents


0 download

TRANSCRIPT

1

Problem Solving: Search Techniques

SCCS451 Artificial Intelligence

Asst. Prof. Dr. Sukanya PongsuparbDr. Srisupa Palakvangsa Na AyudhyaDr. Benjarath Pupacdi

2

Our problem is to find a path from S to G

S

G

Occupied

Free

3

Convert to tree/graph

Space Representation Equivalent Tree

4

What we want to do is…

Once you have your graph you need to search for the best pathTo find a solution when we are not given an algorithm to solve a problem, but only a specification of what a solution looks like

IDEA: Search for a solution

5

What is “Search”?

Search Algorithm An algorithm that takes a problem as inputreturns a solution to the problem, usually after evaluating a number of possible solutions

An important aspect of search algorithm is goal-based problem solving

6

Where to search?

Search from the set of all possible solutions of a problemCalled “search space”

7

How to search?

How to searchStart at the start stateConsider the effect of taking different actions starting fromstates that have been encountered in the search so farStop when a goal state is encountered

A solution is a path in a state space from a start node to a goal node (there can be many goal nodes)The cost of a solution is the sum of the arc costs on the solution path

8

What is “goal-based” problem solving?

Goal formationBased upon the current situation and performance measuresResult is moving into a desirable state (goal state)

Problem formationDetermining actions and states to consider given the goal

ObjectiveSelect the best sequence of actions and states to attain goal

9

Example

Chess GameEach board configuration can be thought of representing a different state of the game.A change of state occurs when one of the player moves a piece.A goal state is any of the possible board configurations corresponding to a checkmate.

e2 to e4

10

Example (cont.)

Chess game has more than 10120 possible states.Winning a game amounts to finding a sequence of states through many possible states that leads to one of goal states, i.e. a check mate state.An intelligent chess playing program would not play the game by exploring all possible moves.Potential hypotheses must be considered before a good one is chosen.

11

Example (cont.)

Other examples using search techniquessearch to find matching words from a dictionary, sentence constructions, and matching contextsTo perceive an image, program searches must be performed to find model patterns that match input scenes

12

Preliminary Concept

Programs can be characterized as a space consisting of a set of states, and a set of operators that map from one state to other statesType of States

one or more of initial state – the starting pointa number of intermediate statesone or more goal states

13

Well-defined “goal-based” problem

Initial stateOperator or successor function - for any state x returns s(x), the set of states reachable from x with one actionState space - all states reachable from the initial state by any sequence of actionsPath - sequence through state spacePath cost - function that assigns a cost to a path. Cost of a path is the sum of costs of individual actions along the pathGoal test - test to determine if at goal stateGoal - a sequence of operations that map an initial state to a goal state

14

Example

15

How to tell which algorithm is better?

Completenessif at least one solution exists, the algorithm is guaranteed to find a solution within a finite amount of time

Time Complexitythe worst-case amount of time that the algorithm takes to run

Space Complexitythe worst-case amount of memory that the algorithm uses

OptimalityIf a solution is found, is it guaranteed to be an optimal one? That is, is it the one with minimum cost?

16

How to tell which algorithm is better? (cont.)

good solution - requires the fewest operations or the least cost to map from an initial state to a goal state.Time and space complexities of an algorithms may be defined in terms of their best, their average, or their worst-case performance in completing some task

17

How to implement our search space?

18

Graph and Tree Representation

19

Graph and Tree Representation

Traditionally a search space is represented as a diagram of a directed graph or a tree.

Each node or vertex in the graph corresponds to a problem state.Arcs between nodes correspond to transformations or mappings between the states.

A tree is a graph which each node has at most one parent.The immediate successors of a node are referred to as children, sibling or offspring.The predecessor nodes are ancestors.An immediate ancestor to a node is a parent.

20

“Search”… “Search”… and “Search”

Search Procedure is a strategy to select the order in which nodes are generated and a given path selectedThe aim of search is not to produce complete physical trees in memory, but rather explore as little of the virtual tree looking for root-goal paths.

Search problems could be classified into two groups according to information used to carry out a given strategy:

Uninformed SearchInformed Search

21

Uninformed Search (or Blind Search)

Orders nodes without using any domain specific information (blindly followed)This algorithm uses the initial state, the search operators, and a test to find a solution.A blind search should proceed in systematic way by exploring nodes in some pre-determined order.Implemented in general with the same implementation for various problems

22

Uninformed Search (or Blind Search) (cont.)

Drawbackdoes not take into account the specific nature of the problemmost search spaces are extremely large, and an uninformed search (especially of a tree or graph) will take a reasonable amount of time only for small examples.

ExampleBreadth-First SearchDepth-First SearchDepth-First Iterative Deepening Search

23

Informed Search

Informed search tries to reduce the amount of search that must be done by making intelligent choices for the nodes that are selected for exploration and expansion. This implies that there are methods to evaluate the likelihood that given nodes are on solution pathsa heuristic that is specific to the problem is used as a guideExample

Hill Climbing MethodBest-First SearchA* SearchBranch-and-Bound Search

24

Example of Search Problems

Eight Puzzles

Travelling Salesman Problem

25

Example: 8 Puzzles

Initial State

8 3 5

6 1

2 4 7

1 2 3

8 4

7 6 5

Goal State

26

State Space Definition of 8-Puzzle

State description: position of each of the 8 tiles in one of 9 squares (or 3x3 board)

Operators: blank position moves up, down, left, or right

Goal Test: current state matches goal configuration illustrated in the previous slide

Path cost: each move is assigned a cost of 1.

27

8 Puzzles (cont.)

An optimal or good solution is one that maps an initial arrangement of tiles to the goal configuration with the smallest number of moves.

The search space for the eight puzzle problem is depicted as the tree structure

28

8 puzzle Search Space

29

8 Puzzles (cont.)

In the tree structure, the nodes are depicted as puzzle configurationsthe root node represents a randomly chosen starting configurationits successor nodes correspond to the movements that are possibleA path is a sequence of nodes starting from the root and progressing downward to the goal node

30

Travelling Salesman Problem

Given a list of cities and their pair wise distances, the task is to find a shortest possible tour that visits each city exactly once.

an exponential amount of time is needed to solve e.g. a minimal solution with only 10 cities is 10! (3,628,800 tours).

31

Examples of Uninformed Search

Breadth-First Search

Depth-First Search

Depth-First Iterative Deepening Search

32

Breadth-First Search (BFS)

Breadth-First Search are performed by exploring all nodes at a given depth before proceeding to the next level.

Advantage: Always finding a minimum path length solution when one exists.

Disadvantage: A great many nodes may need to be explored before a solution is found.

33

Example: Map Navigation

S G

A B

D E

C

F

State Space:S = start, G = goal, other nodes = intermediate states, links = legal transitions

34

BFS Search Tree

SS G

A B

D E

C

F

Queue = {S}

Select S

Goal(S) = true?

If not, Expand(S)

35

BFS Search Tree

SS G

A B

D E

C

FA D

Queue = {A, D}

Select A

Goal(A) = true?

If not, Expand(A)

36

BFS Search Tree

SS G

A B

D E

C

FA D

B D Queue = {D, B, D}

Select D

Goal(D) = true?

If not, expand(D)

37

BFS Search Tree

SS G

A B

D E

C

FA D

A EB D Queue = {B, D, A, E}

Select Betc.

38

BFS Search Tree

SS G

A B

D E

C

FA D

A EB D

B FE S E S BC

Level 3Queue = {C, E, S, E, S, B, B, F}

39

BFS Search Tree

SS G

A B

D E

C

FA D

A EB D

B FE S E S B

GD F B FA D C E A C

C

Level 4Expand queue until G is at frontSelect GGoal(G) = true

40

BFS

41

Examples of Uninformed Search

Breadth-First Search

Depth-First Search

Depth-First Iterative Deepening Search

42

Depth First Search

Depth-first searches are performed by diving downward into a tree.It generates a child node from the most recently expand node, then generating that child’s children, and so on until a goal is found, or some cutoff depth point d is reached. If a goal is not found when a leaf node is reached or at the cutoff point, the program backtracks to the most recently expanded node and generates another of its children.This process continues until a goal is found or failure occurs

43

Depth First Search (cont.)

The depth-first is preferred over the breadth-first when the search tree is known to have a plentiful number of goals.

The depth cutoff introduces some problems. If it is set too shallow, goals may be missed. If set too deep, extra computation may be performed.

44

DFS Search Tree

SS G

A B

D E

C

FA D

Stack = {A,D}

45

DFS Search Tree

SS G

A B

D E

C

FA D

B DStack = {B,D,D}

46

DFS Search Tree

SS G

A B

D E

C

FA D

B D

EC

Stack = {C,E,D,D}

47

DFS Search Tree

SS G

A B

D E

C

FA D

B D

E

D F

C

Stack = {D,F,D,D}

48

DFS Search Tree

SS G

A B

D E

C

FA D

B D

E

D F

C

G

Stack = {G,D,D}

49

DFS

50

Depth-First Search with a depth-limit

Suppose we set the depth limit = 3, then we won’t reach the goal node.

51

Depth-First Search with a depth-limit

For the sake of argument, suppose node 16 is a goal node, then setting the depth limit = 3 will allow us to reach a goal.

52

Examples of Uninformed Search

Breadth-First Search

Depth-First Search

Depth-First Iterative Deepening Search

53

Depth First Iterative Deepening Search (IDS)

Run multiple DFS searches with increasing depth-limitsProcedure

L = 1While no solution, do

DFS from initial state S0 with cutoff L If found goal, stop and return solution, else, increment depth limit L

54

Depth First Iterative Deepening Search (cont.)

Advantage: It is guaranteed to find a shortest-path solution.

Disadvantage: It performs wasted computations before reaching a goal depth. (In many cases, this is okay as the number of nodes up top of the tree isn’t that high.)

55

Iterative deepening search L=0

56

Iterative deepening search L=1

57

Iterative deepening search L=2

58

Iterative Deepening Search L=3

59

Iterative deepening search

60

Informed Search

Use heuristic information to guide the search“heuristic” is a rule of thumb or judgmental technique that sometime leads to a solution, but provides no guarantee of successHeuristic Information - Information about the problem such as

the nature of the statesthe cost of transforming from one state to anotherthe promise of taking a certain path

61

Informed Search (cont.)

Heuristic function - expressed in the form of a heuristic evaluation function

f(n,g) where n is a node and g is the goal

Heuristics help to reduce the number of alternatives from an exponential number to a polynomial number in order to obtain a solution in a tolerable amount of time.

62

Examples of Informed Search

Hill Climbing Method

Best-First Search

A* Search

Branch-and-Bound Search

63

Informed Search: Hill Climbing Method

Hill Climbing is a mathematical optimization technique which belongs to the family of local search. (wiki)

"Like climbing Everest in thick fog with amnesia"

64

Hill Climbing Method (cont.)

Hill climbing attempts to maximize (or minimize) a function f(x), where x are discrete states. Hill climbing will follow the graph from vertex to vertex, always locally increasing (or decreasing) the value of f, until a local maximum (or local minimum) xm is reached. Hill climbing can also operate on a continuous space: in that case, the algorithm is called gradient ascent (or gradient descent if the function is minimized).

Wikipedia

65

Hill Climbing Method (cont.)

Hill climbing is like depth-first searching where the most promising child is selected for expansion.

When the children have been generated, alternative choices are evaluated using some type of heuristic function.

66

Hill Climbing Method (cont.)

The path that appears most promising is then chosen and no further reference to the parent or other children is retained.

This process continues from node-to-node with previously expanded nodes being discarded.

67

Hill Climbing Method (cont.)

68

Hill Climbing Method (cont.)

Possible Problems: local maxima, ridges, plateau

69

Hill Climbing Method (cont.)

ridge

70

Examples of Informed Search

Hill Climbing Method

Best-First Search

A* Search

Branch-and-Bound Search

71

Best First Search

Best-first search is a search algorithm which explores a graph by expanding the most promising node chosen according to a specified rule. (wikipedia)This search uses an evaluation function and always chooses the next node with the best scoreThis search can avoid potential traps encountered in Hill Climbing i.e. local maxima, ridges, and plateau It requires a good measure of goal distance.

72

Hill-Climbing vs Best First Search

Hill-Climbing is a local search. A local search does not keep a history of its path (no frontier nodes stored), and only uses the neighbors to compute the heuristics. Therefore, hill-climbing saves on memory requirement, but its output is only a goal state, not the path from the starting state to the goal state.Example: integrated-circuit design, floor layoutIn Best-first search, we stores the frontier nodes.

73

Examples of Informed Search

Hill Climbing Method

Best-First Search

A* Search

Branch-and-Bound Search

74

A* Search

A* is a best-first graph search algorithm that finds the least-cost path from a given initial node to one goal node (out of one or more possible goals).

The algorithm traverses various paths from start to goal. For each node x traversed, it maintains 3 values:

g(x): the actual shortest distance traveled from initial node to current nodeh(x): the estimated (or "heuristic") distance from current node to goalf(x): g(x) + h(x)

75

A* Search (cont.)

A* algorithm is a specialization of best-first search.

At each node, the A* algorithm generates all successor nodes and computes an estimate of distance (cost) from the start node to a goal node through each of successors.

Then, it chooses the successor with the shortest estimated distance for expansion.

76

A* Search - Example

h(x)

= estimated cost to goal

8

7

6

9

S

6

5

8 7 6

4

3

2

5

5

4

3

6

4

5

6

5

3

4

5

2

3

4 3

G

1

2

1

1

2

3

2

77

A* Search - Example (cont.)

1

2

3

2

S

1

2

1 2 3

5

6

7

4

6

7

8

5

5

6

7

4

6

7

8

7

8

9 10

G

12

11

8

10

11

12

9

g(x)

= actual cost from start to current nodes

78

A* Search - Example (cont.)

8+1

7+2

6+3

9+2

S

6+1

5+2

8+1 7+2 6+3

4+5

3+6

2+7

5+4

5+6

4+7

3+8

6+5

4+5

5+6

6+7

5+4

3+6

4+7

5+8

2+7

3+8

4+9 3+10

G

1+12

2+11

1+8

1+10

2+11

3+12

2+9

f(x) = h(x) + g(x)

79

A* Search - Example (cont.)

Graph

Open List

Closed List

S

S

G goal node

S start node

1

2

3

2

S

1

2

1 2 3

5

6

7

4

6

7

8

5

5

6

7

4

6

7

8

7

8

9 10

G

12

11

8

10

11

12

9

g(x)

8+1 node_successor_2

6+1 node_successor_3

8+1 node_successor_1

1

1

18+1

8+1

6+1

8+1

6+1

8+1

997

S

S

80

A* Search - Example (cont.)

Graph

Open List

Closed List

S

G goal node

8+1

6+1

8+1

997

S

8+1

2

3

2

S

6+1

2

8+1 2 3

5

6

7

4

6

7

8

5

5

6

7

4

6

7

8

7

8

9 10

G

12

11

8

10

11

12

9

S

7 (6+1) current node

6+1

2

S

2

7+2 node_successor_2

5+2 node_successor_3

S node_successor_1

7+2

5+2

5+2

7+2

9

81

A* Search - Example (cont.)

And so it continues until the goal node is popped off the open list…

Graph

Open List

Closed List

S

8+1

6+1

8+1

997

S

5+2

7+2

9

6+1

G goal node

8+1

7+2

3

2

S

6+1

5+2

8+1 2 3

5

6

7

4

6

7

8

5

5

6

7

4

6

7

8

7

8

9 10

G

12

11

8

10

11

12

9

82

A* Search - Example (cont.)

8+1

7+2

3(9)

9+2

S

1(7)

2(7)

1(9) 2(9) 3(9)

5(9)

6(9)

7(9)

4(9)

5+6

4+7

3+8

6+5

5(9)

5+6

6

4(9)

6(9)

4+7

5

7(9)

3+8

4 3

G

1

2

8(9)

1

2

3

2+9

Final Result !!!

83

Examples of Informed Search

Hill Climbing Method

Best-First Search

A* Search

Branch-and-Bound Search

84

Branch-And-Bound Search

Branch and Bound (BB) is a general algorithm for finding optimal solutions of various optimization problems, especially in discrete and combinatorial optimization. Description of Steps:-

divide a feasible region into sub-regions find the lower and the upper bounds of each regionIf these values are equal for the global problem, the optimal value is found.perform this process recursively

85

Branch-And-Bound Search (cont.)

Let’s define that the goal is to find the minimum of f(x)Functions involved:-

Branching – this process splits a given set S of candidates into subsets S1, S2, … of which vi is the minimum of f(x) within Si and min{v1, v2, …} is the minimum of f(x)Bounding - a procedure that computes upper and lower bounds for the minimum value of f(x) within a given subset SPruning – a procedure to remove a node A of which lower bound is greater than the upper bounds of other nodes

86

Branch-And-Bound Search (cont.)

The recursion stops when the current candidate set S is reduced to a single element OR when the upper bound for set S matches the lower bound.Either way, any element of S will be a minimum of the function within S

87

Branch-And-Bound Search - ExampleOptimization Problem: Search for the max value

(50, 1000)(5, 10)

(30, 100)

88

Branch-And-Bound Search - Example

(800, 1000)

Optimization Problem: Search for the max value

(5, 10)

(30, 100) (50, 300)

89

Branch-And-Bound Search - Example

(5, 10)

(30, 100) (50, 300)

(800, 900) (850, 990) (900, 1000)

Optimization Problem: Search for the max value

90

Search Recap

Search

Uninformed search Informed search

Breadth-first search

Depth-first iterative

deepeningsearch

Depth first search

Hill climbing search

Best-first search

A* search

Branch-and-boundsearch

91

ReferencesWikiPediahttp://www-cs-students.stanford.edu/~amitp/http://www.cs.sandia.gov/opt/survey/http://qatar.cmu.edu/cs/16200/http://www.policyalmanac.org/games/aStarTutorial.htmwww.cs.ubc.ca/~kevinlb/teaching/cs322%20-%202006-7/Lectures/lect7.pdfbio.fsu.edu/~stevet/BSC5936/Swofford.F2003.2.pdf