-
Recent Posts
Recent Comments
- R.P. Churchill on TWSL Series 07: Discovery and Data Collection
- R.P. Churchill on A Simulationist’s Framework for Business Analysis: Round Two
- LN on A Simulationist’s Framework for Business Analysis: Round Two
- R.P. Churchill on Starting to Learn About the Java Memory Model
- R.P. Churchill on Multidimensional Arrays in Javascript
Categories
Meta
Monthly Archives: September 2016
A Simple Discrete-Event Simulation: Part 8
Today I automated the generation of entity IDs. First we create a basic counter.
1 2 3 4 |
var globalIDCounter = 0; function getNewID() { return ++globalIDCounter; } |
Then we change the entity declarations to remove the explicit assignment of IDs as we have been doing.
1 2 |
function entity1(initialTime,incrementTime,endTime) { this.entityID = getNewID(); |
That was pretty mindless, so let’s … Continue reading
A Simple Discrete-Event Simulation: Part 7
Today we’ll do some more streamlining. We’ll start by adding a new function to the futureEventsQueue object.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
this.newItem = function(time,entity) { //create futureEventItem var feqItem = new futureEventItem(time,"absolute",entity); this.insertTime = feqItem.getActivationTime(); globalInsertTime = this.insertTime; if (this.feqSize == 0) { this.feq[0] = feqItem; this.feqSize++; console.log("Array size: "+this.feq.length); } else { //find index of feq item to insert before var insertIndex = this.feq.findIndex(this.findLaterTime); //insert the element if (insertIndex < 0) { insertIndex = this.feq.length; } this.feq.splice(insertIndex,0,feqItem); this.feqSize++; console.log("Array size: "+this.feq.length); } }; |
Then, instead of having to specify the “absolute” (vs. “advance”) flag in the initialization of a new entity object, we know we’ll … Continue reading
A Simple Discrete-Event Simulation: Part 6
Now that I’m sure the basics are working the way I’d like I want to see if I can streamline things some more. The first thing to do is recognize that the next item being pulled off the future events … Continue reading
A Simple Discrete-Event Simulation: Part 5
Adding a second entity works correctly.
1 2 3 |
var entityA = new entity(1,11.0,10.0,100.0); var entityB = new entity(2,13.0,13.0,100.0); |
104 minutes entity 1 created at time 0 entity 2 created at time 0 entity 1 updated at time 11 entity 2 updated at time 13 entity 1 updated at time 21 entity … Continue reading
A Simple Discrete-Event Simulation: Part 4
Here is code that actually runs. It creates a single entity, then updates it in a loop until the ending time is exceeded. The next steps will be to see how it works with multiple entities of the same kind … Continue reading