g5baim artificial intelligence methods graham kendall searching

29
G5BAIM Artificial Intelligence Methods Graham Kendall Searching

Upload: patrick-bell

Post on 13-Dec-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: G5BAIM Artificial Intelligence Methods Graham Kendall Searching

G5BAIMArtificial Intelligence Methods

Graham KendallSearching

Page 2: G5BAIM Artificial Intelligence Methods Graham Kendall Searching

G5BAIM SearchingG5BAIM Searching

Problem Definition - 1

• Initial State– The initial state of the problem,

defined in some suitable manner

• Operator– A set of actions that moves the

problem from one state to another

Page 3: G5BAIM Artificial Intelligence Methods Graham Kendall Searching

G5BAIM SearchingG5BAIM Searching

Problem Definition - 1

• Neighbourhood (Successor Function)– The set of all possible states

reachable from a given state

• State Space– The set of all states reachable from

the initial state

Page 4: G5BAIM Artificial Intelligence Methods Graham Kendall Searching

G5BAIM SearchingG5BAIM Searching

Problem Definition - 2

• Goal Test– A test applied to a state which

returns if we have reached a state that solves the problem

• Path Cost– How much it costs to take a

particular path

Page 5: G5BAIM Artificial Intelligence Methods Graham Kendall Searching

G5BAIM SearchingG5BAIM Searching

Problem Definition - Example

5 4

6 1 8

7 3 2

1 2 3

8 4

7 6 5

1 2 3

4 5 6

7 8

1 4 7

2 5 8

3 6

Initial State Goal State

Page 6: G5BAIM Artificial Intelligence Methods Graham Kendall Searching

G5BAIM SearchingG5BAIM Searching

Problem Definition - Example

• States– A description of each of the eight

tiles in each location that it can occupy. It is also useful to include the blank

• Operators– The blank moves left, right, up or

down

Page 7: G5BAIM Artificial Intelligence Methods Graham Kendall Searching

G5BAIM SearchingG5BAIM Searching

Problem Definition - Example

• Goal Test– The current state matches a

certain state (e.g. one of the ones shown on previous slide)

• Path Cost– Each move of the blank costs 1

Page 8: G5BAIM Artificial Intelligence Methods Graham Kendall Searching

G5BAIM SearchingG5BAIM Searching

Problem Definition - Datatype

• Datatype PROBLEM– Components

• INITIAL-STATE,

• OPERATORS,

• GOAL-TEST,

• PATH-COST-FUNCTION

Page 9: G5BAIM Artificial Intelligence Methods Graham Kendall Searching

G5BAIM SearchingG5BAIM Searching

How Good is a Solution?

• Does our search method actually find a solution?

• Is it a good solution?– Path Cost

– Search Cost (Time and Memory)

• Does it find the optimal solution?– But what is optimal?

Page 10: G5BAIM Artificial Intelligence Methods Graham Kendall Searching

G5BAIM SearchingG5BAIM Searching

Evaluating a Search

• Completeness– Is the strategy guaranteed to find a

solution?

• Time Complexity– How long does it take to find a

solution?

Page 11: G5BAIM Artificial Intelligence Methods Graham Kendall Searching

G5BAIM SearchingG5BAIM Searching

Evaluating a Search

• Space Complexity– How much memory does it take to

perform the search?

• Optimality– Does the strategy find the optimal

solution where there are several solutions?

Page 12: G5BAIM Artificial Intelligence Methods Graham Kendall Searching

G5BAIM SearchingG5BAIM Searching

Search Trees

xx x x

x xx x x

o

x

o

xx

o

x………..

Page 13: G5BAIM Artificial Intelligence Methods Graham Kendall Searching

G5BAIM SearchingG5BAIM Searching

Search Trees

• ISSUES– Search trees grow very quickly

– The size of the search tree is governed by the branching factor

– Even this simple game has a complete search tree of 984,410 potential nodes

– The search tree for chess has a branching factor of about 35

