Chapter Two Problem Solving Using Search Defining the Problem How - - PowerPoint PPT Presentation

chapter two
SMART_READER_LITE
LIVE PREVIEW

Chapter Two Problem Solving Using Search Defining the Problem How - - PowerPoint PPT Presentation

Chapter Two Problem Solving Using Search Defining the Problem How do you represent a problem so that the computer can solve it? Even before that, how do you define the problem with enough precision so that you can figure out how to


slide-1
SLIDE 1

Chapter Two

Problem Solving Using Search

slide-2
SLIDE 2

Defining the Problem

  • How do you represent a problem so that

the computer can solve it?

  • Even before that, how do you define the

problem with enough precision so that you can figure out how to represent it?

slide-3
SLIDE 3

State Space

  • First have to develop a mapping from game space world of pieces

and the geometric pattern on board, to a data structure that captures the essence of the current game state.

  • Start with an initial State. A combination of the initial state and the

set of operators make up a state space. The sequence of states produced Is called the path. We have to detect the goal state.

  • Often we want to reach the goal with lowest possible cost. The cost

function is usually denoted by g.

  • Effective search algorithms must cause motion in a controlled

systematic manner. A systematic search that doesn’t use info about the problem is called brute-force or blind search, others are called heuristic or informed search. Here we can make better choices where to expand next.

  • An algorithm is optimal if it finds the best solution, complete if it

guarantees a solution if one exists, efficient in terms of time and space complexity.

slide-4
SLIDE 4

Search Strategies

  • Breadth-First Search
  • Depth-First Search
  • The SearchNode
slide-5
SLIDE 5

Breadth-First Search

  • Searches a state space by constructing a hierarchical

tree.

  • The algorithm defines a way to move through the

structure, examining the values at nodes in a controlled and systematic way to find a node that

  • ffers a solution to the problem.
  • Algorithm:

– create a queue and add the first SearchNode to it. – Loop

– if the queue is empty, quit. – remove the first SearchNode from the queue – if the SearchNode contains the goal state, then exit with the SearchNode as the solution – for each child of the current SearchNode, add the new SearchNode to the back of the queue.

slide-6
SLIDE 6

Depth-First Search

  • Instead of completely searching each level of the

tree before going deeper, follow a single branch

  • f the tree down as many levels as possible until

it either reaches a solution of a dead end.

  • Algorithm:

– create a queue and add the first SearchNode to it. – Loop:

– If the queue is empty, quit – Remove the first SearchNode from the queue – If the SearchNode contains the goal state, then exit with the SearchNode as the solution – For each child of the current SearchNode: add the new SearchNode to the front of the queue.

slide-7
SLIDE 7

Search Application

Grand Forks

International Falls Bemidji Duluth Minneapolis St.Cloud Fargo Sioux Falls Rochester Dubuque Rockford Chicago Wausau Green Bay Milwaukee LaCrosse Madison

slide-8
SLIDE 8

Breadth First Search

  • Chicago to Rochester

– Milwaukee

  • Madison

– LaCrosse

  • Green Bay

– LaCrosse – Wausau

– Rockford

  • Dubuque

– LaCrosse – Rochester (Goal State)

  • Madison
  • Path: Chicago, Rockford, Dubuque, Rochester
slide-9
SLIDE 9

Depth First Search

  • Chicago to Rochester

– Milwaukee

  • Green Bay

– LaCrosse » Minneapolis »

  • St. Claude

»

  • Fargo

»

  • Grand Forks

»

  • International Falls

»

  • Sioux Falls

»

  • Bemidji

»

  • Duluth

» Rochester (Goal State)

  • Path: Chicago, Milwaukee, Green Bay, LaCrosse,

Rochester

slide-10
SLIDE 10

Iterative Deepening Search-1

  • Depth 0: Chicago
  • Depth 1: Chicago

» Rockford » Milwaukee

  • Depth 2: Chicago

» Rockford

  • Dubuque
  • Madison

» Milwaukee

  • Madison
  • Green Bay
slide-11
SLIDE 11

Iterative Deepening Search-2

  • Depth 3: Chicago

– Milwaukee

  • Madison

– LaCrosse

  • Green Bay

– LaCrosse – Wausau

– Rockford

  • Dubuque

– LaCrosse – Rochester (Goal State)

  • Path: Chicago, Rockford, Dubuque, Rochester
slide-12
SLIDE 12

Heuristic Search

  • Generate and Test
  • Best First Search
  • Greedy Search
  • A* Search
slide-13
SLIDE 13

