A Simple Discrete-Event Simulation: Part 26

Having sorted out the internal reference issues in JavaScript I could go ahead and post the next update to the model framework. In this iteration the entities are completely passive, which means that the newly created entities are generated using a secondary puck within the ArrivalsComponent element. Repeatedly clicking on the “Step” button advances through the events one by one, up to 360 minutes. (40-ish clicks, refresh the browser to reset.)

I’ve included the code for the ArrivalsComponent element to show how the two pucks cooperate. Pucks become inactive when they aren’t reinserted into the future events queue (or the current events queue, but we’ll get back to that later). The main puck, the one associated with the blockIncrement method, is recycled every 30 minutes through the entire duration of the simulation. The secondary puck, associated with the makeEntity method, is reactivated as needed during every 30-minute cycle, and is recycled until all of the arrivals for that interval are created.

The newly created entities should be forwarded to some other location (i.e., actually injected into the model), and I’ve left a comment and blank line as a placeholder. This will get filled in as I create the other component types.

Right now I’m redrawing the display every time the activate method is called (at the end, after the work has been done) but later this operation will have to be called externally, so the displays for every element in the model can be redrawn during every update.

Finally, I cleaned up a few things to better follow JavaScript’s preferred naming conventions, use of ending semi-colons, and a few other things as suggested by WebStorm. (I maintain a full personal license for all of JetBrains‘ products.)

Here’s the code for the ArrivalsComponent itself.

Here are a couple of supporting items that need to be declared first.

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

Leave a Reply