1 Finding Shortest Paths with A* Search A* search operates similarly to Dijkstra’s algorithm, but extends the cost function to include an estimated distance.

Slides:



Advertisements
Similar presentations
Stacks, Queues, and Linked Lists
Advertisements

Chapter 3 – Lists A list is just what the name implies, a finite, ordered sequence of items. Order indicates each item has a position. A list of size 0.
SEG4110 – Advanced Software Design and Reengineering TOPIC J C++ Standard Template Library.
CSE 390B: Graph Algorithms Based on CSE 373 slides by Jessica Miller, Ruth Anderson 1.
Chapter 6: Priority Queues (Heaps) Priority Queue ADT Heap Implementation CS 340 Page 100 Heap Applications Leftist Heaps.
COL 106 Shweta Agrawal and Amit Kumar
C++ Templates. What is a template? Templates are type-generic versions of functions and/or classes Template functions and template classes can be used.
Heaps1 Part-D2 Heaps Heaps2 Recall Priority Queue ADT (§ 7.1.3) A priority queue stores a collection of entries Each entry is a pair (key, value)
AVL Trees1 Part-F2 AVL Trees v z. AVL Trees2 AVL Tree Definition (§ 9.2) AVL trees are balanced. An AVL Tree is a binary search tree such that.
Foundation of Computing Systems Lecture 2 Linked Lists.
Project 3, Standard Template Library (STL) Bryce Boe 2013/11/25 CS24, Fall 2013.
CSE 380 – Computer Game Programming Pathfinding AI
CSCI 3160 Design and Analysis of Algorithms Tutorial 2 Chengyu Lin.
Informed Search (no corresponding text chapter). Recall: Wanted " An algorithm and associated data structure(s) that can: 1) Solve an arbitrary 8-puzzle.
Heaps & Priority Queues Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
Dr. Andrew Wallace PhD BEng(hons) EurIng
1 Stack Data : a collection of homogeneous elements arranged in a sequence. Only the first element may be accessed Main Operations: Push : insert an element.
Important Problem Types and Fundamental Data Structures
1 Hash Tables  a hash table is an array of size Tsize  has index positions 0.. Tsize-1  two types of hash tables  open hash table  array element type.
Review C++ exception handling mechanism Try-throw-catch block How does it work What is exception specification? What if a exception is not caught?
9/17/20151 Chapter 12 - Heaps. 9/17/20152 Introduction ► Heaps are largely about priority queues. ► They are an alternative data structure to implementing.
Data Structures Using C++ 2E
DATA STRUCTURES AND ALGORITHMS Lecture Notes 12 Prepared by İnanç TAHRALI.
PRESENTED BY: RAJKRISHNADEEPAK.VUYYURU SWAMYCHANDAN.DONDAPATI VINESHKUMARREDDY.LANKA RAJSEKHARTIRUMALA KANDURI ALAN.
CS 46B: Introduction to Data Structures July 9 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak
Generic Programming Using the C++ Standard Template Library.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Standard Template Library (STL)
1 Heaps and Priority Queues Starring: Min Heap Co-Starring: Max Heap.
C++ STL CSCI 3110.
Topic 24 Heaps "You think you know when you can learn, are more sure when you can write even more when you can teach, but certain when you can program."
Priority Queue. Priority Queues Queue (FIFO). Priority queue. Deletion from a priority queue is determined by the element priority. Two kinds of priority.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
CS 206 Introduction to Computer Science II 11 / 16 / 2009 Instructor: Michael Eckmann.
Standard Template Library The Standard Template Library was recently added to standard C++. –The STL contains generic template classes. –The STL permits.
Introduction to the Standard Template Library (STL) A container class holds a number of similar objects. Examples: –Vector –List –Stack –Queue –Set –Map.
1 Heaps and Priority Queues v2 Starring: Min Heap Co-Starring: Max Heap.
Hash Table March COP 3502, UCF 1. Outline Hash Table: – Motivation – Direct Access Table – Hash Table Solutions for Collision Problem: – Open.
The ADT Table The ADT table, or dictionary Uses a search key to identify its items Its items are records that contain several pieces of data 2 Figure.
Lecture 7 : Intro. to STL (Standard Template Library)
Computer Science and Software Engineering University of Wisconsin - Platteville 11.Standard Template Library Yan Shi CS/SE 2630 Lecture Notes.
Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record.
Data Structures for Midterm 2. C++ Data Structure Runtimes.
PRIORITY QUEUES AND HEAPS Slides of Ken Birman, Cornell University.
FALL 2005CENG 213 Data Structures1 Priority Queues (Heaps) Reference: Chapter 7.
Week 14 - Monday.  What did we talk about last time?  Heaps  Priority queues  Heapsort.
Introduction The STL is a complex piece of software engineering that uses some of C++'s most sophisticated features STL provides an incredible amount.
C++ Review STL CONTAINERS.
CSCI 383 Object-Oriented Programming & Design Lecture 25 Martin van Bommel.
Data Structures David Kauchak cs302 Spring Data Structures What is a data structure? Way of storing data that facilitates particular operations.
Collection types CS Chakrabarti Motivation  Thus far the only collection types we have used are vector and matrix  Problem #1: given an input.
Honors Track: Competitive Programming & Problem Solving Finding your way with A*-algorithm Patrick Shaw.
Unit VI.  C++ templates are a powerful mechanism for code reuse, as they enable the programmer to write code (classes as well as functions) that behaves.
1 The Standard Template Library The STL is a collection of Container classes These are class templates for containers. A container is an object that stores.
CSE373: Data Structures & Algorithms
Set Collection A Bag is a general collection class that implements the Collection interface. A Set is a collection that resembles a Bag with the provision.
Standard Template Library (STL)
- Alan Perlis Heaps "You think you know when you can learn,
- Alan Perlis Topic 24 Heaps "You think you know when you can learn,
Recitation Outline C++ STL associative containers Examples
Dynamic Sets (III, Introduction)
Priority Queues & Heaps
CSC 380: Design and Analysis of Algorithms
Standard Template Library
Important Problem Types and Fundamental Data Structures
Standard Template Library
A dictionary lookup mechanism
Presentation transcript:

