Upload
clara-french
View
220
Download
0
Tags:
Embed Size (px)
Citation preview
CS 484 – Artificial Intelligence 1
Announcements
• Department Picnic: today, after class• Lab 0 due today• Homework 2 due Tuesday, 9/18• Lab 1 due Thursday, 9/20
• Autumn – Current Event Tuesday
Search
Lecture 4
CS 484 – Artificial Intelligence 3
What is search?
• Getting from Arad to Bucharest? ?
?
Arad
SibiuTimisoara
Zerind
CS 484 – Artificial Intelligence 4
Brute Force Search
• exhaustive - examines every node in the search tree.
• Generate and test is simplest:• Generate possible solutions to the problem.• Test if valid solution.• Stop when a valid solution is found.
• The method used to generate possible solutions must be carefully chosen.
CS 484 – Artificial Intelligence 5
Depth-First Search
• DFS - exhaustive search• Follows each path to its deepest node,
before backtracking to try the next path.
CS 484 – Artificial Intelligence 6
Breadth-First Search
• BFS - exhaustive search• Follows each path to a given depth before
moving on to the next depth.
CS 484 – Artificial Intelligence 7
Comparison of Depth-First and Breadth-First Search
• Choose search method wisely• Depth first search may never find the
answer. Why?
CS 484 – Artificial Intelligence 8
Properties of Search Methods
• Complexity• Time and memory
• Completeness• Guaranteed to find a goal if one exists.
• Optimality & Admissibility• Guaranteed to find the best path to the goal.
• Irrevocability• Never back-tracks
CS 484 – Artificial Intelligence 9
Implementations
• DSF implemented using a stack to store states• Recursive function
• BFS implementations are almost identical to depth-first• Difference: use queue rather than a stack.
CS 484 – Artificial Intelligence 10
Depth-First Iterative Deepening
• Combo of DFS and BFS exhaustive search• DFS to depth of 1, then to depth of 2, 3, …
until a goal reached.• Efficient in memory use
• Copes with infinitely long branches.
• Not as inefficient in time as it might appear, • Only examines the largest row (the last one)
once.
CS 484 – Artificial Intelligence 11
Modified Traveling Salesman Problem
• Find shortest path from A to F
• Edges: length of roads
A
B
C
E
F
D
10
3 3
3 46
12
3
A
CB
BCD
DD
D
E
EE
EC
F
FF
F
F
F
F
FB
CS 484 – Artificial Intelligence 12
Heuristics
• Heuristic: a rule used to make search more efficient or effective.
• Use a heuristic evaluation function, f(n):• f(n) is the approximate distance of a node, n, from a
goal node.
• For two node m and n, if f(m) < f(n), than m is more likely to be on an optimal path
• f(n) may not be 100% accurate, but it should give better results than pure guesswork.
CS 484 – Artificial Intelligence 13
Heuristics – how informed?
• The more informed a heuristic is, the better it will perform.
• Heuristic h is more informed than j, if:• h(n) j(n) for all nodes n.
• A search method using h will search more efficiently than one using j.
• A heuristic should reduce the number of nodes that need to be examined.
CS 484 – Artificial Intelligence 14
Choosing Good Heuristics
• Right heuristic can have a significant impact in the time required to solve the problem• Should reduce the number of nodes that need to
be searched• The heuristic cannot take too long to calculate
CS 484 – Artificial Intelligence 15
8-puzzle
• States: location of each of the eight tiles and the blank one
• Initial State: Any state can be designated so• Successor function: Generates legal states that
result from trying 4 actions• Goal test: Checks whether state matches goal state• Path cost: Each step costs 1, total cost == length of
path
7 6
4 3 1
2 5 8
1 2 3
8 4
7 6 5Sta
rt
Sta
te
Goal
Sta
te
CS 484 – Artificial Intelligence 16
8-puzzle
• Game Properties• Typically 20 moves to get from random start to goal
state
• Branching Factor:
• Search tree examines 320 states (3.5 billion)
• Use heuristics to reduce states that are searched• How many states is a given state from the goal?
7 6
4 3 1
2 5 8
1 2 3
8 4
7 6 5Sta
rt
Sta
te
Goal
Sta
te
CS 484 – Artificial Intelligence 17
Admissible Heuristics
• Admissible heuristic:
• Possible 8-puzzle admissible heuristics
CS 484 – Artificial Intelligence 18
Hill Climbing
• Think of it as finding the highest point in a three dimensional search space:
• Check the height one foot away from your current location in each direction; North, South, East and West.
• Find a higher position, move to that location, and restart the algorithm.
• An informed, irrevocable search method.
CS 484 – Artificial Intelligence 19
Foothills
• Cause difficulties for hill-climbing methods.• A foothill is a local maximum.
CS 484 – Artificial Intelligence 20
Plateaus
• Cause difficulties for hill-climbing methods.• Flat areas that make it hard to find where to go
next.
CS 484 – Artificial Intelligence 21
Ridges
• Cause difficulties for hill-climbing methods• B is higher than A.
At C, the hill-climber can’t find a higher point North, South, East or West, so it stops.
CS 484 – Artificial Intelligence 22
Hill Climbing Algorithm
Function hill() {queue = [];state = root_node;while (true) { if is_goal(state) return SUCCESS; else { sort(successor(state)); add_to_front_of_queue (successor(state)); }
if queue == [] return FAILURE; state = queue[0]; remove_first_item
(queue);}
}
CS 484 – Artificial Intelligence 23
Modified Traveling Salesman Problem
• Find shortest path from A to F
• Solve using hill climbing
A
B
C
E
F
D
distance as the crow flies
25
8
206
12
What happens now?
CS 484 – Artificial Intelligence 24
Best-First Search
• Like hill-climbing:• Picks the most likely path (based on heuristic
value) from the partially expanded tree
• Tends to find a shorter1 path than depth-first or breadth-first search, but does not guarantee to find the best path.
1 depends how shorter is defined
CS 484 – Artificial Intelligence 25
Hill Climbing Algorithm
Function hill() {queue = [];state = root_node;while (true) { if is_goal(state) return SUCCESS; else { sort(successor(state)); add_to_front_of_queue (successor(state)); }
if queue == [] return FAILURE; state = queue[0]; remove_first_item
(queue);}
}
CS 484 – Artificial Intelligence 26
Best-Search Algorithm
Function best() {queue = [];state = root_node;while (true) { if is_goal(state) return SUCCESS; else { add_to_front_of_queue (successor(state)); sort(queue); }
if queue == [] return FAILURE; state = queue[0]; remove_first_item
(queue);}
}
CS 484 – Artificial Intelligence 27
Optimal Paths
• An optimal path - shortest possible path from root to goal (i.e lowest cost)
• not necessarily at the shallowest depth, if edges have costs
• The British Museum procedure finds an optimal path by examining every possible path, and selecting the one with the least cost.
• There are more efficient ways.
CS 484 – Artificial Intelligence 28
A* Algorithms
• Uses the cost function:• f(node) = g(node) + h(node).
• g(node) is the cost of the path so far leading to the node.
• h(node) is an underestimate of how far node is from a goal state.
• f is a path-based evaluation function.• An A* algorithm expands paths from nodes that
have the lowest f value.
CS 484 – Artificial Intelligence 29
A* Algorithms (continued)
• A* algorithms are optimal:• They are guaranteed to find the shortest path• Provided h(node) is always an underestimate. (h is an
admissible heuristic).• A* methods are also optimally efficient – they
expand the fewest possible paths to find the right one.
• If h is not admissible, the method is called A, rather than A*.
CS 484 – Artificial Intelligence 30
Modified Traveling Salesman Problem
• Get from A to F using shortest path
• Solve using A*• g(n) – cost so far
• h(n) – heuristic
A
B
C
E
F
D
h(n) = distance as the crow flies
157
26 5
3 66
11
8
146
11
CS 484 – Artificial Intelligence 31
Uniform Cost Search
• Also known as branch and bound.• Like A*, but uses:
• f(node) = g(node).• g(node) is the cost of the path leading up to
node.• Optimal as long as all paths have a positive
weight
CS 484 – Artificial Intelligence 32
Greedy Search
• Like A*, but uses:• f(node) = h(node).
• Hence, always expands the node that appears to be closest to a goal, regardless of what has gone before.
• Not optimal, and not guaranteed to find a solution at all.
• Can easily be fooled into taking poor paths.
CS 484 – Artificial Intelligence 33
Real World Search Problem
• Route-finding Problem• States: represented by location and current time• Initial State: Specified by problem• Successor function: returns states resulting
from taking any scheduled flight leaving later than current time plus transit time
• Goal test: arrived at destination by prescribed time
• Path cost: monetary cost, waiting time, flight time, seat quality, time of day, etc.