search cpsc 386 artificial intelligence ellen walker hiram college

21
Search CPSC 386 Artificial Intelligence Ellen Walker Hiram College

Upload: rudolph-stephens

Post on 13-Dec-2015

221 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Search CPSC 386 Artificial Intelligence Ellen Walker Hiram College

Search

CPSC 386 Artificial IntelligenceEllen WalkerHiram College

Page 2: Search CPSC 386 Artificial Intelligence Ellen Walker Hiram College

Problem Solving Agent

• Goal-based agent (next slide)• Must find sequence of actions that will satisfy goal

• No knowledge of the problem other than definition– No rules– No prior experience

Page 3: Search CPSC 386 Artificial Intelligence Ellen Walker Hiram College

Model-based, Goal Based

AgentEnviron-

mentsensors

effectors

world now

action now

goals

state

how world evolves

what actions do future world

Page 4: Search CPSC 386 Artificial Intelligence Ellen Walker Hiram College

Defining the Problem• World state

– All relevant information about the world (even if it cannot be perceived)

– E.g. “vacuum at left, left is dirty, right is clean”

• Initial state– World state in which the agent starts

• Goal state– World state in which the problem is solved (can be multiple)

• Actions– What the agent can do– Table: (current state, action) -> new state

• Solution– A recommended action sequence that will lead from the current state to a goal state

Page 5: Search CPSC 386 Artificial Intelligence Ellen Walker Hiram College

Searching for a Solution

• If the initial state is a goal state, return an empty sequence of actions

• Repeat (until a sequence is found) [SEARCH]– Choose an action sequence – If the sequence leads to a goal, save it.

• Repeat (until the sequence is empty) [EXECUTE]– Remove the first step from the sequence and execute it.

Page 6: Search CPSC 386 Artificial Intelligence Ellen Walker Hiram College

Environmental requirements

• Static – so the plan will still work later

• Fully Observable – so agent knows the initial state

• Discrete – so agent can enumerate choices

• Deterministic – so agent can plan a sequence of actions, believing each will lead to a specific intermediate state

Page 7: Search CPSC 386 Artificial Intelligence Ellen Walker Hiram College

State Space Formulation

• State space– Graph of states connected by actions– Usually too big to be explicitly represented, we create a Successor Function instead• Successor (state) -> ((action state) (action state)…)

• Goal test– Is this state a goal state?

• Path cost– (we assume) sum of costs of actions in a path

• Solution– Path from initial state to a goal state– Optimal: least-cost path from initial state to a goal state

Page 8: Search CPSC 386 Artificial Intelligence Ellen Walker Hiram College

Example: Water Pouring

• Problem– We have two buckets; one holds 4 gallons, and one holds 3 gallons. There are no markings on the buckets.

– How can we get exactly 2 gallons into one bucket?

Page 9: Search CPSC 386 Artificial Intelligence Ellen Walker Hiram College

Problem Formulation

• Initial state– Two empty buckets (0 0)– Goal state

• (x 2) or (2 x)

• Actions & successor function– Fill a bucket

• (x y) -> (3 y) or (x y) -> (x 4)– Empty a bucket

• (x y) -> (0 y) or (x y) -> (y 0)– Pour from one bucket to another (stop when full)

(x y) -> (0 x+y) or (x+y-4, 4)(x y) -> (x+y 0) or (3, x+y-3)

• Path cost: 1 unit per step

Page 10: Search CPSC 386 Artificial Intelligence Ellen Walker Hiram College

Partial State Space for Water Pouring

(0,0)

(4,0)(0,3)

(4,3) (3,0)(1,3)

(3,3)

(1,0)(0,1)

(4,1)

(2,3)

(2,0)(0,2)

(4,2)

Page 11: Search CPSC 386 Artificial Intelligence Ellen Walker Hiram College

Graph Node Formulation

• State (world state at this node)• Parent-node (previous node on path)

• Action (action taken to generate this node)

• Path cost, g(n) (from initial state to this node)

• Depth (number of steps taken so far)

Page 12: Search CPSC 386 Artificial Intelligence Ellen Walker Hiram College

Generic Searching

• Create a node for the initial state, and put it into the set of unexpanded nodes

• While the problem is not solved…– Pick an unexpanded node [according to strategy]

– Stop (and report the path) if it is a goal state

– Expand it (create nodes for every possible action that can be applied to that state)

Page 13: Search CPSC 386 Artificial Intelligence Ellen Walker Hiram College

Terminology

• Expanded nodes (visited)– Nodes that we have already created child nodes for• Save these to avoid repetition

• Fringe nodes (generated but unvisited)– Nodes that exist but we have not yet created child nodes for them.

Page 14: Search CPSC 386 Artificial Intelligence Ellen Walker Hiram College

Uninformed Search Strategies

• Random (if you let it run long enough)• Depth-first

– Choose the most recently generated fringe node – Save fringe nodes on a stack

• Breadth-first– Choose the least recently generated fringe node– Save fringe nodes on a queue

• Uniform cost– Choose the least cost fringe node– Save fringe nodes on a priority queue, based on path cost

Page 15: Search CPSC 386 Artificial Intelligence Ellen Walker Hiram College

Maze Example

Start a b c d

e f g h

i j k l

m n o Goal

Page 16: Search CPSC 386 Artificial Intelligence Ellen Walker Hiram College

Paths with Costs

A

D

H

B

C

J

GE

I

F

1215

8

11

9

3

105

6

8

159

6

Page 17: Search CPSC 386 Artificial Intelligence Ellen Walker Hiram College

Variations on DFS

• Backtracking search– Instead of generating all children at once and putting them on the stack, generate them one at a time

– Obvious recursive implementation– Minimal space requirements, since only the current path is stored

• Depth-limited search– Recursive implementation with a depth limit– If limit has been reached, return immediately– Distinguish between “cutoff” and “failure”

Page 18: Search CPSC 386 Artificial Intelligence Ellen Walker Hiram College

Issues with DFS and BFS

• DFS can waste a very long time on the wrong path!

• BFS requires much more space to hold the fringe.– DFS stores approximately 1 path– BFS stores all “current” nodes on all paths simultaneously

• BFS can expand nodes beyond the solution

Page 19: Search CPSC 386 Artificial Intelligence Ellen Walker Hiram College

Iterative Deepening Search

• Do a depth-limited search at 1, then at 2, etc.

• Properties– Finds shortest path (like BFS)– Cost of additional searches isn’t much, in the big-O sense. (Because the number of nodes expanded at a level is comparable to all nodes expanded at earlier levels)

– Doesn’t expand nodes beyond solution (which BFS does)

– Cost is O(bd) while BFS is O(bd+1)

• IDS is the preferred uninformed search method when there is a large search space and the depth of the solution is not known.

Page 20: Search CPSC 386 Artificial Intelligence Ellen Walker Hiram College

Bidirectional Search

• Two searches at once– Initial state toward goal state– Goal state toward initial state

• Before expanding a node, see if it’s at the fringe of the other tree. – If so, you have found a complete path

• 2 trees of depth d/2 have much fewer nodes than 1 tree of depth d

• Space cost is high, though - one tree must be kept in memory for testing against.

Page 21: Search CPSC 386 Artificial Intelligence Ellen Walker Hiram College

Evaluating Search Strategies

• Completeness– Will a solution always be found if one exists?

• Optimality– Will the optimal (least cost) solution be found?

• Time Complexity– How long does it take to find the solution?– Often represented by # nodes expanded

• Space Complexity– How much memory is needed to perform the search? – Represented by max # nodes stored at once