1 artificial intelligence cs 165a tuesday, october 9, 2007 blind search (ch. 3) 1

29
1 Artificial Intelligence CS 165A Tuesday, October 9, 2007 Blind search (Ch. 3) 1

Upload: piers-williams

Post on 01-Jan-2016

220 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: 1 Artificial Intelligence CS 165A Tuesday, October 9, 2007  Blind search (Ch. 3) 1

1

Artificial Intelligence

CS 165A

Tuesday, October 9, 2007

Blind search (Ch. 3)

1

Page 2: 1 Artificial Intelligence CS 165A Tuesday, October 9, 2007  Blind search (Ch. 3) 1

2

Notes

• Homework assignment #1 coming soon....– And overall assignment schedule

• Midterm schedule too

• CS is looking to hire a “peer advisor”– Apply to Julia Orr (in CS office) by 4pm Friday

Page 3: 1 Artificial Intelligence CS 165A Tuesday, October 9, 2007  Blind search (Ch. 3) 1

3

2007-2008 Peer Advisor Position Available

Eligibility Criteria:

• Computer Science Major (full major status)

• Junior or Senior status

• Available to work 8-10 hours/ week for the entire 2007-2008 academic year

Some responsibilities of the peer advisor include:

• Advising students about courses and course loads

• Assisting students in scheduling

• Being the Undergraduate Representative on the Computer Science Undergraduate Affairs Committee

• Completing progress checks for students

If you are interested, please submit your resume and application to Julia Orr in Harold Frank Hall 2104 by Friday, October 12th 4pm.

Page 4: 1 Artificial Intelligence CS 165A Tuesday, October 9, 2007  Blind search (Ch. 3) 1

4

Review

• Problem formulation and search– State-space description < {S}, S0, {SG}, {O}, {g} >

S: Possible states S0: Initial state of the agent

SG: Goal state(s)

– Or equivalently, a goal test G(S) O: Operators O: {S} => {S}

– Describes the possible actions of the agent g: Path cost function, assigns a cost to a path/action

• Uninformed (blind) search– Is this a goal state or not?

– Know current path cost (from start to current node)

– No information about the “goodness” of a state

Page 5: 1 Artificial Intelligence CS 165A Tuesday, October 9, 2007  Blind search (Ch. 3) 1

5

Example: MU-Puzzle

• States: Strings comprising the letters M, I, and U

• Initial state: MI

• Goal state: MU

• Operators: (where x stands for any string, including the null string)1. x I x IU “Append U”2. M x M x x “Replicate x”3. x I I I x x U x “Replace with U”4. x UU x x x “Drop UU”

• Path cost: one per step

• Try it– Can you draw the state-space diagram?– Are you guaranteed a solution?

M I

M I I

M I I I I

M U I

M U I U

M U I U U I U

M U I U U I U U I U U I U

M U I I I I U

M U U I U

M I U

M I

M I I

M I I I I

M U I

M U I U

M U I U U I U

M U I U U I U U I U U I U

M U I I I I U

M U U I U

M I U

Page 6: 1 Artificial Intelligence CS 165A Tuesday, October 9, 2007  Blind search (Ch. 3) 1

6

Example: The Vacuum World

• Simplified world: 2 grids

States: Location of vacuum, dirt in grids

Operators: Move left, move right, suck dirt

Goal test: Grids free of dirt

Path cost: Each action costs 1

Page 7: 1 Artificial Intelligence CS 165A Tuesday, October 9, 2007  Blind search (Ch. 3) 1

7

The Vacuum World (cont.)

• How to reach the goal?– If starting at top left state: S, R, S

– If starting at middle far right state: L, S

• What if agent doesn’t know its initial state?– You probably need to redraw the state diagram!

– Represent initial uncertainty as one “meta-state” For example…

Page 8: 1 Artificial Intelligence CS 165A Tuesday, October 9, 2007  Blind search (Ch. 3) 1

8

The Vacuum World (cont.)

Page 9: 1 Artificial Intelligence CS 165A Tuesday, October 9, 2007  Blind search (Ch. 3) 1

9

Example: Measuring Problem

• You have three empty buckets– 3 gallon bucket– 5 gallon bucket– 9 gallon bucket

• You can fill buckets to the top and you can empty buckets onto the ground or into other buckets

• Task: Measure out 7 gallons of water in fewest # of steps

• States, initial state, operators, goal test, path cost?

3 59

Page 10: 1 Artificial Intelligence CS 165A Tuesday, October 9, 2007  Blind search (Ch. 3) 1

10

Example: Measuring Problem (cont.)

(0 0 0)

(3 0 0)

(0 0 3)

(3 0 3)

(0 0 6)

(3 0 6)

(0 3 6)

(3 3 6)

(1 5 6)

(0 5 7)

(0 0 0)

(0 5 0)

(3 2 0)

(3 0 2)

(3 5 2)

(3 0 7)

Two solutions:

Note: In this problem, a goal test is more efficient than explicit goal states (why?)

Is this the best solution?

