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 “parked” 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.
The value for the Bag component’s process time has no meaning in this case, though perhaps it should double as one or both of the delay times.
Two new components were created to serve as the internal “entry” into the sub-process and “exit” 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.
The external system can be made up of any types of components (except Entry or Exit components) but I’ve included only two paths so I didn’t have to think about reporting on top of everything else I did today. That will be tomorrow’s project. The process of traversing an external system is referred to as a “sub-journey” and the new components and processes are named accordingly.
Here’s the updated code for the Bag component:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 |
function BagComponent(processTime, maxCapacity, routingTable, spawnFlag, spawnArriveDelayTime, spawnDepartDelayTime) { if (typeof maxCapacity === "undefined") {maxCapacity = 1;} if (typeof routingTable === "undefined") {routingTable = [1.0];} if (typeof spawnFlag === "undefined") {spawnFlag = false;} if (typeof spawnArriveDelayTime === "undefined") {spawnArriveDelayTime = 0.0;} if (typeof spawnDepartDelayTime === "undefined") {spawnDepartDelayTime = 0.0;} //generally exclusive, should always be fed by a queue or at least "protected" by a status-based diversion component setOfComponents.push(this); this.componentID = getNewComponentID(); this.componentType = "Bag"; this.componentName = "Bag"; this.componentGroup = "Bag"; this.exclusive = true; this.routingMethod = 1; //1: one connection, 2: distribution, 3 routing this.previousComponentList = []; this.previousComponentCount = 0; this.nextComponentList = []; this.nextComponentCount = 0; this.nextComponentIDList = []; this.processTime = processTime; //this.processTimeSwitch = processTimeSwitch; this.maxCapacity = maxCapacity; this.savedDestination = -1; this.previousComponentIndex = 0; this.nextComponentIndex = 0; this.entityQueue = []; this.subEntityQueue = []; for (var i=0; i<maxCapacity; i++) { this.entityQueue[i] = null; this.subEntityQueue[i] = null; } this.exitQueue = []; this.routingTable = routingTable; this.openStatus = true; this.entryTime = ""; this.entryEntityID = ""; this.exitTime = ""; this.exitEntityID = ""; this.exitResidenceTime = ""; this.countInBag = 0; this.countInProcess = 0; this.activity = ""; this.endEntryDisplayTime = 0; this.endExitDisplayTime = 0; this.endAllDisplayTime = 0; this.displayDelay = 0; this.graphic = null; this.spawnFlag = spawnFlag; this.spawnArriveDelayTime = spawnArriveDelayTime; this.spawnDepartDelayTime = spawnDepartDelayTime; this.startSubComponent = null; //TODO: verify that this is assigned if spawnFlag set to true this.returnSubComponent = null; //TODO: verify that this is assigned if spawnFlag set to true this.reset = function() { this.previousComponentIndex = this.previousComponentCount - 1; this.nextComponentIndex = this.nextComponentCount - 1; this.entityQueue = []; for (var i=0; i<maxCapacity; i++) { this.entityQueue[i] = null; } this.exitQueue = []; this.openStatus = true; this.savedDestination = -1; this.entryTime = ""; this.entryEntityID = ""; this.exitTime = ""; this.exitEntityID = ""; this.exitResidenceTime = ""; this.countInBag = 0; this.countInProcess = 0; this.activity = ""; this.endEntryDisplayTime = 0; this.endExitDisplayTime = 0; this.endAllDisplayTime = 0; }; this.assignPreviousComponent = function(prev) { //TODO-: implement code that makes this actually work this.previousComponentList.push(prev); this.previousComponentCount++; this.previousComponentIndex = this.previousComponentCount - 1; //TODO-: assign this automatically when upstream link and exclusive paths are required? }; this.assignNextComponent = function(next) { //BagComponent this.nextComponentList.push(next); this.nextComponentCount++; this.nextComponentIndex = this.nextComponentCount - 1; next.assignPreviousComponent(this); //TODO-: automatically assign upstream link if downstream component is exclusive? }; this.assignStartSubJourneyComponent = function(startComp) { //next component must be non-exclusive, should be a StartSubJourneyComponent this.startSubComponent = startComp; //TODO: verify that this is assigned if spawnFlag set to true }; this.assignReturnFromSubJourneyComponent = function(returnComp) { this.returnSubComponent = returnComp; //TODO: verify that this is assigned if spawnFlag set to true }; this.verifyLinks = function() { var i; var error = ""; if (this.nextComponentCount > 0) { for (i = 0; i < this.nextComponentCount; i++) { //> if (this.nextComponentList[i]) { //link exists if (typeof this.nextComponentList[i] === "object") { //link points to an object if ("componentType" in this.nextComponentList[i]) { //object contains member componentType if ((this.nextComponentList[i].componentType == "Arrivals") || (this.nextComponentList[i].componentType == "Entry")) { error += this.componentType + " comp. " + this.componentID + " next comp. list element " + i + " is not an allowed comp.\n"; } } else { //linked object does not contain member componentType error += this.componentType + " comp. " + this.componentID + " next comp. list item " + i + " does not have componentType\n"; } } else { //link points to something that is not an object error += this.componentType + " comp. " + this.componentID + " next comp. list item " + i + " is not an object\n"; } } else { //link that should exist does not error += this.componentType + " comp. " + this.componentID + " next comp. list item " + i + " does not exist\n"; } } } else { error += this.componentType + " comp. " + this.componentID + " has index of zero next components\n"; } if (this.previousComponentCount > 0) { for (i = 0; i < this.previousComponentCount; i++) { //> if (this.previousComponentList[i]) { //link exists if (typeof this.previousComponentList[i] === "object") { //link points to an object if ("componentType" in this.previousComponentList[i]) { //object contains member componentType if ((this.previousComponentList[i].componentType == "Arrivals") || (this.previousComponentList[i].componentType == "Exit")) { error += this.componentType + " comp. " + this.componentID + " previous comp. list element " + i + " is not an allowed comp.\n"; } } else { //linked object does not contain member componentType error += this.componentType + " comp. " + this.componentID + " previous comp. list item " + i + " does not have componentType\n"; } } else { //link points to something that is not an object error += this.componentType + " comp. " + this.componentID + " previous comp. list item " + i + " is not an object\n"; } } else { //link that should exist does not error += this.componentType + " comp. " + this.componentID + " previous comp. list item " + i + " does not exist\n"; } } } else { error += this.componentType + " comp. " + this.componentID + " has index of zero previous components\n"; } return error; }; this.getNextComponentIDs = function() { for (var i = 0; i < this.nextComponentCount; i++) { if (this.nextComponentList[i].getComponentType() != "Path") { this.nextComponentIDList[i] = this.nextComponentList[i].getComponentID(); } else { this.nextComponentIDList[i] = this.nextComponentList[i].passComponentID(); } } }; this.getComponentID = function() { return this.componentID; }; this.getComponentType = function() { //BagComponent return this.componentType; }; this.getComponentName = function() { return this.componentName; }; this.setComponentName = function(componentName) { this.componentName = componentName; }; this.getComponentGroup = function() { return this.componentGroup; }; this.setComponentGroup = function(componentGroup) { this.componentGroup = componentGroup; addToGroupStatsNameListWrapper(componentGroup); }; this.getExclusive = function() { return this.exclusive; }; this.setExclusive = function(exclusive) { this.exclusive = exclusive; }; this.getProcessTime = function() { return this.processTime; }; //this.getProcessTimeSwitch = function() { // return this.processTimeSwitch; //}; //this.setProcessTimeSwitch = function(processTimeSwitch) { // this.processTimeSwitch = processTimeSwitch; //}; this.getMaxCapacity = function() { return this.maxCapacity; }; this.setMaxCapacity = function(maxCapacity) { this.maxCapacity = maxCapacity; }; this.getOpenStatus = function() { return this.openStatus; }; this.setOpenStatus = function(openStatus) { this.openStatus = openStatus; }; this.getForwardAttemptTime = function() { if (this.exitQueue.length > 0) { return this.exitQueue[this.exitQueue.length - 1].getForwardAttemptTime(); } else { return Infinity; } }; this.getRoutingMethod = function() { return this.routingMethod; }; this.setRoutingMethod = function(routingMethod) { this.routingMethod = routingMethod; }; this.getEntryTime = function() { return this.entryTime; }; this.getEntryEntityID = function() { return this.entryEntityID; }; this.getExitTime = function() { return this.exitTime; }; this.getExitEntityID = function() { return this.exitEntityID; }; this.getExitResidenceTime = function() { return this.exitResidenceTime; }; this.getCountInBag = function() { return this.countInBag; }; this.getCountInProcess = function() { return this.countInProcess; }; this.getActivity = function() { return this.activity; }; this.getEndEntryDisplayTime = function() { return this.endEntryDisplayTime; }; this.getEndExitDisplayTime = function() { return this.endExitDisplayTime; }; this.getEndAllDisplayTime = function() { return this.endAllDisplayTime; }; this.dataGroup = new DisplayGroup1(); this.defineDataGroup = function(displayDelay, x, y, vw, bc, vc, lc) { this.displayDelay = displayDelay; this.dataGroup.define(this.componentID, this.componentType, x, y, vw, bc, vc, lc); }; this.dataGroup.addValue(this.entryEntityID, "Entry ID", "integer"); this.dataGroup.addValue(this.countInBag, "# In Bag", "numdec", "integer"); this.dataGroup.addValue(this.exitEntityID, "Exit ID", "integer"); this.dataGroup.addValue(this.exitResidenceTime, "Resdnce Tm", "numdec", 5); this.dataGroup.addValue(this.activity, "Activity", "text"); this.assignDisplayValues = function() { this.dataGroup.valueList[0].value = this.entryEntityID; this.dataGroup.valueList[1].value = this.countInBag; this.dataGroup.valueList[2].value = this.exitEntityID; this.dataGroup.valueList[3].value = this.exitResidenceTime; this.dataGroup.valueList[4].value = this.activity; if (this.exclusive) { if (this.openStatus) { this.dataGroup.setBorderColor("#00FF00"); } else { this.dataGroup.setBorderColor("#FF0000"); } } }; this.drawData = function() { //BagComponent this.assignDisplayValues(); this.dataGroup.drawBasic(); }; this.defineGraphic = function(graphic) { this.graphic = graphic; }; this.updateGraphic = function() { this.graphic.setTraverseValue(this.countInProcess); this.graphic.setCountValue(this.countInBag); //if (this.exclusive) { // if (this.openStatus) { // this.graphic.setBorderColor("#00FF00"); // } else { // this.graphic.setBorderColor("#FF0000"); // } //} }; this.isOpen = function() { //BagComponent if (this.exclusive) { if (this.currentCount() < this.maxCapacity) { this.openStatus = true; } else { this.openStatus = false; } for (var i = 0; i < this.previousComponentCount; i++) { if (this.previousComponentList[i].getComponentType() == "Path") { 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 } } } return this.openStatus; //if not exclusive should be set to true by default }; this.clearEntryDisplay = function() { //only clear display if a new one hasn't started a new timer if (globalSimClock >= this.endEntryDisplayTime) { this.entryTime = ""; this.entryEntityID = ""; } if (globalSimClock >= this.endAllDisplayTime) { this.activity = ""; } //displayProgressText("Bag entry "+this.componentID+" clears at time "+globalSimClock.toFixed(6)); }; this.clearExitDisplay = function() { //only clear display if a new one hasn't started a new timer if (globalSimClock >= this.endExitDisplayTime) { this.exitTime = ""; this.exitEntityID = ""; this.exitResidenceTime = ""; } if (globalSimClock >= this.endAllDisplayTime) { this.activity = ""; } //displayProgressText("Bag exit "+this.componentID+" clears at time "+globalSimClock.toFixed(6)); }; this.currentCount = function() { var count = 0; if (this.exclusive) { //start with entities already in component count = this.countInBag; //add entities in feeding paths for (var i = 0; i < this.previousComponentCount; i++) { 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 count += this.previousComponentList[i].currentCount(); } } } return count; }; this.pullFromPrevious = function() { //BagComponent var oldest = this.previousComponentList[0].getForwardAttemptTime(); var oldestIndex = 0; for (var i = 1; i < this.previousComponentCount; i++) { var age = this.previousComponentList[i].getForwardAttemptTime(); if (age < oldest) { oldestIndex = i; } } if (this.previousComponentList[oldestIndex].getComponentType() != "Path") { if (this.previousComponentList[oldestIndex].getComponentType() != "Entry") { //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 this.previousComponentList[oldestIndex].forwardEntity(this.componentID); } } else { displayProgressText("Bag comp. " + this.componentID + " pulls from previous (" + oldestIndex + ") at time " + globalSimClock.toFixed(6)); this.previousComponentList[oldestIndex].pullFromPrevious(this.componentID); } }; this.nextOpen = function() { var startIndex = this.nextComponentIndex; var tempIndex = startIndex; do { tempIndex++; if (tempIndex >= this.nextComponentCount) { tempIndex = 0; } if (this.nextComponentList[tempIndex].isOpen()) { //open link found, update and return nextComponentIndex return tempIndex; } } while (tempIndex != startIndex); return -1; //no open links found, leave nextComponentIndex unchanged }; this.processComplete = function(entity) { //BagComponent this.countInProcess--; //TODO: ensure handled properly if process time is zero //prob. not applicable //figure out which entity just finished processing var tempID = entity.entityID; this.exitQueue.unshift(entity); this.entityQueue[entity.getLocalIndex()] = null; entity.setForwardAttemptTime(globalSimClock); displayProgressText("Bag comp. " + this.componentID + " entity: " + tempID + " processed at " + globalSimClock.toFixed(6)); this.forwardEntity(); //try to forward it }; this.startSubJourney = function(subEntity) { this.startSubComponent.receiveEntity(subEntity); this.subEntityQueue[subEntity.parentEntity.getLocalIndex()] = null; }; this.continueFromSubJourney = function(subEntity) { this.subEntityQueue[subEntity.parentEntity.getLocalIndex()] = null; this.processComplete(subEntity.parentEntity); removeEntityFromList(subEntity.getEntityID()); //be sure to destroy the subEntity }; this.returnFromSubJourney = function(subEntity) { this.subEntityQueue[subEntity.parentEntity.getLocalIndex()] = subEntity; if (this.spawnDepartDelayTime > 0.0) { advance(this.spawnDepartDelayTime, this, "endSubDepartDelay", subEntity); } else { this.continueFromSubJourney(subEntity); } }; //##default parameters## //this.forwardEntity = function(destIndex = -1) { //BagComponent //this.forwardEntity = function() { //BagComponent ///var routingTable = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : -1; this.forwardEntity = function(destIndex) { //BagComponent if (typeof destIndex === "undefined") {destIndex = -1;} var dest = -1; if (destIndex >= 0) { //pull request from a specific downstream component, must send entity there if (this.routingMethod == 1) { //single connection, nothing to do dest = 0; } else if (this.routingMethod == 2) { //distribution, send to any request dest = 0; while ((this.nextComponentIDList[dest] != destIndex) && (dest < this.nextComponentCount)) { //second test should not be needed, loop can't fail to return valid result dest++; } } else if (this.routingMethod == 3) { //model routing logic, TODO: don't forward if not desired destination dest = 0; while ((this.nextComponentIDList[dest] != destIndex) && (dest < this.nextComponentCount)) { //second test should not be needed, loop can't fail to return valid result dest++; } } dummy2 = 0; } else { if (this.routingMethod == 1) { //single connection if (this.nextComponentList[0].isOpen()) { dest = 0; } } else if (this.routingMethod == 2) { //distribution var nextIndex = this.nextOpen(); if (nextIndex >= 0) { dest = nextIndex; //this.nextComponentIndex = dest; } } else if (this.routingMethod == 3) { //model routing logic if (this.savedDestination >= 0) { dest = this.savedDestination; } else { dest = 0; var test = Math.random(); //need access to entity type but can't pop it off queue here var index = this.countInQueue - 1; if (index >= 0) { index = entityDiversionPercentIndex(this.entityQueue[index]); //get head item in queue and find out what type it is } else { index = 0; //nothing in queue, following code will work but nothing will be popped and processed below } while (test > this.routingTable[index][dest]) { dest++; } if (dest <= this.nextComponentCount) { if (!this.nextComponentList[dest].isOpen()) { dest = -1; } } else { alert("Bag comp. tried to assign destination with too high of an index") } if (dest >= 0) { this.savedDestination = dest; //ensure that once destination is determined for this entity that we don't keep changing it } } } else { //0 uninitialized or anything else alert("comp. " + this.componentID + " incorrect routing method: " + this.routingMethod); } } if (dest >= 0) { if (this.countInBag > this.countInProcess) { var entity = this.exitQueue.pop(); //TODO-: are we testing to ensure the next entity is really available if (entity) { //TODO-: since we've tested above this should not be necessary //calculate how long item was in process this.exitResidenceTime = globalSimClock - entity.getLocalEntryTime(); this.exitTime = globalSimClock; this.exitEntityID = entity.entityID; this.activity = "forward entity"; this.endExitDisplayTime = globalSimClock + this.displayDelay; this.endAllDisplayTime = this.endExitDisplayTime; advance(this.displayDelay, this, "clearExitDisplay"); displayProgressText("Bag comp. " + this.componentID + " forwards entity: " + this.exitEntityID + " at time " + globalSimClock.toFixed(6)); this.countInBag--; //should be open now if (this.exclusive) { displayProgressText("Bag comp. " + this.componentID + " calls pull from previous at time " + globalSimClock.toFixed(6)); if (!this.openStatus) { 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 } } this.isOpen(); this.nextComponentIndex = dest; this.savedDestination = -1; //clear old choice when entity successfully forwarded this.nextComponentList[dest].receiveEntity(entity); //record stats if (this.nextComponentList[dest].getComponentGroup() != entity.getComponentGroup()) { //truly leaving a component group along the current connection recordGroupStatsWrapper(this.componentGroup, entity.getComponentGroupEntryTime(), entity); } } } } }; this.receiveEntity = function(entity) { //BagComponent //receive the entity entity.setLocalEntryTime(); //record time entity entered bag if (entity.getComponentGroup() != this.componentGroup) { entity.setComponentGroup(this.componentGroup); entity.setComponentGroupEntryTime(globalSimClock); recordGroupStatsSystemEntryWrapper(this.componentGroup,entity); } //figure out which parking space to use var i = 0; while (this.entityQueue[i] != null) { i++; } if (i < this.maxCapacity) { this.entityQueue[i] = entity; entity.setLocalIndex(i); } else { //this shouldn't happen alert("Bag comp. "+this.componentID+" over capacity at time "+this.globalSimClock.toFixed(6)); } entity.setForwardAttemptTime(Infinity); //TODO: figure out how to handle this entity.setPermission(false); //entity has reached end of related components group, permission no longer matters this.countInProcess++; this.countInBag++; //TODO: handle if process time is zero? this.isOpen(); //display what was done this.entryTime = globalSimClock; this.entryEntityID = entity.entityID; this.activity = "receive entity"; //set timer to clear the display after a bit this.endEntryDisplayTime = globalSimClock + this.displayDelay; this.endAllDisplayTime = this.endEntryDisplayTime; advance(this.displayDelay, this, "clearEntryDisplay"); //set timer for the process duration // var pTime = this.processTime[entityProcessTimeIndex(entity,this.processTimeSwitch)]; if (!this.spawnFlag) { var pTime = processTime(entity); advance(pTime, this, "processComplete",entity); } else { //spawn subordinate entity var subEntity = generateNewEntity(entity); //reference to parent entity assignEntityTypesSub(subEntity); this.subEntityQueue[i] = subEntity; recordGroupStatsSystemEntryWrapper("SubSystem",subEntity); if (this.spawnArriveDelayTime > 0.0) { advance(this.spawnArriveDelayTime, this, "endSubArriveDelay", subEntity); } else { this.startSubJourney(subEntity); } } displayProgressText("Bag comp. " + this.componentID + " receives entity: " + this.entryEntityID + " at time " + globalSimClock.toFixed(6)); }; this.activate = function(nextState, entity2) { if (nextState == "clearEntryDisplay") { this.clearEntryDisplay(); } else if (nextState == "clearExitDisplay") { this.clearExitDisplay(); } else if (nextState == "processComplete") { this.processComplete(entity2); } else if (nextState == "endSubArriveDelay") { this.startSubJourney(entity2); } else if (nextState == "endSubDepartDelay") { this.continueFromSubJourney(entity2); } else { errorUndefinedAdvanceState(this.entityID, this.nextState); } }; //this.activate } //BagComponent |
Here are the new source and destination components:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
function StartSubJourneyComponent(parent) { setOfComponents.push(this); this.componentID = getNewComponentID(); this.componentType = "startSubJourney"; this.componentName = "startSubJourney"; this.nextComponent = null; this.parent = parent; this.exclusive = false; this.graphic = null; this.x1 = 0; this.y1 = 0; this.reset = function() { //do nothing }; this.assignNextComponent = function(next) { //StartSubJourneyComponent this.nextComponent = next; next.assignPreviousComponent(this); }; this.verifyLinks = function() { var error = ""; if (this.nextComponent) { //link exists if (typeof this.nextComponent === "object") { //link points to an object if ("componentType" in this.nextComponent) { //object contains member componentType if ((this.nextComponent.componentType == "Arrivals") || (this.nextComponent.componentType == "Entry")) { error += this.componentType + " comp. " + this.componentID + " next comp. is not an allowed comp.\n"; } } else { //linked object does not contain member componentType error += this.componentType + " comp. " + this.componentID + " next comp. does not have componentType\n"; } } else { //link points to something that is not an object error += this.componentType + " comp. " + this.componentID + " next comp. is not an object\n"; } } else { //link that should exist does not error += this.componentType + " comp. " + this.componentID + " next comp. does not exist\n"; } return error; }; this.getComponentID = function() { return this.componentID; }; this.getComponentType = function() { return this.componentType; }; this.getComponentName = function() { return this.componentName; }; this.setComponentName = function(componentName) { this.componentName = componentName; }; this.getExclusive = function() { return this.exclusive; }; this.defineGraphic = function(graphic) { this.graphic = graphic; //TODO: ensure location automatically set by return node in parent component }; this.updateGraphic = function() { }; this.assignLocation = function(x,y) { this.x1 = x; this.y1 = y; }; this.getLocation = function() { return {x: this.x1, y: this.y1}; } this.receiveEntity = function(entity) { this.nextComponent.receiveEntity(entity); }; } //StartSubJourneyComponent function ReturnFromSubJourneyComponent(parent) { setOfComponents.push(this); this.componentID = getNewComponentID(); this.componentType = "returnFromSubJourney"; this.componentName = "returnFromSubJourney"; this.parent = parent; this.exclusive = false; this.openStatus = true; this.previousComponentList = []; this.previousComponentCount = 0; this.previousComponentIndex = 0; this.graphic = null; this.x1 = 0; this.y1 = 0; this.reset = function() { //do nothing }; this.assignPreviousComponent = function(prev) { this.previousComponentList.push(prev); this.previousComponentCount++; this.previousComponentIndex = this.previousComponentCount - 1; }; this.verifyLinks = function() { var error = ""; var i; if (this.previousComponentCount > 0) { for (i = 0; i < this.previousComponentCount; i++) { //> if (this.previousComponentList[i]) { //link exists if (typeof this.previousComponentList[i] === "object") { //link points to an object if ("componentType" in this.previousComponentList[i]) { //object contains member componentType if ((this.previousComponentList[i].componentType == "Arrivals") || (this.previousComponentList[i].componentType == "Exit")) { error += this.componentType + " comp. " + this.componentID + " previous comp. list element " + i + " is not an allowed comp.\n"; } } else { //linked object does not contain member componentType error += this.componentType + " comp. " + this.componentID + " previous comp. list item " + i + " does not have componentType\n"; } } else { //link points to something that is not an object error += this.componentType + " comp. " + this.componentID + " previous comp. list item " + i + " is not an object\n"; } } else { //link that should exist does not error += this.componentType + " comp. " + this.componentID + " previous comp. list item " + i + " does not exist\n"; } } } else { error += this.componentType + " comp. " + this.componentID + " has index of zero previous components\n"; } return error; }; |
Here’s the code that defines the entire system:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 |
//schedule for seven hours of arrivals in half-hour blocks var arrivalSchedule = [0, 1, 2, 6, 7, 7, 8, 9, 7, 6, 4, 2, 1, 0]; 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]]; var arrival1 = new ArrivalsComponent(30.0, arrivalSchedule, entryDistribution); arrival1.defineDataGroup(2.0, 61, 2, 70, globalNeutralColor, globalValueColor, globalLabelColor); //leave in place var tempGraphic; var routingTable = [[1.0],[1.0],[1.0]]; var entry1 = new EntryComponent(routingTable); entry1.defineDataGroup(2.0, 90, 105, 80, globalNeutralColor, globalValueColor, globalLabelColor); //x,y,valuewidth,border,value,label entry1.setRoutingMethod(3); //1 single connection, 2 distribution logic, 3 model logic entry1.setComponentName("Entry1"); tempGraphic = new DisplayElement(entry1, 210, 5, 68, 20, 0.0, false, false, []); entry1.defineGraphic(tempGraphic); arrival1.assignNextComponent(entry1); var pathE1Q0A = new PathComponent(); pathE1Q0A.setSpeedTime(10.0, 1.0); tempGraphic = new DisplayElement(pathE1Q0A, 0, 0, 260, 37, 0.0, false, false, []); pathE1Q0A.defineGraphic(tempGraphic); entry1.assignNextComponent(pathE1Q0A); var pathE1Q0B = new PathComponent(); pathE1Q0B.setSpeedTime(10.0, 1.0); tempGraphic = new DisplayElement(pathE1Q0B, 260, 37, 0, 0, 0.0, false, false, []); pathE1Q0B.defineGraphic(tempGraphic); var routingTableQ0 = [[1.0],[1.0],[1.0]]; //not actually needed since routingMethod is 2 here var queue0 = new QueueComponent(0.0, Infinity, routingTableQ0); queue0.defineDataGroup(2.0, 90, 205, 80, globalNeutralColor, globalValueColor, globalLabelColor); queue0.setRoutingMethod(2); //1 single connection, 2 distribution logic, 3 model logic queue0.setComponentName("Q0"); queue0.setComponentGroup("Primary"); tempGraphic = new DisplayElement(queue0, 200, 50, 88, 56, 0.0, false, false, []); var tgBaseY = 25; //49; tempGraphic.addXYLoc(44, tgBaseY + 24); tempGraphic.addXYLoc(32, tgBaseY + 24); tempGraphic.addXYLoc(20, tgBaseY + 24); tempGraphic.addXYLoc(8, tgBaseY + 24); tempGraphic.addXYLoc(8, tgBaseY + 12); tempGraphic.addXYLoc(20, tgBaseY + 12); tempGraphic.addXYLoc(32, tgBaseY + 12); tempGraphic.addXYLoc(44, tgBaseY + 12); tempGraphic.addXYLoc(56, tgBaseY + 12); tempGraphic.addXYLoc(68, tgBaseY + 12); tempGraphic.addXYLoc(80, tgBaseY + 12); tempGraphic.addXYLoc(80, tgBaseY); tempGraphic.addXYLoc(68, tgBaseY); tempGraphic.addXYLoc(56, tgBaseY); tempGraphic.addXYLoc(44, tgBaseY); tempGraphic.addXYLoc(32, tgBaseY); tempGraphic.addXYLoc(20, tgBaseY); tempGraphic.addXYLoc(8, tgBaseY); queue0.defineGraphic(tempGraphic); pathE1Q0B.assignNextComponent(queue0); pathE1Q0A.assignNextComponent(pathE1Q0B); var pathQ0Q1 = new PathComponent(); pathQ0Q1.setSpeedTime(20, 1.0); tempGraphic = new DisplayElement(pathQ0Q1, 0, 0, 0, 0, 0.0, false, false, []); pathQ0Q1.defineGraphic(tempGraphic); queue0.assignNextComponent(pathQ0Q1); var pathQ0Q2 = new PathComponent(); pathQ0Q2.setSpeedTime(20, 1.0); tempGraphic = new DisplayElement(pathQ0Q2, 0, 0, 0, 0, 0.0, false, false, []); pathQ0Q2.defineGraphic(tempGraphic); queue0.assignNextComponent(pathQ0Q2); var pathQ0Q3 = new PathComponent(); pathQ0Q3.setSpeedTime(20, 1.0); tempGraphic = new DisplayElement(pathQ0Q3, 0, 0, 0, 0, 0.0, false, false, []); pathQ0Q3.defineGraphic(tempGraphic); queue0.assignNextComponent(pathQ0Q3); var routingTableQ123 = [[1.0],[1.0],[1.0]]; //not actually needed since routingMethod is 1 here var queue1 = new QueueComponent(3.0, 3, routingTableQ123); queue1.defineDataGroup(2.0, 5, 341, 80, globalNeutralColor, globalValueColor, globalLabelColor); queue1.setRoutingMethod(1); //1 single connection, 2 distribution logic, 3 model logic queue1.setExclusive(true); queue1.setComponentName("Q1"); queue1.setComponentGroup("Primary"); tempGraphic = new DisplayElement(queue1, 141, 131, 64, 36, 0.0, false, false, []); tgBaseY = 29; //53 tempGraphic.addXYLoc(32, tgBaseY); tempGraphic.addXYLoc(20, tgBaseY); tempGraphic.addXYLoc(8, tgBaseY); queue1.defineGraphic(tempGraphic); pathQ0Q1.assignNextComponent(queue1); var queue2 = new QueueComponent(3.0, 3, routingTableQ123); queue2.defineDataGroup(2.0, 175, 341, 80, globalNeutralColor, globalValueColor, globalLabelColor); queue2.setRoutingMethod(1); //1 single connection, 2 distribution logic, 3 model logic queue2.setExclusive(true); queue2.setComponentName("Q2"); queue2.setComponentGroup("Primary"); tempGraphic = new DisplayElement(queue2, 212, 131, 64, 36, 0.0, false, false, []); tgBaseY = 29; //53; tempGraphic.addXYLoc(32, tgBaseY); tempGraphic.addXYLoc(20, tgBaseY); tempGraphic.addXYLoc(8, tgBaseY); queue2.defineGraphic(tempGraphic); pathQ0Q2.assignNextComponent(queue2); var queue3 = new QueueComponent(3.0, 3, routingTableQ123); queue3.defineDataGroup(2.0, 175, 341, 80, globalNeutralColor, globalValueColor, globalLabelColor); queue3.setRoutingMethod(1); //1 single connection, 2 distribution logic, 3 model logic queue3.setExclusive(true); queue3.setComponentName("Q3"); queue3.setComponentGroup("Primary"); tempGraphic = new DisplayElement(queue3, 283, 131, 64, 36, 0.0, false, false, []); tgBaseY = 29; //53; tempGraphic.addXYLoc(32, tgBaseY); tempGraphic.addXYLoc(20, tgBaseY); tempGraphic.addXYLoc(8, tgBaseY); queue3.defineGraphic(tempGraphic); pathQ0Q3.assignNextComponent(queue3); var pathQ1P1 = new PathComponent(); pathQ1P1.setSpeedTime(20, 1.0); tempGraphic = new DisplayElement(pathQ1P1, 0, 0, 0, 0, 0.0, false, false, []); pathQ1P1.defineGraphic(tempGraphic); queue1.assignNextComponent(pathQ1P1); var pathQ2P2 = new PathComponent(); pathQ2P2.setSpeedTime(20, 1.0); tempGraphic = new DisplayElement(pathQ2P2, 0, 0, 0, 0, 0.0, false, false, []); pathQ2P2.defineGraphic(tempGraphic); queue2.assignNextComponent(pathQ2P2); var pathQ3P3 = new PathComponent(); pathQ3P3.setSpeedTime(20, 1.0); tempGraphic = new DisplayElement(pathQ3P3, 0, 0, 0, 0, 0.0, false, false, []); pathQ3P3.defineGraphic(tempGraphic); queue3.assignNextComponent(pathQ3P3); 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 var processTimeP123 = [10.0,20.8,13.0]; //fast, slow visitor, slow citizen or LPR var process1 = new ProcessComponent(processTimeP123, 0, 1, routingTableP123); process1.defineDataGroup(2.0, 5, 477, 80, globalNeutralColor, globalValueColor, globalLabelColor); process1.setExclusive(true); process1.setRoutingMethod(3); //1 single connection, 2 distribution logic, 3 model logic process1.setComponentName("P1"); process1.setComponentGroup("Primary"); tempGraphic = new DisplayElement(process1, 141, 192, 64, 36, 0.0, false, false, []); tgBaseY = 29; //53; tempGraphic.addXYLoc(32, tgBaseY); process1.defineGraphic(tempGraphic); pathQ1P1.assignNextComponent(process1); var process2 = new ProcessComponent(processTimeP123, 0, 1, routingTableP123); process2.defineDataGroup(2.0, 175, 477, 80, globalNeutralColor, globalValueColor, globalLabelColor); process2.setExclusive(true); process2.setRoutingMethod(3); //1 single connection, 2 distribution logic, 3 model logic process2.setComponentName("P2"); process2.setComponentGroup("Primary"); tempGraphic = new DisplayElement(process2, 212, 192, 64, 36, 0.0, false, false, []); tgBaseY = 29; //53; tempGraphic.addXYLoc(32, tgBaseY); process2.defineGraphic(tempGraphic); pathQ2P2.assignNextComponent(process2); var process3 = new ProcessComponent(processTimeP123, 0, 1, routingTableP123); process3.defineDataGroup(2.0, 175, 477, 80, globalNeutralColor, globalValueColor, globalLabelColor); process3.setExclusive(true); process3.setRoutingMethod(3); //1 single connection, 2 distribution logic, 3 model logic process3.setComponentName("P3"); process3.setComponentGroup("Primary"); tempGraphic = new DisplayElement(process3, 283, 192, 64, 36, 0.0, false, false, []); tgBaseY = 29; //53; tempGraphic.addXYLoc(32, tgBaseY); process3.defineGraphic(tempGraphic); pathQ3P3.assignNextComponent(process3); var pathP1X1 = new PathComponent(); pathP1X1.setSpeedTime(30, 1.0); tempGraphic = new DisplayElement(pathP1X1, 0, 0, 0, 0, 0.0, false, false, []); pathP1X1.defineGraphic(tempGraphic); process1.assignNextComponent(pathP1X1); var pathP2X1 = new PathComponent(); pathP2X1.setSpeedTime(30, 1.0); tempGraphic = new DisplayElement(pathP2X1, 0, 0, 0, 0, 0.0, false, false, []); pathP2X1.defineGraphic(tempGraphic); process2.assignNextComponent(pathP2X1); var pathP3X1 = new PathComponent(); pathP3X1.setSpeedTime(30, 1.0); tempGraphic = new DisplayElement(pathP3X1, 0, 0, 0, 0, 0.0, false, false, []); pathP3X1.defineGraphic(tempGraphic); process3.assignNextComponent(pathP3X1); var exit1 = new ExitComponent(); exit1.defineDataGroup(2.0, 90, 576, 80, globalNeutralColor, globalValueColor, globalLabelColor); exit1.setComponentName("Exit1"); tempGraphic = new DisplayElement(exit1, 210, 429, 68, 20, 0.0, false, false, []); exit1.defineGraphic(tempGraphic); pathP1X1.assignNextComponent(exit1); pathP2X1.assignNextComponent(exit1); pathP3X1.assignNextComponent(exit1); var pathP1Q10 = new PathComponent(); pathP1Q10.setSpeedTime(20, 1.0); tempGraphic = new DisplayElement(pathP1Q10, 0, 0, 0, 0, 0.0, false, false, []); pathP1Q10.defineGraphic(tempGraphic); process1.assignNextComponent(pathP1Q10); var pathP2Q10 = new PathComponent(); pathP2Q10.setSpeedTime(20, 1.0); tempGraphic = new DisplayElement(pathP2Q10, 0, 0, 0, 0, 0.0, false, false, []); pathP2Q10.defineGraphic(tempGraphic); process2.assignNextComponent(pathP2Q10); var pathP3Q10 = new PathComponent(); pathP3Q10.setSpeedTime(20, 1.0); tempGraphic = new DisplayElement(pathP3Q10, 0, 0, 0, 0, 0.0, false, false, []); pathP3Q10.defineGraphic(tempGraphic); process3.assignNextComponent(pathP3Q10); var routingTableQ10 = [[1.0],[1.0],[1.0]]; //not actually needed since routingMethod is 2 here var queue10 = new QueueComponent(3.0, Infinity, routingTableQ10); queue10.defineDataGroup(2.0, 230, 353, 80, globalNeutralColor, globalValueColor, globalLabelColor); queue10.setRoutingMethod(2); //1 single connection, 2 distribution logic, 3 model logic queue10.setExclusive(false); queue10.setComponentName("Q10"); queue10.setComponentGroup("Secondary"); tempGraphic = new DisplayElement(queue10, 314, 253, 64, 48, 0.0, false, false, []); tgBaseY = 29; //53 tempGraphic.addXYLoc(32, tgBaseY + 12); tempGraphic.addXYLoc(20, tgBaseY + 12); tempGraphic.addXYLoc(8, tgBaseY + 12); tempGraphic.addXYLoc(8, tgBaseY); tempGraphic.addXYLoc(20, tgBaseY); tempGraphic.addXYLoc(32, tgBaseY); tempGraphic.addXYLoc(44, tgBaseY); tempGraphic.addXYLoc(56, tgBaseY); queue10.defineGraphic(tempGraphic); pathP1Q10.assignNextComponent(queue10); pathP2Q10.assignNextComponent(queue10); pathP3Q10.assignNextComponent(queue10); var pathQ10P10 = new PathComponent(); pathQ10P10.setSpeedTime(20, 1.0); tempGraphic = new DisplayElement(pathQ10P10, 0, 0, 0, 0, 0.0, false, false, []); pathQ10P10.defineGraphic(tempGraphic); queue10.assignNextComponent(pathQ10P10); var pathQ10P11 = new PathComponent(); pathQ10P11.setSpeedTime(20, 1.0); tempGraphic = new DisplayElement(pathQ10P11, 0, 0, 0, 0, 0.0, false, false, []); pathQ10P11.defineGraphic(tempGraphic); queue10.assignNextComponent(pathQ10P11); var routingTableP1011 = [[0.8,1.0],[0.8,1.0],[0.8, 1.0]]; var processTimeP1011 = [40.0,40.0,40.0]; //fast, slow visitor, slow citizen or LPR var process10 = new ProcessComponent(processTimeP1011, 0, 1, routingTableP1011); process10.defineDataGroup(2.0, 5, 477, 80, globalNeutralColor, globalValueColor, globalLabelColor); process10.setExclusive(true); process10.setRoutingMethod(3); //1 single connection, 2 distribution logic, 3 model logic process10.setComponentName("P10"); process10.setComponentGroup("Secondary"); tempGraphic = new DisplayElement(process10, 279, 326, 64, 36, 0.0, false, false, []); tgBaseY = 29; //53; tempGraphic.addXYLoc(32, tgBaseY); process10.defineGraphic(tempGraphic); pathQ10P10.assignNextComponent(process10); var pathP10X1 = new PathComponent(); pathP10X1.setSpeedTime(20, 1.0); tempGraphic = new DisplayElement(pathP10X1, 0, 0, 0, 0, 0.0, false, false, []); pathP10X1.defineGraphic(tempGraphic); process10.assignNextComponent(pathP10X1); pathP10X1.assignNextComponent(exit1); var process11 = new ProcessComponent(processTimeP1011, 0, 1, routingTableP1011); process11.defineDataGroup(2.0, 5, 477, 80, globalNeutralColor, globalValueColor, globalLabelColor); process11.setExclusive(true); process11.setRoutingMethod(3); //1 single connection, 2 distribution logic, 3 model logic process11.setComponentName("P11"); process11.setComponentGroup("Secondary"); tempGraphic = new DisplayElement(process11, 350, 326, 64, 36, 0.0, false, false, []); tgBaseY = 29; //53; tempGraphic.addXYLoc(32, tgBaseY); process11.defineGraphic(tempGraphic); pathQ10P11.assignNextComponent(process11); var pathP11X1 = new PathComponent(); pathP11X1.setSpeedTime(20, 1.0); tempGraphic = new DisplayElement(pathP11X1, 0, 0, 0, 0, 0.0, false, false, []); pathP11X1.defineGraphic(tempGraphic); process11.assignNextComponent(pathP11X1); pathP11X1.assignNextComponent(exit1); var pathP10X2 = new PathComponent(); pathP10X2.setSpeedTime(20, 1.0); tempGraphic = new DisplayElement(pathP10X2, 0, 0, 0, 0, 0.0, false, false, []); pathP10X2.defineGraphic(tempGraphic); process10.assignNextComponent(pathP10X2); var pathP11X2 = new PathComponent(); pathP11X2.setSpeedTime(20, 1.0); tempGraphic = new DisplayElement(pathP11X2, 0, 0, 0, 0, 0.0, false, false, []); pathP11X2.defineGraphic(tempGraphic); process11.assignNextComponent(pathP11X2); var exit2 = new ExitComponent(); exit2.defineDataGroup(2.0, 230, 576, 80, globalNeutralColor, globalValueColor, globalLabelColor); exit2.setComponentName("Exit2"); tempGraphic = new DisplayElement(exit2, 314, 400, 68, 20, 0.0, false, false, []); exit2.defineGraphic(tempGraphic); pathP10X2.assignNextComponent(exit2); pathP11X2.assignNextComponent(exit2); var globalProcessTimeSettings = [[5,7,9],[30,50,80]]; function processTimeBag1(entity) { var processTime; var globalIndex = 1; if (entity.getPropertyValue("Residency") == "Citizen") { processTime = globalProcessTimeSettings[globalIndex][0]; } else if (entity.getPropertyValue("Residency") == "LPR") { processTime = globalProcessTimeSettings[globalIndex][1]; } else if (entity.getPropertyValue("Residency") == "Visitor") { processTime = globalProcessTimeSettings[globalIndex][2]; } return processTime; } var routingTableB1 = [[1.0],[1.0],[1.0]]; //var processTimeB1 = [30.0,50.0,80.0]; //citizen, LPR, or visitor //var bag1 = new BagComponent(processTimeB1, 1, 12, routingTableB1); var bag1 = new BagComponent(processTimeBag1, 12, routingTableB1, true, 10.0, 10.0); bag1.defineDataGroup(2.0,5,300,100, globalNeutralColor, globalValueColor, globalLabelColor); bag1.setExclusive(true); bag1.setRoutingMethod(1); //1 single connection, 2 distribution logic, 3 model logic bag1.setComponentName("B1"); bag1.setComponentGroup("Parking Lot"); tempGraphic = new DisplayElement(bag1, 130, 253, 52, 90, 0.0, false, false, []); tgBaseY = 29; tempGraphic.addXYLoc(8, tgBaseY); tempGraphic.addXYLoc(20, tgBaseY); tempGraphic.addXYLoc(32, tgBaseY); tempGraphic.addXYLoc(44, tgBaseY); tempGraphic.addXYLoc(8, tgBaseY + 12); tempGraphic.addXYLoc(20, tgBaseY + 12); tempGraphic.addXYLoc(32, tgBaseY + 12); tempGraphic.addXYLoc(44, tgBaseY + 12); tempGraphic.addXYLoc(8, tgBaseY + 24); tempGraphic.addXYLoc(20, tgBaseY + 24); tempGraphic.addXYLoc(32, tgBaseY + 24); tempGraphic.addXYLoc(44, tgBaseY + 24); //end fixed spaces = maxCapacity tempGraphic.addXYLoc(26, tgBaseY + 52); //start spaces for exitQueue tempGraphic.addXYLoc(14, tgBaseY + 52); tempGraphic.addXYLoc(14, tgBaseY + 40); tempGraphic.addXYLoc(26, tgBaseY + 40); tempGraphic.addXYLoc(38, tgBaseY + 40); bag1.defineGraphic(tempGraphic); var pathP1B1 = new PathComponent(); pathP1B1.setSpeedTime(20,1.0); tempGraphic = new DisplayElement(pathP1B1, 0, 0, 0, 0, 0.0, false, false, []); pathP1B1.defineGraphic(tempGraphic); process1.assignNextComponent(pathP1B1); pathP1B1.assignNextComponent(bag1); var pathP2B1 = new PathComponent(); pathP2B1.setSpeedTime(20,1.0); tempGraphic = new DisplayElement(pathP2B1, 0, 0, 0, 0, 0.0, false, false, []); pathP2B1.defineGraphic(tempGraphic); process2.assignNextComponent(pathP2B1); pathP2B1.assignNextComponent(bag1); var pathP3B1 = new PathComponent(); pathP3B1.setSpeedTime(20,1.0); tempGraphic = new DisplayElement(pathP3B1, 0, 0, 0, 0, 0.0, false, false, []); pathP3B1.defineGraphic(tempGraphic); process3.assignNextComponent(pathP3B1); pathP3B1.assignNextComponent(bag1); var routingTableP20 = [[1.0],[1.0],[1.0]]; var processTimeP20 = [60.0,60.0,60.0]; //fast, slow visitor, slow citizen or LPR var process20 = new ProcessComponent(processTimeP20, 1, 1, routingTableP20); process20.defineDataGroup(2.0, 5, 477, 80, globalNeutralColor, globalValueColor, globalLabelColor); process20.setExclusive(true); process20.setRoutingMethod(1); //1 single connection, 2 distribution logic, 3 model logic process20.setComponentName("P20"); process20.setComponentGroup("Parking Lot"); tempGraphic = new DisplayElement(process20, 157, 368, 64, 36, 0.0, false, false, []); tgBaseY = 29; tempGraphic.addXYLoc(32, tgBaseY); process20.defineGraphic(tempGraphic); var pathB1P20 = new PathComponent(); pathB1P20.setSpeedTime(20,1.0); tempGraphic = new DisplayElement(pathB1P20, 0, 0, 0, 0, 0.0, false, false, []); pathB1P20.defineGraphic(tempGraphic); bag1.assignNextComponent(pathB1P20); pathB1P20.assignNextComponent(process20); var pathP20X1 = new PathComponent(); pathP20X1.setSpeedTime(20,1.0); tempGraphic = new DisplayElement(pathP20X1, 0, 0, 0, 0, 0.0, false, false, []); pathP20X1.defineGraphic(tempGraphic); process20.assignNextComponent(pathP20X1); pathP20X1.assignNextComponent(exit1); var startSubJourneyBag1 = new StartSubJourneyComponent(bag1); bag1.assignStartSubJourneyComponent(startSubJourneyBag1); tempGraphic = new DisplayElement(startSubJourneyBag1, 0, 0, 128, 263, 0.0, false, true, []); startSubJourneyBag1.defineGraphic(tempGraphic); //TODO: bury this assignment in the DisplayElement constructor var returnFromSubJourneyBag1 = new ReturnFromSubJourneyComponent(bag1); bag1.assignReturnFromSubJourneyComponent(returnFromSubJourneyBag1); tempGraphic = new DisplayElement(returnFromSubJourneyBag1, 128, 333, 0, 0, 0.0, true, false, []); returnFromSubJourneyBag1.defineGraphic(tempGraphic); var pathB1Z = new PathComponent(); pathB1Z.setSpeedTime(20,1.0); tempGraphic = new DisplayElement(pathB1Z, 128, 263, 50, 298, 0.0, false, false, []); pathB1Z.defineGraphic(tempGraphic); var pathZB1 = new PathComponent(); pathZB1.setSpeedTime(20,1.0); tempGraphic = new DisplayElement(pathZB1, 50, 298, 128, 333, 0.0, false, false, []); pathZB1.defineGraphic(tempGraphic); startSubJourneyBag1.assignNextComponent(pathB1Z); pathB1Z.assignNextComponent(pathZB1); pathZB1.assignNextComponent(returnFromSubJourneyBag1); |
Some adjustments had to be made to the DisplayElement object as well, to handle drawing the 2D and 3D versions of the new components.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
function DisplayElement(parent,x1,y1,w,h,angle,count,traverse,xylocs) { //TODO: include mechanisms for drawing paths here this.parent = parent; this.x1 = x1; this.y1 = y1; if ((this.parent.getComponentType() == "startSubJourney") || (this.parent.getComponentType() == "returnFromSubJourney")) { this.x2 = w; this.y2 = h; this.isJourney = true; this.isPath = false; } else if (this.parent.getComponentType() != "Path") { this.x2 = x1 + w; this.y2 = y1 + h; this.isJourney = false; this.isPath = false; } else { this.x2 = w; this.y2 = h; this.isJourney = false; this.isPath = true; } this.angle = angle; //not used for now, default to 0.0; this.index = this.parent.getComponentID(); this.nodeColor = globalNodeColor; var tempType = this.parent.getComponentType(); switch (tempType) { case "Queue": this.type = "Q"; break; case "Process": this.type = "P"; break; case "Entry": this.type = "E"; break; case "Exit": this.type = "X"; break; case "Bag": this.type = "B"; break; case "Stack": this.type = "S"; break; case "Control": this.type = "C"; break; default: this.type = "?"; //other types are never displayed this way } this.label = this.index + "-" + this.type + ": " +this.parent.getComponentName(); this.labelWidth = globalCTX.measureText(this.label).width; this.innode = true; this.outnode = true; if (this.parent.getComponentType() == "Entry") { this.innode = false; } else if (this.parent.getComponentType() == "Exit") { this.outnode = false; } else if (this.parent.getComponentType() == "Arrivals") { this.innode = false; } else if (this.parent.getComponentType() == "startSubJourney") { this.innode = false; } else if (this.parent.getComponentType() == "returnFromSubJourney") { this.outnode = false; } this.count = count; this.traverse = traverse; this.countValue = 0; this.traverseValue = 0; this.nodexi = w * 0.5; this.nodexo = this.nodexi; this.nodeyi = 0.0; this.nodeyo = h; this.locsCount = xylocs.length; this.entityLocs = []; this.component3D = null; //use this information to define a 3D display component for (var i=0; i<this.locsCount; i++) { this.entityLocs.push(xylocs[i]); } this.addXYLoc = function(xl,yl) { var loc = {x: xl, y: yl}; this.entityLocs.push(loc); this.locsCount++; }; this.setNeutralColor = function(nc) { this.neutralColor = nc; }; this.setTraverseValue = function(tv) { this.traverseValue = tv; }; this.setCountValue = function(cv) { this.countValue = cv; }; this.setStartPoint = function(x1,y1) { this.x1 = x1; this.y1 = y1; }; this.setEndPoint = function(x2,y2) { this.x2 = x2; this.y2 = y2; }; this.getInNode = function() { if (this.innode) { if (this.isJourney) { return {x: this.x1, y: this.y1}; } else if (!this.isPath) { return {x: this.x1+this.nodexi, y: this.y1+this.nodeyi}; } else { return {x: this.x1, y: this.y1}; } } else { alert("display element queried for non-existent incoming node"); return null; //in theory this should never happen } }; this.getOutNode = function() { if (this.outnode) { if (this.isJourney) { return {x: this.x2, y: this.y2}; } else if (!this.isPath) { return {x: this.x1+this.nodexo, y: this.y1+this.nodeyo}; } else { return {x: this.x2, y: this.y2}; } } else { alert("display element queried for non-existent outgoing node"); return null; //in theory this should never happen } }; this.defineColors = function(lc,vc,nc,nvc,rc,rvc,wc,wvc) { this.labelColor = lc; //text labels this.valueColor = vc; //text values this.neutralColor = nc; //non-exclusive path and component color this.neutralVertexColor = nvc; //non-exclusive wireframe color this.readyColor = rc; //exclusive open component or ready-to-go entity color this.readyVertexColor = rvc; //exclusive open component or ready-to-go entity vertex color this.waitingColor = wc; //exclusive closed component or in-process entity color this.waitingVertexColor = wvc; //exclusive closed component or in-process entity vertex color }; this.defineGlobalDefaultColors = function() { this.defineColors(globalLabelColor,globalValueColor,globalNeutralColor,globalNeutralVertexColor, globalReadyColor,globalReadyVertexColor,globalWaitingColor,globalWaitingVertexColor); }; this.defineGlobalDefaultColors(); this.drawBasic = function() { var borderColor; if (this.parent.getExclusive()) { if (this.parent.getOpenStatus()) { borderColor = this.readyColor; } else { borderColor = this.waitingColor; } } else { borderColor = this.neutralColor; } if (this.isJourney) { globalCTX.strokeStyle = borderColor; globalCTX.beginPath(); if (this.innode) { globalCTX.moveTo(this.x1-5+0.5,this.y1-5+0.5); globalCTX.lineTo(this.x1+4+0.5,this.y1-5+0.5); globalCTX.lineTo(this.x1+4+0.5,this.y1+4+0.5); globalCTX.lineTo(this.x1-5+0.5,this.y1+4+0.5); globalCTX.lineTo(this.x1-5+0.5,this.y1-5+0.5); } else { globalCTX.moveTo(this.x2-5+0.5,this.y2-5+0.5); globalCTX.lineTo(this.x2+4+0.5,this.y2-5+0.5); globalCTX.lineTo(this.x2+4+0.5,this.y2+4+0.5); globalCTX.lineTo(this.x2-5+0.5,this.y2+4+0.5); globalCTX.lineTo(this.x2-5+0.5,this.y2-5+0.5); } globalCTX.stroke(); //do nothing } else if (!this.isPath) { var runningHeight = 15; globalCTX.strokeStyle = borderColor; globalCTX.beginPath(); globalCTX.moveTo(this.x1+0.5,this.y1+0.5); globalCTX.lineTo(this.x2+0.5,this.y1+0.5); globalCTX.lineTo(this.x2+0.5,this.y2+0.5); globalCTX.lineTo(this.x1+0.5,this.y2+0.5); globalCTX.lineTo(this.x1+0.5,this.y1+0.5); globalCTX.stroke(); globalCTX.font = "12px Arial"; globalCTX.fillStyle = this.labelColor; globalCTX.textAlign = "center"; globalCTX.fillText(this.label,this.x1+this.nodexi,this.y1+runningHeight); runningHeight += 12; if (this.traverse) { globalCTX.textAlign = "right"; var waitChar = "P:"; if (this.parent.getComponentType() == "Queue") { waitChar = "T:"; } else if (this.parent.getComponentType() == "Process") { waitChar = "P:"; } globalCTX.fillText(waitChar,x1+15,this.y1+runningHeight); globalCTX.fillStyle = this.valueColor; globalCTX.textAlign = "left"; globalCTX.fillText(this.traverseValue,x1+17,this.y1+runningHeight); runningHeight += 12; } if (this.count) { globalCTX.fillStyle = this.labelColor; globalCTX.textAlign = "right"; globalCTX.fillText("Q:",x1+15,this.y1+runningHeight); globalCTX.fillStyle = this.valueColor; globalCTX.textAlign = "left"; globalCTX.fillText(this.countValue,x1+17,this.y1+runningHeight); runningHeight += 12; } } else { globalCTX.strokeStyle = borderColor; globalCTX.beginPath(); globalCTX.moveTo(this.x1+0.5,this.y1+0.5); globalCTX.lineTo(this.x2+0.5,this.y2+0.5); globalCTX.stroke(); } }; this.drawNodes = function() { if (this.isJourney) { if (this.innode) { drawNode(this.x1,this.y1,3,this.nodeColor); } if (this.outnode) { drawNode(this.x2,this.y2,3,this.nodeColor); } } else if (!this.isPath) { if (this.innode) { drawNode(this.x1+this.nodexi,this.y1+this.nodeyi,3,this.nodeColor); } if (this.outnode) { drawNode(this.x1+this.nodexo,this.y1+this.nodeyo,3,this.nodeColor); } } else { if (this.parent.previousComponent.getComponentType() == "Path") { drawNode(this.x1,this.y1,3,this.nodeColor); } if (this.parent.nextComponent.getComponentType() == "Path") { drawNode(this.x2,this.y2,3,this.nodeColor); } } }; this.drawEntities = function() { var i; var drawCount; var drawColor; if (this.isPath) { drawCount = this.parent.entityQueue.length; for (i=0; i<drawCount; i++) { var location = this.parent.entityQueue[i].getLocation(); drawNode(location.x,location.y,5,this.readyColor); drawNode(location.x,location.y,3,this.parent.entityQueue[i].getEntityColor()) } } else if (this.parent.getComponentType() == "Bag") { drawCount = this.parent.maxCapacity; //should be < this.entityLocs.length drawColor = this.waitingColor; for (i=0; i<drawCount; i++) { if (this.parent.entityQueue[i] != null) { var xx = this.entityLocs[i].x; var yy = this.entityLocs[i].y; drawNode(this.x1+xx,this.y1+yy,5,drawColor); drawNode(this.x1+xx,this.y1+yy,3,this.parent.entityQueue[i].getEntityColor()); if (this.parent.subEntityQueue[i] != null) { drawNode(this.x1+xx+3,this.y1+yy-3,5,drawColor) drawNode(this.x1+xx+3,this.y1+yy-3,3,this.parent.subEntityQueue[i].getEntityColor()); } } } drawCount = this.entityLocs.length - this.parent.maxCapacity; if (this.parent.exitQueue.length < drawCount) { drawCount = this.parent.exitQueue.length; } drawColor = this.readyColor; for (i=0; i<drawCount; i++) { //locs for exit queue in order from maxCapacity var xx = this.entityLocs[this.parent.maxCapacity + i].x; var yy = this.entityLocs[this.parent.maxCapacity + i].y; drawNode(this.x1+xx,this.y1+yy,5,drawColor); //exit queue items in reverse order drawNode(this.x1+xx,this.y1+yy,3,this.parent.exitQueue[this.parent.exitQueue.length-1-i].getEntityColor()); } } else if (this.parent.getComponentType() != "Arrivals") { var qCount = this.countValue - this.traverseValue; if (this.countValue > this.locsCount) { drawCount = this.locsCount; } else { drawCount = this.countValue; } for (i=0; i<drawCount; i++) { if (i < qCount) { drawColor = this.readyColor; } else { drawColor = this.waitingColor; } var xx = this.entityLocs[i].x; var yy = this.entityLocs[i].y; drawNode(this.x1+xx,this.y1+yy,5,drawColor); drawNode(this.x1+xx,this.y1+yy,3,this.parent.entityQueue[i].getEntityColor()); } } }; this.define3DComponent = function() { //when everything else is defined and verified, call this to build 3D component info list var faceColor; var vertexColor; if (this.parent.getExclusive()) { if (this.parent.getOpenStatus()) { faceColor = this.readyColor; vertexColor = this.readyVertexColor; } else { faceColor = this.waitingColor; vertexColor = this.waitingVertexColor; } } else { faceColor = this.neutralColor; vertexColor = this.neutralVertexColor; } if (this.isPath) { this.component3D = define3DPathComponent(this.x1,this.y1,this.x2,this.y2,faceColor); if (this.parent.nextComponent.getComponentType() == "Path") { //define a 3D node here, only at the end of the first path define3DNode(this.x2,this.y2,globalNodeColor,globalNodeVertexColor); } } else if (this.parent.getComponentType() != "Arrivals") { if (!this.isJourney) { &nb |