A Simple Discrete-Event Simulation: Part 2

Today I’ve added the ability to retrieve the first item from the future events queue, which is the next item to process and that with the lowest activation time. In this case I just update the item’s time when it’s retrieved, then insert it back into the future events queue wherever it belongs. In the example it goes to the end of the queue with a time of 55.

Note that I’ve updated that state values, though I haven’t defined how they’re going to work yet.

I added an update function to the futureEventItem object. I added the functions getFirstItem and insertExistingItem to the futureEventsQueue object. Finally, I added some calls to exercise the new capabilities down at the bottom.

The console output again indicates that things are working as expected.

Number of events in queue: 0
Array size: 1
reportItemInfo: element: [object Object] index: 0 arr: [object Object]
Time: 40 ID: 333 Prev: prev1 Next: next1
Number of events in queue: 1
Array size: 2
reportItemInfo: element: [object Object] index: 0 arr: [object Object],[object Object]
Time: 30 ID: 444 Prev: prev2 Next: next2
reportItemInfo: element: [object Object] index: 1 arr: [object Object],[object Object]
Time: 40 ID: 333 Prev: prev1 Next: next1
Number of events in queue: 2
Array size: 3
reportItemInfo: element: [object Object] index: 0 arr: [object Object],[object Object],[object Object]
Time: 30 ID: 444 Prev: prev2 Next: next2
reportItemInfo: element: [object Object] index: 1 arr: [object Object],[object Object],[object Object]
Time: 40 ID: 333 Prev: prev1 Next: next1
reportItemInfo: element: [object Object] index: 2 arr: [object Object],[object Object],[object Object]
Time: 50 ID: 555 Prev: prev3 Next: next3
Number of events in queue: 3
reportItemInfo: element: [object Object] index: 0 arr: [object Object],[object Object]
Time: 40 ID: 333 Prev: prev1 Next: next1
reportItemInfo: element: [object Object] index: 1 arr: [object Object],[object Object]
Time: 50 ID: 555 Prev: prev3 Next: next3
Number of events in queue: 2
Array size: 3
reportItemInfo: element: [object Object] index: 0 arr: [object Object],[object Object],[object Object]
Time: 40 ID: 333 Prev: prev1 Next: next1
reportItemInfo: element: [object Object] index: 1 arr: [object Object],[object Object],[object Object]
Time: 50 ID: 555 Prev: prev3 Next: next3
reportItemInfo: element: [object Object] index: 2 arr: [object Object],[object Object],[object Object]
Time: 55 ID: 444 Prev: prev1a Next: next1a
Number of events in queue: 3

This entry was posted in Simulation and tagged , . Bookmark the permalink.

Leave a Reply