A Simple Discrete-Event Simulation: Part 27

Today I made a few tweaks, but the main thing was adding an Entry component and a means of moving entities through the model. Remembering that the entities are entirely passive, the components must be able to hand entities off to the next component, know what the next component is, and receive entities from the previous component.

First, here’s the model itself, which takes 80 or so clicks to run to the end.

Here’s the code for the entry component, which contains the methods needed to receive and forward entities. The forwarding mechanisms have clearly been added to the Arrivals component as well.

The only interesting thing the entry component does is clear its data display after two seconds, unless its data has been overwritten by the arrival of a newer entity.

The lines that initialize the components are here.

I also had to modify the function that displays formatted data, to make sure the desired formats are appropriate for the type of data expected. This came up when functions like toFixed and toPrecision choked when I assigned empty strings to generate a blank display. The fact that JavaScript is weakly typed makes it possible to do and one gets tempted to take advantage of such features.

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

Leave a Reply