{"id":1343,"date":"2017-01-23T20:50:10","date_gmt":"2017-01-24T01:50:10","guid":{"rendered":"http:\/\/rpchurchill.com\/?p=1343"},"modified":"2017-02-03T12:50:50","modified_gmt":"2017-02-03T17:50:50","slug":"a-simple-discrete-event-simulation-part-75","status":"publish","type":"post","link":"https:\/\/rpchurchill.com\/wordpress\/posts\/2017\/01\/23\/a-simple-discrete-event-simulation-part-75\/","title":{"rendered":"A Simple Discrete-Event Simulation: Part 75"},"content":{"rendered":"<p><iframe loading=\"lazy\" width=\"426px\" height=\"1030px\" src=\"https:\/\/www.rpchurchill.com\/demo\/des\/discrete-event-sim_20170123.html\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p>Today I expanded the capability of the Bag component to allow entities to reside there, spawn new sub-entities that undergo an external process of their own, and return to the &#8220;parked&#8221; entity.  Delay times can be specified that control how long it takes the spawned sub-entity to start moving once the main entity parks, and how long it takes the before main entity transfers to the exit queue once the sub-entity returns.  Think of the delays like this.  You drive into a parking lot and park.  Then you gather up your belongings, paperwork, and do whatever else you might have to before walking in to your next activity.  The activity has its own duration, at which point you walk back to your parked car.  Then you put all your stuff back in the car, get settled as you need to, and you finally drive out of the parking lot.  The spawned entity is, in our example, colored orange.  When it is waiting at the main entity within the Bag component is is displayed on top of the main entity that spawned it, a handful of pixels up and to the right.<\/p>\n<p>The value for the Bag component&#8217;s process time has no meaning in this case, though perhaps it should double as one or both of the delay times. <\/p>\n<p>Two new components were created to serve as the internal &#8220;entry&#8221; into the sub-process and &#8220;exit&#8221; back out of the sub-process.  They have as little of the machinery common to the other component types as possible.  When entities are forwarded to them they are immediately forwarded to their next component.  The source component can only connect to a single, downstream component, but multiple upstream components can be connected to the destination component.<\/p>\n<p>The external system can be made up of any types of components (except Entry or Exit components) but I&#8217;ve included only two paths so I didn&#8217;t have to think about reporting on top of everything else I did today.  That will be tomorrow&#8217;s project.  The process of traversing an external system is referred to as a &#8220;sub-journey&#8221; and the new components and processes are named accordingly.<\/p>\n<p>Here&#8217;s the updated code for the Bag component:<\/p>\n<pre class=\"toolbar-overlay:false wrap:false height-set:true lang:default decode:true \">\r\n    function BagComponent(processTime, maxCapacity, routingTable, spawnFlag, spawnArriveDelayTime, spawnDepartDelayTime) {\r\n      if (typeof maxCapacity === \"undefined\") {maxCapacity = 1;}\r\n      if (typeof routingTable === \"undefined\") {routingTable = [1.0];}\r\n      if (typeof spawnFlag === \"undefined\") {spawnFlag = false;}\r\n      if (typeof spawnArriveDelayTime === \"undefined\") {spawnArriveDelayTime = 0.0;}\r\n      if (typeof spawnDepartDelayTime === \"undefined\") {spawnDepartDelayTime = 0.0;}\r\n      \/\/generally exclusive, should always be fed by a queue or at least \"protected\" by a status-based diversion component\r\n      setOfComponents.push(this);\r\n      this.componentID = getNewComponentID();\r\n      this.componentType = \"Bag\";\r\n      this.componentName = \"Bag\";\r\n      this.componentGroup = \"Bag\";\r\n      this.exclusive = true;\r\n      this.routingMethod = 1;  \/\/1: one connection, 2: distribution, 3 routing\r\n      this.previousComponentList = [];\r\n      this.previousComponentCount = 0;\r\n      this.nextComponentList = [];\r\n      this.nextComponentCount = 0;\r\n      this.nextComponentIDList = [];\r\n      this.processTime = processTime;\r\n      \/\/this.processTimeSwitch = processTimeSwitch;\r\n      this.maxCapacity = maxCapacity;\r\n      this.savedDestination = -1;\r\n      this.previousComponentIndex = 0;\r\n      this.nextComponentIndex = 0;\r\n      this.entityQueue = [];\r\n      this.subEntityQueue = [];\r\n      for (var i=0; i<maxCapacity; i++) {\r\n        this.entityQueue[i] = null;\r\n        this.subEntityQueue[i] = null;\r\n      }\r\n      this.exitQueue = [];\r\n      this.routingTable = routingTable;\r\n      this.openStatus = true;\r\n      this.entryTime = \"\";\r\n      this.entryEntityID = \"\";\r\n      this.exitTime = \"\";\r\n      this.exitEntityID = \"\";\r\n      this.exitResidenceTime = \"\";\r\n      this.countInBag = 0;\r\n      this.countInProcess = 0;\r\n      this.activity = \"\";\r\n      this.endEntryDisplayTime = 0;\r\n      this.endExitDisplayTime = 0;\r\n      this.endAllDisplayTime = 0;\r\n      this.displayDelay = 0;\r\n      this.graphic = null;\r\n      this.spawnFlag = spawnFlag;\r\n      this.spawnArriveDelayTime = spawnArriveDelayTime;\r\n      this.spawnDepartDelayTime = spawnDepartDelayTime;\r\n      this.startSubComponent = null;  \/\/TODO: verify that this is assigned if spawnFlag set to true\r\n      this.returnSubComponent = null; \/\/TODO: verify that this is assigned if spawnFlag set to true\r\n\r\n      this.reset = function() {\r\n        this.previousComponentIndex = this.previousComponentCount - 1;\r\n        this.nextComponentIndex = this.nextComponentCount - 1;\r\n        this.entityQueue = [];\r\n        for (var i=0; i<maxCapacity; i++) {\r\n          this.entityQueue[i] = null;\r\n        }\r\n        this.exitQueue = [];\r\n        this.openStatus = true;\r\n        this.savedDestination = -1;\r\n        this.entryTime = \"\";\r\n        this.entryEntityID = \"\";\r\n        this.exitTime = \"\";\r\n        this.exitEntityID = \"\";\r\n        this.exitResidenceTime = \"\";\r\n        this.countInBag = 0;\r\n        this.countInProcess = 0;\r\n        this.activity = \"\";\r\n        this.endEntryDisplayTime = 0;\r\n        this.endExitDisplayTime = 0;\r\n        this.endAllDisplayTime = 0;\r\n      };\r\n      this.assignPreviousComponent = function(prev) {  \/\/TODO-: implement code that makes this actually work\r\n        this.previousComponentList.push(prev);\r\n        this.previousComponentCount++;\r\n        this.previousComponentIndex = this.previousComponentCount - 1;\r\n        \/\/TODO-: assign this automatically when upstream link and exclusive paths are required?\r\n      };\r\n      this.assignNextComponent = function(next) {  \/\/BagComponent\r\n        this.nextComponentList.push(next);\r\n        this.nextComponentCount++;\r\n        this.nextComponentIndex = this.nextComponentCount - 1;\r\n        next.assignPreviousComponent(this);\r\n        \/\/TODO-: automatically assign upstream link if downstream component is exclusive?\r\n      };\r\n      this.assignStartSubJourneyComponent = function(startComp) {\r\n        \/\/next component must be non-exclusive, should be a StartSubJourneyComponent\r\n        this.startSubComponent = startComp;  \/\/TODO: verify that this is assigned if spawnFlag set to true\r\n      };\r\n      this.assignReturnFromSubJourneyComponent = function(returnComp) {\r\n        this.returnSubComponent = returnComp; \/\/TODO: verify that this is assigned if spawnFlag set to true\r\n      };\r\n      this.verifyLinks = function() {\r\n        var i;\r\n        var error = \"\";\r\n        if (this.nextComponentCount > 0) {\r\n          for (i = 0; i < this.nextComponentCount; i++) {  \/\/>\r\n            if (this.nextComponentList[i]) {  \/\/link exists\r\n              if (typeof this.nextComponentList[i] === \"object\") {  \/\/link points to an object\r\n                if (\"componentType\" in this.nextComponentList[i]) {  \/\/object contains member componentType\r\n                  if ((this.nextComponentList[i].componentType == \"Arrivals\") ||\r\n                      (this.nextComponentList[i].componentType == \"Entry\")) {\r\n                    error += this.componentType + \" comp. \" + this.componentID + \" next comp. list element \" + i + \" is not an allowed comp.\\n\";\r\n                  }\r\n                } else {\r\n                  \/\/linked object does not contain member componentType\r\n                  error += this.componentType + \" comp. \" + this.componentID + \" next comp. list item \" + i + \" does not have componentType\\n\";\r\n                }\r\n              } else {\r\n                \/\/link points to something that is not an object\r\n                error += this.componentType + \" comp. \" + this.componentID + \" next comp. list item \" + i + \" is not an object\\n\";\r\n              }\r\n            } else {\r\n              \/\/link that should exist does not\r\n              error += this.componentType + \" comp. \" + this.componentID + \" next comp. list item \" + i + \" does not exist\\n\";\r\n            }\r\n          }\r\n        } else {\r\n          error += this.componentType + \" comp. \" + this.componentID + \" has index of zero next components\\n\";\r\n        }\r\n        if (this.previousComponentCount > 0) {\r\n          for (i = 0; i < this.previousComponentCount; i++) {  \/\/>\r\n            if (this.previousComponentList[i]) {  \/\/link exists\r\n              if (typeof this.previousComponentList[i] === \"object\") {  \/\/link points to an object\r\n                if (\"componentType\" in this.previousComponentList[i]) {  \/\/object contains member componentType\r\n                  if ((this.previousComponentList[i].componentType == \"Arrivals\") ||\r\n                      (this.previousComponentList[i].componentType == \"Exit\")) {\r\n                    error += this.componentType + \" comp. \" + this.componentID + \" previous comp. list element \" + i + \" is not an allowed comp.\\n\";\r\n                  }\r\n                } else {\r\n                  \/\/linked object does not contain member componentType\r\n                  error += this.componentType + \" comp. \" + this.componentID + \" previous comp. list item \" + i + \" does not have componentType\\n\";\r\n                }\r\n              } else {\r\n                \/\/link points to something that is not an object\r\n                error += this.componentType + \" comp. \" + this.componentID + \" previous comp. list item \" + i + \" is not an object\\n\";\r\n              }\r\n            } else {\r\n              \/\/link that should exist does not\r\n              error += this.componentType + \" comp. \" + this.componentID + \" previous comp. list item \" + i + \" does not exist\\n\";\r\n            }\r\n          }\r\n        } else {\r\n          error += this.componentType + \" comp. \" + this.componentID + \" has index of zero previous components\\n\";\r\n        }\r\n        return error;\r\n      };\r\n\r\n      this.getNextComponentIDs = function() {\r\n        for (var i = 0; i < this.nextComponentCount; i++) {\r\n          if (this.nextComponentList[i].getComponentType() != \"Path\") {\r\n            this.nextComponentIDList[i] = this.nextComponentList[i].getComponentID();\r\n          } else {\r\n            this.nextComponentIDList[i] = this.nextComponentList[i].passComponentID();\r\n          }\r\n        }\r\n      };\r\n\r\n      this.getComponentID = function() {\r\n        return this.componentID;\r\n      };\r\n      this.getComponentType = function() {  \/\/BagComponent\r\n        return this.componentType;\r\n      };\r\n      this.getComponentName = function() {\r\n        return this.componentName;\r\n      };\r\n      this.setComponentName = function(componentName) {\r\n        this.componentName = componentName;\r\n      };\r\n      this.getComponentGroup = function() {\r\n        return this.componentGroup;\r\n      };\r\n      this.setComponentGroup = function(componentGroup) {\r\n        this.componentGroup = componentGroup;\r\n        addToGroupStatsNameListWrapper(componentGroup);\r\n      };\r\n      this.getExclusive = function() {\r\n        return this.exclusive;\r\n      };\r\n      this.setExclusive = function(exclusive) {\r\n        this.exclusive = exclusive;\r\n      };\r\n      this.getProcessTime = function() {\r\n        return this.processTime;\r\n      };\r\n      \/\/this.getProcessTimeSwitch = function() {\r\n      \/\/  return this.processTimeSwitch;\r\n      \/\/};\r\n      \/\/this.setProcessTimeSwitch = function(processTimeSwitch) {\r\n      \/\/  this.processTimeSwitch = processTimeSwitch;\r\n      \/\/};\r\n      this.getMaxCapacity = function() {\r\n        return this.maxCapacity;\r\n      };\r\n      this.setMaxCapacity = function(maxCapacity) {\r\n        this.maxCapacity = maxCapacity;\r\n      };\r\n      this.getOpenStatus = function() {\r\n        return this.openStatus;\r\n      };\r\n      this.setOpenStatus = function(openStatus) {\r\n        this.openStatus = openStatus;\r\n      };\r\n      this.getForwardAttemptTime = function() {\r\n        if (this.exitQueue.length > 0) {\r\n          return this.exitQueue[this.exitQueue.length - 1].getForwardAttemptTime();\r\n        } else {\r\n          return Infinity;\r\n        }\r\n      };\r\n      this.getRoutingMethod = function() {\r\n        return this.routingMethod;\r\n      };\r\n      this.setRoutingMethod = function(routingMethod) {\r\n        this.routingMethod = routingMethod;\r\n      };\r\n      this.getEntryTime = function() {\r\n        return this.entryTime;\r\n      };\r\n      this.getEntryEntityID = function() {\r\n        return this.entryEntityID;\r\n      };\r\n      this.getExitTime = function() {\r\n        return this.exitTime;\r\n      };\r\n      this.getExitEntityID = function() {\r\n        return this.exitEntityID;\r\n      };\r\n      this.getExitResidenceTime = function() {\r\n        return this.exitResidenceTime;\r\n      };\r\n      this.getCountInBag = function() {\r\n        return this.countInBag;\r\n      };\r\n      this.getCountInProcess = function() {\r\n        return this.countInProcess;\r\n      };\r\n      this.getActivity = function() {\r\n        return this.activity;\r\n      };\r\n      this.getEndEntryDisplayTime = function() {\r\n        return this.endEntryDisplayTime;\r\n      };\r\n      this.getEndExitDisplayTime = function() {\r\n        return this.endExitDisplayTime;\r\n      };\r\n      this.getEndAllDisplayTime = function() {\r\n        return this.endAllDisplayTime;\r\n      };\r\n\r\n      this.dataGroup = new DisplayGroup1();\r\n      this.defineDataGroup = function(displayDelay, x, y, vw, bc, vc, lc) {\r\n        this.displayDelay = displayDelay;\r\n        this.dataGroup.define(this.componentID, this.componentType, x, y, vw, bc, vc, lc);\r\n      };\r\n      this.dataGroup.addValue(this.entryEntityID, \"Entry ID\", \"integer\");\r\n      this.dataGroup.addValue(this.countInBag, \"# In Bag\", \"numdec\", \"integer\");\r\n      this.dataGroup.addValue(this.exitEntityID, \"Exit ID\", \"integer\");\r\n      this.dataGroup.addValue(this.exitResidenceTime, \"Resdnce Tm\", \"numdec\", 5);\r\n      this.dataGroup.addValue(this.activity, \"Activity\", \"text\");\r\n\r\n      this.assignDisplayValues = function() {\r\n        this.dataGroup.valueList[0].value = this.entryEntityID;\r\n        this.dataGroup.valueList[1].value = this.countInBag;\r\n        this.dataGroup.valueList[2].value = this.exitEntityID;\r\n        this.dataGroup.valueList[3].value = this.exitResidenceTime;\r\n        this.dataGroup.valueList[4].value = this.activity;\r\n        if (this.exclusive) {\r\n          if (this.openStatus) {\r\n            this.dataGroup.setBorderColor(\"#00FF00\");\r\n          } else {\r\n            this.dataGroup.setBorderColor(\"#FF0000\");\r\n          }\r\n        }\r\n      };\r\n      this.drawData = function() {  \/\/BagComponent\r\n        this.assignDisplayValues();\r\n        this.dataGroup.drawBasic();\r\n      };\r\n\r\n      this.defineGraphic = function(graphic) {\r\n        this.graphic = graphic;\r\n      };\r\n      this.updateGraphic = function() {\r\n        this.graphic.setTraverseValue(this.countInProcess);\r\n        this.graphic.setCountValue(this.countInBag);\r\n        \/\/if (this.exclusive) {\r\n        \/\/  if (this.openStatus) {\r\n        \/\/    this.graphic.setBorderColor(\"#00FF00\");\r\n        \/\/  } else {\r\n        \/\/    this.graphic.setBorderColor(\"#FF0000\");\r\n        \/\/  }\r\n        \/\/}\r\n      };\r\n\r\n      this.isOpen = function() {  \/\/BagComponent\r\n        if (this.exclusive) {\r\n          if (this.currentCount() < this.maxCapacity) {\r\n            this.openStatus = true;\r\n          } else {\r\n            this.openStatus = false;\r\n          }\r\n          for (var i = 0; i < this.previousComponentCount; i++) {\r\n            if (this.previousComponentList[i].getComponentType() == \"Path\") {\r\n              this.previousComponentList[i].setPreviousStatus(this.openStatus);  \/\/this may only be needed to determine open\/closed status for display, count <=> capacity used when something is trying to enter\r\n            }\r\n          }\r\n        }\r\n        return this.openStatus;  \/\/if not exclusive should be set to true by default\r\n      };\r\n      this.clearEntryDisplay = function() {\r\n        \/\/only clear display if a new one hasn't started a new timer\r\n        if (globalSimClock >= this.endEntryDisplayTime) {\r\n          this.entryTime = \"\";\r\n          this.entryEntityID = \"\";\r\n        }\r\n        if (globalSimClock >= this.endAllDisplayTime) {\r\n          this.activity = \"\";\r\n        }\r\n        \/\/displayProgressText(\"Bag entry \"+this.componentID+\" clears at time \"+globalSimClock.toFixed(6));\r\n      };\r\n      this.clearExitDisplay = function() {\r\n        \/\/only clear display if a new one hasn't started a new timer\r\n        if (globalSimClock >= this.endExitDisplayTime) {\r\n          this.exitTime = \"\";\r\n          this.exitEntityID = \"\";\r\n          this.exitResidenceTime = \"\";\r\n        }\r\n        if (globalSimClock >= this.endAllDisplayTime) {\r\n          this.activity = \"\";\r\n        }\r\n        \/\/displayProgressText(\"Bag exit \"+this.componentID+\" clears at time \"+globalSimClock.toFixed(6));\r\n      };\r\n      this.currentCount = function() {\r\n        var count = 0;\r\n        if (this.exclusive) {\r\n          \/\/start with entities already in component\r\n          count = this.countInBag;\r\n          \/\/add entities in feeding paths\r\n          for (var i = 0; i < this.previousComponentCount; i++) {\r\n            if (this.previousComponentList[i].componentType == \"Path\") {  \/\/TODO- consider adding test for whether path is boundary component for associated exclusive group of components \/\/do this using no-time\/no-space control component to define boundary\r\n              count += this.previousComponentList[i].currentCount();\r\n            }\r\n          }\r\n        }\r\n        return count;\r\n      };\r\n      this.pullFromPrevious = function() {  \/\/BagComponent\r\n        var oldest = this.previousComponentList[0].getForwardAttemptTime();\r\n        var oldestIndex = 0;\r\n        for (var i = 1; i < this.previousComponentCount; i++) {\r\n          var age = this.previousComponentList[i].getForwardAttemptTime();\r\n          if (age < oldest) {\r\n            oldestIndex = i;\r\n          }\r\n        }\r\n        if (this.previousComponentList[oldestIndex].getComponentType() != \"Path\") {\r\n          if (this.previousComponentList[oldestIndex].getComponentType() != \"Entry\") {\r\n            \/\/TODO: this should call forward entity in a way that ensures that previous component only sends entity to where it is requested and if one is available and if this is a legitimate destination\r\n            this.previousComponentList[oldestIndex].forwardEntity(this.componentID);\r\n          }\r\n        } else {\r\n          displayProgressText(\"Bag comp. \" + this.componentID + \" pulls from previous (\" + oldestIndex + \") at time \" + globalSimClock.toFixed(6));\r\n          this.previousComponentList[oldestIndex].pullFromPrevious(this.componentID);\r\n        }\r\n      };\r\n      this.nextOpen = function() {\r\n        var startIndex = this.nextComponentIndex;\r\n        var tempIndex = startIndex;\r\n        do {\r\n          tempIndex++;\r\n          if (tempIndex >= this.nextComponentCount) {\r\n            tempIndex = 0;\r\n          }\r\n          if (this.nextComponentList[tempIndex].isOpen()) {\r\n            \/\/open link found, update and return nextComponentIndex\r\n            return tempIndex;\r\n          }\r\n        } while (tempIndex != startIndex);\r\n        return -1;  \/\/no open links found, leave nextComponentIndex unchanged\r\n      };\r\n      this.processComplete = function(entity) {  \/\/BagComponent\r\n        this.countInProcess--;   \/\/TODO: ensure handled properly if process time is zero \/\/prob. not applicable\r\n        \/\/figure out which entity just finished processing\r\n        var tempID = entity.entityID;\r\n        this.exitQueue.unshift(entity);\r\n        this.entityQueue[entity.getLocalIndex()] = null;\r\n        entity.setForwardAttemptTime(globalSimClock);\r\n        displayProgressText(\"Bag comp. \" + this.componentID + \" entity: \" + tempID + \" processed at \" + globalSimClock.toFixed(6));\r\n        this.forwardEntity();  \/\/try to forward it\r\n      };\r\n      this.startSubJourney = function(subEntity) {\r\n        this.startSubComponent.receiveEntity(subEntity);\r\n        this.subEntityQueue[subEntity.parentEntity.getLocalIndex()] = null;\r\n      };\r\n      this.continueFromSubJourney = function(subEntity) {\r\n        this.subEntityQueue[subEntity.parentEntity.getLocalIndex()] = null;\r\n        this.processComplete(subEntity.parentEntity);\r\n        removeEntityFromList(subEntity.getEntityID());  \/\/be sure to destroy the subEntity      \r\n      };\r\n      this.returnFromSubJourney = function(subEntity) {\r\n        this.subEntityQueue[subEntity.parentEntity.getLocalIndex()] = subEntity;\r\n        if (this.spawnDepartDelayTime > 0.0) {\r\n          advance(this.spawnDepartDelayTime, this, \"endSubDepartDelay\", subEntity);\r\n        } else {\r\n          this.continueFromSubJourney(subEntity);\r\n        }\r\n      };\r\n      \/\/##default parameters##\r\n      \/\/this.forwardEntity = function(destIndex = -1) {  \/\/BagComponent\r\n      \/\/this.forwardEntity = function() {  \/\/BagComponent\r\n        \/\/\/var routingTable = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : -1;\r\n      this.forwardEntity = function(destIndex) {  \/\/BagComponent\r\n        if (typeof destIndex === \"undefined\") {destIndex = -1;}\r\n        var dest = -1;\r\n        if (destIndex >= 0) {  \/\/pull request from a specific downstream component, must send entity there\r\n          if (this.routingMethod == 1) { \/\/single connection, nothing to do\r\n            dest = 0;\r\n          } else if (this.routingMethod == 2) { \/\/distribution, send to any request\r\n            dest = 0;\r\n            while ((this.nextComponentIDList[dest] != destIndex) && (dest < this.nextComponentCount)) {  \/\/second test should not be needed, loop can't fail to return valid result\r\n              dest++;\r\n            }\r\n          } else if (this.routingMethod == 3) {  \/\/model routing logic, TODO: don't forward if not desired destination\r\n            dest = 0;\r\n            while ((this.nextComponentIDList[dest] != destIndex) &#038;&#038; (dest < this.nextComponentCount)) {  \/\/second test should not be needed, loop can't fail to return valid result\r\n              dest++;\r\n            }\r\n          }\r\n          dummy2 = 0;\r\n        } else {\r\n          if (this.routingMethod == 1) {  \/\/single connection\r\n            if (this.nextComponentList[0].isOpen()) {\r\n              dest = 0;\r\n            }\r\n          } else if (this.routingMethod == 2) {  \/\/distribution\r\n            var nextIndex = this.nextOpen();\r\n            if (nextIndex >= 0) {\r\n              dest = nextIndex;\r\n              \/\/this.nextComponentIndex = dest;\r\n            }\r\n          } else if (this.routingMethod == 3) {  \/\/model routing logic\r\n            if (this.savedDestination >= 0) {\r\n              dest = this.savedDestination;\r\n            } else {\r\n              dest = 0;\r\n              var test = Math.random();\r\n              \/\/need access to entity type but can't pop it off queue here\r\n              var index = this.countInQueue - 1;\r\n              if (index >= 0) {\r\n                index = entityDiversionPercentIndex(this.entityQueue[index]);  \/\/get head item in queue and find out what type it is\r\n              } else {\r\n                index = 0;  \/\/nothing in queue, following code will work but nothing will be popped and processed below\r\n              }\r\n              while (test > this.routingTable[index][dest]) {\r\n                dest++;\r\n              }\r\n              if (dest <= this.nextComponentCount) {\r\n                if (!this.nextComponentList[dest].isOpen()) {\r\n                  dest = -1;\r\n                }\r\n              } else {\r\n                alert(\"Bag comp. tried to assign destination with too high of an index\")\r\n              }\r\n              if (dest >= 0) {\r\n                this.savedDestination = dest;  \/\/ensure that once destination is determined for this entity that we don't keep changing it\r\n              }\r\n            }\r\n          } else {  \/\/0 uninitialized or anything else\r\n            alert(\"comp. \" + this.componentID + \" incorrect routing method: \" + this.routingMethod);\r\n          }\r\n        }\r\n        if (dest >= 0) {\r\n          if (this.countInBag > this.countInProcess) {\r\n            var entity = this.exitQueue.pop();  \/\/TODO-: are we testing to ensure the next entity is really available\r\n            if (entity) {  \/\/TODO-: since we've tested above this should not be necessary\r\n              \/\/calculate how long item was in process\r\n              this.exitResidenceTime = globalSimClock - entity.getLocalEntryTime();\r\n              this.exitTime = globalSimClock;\r\n              this.exitEntityID = entity.entityID;\r\n              this.activity = \"forward entity\";\r\n              this.endExitDisplayTime = globalSimClock + this.displayDelay;\r\n              this.endAllDisplayTime = this.endExitDisplayTime;\r\n              advance(this.displayDelay, this, \"clearExitDisplay\");\r\n              displayProgressText(\"Bag comp. \" + this.componentID + \" forwards entity: \" + this.exitEntityID + \" at time \" + globalSimClock.toFixed(6));\r\n\r\n              this.countInBag--;\r\n              \/\/should be open now\r\n              if (this.exclusive) {\r\n                displayProgressText(\"Bag comp. \" + this.componentID + \" calls pull from previous at time \" + globalSimClock.toFixed(6));\r\n                if (!this.openStatus) {\r\n                  this.pullFromPrevious(); \/\/TODO: call this with a modest (~1 sec) delay to account for reaction time? \/\/may or may not successfully get an entity but should always be called\r\n                }\r\n              }\r\n              this.isOpen();\r\n              this.nextComponentIndex = dest;\r\n              this.savedDestination = -1;  \/\/clear old choice when entity successfully forwarded\r\n              this.nextComponentList[dest].receiveEntity(entity);\r\n              \/\/record stats\r\n              if (this.nextComponentList[dest].getComponentGroup() != entity.getComponentGroup()) {  \/\/truly leaving a component group along the current connection\r\n                recordGroupStatsWrapper(this.componentGroup, entity.getComponentGroupEntryTime(), entity);\r\n              }\r\n            }\r\n          }\r\n        }\r\n      };\r\n      this.receiveEntity = function(entity) {  \/\/BagComponent\r\n        \/\/receive the entity\r\n        entity.setLocalEntryTime();  \/\/record time entity entered bag\r\n        if (entity.getComponentGroup() != this.componentGroup) {\r\n          entity.setComponentGroup(this.componentGroup);\r\n          entity.setComponentGroupEntryTime(globalSimClock);\r\n          recordGroupStatsSystemEntryWrapper(this.componentGroup,entity);\r\n        }\r\n        \/\/figure out which parking space to use\r\n        var i = 0;\r\n        while (this.entityQueue[i] != null) {\r\n          i++;\r\n        }\r\n        if (i < this.maxCapacity) {\r\n          this.entityQueue[i] = entity;\r\n          entity.setLocalIndex(i);\r\n        } else {  \/\/this shouldn't happen\r\n          alert(\"Bag comp. \"+this.componentID+\" over capacity at time \"+this.globalSimClock.toFixed(6));\r\n        }\r\n        entity.setForwardAttemptTime(Infinity);  \/\/TODO: figure out how to handle this\r\n        entity.setPermission(false);  \/\/entity has reached end of related components group, permission no longer matters\r\n        this.countInProcess++;\r\n        this.countInBag++;  \/\/TODO: handle if process time is zero?\r\n        this.isOpen();\r\n        \/\/display what was done\r\n        this.entryTime = globalSimClock;\r\n        this.entryEntityID = entity.entityID;\r\n        this.activity = \"receive entity\";\r\n        \/\/set timer to clear the display after a bit\r\n        this.endEntryDisplayTime = globalSimClock + this.displayDelay;\r\n        this.endAllDisplayTime = this.endEntryDisplayTime;\r\n        advance(this.displayDelay, this, \"clearEntryDisplay\");\r\n        \/\/set timer for the process duration\r\n\/\/        var pTime = this.processTime[entityProcessTimeIndex(entity,this.processTimeSwitch)];\r\n        if (!this.spawnFlag) {\r\n          var pTime = processTime(entity);\r\n          advance(pTime, this, \"processComplete\",entity);\r\n        } else {  \/\/spawn subordinate entity\r\n          var subEntity = generateNewEntity(entity);  \/\/reference to parent entity\r\n          assignEntityTypesSub(subEntity);\r\n          this.subEntityQueue[i] = subEntity;\r\n          recordGroupStatsSystemEntryWrapper(\"SubSystem\",subEntity);\r\n          if (this.spawnArriveDelayTime > 0.0) {\r\n            advance(this.spawnArriveDelayTime, this, \"endSubArriveDelay\", subEntity);\r\n          } else {\r\n            this.startSubJourney(subEntity);\r\n          }\r\n        }\r\n        displayProgressText(\"Bag comp. \" + this.componentID + \" receives entity: \" + this.entryEntityID + \" at time \" + globalSimClock.toFixed(6));\r\n      };\r\n      this.activate = function(nextState, entity2) {\r\n        if (nextState == \"clearEntryDisplay\") {\r\n          this.clearEntryDisplay();\r\n        } else if (nextState == \"clearExitDisplay\") {\r\n          this.clearExitDisplay();\r\n        } else if (nextState == \"processComplete\") {\r\n          this.processComplete(entity2);\r\n        } else if (nextState == \"endSubArriveDelay\") {\r\n          this.startSubJourney(entity2);\r\n        } else if (nextState == \"endSubDepartDelay\") {\r\n          this.continueFromSubJourney(entity2);\r\n        } else {\r\n          errorUndefinedAdvanceState(this.entityID, this.nextState);\r\n        }\r\n      };  \/\/this.activate\r\n\r\n    }  \/\/BagComponent\r\n<\/pre>\n<p>Here are the new source and destination components:<\/p>\n<pre class=\"toolbar-overlay:false wrap:false height-set:true lang:default decode:true \">\r\n    function StartSubJourneyComponent(parent) {\r\n      setOfComponents.push(this);\r\n      this.componentID = getNewComponentID();\r\n      this.componentType = \"startSubJourney\";\r\n      this.componentName = \"startSubJourney\";\r\n      this.nextComponent = null;\r\n      this.parent = parent;\r\n      this.exclusive = false;\r\n      this.graphic = null;\r\n      this.x1 = 0;\r\n      this.y1 = 0;\r\n      this.reset = function() {\r\n        \/\/do nothing\r\n      };\r\n      this.assignNextComponent = function(next) {  \/\/StartSubJourneyComponent\r\n        this.nextComponent = next;\r\n        next.assignPreviousComponent(this);\r\n      };\r\n      this.verifyLinks = function() {\r\n        var error = \"\";\r\n        if (this.nextComponent) {  \/\/link exists\r\n          if (typeof this.nextComponent === \"object\") {  \/\/link points to an object\r\n            if (\"componentType\" in this.nextComponent) {  \/\/object contains member componentType\r\n              if ((this.nextComponent.componentType == \"Arrivals\") ||\r\n                  (this.nextComponent.componentType == \"Entry\")) {\r\n                error += this.componentType + \" comp. \" + this.componentID + \" next comp. is not an allowed comp.\\n\";\r\n              }\r\n            } else {\r\n              \/\/linked object does not contain member componentType\r\n              error += this.componentType + \" comp. \" + this.componentID + \" next comp. does not have componentType\\n\";\r\n            }\r\n          } else {\r\n            \/\/link points to something that is not an object\r\n            error += this.componentType + \" comp. \" + this.componentID + \" next comp. is not an object\\n\";\r\n          }\r\n        } else {\r\n          \/\/link that should exist does not\r\n          error += this.componentType + \" comp. \" + this.componentID + \" next comp. does not exist\\n\";\r\n        }\r\n        return error;\r\n      };\r\n\r\n      this.getComponentID = function() {\r\n        return this.componentID;\r\n      };\r\n      this.getComponentType = function() {\r\n        return this.componentType;\r\n      };\r\n      this.getComponentName = function() {\r\n        return this.componentName;\r\n      };\r\n      this.setComponentName = function(componentName) {\r\n        this.componentName = componentName;\r\n      };\r\n      this.getExclusive = function() {\r\n        return this.exclusive;\r\n      };\r\n      this.defineGraphic = function(graphic) {\r\n        this.graphic = graphic;  \/\/TODO: ensure location automatically set by return node in parent component\r\n      };\r\n      this.updateGraphic = function() {\r\n      };\r\n      this.assignLocation = function(x,y) {\r\n        this.x1 = x;\r\n        this.y1 = y;\r\n      };\r\n      this.getLocation = function() {\r\n        return {x: this.x1, y: this.y1};\r\n      }\r\n      this.receiveEntity = function(entity) {\r\n        this.nextComponent.receiveEntity(entity);\r\n      };\r\n    }  \/\/StartSubJourneyComponent\r\n\r\n    function ReturnFromSubJourneyComponent(parent) {\r\n      setOfComponents.push(this);\r\n      this.componentID = getNewComponentID();\r\n      this.componentType = \"returnFromSubJourney\";\r\n      this.componentName = \"returnFromSubJourney\";\r\n      this.parent = parent;\r\n      this.exclusive = false;\r\n      this.openStatus = true;\r\n      this.previousComponentList = [];\r\n      this.previousComponentCount = 0;\r\n      this.previousComponentIndex = 0;\r\n      this.graphic = null;\r\n      this.x1 = 0;\r\n      this.y1 = 0;\r\n      this.reset = function() {\r\n        \/\/do nothing\r\n      };\r\n      \r\n      this.assignPreviousComponent = function(prev) {\r\n        this.previousComponentList.push(prev);\r\n        this.previousComponentCount++;\r\n        this.previousComponentIndex = this.previousComponentCount - 1;\r\n      };\r\n      this.verifyLinks = function() {\r\n        var error = \"\";\r\n        var i;\r\n        if (this.previousComponentCount > 0) {\r\n          for (i = 0; i < this.previousComponentCount; i++) {  \/\/>\r\n            if (this.previousComponentList[i]) {  \/\/link exists\r\n              if (typeof this.previousComponentList[i] === \"object\") {  \/\/link points to an object\r\n                if (\"componentType\" in this.previousComponentList[i]) {  \/\/object contains member componentType\r\n                  if ((this.previousComponentList[i].componentType == \"Arrivals\") ||\r\n                      (this.previousComponentList[i].componentType == \"Exit\")) {\r\n                    error += this.componentType + \" comp. \" + this.componentID + \" previous comp. list element \" + i + \" is not an allowed comp.\\n\";\r\n                  }\r\n                } else {\r\n                  \/\/linked object does not contain member componentType\r\n                  error += this.componentType + \" comp. \" + this.componentID + \" previous comp. list item \" + i + \" does not have componentType\\n\";\r\n                }\r\n              } else {\r\n                \/\/link points to something that is not an object\r\n                error += this.componentType + \" comp. \" + this.componentID + \" previous comp. list item \" + i + \" is not an object\\n\";\r\n              }\r\n            } else {\r\n              \/\/link that should exist does not\r\n              error += this.componentType + \" comp. \" + this.componentID + \" previous comp. list item \" + i + \" does not exist\\n\";\r\n            }\r\n          }\r\n        } else {\r\n          error += this.componentType + \" comp. \" + this.componentID + \" has index of zero previous components\\n\";\r\n        }\r\n        return error;\r\n      };\r\n<\/pre>\n<p>Here&#8217;s the code that defines the entire system:<\/p>\n<pre class=\"toolbar-overlay:false wrap:false height-set:true lang:default decode:true \">\r\n    \/\/schedule for seven hours of arrivals in half-hour blocks\r\n    var arrivalSchedule = [0, 1, 2, 6, 7, 7, 8, 9, 7, 6, 4, 2, 1, 0];\r\n    var entryDistribution = [[1.0], [1.0], [1.0], [1.0], [1.0], [1.0], [1.0], [1.0], [1.0], [1.0], [1.0], [1.0], [1.0], [1.0]];\r\n\r\n    var arrival1 = new ArrivalsComponent(30.0, arrivalSchedule, entryDistribution);\r\n    arrival1.defineDataGroup(2.0, 61, 2, 70, globalNeutralColor, globalValueColor, globalLabelColor);  \/\/leave in place\r\n    var tempGraphic;\r\n\r\n    var routingTable = [[1.0],[1.0],[1.0]];\r\n    var entry1 = new EntryComponent(routingTable);\r\n    entry1.defineDataGroup(2.0, 90, 105, 80, globalNeutralColor, globalValueColor, globalLabelColor);  \/\/x,y,valuewidth,border,value,label\r\n    entry1.setRoutingMethod(3);  \/\/1 single connection, 2 distribution logic, 3 model logic\r\n    entry1.setComponentName(\"Entry1\");\r\n\r\n    tempGraphic = new DisplayElement(entry1, 210, 5, 68, 20, 0.0, false, false, []);\r\n    entry1.defineGraphic(tempGraphic);\r\n\r\n    arrival1.assignNextComponent(entry1);\r\n\r\n    var pathE1Q0A = new PathComponent();\r\n    pathE1Q0A.setSpeedTime(10.0, 1.0);\r\n\r\n    tempGraphic = new DisplayElement(pathE1Q0A, 0, 0, 260, 37, 0.0, false, false, []);\r\n    pathE1Q0A.defineGraphic(tempGraphic);\r\n\r\n    entry1.assignNextComponent(pathE1Q0A);\r\n\r\n    var pathE1Q0B = new PathComponent();\r\n    pathE1Q0B.setSpeedTime(10.0, 1.0);\r\n\r\n    tempGraphic = new DisplayElement(pathE1Q0B, 260, 37, 0, 0, 0.0, false, false, []);\r\n    pathE1Q0B.defineGraphic(tempGraphic);\r\n\r\n    var routingTableQ0 = [[1.0],[1.0],[1.0]];  \/\/not actually needed since routingMethod is 2 here\r\n    var queue0 = new QueueComponent(0.0, Infinity, routingTableQ0);\r\n    queue0.defineDataGroup(2.0, 90, 205, 80, globalNeutralColor, globalValueColor, globalLabelColor);\r\n    queue0.setRoutingMethod(2);  \/\/1 single connection, 2 distribution logic, 3 model logic\r\n    queue0.setComponentName(\"Q0\");\r\n    queue0.setComponentGroup(\"Primary\");\r\n\r\n    tempGraphic = new DisplayElement(queue0, 200, 50, 88, 56, 0.0, false, false, []);\r\n    var tgBaseY = 25;  \/\/49;\r\n    tempGraphic.addXYLoc(44, tgBaseY + 24);\r\n    tempGraphic.addXYLoc(32, tgBaseY + 24);\r\n    tempGraphic.addXYLoc(20, tgBaseY + 24);\r\n    tempGraphic.addXYLoc(8, tgBaseY + 24);\r\n    tempGraphic.addXYLoc(8, tgBaseY + 12);\r\n    tempGraphic.addXYLoc(20, tgBaseY + 12);\r\n    tempGraphic.addXYLoc(32, tgBaseY + 12);\r\n    tempGraphic.addXYLoc(44, tgBaseY + 12);\r\n    tempGraphic.addXYLoc(56, tgBaseY + 12);\r\n    tempGraphic.addXYLoc(68, tgBaseY + 12);\r\n    tempGraphic.addXYLoc(80, tgBaseY + 12);\r\n    tempGraphic.addXYLoc(80, tgBaseY);\r\n    tempGraphic.addXYLoc(68, tgBaseY);\r\n    tempGraphic.addXYLoc(56, tgBaseY);\r\n    tempGraphic.addXYLoc(44, tgBaseY);\r\n    tempGraphic.addXYLoc(32, tgBaseY);\r\n    tempGraphic.addXYLoc(20, tgBaseY);\r\n    tempGraphic.addXYLoc(8, tgBaseY);\r\n    queue0.defineGraphic(tempGraphic);\r\n\r\n    pathE1Q0B.assignNextComponent(queue0);\r\n\r\n    pathE1Q0A.assignNextComponent(pathE1Q0B);\r\n\r\n    var pathQ0Q1 = new PathComponent();\r\n    pathQ0Q1.setSpeedTime(20, 1.0);\r\n\r\n    tempGraphic = new DisplayElement(pathQ0Q1, 0, 0, 0, 0, 0.0, false, false, []);\r\n    pathQ0Q1.defineGraphic(tempGraphic);\r\n\r\n    queue0.assignNextComponent(pathQ0Q1);\r\n\r\n    var pathQ0Q2 = new PathComponent();\r\n    pathQ0Q2.setSpeedTime(20, 1.0);\r\n\r\n    tempGraphic = new DisplayElement(pathQ0Q2, 0, 0, 0, 0, 0.0, false, false, []);\r\n    pathQ0Q2.defineGraphic(tempGraphic);\r\n\r\n    queue0.assignNextComponent(pathQ0Q2);\r\n\r\n    var pathQ0Q3 = new PathComponent();\r\n    pathQ0Q3.setSpeedTime(20, 1.0);\r\n\r\n    tempGraphic = new DisplayElement(pathQ0Q3, 0, 0, 0, 0, 0.0, false, false, []);\r\n    pathQ0Q3.defineGraphic(tempGraphic);\r\n\r\n    queue0.assignNextComponent(pathQ0Q3);\r\n\r\n    var routingTableQ123 = [[1.0],[1.0],[1.0]];  \/\/not actually needed since routingMethod is 1 here\r\n    var queue1 = new QueueComponent(3.0, 3, routingTableQ123);\r\n    queue1.defineDataGroup(2.0, 5, 341, 80, globalNeutralColor, globalValueColor, globalLabelColor);\r\n    queue1.setRoutingMethod(1);  \/\/1 single connection, 2 distribution logic, 3 model logic\r\n    queue1.setExclusive(true);\r\n    queue1.setComponentName(\"Q1\");\r\n    queue1.setComponentGroup(\"Primary\");\r\n\r\n    tempGraphic = new DisplayElement(queue1, 141, 131, 64, 36, 0.0, false, false, []);\r\n    tgBaseY = 29;  \/\/53\r\n    tempGraphic.addXYLoc(32, tgBaseY);\r\n    tempGraphic.addXYLoc(20, tgBaseY);\r\n    tempGraphic.addXYLoc(8, tgBaseY);\r\n    queue1.defineGraphic(tempGraphic);\r\n\r\n    pathQ0Q1.assignNextComponent(queue1);\r\n\r\n    var queue2 = new QueueComponent(3.0, 3, routingTableQ123);\r\n    queue2.defineDataGroup(2.0, 175, 341, 80, globalNeutralColor, globalValueColor, globalLabelColor);\r\n    queue2.setRoutingMethod(1);  \/\/1 single connection, 2 distribution logic, 3 model logic\r\n    queue2.setExclusive(true);\r\n    queue2.setComponentName(\"Q2\");\r\n    queue2.setComponentGroup(\"Primary\");\r\n\r\n    tempGraphic = new DisplayElement(queue2, 212, 131, 64, 36, 0.0, false, false, []);\r\n    tgBaseY = 29; \/\/53;\r\n    tempGraphic.addXYLoc(32, tgBaseY);\r\n    tempGraphic.addXYLoc(20, tgBaseY);\r\n    tempGraphic.addXYLoc(8, tgBaseY);\r\n    queue2.defineGraphic(tempGraphic);\r\n\r\n    pathQ0Q2.assignNextComponent(queue2);\r\n\r\n    var queue3 = new QueueComponent(3.0, 3, routingTableQ123);\r\n    queue3.defineDataGroup(2.0, 175, 341, 80, globalNeutralColor, globalValueColor, globalLabelColor);\r\n    queue3.setRoutingMethod(1);  \/\/1 single connection, 2 distribution logic, 3 model logic\r\n    queue3.setExclusive(true);\r\n    queue3.setComponentName(\"Q3\");\r\n    queue3.setComponentGroup(\"Primary\");\r\n\r\n    tempGraphic = new DisplayElement(queue3, 283, 131, 64, 36, 0.0, false, false, []);\r\n    tgBaseY = 29; \/\/53;\r\n    tempGraphic.addXYLoc(32, tgBaseY);\r\n    tempGraphic.addXYLoc(20, tgBaseY);\r\n    tempGraphic.addXYLoc(8, tgBaseY);\r\n    queue3.defineGraphic(tempGraphic);\r\n\r\n    pathQ0Q3.assignNextComponent(queue3);\r\n\r\n    var pathQ1P1 = new PathComponent();\r\n    pathQ1P1.setSpeedTime(20, 1.0);\r\n\r\n    tempGraphic = new DisplayElement(pathQ1P1, 0, 0, 0, 0, 0.0, false, false, []);\r\n    pathQ1P1.defineGraphic(tempGraphic);\r\n\r\n    queue1.assignNextComponent(pathQ1P1);\r\n\r\n    var pathQ2P2 = new PathComponent();\r\n    pathQ2P2.setSpeedTime(20, 1.0);\r\n\r\n    tempGraphic = new DisplayElement(pathQ2P2, 0, 0, 0, 0, 0.0, false, false, []);\r\n    pathQ2P2.defineGraphic(tempGraphic);\r\n\r\n    queue2.assignNextComponent(pathQ2P2);\r\n\r\n    var pathQ3P3 = new PathComponent();\r\n    pathQ3P3.setSpeedTime(20, 1.0);\r\n\r\n    tempGraphic = new DisplayElement(pathQ3P3, 0, 0, 0, 0, 0.0, false, false, []);\r\n    pathQ3P3.defineGraphic(tempGraphic);\r\n\r\n    queue3.assignNextComponent(pathQ3P3);\r\n\r\n    var routingTableP123 = [[0.82, 0.9, 1.0],[0.75,0.9,1.0],[0.448,0.9,1.0]];  \/\/citizen, LPR, visitor \/ parking_lot, exit, secondary\r\n    var processTimeP123 = [10.0,20.8,13.0];  \/\/fast, slow visitor, slow citizen or LPR\r\n    var process1 = new ProcessComponent(processTimeP123, 0, 1, routingTableP123);\r\n    process1.defineDataGroup(2.0, 5, 477, 80, globalNeutralColor, globalValueColor, globalLabelColor);\r\n    process1.setExclusive(true);\r\n    process1.setRoutingMethod(3);  \/\/1 single connection, 2 distribution logic, 3 model logic\r\n    process1.setComponentName(\"P1\");\r\n    process1.setComponentGroup(\"Primary\");\r\n\r\n    tempGraphic = new DisplayElement(process1, 141, 192, 64, 36, 0.0, false, false, []);\r\n    tgBaseY = 29; \/\/53;\r\n    tempGraphic.addXYLoc(32, tgBaseY);\r\n    process1.defineGraphic(tempGraphic);\r\n\r\n    pathQ1P1.assignNextComponent(process1);\r\n\r\n    var process2 = new ProcessComponent(processTimeP123, 0, 1, routingTableP123);\r\n    process2.defineDataGroup(2.0, 175, 477, 80, globalNeutralColor, globalValueColor, globalLabelColor);\r\n    process2.setExclusive(true);\r\n    process2.setRoutingMethod(3);  \/\/1 single connection, 2 distribution logic, 3 model logic\r\n    process2.setComponentName(\"P2\");\r\n    process2.setComponentGroup(\"Primary\");\r\n\r\n    tempGraphic = new DisplayElement(process2, 212, 192, 64, 36, 0.0, false, false, []);\r\n    tgBaseY = 29; \/\/53;\r\n    tempGraphic.addXYLoc(32, tgBaseY);\r\n    process2.defineGraphic(tempGraphic);\r\n\r\n    pathQ2P2.assignNextComponent(process2);\r\n\r\n    var process3 = new ProcessComponent(processTimeP123, 0, 1, routingTableP123);\r\n    process3.defineDataGroup(2.0, 175, 477, 80, globalNeutralColor, globalValueColor, globalLabelColor);\r\n    process3.setExclusive(true);\r\n    process3.setRoutingMethod(3);  \/\/1 single connection, 2 distribution logic, 3 model logic\r\n    process3.setComponentName(\"P3\");\r\n    process3.setComponentGroup(\"Primary\");\r\n\r\n    tempGraphic = new DisplayElement(process3, 283, 192, 64, 36, 0.0, false, false, []);\r\n    tgBaseY = 29; \/\/53;\r\n    tempGraphic.addXYLoc(32, tgBaseY);\r\n    process3.defineGraphic(tempGraphic);\r\n\r\n    pathQ3P3.assignNextComponent(process3);\r\n\r\n    var pathP1X1 = new PathComponent();\r\n    pathP1X1.setSpeedTime(30, 1.0);\r\n\r\n    tempGraphic = new DisplayElement(pathP1X1, 0, 0, 0, 0, 0.0, false, false, []);\r\n    pathP1X1.defineGraphic(tempGraphic);\r\n\r\n    process1.assignNextComponent(pathP1X1);\r\n\r\n    var pathP2X1 = new PathComponent();\r\n    pathP2X1.setSpeedTime(30, 1.0);\r\n\r\n    tempGraphic = new DisplayElement(pathP2X1, 0, 0, 0, 0, 0.0, false, false, []);\r\n    pathP2X1.defineGraphic(tempGraphic);\r\n\r\n    process2.assignNextComponent(pathP2X1);\r\n\r\n    var pathP3X1 = new PathComponent();\r\n    pathP3X1.setSpeedTime(30, 1.0);\r\n\r\n    tempGraphic = new DisplayElement(pathP3X1, 0, 0, 0, 0, 0.0, false, false, []);\r\n    pathP3X1.defineGraphic(tempGraphic);\r\n\r\n    process3.assignNextComponent(pathP3X1);\r\n\r\n    var exit1 = new ExitComponent();\r\n    exit1.defineDataGroup(2.0, 90, 576, 80, globalNeutralColor, globalValueColor, globalLabelColor);\r\n    exit1.setComponentName(\"Exit1\");\r\n\r\n    tempGraphic = new DisplayElement(exit1, 210, 429, 68, 20, 0.0, false, false, []);\r\n    exit1.defineGraphic(tempGraphic);\r\n\r\n    pathP1X1.assignNextComponent(exit1);\r\n    pathP2X1.assignNextComponent(exit1);\r\n    pathP3X1.assignNextComponent(exit1);\r\n\r\n    var pathP1Q10 = new PathComponent();\r\n    pathP1Q10.setSpeedTime(20, 1.0);\r\n\r\n    tempGraphic = new DisplayElement(pathP1Q10, 0, 0, 0, 0, 0.0, false, false, []);\r\n    pathP1Q10.defineGraphic(tempGraphic);\r\n\r\n    process1.assignNextComponent(pathP1Q10);\r\n\r\n    var pathP2Q10 = new PathComponent();\r\n    pathP2Q10.setSpeedTime(20, 1.0);\r\n\r\n    tempGraphic = new DisplayElement(pathP2Q10, 0, 0, 0, 0, 0.0, false, false, []);\r\n    pathP2Q10.defineGraphic(tempGraphic);\r\n\r\n    process2.assignNextComponent(pathP2Q10);\r\n\r\n    var pathP3Q10 = new PathComponent();\r\n    pathP3Q10.setSpeedTime(20, 1.0);\r\n\r\n    tempGraphic = new DisplayElement(pathP3Q10, 0, 0, 0, 0, 0.0, false, false, []);\r\n    pathP3Q10.defineGraphic(tempGraphic);\r\n\r\n    process3.assignNextComponent(pathP3Q10);\r\n\r\n    var routingTableQ10 = [[1.0],[1.0],[1.0]];  \/\/not actually needed since routingMethod is 2 here\r\n    var queue10 = new QueueComponent(3.0, Infinity, routingTableQ10);\r\n    queue10.defineDataGroup(2.0, 230, 353, 80, globalNeutralColor, globalValueColor, globalLabelColor);\r\n    queue10.setRoutingMethod(2);  \/\/1 single connection, 2 distribution logic, 3 model logic\r\n    queue10.setExclusive(false);\r\n    queue10.setComponentName(\"Q10\");\r\n    queue10.setComponentGroup(\"Secondary\");\r\n\r\n    tempGraphic = new DisplayElement(queue10, 314, 253, 64, 48, 0.0, false, false, []);\r\n    tgBaseY = 29;  \/\/53\r\n    tempGraphic.addXYLoc(32, tgBaseY + 12);\r\n    tempGraphic.addXYLoc(20, tgBaseY + 12);\r\n    tempGraphic.addXYLoc(8, tgBaseY + 12);\r\n    tempGraphic.addXYLoc(8, tgBaseY);\r\n    tempGraphic.addXYLoc(20, tgBaseY);\r\n    tempGraphic.addXYLoc(32, tgBaseY);\r\n    tempGraphic.addXYLoc(44, tgBaseY);\r\n    tempGraphic.addXYLoc(56, tgBaseY);\r\n    queue10.defineGraphic(tempGraphic);\r\n\r\n    pathP1Q10.assignNextComponent(queue10);\r\n    pathP2Q10.assignNextComponent(queue10);\r\n    pathP3Q10.assignNextComponent(queue10);\r\n\r\n    var pathQ10P10 = new PathComponent();\r\n    pathQ10P10.setSpeedTime(20, 1.0);\r\n\r\n    tempGraphic = new DisplayElement(pathQ10P10, 0, 0, 0, 0, 0.0, false, false, []);\r\n    pathQ10P10.defineGraphic(tempGraphic);\r\n\r\n    queue10.assignNextComponent(pathQ10P10);\r\n\r\n    var pathQ10P11 = new PathComponent();\r\n    pathQ10P11.setSpeedTime(20, 1.0);\r\n\r\n    tempGraphic = new DisplayElement(pathQ10P11, 0, 0, 0, 0, 0.0, false, false, []);\r\n    pathQ10P11.defineGraphic(tempGraphic);\r\n\r\n    queue10.assignNextComponent(pathQ10P11);\r\n\r\n    var routingTableP1011 = [[0.8,1.0],[0.8,1.0],[0.8, 1.0]];\r\n    var processTimeP1011 = [40.0,40.0,40.0];  \/\/fast, slow visitor, slow citizen or LPR\r\n    var process10 = new ProcessComponent(processTimeP1011, 0, 1, routingTableP1011);\r\n    process10.defineDataGroup(2.0, 5, 477, 80, globalNeutralColor, globalValueColor, globalLabelColor);\r\n    process10.setExclusive(true);\r\n    process10.setRoutingMethod(3);  \/\/1 single connection, 2 distribution logic, 3 model logic\r\n    process10.setComponentName(\"P10\");\r\n    process10.setComponentGroup(\"Secondary\");\r\n\r\n    tempGraphic = new DisplayElement(process10, 279, 326, 64, 36, 0.0, false, false, []);\r\n    tgBaseY = 29; \/\/53;\r\n    tempGraphic.addXYLoc(32, tgBaseY);\r\n    process10.defineGraphic(tempGraphic);\r\n\r\n    pathQ10P10.assignNextComponent(process10);\r\n\r\n    var pathP10X1 = new PathComponent();\r\n    pathP10X1.setSpeedTime(20, 1.0);\r\n\r\n    tempGraphic = new DisplayElement(pathP10X1, 0, 0, 0, 0, 0.0, false, false, []);\r\n    pathP10X1.defineGraphic(tempGraphic);\r\n\r\n    process10.assignNextComponent(pathP10X1);\r\n\r\n    pathP10X1.assignNextComponent(exit1);\r\n\r\n    var process11 = new ProcessComponent(processTimeP1011, 0, 1, routingTableP1011);\r\n    process11.defineDataGroup(2.0, 5, 477, 80, globalNeutralColor, globalValueColor, globalLabelColor);\r\n    process11.setExclusive(true);\r\n    process11.setRoutingMethod(3);  \/\/1 single connection, 2 distribution logic, 3 model logic\r\n    process11.setComponentName(\"P11\");\r\n    process11.setComponentGroup(\"Secondary\");\r\n\r\n    tempGraphic = new DisplayElement(process11, 350, 326, 64, 36, 0.0, false, false, []);\r\n    tgBaseY = 29; \/\/53;\r\n    tempGraphic.addXYLoc(32, tgBaseY);\r\n    process11.defineGraphic(tempGraphic);\r\n\r\n    pathQ10P11.assignNextComponent(process11);\r\n\r\n    var pathP11X1 = new PathComponent();\r\n    pathP11X1.setSpeedTime(20, 1.0);\r\n\r\n    tempGraphic = new DisplayElement(pathP11X1, 0, 0, 0, 0, 0.0, false, false, []);\r\n    pathP11X1.defineGraphic(tempGraphic);\r\n\r\n    process11.assignNextComponent(pathP11X1);\r\n\r\n    pathP11X1.assignNextComponent(exit1);\r\n\r\n    var pathP10X2 = new PathComponent();\r\n    pathP10X2.setSpeedTime(20, 1.0);\r\n\r\n    tempGraphic = new DisplayElement(pathP10X2, 0, 0, 0, 0, 0.0, false, false, []);\r\n    pathP10X2.defineGraphic(tempGraphic);\r\n\r\n    process10.assignNextComponent(pathP10X2);\r\n\r\n    var pathP11X2 = new PathComponent();\r\n    pathP11X2.setSpeedTime(20, 1.0);\r\n\r\n    tempGraphic = new DisplayElement(pathP11X2, 0, 0, 0, 0, 0.0, false, false, []);\r\n    pathP11X2.defineGraphic(tempGraphic);\r\n\r\n    process11.assignNextComponent(pathP11X2);\r\n\r\n    var exit2 = new ExitComponent();\r\n    exit2.defineDataGroup(2.0, 230, 576, 80, globalNeutralColor, globalValueColor, globalLabelColor);\r\n    exit2.setComponentName(\"Exit2\");\r\n\r\n    tempGraphic = new DisplayElement(exit2, 314, 400, 68, 20, 0.0, false, false, []);\r\n    exit2.defineGraphic(tempGraphic);\r\n\r\n    pathP10X2.assignNextComponent(exit2);\r\n    pathP11X2.assignNextComponent(exit2);\r\n\r\n    var globalProcessTimeSettings = [[5,7,9],[30,50,80]];\r\n    function processTimeBag1(entity) {\r\n      var processTime;\r\n      var globalIndex = 1;\r\n      if (entity.getPropertyValue(\"Residency\") == \"Citizen\") {\r\n        processTime = globalProcessTimeSettings[globalIndex][0];\r\n      } else if (entity.getPropertyValue(\"Residency\") == \"LPR\") {\r\n        processTime = globalProcessTimeSettings[globalIndex][1];\r\n      } else if (entity.getPropertyValue(\"Residency\") == \"Visitor\") {\r\n        processTime = globalProcessTimeSettings[globalIndex][2];\r\n      }\r\n      return processTime;\r\n    }\r\n    \r\n    var routingTableB1 = [[1.0],[1.0],[1.0]];\r\n    \/\/var processTimeB1 = [30.0,50.0,80.0];  \/\/citizen, LPR, or visitor\r\n    \/\/var bag1 = new BagComponent(processTimeB1, 1, 12, routingTableB1);\r\n    var bag1 = new BagComponent(processTimeBag1, 12, routingTableB1, true, 10.0, 10.0);\r\n    bag1.defineDataGroup(2.0,5,300,100, globalNeutralColor, globalValueColor, globalLabelColor);\r\n    bag1.setExclusive(true);\r\n    bag1.setRoutingMethod(1);  \/\/1 single connection, 2 distribution logic, 3 model logic\r\n    bag1.setComponentName(\"B1\");\r\n    bag1.setComponentGroup(\"Parking Lot\");\r\n    \r\n    tempGraphic = new DisplayElement(bag1, 130, 253, 52, 90, 0.0, false, false, []);\r\n    tgBaseY = 29;\r\n    tempGraphic.addXYLoc(8, tgBaseY);\r\n    tempGraphic.addXYLoc(20, tgBaseY);\r\n    tempGraphic.addXYLoc(32, tgBaseY);\r\n    tempGraphic.addXYLoc(44, tgBaseY);\r\n    tempGraphic.addXYLoc(8, tgBaseY + 12);\r\n    tempGraphic.addXYLoc(20, tgBaseY + 12);\r\n    tempGraphic.addXYLoc(32, tgBaseY + 12);\r\n    tempGraphic.addXYLoc(44, tgBaseY + 12);\r\n    tempGraphic.addXYLoc(8, tgBaseY + 24);\r\n    tempGraphic.addXYLoc(20, tgBaseY + 24);\r\n    tempGraphic.addXYLoc(32, tgBaseY + 24);\r\n    tempGraphic.addXYLoc(44, tgBaseY + 24);  \/\/end fixed spaces = maxCapacity\r\n    tempGraphic.addXYLoc(26, tgBaseY + 52);  \/\/start spaces for exitQueue\r\n    tempGraphic.addXYLoc(14, tgBaseY + 52);\r\n    tempGraphic.addXYLoc(14, tgBaseY + 40);\r\n    tempGraphic.addXYLoc(26, tgBaseY + 40);\r\n    tempGraphic.addXYLoc(38, tgBaseY + 40);\r\n    bag1.defineGraphic(tempGraphic);\r\n    \r\n    var pathP1B1 = new PathComponent();\r\n    pathP1B1.setSpeedTime(20,1.0);\r\n    \r\n    tempGraphic = new DisplayElement(pathP1B1, 0, 0, 0, 0, 0.0, false, false, []);\r\n    pathP1B1.defineGraphic(tempGraphic);\r\n    \r\n    process1.assignNextComponent(pathP1B1);\r\n    \r\n    pathP1B1.assignNextComponent(bag1);\r\n    \r\n    var pathP2B1 = new PathComponent();\r\n    pathP2B1.setSpeedTime(20,1.0);\r\n    \r\n    tempGraphic = new DisplayElement(pathP2B1, 0, 0, 0, 0, 0.0, false, false, []);\r\n    pathP2B1.defineGraphic(tempGraphic);\r\n    \r\n    process2.assignNextComponent(pathP2B1);\r\n    \r\n    pathP2B1.assignNextComponent(bag1);\r\n    \r\n    var pathP3B1 = new PathComponent();\r\n    pathP3B1.setSpeedTime(20,1.0);\r\n    \r\n    tempGraphic = new DisplayElement(pathP3B1, 0, 0, 0, 0, 0.0, false, false, []);\r\n    pathP3B1.defineGraphic(tempGraphic);\r\n    \r\n    process3.assignNextComponent(pathP3B1);\r\n    \r\n    pathP3B1.assignNextComponent(bag1);\r\n    \r\n    var routingTableP20 = [[1.0],[1.0],[1.0]];\r\n    var processTimeP20 = [60.0,60.0,60.0];  \/\/fast, slow visitor, slow citizen or LPR\r\n    var process20 = new ProcessComponent(processTimeP20, 1, 1, routingTableP20);\r\n    process20.defineDataGroup(2.0, 5, 477, 80, globalNeutralColor, globalValueColor, globalLabelColor);\r\n    process20.setExclusive(true);\r\n    process20.setRoutingMethod(1);  \/\/1 single connection, 2 distribution logic, 3 model logic\r\n    process20.setComponentName(\"P20\");\r\n    process20.setComponentGroup(\"Parking Lot\");\r\n    \r\n    tempGraphic = new DisplayElement(process20, 157, 368, 64, 36, 0.0, false, false, []);\r\n    tgBaseY = 29;\r\n    tempGraphic.addXYLoc(32, tgBaseY);\r\n    process20.defineGraphic(tempGraphic);\r\n    \r\n    var pathB1P20 = new PathComponent();\r\n    pathB1P20.setSpeedTime(20,1.0);\r\n    \r\n    tempGraphic = new DisplayElement(pathB1P20, 0, 0, 0, 0, 0.0, false, false, []);\r\n    pathB1P20.defineGraphic(tempGraphic);\r\n    \r\n    bag1.assignNextComponent(pathB1P20);\r\n    \r\n    pathB1P20.assignNextComponent(process20);\r\n    \r\n    var pathP20X1 = new PathComponent();\r\n    pathP20X1.setSpeedTime(20,1.0);\r\n    \r\n    tempGraphic = new DisplayElement(pathP20X1, 0, 0, 0, 0, 0.0, false, false, []);\r\n    pathP20X1.defineGraphic(tempGraphic);\r\n    \r\n    process20.assignNextComponent(pathP20X1);\r\n    \r\n    pathP20X1.assignNextComponent(exit1);\r\n\r\n    var startSubJourneyBag1 = new StartSubJourneyComponent(bag1);\r\n    bag1.assignStartSubJourneyComponent(startSubJourneyBag1);\r\n    \r\n    tempGraphic = new DisplayElement(startSubJourneyBag1, 0, 0, 128, 263, 0.0, false, true, []);\r\n    startSubJourneyBag1.defineGraphic(tempGraphic);  \/\/TODO: bury this assignment in the DisplayElement constructor\r\n    \r\n    var returnFromSubJourneyBag1 = new ReturnFromSubJourneyComponent(bag1);\r\n    bag1.assignReturnFromSubJourneyComponent(returnFromSubJourneyBag1);\r\n    \r\n    tempGraphic = new DisplayElement(returnFromSubJourneyBag1, 128, 333, 0, 0, 0.0, true, false, []);\r\n    returnFromSubJourneyBag1.defineGraphic(tempGraphic);\r\n    \r\n    var pathB1Z = new PathComponent();\r\n    pathB1Z.setSpeedTime(20,1.0);\r\n    \r\n    tempGraphic = new DisplayElement(pathB1Z, 128, 263, 50, 298, 0.0, false, false, []);\r\n    pathB1Z.defineGraphic(tempGraphic);\r\n    \r\n    var pathZB1 = new PathComponent();\r\n    pathZB1.setSpeedTime(20,1.0);\r\n    \r\n    tempGraphic = new DisplayElement(pathZB1, 50, 298, 128, 333, 0.0, false, false, []);\r\n    pathZB1.defineGraphic(tempGraphic);\r\n    \r\n    startSubJourneyBag1.assignNextComponent(pathB1Z);\r\n    \r\n    pathB1Z.assignNextComponent(pathZB1);\r\n    \r\n    pathZB1.assignNextComponent(returnFromSubJourneyBag1);    \r\n<\/pre>\n<p>Some adjustments had to be made to the DisplayElement object as well, to handle drawing the 2D and 3D versions of the new components.<\/p>\n<pre class=\"toolbar-overlay:false wrap:false height-set:true lang:default decode:true \">\r\n    function DisplayElement(parent,x1,y1,w,h,angle,count,traverse,xylocs) {\r\n      \/\/TODO: include mechanisms for drawing paths here\r\n      this.parent = parent;\r\n      this.x1 = x1;\r\n      this.y1 = y1;\r\n      if ((this.parent.getComponentType() == \"startSubJourney\") ||\r\n          (this.parent.getComponentType() == \"returnFromSubJourney\")) {\r\n        this.x2 = w;\r\n        this.y2 = h;\r\n        this.isJourney = true;\r\n        this.isPath = false;\r\n      } else if (this.parent.getComponentType() != \"Path\") {\r\n        this.x2 = x1 + w;\r\n        this.y2 = y1 + h;\r\n        this.isJourney = false;\r\n        this.isPath = false;\r\n      } else {\r\n        this.x2 = w;\r\n        this.y2 = h;\r\n        this.isJourney = false;\r\n        this.isPath = true;\r\n      }\r\n      this.angle = angle;  \/\/not used for now, default to 0.0;\r\n      this.index = this.parent.getComponentID();\r\n      this.nodeColor = globalNodeColor;\r\n      var tempType = this.parent.getComponentType();\r\n      switch (tempType) {\r\n        case \"Queue\": this.type = \"Q\"; break;\r\n        case \"Process\": this.type = \"P\"; break;\r\n        case \"Entry\": this.type = \"E\"; break;\r\n        case \"Exit\": this.type = \"X\"; break;\r\n        case \"Bag\": this.type = \"B\"; break;\r\n        case \"Stack\": this.type = \"S\"; break;\r\n        case \"Control\": this.type = \"C\"; break;\r\n        default: this.type = \"?\";  \/\/other types are never displayed this way\r\n      }\r\n      this.label = this.index + \"-\" + this.type + \": \" +this.parent.getComponentName();\r\n      this.labelWidth = globalCTX.measureText(this.label).width;\r\n      this.innode = true;\r\n      this.outnode = true;\r\n      if (this.parent.getComponentType() == \"Entry\") {\r\n        this.innode = false;\r\n      } else if (this.parent.getComponentType() == \"Exit\") {\r\n        this.outnode = false;\r\n      } else if (this.parent.getComponentType() == \"Arrivals\") {\r\n        this.innode = false;\r\n      } else if (this.parent.getComponentType() == \"startSubJourney\") {\r\n        this.innode = false;\r\n      } else if (this.parent.getComponentType() == \"returnFromSubJourney\") {\r\n        this.outnode = false;\r\n      }\r\n      this.count = count;\r\n      this.traverse = traverse;\r\n      this.countValue = 0;\r\n      this.traverseValue = 0;\r\n      this.nodexi = w * 0.5;\r\n      this.nodexo = this.nodexi;\r\n      this.nodeyi = 0.0;\r\n      this.nodeyo = h;\r\n      this.locsCount = xylocs.length;\r\n      this.entityLocs = [];\r\n      this.component3D = null;\r\n      \/\/use this information to define a 3D display component\r\n      \r\n      for (var i=0; i<this.locsCount; i++) {\r\n        this.entityLocs.push(xylocs[i]);\r\n      }\r\n      this.addXYLoc = function(xl,yl) {\r\n        var loc = {x: xl, y: yl};\r\n        this.entityLocs.push(loc);\r\n        this.locsCount++;\r\n      };\r\n      this.setNeutralColor = function(nc) {\r\n        this.neutralColor = nc;\r\n      };\r\n      this.setTraverseValue = function(tv) {\r\n        this.traverseValue = tv;\r\n      };\r\n      this.setCountValue = function(cv) {\r\n        this.countValue = cv;\r\n      };\r\n      this.setStartPoint = function(x1,y1) {\r\n        this.x1 = x1;\r\n        this.y1 = y1;\r\n      };\r\n      this.setEndPoint = function(x2,y2) {\r\n        this.x2 = x2;\r\n        this.y2 = y2;\r\n      };\r\n      this.getInNode = function() {\r\n        if (this.innode) {\r\n          if (this.isJourney) {\r\n            return {x: this.x1, y: this.y1};\r\n          } else if (!this.isPath) {\r\n            return {x: this.x1+this.nodexi, y: this.y1+this.nodeyi};\r\n          } else {\r\n            return {x: this.x1, y: this.y1};\r\n          }\r\n        } else {\r\n          alert(\"display element queried for non-existent incoming node\");\r\n          return null;  \/\/in theory this should never happen\r\n        }\r\n      };\r\n      this.getOutNode = function() {\r\n        if (this.outnode) {\r\n          if (this.isJourney) {\r\n            return {x: this.x2, y: this.y2};\r\n          } else if (!this.isPath) {\r\n            return {x: this.x1+this.nodexo, y: this.y1+this.nodeyo};\r\n          } else {\r\n            return {x: this.x2, y: this.y2};\r\n          }\r\n        } else {\r\n          alert(\"display element queried for non-existent outgoing node\");\r\n          return null;  \/\/in theory this should never happen\r\n        }\r\n      };\r\n      this.defineColors = function(lc,vc,nc,nvc,rc,rvc,wc,wvc) {\r\n        this.labelColor = lc;             \/\/text labels\r\n        this.valueColor = vc;             \/\/text values\r\n        this.neutralColor = nc;           \/\/non-exclusive path and component color\r\n        this.neutralVertexColor = nvc;    \/\/non-exclusive wireframe color\r\n        this.readyColor = rc;             \/\/exclusive open component or ready-to-go entity color\r\n        this.readyVertexColor = rvc;      \/\/exclusive open component or ready-to-go entity vertex color\r\n        this.waitingColor = wc;           \/\/exclusive closed component or in-process entity color\r\n        this.waitingVertexColor = wvc;    \/\/exclusive closed component or in-process entity vertex color\r\n      };\r\n      this.defineGlobalDefaultColors = function() {\r\n        this.defineColors(globalLabelColor,globalValueColor,globalNeutralColor,globalNeutralVertexColor,\r\n                          globalReadyColor,globalReadyVertexColor,globalWaitingColor,globalWaitingVertexColor);\r\n      };\r\n      this.defineGlobalDefaultColors();\r\n      this.drawBasic = function() {\r\n        var borderColor;\r\n        if (this.parent.getExclusive()) {\r\n          if (this.parent.getOpenStatus()) {\r\n            borderColor = this.readyColor;\r\n          } else {\r\n            borderColor = this.waitingColor;\r\n          }\r\n        } else {\r\n          borderColor = this.neutralColor;\r\n        }\r\n        if (this.isJourney) {\r\n          globalCTX.strokeStyle = borderColor;\r\n          globalCTX.beginPath();\r\n          if (this.innode) {\r\n            globalCTX.moveTo(this.x1-5+0.5,this.y1-5+0.5);\r\n            globalCTX.lineTo(this.x1+4+0.5,this.y1-5+0.5);\r\n            globalCTX.lineTo(this.x1+4+0.5,this.y1+4+0.5);\r\n            globalCTX.lineTo(this.x1-5+0.5,this.y1+4+0.5);\r\n            globalCTX.lineTo(this.x1-5+0.5,this.y1-5+0.5);\r\n          } else {\r\n            globalCTX.moveTo(this.x2-5+0.5,this.y2-5+0.5);\r\n            globalCTX.lineTo(this.x2+4+0.5,this.y2-5+0.5);\r\n            globalCTX.lineTo(this.x2+4+0.5,this.y2+4+0.5);\r\n            globalCTX.lineTo(this.x2-5+0.5,this.y2+4+0.5);\r\n            globalCTX.lineTo(this.x2-5+0.5,this.y2-5+0.5);\r\n          }\r\n          globalCTX.stroke();\r\n          \/\/do nothing\r\n        } else if (!this.isPath) {\r\n          var runningHeight = 15;\r\n          globalCTX.strokeStyle = borderColor;\r\n          globalCTX.beginPath();\r\n          globalCTX.moveTo(this.x1+0.5,this.y1+0.5);\r\n          globalCTX.lineTo(this.x2+0.5,this.y1+0.5);\r\n          globalCTX.lineTo(this.x2+0.5,this.y2+0.5);\r\n          globalCTX.lineTo(this.x1+0.5,this.y2+0.5);\r\n          globalCTX.lineTo(this.x1+0.5,this.y1+0.5);\r\n          globalCTX.stroke();\r\n          globalCTX.font = \"12px Arial\";\r\n          globalCTX.fillStyle = this.labelColor;\r\n          globalCTX.textAlign = \"center\";\r\n          globalCTX.fillText(this.label,this.x1+this.nodexi,this.y1+runningHeight);\r\n          runningHeight += 12;\r\n          if (this.traverse) {\r\n            globalCTX.textAlign = \"right\";\r\n            var waitChar = \"P:\";\r\n            if (this.parent.getComponentType() == \"Queue\") {\r\n              waitChar = \"T:\";\r\n            } else if (this.parent.getComponentType() == \"Process\") {\r\n              waitChar = \"P:\";\r\n            } \r\n            globalCTX.fillText(waitChar,x1+15,this.y1+runningHeight);\r\n            globalCTX.fillStyle = this.valueColor;\r\n            globalCTX.textAlign = \"left\";\r\n            globalCTX.fillText(this.traverseValue,x1+17,this.y1+runningHeight);\r\n            runningHeight += 12;\r\n          }\r\n          if (this.count) {\r\n            globalCTX.fillStyle = this.labelColor;\r\n            globalCTX.textAlign = \"right\";\r\n            globalCTX.fillText(\"Q:\",x1+15,this.y1+runningHeight);\r\n            globalCTX.fillStyle = this.valueColor;\r\n            globalCTX.textAlign = \"left\";\r\n            globalCTX.fillText(this.countValue,x1+17,this.y1+runningHeight);\r\n            runningHeight += 12;\r\n          }\r\n        } else {\r\n          globalCTX.strokeStyle = borderColor;\r\n          globalCTX.beginPath();\r\n          globalCTX.moveTo(this.x1+0.5,this.y1+0.5);\r\n          globalCTX.lineTo(this.x2+0.5,this.y2+0.5);\r\n          globalCTX.stroke();        \r\n        }\r\n      };\r\n      this.drawNodes = function() {\r\n        if (this.isJourney) {\r\n          if (this.innode) {\r\n            drawNode(this.x1,this.y1,3,this.nodeColor);\r\n          }\r\n          if (this.outnode) {\r\n            drawNode(this.x2,this.y2,3,this.nodeColor);\r\n          }        \r\n        } else if (!this.isPath) {\r\n          if (this.innode) {\r\n            drawNode(this.x1+this.nodexi,this.y1+this.nodeyi,3,this.nodeColor);\r\n          }\r\n          if (this.outnode) {\r\n            drawNode(this.x1+this.nodexo,this.y1+this.nodeyo,3,this.nodeColor);\r\n          }\r\n        } else {\r\n          if (this.parent.previousComponent.getComponentType() == \"Path\") {\r\n            drawNode(this.x1,this.y1,3,this.nodeColor);\r\n          }\r\n          if (this.parent.nextComponent.getComponentType() == \"Path\") {\r\n            drawNode(this.x2,this.y2,3,this.nodeColor);\r\n          }\r\n        }\r\n      };\r\n      this.drawEntities = function() {\r\n        var i;\r\n        var drawCount;\r\n        var drawColor;\r\n        if (this.isPath) {\r\n          drawCount = this.parent.entityQueue.length;\r\n          for (i=0; i<drawCount; i++) {\r\n            var location = this.parent.entityQueue[i].getLocation();\r\n            drawNode(location.x,location.y,5,this.readyColor);\r\n            drawNode(location.x,location.y,3,this.parent.entityQueue[i].getEntityColor())\r\n          }\r\n        } else if (this.parent.getComponentType() == \"Bag\") {\r\n          drawCount = this.parent.maxCapacity;  \/\/should be < this.entityLocs.length\r\n          drawColor = this.waitingColor;\r\n          for (i=0; i<drawCount; i++) {\r\n            if (this.parent.entityQueue[i] != null) {\r\n              var xx = this.entityLocs[i].x;\r\n              var yy = this.entityLocs[i].y;\r\n              drawNode(this.x1+xx,this.y1+yy,5,drawColor);\r\n              drawNode(this.x1+xx,this.y1+yy,3,this.parent.entityQueue[i].getEntityColor());\r\n              if (this.parent.subEntityQueue[i] != null) {\r\n                drawNode(this.x1+xx+3,this.y1+yy-3,5,drawColor)\r\n                drawNode(this.x1+xx+3,this.y1+yy-3,3,this.parent.subEntityQueue[i].getEntityColor());\r\n              }\r\n            }\r\n          }\r\n          drawCount = this.entityLocs.length - this.parent.maxCapacity;\r\n          if (this.parent.exitQueue.length < drawCount) {\r\n            drawCount = this.parent.exitQueue.length;\r\n          }\r\n          drawColor = this.readyColor;\r\n          for (i=0; i<drawCount; i++) {\r\n            \/\/locs for exit queue in order from maxCapacity\r\n            var xx = this.entityLocs[this.parent.maxCapacity + i].x;\r\n            var yy = this.entityLocs[this.parent.maxCapacity + i].y;\r\n            drawNode(this.x1+xx,this.y1+yy,5,drawColor);\r\n            \/\/exit queue items in reverse order\r\n            drawNode(this.x1+xx,this.y1+yy,3,this.parent.exitQueue[this.parent.exitQueue.length-1-i].getEntityColor());            \r\n          }\r\n        } else if (this.parent.getComponentType() != \"Arrivals\") {\r\n          var qCount = this.countValue - this.traverseValue;\r\n          if (this.countValue > this.locsCount) {\r\n            drawCount = this.locsCount;\r\n          } else {\r\n            drawCount = this.countValue;\r\n          }\r\n          for (i=0; i<drawCount; i++) {\r\n            if (i < qCount) {\r\n              drawColor = this.readyColor;\r\n            } else {\r\n              drawColor = this.waitingColor;\r\n            }\r\n            var xx = this.entityLocs[i].x;\r\n            var yy = this.entityLocs[i].y;\r\n            drawNode(this.x1+xx,this.y1+yy,5,drawColor);\r\n            drawNode(this.x1+xx,this.y1+yy,3,this.parent.entityQueue[i].getEntityColor());\r\n          }\r\n        }\r\n      };\r\n      this.define3DComponent = function() {\r\n        \/\/when everything else is defined and verified, call this to build 3D component info list\r\n        var faceColor;\r\n        var vertexColor;\r\n        if (this.parent.getExclusive()) {\r\n          if (this.parent.getOpenStatus()) {\r\n            faceColor = this.readyColor;\r\n            vertexColor = this.readyVertexColor;\r\n          } else {\r\n            faceColor = this.waitingColor;\r\n            vertexColor = this.waitingVertexColor;          \r\n          }\r\n        } else {\r\n          faceColor = this.neutralColor;\r\n          vertexColor = this.neutralVertexColor;\r\n        } \r\n        if (this.isPath) {\r\n          this.component3D = define3DPathComponent(this.x1,this.y1,this.x2,this.y2,faceColor);\r\n          if (this.parent.nextComponent.getComponentType() == \"Path\") {\r\n            \/\/define a 3D node here, only at the end of the first path\r\n            define3DNode(this.x2,this.y2,globalNodeColor,globalNodeVertexColor);\r\n          }\r\n        } else if (this.parent.getComponentType() != \"Arrivals\") {\r\n          if (!this.isJourney) {\r\n            this.component3D = define3DBoxComponent(this.x1,this.y1,w,h,faceColor,vertexColor,this.innode,this.outnode);\r\n          } else {\r\n            if (this.outnode) {\r\n              define3DNode(this.x2,this.y2,globalNodeColor,globalNodeVertexColor);\r\n            } \r\n            if (this.innode) {\r\n              define3DNode(this.x1,this.y1,globalNodeColor,globalNodeVertexColor);\r\n            } \r\n          }\r\n        } else {\r\n          \/\/do nothing\r\n        }\r\n      };\r\n      this.update3DComponent = function() {\r\n        var faceColor;\r\n        var vertexColor;\r\n        if (this.parent.getExclusive()) {\r\n          if (this.parent.getOpenStatus()) {\r\n            faceColor = this.readyColor;\r\n            vertexColor = this.readyVertexColor;\r\n          } else {\r\n            faceColor = this.waitingColor;\r\n            vertexColor = this.waitingVertexColor;          \r\n          }\r\n        } else {\r\n          faceColor = this.neutralColor;\r\n          vertexColor = this.neutralVertexColor;\r\n        } \r\n        if (this.isPath) {\r\n          update3DPathColor(this.component3D,faceColor);\r\n        } else if (this.parent.getComponentType() != \"Arrivals\") {\r\n          if (!this.isJourney) {\r\n            update3DComponentColor(this.component3D,faceColor,vertexColor);\r\n          }\r\n        }\r\n      };\r\n      this.update3DEntities = function() {\r\n        var i;\r\n        if (this.isPath) {\r\n          var drawCount = this.parent.entityQueue.length;\r\n          for (i=0; i<drawCount; i++) {\r\n            var location = this.parent.entityQueue[i].getLocation();\r\n            update3DEntity(global3DRefreshEntityCount++,location.x,location.y,this.readyColor,this.readyVertexColor);\r\n          }\r\n        } else if (this.parent.getComponentType() != \"Arrivals\") {\r\n          var qCount = this.countValue - this.traverseValue;\r\n          if (this.countValue > this.locsCount) {\r\n            drawCount = this.locsCount;\r\n          } else {\r\n            drawCount = this.countValue;\r\n          }\r\n          var faceColor;\r\n          var vertexColor;\r\n          for (i=0; i<drawCount; i++) {\r\n            if (i < qCount) {\r\n              faceColor = this.readyColor;\r\n              vertexColor = this.readyVertexColor;\r\n            } else {\r\n              faceColor = this.waitingColor;\r\n              vertexColor = this.waitingVertexColor;\r\n            }\r\n            var xx = this.x1 + this.entityLocs[i].x;\r\n            \/\/var yy = global3DTopHeight + (global3DEntityHeight \/ 2) + global3DNodeUpOffset;  \/\/declared inside update3DEntity\r\n            var zz = this.y1 + this.entityLocs[i].y;\r\n            update3DEntity(global3DRefreshEntityCount++,xx,zz,faceColor,vertexColor);\r\n          }\r\n        }\r\n      };\r\n      \r\n    }  \/\/DisplayElement\r\n<\/pre>\n<p>I also made the background transparent so it'll look a bit nicer in an iframe and need to do something more explicit with the 3D versions of the sub-entities.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today I expanded the capability of the Bag component to allow entities to reside there, spawn new sub-entities that undergo an external process of their own, and return to the &#8220;parked&#8221; entity. Delay times can be specified that control how &hellip; <a href=\"https:\/\/rpchurchill.com\/wordpress\/posts\/2017\/01\/23\/a-simple-discrete-event-simulation-part-75\/\">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],"_links":{"self":[{"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/posts\/1343"}],"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=1343"}],"version-history":[{"count":11,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/posts\/1343\/revisions"}],"predecessor-version":[{"id":1393,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/posts\/1343\/revisions\/1393"}],"wp:attachment":[{"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/categories?post=1343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rpchurchill.com\/wordpress\/wp-json\/wp\/v2\/tags?post=1343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}