Page 14: G5BAIM Artificial Intelligence Methods Graham Kendall Searching

G5BAIM SearchingG5BAIM SearchingImplementing a Search - What we need to store

• State– This represents the state in the state

space to which this node corresponds

• Parent-Node– This points to the node that generated

this node. In a data structure representing a tree it is usual to call this the parent node

Page 15: G5BAIM Artificial Intelligence Methods Graham Kendall Searching

G5BAIM SearchingG5BAIM SearchingImplementing a Search - What we need to store

• Operator– The operator that was applied to generate

this node

• Depth– The number of nodes from the root (i.e.

the depth)

• Path-Cost– The path cost from the initial state to this

node

Page 16: G5BAIM Artificial Intelligence Methods Graham Kendall Searching

G5BAIM SearchingG5BAIM Searching

Implementing a Search - Datatype

• Datatype node– Components:

• STATE,

• PARENT-NODE,

• OPERATOR,

• DEPTH,

• PATH-COST

Page 17: G5BAIM Artificial Intelligence Methods Graham Kendall Searching

G5BAIM SearchingG5BAIM Searching

Using a Tree – The Obvious Solution?

• Advantages– It’s intuitive

– Parent’s are automatically catered for

Page 18: G5BAIM Artificial Intelligence Methods Graham Kendall Searching

G5BAIM SearchingG5BAIM Searching

Using a Tree – The Obvious Solution?

• But– It can be wasteful on space

– It can be difficult the implement, particularly if there are varying number of children (as in tic-tac-toe)

– It is not always obvious which node to expand next. We may have to search the tree looking for the best leaf node (sometimes called the fringe or frontier nodes). This can obviously be computationally expensive

Page 19: G5BAIM Artificial Intelligence Methods Graham Kendall Searching

G5BAIM SearchingG5BAIM Searching

Using a Tree – Maybe not so obvious

• Therefore– It would be nice to have a

“simpler” data structure to represent our tree

– And it would be nice if the next node to be expanded was an O(1) operation

Page 20: G5BAIM Artificial Intelligence Methods Graham Kendall Searching

G5BAIM SearchingG5BAIM Searching

Basic Queue Operations

• Make-Queue(Elements)– Create a queue with the given elements

• Empty?(Queue)– Returns true if the queue is empty

• Remove-Front(Queue)– Removes the element at the head of the

queue and returns it

Page 21: G5BAIM Artificial Intelligence Methods Graham Kendall Searching

G5BAIM SearchingG5BAIM Searching

Queue Operations - Adding Elements

• Queuing-FN(Elements,Queue)– Inserts a set of elements into the

queue. Different queuing functions produce different search algorithms.

Page 22: G5BAIM Artificial Intelligence Methods Graham Kendall Searching

G5BAIM SearchingG5BAIM Searching

General Search

• 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

• End Function

Page 23: G5BAIM Artificial Intelligence Methods Graham Kendall Searching

G5BAIM SearchingG5BAIM Searching

General Search• 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

• End Function

Page 24: G5BAIM Artificial Intelligence Methods Graham Kendall Searching

G5BAIM SearchingG5BAIM Searching

General Search• 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

• End Function

Page 25: G5BAIM Artificial Intelligence Methods Graham Kendall Searching

G5BAIM SearchingG5BAIM Searching

General Search• 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

• End Function

Page 26: G5BAIM Artificial Intelligence Methods Graham Kendall Searching

G5BAIM SearchingG5BAIM Searching

General Search• 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

• End Function

Page 27: G5BAIM Artificial Intelligence Methods Graham Kendall Searching

G5BAIM SearchingG5BAIM Searching

General Search• 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

• End Function

Page 28: G5BAIM Artificial Intelligence Methods Graham Kendall Searching

G5BAIM SearchingG5BAIM Searching

General Search• 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

• End Function

Page 29: G5BAIM Artificial Intelligence Methods Graham Kendall Searching

G5BAIMArtificial Intelligence Methods

Graham KendallEnd of Searching