{"id":961,"date":"2016-09-08T02:00:05","date_gmt":"2016-09-08T07:00:05","guid":{"rendered":"http:\/\/rpchurchill.com\/?p=961"},"modified":"2016-09-13T12:08:32","modified_gmt":"2016-09-13T17:08:32","slug":"a-simple-discrete-event-simulation-part-7","status":"publish","type":"post","link":"https:\/\/rpchurchill.com\/wordpress\/posts\/2016\/09\/08\/a-simple-discrete-event-simulation-part-7\/","title":{"rendered":"A Simple Discrete-Event Simulation: Part 7"},"content":{"rendered":"<p>Today we&#8217;ll do some more streamlining.<\/p>\n<p>We&#8217;ll start by adding a new function to the <code>futureEventsQueue<\/code> object.<\/p>\n<pre class=\"toolbar-overlay:false wrap:false height-set:true lang:default decode:true \">\r\n      this.newItem = function(time,entity) {\r\n        \/\/create futureEventItem\r\n        var feqItem = new futureEventItem(time,\"absolute\",entity);\r\n        this.insertTime = feqItem.getActivationTime();\r\n        globalInsertTime = this.insertTime;\r\n        if (this.feqSize == 0) {  \r\n          this.feq[0] = feqItem;\r\n          this.feqSize++;\r\n          console.log(\"Array size: \"+this.feq.length);\r\n        } else {\r\n          \/\/find index of feq item to insert before\r\n          var insertIndex = this.feq.findIndex(this.findLaterTime);\r\n          \/\/insert the element\r\n          if (insertIndex < 0) {\r\n            insertIndex = this.feq.length;\r\n          }\r\n          this.feq.splice(insertIndex,0,feqItem);\r\n          this.feqSize++;\r\n          console.log(\"Array size: \"+this.feq.length);\r\n        }\r\n      };\r\n<\/pre>\n<p>Then, instead of having to specify the \"absolute\" (vs. \"advance\") flag in the initialization of a new <code>entity<\/code> object, we know we'll be inserting it into the future events queue at a specific time (which might, in fact, be the current time, but that is a different discussion).  Look for the streamlined and specific <code>newItem<\/code> call in place of the more general <code>insertItem<\/code> call.<\/p>\n<pre class=\"toolbar-overlay:false wrap:false height-set:true lang:default decode:true \">\r\n    function entity(entityID,initialTime,incrementTime,endTime) {\r\n      this.entityID = entityID;\r\n      this.initialTime = initialTime;\r\n      this.incrementTime = incrementTime;\r\n      this.endTime = endTime;\r\n      this.nextState = \"increment\";\r\n      \/\/feq.insertItem(initialTime,\"absolute\",this);\r\n      feq.newItem(initialTime,this);\r\n<\/pre>\n<p>Again the output is unchanged so we're still pretty sure we haven't broken anything.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today we&#8217;ll do some more streamlining. We&#8217;ll start by adding a new function to the futureEventsQueue object. this.newItem = function(time,entity) { \/\/create futureEventItem var feqItem = new futureEventItem(time,&#8221;absolute&#8221;,entity); this.insertTime = feqItem.getActivationTime(); globalInsertTime = this.insertTime; if (this.feqSize == 0) { this.feq[0] &hellip; <a href=\"https:\/\/rpchurchill.com\/wordpress\/posts\/2016\/09\/08\/a-simple-discrete-event-simulation-part-7\/\">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\/961"}],"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=961"}],"version-history":[{"count":1,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/posts\/961\/revisions"}],"predecessor-version":[{"id":962,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/posts\/961\/revisions\/962"}],"wp:attachment":[{"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/media?parent=961"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/categories?post=961"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/tags?post=961"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}