CPSC 531: System Modeling and Simulation

Slides:



Advertisements
Similar presentations
COL 106 Shweta Agrawal and Amit Kumar
Advertisements

Binary Heaps CSE 373 Data Structures Lecture 11. 2/5/03Binary Heaps - Lecture 112 Readings Reading ›Sections
Version TCSS 342, Winter 2006 Lecture Notes Priority Queues Heaps.
BST Data Structure A BST node contains: A BST contains
Source: Muangsin / Weiss1 Priority Queue (Heap) A kind of queue Dequeue gets element with the highest priority Priority is based on a comparable value.
PQ, binary heaps G.Kamberova, Algorithms Priority Queue ADT Binary Heaps Gerda Kamberova Department of Computer Science Hofstra University.
Important Problem Types and Fundamental Data Structures
ADT Table and Heap Ellen Walker CPSC 201 Data Structures Hiram College.
Outline Binary Trees Binary Search Tree Treaps. Binary Trees The empty set (null) is a binary tree A single node is a binary tree A node has a left child.
WEEK 3 Leftist Heaps CE222 Dr. Senem Kumova Metin CE222_Dr. Senem Kumova Metin.
Algorithms and data structures Protected by
Priority Queues and Heaps. October 2004John Edgar2  A queue should implement at least the first two of these operations:  insert – insert item at the.
Advanced Data Structure By Kayman 21 Jan Outline Review of some data structures Array Linked List Sorted Array New stuff 3 of the most important.
CompSci 100e 8.1 Scoreboard l What else might we want to do with a data structure? AlgorithmInsertionDeletionSearch Unsorted Vector/array Sorted vector/array.
HeapSort 25 March HeapSort Heaps or priority queues provide a means of sorting: 1.Construct a heap, 2.Add each item to it (maintaining the heap.
CS6045: Advanced Algorithms Data Structures. Dynamic Sets Next few lectures will focus on data structures rather than straight algorithms In particular,
CSE373: Data Structures & Algorithms Lecture 8: AVL Trees and Priority Queues Linda Shapiro Spring 2016.
FALL 2005CENG 213 Data Structures1 Review. FALL 2005CENG 213 Data Structures2 Collection of items Problems that must manage data by value. Some important.
Tree-Structured Indexes. Introduction As for any index, 3 alternatives for data entries k*: – Data record with key value k –  Choice is orthogonal to.
Priority Queues and Heaps. John Edgar  Define the ADT priority queue  Define the partially ordered property  Define a heap  Implement a heap using.
Priority Queues and Heaps Tom Przybylinski. Maps ● We have (key,value) pairs, called entries ● We want to store and find/remove arbitrary entries (random.
CSE373: Data Structures & Algorithms Priority Queues
CSC317 Selection problem q p r Randomized‐Select(A,p,r,i)
CSCE 3110 Data Structures & Algorithm Analysis
Heaps (8.3) CSE 2011 Winter May 2018.
Top 50 Data Structures Interview Questions
CS522 Advanced database Systems
CS522 Advanced database Systems
Indexing ? Why ? Need to locate the actual records on disk without having to read the entire table into memory.
Lecture 15 AVL Trees Slides modified from © 2010 Goodrich, Tamassia & by Prof. Naveen Garg’s Lectures.
Binary Search Tree Chapter 10.
Programming Abstractions
Lecture 22 Binary Search Trees Chapter 10 of textbook
Hashing Exercises.
Source: Muangsin / Weiss
CS Anya E. Vostinar Grinnell College
Cse 373 April 26th – Exam Review.
External Methods Chapter 15 (continued)
ITEC 2620M Introduction to Data Structures
Tree data structure.
CMPS 3130/6130 Computational Geometry Spring 2017
Binary Search Trees Why this is a useful data structure. Terminology
Heap Chapter 9 Objectives Upon completion you will be able to:
ECET 370 HELPS Education Your Life-- ecet370helps.com.
Map interface Empty() - return true if the map is empty; else return false Size() - return the number of elements in the map Find(key) - if there is an.
Chapter 1.
CS222P: Principles of Data Management Notes #6 Index Overview and ISAM Tree Index Instructor: Chen Li.
Part-D1 Priority Queues
Tree data structure.
Ch 6: Heapsort Ming-Te Chi
B-Tree Insertions, Intro to Heaps
CSE332: Data Abstractions Lecture 4: Priority Queues
ITEC 2620M Introduction to Data Structures
Tree Representation Heap.
B+Trees The slides for this text are organized into chapters. This lecture covers Chapter 9. Chapter 1: Introduction to Database Systems Chapter 2: The.
A Robust Data Structure
CS6045: Advanced Algorithms
Binary Trees, Binary Search Trees
CS222/CS122C: Principles of Data Management Notes #6 Index Overview and ISAM Tree Index Instructor: Chen Li.
Definition Applications Implementations Heap Comparison
Chapter 4: Simulation Designs
Priority Queues CSE 373 Data Structures.
Important Problem Types and Fundamental Data Structures
Tree-Structured Indexes
Data Structures for Shaping and Scheduling
CO4301 – Advanced Games Development Week 12 Using Trees
Binary Trees, Binary Search Trees
CS222/CS122C: Principles of Data Management UCI, Fall 2018 Notes #05 Index Overview and ISAM Tree Index Instructor: Chen Li.
CS222/CS122C: Principles of Data Management UCI, Fall 2018 Notes #06 B+ trees Instructor: Chen Li.
CS222P: Principles of Data Management UCI, Fall Notes #06 B+ trees
Presentation transcript:

CPSC 531: System Modeling and Simulation Carey Williamson Department of Computer Science University of Calgary Fall 2017

Event List Management Event List: Data structure containing the events that are scheduled to occur in the future in the simulation Also contains meta-data associated with events Important to understand the requirements of an event list, and its dynamics, in order to manage events efficiently within a simulation In some simulations, event list management may dominate the simulation execution time!

Two critical operations in event list management: Basic Questions Several important questions to consider when contemplating the implementation of an event list: Is the maximum number of events fixed or variable? Is the event list management technique intended for one specific simulation model, or general purpose in nature? Two critical operations in event list management: Insertion (also called enqueue) for scheduling an event Deletion (also called dequeue) for removing an event Often a tradeoff between these two operations!

Criteria for Event List Management Speed: Data structure and algorithms used for insertion and deletion should have minimal execution time Efficient searching is the key (implies sorting, pointers, etc) Robustness: Should perform well for a wide range of scenarios Might exploit knowledge of specific simulation model Adaptability: Event list management should be “parameter free” Search time depends on length of list and time distribution of events

Think time: uniformly distributed Example: ttr.c Example: time-sharing computer system model called the Think-Type-Receive model (or modified version called Think-Tweet-Read in twit.c) Think time: uniformly distributed Typing time: uniformly distributed num of chars Receiving time: uniformly distribed num of chars Notes: Users spend most of the time thinking and/or typing Most of the events in the system are transmitting chars

Example: ttr.c Array implementation (unsorted) Linked list implementation (sorted, search from head) Linked list approach is 65-80% faster! Num Users N Number of Events Avg Search 5 9,902 10 20,678 50 101,669 100 201,949 Num Users N Number of Events Avg Search 5 9,902 1.72 10 20,678 2.73 50 101,669 10.45 100 201,949 19.81

Many Implementation Choices Possible Array (sorted or unsorted) Suitable for small simulations with < 10 events on list Linked list Singly-linked or doubly-linked Multiple linked lists Uses k lists, each of which has a subset of the events Could dynamically adjust k to manage average length Binary tree Heap Calendar queue

Binary Tree A recursive data structure, where each node has at most two children Tree is ordered, with smaller values to the left of the root, and larger values to the right of the root Most imminent event would be the leftmost node Average case for insertion and deletion is O(log n) Worst case is O(n) for n events (linked list) Usually enforces a full or a complete binary tree More elaborate options include a balanced binary tree or a splay tree

Binary Tree Example 0.001 ID Time 0.001 1 2.551 2 8.041 3 6.748 4 0.001 1 2.551 2 8.041 3 6.748 4 9.039 5 5.691 6 5.449 7 1.940 8 7.887 9 2.305 2.551 8.041 1.940 2.305 6.748 9.039 5.691 7.887 5.449

Complete Binary Tree Example ID Time 0.001 1 2.551 2 8.041 3 6.748 4 9.039 5 5.691 6 5.449 7 1.940 8 7.887 9 2.305 6.748 2.551 8.041 5.691 7.887 9.039 1.940 0.001 2.305 5.449

Heap A recursive data structure, in which the root node has the lowest event time, and subtrees are heaps Most imminent event would be the root node Average case for deletion is O(1) Average case for insertion is O(log n) Usually enforces a complete binary tree model Need to maintain heap property upon each deletion and/or insertion More elaborate options can balance the subtrees

Heap Example ID Time 0.001 1 2.551 2 8.041 3 6.748 4 9.039 5 5.691 6 5.449 7 1.940 8 7.887 9 2.305 0.001 1.940 5.449 2.305 8.041 5.691 2.551 6.748 7.887 9.039

Use multiple data structures, either alternately or in parallel Hybrid Schemes Use multiple data structures, either alternately or in parallel Example 1: Linked list and heap Use linked list when there are few events on event list Use heap when there are lots of events on event list Dynamically switch between the two (copying overhead) Example 2: Henriksen’s algorithm Linked list contains all events on event list Binary tree contains subset of events and times Tree search indexes into doubly-linked list Bounds maximum search distance for insertions (avg case)

Calendar Queue A famous event list data structure [Brown 1988] Useful when future events have widely varying times Analogy: day planner (day/week/month/year) Multiple linked lists, with logarithmic time spacings Near future events are on the first (closest) list Distant future events are on the last (farthest) list Hashing operation determines which list to use Avoids cluttering any event list with too many events Avg case performance is O(1) for insertion/deletion

Summary In complex simulation models, the number of events on the event list might be unknown, and very large In such cases, an efficient event list implementation is important for minimizing simulation run time Event list coordination is also especially important in parallel/distributed simulation models, because it can become a central bottleneck (i.e., contention) We won’t encounter these issues in CPSC 531, but it is good to know when doing (larger) simulations in the real working world!