A Simple Discrete-Event Simulation: Part 69

Today I ticked one item off the To Do list and generally streamlined other parts of the code. The list item involved modifying the Queue component so it would smoothly handle situations when the traversal time is set to zero. If you don’t recall, this is the case when modeling abstract queues like those in data processing or business systems. Even if the time isn’t technically zero in those cases an entity is theoretically ready to be retrieved from a queue the instant it’s put in there. It takes a finite amount of time to traverse a physical queue in the real world. The solution involved calling the traverseComplete function directly in the receiveEntity function rather than putting the event into the future events queue.

You can tell it’s working as intended by noticing that the first entities drop right through the big, common Queue component (Q0) and never show a red waiting-to-traverse status even when they stack up during the run.

I originally thought this was going to be more complicated but once I recognized that I had a nicely compartmentalized traverseComplete function with all of the requisite logic the fix was obvious.

The things I cleaned up started with rationalizing the way I defined the display and movement parameters for Path components. I originally had two ways of generating the path displays: one based on each component’s built-in dataGroup object and one for each component’s graphics object. It turns out that the initialization process was using a goofy mix of techniques so I changed things so the locations are all specified in the graphics object and then transferred to the core component object. The last part is important because the actual movement is calculated in the core component object.

Another thing I streamlined was the definition of the graphics objects in the form of the DisplayElements constructor. I modified it so it obviated the need to supply flags for whether the incoming and outgoing nodes exist, since this can be determined automatically based on the parent component’s type, and I also added an automatic call to its defineGlobalDefaultColors method so it doesn’t have to be invoked externally every time.

I turned off the display of the Arrivals component to save some space and sped up a couple of other items that aren’t otherwise interesting enough to describe.

Here’s the new setup code. Not that you’d notice, but it is a little shorter and cleaner.

I noticed that the arrival schedule and entry distribution arrays are only defined for seven hours (14 x 30 min or 420 min total) while the simulations is allowed to run for ten hours (20 x 30 min or 600 min total). This doesn’t apear to be an issue since all entities are injected into the system within the first seven hours, but I’ll add a To Do item to review it.

Right now we have array parameters with multiple dimensions defined by time (schedule intervals) for the arrival items and for processing time and diversion percentage based on entity type. It’s possible to do both things but it’s only practical to implement if good data can be collected to drive the process. For now we’ll keep things simple and be satisfied that we’ve demonstrated the capability.

