lecture 1: introduction and revision of searchpsznza/g52pas/lecture1.pdf · planning and search...
TRANSCRIPT
Planning and search
Lecture 1: Introduction and Revision of Search
Lecture 1: Introduction and Revision of Search 1
Contact and web page
♦ Lecturer: Natasha Alechina
♦ email: [email protected]
♦ web page: http://www.cs.nott.ac.uk/∼nza/G52PAS
♦ Textbook: Stuart Russell and Peter Norvig. Artificial Intelligence: AModern Approach, 3rd edition
♦ Slides: mostly by Stuart Russell (big thanks!)
Lecture 1: Introduction and Revision of Search 2
Outline
♦ What this module is about
♦ Where search and planning fit in AI
♦ Reminder of uninformed search algorithms
♦ Definition of planning
♦ Plan of the module
♦ What to read for next week
Lecture 1: Introduction and Revision of Search 3
Problem-solving agents
Simple problem-solving agent:
function Simple-Problem-Solving-Agent( percept) returns an action
static: 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 then
goal←Formulate-Goal(state)
problem←Formulate-Problem(state, goal)
seq←Search( problem)
if seq=failure then return a null action
action←First(seq)
seq←Rest(seq)
return action
Lecture 1: Introduction and Revision of Search 4
Example of a search problem: Romania
On holiday in Romania; currently in Arad.Flight leaves tomorrow from Bucharest
Formulate goal:be in Bucharest
Formulate problem:states: various citiesactions: drive between cities
Find solution:sequence of cities, e.g., Arad, Sibiu, Fagaras, Bucharest
Lecture 1: Introduction and Revision of Search 5
Example: Romania
Giurgiu
UrziceniHirsova
Eforie
Neamt
Oradea
Zerind
Arad
Timisoara
Lugoj
Mehadia
DobretaCraiova
Sibiu Fagaras
Pitesti
Vaslui
Iasi
Rimnicu Vilcea
Bucharest
71
75
118
111
70
75
120
151
140
99
80
97
101
211
138
146 85
90
98
142
92
87
86
Lecture 1: Introduction and Revision of Search 6
Single-state problem formulation
A problem is defined by four items:
initial state e.g., “at Arad”
successor function S(x) = set of action–state pairse.g., S(Arad) = {〈Drive(Arad,Zerind), Zerind〉, . . .}
goal test, can beexplicit, e.g., x = “at Bucharest”implicit, e.g., HasAirport(x)
path cost (additive)e.g., sum of distances, number of actions executed, etc.c(x, a, y) is the step cost, assumed to be ≥ 0
A solution is a sequence of actionsleading from the initial state to a goal state
Lecture 1: Introduction and Revision of Search 7
Selecting a state space
Real world is absurdly complex⇒ state space must be abstracted for problem solving
(Abstract) state = set of real states
(Abstract) action = complex combination of real actionse.g., “Drive(Arad, Zerind)” represents a complex set
of possible routes, detours, rest stops, etc.For guaranteed realizability, any real state “in Arad”
must get to some real state “in Zerind”
(Abstract) solution =set of real paths that are solutions in the real world
Each abstract action should be “easier” than the original problem!
Lecture 1: Introduction and Revision of Search 8
Example: The 8-puzzle
2
Start State Goal State
51 3
4 6
7 8
5
1
2
3
4
6
7
8
5
states??actions??goal test??path cost??
Lecture 1: Introduction and Revision of Search 9
Example: The 8-puzzle
2
Start State Goal State
51 3
4 6
7 8
5
1
2
3
4
6
7
8
5
states??: integer locations of tiles (ignore intermediate positions)actions??goal test??path cost??
Lecture 1: Introduction and Revision of Search 10
Example: The 8-puzzle
2
Start State Goal State
51 3
4 6
7 8
5
1
2
3
4
6
7
8
5
states??: integer locations of tiles (ignore intermediate positions)actions??: move blank left, right, up, down (ignore unjamming etc.)goal test??path cost??
Lecture 1: Introduction and Revision of Search 11
Example: The 8-puzzle
2
Start State Goal State
51 3
4 6
7 8
5
1
2
3
4
6
7
8
5
states??: integer locations of tiles (ignore intermediate positions)actions??: move blank left, right, up, down (ignore unjamming etc.)goal test??: = goal state (given)path cost??
Lecture 1: Introduction and Revision of Search 12
Example: The 8-puzzle
2
Start State Goal State
51 3
4 6
7 8
5
1
2
3
4
6
7
8
5
states??: integer locations of tiles (ignore intermediate positions)actions??: move blank left, right, up, down (ignore unjamming etc.)goal test??: = goal state (given)path cost??: 1 per move
Lecture 1: Introduction and Revision of Search 13
Tree search algorithms
Basic idea:offline, simulated exploration of state spaceby generating successors of already-explored states
(a.k.a. expanding states)
function Tree-Search( problem, strategy) returns a solution, or failure
initialize the search tree using the initial state of problem
loop do
if there are no candidates for expansion then return failure
choose a leaf node for expansion according to strategy
if the node contains a goal state then return the corresponding solution
else expand the node and add the resulting nodes to the search tree
end
Lecture 1: Introduction and Revision of Search 14
Tree search example
Rimnicu Vilcea Lugoj
ZerindSibiu
Arad Fagaras Oradea
Timisoara
AradArad Oradea
Arad
Lecture 1: Introduction and Revision of Search 15
Tree search example
Rimnicu Vilcea LugojArad Fagaras Oradea AradArad Oradea
Zerind
Arad
Sibiu Timisoara
Lecture 1: Introduction and Revision of Search 16
Tree search example
Lugoj AradArad OradeaRimnicu Vilcea
Zerind
Arad
Sibiu
Arad Fagaras Oradea
Timisoara
Lecture 1: Introduction and Revision of Search 17
Implementation: states vs. nodes
A state is a (representation of) a physical configurationA node is a data structure constituting part of a search tree
includes parent, children, depth, path cost g(x)States do not have parents, children, depth, or path cost!
1
23
45
6
7
81
23
45
6
7
8
State Node depth = 6
g = 6
state
parent, action
The Expand function creates new nodes, filling in the various fields and us-ing the SuccessorFn of the problem to create the corresponding states.
Lecture 1: Introduction and Revision of Search 18
Implementation: general tree search
Lecture 1: Introduction and Revision of Search 19
function Tree-Search( problem, fringe) returns a solution, or failure
fringe← Insert(Make-Node(Initial-State[problem]), fringe)
loop do
if fringe is empty then return failure
node←Remove-Front(fringe)
if Goal-Test(problem,State(node)) then return node
fringe← InsertAll(Expand(node,problem), fringe)
function Expand(node, problem) returns a set of nodes
successors← the empty set
for each action, result in Successor-Fn(problem,State[node]) do
s← a new Node
Parent-Node[s]← node; Action[s]← action; State[s]← result
Path-Cost[s]←Path-Cost[node] + Step-Cost(State[node],action,
result)
Depth[s]←Depth[node] + 1
add s to successors
return successors
Lecture 1: Introduction and Revision of Search 20
Search strategies
A strategy is defined by picking the order of node expansion
Strategies are evaluated along the following dimensions:completeness—does it always find a solution if one exists?time complexity—number of nodes generated/expandedspace complexity—maximum number of nodes in memoryoptimality—does it always find a least-cost solution?
Time and space complexity are measured in terms ofb—maximum branching factor of the search treed—depth of the least-cost solutionm—maximum depth of the state space (may be ∞)
Lecture 1: Introduction and Revision of Search 21
Uninformed search strategies
Uninformed strategies use only the information availablein the problem definition
Breadth-first search
Uniform-cost search
Depth-first search
Depth-limited search
Iterative deepening search
Lecture 1: Introduction and Revision of Search 22
Breadth-first search
Expand shallowest unexpanded node
Implementation:fringe is a FIFO queue, i.e., new successors go at end
A
B C
D E F G
Lecture 1: Introduction and Revision of Search 23
Breadth-first search
Expand shallowest unexpanded node
Implementation:fringe is a FIFO queue, i.e., new successors go at end
A
B C
D E F G
Lecture 1: Introduction and Revision of Search 24
Breadth-first search
Expand shallowest unexpanded node
Implementation:fringe is a FIFO queue, i.e., new successors go at end
A
B C
D E F G
Lecture 1: Introduction and Revision of Search 25
Breadth-first search
Expand shallowest unexpanded node
Implementation:fringe is a FIFO queue, i.e., new successors go at end
A
B C
D E F G
Lecture 1: Introduction and Revision of Search 26
Uniform-cost search
Expand least-cost unexpanded node
Implementation:fringe = queue ordered by path cost, lowest first
Equivalent to breadth-first if step costs all equal
Lecture 1: Introduction and Revision of Search 27
Depth-first search
Expand deepest unexpanded node
Implementation:fringe = LIFO queue, i.e., put successors at front
A
B C
D E F G
H I J K L M N O
Lecture 1: Introduction and Revision of Search 28
Depth-first search
Expand deepest unexpanded node
Implementation:fringe = LIFO queue, i.e., put successors at front
A
B C
D E F G
H I J K L M N O
Lecture 1: Introduction and Revision of Search 29
Depth-first search
Expand deepest unexpanded node
Implementation:fringe = LIFO queue, i.e., put successors at front
A
B C
D E F G
H I J K L M N O
Lecture 1: Introduction and Revision of Search 30
Depth-first search
Expand deepest unexpanded node
Implementation:fringe = LIFO queue, i.e., put successors at front
A
B C
D E F G
H I J K L M N O
Lecture 1: Introduction and Revision of Search 31
Depth-first search
Expand deepest unexpanded node
Implementation:fringe = LIFO queue, i.e., put successors at front
A
B C
D E F G
H I J K L M N O
Lecture 1: Introduction and Revision of Search 32
Depth-first search
Expand deepest unexpanded node
Implementation:fringe = LIFO queue, i.e., put successors at front
A
B C
D E F G
H I J K L M N O
Lecture 1: Introduction and Revision of Search 33
Depth-first search
Expand deepest unexpanded node
Implementation:fringe = LIFO queue, i.e., put successors at front
A
B C
D E F G
H I J K L M N O
Lecture 1: Introduction and Revision of Search 34
Depth-first search
Expand deepest unexpanded node
Implementation:fringe = LIFO queue, i.e., put successors at front
A
B C
D E F G
H I J K L M N O
Lecture 1: Introduction and Revision of Search 35
Depth-first search
Expand deepest unexpanded node
Implementation:fringe = LIFO queue, i.e., put successors at front
A
B C
D E F G
H I J K L M N O
Lecture 1: Introduction and Revision of Search 36
Depth-first search
Expand deepest unexpanded node
Implementation:fringe = LIFO queue, i.e., put successors at front
A
B C
D E F G
H I J K L M N O
Lecture 1: Introduction and Revision of Search 37
Depth-first search
Expand deepest unexpanded node
Implementation:fringe = LIFO queue, i.e., put successors at front
A
B C
D E F G
H I J K L M N O
Lecture 1: Introduction and Revision of Search 38
Depth-first search
Expand deepest unexpanded node
Implementation:fringe = LIFO queue, i.e., put successors at front
A
B C
D E F G
H I J K L M N O
Lecture 1: Introduction and Revision of Search 39
Depth-limited search
Sometimes DFS does not terminate (infinite branch)
Fix: introduce a depth limit l
Backtrack when reach l (as if found a leaf node)
Lecture 1: Introduction and Revision of Search 40
Iterative deepening search
Do depth-limited search with l = 1, 2, 3, . . .
Lecture 1: Introduction and Revision of Search 41
Iterative deepening search l = 0
Limit = 0 A A
Lecture 1: Introduction and Revision of Search 42
Iterative deepening search l = 1
Limit = 1 A
B C
A
B C
A
B C
A
B C
Lecture 1: Introduction and Revision of Search 43
Iterative deepening search l = 2
Limit = 2 A
B C
D E F G
A
B C
D E F G
A
B C
D E F G
A
B C
D E F G
A
B C
D E F G
A
B C
D E F G
A
B C
D E F G
A
B C
D E F G
Lecture 1: Introduction and Revision of Search 44
Iterative deepening search l = 3
Limit = 3
A
B C
D E F G
H I J K L M N O
A
B C
D E F G
H I J K L M N O
A
B C
D E F G
H I J K L M N O
A
B C
D E F G
H I J K L M N O
A
B C
D E F G
H I J K L M N O
A
B C
D E F G
H I J K L M N O
A
B C
D E F G
H I J K L M N O
A
B C
D E F G
H I J K L M N O
A
B C
D E F G
H I J K L M N O
A
B C
D E F G
H I J K L M N O
A
B C
D E F G
H J K L M N OI
A
B C
D E F G
H I J K L M N O
Lecture 1: Introduction and Revision of Search 45
Summary of basic search algorithms
Criterion Breadth- Uniform- Depth- Depth- IterativeFirst Cost First Limited Deepening
Complete? Yesa Yesa,b No No (Yes, if l ≥ d) Yesa
Time O(bd) O(b⌈C∗/ǫ⌉) O(bm) O(bl) O(bd)
Space O(bd) O(b⌈C∗/ǫ⌉) O(bm) O(bl) O(bd)
Optimal? Yesc Yes No No Yesc
C∗ is the cost of the optimal solution, ǫ is the minimal cost of a step, b thebranching factor, d the depth of the shallowest solution, m the maximumdepth of the search tree, l the depth limit.
a complete if b is finite; b complete if step costs ≥ ǫ, c optimal if step costsare identical
Lecture 1: Introduction and Revision of Search 46
Planning
Planning: devising a plan of action to achieve the goal (for example: buymilk, bananas, and a cordless drill)
Also talking about states of the world and actions, but more sophisticatedrepresentation
States have structure (properties); actions have pre- and post-conditions.
Action: Buy(x)
Have(x)
At(p) Sells(p,x)
Buy(x)
Precondition: At(p), Sells(p, x)Effect: Have(x)
Lecture 1: Introduction and Revision of Search 47
Search vs. planning contd.
Planning systems do the following:1) open up action and goal representation to allow selection2) divide-and-conquer by subgoaling3) relax requirement for sequential construction of solutions
Search Planning
States Data structures Logical sentencesActions Code Preconditions/outcomesGoal Code Logical sentence (conjunction)Plan Sequence from S0 Constraints on actions
Lecture 1: Introduction and Revision of Search 48
Plan of the module: search topics
♦ Another revision lecture on properties of uninformed search algorithms,heuristic search (A∗)
♦ Graph search, direction of search
♦ Local search (annealing, tabu, ...)
♦ Population-based methods (genetic algorithms...)
♦ Reducing search to SAT
♦ Search with non-determinism and partial observability
♦ Logical agents; first-order logic
Lecture 1: Introduction and Revision of Search 49
Plan of the module: planning topics
♦ Situation calculus
♦ What is classical planning. Forward planning.
♦ Classical planning continued. Regression Planning
♦ Classical planning continued. Partial-Order Planning
♦ Classical planning continued. GraphPlan.
♦ Classical planning continued. SatPlan.
♦ Planning with time and resources
♦ HTN planning.
♦ Planning and acting in non-deterministic domains.
Lecture 1: Introduction and Revision of Search 50
What to read for the next lecture
Chapter 3 in Russell and Norvig (this is revision)
Lecture 1: Introduction and Revision of Search 51