Event Lists Refs: Sections 2.2 and 2.8 in Law, Section 5.3 in - - PowerPoint PPT Presentation

event lists
SMART_READER_LITE
LIVE PREVIEW

Event Lists Refs: Sections 2.2 and 2.8 in Law, Section 5.3 in - - PowerPoint PPT Presentation

Event Lists Refs: Sections 2.2 and 2.8 in Law, Section 5.3 in Leemis and Park Peter J. Haas CS 590M: Simulation Spring Semester 2020 1 / 9 Event Lists Overview Linked Lists Heaps Hybrid Data Structures 2 / 9 Event Lists (aka Pending


slide-1
SLIDE 1

Event Lists

Refs: Sections 2.2 and 2.8 in Law, Section 5.3 in Leemis and Park Peter J. Haas CS 590M: Simulation Spring Semester 2020

1 / 9

slide-2
SLIDE 2

Event Lists Overview Linked Lists Heaps Hybrid Data Structures

2 / 9

slide-3
SLIDE 3

Event Lists (aka Pending Event Sets)

Fetch-next, insert, and cancel operations

I Fundamental operations in discrete-event simulations

(up to 40% of sim time)

I So far we have used clock-reading vectors I For M events, it takes O(M) time to get next event I Unsuitable for large-scale simulation

Alternative: event lists

I For GSMP’s with unit speeds I Idea: Maintain list of (event type, event time) pairs

I event time = (absolute) time when event is scheduled to occur

I Challenge: support operations efficiently

(priority queue with removals)

3 / 9

slide-4
SLIDE 4

Linked Lists

Goal: Maintain events in sorted order

I Singly-linked lists 20.3 23.7 34.0 head tail

I fetch-next is O(1), insert and cancel are O(M)

I Doubly-linked lists 20.3 23.7 34.0 head tail

4 / 9

÷

.

slide-5
SLIDE 5

Linked Lists, Continued

I Indexed doubly-linked lists 20.3 23.7 23.7 34.0 head tail

I Faster lookup I Need to maintain median element I Cost outweighs benefit for more than one index 5 / 9

slide-6
SLIDE 6

Implicit Binary Heaps

Binary tree that maintains min-heap property

I Parent has smaller value than

children

I Can store efficiently as an array I Fetch-next is O(1) plus an

O(log M) update

6 / 9

1.6 3.1 4.2 2.9 3.7 2.5 2.3 3.1 4.2 2.9 3.7 2.5 2.3 3.1 4.2 2.9 3.7 2.5 2.3

slide-7
SLIDE 7

Heaps, Continued

I Insert is O(log M) I Cancellation is O(M) search + O(log M) update I Python solution for O(1) cancellation

I Use heapq to implement heap I Use a dict for O(1) find I Mark event as ”canceled ”and I Ignore cancelled events upon fetch I OK if not too many cancellations I See code on website 7 / 9

4.2 2.1 2.9 3.7 2.5 2.3 3.1 2.1 4.2 2.9 3.7 2.5 2.3 3.1 2.1 4.2 2.9 3.7 2.5 2.3 3.1

2.1 4.2 2.9 3.7 2.5 2.3 3.1 "e2" "e1" "e4" "e3" "e5" "e6" "e7"

slide-8
SLIDE 8

Hybrid Data Structures

Bucket System

I Event time “hashes” to a bucket I Recycle buckets

when they become empty Henriksen’s algorithm

I Used in many

early commercial systems

I Combines binary search tree

with doubly-linked list

I Can have bad worst-case behavior

8 / 9

1.3 7.2 5.8 12.6 19.3 17.7 24.0 28.2 87.2 230.1

1-10 10-20 20-30 80-90

  • verflow

...

slide-9
SLIDE 9

Hybrid Data Structures, Continued

Lazy Queue [Ronngren et al. 1991]

I Three parts:

I Near Future (NF): a sorted linked list I Far Future (FF): an unsorted bucket system I Very Far Future (VFF): an unsorted linked list

I Sorting only happens when FF

bucket is moved to NF

I Occasional adaptive resizing of #

and length of buckets

I Dominates most other event list

schemes for > 50 events

9 / 9

1-2 0-1 2-3 3-4 4-5 5-6 > 6 NF FF VFF

sorted unsorted