Generate and Test

  • 1. Generate a possible solution
  • 2. Test to see if this is actually a solution
  • 3. If a solution has been found ,quit.

Otherwise, return to step 1

slide-14
SLIDE 14

Best First Search

  • Is just a General Search
  • minimum-cost nodes are expanded first
  • we basically choose the node that appears to be

best according to the evaluation function Two basic approaches:

  • Expand the node closest to the goal
  • Expand the node on the least-cost solution path
slide-15
SLIDE 15

Greedy Search

  • “ … minimize estimated cost to reach a goal”
  • a heuristic function calculates such cost estimates

h(n) = estimated cost of the cheapest path from the state at node n to a goal state

slide-16
SLIDE 16

Straight-line distance

  • The straight-line distance heuristic function is a for

finding route-finding problem

hSLD(n) = straight-line distance between n and the goal location

slide-17
SLIDE 17

75 118 111 140 80 97 99 101 211 A B C D E F G H I

A E B C h=253 h=329 h=374

State h(n) A 366 B 374 C 329 D 244 E 253 F 178 G 193 H 9 8 I

slide-18
SLIDE 18

A E C B A F G

h=253 h = 366 h = 178 h = 193

State h(n) A 366 B 374 C 329 D 244 E 253 F 178 G 193 H 98 I

slide-19
SLIDE 19

A A F B C E G I E

h = 253 h =366 h=178 h=193 h = 0 h = 253

State h(n) A 366 B 374 C 329 D 244 E 253 F 178 G 193 H 98 I

slide-20
SLIDE 20

Optimality

A- E- F- I = 450 A- E- G- H- I = 418 vs.

75 118 111 140 80 97 99 101 211 A B C D E F G H I

State h(n) A 366 B 374 C 329 D 244 E 253 F 178 G 193 H 98 I

slide-21
SLIDE 21

Completeness

  • Greedy Search is incomplete
  • Worst-case time complexity

O(bm)

Straight-line distance

A B C D

h(n)

5 7 6 A D B C

Target node

Starting node

slide-22
SLIDE 22

A* search

f(n) = g(n) + h(n)

  • h = heuristic function
  • g = uniform-cost search

75 118 111 140 80 97 99 101 211 A B C D E F G H I

State h(n) A 366 B 374 C 329 D 244 E 253 F 178 G 193 H 98 I

slide-23
SLIDE 23

“ Since g(n) gives the path from the start node to node n, and h(n) is the estimated cost of the cheapest path from n to the goal, we have… ” f(n) = estimated cost of the cheapest solution through n

slide-24
SLIDE 24

A E C B

f = 75 +374 =449 f = 118+329 =447 f=140 + 253 =393

f(n) = g(n) + h(n) A E C B A F G

f = 140+253 = 393 f =0 + 366 = 366 f = 280+366 = 646 f =239+178 =417 f = 220+193 = 413

slide-25
SLIDE 25

A A F B C E G H E

f = 140 + 253 = 393 f =220+193 =413 f = 317+98 = 415 f = 300+253 = 553

f =0 + 366= 366

slide-26
SLIDE 26

A A F B C E G H E f = 140 + 253 = 393 f =220+193 =413 f = 300+253 = 553 f =0 + 366= 366 f = 317+98 = 415 I

f = 418+0 = 418

f(n) = g(n) + h(n)

State h(n) A 366 B 374 C 329 D 244 E 253 F 178 G 193 H 98 I

slide-27
SLIDE 27

A- E- G- H- I = 418

Remember earlier

G H I E A

f = 418+0 = 418

slide-28
SLIDE 28

Genetic Algorithm-1

  • Use Biological process metaphor
  • The problem state must be encoded into a string

called a chromosome ( usually binary)

  • An Evaluation function that takes that encoded

string as input and produces “Goodness” or biological fitness score.

  • This score is then used to rank a set of strings

(individuals)

  • The individuals that are most fit are randomly

selected to survive and even procreate into the next generation

slide-29
SLIDE 29

Genetic Algorithm-2

  • Genetically inspired operators are used:

mutation and cross over.

  • The mutation operator performs random

mutation or changes in the chromosome. In the usual binary string case, few bits are randomly flapped

  • The crossover operator takes two

particular fit individuals and combine their genetic material forming two new children

slide-30
SLIDE 30

Genetic Algorithm-3

  • Example

– Parent A: 0010010011 – Parent B: 1100001010 – Mutate (A): 0011010001 – Crossover (A,B) Child1: 0010001010 Child2: 1100010011