• Keine Ergebnisse gefunden

Foundations of Artificial Intelligence 8. State-Space Search: Data Structures for Search Algorithms Malte Helmert

N/A
N/A
Protected

Academic year: 2022

Aktie "Foundations of Artificial Intelligence 8. State-Space Search: Data Structures for Search Algorithms Malte Helmert"

Copied!
31
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Foundations of Artificial Intelligence

8. State-Space Search: Data Structures for Search Algorithms

Malte Helmert

University of Basel

March 15, 2021

(2)

Introduction Search Nodes Open Lists Closed Lists Summary

State-Space Search: Overview

Chapter overview: state-space search 5.–7. Foundations

8.–12. Basic Algorithms

8. Data Structures for Search Algorithms 9. Tree Search and Graph Search 10. Breadth-first Search

11. Uniform Cost Search

12. Depth-first Search and Iterative Deepening 13.–19. Heuristic Algorithms

(3)

Introduction Search Nodes Open Lists Closed Lists Summary

Introduction

(4)

Introduction Search Nodes Open Lists Closed Lists Summary

Search Algorithms

We now move to search algorithms.

As everywhere in computer science, suitable data structures are a key to good performance.

commonoperations must befast

Well-implemented search algorithms process

up to ∼30,000,000 states/second on a single CPU core.

bonus materials (Burns et al. paper)

this chapter: somefundamental data structuresfor search

(5)

Introduction Search Nodes Open Lists Closed Lists Summary

Preview: Search Algorithms

next chapter: we introduce search algorithms

now: short previewto motivate data structures for search

(6)

Introduction Search Nodes Open Lists Closed Lists Summary

Example: Search Algorithm

Starting with initial state,

repeatedly expanda state bygenerating itssuccessors.

Stop when agoal state is expanded

or all reachable states have been considered.

German: expandieren, erzeugen

h3,3,1i

. . . and so on (expansion order depends on search algorithm used)

(7)

Introduction Search Nodes Open Lists Closed Lists Summary

Example: Search Algorithm

Starting with initial state,

repeatedly expanda state bygenerating itssuccessors.

Stop when agoal state is expanded

or all reachable states have been considered.

German: expandieren, erzeugen

h3,3,1i

. . . and so on (expansion order depends on search algorithm used)

(8)

Introduction Search Nodes Open Lists Closed Lists Summary

Example: Search Algorithm

Starting with initial state,

repeatedly expanda state bygenerating itssuccessors.

Stop when agoal state is expanded

or all reachable states have been considered.

German: expandieren, erzeugen

h3,3,1i

h2,2,0i h3,2,0i h3,1,0i

. . . and so on (expansion order depends on search algorithm used)

(9)

Introduction Search Nodes Open Lists Closed Lists Summary

Example: Search Algorithm

Starting with initial state,

repeatedly expanda state bygenerating itssuccessors.

Stop when agoal state is expanded

or all reachable states have been considered.

German: expandieren, erzeugen

h3,3,1i

h2,2,0i h3,2,0i

h3,3,1i

h3,1,0i

. . . and so on (expansion order depends on search algorithm used)

(10)

Introduction Search Nodes Open Lists Closed Lists Summary

Example: Search Algorithm

Starting with initial state,

repeatedly expanda state bygenerating itssuccessors.

Stop when agoal state is expanded

or all reachable states have been considered.

German: expandieren, erzeugen

h3,3,1i

h2,2,0i

h3,2,1i h3,3,1i

h3,2,0i

h3,3,1i

h3,1,0i

. . . and so on (expansion order depends on search algorithm used)

(11)

Introduction Search Nodes Open Lists Closed Lists Summary

Example: Search Algorithm

Starting with initial state,

repeatedly expanda state bygenerating itssuccessors.

Stop when agoal state is expanded

or all reachable states have been considered.

German: expandieren, erzeugen

h3,3,1i

h2,2,0i

h3,2,1i h3,3,1i

h3,2,0i

h3,3,1i

h2,2,0i h3,2,0i h3,1,0i

h3,1,0i

. . . and so on (expansion order depends on search algorithm used)

(12)

Introduction Search Nodes Open Lists Closed Lists Summary

Example: Search Algorithm

Starting with initial state,

repeatedly expanda state bygenerating itssuccessors.

Stop when agoal state is expanded

or all reachable states have been considered.

German: expandieren, erzeugen

h3,3,1i

h2,2,0i

h3,2,1i h3,3,1i

h3,2,0i

h3,3,1i

h2,2,0i h3,2,0i h3,1,0i

h3,1,0i

. . . and so on (expansion order depends on search algorithm used)

(13)

Introduction Search Nodes Open Lists Closed Lists Summary

Fundamental Data Structures for Search

We consider three abstract data structures for search:

search node: stores a state that has been reached, how it was reached, and at which cost

nodes of the example search tree

open list: efficiently organizes leaves of search tree set of leaves of example search tree

closed list: remembers expanded states

to avoid duplicated expansions of the same state inner nodes of a search tree

German: Suchknoten, Open-Liste, Closed-Liste Not all algorithms use all three data structures,

and they are sometimes implicit (e.g., in the CPU stack)

(14)

Introduction Search Nodes Open Lists Closed Lists Summary

Search Nodes

(15)

Introduction Search Nodes Open Lists Closed Lists Summary

Search Nodes

Search Node

Asearch node(node for short) stores a state

that has been reached, how it was reached, and at which cost.

Collectively they form the so-calledsearch tree(Suchbaum).

(16)

Introduction Search Nodes Open Lists Closed Lists Summary