Here’s the updated To Do List:

  • Review handling of arrival schedule and entry distribution arrays beyond period where they’re defined
  • Standardize linking and exclusivity process
  • Resolve and standardize new vs. advance issue
  • Rework drawing of Path components so correct elements are always on top
  • New property for forward exclusivity as opposed to receiving exclusivity.
  • Formalize and implement method of receiving from multiple upstream components in turn. Implementing and observing this may illuminate the behaviors that will need to be implemented for the general path solution described in one or more previous posts.
  • Rework the Queue mechanism to flexibly handle finite-traversal time and zero-traversal time configurations
  • Revisit distribution logic to make sure it’s cycling the way it should be.
  • Learn JavaScript’s prototype object pattern and re-implement everything in that in place of the closure pattern I’ve been using; I’ll want to bite that bullet before this thing goes much farther
  • Add Control, Bag, and Stack components
  • Expand function of Process components to handle multiple entities in parallel, in effect making a single component function as if it were multiple, associated ones
  • Discrete-event simulation frameworks often include the concept of sets (logical containers that that be iterated and compared for intersection and so on, so that idea should be implemented; this would expand on things were doing now with lists of components and entities; the need for this was inspired by thinking about the bag data structure in general
  • Ponder the idea of implementing a combined Queue-Process component
  • Expand Path component representation so it can incorporate multiple line segments
  • Add ability to sense reaching tail end of FIFO queue based on stopping to wait on a Path component; collect statistics accordingly (possibly add wait flag to entities so they can test against the next entity in line)
  • Look into creating a zero-duration, zero-queue decision component
  • Create standardized routing mechanism (to components of different types) based on process logic (vs. distribution logic to multiple components of the same type)
  • Add a test to verify that valid routes exist to support all required paths that may be taken by different types of entities.
  • Add a test to automatically assign downstream distribution mechanisms. See if the need for this isn’t actually obviated at some point.
  • Implement mechanism to identify combinations of related components into groups (e.g., a group of tollbooths represent a single toll plaza)
  • Gather and report system-, component-, and group-level statistics
  • Add ability to stream large volumes of output information which can be post-processed and quantified via a parsing mechanism; this is necessary for advanced statistical characterization
  • Streamline the process of defining the endpoints of Path components (i.e., attach standard nodes to other components and connect to those automatically, which will greatly save on the number of x,y locations the designer must specify manually)
  • Add an edit mode that allows designers to change component properties interactively (ultimately including being able to drag them)
  • Use the new, completely external mechanism for displaying component data
  • Describe how abstract representation can be used to represent detailed layouts and interactions; include ability to flag or alarm situations which would cause conflicts in the real world that would not necessarily be captured in a model unless specifically tested for
  • Add the ability to graph outputs as part of reporting
  • Add scrolling, animated graphs to illustrate progress as simulations run
  • Include ability for users to call up component and entity status by written or graphical display interactively while runs are in progress
  • Create streamlined graphical representations of all component types; create data display for Path components
  • Add ability to display entities inside relevant non-path components
  • Abstract the current x,y locations of all elements and scale them to the screen so the user can zoom in and out
  • Employ three.js framework to render models in 3D. Also consider piping this output through the associated VR framework.
  • Improve how type is displayed for 2D entities
  • Improve how status is displayed for 2D entities
  • Modify 3D entities to reflect entity type as well as status
  • Add ability for users to interactively change things during runs
  • Add Monte Carlo mechanisms to various timing and routing events (beyond what’s already been demonstrated)
  • Allow designer to build Monte Carlo and other distributions from acquired data using standardized tools
  • Incorporate Monte Carlo dithering or explicit curve shape for distributions
  • Add ability to perform multiple runs and statistically quantify generated outputs
  • Make simulation display update at regular intervals of simulated time rather than intervals defined by individual events; also make this “speed” scalable
  • Include ability to add arbitrary graphic elements to models (labels, keys, tables, etc.)
  • Include ability to display an underlay “below” the model display (e.g., a floor plan of a modeled process)
  • Allow user to turn off display and run model in “fire-and-forget” mode where it generates results without wasting time redrawing graphics.
  • Allow user to selectively turn different display elements on and off
  • Create suite of test configurations to exercise every combination of connections and support regression testing.
  • Add ability to assign open/close schedules for components and groups
  • Add ability to introduce multiple types of entities in model with different processing rules for routing and timing
  • Add ability to combine multiple queues into a single, logical unit
  • Add ability to adapt standard base components to represent varied and specialized things (this applies mostly to Process components)
  • Add ability to save and restore model definitions (in files/XML and in databases, requires PHP/MySql, Node.js or other back end capability)
  • Add ability to represent more abstract processes:
    • Reintroduce wait..until mechanism that uses the current events queue
    • Include pools of resources that are needed by different processes
    • Implement non-FIFO queues or collections that receive and forward entities based on arbitrary (user-defined) criteria
    • Include ability to accept events that happen according to fixed schedules rather than random ones (e.g., to match observed data)
    • Include the ability to change representation of entities and components to represent state changes (by color, shape, labels, flags, etc.)
    • Support input and editing of modular packages of information used to define and drive models
    • Add ability to represent BPM processes using standard BPMN notation
  • Really complex stuff
    • Develop more complex, arbitrary node-and-link representation of model, which brings up worlds of complications on its own!
    • Polish related sections of code and break them into modules which can be included on a modular basis
    • Make modules and examples distributable for use by a wider community
    • Make entities be active rather than passive, retain some intelligence in the components
      • Write documentation for modules as needed
      • Share on GitHub
      • Create dedicated project page on my website
      • Update and enhance my custom Graph component as well as the simulation framework
  • Re-implement this system in a more appropriate language like C++ or at least Java
This entry was posted in Simulation and tagged . Bookmark the permalink.

Leave a Reply