A Simple Discrete-Event Simulation: Part 28

Today I added a queue component, so the entities are generated by the Arrivals component, inserted at the Entry component, and forwarded to the Queue component. At this point the processes are all instantaneous, but they will get more interesting when the Process component is added tomorrow. It is assumed that the process represented by the Process component will not be instantaneous.

(Click on the “Step” button to advance through the model, refresh the page to run it again.)

Here’s the code for the Queue component, which contains the methods needed to receive and forward entities. The forwarding mechanisms have been added to the Entry component as well. The Queue component has code for forwarding items but I haven’t activated it yet. It does the following important things:

  • It maintains and displays a count of the number of items in the queue.
  • It stores the actual entities received in a local queue structure, which adds received entities to one end of the queue and takes forwarded entities off the other end of the queue.
  • It updates the entity elements with time stamps for when they enter and exit the queue. (Again, the exit mechanism is not yet used so all arriving entities just pile up in the queue.)

The Queue component clears its entry and exit information independently after two seconds, unless its data has been overwritten by the processing of a newer entity. This is the same thing I did for the Entry component but this has not been done for the Arrivals component. In truth I’m thinking none of the clearing operations are necessary, I just had a feeling they would make it easier to trace things visually as I was building the mechanism. I will probably switch off this behavior once I’m sure everything is working the way I’d like it to.

The messages have been updated and reordered a bit so everything is more consistent and easier to follow.

The Arrivals component actually destroys itself at the end of the simulation, and I should probably do that for the other components as well.

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

Leave a Reply