Sunday, October 25, 2020

Agent-Based Modeling in ExtendSim

 

Is it possible to build an agent-based simulation (ABS) model in ExtendSim? Certainly. We recently helped build a model of the intensive care unit (ICU) of a hospital. The purpose of the model was to study the impact of facility design. We used ExtendSim to compare two facility designs by looking at how nurses interact with each other when requesting patient care assistance. The model turned out to a good example of an ABS model, and it was straightforward to build in ExtendSim. 

Typical discrete event simulation (DES) models are process-based where entities flow through a defined set process. ABS models are a special case of DES models. ABS models use autonomous decision-making entities called agents where the agents make decisions based on a set of rules. In typical ABS models, the focus is on the agent behaviors.

The ICU model turned out to be a state diagram similar to the one shown below (please note that I have simplified the state diagram for illustrative purposes). The nurses are modeled as agents in the system. The nurse behavior is modeled using their states and the rules around why the nurse agents transition from one state to another. 


Sometimes, a nurse’s patient requests help, so the nurse agent transitions from idle to helping the patient. Other times, a nurse who is with the patient, requests help from another nurse that is currently idle. This forces a state change in two nurse agents. One nurse agent transitions from “I am helping my patient” to “another nurse is helping me.” Meanwhile, the nurse agent who is helping will transition from “idle” to “I am helping another nurse.” When the helping task is complete, both nurse agents transition back to their idle states and on with their next task.

This example is simple to build in ExtendSim once you understand the modeling components involved. This includes the ExtendSim database, a few advanced database features of which the link alert is the most important, and the Queue Equation block (all of these topics are covered in the Advanced ExtendSim course by the way).  What we discovered from this experience is that ExtendSim is a great tool to solve certain kinds of ABS models.

Thursday, July 2, 2020

Race Conditions

written by Dave Krahl, QMT Group
In computer science and engineering a race condition is "an undesirable situation that occurs when a device or system attempts to perform two or more operations at the same time, but because of the nature of the device or system, the operations must be done in the proper sequence to be done correctly". In discrete event simulation programs such as ExtendSim, a race condition is when multiple events happen at the same simulated time and the order of these events has an impact on the operation of the model. Because discrete event simulators process events at discrete times, race conditions are fairly common. There is no standard solution to this, and it is handled differently by the various simulation software programs. When an event occurs in a discrete event simulation model any number of actions can be triggered. The order of these actions can have a significant effect on the behavior of the model. A classic example is if a resource is released and the item (or entity) releasing that resource requests the same resource again and other items are waiting for that resource. Is the releasing item in contention for the resource?

ExtendSim has a number of features that provide additional control over the sequence and scheduling of events as well as the transmission of messages. These include:
  • Scheduling a 0 time event in an equation before it is evaluated. This provides the ability to delay the calculation of the equation and any subsequent messages sent by the equation returning control to the block that initiated the calculation. This can be implemented in custom blocks as well.
  • Detailed control of messages in the equation and custom blocks. Whether or not a connector responds to a message is a user-defined option.
  • In custom blocks, there are message handlers for every type of interaction. These can be used to control how other messages are sent out.
While there are numerous tools for solving race condition problems, the biggest challenge is detecting them in the first place. This often requires detailed inspection of the results of an event in the simulation. Some tools available for this in ExtendSim are:
  • Tracing of simulation execution
  • Enabling debugging code and in particular examining the "stack" of function calls and message handlers
  • Animation of item movement
  • Record Message block in the ExtendSim Utilities library shows sequences of messages
  • History block that shows item movement and properties.
Race conditions are an artifact of discrete event simulation as a technology. This issue is something that every experienced simulation modeler has encountered in their modeling experience. Identifying the race condition can be challenging. However, tools exist in simulation programs to address any race condition problems and control the execution of the model.

Saturday, February 1, 2020

Making a Backup Of your Model

It is an excellent idea to make a backup of your model from time to time.  This could be useful if you want to go back and open a previous model version.  In order to do that, you should periodically make a complete backup of your model and any additional files it might need.  You might not be able to run an old model if you don’t.  The complete archived model should include the same elements you would need to include if you sent the model to someone else to run.  Every model might not have all of these elements, but if they do, store them with that current version of the model.  The list is as follows:

  • Model
  • Custom libraries *
  • Custom Include files **
  • Pictures used for animation
  • External Data Files you are Importing from or Exporting to
* You don't need to backup the standard libraries which are installed with ExtendSim.  You only need to back up your custom libraries that are used in the model if you have any.  You might not have any but you will know it if you do.

** You don't need to backup the standard include files which are installed with ExtendSim.  You only need to back up your custom include files if you use any in custom block or the standard Equation blocks.

Consider one simple example of why you want to archive files along with the model itself.  Suppose we have an Excel workbook that is used to import data from the beginning of the run.  Let's say we have one tab for each of the input tables.  When we made a backup of the model, we did not back up anything other than the model.  Suppose we start working on the input data and made some changes to the model and the Excel workbook.  If we wanted to open the previous model and run it, we would have the archived model but we didn’t backup the spreadsheet so we would only have the updated spreadsheet.  The old model wouldn't understand what to do with this updated Excel file.  There would be a mismatch.  We would be able to open the model up in this case, but we couldn't run the model. 

The same concept applies to all the other files in the list above.  If we don't include them in the model backup, then when we go and open the backup model it may or may not work properly if there have been changes to the library files, include files, pictures, or data files.  These files can change over time as you enhance your model so it would be a great idea to keep a copy of these files with the model backup.
I use WinZip to make a complete backup of all the required files, but other tools could be used as well.  If you are working in a group of model developers, and everyone is working on the model, then something more advanced should be used which allows each user to "check in" changes on each individual file.  Source control tools can be used here.  The source control tools work well for keeping track of changes if the users document changes appropriately.

If you need to send your model to someone else to run, this same backup can be used.  Just don’t forget to include all necessary files. Your model might not contain all the files in this list, but if it does, then you will need to include it in the backup. 

Popular Posts