A Simple Discrete-Event Simulation: Part 41

Today I took a step back to slightly simpler version of the simulation that uses the original version of the Path components (the ones that have the nodes built into them and act like standalone components). I took two steps forward, however, in that I added new complexity to the framework by providing the ability to include multiple entry points and the ability to either step through the simulation or run it so it steps through the simulation automatically. I also added the ability to pause the simulation when it’s running automatically.

Up to now I’ve assumed that components can only be linked together in one line; each component was linked to exactly one subsequent and/or one previous component. I started to allow for more arbitrary constructions when I developed separate nodes that could be linked to multiple incoming or outgoing paths. We aren’t using independent nodes here so we have to recreate that capability using the components we do have. We can start by allowing the Arrivals component to be linked to multiple Entry components. You can see this in the demo; there is one Arrivals component and two Entry components. Each Entry component is linked to a separate Path component and each Path component is then linked to the single Exit component. It’s a pretty simple setup, but it includes everything needed to illustrate the principle.

The code for the Arrivals component includes a few changes. We’ve eliminated the single value for nextComponent and replaced it with an array of values called entryList. This allows the Arrivals component to be linked to as many Entry components as desired.

We’ve also added an additional input parameter to the constructor or initial call, in the form of an entryDistributionArray. This array should have as many primary members as there are time slices in the model (we’ve been going with twelve time slices of thirty time units each). Each member of the array should itself be an array with as many members as there are linked Entry components. This information is used in the forwardEntity method in the following way. The values in the secondary dimension of the array represent the cumulative chance that any given entity arrives at that Entry component, ranging from 0.0 to 1.0 and always increasing. We initialize each array to have values of 0.7 and 1.0, which means that 70 percent of the entities will be forwarded to the first Entry component while the other 30% will be forwarded to the second Entry component. If we had assigned five possible Entry components we might specify a secondary array of [0.4,0.45,0.6,0.9,1.0], which means that Entry components one through five would be expected to receive 40, 5, 15, 30, and 10 percent of the generated entries, respectively. The actual selection is based on the result of a call to Math.random(), which generates a value between 0.0 (inclusive) and 1.0 (not inclusive).

That’s really all there is to it. At this point none of the other components had to be changed. That said, I did add a counter to each Entry component to keep track of the number of arriving entities routed to each. Since I assigned values of 0.7 and 1.0 for each of the 12 time slices we would expect roughly two-thirds of the entities to arrive through the first (left hand) entry components. Since the results are generated randomly and the browser (I tested this only on Firefox and Safari) doesn’t reset the random number seeds when I refresh the page to rerun the model, the exact distribution varies a little bit between runs.

Here’s the code that initializes everything, including the division of arrivals by Entry component.

We’ve assigned the diversion percentages for the arrivals (from the Arrivals component to the various Entry components) by time slice but there may not be a need to add that much complexity. If the division by entry point doesn’t change over time then a single set of values could be used just as easily. I’ve worked with some very complex models that made this assumption.

Tomorrow I’ll continue adding complexity by adding the ability to specify multiple destinations to at least one other component type.

Finally, I will also see if I can’t allow the user to reinitialize and rerun the simulation without having to refresh the whole browser page.

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

Leave a Reply