25
States and Search Core of intelligent behaviour

States and Search Core of intelligent behaviour. D Goforth - COSC 4117, fall 20062 The simple problem solver Restricted form of general agent: Figure

Embed Size (px)

Citation preview

States and Search

Core of intelligent behaviour

D Goforth - COSC 4117, fall 2006 2

The simple problem solverRestricted form of general agent: Figure 3.1 , p.61function Simple-Problem-Solving-Agent( percept) returns

action seq an action sequence, initially empty state some description of the current world state goal a goal, initially null problem a problem formulation

state = Update-State(state, percept) if seq is empty (ie – do search first time only)

goal = Formulate-Goal(state)if (state==goal) return nil problem = Formulate-Problem(state, goal) (performance)seq = Search(problem)

action First(seq) seq = Rest(seq) return action

Creating a solution sequence by graph search

D Goforth - COSC 4117, fall 2006 3

The simple problem solver works by simulating the problem in internal

representation and trying plans till a good one is discovered

works in deterministic, static, single agent environments plan is made once and never changed

works if plan is perfect – actions do what plan assumes no corrections to path are required

works efficiently if space is not too large

D Goforth - COSC 4117, fall 2006 4

Representation of Environment – abstractions of real world

states and state space – only relevant information in state representation

actions - successor function costs and path cost (eg touring problem TSP)

start state goal

state or criterion function of state(s)

D Goforth - COSC 4117, fall 2006 5

Representation of Environment – state space efficiency

Faster processing minimization of number of states minimization of degree of branching

of successor function (actions)Smaller memory allocation large state spaces are

generated/explored, not stored/traversed

D Goforth - COSC 4117, fall 2006 6

Searching state space

The fundamental methodfor creating a plan

IsSEARCH

D Goforth - COSC 4117, fall 2006 7

Searching – graph traversals – TREE-SEARCH – p. 70

start node and all possible actions, then pick another node...:

D Goforth - COSC 4117, fall 2006 8

Design of a search space – the spanning tree over a state space

Node in search space current state reference to parent node on path action from parent to node path cost from start node (may be just

path length)

D Goforth - COSC 4117, fall 2006 9

Problem-solving agent – example

L L L L

R R R R L R R R

R L L L

R R L L R L L RR L R L

L R L L L L L RL L R L

R R R L R L R RR R L R

L R R L L L R RL R L R

Node in search space

L L R L

2

F

State

Parent link

Action

Path length

R R R L

3

Ff

D Goforth - COSC 4117, fall 2006 10

Problem-solving agent – example

L L L L

R R R R L R R R

R L L L

R R L L R L L RR L R L

L R L L L L L RL L R L

R R R L R L R RR R L R

L R R L L L R RL R L R

SPANNING TREE

Note why some state space edges are not traversed in the spanning tree

D Goforth - COSC 4117, fall 2006 11

General search algorithm – p.72

EXAMPLE: breadth first search in a binary tree

start state (visitedList)

fringe (openList)current state

general search algorithm -variationstartState

initial state of environmentadjacentNode, node

nodes of search tree: contain state, parent, action, path costopenList

collection of Nodes generated, not tested yet (fringe)visitedList

collection of Nodes already tested and not the goalaction[n]

list of actions that can be taken by agent

goalStateFound(state) returns booleanevaluate a state as goal

precondition(state, action) returns booleantest a state for action

apply(node,action) returns nodeapply action to get next state node

makeSequence(node) returns sequence of actionsgenerate plan as sequence of actions

general search algorithm -variationalgorithm search (startState, goalStateFound())

returns action sequence openList = new NodeCollection(); // stack or queue or... visitedList = new NodeCollection(); node = new Node(startState, null, null, 0 0); openList.insert(node) while ( notEmpty(openList) ) node = openList.get() if (goalStateFound (node.state) ) // successful search

return makeSequence(node) for k = 0..n-1

if (precondition(node.state, action[k])==TRUE) adjacentNode = apply(nextNode,action[k])

if NOT(adjacentNode in openList OR visitedList) openList.insert(adjacentNode)

visitedList.insert(node) return null

D Goforth - COSC 4117, fall 2006 14

algorithms of general search

breadth first depth first iterative deepening search uniform cost search

D Goforth - COSC 4117, fall 2006 15

variations on search algorithm

1. breadth first search openList is a queue

2. depth first search openList is a stack (recursive depth first is equivalent)

tradeoffs for bfs:shortest path vs resources required

R R R L

3

Ff

State

Parent link

Action

Path length

D Goforth - COSC 4117, fall 2006 16

comparison of bfs and dfs nodes on openList while search is at level k:

bfs O(nk ) n is branching factor dfs O(nk) recursive dfs O(k)

quality of solution path bfs always finds path with fewest actions dfs may find a longer path before a shorter one

D Goforth - COSC 4117, fall 2006 17

depth-limited dfs use depth first search

with limited path lengthegdfs(startNode,goalStateFound(),3)uses dfs but only goes to level 3

D Goforth - COSC 4117, fall 2006 18

iterated (depth-limited) dfs

variation on dfs to get best of both small openList of dfs finds path with fewest actions like bfs

repeated searching is not a big problem!!!

D Goforth - COSC 4117, fall 2006 19

iterative deepening dfs search algorithm puts depth-limited dfs in a loop:algorithm search (startState, goalStateFound())

Node node = nulldepth = 0while (node == null)

depth++node = dfs(startState,goalStateFound(),depth)

return node

D Goforth - COSC 4117, fall 2006 20

uniform cost search

find best path when there is an action cost for each edge: a path of more edges may be better than

a path of fewer edges: 12+8+9+4+10 (5 edges) is preferred to

35+18 (2 edges) variation on bfs openList is a priority queue ordered on

path cost from start state

D Goforth - COSC 4117, fall 2006 21

uniform cost search - example

openList is a priority queue ordered on path cost from start state

visited.

openC(2),B(4),D(8)

currentA(0)

A

B C D

42

8

visited.

openC(2),B(4),D(8)

currentA(0)

A

B C D

42

8

visitedA(0)

openB(4),E(5),D(8)

currentC(2)

A

B C D

42

8

E

3

visitedA(0),C(2), B(4) open

G(6),F(7),D(8), H(10)current

E(5)

A

B C D

42

8

E

3

F G

35

visitedA(0),C(2)

openE(5),F(7),D(8),G(9)

currentB(4)

A

B C D

42

8

E

3

F G

35

H

5

1

1

3

1 2

3 4

D Goforth - COSC 4117, fall 2006 23

variations of the general algorithm

openList structure time of testing for goal state

D Goforth - COSC 4117, fall 2006 24

(some) problems that complicate search

perceptions are incomplete representation of state

dynamic environment – path of actions is not only cause of state change (eg games)

D Goforth - COSC 4117, fall 2006 25

what kind of problem-reprise fully / partly observable

- is state known? deterministic / stochastic

- effect of action uncertain? sequential / episodic

- plan required/useful? static / dynamic

- state changes between action & perception and/or between perception & action

discrete / continuous- concurrent or sequential actions on state

single- / multi-agentdynamic environment;possible communication, distributed AI