Attributes of a Search Node

Attributes of a Search Noden

n.state state associated with this node n.parent search node that generated this node

(nonefor the root node)

n.action action leading from n.parent to n (nonefor the root node)

n.path cost cost of path from initial state ton.state that result from following the parent references (traditionally denoted byg(n))

. . . and sometimes additional attributes (e.g.,depthin tree)

(17)

Introduction Search Nodes Open Lists Closed Lists Summary

Search Nodes: Java

Search Nodes (Java Syntax) public interface State { }

public interface Action { }

public class SearchNode { State state;

SearchNode parent;

Action action;

int pathCost;

}

(18)

Introduction Search Nodes Open Lists Closed Lists Summary

Node in a Search Tree

1 2 3 4 5 6 7

1 8 2 3 4 5 6 7

8

Node

DEPTH = 6

STATE

PARENT-NODE

ACTION = right PATH-COST = 6

(19)

Introduction Search Nodes Open Lists Closed Lists Summary

Implementing Search Nodes

reasonable implementation of search nodes is easy advanced aspects:

Do we need explicit nodes at all?

Can we use lazy evaluation?

Should we manually manage memory?

Can we compress information?

(20)

Introduction Search Nodes Open Lists Closed Lists Summary

Operations on Search Nodes: make root node

Generate root node of a search tree:

functionmake root node() node:=newSearchNode node.state :=init() node.parent :=none node.action :=none node.path cost := 0 returnnode

(21)

Introduction Search Nodes Open Lists Closed Lists Summary

Operations on Search Nodes: make node

Generate child node of a search node:

functionmake node(parent,action,state) node:=newSearchNode

node.state :=state node.parent :=parent node.action :=action

node.path cost :=parent.path cost +cost(action) returnnode

(22)

Introduction Search Nodes Open Lists Closed Lists Summary

Operations on Search Nodes: extract path

Extract the path to a search node:

functionextract path(node) path:=hi

whilenode.parent6=none:

path.append(node.action) node:=node.parent path.reverse()

returnpath

(23)

Introduction Search Nodes Open Lists Closed Lists Summary

Open Lists

(24)

Introduction Search Nodes Open Lists Closed Lists Summary

Open Lists

Open List

Theopen list (also: frontier) organizes the leaves of a search tree.

It must support two operations efficiently:

determine and remove the next node to expand

insert a new node that is a candidate node for expansion Remark: despite the name, it is usually a very bad idea to implement open lists as simplelists.

(25)

Introduction Search Nodes Open Lists Closed Lists Summary

Open Lists: Modify Entries

Some implementations supportmodifying an open list entry when a shorter path to the corresponding state is found.

This complicates the implementation.

We do not consider such modifications

and instead use delayed duplicate elimination( later)

(26)

Introduction Search Nodes Open Lists Closed Lists Summary

Interface of Open Lists

Methods of an Open Listopen

open.is empty() test if the open list is empty

open.pop() removes and returns the next node to expand open.insert(n) inserts noden into the open list

Different search algorithm use different strategies for the decision which node to return inopen.pop.

The choice of a suitable data structure depends on this strategy (e.g., stack, deque, min-heap).

(27)

Introduction Search Nodes Open Lists Closed Lists Summary

Closed Lists

(28)

Introduction Search Nodes Open Lists Closed Lists Summary

Closed Lists

Closed List

Theclosed listremembers expanded states to avoid duplicated expansions of the same state.

It must support two operations efficiently:

insert a node whose state is not yet in the closed list test if a node with a given state is in the closed list;

if yes, return it

Remark: despite the name, it is usually a very bad idea to implement closed lists as simplelists. (Why?)

(29)

Introduction Search Nodes Open Lists Closed Lists Summary

Interface and Implementation of Closed Lists

Methods of a Closed Listclosed

closed.insert(n) insert noden into closed;

if a node with this state already exists inclosed, replace it

closed.lookup(s) test if a node with states exists in the closed list;

if yes, return it; otherwise, returnnone Hash tables with states as keys can serve as

efficient implementations of closed lists.

(30)

Introduction Search Nodes Open Lists Closed Lists Summary

Summary

(31)

Introduction Search Nodes Open Lists Closed Lists Summary

Summary

search node:

represents states reached during search and associated information

node expansion:

generate successor nodes of a node by applying all actions applicable in the state belonging to the node

open list or frontier:

set of nodes that are currently candidates for expansion closed list:

set of already expanded nodes (and their states)

Referenzen

ÄHNLICHE DOKUMENTE

State-Space Search: Data Structures for Search Algorithms Open Lists. 8.3

recognize duplicates: when a state is reached on multiple paths, only keep one search node search nodes correspond 1:1 to reachable states search tree bounded, as number of states

I recognize duplicates: when a state is reached on multiple paths, only keep one search node I search nodes correspond 1:1 to reachable states I search tree bounded, as number of

breadth-first search ( this chapter) uniform cost search ( Chapter 11) depth-first search ( Chapter 12) depth-limited search ( Chapter 12) iterative deepening search ( Chapter

I breadth-first search ( this chapter) I uniform cost search ( Chapter 11) I depth-first search ( Chapter 12) I depth-limited search ( Chapter 12) I iterative deepening search (

breadth-first search optimal if all action costs equal otherwise no optimality guarantee example:.. remedy: uniform

uniform cost search: expand nodes in order of ascending path costs. I usually as a

space complexity O(bm) if m maximal search depth reached low memory complexity main reason why depth-first search interesting despite its disadvantages.. Depth-first