{"id":1003,"date":"2016-09-26T22:08:47","date_gmt":"2016-09-27T03:08:47","guid":{"rendered":"http:\/\/rpchurchill.com\/?p=1003"},"modified":"2016-09-26T22:08:47","modified_gmt":"2016-09-27T03:08:47","slug":"a-simple-discrete-event-simulation-part-15","status":"publish","type":"post","link":"https:\/\/rpchurchill.com\/wordpress\/posts\/2016\/09\/26\/a-simple-discrete-event-simulation-part-15\/","title":{"rendered":"A Simple Discrete-Event Simulation: Part 15"},"content":{"rendered":"<p>Today I wanted to describe a few additional methods for generating arrivals over a given time span.  Last week we divided the arrivals evenly over the span without placing any at the beginning or end.  The next possibility is generating entities in order by ID and giving them random time offsets into the span.  This means that the entities will arrive in the simulation out of order by ID.  The next possibility is to randomly generate a list of offset times into the span, sort them in time order, and *then* assign them to the entities as they are generated in order by ID.  In this case the new entities arrive in order by both ID and time.<\/p>\n<p>Here&#8217;s the relevant code snippet.<\/p>\n<pre class=\"toolbar-overlay:false wrap:false height-set:true lang:default decode:true \">\r\n      this.increment = function() {  \/\/should be called at the beginning of every half-hour block\r\n        \/\/get arrival count per array index\r\n        var arrivals = scheduleArray[this.arrayIndex];\r\n        if (arrivals > 0) {\r\n\/*          \/\/distribute arrivals evenly across the time span\r\n          var increment = scheduleBlockMinutes \/ (arrivals + 1);\r\n          var arrivalBump = 0.0;\r\n          for (var i=0; i<arrivals; i++) {\r\n            arrivalBump += increment;\r\n            this.generateNewEntity(globalSimClock + arrivalBump, 2.0, globalSimClock + arrivalBump + 1.0);\r\n          }  *\/\r\n          \/\/distribute arrivals randomly across the time span\r\n\/*          for (var i=0; i<arrivals; i++) {\r\n            var arrivalBump = Math.random() * scheduleBlockMinutes;\r\n            this.generateNewEntity(globalSimClock + arrivalBump, 2.0, globalSimClock + arrivalBump + 1.0);\r\n          } *\/\r\n          \/\/distribute arrivals randomly across the time span but have them arrive in sorted order by ID\r\n          var arrivalArray = [];\r\n          for (var i=0; i<arrivals; i++) {\r\n            arrivalArray[i] = Math.random() * scheduleBlockMinutes;\r\n          } \r\n          \/\/sort the array\r\n          arrivalArray.sort(compareNumeric);\r\n          \/\/generate the arrivals          \r\n          for (var i=0; i<arrivals; i++) {\r\n            var arrivalBump = arrivalArray[i];\r\n            this.generateNewEntity(globalSimClock + arrivalBump, 2.0, globalSimClock + arrivalBump + 1.0);\r\n          }\r\n        }\r\n        this.arrayIndex++;\r\n        displayProgressText(\"Entry component \"+this.entityID+\" generates \"+arrivals+\" new entities at time \"+globalSimClock+\"<br \/>\");\r\n        if (globalSimClock + this.incrementTime >= this.endTime) {\r\n          this.nextState = \"destroy\";\r\n        }\r\n        advance(this.incrementTime);\r\n      }\r\n<\/pre>\n<p>Again, this situation can be complicated by how arrivals are generated across multiple entry components, if applicable.<\/p>\n<p>Here&#8217;s the output for the second case, where the entities are generated in order by ID but out of order by time.<br \/>\n<code><br \/>\n360.000000 minutes<\/p>\n<p>Entry component 1 generates 0 new entities at time 0<br \/>\nEntry component 1 generates 0 new entities at time 30<br \/>\nentity 2 created at time 60<br \/>\nEntry component 1 generates 1 new entities at time 60<br \/>\nentity 2 updated at time 73.99298622427338<br \/>\nentity 2 terminated at time 75.99298622427338<br \/>\nentity 3 created at time 90<br \/>\nentity 4 created at time 90<br \/>\nentity 5 created at time 90<br \/>\nEntry component 1 generates 3 new entities at time 90<br \/>\nentity 3 updated at time 90.65448947567586<br \/>\nentity 3 terminated at time 92.65448947567586<br \/>\nentity 5 updated at time 102.45876143380077<br \/>\nentity 5 terminated at time 104.45876143380077<br \/>\nentity 4 updated at time 119.38927621505289<br \/>\nentity 6 created at time 120<br \/>\nentity 7 created at time 120<br \/>\nentity 8 created at time 120<br \/>\nentity 9 created at time 120<br \/>\nEntry component 1 generates 4 new entities at time 120<br \/>\nentity 4 terminated at time 121.38927621505289<br \/>\nentity 9 updated at time 123.9335770886767<br \/>\nentity 6 updated at time 125.66906431405235<br \/>\nentity 9 terminated at time 125.9335770886767<br \/>\nentity 6 terminated at time 127.66906431405235<br \/>\nentity 8 updated at time 130.20640371951362<br \/>\nentity 8 terminated at time 132.20640371951362<br \/>\nentity 7 updated at time 148.20505933816443<br \/>\n...<br \/>\nEntry component 1 generates 6 new entities at time 210<br \/>\nentity 22 updated at time 210.33055244386358<br \/>\nentity 22 terminated at time 212.33055244386358<br \/>\nentity 23 updated at time 218.17391645202767<br \/>\nentity 20 updated at time 220.06975372967392<br \/>\nentity 23 terminated at time 220.17391645202767<br \/>\nentity 20 terminated at time 222.06975372967392<br \/>\nentity 21 updated at time 226.5677482735777<br \/>\nentity 24 updated at time 226.65044172930732<br \/>\nentity 19 updated at time 228.05749230023298<br \/>\nentity 21 terminated at time 228.5677482735777<br \/>\nentity 24 terminated at time 228.65044172930732<br \/>\nentity 19 terminated at time 230.05749230023298<br \/>\n...<br \/>\nEntry component 1 generates 0 new entities at time 330<br \/>\nEntry component 1 terminated at time 360<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today I wanted to describe a few additional methods for generating arrivals over a given time span. Last week we divided the arrivals evenly over the span without placing any at the beginning or end. The next possibility is generating &hellip; <a href=\"https:\/\/rpchurchill.com\/wordpress\/posts\/2016\/09\/26\/a-simple-discrete-event-simulation-part-15\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[60],"tags":[121,49],"_links":{"self":[{"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/posts\/1003"}],"collection":[{"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/comments?post=1003"}],"version-history":[{"count":1,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/posts\/1003\/revisions"}],"predecessor-version":[{"id":1004,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/posts\/1003\/revisions\/1004"}],"wp:attachment":[{"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1003"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/categories?post=1003"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/tags?post=1003"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}