Top Banner
26

P ROBLEM Write an algorithm that calculates the most efficient route between two points as quickly as possible.

Jan 02, 2016

Download

Documents

Malcolm Griffin
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: P ROBLEM Write an algorithm that calculates the most efficient route between two points as quickly as possible.
Page 2: P ROBLEM Write an algorithm that calculates the most efficient route between two points as quickly as possible.

PROBLEM

Write an algorithm that calculates the most efficient route

between two points as quickly as possible.

Page 3: P ROBLEM Write an algorithm that calculates the most efficient route between two points as quickly as possible.

INTRODUCTION TO ALGORITHMS

SEARCHING & FINDING

Improving search techniques

Simon Ellis

24th March, 2014

Page 4: P ROBLEM Write an algorithm that calculates the most efficient route between two points as quickly as possible.

Search techniques

Breadth-first search (BFS)

Depth-first search (DFS)

Tree spanning

Greedy best-first search

Dijkstra’s algorithm

Page 5: P ROBLEM Write an algorithm that calculates the most efficient route between two points as quickly as possible.

Improving search performance

Guided search Uses an heuristic to improve performance

Guaranteed to find a path if one exists Like other searches … but will always return the optimum path with

admissible heuristic

Page 6: P ROBLEM Write an algorithm that calculates the most efficient route between two points as quickly as possible.

Heuristics

An heuristic is an experience-based technique used for problem-solving, learning and discovery

Solution is not guaranteed to be optimal

Speeds up process of finding a satisfactory solution using shortcuts

Could be called ‘computational best-guesswork’

Page 7: P ROBLEM Write an algorithm that calculates the most efficient route between two points as quickly as possible.

Heuristics

Strategies using readily accessible, if not always strictly applicable, information to control and influence problem solving

Page 8: P ROBLEM Write an algorithm that calculates the most efficient route between two points as quickly as possible.

Heuristics

Common heuristics in humans include Trial and error Drawing a picture Writing out an algorithm Assuming you have a solution and attempting to

derive from that (‘working backwards’) Talking to someone about a problem Obtaining a concrete example of an abstract problem Trying for a general solution before the specific one

(‘inventor’s paradox’) Putting a problem aside and coming back to it later Getting someone else to do it for you

Page 9: P ROBLEM Write an algorithm that calculates the most efficient route between two points as quickly as possible.

Admissibility

An heuristic is admissible if and only if it is optimistic

An ‘optimistic’ heuristic will never over-estimate the remaining cost to the goal from any given node n

Assume n is a node h is an heuristic h(n) is the heuristic cost C(n) is the actual cost

Page 10: P ROBLEM Write an algorithm that calculates the most efficient route between two points as quickly as possible.

Admissibility

An admissible heuristic can be derived from Induction and inductive learning Information from databases with solutions to

subproblems Relaxed versions of the problem

Page 11: P ROBLEM Write an algorithm that calculates the most efficient route between two points as quickly as possible.

A* basics

Best-first search

Finds a least-cost path from initial node to goal node

Uses a knowledge-plus-heuristic cost to determine search order

Complete and admissible Will always find a solution if it exists Guaranteed to find the shortest path between nodes

Page 12: P ROBLEM Write an algorithm that calculates the most efficient route between two points as quickly as possible.

A* basics

Maintains 2 pieces of information Open list

Contains candidate nodes which may lie along the path

Closed list Contains nodes which have the lowest path score so far

Nodes move between lists based on current information

Page 13: P ROBLEM Write an algorithm that calculates the most efficient route between two points as quickly as possible.

A* basics

Uses a knowledge-plus-heuristic cost

Knowledge Movement cost to reach node nk from initial node n0 G

Heuristic cost to reach target node nt from node nk H

Lowest total path cost to node nk is given by F = G

+ H

Best path is given by sequence of nodes with lowest F

Page 14: P ROBLEM Write an algorithm that calculates the most efficient route between two points as quickly as possible.

A* algorithm 1

1. Add initial node n0 to open list

2. Do

1. Find the node with the lowest F cost on the open list, nc

2. Remove nc from the open list and add it to the closed list

3. For all nodes nk connected to nc

1. If node is on the closed list or not traversable (e.g. a wall): ignore it

2. If node is not on the open list: add it, record costs, make nc its parent

3. If node is already on the open list: check to see if this path to nc is

better (i.e. a lower G score); if so, change parent of nc to nk and

recalculate its G and F scores (may require resorting of open list)

4. Until

1. If nt is added to the closed list, path has been found

2. If open list is empty, there is no path

Page 15: P ROBLEM Write an algorithm that calculates the most efficient route between two points as quickly as possible.

A* algorithm 2

3. Derive path if one exists

1. Begin at target node nt

2. Follow chain of parent nodes back to node n0

3. Reverse order of nodes to derive path

Page 16: P ROBLEM Write an algorithm that calculates the most efficient route between two points as quickly as possible.

A* heuristics

There are some ‘standard heuristics’ G

For square grids, often the ‘Manhattan distance’• Orthogonal movement costs 10 or 1

• Diagonal movement costs 14 or 1.4

For other graphs, the edge cost is generally used

H Straight-line distance often used

Numerous other heuristics are possible (Manhattan, cross-product…)

Page 17: P ROBLEM Write an algorithm that calculates the most efficient route between two points as quickly as possible.

A* heuristics

Scales must be the same for both heuristics!

What happens if scales are not the same? Firstly, heuristic is probably inadmissible

(overestimates cost) Won’t find the best path Might take longer to run

In short, will not find the best path in the best time

Page 18: P ROBLEM Write an algorithm that calculates the most efficient route between two points as quickly as possible.

Example

Page 19: P ROBLEM Write an algorithm that calculates the most efficient route between two points as quickly as possible.

Example

Page 20: P ROBLEM Write an algorithm that calculates the most efficient route between two points as quickly as possible.

Example

Page 21: P ROBLEM Write an algorithm that calculates the most efficient route between two points as quickly as possible.

Example

Page 22: P ROBLEM Write an algorithm that calculates the most efficient route between two points as quickly as possible.

Example

Page 23: P ROBLEM Write an algorithm that calculates the most efficient route between two points as quickly as possible.

Example

Page 24: P ROBLEM Write an algorithm that calculates the most efficient route between two points as quickly as possible.

A* performance

Speed: O(bd)

Memory requirement: O(bd)

… why? Same as Dijkstra’s algorithm

Dijkstra’s algorithm is effectively A* with H = 0 for all nodes

Page 25: P ROBLEM Write an algorithm that calculates the most efficient route between two points as quickly as possible.

ANY QUESTIONS?