A Simple Discrete-Event Simulation: Part 29

Today I added a Process component. This component is meant to represent a process that takes some amount of time to complete. The time could be zero and there can be other side effects, which usually involve changing properties of the entities being processed, but the time consumed is almost always the salient feature.

The Process component works almost exactly like the Queue component, including the incorporation of the internal array that can hold multiple entities. I don’t do anything special with this yet, but this capability is in place to support special processes of which I’m aware (e.g., a stacked booth where entity A enters first, followed by entity B, and where their process times are independent; if A finishes first it can leave right away but if B finishes first it has to wait for A). For the current implementation the Process component can work with only a single entity at a time.

I also modified the handoff of entities between components. When an entity gets to the far end of a Queue component (which happens instantaneously at present), it queries the next component (the Process component) to see if it can accept an entity. If it can then the entity is passed downstream. If it cannot then nothing happens. On the other end, the downstream component, when it becomes able to accept a new entity, queries the upstream entity to pull the next entity if one is available. This push-pull mechanism requires links to be stored in both directions, and may also be generalized as the mode of connections between all components.

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

Here’s the code for the Process component.

Here’s the code that initializes all the components.

The processing time was set to nine seconds so we can watch a nice collection of entities build up in the queue but which allows the system to completely empty out by the end of the simulation. Once the queue is continually not empty the process is engaged continuously.

Stepping through the simulation in this mode takes some patience, so once I get the Exit component incorporated I’m going to change things up a bit.

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

Leave a Reply