Page 11: 1 Artificial Intelligence CS 165A Tuesday, October 9, 2007  Blind search (Ch. 3) 1

11

Searching for Solutions

• Finding a solution is done by searching through the state space– While maintaining a set of partial solution sequences

• The search strategy determines which states should be expanded first– Expand a state = Applying the operators to the current state and

thereby generating a new set of successor states

• Conceptually, the search process builds up a search tree that is superimposed over the state space– Root node of the tree Initial state

– Leaves of the tree States to be expanded (or expanded to null)

– At each step, the search algorithm chooses a leaf to expand

Page 12: 1 Artificial Intelligence CS 165A Tuesday, October 9, 2007  Blind search (Ch. 3) 1

12

State Space vs. Search Tree

• The state space and the search tree are not the same thing!– A state represents a (possibly physical) configuration

– A search tree node is a data structure which includes: { parent, children, depth, path cost }

– States do not have parents, children, depths, path costs

– Number of states number of nodes

Page 13: 1 Artificial Intelligence CS 165A Tuesday, October 9, 2007  Blind search (Ch. 3) 1

13

State Space vs. Search Tree (cont.)

State space: 8 states

Page 14: 1 Artificial Intelligence CS 165A Tuesday, October 9, 2007  Blind search (Ch. 3) 1

14

State Space vs. Search Tree (cont.)

Search tree (partially expanded)

B C CB F

D H G

A D GA D E

B C

A

Page 15: 1 Artificial Intelligence CS 165A Tuesday, October 9, 2007  Blind search (Ch. 3) 1

15

Example: Missionaries and Cannibals

Problem: Three missionaries and three cannibals are on one side of a river, along with a boat that can hold one or two people. Find a way to get everyone to the other side, without ever leaving a group of missionaries in one place outnumbered by the cannibals in that place

• States, operators, goal test, path cost?

Demo

Page 16: 1 Artificial Intelligence CS 165A Tuesday, October 9, 2007  Blind search (Ch. 3) 1

16

M&C (cont.)

• Initial state • Goal state

MM M

CC C

MM M

CC C

(3 3 1) (0 0 0)(ML CL BL)

Page 17: 1 Artificial Intelligence CS 165A Tuesday, October 9, 2007  Blind search (Ch. 3) 1

17

M&C (cont.)

M MM

C

C

C(2 2 0)

Page 18: 1 Artificial Intelligence CS 165A Tuesday, October 9, 2007  Blind search (Ch. 3) 1

18

M&C (cont.)

• Problem description <{S}, S0, {SGj}, {Oi}, {gi}>

• {S} : { ({1,2,3} {1,2,3} {1 0}) }

• S0 : (3 3 1)

• SG : (0 0 0)

• g = 1

• {O} : { (x y b) (x’ y’ b’) }

• Constraints:– x >= 0, y >= 0– x’ >= 0, y’ >= 0– If x > 0 then x >= y– If x’ > 0 then x’ >= y’– b + b’ = 1

Operators:(x y 1) (x-2 y 0)

(x y 1) (x-1 y-1 0)

(x y 1) (x y-2 0)

(x y 1) (x-1 y 0)

(x y 1) (x y-1 0)

(x y 0) (x+2 y 1)

(x y 0) (x+1 y+1 1)

(x y 0) (x y+2 1)

(x y 0) (x+1 y 1)

(x y 0) (x y+1 1)

Page 19: 1 Artificial Intelligence CS 165A Tuesday, October 9, 2007  Blind search (Ch. 3) 1

19

M&C (cont.)

One solution path:(3 3 1)

(2 2 0)

(3 2 1)

(3 0 0)

(3 1 1)

(1 1 0)

(2 2 1)

(0 2 0)

(0 3 1)

(0 1 0)

(0 2 1)

(0 0 0)

• 11 steps

• 511 = 48 million states to explore

3 3 1

1 3 0 2 2 0 3 1 0 2 3 0 3 2 0

Page 20: 1 Artificial Intelligence CS 165A Tuesday, October 9, 2007  Blind search (Ch. 3) 1

20

Search Criteria

• Primary criteria to evaluate search strategies– Completeness

Is it guaranteed to find a solution (if one exists)?– Optimality

Does it find the “best” solution (if there are more than one)?– Time complexity

Number of nodes generated/expanded (How long does it take to find a solution?)

– Space complexity How much memory does it require?

• Some performance measures– Best case– Worst case– Average case– Real-world case

Page 21: 1 Artificial Intelligence CS 165A Tuesday, October 9, 2007  Blind search (Ch. 3) 1

21

Search Criteria (cont.)

• Complexity analysis and O( ) notation (see Appendix A)– b = Maximum branching factor of the search tree

– d = Depth of an optimal solution (may be more than one)

– m = maximum depth of the search tree (may be infinite)

• Examples

– O( b3d2 ) – polynomial time

– O( bd ) – exponential time

b = 2, d = 2, m = 3For chess, bave= 35

Search tree

Page 22: 1 Artificial Intelligence CS 165A Tuesday, October 9, 2007  Blind search (Ch. 3) 1

