Foundations of Artificial Intelligence
March 7, 2016 — 8. State-Space Search: Data Structures for Search Algorithms
8.1 Introduction
Foundations of Artificial Intelligence
8. State-Space Search: Data Structures for Search Algorithms
8.2 Search Nodes
Malte Helmert
8.3 Open Lists
Universität Basel
8.4 Closed Lists
March 7, 2016
8.5 Summary
M. Helmert (Universität Basel)
Foundations of Artificial Intelligence
March 7, 2016
1 / 32
M. Helmert (Universität Basel)
Foundations of Artificial Intelligence
8. State-Space Search: Data Structures for Search Algorithms
March 7, 2016
2 / 32
Introduction
State-Space Search: Overview
Chapter overview: state-space search
I
I
5.–7. Foundations
8.–12. Basic Algorithms
I
I
I
I
I
I
8.1 Introduction
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
M. Helmert (Universität Basel)
Foundations of Artificial Intelligence
March 7, 2016
3 / 32
M. Helmert (Universität Basel)
Foundations of Artificial Intelligence
March 7, 2016
4 / 32
8. State-Space Search: Data Structures for Search Algorithms
Introduction
Search Algorithms
Introduction
Preview: Search Algorithms
I
We now move to search algorithms.
I
As everywhere in computer science, suitable data structures
are a key to good performance.
common operations must be fast
I
8. State-Space Search: Data Structures for Search Algorithms
Well-implemented search algorithms process
up to ∼30,000,000 states/second on a single CPU core.
I
next chapter: we introduce search algorithms
I
now: short preview to motivate data structures for search
bonus materials (Burns et al. paper)
this chapter: some fundamental data structures for search
M. Helmert (Universität Basel)
Foundations of Artificial Intelligence
March 7, 2016
8. State-Space Search: Data Structures for Search Algorithms
5 / 32
Introduction
Example: Search Algorithm
I
I
I
I
M. Helmert (Universität Basel)
Foundations of Artificial Intelligence
March 7, 2016
8. State-Space Search: Data Structures for Search Algorithms
6 / 32
Introduction
Example: Search Algorithm
Starting with initial state,
repeatedly expand a state by generating its successors.
Stop when a goal state is expanded
or all reachable states have been considered.
I
I
I
I
German: expandieren, erzeugen
Starting with initial state,
repeatedly expand a state by generating its successors.
Stop when a goal state is expanded
or all reachable states have been considered.
German: expandieren, erzeugen
h3, 3, 1i
M. Helmert (Universität Basel)
Foundations of Artificial Intelligence
March 7, 2016
7 / 32
M. Helmert (Universität Basel)
Foundations of Artificial Intelligence
March 7, 2016
8 / 32
8. State-Space Search: Data Structures for Search Algorithms
Introduction
Example: Search Algorithm
I
I
I
I
8. State-Space Search: Data Structures for Search Algorithms
Example: Search Algorithm
Starting with initial state,
repeatedly expand a state by generating its successors.
Stop when a goal state is expanded
or all reachable states have been considered.
I
I
I
I
German: expandieren, erzeugen
Starting with initial state,
repeatedly expand a state by generating its successors.
Stop when a goal state is expanded
or all reachable states have been considered.
German: expandieren, erzeugen
h3, 3, 1i
h2, 2, 0i
h3, 2, 0i
Introduction
h3, 3, 1i
h3, 1, 0i
h2, 2, 0i
h3, 2, 0i
h3, 1, 0i
h3, 3, 1i
M. Helmert (Universität Basel)
Foundations of Artificial Intelligence
March 7, 2016
8. State-Space Search: Data Structures for Search Algorithms
9 / 32
Introduction
Example: Search Algorithm
I
I
I
I
M. Helmert (Universität Basel)
Foundations of Artificial Intelligence
8. State-Space Search: Data Structures for Search Algorithms
I
I
I
I
German: expandieren, erzeugen
h3, 2, 1i
h3, 3, 1i
German: expandieren, erzeugen
h3, 3, 1i
h3, 1, 0i
h2, 2, 0i
h3, 3, 1i
h3, 2, 1i
h3, 2, 0i
h3, 3, 1i
Foundations of Artificial Intelligence
March 7, 2016
11 / 32
M. Helmert (Universität Basel)
h3, 1, 0i
h3, 3, 1i
h2, 2, 0i
M. Helmert (Universität Basel)
Introduction
Starting with initial state,
repeatedly expand a state by generating its successors.
Stop when a goal state is expanded
or all reachable states have been considered.
h3, 3, 1i
h3, 2, 0i
10 / 32
Example: Search Algorithm
Starting with initial state,
repeatedly expand a state by generating its successors.
Stop when a goal state is expanded
or all reachable states have been considered.
h2, 2, 0i
March 7, 2016
h3, 2, 0i
h3, 1, 0i
Foundations of Artificial Intelligence
March 7, 2016
12 / 32
8. State-Space Search: Data Structures for Search Algorithms
Introduction
Example: Search Algorithm
I
I
I
I
8. State-Space Search: Data Structures for Search Algorithms
Introduction
Fundamental Data Structures for Search
Starting with initial state,
repeatedly expand a state by generating its successors.
Stop when a goal state is expanded
or all reachable states have been considered.
We consider three abstract data structures for search:
I
search node: stores a state that has been reached,
how it was reached, and at which cost
nodes of the example search tree
German: expandieren, erzeugen
I
open list: efficiently organizes leaves of search tree
set of leaves of example search tree
h3, 3, 1i
h2, 2, 0i
I
h3, 2, 0i
h3, 1, 0i
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
h3, 2, 1i
h3, 3, 1i
h3, 3, 1i
h2, 2, 0i
h3, 2, 0i
Not all algorithm use all three data structures,
and they are sometimes implicit (e.g., in the CPU stack)
h3, 1, 0i
. . . and so on (expansion order depends on search algorithm used)
M. Helmert (Universität Basel)
Foundations of Artificial Intelligence
8. State-Space Search: Data Structures for Search Algorithms
March 7, 2016
13 / 32
Search Nodes
M. Helmert (Universität Basel)
Foundations of Artificial Intelligence
March 7, 2016
8. State-Space Search: Data Structures for Search Algorithms
14 / 32
Search Nodes
Search Nodes
8.2 Search Nodes
Search Node
A search node (node for short) stores a state
that has been reached, how it was reached, and at which cost.
Collectively they form the so-called search tree (Suchbaum).
M. Helmert (Universität Basel)
Foundations of Artificial Intelligence
March 7, 2016
15 / 32
M. Helmert (Universität Basel)
Foundations of Artificial Intelligence
March 7, 2016
16 / 32
8. State-Space Search: Data Structures for Search Algorithms
Search Nodes
Attributes of a Search Node
8. State-Space Search: Data Structures for Search Algorithms
Search Nodes
Search Nodes: Java
Search Nodes (Java Syntax)
Attributes of a Search Node n
n.state state associated with this node
public interface State {
}
n.parent search node that generated this node
(none for the root node)
public interface Action {
}
n.action action leading from n.parent to n
(none for the root node)
public class SearchNode {
State state;
SearchNode parent;
Action action;
int pathCost;
}
n.path cost cost of path from initial state to n.state
that result from following the parent references
(traditionally denoted by g (n))
. . . and sometimes additional attributes (e.g., depth in tree)
M. Helmert (Universität Basel)
Foundations of Artificial Intelligence
March 7, 2016
8. State-Space Search: Data Structures for Search Algorithms
17 / 32
Search Nodes
Node in a Search Tree
M. Helmert (Universität Basel)
8. State-Space Search: Data Structures for Search Algorithms
I
I
Node
4
6
1
88
7
3
22
M. Helmert (Universität Basel)
March 7, 2016
18 / 32
Search Nodes
Implementing Search Nodes
PARENT-NODE
5
Foundations of Artificial Intelligence
ACTION = right
DEPTH = 6
PATH-COST = 6
I
I
I
STATE
Foundations of Artificial Intelligence
reasonable implementation of search nodes is easy
advanced aspects:
I
March 7, 2016
19 / 32
Do we need explicit nodes at all?
Can we use lazy evaluation?
Should we manually manage memory?
Can we compress information?
M. Helmert (Universität Basel)
Foundations of Artificial Intelligence
March 7, 2016
20 / 32
8. State-Space Search: Data Structures for Search Algorithms
Search Nodes
Operations on Search Nodes: make root node
8. State-Space Search: Data Structures for Search Algorithms
Operations on Search Nodes: make node
Generate root node of a search tree:
Generate child node of a search node:
function make root node()
function make node(parent, action, state)
node := new SearchNode
node.state := init()
node.parent := none
node.action := none
node.path cost := 0
return node
node := new SearchNode
node.state := state
node.parent := parent
node.action := action
node.path cost := parent.path cost + cost(action)
return node
M. Helmert (Universität Basel)
Foundations of Artificial Intelligence
8. State-Space Search: Data Structures for Search Algorithms
Search Nodes
March 7, 2016
21 / 32
Search Nodes
M. Helmert (Universität Basel)
Foundations of Artificial Intelligence
March 7, 2016
8. State-Space Search: Data Structures for Search Algorithms
22 / 32
Open Lists
Operations on Search Nodes: extract path
Extract the path to a search node:
8.3 Open Lists
function extract path(node)
path := hi
while node.parent 6= none:
path.append(node.action)
node := node.parent
path.reverse()
return path
M. Helmert (Universität Basel)
Foundations of Artificial Intelligence
March 7, 2016
23 / 32
M. Helmert (Universität Basel)
Foundations of Artificial Intelligence
March 7, 2016
24 / 32
8. State-Space Search: Data Structures for Search Algorithms
Open Lists
Open Lists
8. State-Space Search: Data Structures for Search Algorithms
Open Lists
Open Lists: Modify Entries
Open List
The open list (also: frontier) organizes the leaves of a search tree.
I
Some implementations support modifying an open list entry
when a shorter path to the corresponding state is found.
I
This complicates the implementation.
It must support two operations efficiently:
I
determine and remove the next node to expand
I
insert a new node that is a candidate node for expansion
We do not consider such modifications
and instead use delayed duplicate elimination (
later)
Remark: despite the name, it is usually a very bad idea
to implement open lists as simple lists.
M. Helmert (Universität Basel)
Foundations of Artificial Intelligence
March 7, 2016
8. State-Space Search: Data Structures for Search Algorithms
25 / 32
Open Lists
M. Helmert (Universität Basel)
Foundations of Artificial Intelligence
March 7, 2016
8. State-Space Search: Data Structures for Search Algorithms
26 / 32
Closed Lists
Interface of Open Lists
Methods of an Open List open
open.is empty() test if the open list is empty
8.4 Closed Lists
open.pop() removes and returns the next node to expand
open.insert(n) inserts node n into the open list
I
Different search algorithm use different strategies
for the decision which node to return in open.pop.
I
The choice of a suitable data structure depends
on this strategy (e.g., stack, deque, min-heap).
M. Helmert (Universität Basel)
Foundations of Artificial Intelligence
March 7, 2016
27 / 32
M. Helmert (Universität Basel)
Foundations of Artificial Intelligence
March 7, 2016
28 / 32
8. State-Space Search: Data Structures for Search Algorithms
Closed Lists
Closed Lists
8. State-Space Search: Data Structures for Search Algorithms
Interface and Implementation of Closed Lists
Closed List
The closed list remembers expanded states
to avoid duplicated expansions of the same state.
Methods of a Closed List closed
closed.insert(n) insert node n into closed;
if a node with this state already exists in closed,
replace it
It must support two operations efficiently:
I
insert a node whose state is not yet in the closed list
I
test if a node with a given state is in the closed list;
if yes, return it
closed.lookup(s) test if a node with state s exists in the closed list;
if yes, return it; otherwise, return none
I
Remark: despite the name, it is usually a very bad idea
to implement closed lists as simple lists. (Why?)
M. Helmert (Universität Basel)
Closed Lists
Foundations of Artificial Intelligence
March 7, 2016
8. State-Space Search: Data Structures for Search Algorithms
29 / 32
Summary
Hash tables with states as keys can serve as
efficient implementations of closed lists.
M. Helmert (Universität Basel)
Foundations of Artificial Intelligence
March 7, 2016
8. State-Space Search: Data Structures for Search Algorithms
30 / 32
Summary
Summary
8.5 Summary
M. Helmert (Universität Basel)
Foundations of Artificial Intelligence
March 7, 2016
31 / 32
I
search node:
represents states reached during search
and associated information
I
node expansion:
generate successor nodes of a node by applying all actions
applicable in the state belonging to the node
I
open list or frontier:
set of nodes that are currently candidates for expansion
I
closed list:
set of already expanded nodes (and their states)
M. Helmert (Universität Basel)
Foundations of Artificial Intelligence
March 7, 2016
32 / 32
© Copyright 2026 Paperzz