1 Finding Shortest Paths with A* Search A* search operates similarly to Dijkstra’s algorithm, but extends the cost function to include an estimated distance from the current node to the target Expands only the most promising nodes; its best-first search strategy eliminates a large portion of the solution space A* search (exploring 6 nodes) Dijkstra‘s algorithm (exploring 31 nodes) O O O O O 6 O s s t t s Source t O Target Obstacle

Intro to STL - MAP map[key] = value – Each key has to be unique. (Same keys take the same entry) – The keys are sorted in ascending order Example – #include – map myMap; – point p1; p1.x = 0; p1.y = 1; – myMap[p1] = 0.1; //insert an element into the map Pros and Cons – Quick direct access of a single element. Fast insertion and deletion. – Map follows a strict ordering in storing elements (not flexible) Multimap (similar to map) – Each key doesn’t have to be unique – Access to a key will return an “equal range” (all values with the same key) – Multimap also follows a strict ordering (not flexible)

Intro to STL - SET Associative container like map – Each element stored in a set is unique – Elements are stored in ascending order – Fast Insertion and deletion, but relatively slow element access Example – #include – set mySet; – point p1; p1.x = 0; p1.y = 1; – mySet.insert(p1); //insert an element into the set Common usage – For duplicated elements removal – Quickly sort a batch of data on the fly (sorting while storing) – Merge two sets of data

Intro to STL - VECTOR Essentially is an array – Stores element serially in the memory – Can dynamically grow thus has safer and more convenient memory management (compared to C arrays) Example – #include – vector myVec; – point p1; p1.x = 0; p1.y = 1; – myVec.push_back(p1); //push an element into the vector Pros and Cons – Quick access of elements – The order of storing the elements is completely user defined (flexible) – Search, insertion, deletion not as fast as map or set (O(n) versus O(logn))

Intro to STL - QUEUE FIFO queue – Mostly used for BFS (such as for Maze Routing) – Only the first or the last element can be accessed – Access order decided by the order that the elements are pushed Example – #include – queue myQ; – point p1; p1.x = 0; p1.y = 1; – myQ.push(p1); //push an element into the queue Priority queue (C++ STL implementation) – Not suitable for routing because the elements are stored in descending order (the top element has the maximum value) – The default container to realize a priority queue is by using “vector” (will show how to do it soon!)

Integration in Your Code Migrating a C/C++ code to STL – Array  Vector – Linked list  STL list – …  What to change – Compiler: gcc  g++ – Add the following lines to your header files: #include … other STL containers used #include  #include … Add “using namespace std”

Pseudo-code From handout

Data structure for A*: Priority Queue Priority queue implemented using STL as a vector vector > PQ – Defines PQ with each element inside PQ made of pair, where “double” is used to store f[point] (score of vertex) How to implement enqueue of the priority queue? – Need to score elements in ascending order of the score – Note there can be cases when multiple elements in the PQ having the same score » Here, newly enqueued points should be stored on top of the older ones if they have smaller or equal f values for(it_PQ = PQ.begin(); it_PQ != PQ.end(); it_PQ++){ if(f[point] <= (*it_PQ).first){ PQ.insert(it_PQ, make_pair(f[point],point)); break; } } if(it_PQ == PQ.end()){ PQ.insert(it_PQ, make_pair(f[point], point)); }

Data structure for A*: Priority Queue Dequeue Erasing an element from the queue – For example erasing from the top : PQ.erase(PQ.begin()); How to extract min?  Based on the way we maintain the PQ as shown in the previous slide, just extract the top element, or the front element Min = PQ.front();

Data structure for A*: Strong Parents for Retracing Paths map > RP – RP[current_pnt] = – Parent point and the d values are always updated together – Note that d[current_pnt] is also used in the computation of f[current_pnt] Path retracing – Starting from the ending point, we can iteratively retrace the parent point until we reach the beginning point. vector path; point cur_pnt = end_pnt; while(cur_pnt != beg_pnt){ point temp = RP[cur_pnt].first; path.push_back(temp); cur_pnt = temp;}