22

Uninformed (“Blind”) Search Strategies

• No information is available other than– The current state

Its parent (perhaps complete path from initial state)

Its operators (to produce successors)

– The goal test

– The current path cost (cost from start state to current state)

• Blind search strategies– Breadth-first search

– Uniform cost search

– Depth-first search

– Depth-limited search

– Iterative deepening search

– Bidirectional search

Page 23: 1 Artificial Intelligence CS 165A Tuesday, October 9, 2007  Blind search (Ch. 3) 1

23

General Search Algorithm (Version 1)

• Various strategies are merely variations of the following function:

function GENERAL-SEARCH(problem, strategy) returns a solution or failure

initialize the search tree using the initial state of problem loop do if there are no candidates for expansion then return failure choose a leaf node for expansion according to strategy if the node contains a goal state then return the corresponding solution else expand the node and add the resulting nodes to the search tree end

function GENERAL-SEARCH(problem, strategy) returns a solution or failure

initialize the search tree using the initial state of problem loop do if there are no candidates for expansion then return failure choose a leaf node for expansion according to strategy if the node contains a goal state then return the corresponding solution else expand the node and add the resulting nodes to the search tree end

(Called “Tree-Search” in the textbook)

Page 24: 1 Artificial Intelligence CS 165A Tuesday, October 9, 2007  Blind search (Ch. 3) 1

24

General Search Algorithm (Version 2)

function GENERAL-SEARCH(problem, QUEUING-FN) returns a solution or failure

nodes MAKE-QUEUE(MAKE-NODE(INITIAL-STATE[problem])) loop do if nodes is empty then return failure node REMOVE-FRONT(nodes) if GOAL-TEST[problem] applied to STATE(node) succeeds then return node nodes QUEUING-FN(nodes, EXPAND(node, OPERATORS[problem])) end

function GENERAL-SEARCH(problem, QUEUING-FN) returns a solution or failure

nodes MAKE-QUEUE(MAKE-NODE(INITIAL-STATE[problem])) loop do if nodes is empty then return failure node REMOVE-FRONT(nodes) if GOAL-TEST[problem] applied to STATE(node) succeeds then return node nodes QUEUING-FN(nodes, EXPAND(node, OPERATORS[problem])) end

• Uses a queue (a list) and a queuing function to implement a search strategy

– Queuing-Fn(queue, elements) inserts a set of elements into the queue and determines the order of node expansion

Page 25: 1 Artificial Intelligence CS 165A Tuesday, October 9, 2007  Blind search (Ch. 3) 1

25

Breadth-First Search

• All nodes at depth d in the search tree are expanded before any nodes at depth d+1– First consider all paths of length N, then all paths of length N+1,

etc.

• Doesn’t consider path cost – finds the solution with the shortest path

• Uses FIFO queue

function BREADTH-FIRST-SEARCH(problem) returns a solution or failure return GENERAL-SEARCH(problem, ENQUEUE-AT-END)

function BREADTH-FIRST-SEARCH(problem) returns a solution or failure return GENERAL-SEARCH(problem, ENQUEUE-AT-END)

Page 26: 1 Artificial Intelligence CS 165A Tuesday, October 9, 2007  Blind search (Ch. 3) 1

26

Example

B

A

C

D E

F

State space graph Search tree

D

Queue

(A)

(B C)

(C D)

(D B D E)

(B D E)

(D E D)

(E D)

(D F)

(F)

( )

D F

D EB

B C

A

Page 27: 1 Artificial Intelligence CS 165A Tuesday, October 9, 2007  Blind search (Ch. 3) 1

27

Example: MU-Puzzle

State space description

• Start state: MI• Goal state: MU• Operators:

1. x I x IU2. M x M x x3. xI I Ix xUx4. xUUx xx

Search tree

MIUIUIUIU

2

MIIUIIU

2

MIIIIU MIIIIIIII MUI MIU

1 2 33

2

MIIU MIIII

1

MIUIU

2

MIU

1

MII

2

MI

Page 28: 1 Artificial Intelligence CS 165A Tuesday, October 9, 2007  Blind search (Ch. 3) 1

28

Example: MU-Puzzle (cont.)

MIIIIUMIUIUIUIU

Search tree

MIUIU

MIU

MIIUIIU

MIIIIMIIU

MII

MI

MIIIIIIII MUI MIU

Queue

(MI)

(MIU MII)

(MII MIUIU)

(MIUIU MIIU MIIII)

(MIIU MIII MIUIUIUIU)

(MIII MIUIUIUIU MIIUIIU)

(MIIIIU MIIIIIIII MUI MIUMIUIUIUIU MIIUIIU)

Page 29: 1 Artificial Intelligence CS 165A Tuesday, October 9, 2007  Blind search (Ch. 3) 1

29

Breadth-First Search

• Complete?

• Optimal?

• Time complexity?

• Space complexity?

Yes

Yes

Exponential: O( bd )

Exponential: O( bd )

In practice, the memory requirements are typically worse than the time requirements