A Simple Discrete-Event Simulation: Part 14

Today I modified the entry component so it creates new entities according to a supplied schedule. This can be made as complex as we’d like but let’s keep it simple for now: the input parameters are the duration of each scheduled block (in minutes) and the array of arrivals itself.

The entry object keeps a running index into the schedule array, a new value of which is read every 30 minutes. The increment method generates new entities spread even across the time span. It does this by dividing the block duration by the number of arrivals plus one, and then generating a new arrival on each increment (one arrival leads to two spans which leads to an arrival at 15 minutes, two arrivals leads to three spans which leads to arrivals at ten and twenty minutes, three arrivals leads to four spans which lead to arrivals every 7.5 minutes). No arrivals happen at the beginning or end of the schedule block.

Here’s the code for the new entry component:

And here’s the array definition and the call to create the entry component.

This works as expected, as demonstrated by the output:


360.000000 minutes

Entry component 1 generates 0 new entities at time 0
Entry component 1 generates 0 new entities at time 30
entity 2 created at time 60
Entry component 1 generates 1 new entities at time 60
entity 2 updated at time 75
entity 2 terminated at time 77
entity 3 created at time 90
entity 4 created at time 90
entity 5 created at time 90
Entry component 1 generates 3 new entities at time 90
entity 3 updated at time 97.5
entity 3 terminated at time 99.5
entity 4 updated at time 105
entity 4 terminated at time 107
entity 5 updated at time 112.5
entity 5 terminated at time 114.5
entity 6 created at time 120
entity 7 created at time 120
entity 8 created at time 120
entity 9 created at time 120
Entry component 1 generates 4 new entities at time 120
entity 6 updated at time 126
entity 6 terminated at time 128
entity 7 updated at time 132
entity 7 terminated at time 134
entity 8 updated at time 138
entity 8 terminated at time 140
entity 9 updated at time 144
entity 9 terminated at time 146
entity 10 created at time 150
entity 11 created at time 150
entity 12 created at time 150
entity 13 created at time 150
Entry component 1 generates 4 new entities at time 150
entity 10 updated at time 156
entity 10 terminated at time 158
entity 11 updated at time 162
entity 11 terminated at time 164
entity 12 updated at time 168
entity 12 terminated at time 170
entity 13 updated at time 174
entity 13 terminated at time 176
entity 14 created at time 180
entity 15 created at time 180
entity 16 created at time 180
entity 17 created at time 180
entity 18 created at time 180
Entry component 1 generates 5 new entities at time 180
entity 14 updated at time 185
entity 14 terminated at time 187
entity 15 updated at time 190
entity 15 terminated at time 192
entity 16 updated at time 195
entity 16 terminated at time 197
entity 17 updated at time 200
entity 17 terminated at time 202
entity 18 updated at time 205
entity 18 terminated at time 207
entity 19 created at time 210
entity 20 created at time 210
entity 21 created at time 210
entity 22 created at time 210
entity 23 created at time 210
entity 24 created at time 210
Entry component 1 generates 6 new entities at time 210
entity 19 updated at time 214.28571428571428
entity 19 terminated at time 216.28571428571428
entity 20 updated at time 218.57142857142858
entity 20 terminated at time 220.57142857142858
entity 21 updated at time 222.85714285714286
entity 21 terminated at time 224.85714285714286
entity 22 updated at time 227.14285714285714
entity 22 terminated at time 229.14285714285714
entity 23 updated at time 231.42857142857142
entity 23 terminated at time 233.42857142857142
entity 24 updated at time 235.71428571428572
entity 24 terminated at time 237.71428571428572
entity 25 created at time 240
entity 26 created at time 240
entity 27 created at time 240
Entry component 1 generates 3 new entities at time 240
entity 25 updated at time 247.5
entity 25 terminated at time 249.5
entity 26 updated at time 255
entity 26 terminated at time 257
entity 27 updated at time 262.5
entity 27 terminated at time 264.5
entity 28 created at time 270
entity 29 created at time 270
Entry component 1 generates 2 new entities at time 270
entity 28 updated at time 280
entity 28 terminated at time 282
entity 29 updated at time 290
entity 29 terminated at time 292
entity 30 created at time 300
Entry component 1 generates 1 new entities at time 300
entity 30 updated at time 315
entity 30 terminated at time 317
Entry component 1 generates 0 new entities at time 330
Entry component 1 terminated at time 360

Again, there are a lot of ways to make this mechanism more complicated. We could define several types of arrivals, which would involve a more complex data structure and more involved calculations. We could define different ways to distribute the arrivals over each time span (which I will discuss next week). We could have this component generate entries for the entire simulation and then use a different data structure to define how arrivals are distributed over multiple locations where the entries actually occur. Conversely, we could have a separate entry component and arrival definition for each entry location, individually. The possibilities are endless.

The main thing to note is that, depending on how it’s implemented, the entry component may be less a part of the process being modeled then it is a meta-component of the simulation. The mechanisms can and usually do end up being co-mingled.

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

Leave a Reply