After finishing our reading assignment, let’s just jump right into simulations. In this discussion I want you to tell me briefly how would you design a simulation project to study COVID-19 spread on a university campus. The general goal is obvious – try to predict how quickly would the disease spread under various scenarios.
Questions to keep in mind: What elements would your simulation model? What things do you think are important to consider, and how do you think we can implement them? What would be the inputs into your simulation? What parameters do you want to alter for “what if” scenarios?
Remember, this is our first week, we are not supposed to know much, so just show me your thought on the matter. I will not be grading harshly (as long as I see that you put some thought in it). Also, keep it brief (about a “page”), we do not want a full blown project yet.
The three methods in simulation modeling 1
By method in simulation modeling, we mean a general framework for mapping a
real-world system to its model. A method suggests a type of language, or “terms and
conditions” for model building. To date, there exist three methods:
• System Dynamics
• Discrete Event Modeling
• Agent-Based Modeling
The choice of method should be based on the system being modeled and the
purpose of the modeling – though often it is most heavily influenced by the
background or available tool set of the modeler. Consider Figure 2.1 where the
modeler is deciding how best to build a model of a supermarket. Depending on the
problem, he may: put together a process flowchart where customers are entities
and employees are resources; an agent-based model, where consumers are agents
affected by ads, communication, and interaction with agents-employees; or a
feedback structure, where sales are in the loop with ads, quality of service, pricing,
customer loyalty, and other factors.
Figure 2.1 The modeler chooses a modeling method
Stocks, flows,
feedbacks
Entities (agents),
resources, operations
Agents, behavior
rules, interaction
The Modeler
Advertising
Price
Sales
Loyalty
Arrivals Choosing
products
Checkout
Cashiers
Exit
Consumers
Ads
Staff
? ? ?
2 The Big Book of Simulation Modeling · Multimethod Modeling with AnyLogic 8
Sometimes, different parts of the system are best (meaning most naturally or
elegantly) modeled using different methods. In this case, a multi-method model is
built.
2.1. System dynamics
System dynamics is a method created in the mid-1950s by MIT Professor Jay
Forrester, whose original background was in science and engineering. Forrester’s
idea was to use the laws of physics, in particular the laws of electrical circuits, to
describe and investigate the dynamics of economic and, later on, social systems. The
principles and the modeling language of system dynamics were formed in the 1950s
and early 1960s, and remain unchanged today. Most of the definitions below are
taken from (System Dynamics Society, Inc., 2019), Wikipedia, and (Sterman, 2000).
System dynamics is a method of studying dynamic systems. It suggests that you
should:
• Take an endogenous point of view. Model the system as a causally closed
structure that itself defines its behavior.
• Discover the feedback loops (circular causality) in the system. Feedback loops
are the heart of system dynamics.
• Identify stocks (accumulations) and the flows that affect them. Stocks are the
memory of the system, and sources of disequilibrium.
• See things from a certain perspective. Consider individual events and
decisions as “surface phenomena that ride on an underlying tide of system
structure and behavior.” Take a continuous view where events and decisions
are blurred.
To feel the spirit of system dynamics (especially in the context of comparing
different modeling methods), consider a shop with a counterman serving the shop’s
clients. The more people come to the shop per hour, the longer the queue grows.
You can build a discrete event model that will give you the length of the queue as a
function of the clients’ arrival rate and the service time. However, in a real shop, as
the queue grows longer, some clients may decide not to join the queue, and instead
leave the shop. Others may decide to leave the queue after having waited longer
than they expected to. In other words, the length of the queue feeds back to inhibit
the rate of queue growth. The results of the “straightforward” model (sometimes
called open-loop models in the system dynamics community), will not be valid
unless it addresses these circular causal dependencies. One of the key advantages of
the system dynamics approach is to readily and elegantly identify such feedback
loops and include them into the model.
The three methods in simulation modeling 3
This section should not be considered an introduction to system dynamics. This is
just a glimpse into a complex area of study and we will provide just one possible
scenario of model building to illustrate the methodology. The recommended
reading is (Sterman, 2000), one of the best books ever written on modeling in
general.
Example 2.1: New product diffusion
Consider a company that starts selling a new consumer product. The addressable
market has a known size, which does not change over time. Consumers are sensitive
to both advertising and word of mouth. The product has an unlimited lifetime and
does not need replacement or repeated purchases. A consumer needs only one
product. We are to forecast the sales dynamics.
We will start with identifying the key variables in our model, and will iteratively
draw causal loop diagrams. In a causal loop diagram, variables are connected by
arrows showing the causal influences among them, with important feedback loops
explicitly identified. Causal loop diagrams are good for quickly capturing your
hypotheses about the causes of the dynamics in the system, and communicating it to
others (Sterman, 2000).
In our system, one of the variables is obviously Sales – the number of people who
bought our product per time unit, e.g. per week. The number of Potential Clients will
be the other variable. The bigger the market, the greater the sales; therefore, we can
draw a causal dependency from PotentialClients to Sales with positive polarity (see
Figure 2.2, A). On the other hand, as potential clients buy the product, they stop
being potential clients, so there is another influence from Sales back to
PotentialClients, this time with negative polarity. The feedback loop we have just
created is a negative, or balancing feedback loop: it works for reaching a certain goal.
In our case, we ultimately will sell the product to all potential clients, and both
variables will become zero.
What determines the sales rate? According to our assumptions, consumers are
sensitive to ads and to what other consumers say. So, we will distinguish between
sales from advertising, and sales from word of mouth. We introduce two new
variables and create two balancing loops instead of one, see Figure 2.2, B. The
SalesFromWordofMouth depend on the number of (hopefully happy) owners of our
product – our Clients. The number of clients grows with Sales. We draw another
feedback loop, this time positive, or reinforcing (see Figure 2.2, C).
4 The Big Book of Simulation Modeling · Multimethod Modeling with AnyLogic 8
Figure 2.2 System dynamics model of a new product diffusion
Sales
+
Potential
Clients
–
B
Sales
Potential
Clients
–
Sales from
Ad
Sales from Word
of Mouth
+
+
+
R
B
+
Sales
Potential
Clients
–
Sales from
Ad
Sales from Word
of Mouth
+ +
+
B
+
Clients
+
+
A
B
C
B
B
D Stock and flow diagram
A, B, C: Causal loop diagrams
R
Sales
Potential
Clients
Sales from
Ad
Sales from Word
of Mouth
+ +
+
B
+
Clients
+
B
Ad
Effectiveness Contact
Rate
Sales
Fraction
+
+
+
The three methods in simulation modeling 5
While the causal loop diagram we have drawn shows variable interdependencies
and feedbacks, it misses the clear mathematical interpretation, and therefore
cannot be simulated directly. One of the things that we need to do on our way to the
mathematical model is to identify stocks and flows among the variables in our
system. Stocks are accumulations, and characterize the state of the system. Flows
are the rates at which these system states change. Units of measure can help
identify stocks and flows. Stocks are usually quantities such as people, inventory,
money, and knowledge. Flows are measured in the same units per time period; for
example, clients per month, or dollars per year.
In our model, the stocks are PotentialClients and Clients, and the flow between them is
Sales. We can now draw a stock and flow diagram and write equations for our model.
The diagram is shown in Figure 2.2, D. The equations behind that diagram are:
Sales
dt
lientsPotentialCd
−
=
)(
Sales
dt
Clientsd
=
)(
ordofMouthSalesFromWdSalesFromASales +=
The first two equations are differential equations. They define how the stock values
change over time. For example, the number of Clients grows at the Sales rate. The
third equation tells that the sales rate consists of two sources, and those sources are
independent. The equations for those sources, however, are not clear from the
causal loop diagram, and we need to make more assumptions in order to define
them.
How big are the sales from advertising? Frank Bass, who originally developed this
model, assumed that the probability that a potential client will decide to buy as a
result of exposure to advertising is constant at each time period. Therefore, at each
period, advertising causes a constant fraction of potential clients to buy the product.
To reflect this in the model, we introduce a parameter, AdEffectiveness, which is a
fractional rate. The equation for the sales from advertising, therefore, is:
enessAdEffectivlientsPotentialCdSalesFromA ×=
The equation for the sales generated by word of mouth is common for any model of
diffusion, be it infectious disease, innovation, a new idea, or a new product. We
assume that the people in the community come into contact at a certain rate – say,
each person contacts ContactRate people per time unit. If a client contacts a potential
client, the latter will decide to buy with a certain constant probability, which we will
call SalesFraction. So, at each time unit, each client generates
6 The Big Book of Simulation Modeling · Multimethod Modeling with AnyLogic 8
ionSalesFract
ClientslientsPotentialC
lientsPotentialCeContactRat
×
+
×
sales. The middle component in this formula is the fraction of potential clients
among all people in the community – that is, the probability that a person being
contacted is a potential client. The formula for the sales from word of mouth, then,
is the following:
=rdofMouthSaleFromWo
ionSalesFract
ClientslientsPotentialC
lientsPotentialCeContactRatClients ×
+
××
Now the mathematical representation of the model is completed, and we are almost
ready to run the simulation.
The model-building scenario described above is just one of many possible scenarios.
For example, a modeler can start thinking in terms of stocks and flows right away
and not use the causal loop diagram at all, or generate it afterwards from the stock
and flow diagram. One could start with the positive feedback loop describing the
word-of-mouth effect, and then add the advertising influence. The choice of
additional assumptions and the corresponding parameters could also be different.
Before running the simulation, however, we need to specify the values of the
parameters and the initial values of the stocks. While the size of the market is
roughly known, and the number of clients is known for sure, the three parameters
that we have introduced in the last phase of model building cannot be measured
directly in the real system. One of the ways to determine the values of such
parameters is through model calibration. Calibration assumes you have reference
(historical) data, with which you can compare and fit the simulation output by
varying the model parameters.
Figure 2.3 shows the simulation results for the following parameter values:
• The size of the market is 10,000 people;
• At each time unit, 1.5% of potential clients buy the product because of
advertising;
• Each person contacts 100 other people per time unit;
• If a client contacts a potential client, the latter will buy the product with the
probability of 1.1%.
The three methods in simulation modeling 7
Figure 2.3 Output of the new product diffusion model
S-shaped curve of Client base (= cumulative Sales)
Bell-shaped curve of Sales and its components
AnyLogic system dynamics model at runtime
Sales curve if advertising is stopped shortly after the product launch
Ad off
8 The Big Book of Simulation Modeling · Multimethod Modeling with AnyLogic 8
The curve of the client base over time is S-shaped. This is a result of the interaction
of the two feedback loops. In the beginning, while the size of the market is still large,
the reinforcing word-of-mouth effect causes the exponential growth. Then, as the
market gets closer to saturation (meaning the system approaches its growth limit),
the balancing feedback loop starts to dominate and brings the system to the
equilibrium state: everybody who could buy the product has now bought it, and
sales are at zero.
The sales curve (Sales is derivative of the client base) is bell-shaped. You can
compare two scenarios; in the one at the very bottom of Figure 2.3, the advertising
is turned off shortly after the launch of the product, which has a surprisingly small
effect on sales.
Underlying mathematics and simulation engine
Mathematically, a system dynamics model is a system of coupled, nonlinear, first-
order differential equations
),()( PXF
dt
Xd
=
where X is a vector of stocks, P is a set of parameters, and F is a nonlinear
vector-valued function. Simulation of system dynamics models is done with
numerical methods that partition simulated time into discrete intervals of length dt
and step the system through time one dt at a time.
While numerical methods may be very sophisticated in the modeling tools used by
natural scientists and engineers (especially the ones with the adaptive variable time
step), the numerical methods used in system dynamics are simple, fixed-step
methods: Euler and Runge-Kutta. In addition to differential equations, the
simulation engine must be able to solve algebraic equations that appear in the
models with algebraic loops.
Unlike discrete event and agent-based models, system dynamics models are
deterministic, unless stochastic elements are explicitly inserted into them.
Abstraction level
System dynamics suggests a very high abstraction level and is positioned as a
strategic modeling methodology. In the models of social dynamics, epidemics, or
consumer choice, individual people never appear as well as individual product
items, jobs, or houses – they are aggregated into stocks (compartments) and
sometimes segmented into gender, education, income level, etc. (You have probably
noticed non-integer values such as 10.674 people or 0.24 cars in system dynamics
models during runtime.) Similarly, individual events like a purchase decision,
The three methods in simulation modeling 9
leaving a job, or recovery from a disease, are not considered – they are aggregated
in flows.
Although the language of system dynamics is very simple, if not primitive,
compared to other methods, thinking in its terms and on its level of abstraction is a
real art. System dynamics models are inevitably full of notions that do not have
direct material or measurable equivalents in the real world – for example, morale,
awareness, knowledge, and the impact of advertising. The choice of those notions,
and drawing the corresponding feedback structures, is not, in many cases, as
straightforward task as the design of a process flowchart or an agent behavior.
Software tools
System dynamics modeling is supported by four software tools: Vensim™,
AnyLogic™, iThink™/STELLA™, and Powersim™. The modeling language of system
dynamics is well-defined and minimalistic – there are no application-specific
dialects. Model conversion is possible between most pairs of tools, and vendors are
discussing using a standard XML-based language to be supported by everyone. The
tools differ in detail. For example, iThink™ offers special types of stocks like
Queue
or Oven, which are not present in other tools; Vensim™ and AnyLogic™ offer more
powerful and flexible arrays; etc.
2.2. Discrete event modeling
Discrete event modeling is almost as old as system dynamics. In October 1961, IBM
engineer Geoffrey Gordon introduced the first version of GPSS (General Purpose
Simulation System, originally Gordon’s Programmable Simulation System), which is
considered to be the first method of software implementation of discrete event
modeling. These days, discrete event modeling is supported by a large number of
software tools, including modern versions of GPSS itself.
The idea of discrete event modeling method is this: the modeler considers the
system being modeled as a process, i.e. a sequence of operations being
performed across entities.
The operations include delays, service by various resources, choosing the process
branch, splitting, combining, and some others. Since entities compete for resources
and can be delayed, queues are present in virtually any discrete event model. The
model is specified graphically as a process flowchart, where blocks represent
operations (there are textual languages as well, but they are in the minority). The
flowchart usually begins with “source” blocks that generate entities and inject them
into the process, and ends with “sink” blocks that remove entities from the model.
10 The Big Book of Simulation Modeling · Multimethod Modeling with AnyLogic 8
This type of diagram is familiar to the business world as a process diagram and is
ubiquitous in describing their process steps. This familiarity is one of the reasons
why discrete event modeling has been the most successful method in penetrating
the business community.
In AnyLogic, the entities (originally in GPSS they were called transactions) that are
flowing through the process flowchart, are actually agents – the same active items
you use in your agent-based models, see Section 1.3. Therefore, throughout this
book we will be using the term agent also for what traditionally is known as entity
or transaction. It makes a particular sense since AnyLogic agents (unlike entities in
other discrete event simulation software) are not just passive objects, they may
have active behavior.
Agents may represent clients, patients, phone calls, documents (physical and
electronic), parts, products, pallets, computer transactions, vehicles, tasks, projects,
and ideas.
Resources represent various staff, doctors, operators, workers, servers, CPUs,
computer memory, equipment, and transport.
Service times, as well as agent arrival times, are usually stochastic, drawn from a
probability distribution. Therefore, discrete event models are stochastic
themselves. This means that a model must be run for a certain time, and/or needs a
certain number of replications, before it produces a meaningful output.
The typical output expected from a discrete event model is:
• Utilization of resources,
• Time spent in the system or its part by an agent,
• Waiting times,
• Queue lengths,
• System throughput,
• Bottlenecks,
• Cost of the agent processing and its structure.
Example 2.2: Bank
Consider a bank with an ATM inside. The process in the bank is described as
follows:
• On average, 45 clients per hour enter the bank.
• Having entered the bank, half of the clients go to the ATM, and the other half
go straight to the cashiers.
• Usage of the ATM has a minimum duration of 1 minute, a maximum of 4
minutes, and a most likely duration of 2 minutes.
The three methods in simulation modeling 11
• Service with a cashier takes a minimum of 3 minutes and a maximum of 20
minutes, with a most likely duration of 5 minutes.
• After using the ATM, 30% of the clients go to the cashiers. The others exit the
bank.
• There are 5 cashiers in the bank, and there is a single shared queue for all the
cashiers.
• After being served by a cashier, clients exit the bank.
We need to find out the:
• Utilization of cashiers,
• Average queue lengths, both to the ATM and to the cashiers, and the
• Distribution of time spent by a customer in the bank.
With this problem definition, building a discrete event model is more or less a
straightforward task. Clients obviously are agents, and the cashiers are resources.
The flowchart of the bank is shown in Figure 2.4. The block ClientsArrive generates
clients at the rate of 0.75 per minute (45 per hour). Having appeared in the model,
50% of the clients go to the cashiers, and 50% to the ATM. The usage of the ATM is
modeled by the Delay block ServiceAtATM, preceded by the Queue block. Service at
cashiers is modeled by a pair of blocks: Service with triangularly distributed service
time and ResourcePool Cashiers with capacity 5. The flowchart ends with the Sink block
ClientsLeave.
Despite the example above it is not always easy to identify what are agents and
what are resources, especially in systems where there is no obvious continuous
process flow (many manufacturing systems fall into this class). Sometimes you need
to introduce a “dispatcher” agent to establish the sequence of operation. If this is so,
it may make sense to consider the agent-based modeling method and represent the
system as a set of interacting active units. This is discussed later in this chapter.
The output data is generated as the model is running. Statistics are collected at the
blocks, as well as by the agents while they move through the process flowchart. The
data (for example, the cashiers’ utilization) can be observed on-the-fly via inspect
windows and is stored in the model execution logs, which can be accessed after the
model run is finished. Each agent (client) measures time spent in the bank by
making a timestamp at the entry and then comparing it with the current time at the
exit.
12 The Big Book of Simulation Modeling · Multimethod Modeling with AnyLogic 8
Figure 2.4 Discrete event model of a bank
Abstraction level
As you can see, the level of abstraction suggested by discrete event modeling is
significantly lower than that of system dynamics; the diagram mirrors sequential
steps that happen in the physical system. While in system dynamics we aggregate
individual objects and talk about the dynamics of their quantities, in discrete event
modeling each object in the system is represented by an agent or a resource and
keeps its individuality. Agents and resources may have attributes, may differ from
each other, and can be treated differently by the process (the “perfect mix”
Source
[arrival rate: 0.75]
Decision
[50%]
Delay
[delay time
distribution: 1,2,4 ]
Queue
Service
[service time
distribution: 3,5,20 ] Sink
ResourcePool
[capacity: 5]
Decision
[30%]
The process flowchart
The model output
The three methods in simulation modeling 13
assumption of a system dynamics model is dropped). In discrete event models, time
delays can be deterministic or stochastic with any probability distribution. In
system dynamics, “natural” delays have an exponential distribution and
deterministic delays are special constructs.
Underlying mathematics and simulation engine
The mathematics behind discrete event simulation are based on discrete time. The
model clock is advanced only when something significant happens in the model –
namely, when an agent starts or finishes an operation. Any change in the model is
associated with those events; continuous changes are approximated by
instantaneous ones. Discrete time, and its implementation in the simulation engine,
is discussed in detail in Chapter 8, “Discrete events and Event model object”.
Software tools
Unlike system dynamics, discrete event modeling is supported by tens (if not
hundreds) of software tools. There is no uniformly accepted language for specifying
discrete event models; interoperability is not possible, and not even planned by
software vendors. There are some standardized languages for specifying some
specific types of processes – for example, business processes – but even those
languages are not directly supported by simulation modeling tools. Each tool offers
its own set of blocks and its own scripting language. Some tools are general-
purpose, while some are specifically designed for a particular application area. They
may look very different, but behind the GUI each of them has a simulation engine
that supports a discrete clock and an event queue, and moves entities (agents,
transactions) through the process flowchart.
2.3. Agent-based modeling
Agent-based modeling is a more recent modeling method than system dynamics or
discrete event modeling. Until the early 2000s, agent-based modeling was pretty
much an academic topic. The adoption of agent-based modeling by simulation
practitioners started in 2002-2003. It was triggered by:
• Desire to get a deeper insight into systems that are not well-captured by
traditional modeling approaches;
• Advances in modeling technology coming from computer science, namely
object-oriented modeling, UML, and statecharts (see Chapter 7);
• Rapid growth of the availability of CPU power and memory (agent-based
models are more demanding of both, compared to system dynamics and
discrete event models).
14 The Big Book of Simulation Modeling · Multimethod Modeling with AnyLogic 8
Agent-based modeling suggests to the modeler yet another way of looking at the
system.
You may not know how the system as a whole behaves, what are the key
variables and dependencies between them, or simply don’t see that there is a
process flow, but you may have some insight into how the objects in the
system behave individually. Therefore, you can start building the model from
the bottom up by identifying those objects (agents) and defining their
behaviors.
Sometimes, you can connect the agents to each other and let them interact;
other times, you can put them in an environment, which may have its own
dynamics. The global behavior of the system then emerges out of many (tens,
hundreds, thousands, even millions) concurrent individual behaviors.
There are no standard languages for agent-based modeling. The structure of an
agent-based model is created using graphical editors or scripts, depending on the
software. The behavior of agents is specified in many different ways. Frequently, the
agent has a notion of state, and its actions and reactions depend on its state. In such
cases, behavior is best defined with statecharts. Sometimes, behavior is defined in
the form of rules executed upon special events. In many cases, the internal
dynamics of the agent can be best captured using system dynamics or discrete event
approach. In these cases, we can put a stock and flow diagram (see Section 5.1) or a
process flowchart inside an agent. Similarly, processes outside of agents and the
dynamics of the environment where they live are often naturally modeled using
traditional methods. We find that a large percentage of agent-based models,
therefore, are multi-method models.
Example 2.3: Agent-based epidemic model
As an example, we will build an agent-based model of the spread of contagious
disease. Here is the problem statement:
• Consider a population of 10,000 people. They live in an area of 10 by 10
kilometers and are evenly spread throughout the area.
• A person in the area knows everybody who lives within 1 kilometer of him
and does not know anybody else.
• 10 random people are initially infected, and everybody else is susceptible
(none are immune).
• If an infectious person contacts a susceptible person, the latter gets infected
with probability 0.1.
The three methods in simulation modeling 15
• Having been infected, a person does not immediately become infectious.
There is a latent phase that lasts from 3 to 6 days. We will name people in the
latent phase exposed.
• The illness duration after the latent phase (i.e. the duration of the infectious
phase) is uniformly distributed between 7 and 15 days.
• During the infectious phase, a person on average contacts 5 people he knows
per day.
• When the person recovers, he becomes immune to the disease, but not
forever. Immunity lasts from 30 to 70 days.
We are to find out the epidemic dynamics – namely, the number of exposed and
infectious people over time.
The terminology and the overall structure of the problem is taken from the
(“Compartmental models in epidemiology”. n.d.) – namely, from the SEIR
(Susceptible Exposed Infectious Recovered) model. The SEIR problem was
originally solved using differential equations; the approach is similar to system
dynamics. We, however, are adding details that are not well captured by
compartmental (aggregated) models: space, communication dependent on space,
and uniformly distributed phase durations. The rationale behind using the agent-
based approach is its naturalness: we may not know how to derive global equations
for a particular disease, but we know the course of the disease and can model this
easily and in a straightforward manner at the individual level.
16 The Big Book of Simulation Modeling · Multimethod Modeling with AnyLogic 8
Figure 2.5 Individual behavior of a person in the agent-based epidemic model
According to the problem specification, a person can potentially be in one of four
phases, and different things happen to him in each of the different phases. This type
of behavior is best modeled with a statechart (see Chapter 7). Look at Figure 2.5.
The four states of the statechart correspond to the four phases of the disease.
Initially, the person is in the Susceptible state, and will remain susceptible unless gets
infected. Infection can only be passed during a contact; it is modeled by a message
sent from one agent to another. The transition from Susceptible to Exposed is
triggered by the receipt of the message “Infection”. Once the person gets to the
Exposed state, the timeout for the next transition EndOfLatency is evaluated, and the
transition gets scheduled. Thus, the time spent in the Exposed state is drawn from
the uniform distribution with the range [3, 6] days. Similarly, the time spent in the
Infectious and Immune states is defined by the corresponding stochastic timeouts.
Finally, while the person is in the Infectious phase, he periodically contacts other
people and can pass infection. This is modeled by an internal transition (see Section
7.3) Contact that is executed cyclically at a given rate. When that transition is taken,
a message “Infection” is sent to a randomly chosen “friend”.
Triggered by: Message “Infection”
Timeout: uniform( 3, 6 )
Timeout: uniform( 7, 15 )
Timeout: uniform( 30, 70 )
Rate: 5 * 0.1
Action:
sendToRandomConnected( “Infection” );
Performance improvement
The three methods in simulation modeling 17
Here we do a simple simulation performance improvement. Instead of explicitly
modeling each contact and then deciding whether the other person was infected, we
model only “successful” contacts, which are far less common. We multiply the
contact rate by the infection probability, so that if the latter is 10%, the contacts will
occur 10 times more rarely, but will pass infection for sure.
Now that we have defined the behavior of a person, we need to:
• Evenly populate the 2D space with 10,000 people (in object-oriented
terminology, we would say instances of class Person);
• Establish network connections based on distance (this type of network is
supported by most agent-based modeling tools);
• Infect 10 random people (e.g. by manually sending them the message
“Infection” at the beginning of the simulation);
• Run the model.
The dynamics of the model are fascinating to watch. Look at Figure 2.6. Shortly after
the model initializes, you can observe the clusters of sick people around the initially
infected ones. After the initial peak at about day 50, the epidemic goes down.
However, because the immunity of the recovered people does not last very long,
they get infected again by those people who are still sick. The second wave of the
epidemic starts, and it all repeats again.
It is exciting to play with the parameters. If we run the same model with a longer
and more deterministic immunity phase, say from 60 to 70 days, we will observe
only one outbreak of the epidemic and no oscillations (see the bottom chart in
Figure 2.6). If we then change the type of network to the one with some long-
distance links, the epidemic will again last forever.
18 The Big Book of Simulation Modeling · Multimethod Modeling with AnyLogic 8
Figure 2.6 Animation and output of the agent-based epidemic model
1 2
3 4
30 days later
60 days later – most are immune 150 days later – the second wave
Initial state
These people are
infected
The epidemic dynamics with the default parameters (immunity lasts 30 to 70 days)
Here immunity lasts 60 to 70 days – and the epidemic ends after the first wave
Longer lasting
immunity
The three methods in simulation modeling 19
The agent-based model we have created is very easy to modify to represent new
assumptions. Different types of social networks, households, contacts at work and
at home, treatment, impact of vaccination, etc. – all can be captured in the agent-
based model, naturally and incrementally.
Abstraction level
Agent-based modeling does not assume any particular abstraction level. If agents
are individuals, then the agent-based model is certainly more detailed than a
segmented system dynamics model where individuals are aggregated based on
characteristics. Agent, however, can be developed with high level of abstraction.
For example, the agents may be competing projects, companies, or even ideas or
philosophies.
Deciding what, exactly, should be modeled as an agent is not always as trivial as in
the epidemic example. Even if we are considering people, an individual person
should not necessarily become an agent. For example, in the model of an automobile
market, agents may be households and not individual people, because the decision
about which car to buy is mainly made at the household level and depends on
household parameters.
For those who have read books and papers on agent-based modeling
Academics are still discussing what kind of properties an object should have to
“deserve” to be called an “agent”: pro- and re-activeness, spatial awareness, ability
to learn, social ability, “intellect”, etc. In applied agent-based modeling, however,
you will find all kinds of agents: stupid and smart, communicating with each other
and living in total isolation, living in space and without a space, learning and
adapting as well as not changing their behavior patterns at all, and so on.
Here are some useful facts aimed to ensure that you are not misguided by academic
literature and various “theories” of agent-based modeling:
• Agents are not the same thing as cellular automata and they do not have
to live in discrete space (like the grid in The Game of Life, (“The Game of Life”,
n.d.)). In many agent-based models, space is not present at all. When space is
needed, in most cases it is continuous – sometimes a geographical map or a
facility floor plan.
• Agent-based modeling does not assume clock “ticks” or “steps” on which
agents check conditions and make decisions (synchronous discrete time).
Most well-built and efficient agent-based models are asynchronous
(conditions are checked, and things happen only when they need to).
20 The Big Book of Simulation Modeling · Multimethod Modeling with AnyLogic 8
Continuous time dynamics may also be a part of agent or environment
behavior.
• Agents are not necessarily people. Anything can be an agent: a vehicle, a
piece of equipment, a project, an idea, an organization, an investment, etc.
• An object that seems to be absolutely passive can be an agent. For
example, even a transmission line segment in a power grid can be modeled as
agent. We can associate it with maintenance and replacement schedules, cost,
failure events, and so on.
• There can be many, or very few, agents in an agent-based model
(depending on the problem, in a market model we can consider thousands of
consumers as well as just two competing companies). Agents can be of the
same type or can be all of different types.
• There are agent-based models where agents do not interact at all. For
example, in the area of health economics, there are models of alcohol usage,
obesity, chronic diseases where individual dynamics depend only on
personal parameters, and, sometimes, on the environment.
Underlying mathematics and simulation engine
Most agent-based models work in discrete time – interaction, decision making, and
state changes are instant. In this respect, at the low level the simulation engine
should not be much different from the one used for discrete event modeling. At a
higher level, it is desirable that the engine supports:
• A large number of concurrent activities, including their dynamic creation and
destruction.
• Correct handling of multiple instantaneous events, in particular deterministic
and random execution. This is important for synchronous models.
• Networks and communication.
• 2D, 3D, and geographical space, and space-related functionality.
If the agent internal dynamics or environment dynamics have continuous-time
elements, such as differential equations, the simulation engine must include
numerical methods and support hybrid discrete/continuous time.
Software tools
AnyLogic remains the only professional agent-based modeling tool. It supports
statecharts (see Chapter 7), object oriented-ness and Java, and has the ability to use
system dynamics and process flowcharts inside and outside agents to allow the
building of industrial strength agent-based models. Other software for agent-based
modeling falls in one of the two classes: graphical tools with limited capabilities for
The three methods in simulation modeling 21
rapid building of toy models, or Java or C++ libraries where you can do more but
have to code a lot.
-
Chapter 2. The three methods in simulation modeling
2.1. System dynamics
Example 2.1: New product diffusion
Underlying mathematics and simulation engine
Abstraction level
Software tools
2.2. Discrete event modeling
Example 2.2: Bank
Abstraction level
Underlying mathematics and simulation engine
Software tools
2.3. Agent-based modeling
Example 2.3: Agent-based epidemic model
Abstraction level
For those who have read books and papers on agent-based modeling
Underlying mathematics and simulation engine
Software tools
Modeling and simulation modeling 1
In this chapter we will talk about modeling in general, types of models, and then
focus on simulation modeling.
Modeling is one of the ways to solve problems that appear in the real world. In
many cases we cannot afford finding the right solutions by experimenting with real
objects: building, destroying, making changes may be too expensive, dangerous, or
just impossible. If this is so, we leave the real world and go up to the world of
models, see Figure 1.1. We build a model of a real system: its representation in a
modeling language. This process assumes abstraction: we throw away the details
that (we think) are irrelevant to the problem we are trying to solve and keep what
we think is important. The model is always less complex than the original system.
Figure 1.1 Modeling
2 The Big Book of Simulation Modeling · Multimethod Modeling with AnyLogic 8
The phase of building the model, that is mapping the real world to the world of
models, choosing the abstraction level and the modeling language (= the
method) is a less formalized thing in the whole process of using models to
solve problems. This is still more an art than a science.
Having built the model (or sometimes even while building the model), we start to
explore and understand the structure and behavior of the original system, test how
the system will behave under various conditions, play and compare different
scenarios, optimize. When we find the solution we are looking for, we map that
solution back to the real world.
The whole modeling thing is actually about finding the way from the problem
to its solution through a risk-free world where we are allowed to make
mistakes, undo things, go back in time, and start all over again.
1.1. Types of models
There are many different types of models that we build. Consider Figure 1.2.
Everybody builds mental models every day. A mental model is your understanding
of how things work in the real world: friends, family, colleagues, car drivers, town
where you live, things that you buy, economy, sports, politics, your own body.
Decisions like what to say to your kid, what to eat for breakfast, who to vote for, or
where to take your girlfriend tonight are all based on mental models.
Figure 1.2 Types of models
An org chart of a company drawn using boxes with arrows is a model. You can use it
to explain the structure of the organization, you can move people from one position
Boxes and arrows
Formulas on a sheet of paper
Physical models
Spreadsheets
Computer simulation models
Mental models
Modeling and simulation modeling 3
or group to another and think about the advantages and drawbacks of a new
structure.
If you take a pen and a sheet of paper and derive a formula for the optimal cross-
slope of a road on a bend as a function of the turning radius and vehicle speed, you
actually create an analytical model of vehicle movement in a turn based on another
model – Newton’s laws of motion.
Models can be physical. A model railroad can be used, for example, to optimize the
layout and operation of a classification yard. A wind tunnel is a model of a free flight
used to study aerodynamic forces and optimize the shape and design of the
airplane.
Computers provide us with a flexible virtual world where we can easily create
anything we can imagine. They are naturally and extensively used for modeling.
Computer models can be of different kinds. The spreadsheet is the most accessible
modeling software where someone can model arithmetic or algebra – such as
expenses, for near foreseeable future. Software such as MS Visio™ can be used, for
example, to plan your office layout; Autodesk 3ds Max™ to visualize interior design;
Wolfram Mathematica™ to perform fast exact-match searches for sequences in the
human genome; IBM WebSphere Business Modeler™ to model and analyze business
processes. Finally, and this is the topic of this book, there are simulation modeling
tools used to explore various dynamic systems from consumer markets to
battlefields.
1.2. Analytical vs. Simulation modeling
If you visit a group responsible for strategic planning, process optimization, sales
forecast, logistics, marketing, project management, or HR management in a large
company and see what kind of modeling tools and technologies they use you’ll find
out that the most popular modeling software is MS Excel™. Excel has obvious
advantages: it is installed on any office computer and it is very easy to use. It is also
extensible: you can add scripts to your formulas as the spreadsheet logic becomes
more sophisticated.
4 The Big Book of Simulation Modeling · Multimethod Modeling with AnyLogic 8
Figure 1.3 Analytical model (Excel spreadsheet)
The technology behind the spreadsheet-based modeling is simple: there are cells
where you enter the model inputs and there are other cells where you view the
outputs. The output values are linked to the input ones via chains of formulas and,
in more complex models, scripts. Various add-ons allow you to perform parameter
variation, Monte Carlo, or optimization experiments.
There is, however, a large class of problems where the analytic (formula-based)
solution does not exist or is very hard to find. This class, in particular, includes
dynamic systems featuring:
• Non-linear behavior
• “Memory”
• Non-intuitive influences between variables
• Time and causal dependencies
• All above combined with uncertainty and large number of parameters
You can’t even put together a meaningful mental model of such a system not to
mention assemble all the appropriate formulas.
Consider as an example a transportation optimization problem where you are to
optimize the use of a rail car or truck fleet. Travel, loading and unloading times,
maintenances, breakdowns, delivery time restrictions, terminal point capacities
make that kind of problem very hard to approach with a spreadsheet. The
availability of a vehicle at a particular location on a particular date and
time
depends on a sequence of events preceding that time. Answering the question of
where to send the vehicle when it is idle requires the analysis of event sequences in
the future.
X1
X2
X3
X4
Y1
Y2
Y3
Y4
Y = f(X)
Formulas and scripts
Calculate!
Inputs
Outputs
Modeling and simulation modeling 5
Formulas that are good for expressing static dependencies between variables,
fail to work when it comes to describing the systems with dynamic behavior.
This is the time for another modeling technology that is specifically designed
for analyzing dynamic systems, namely for simulation modeling.
The simulation model is always an executable model: you can run it and it will build
you a trajectory of the systems state changes over time. You can consider a
simulation model as a set of rules that tell how to obtain the next state of the system
from the current state. Those rules can be of many different forms: differential
equations, statecharts, process flowcharts, schedules, etc. The outputs of the model
are produced and observed as the model is running.
Figure 1.4 Simulation model
Simulation modeling is done with special software tools that employ simulation-
specific languages, both graphic and textual. It typically requires some training and
learning. But the efforts invested in adoption of simulation technology pay off when
you need to perform high quality analysis of a system with dynamic behavior.
People (especially those who count themselves as Excel professionals and have
some programming background), nevertheless, sometimes still try to build
spreadsheet models of dynamic systems. As they feel the need to capture more
details, they inevitably start reproducing the functionality of simulators in Excel.
The models become huge and unmanageable. These monsters are full of code,
they’re slow, they have very short lifetimes, and they are usually soon discarded.
The limits of analytical modeling: queuing theory
To illustrate the power of simulation and to better understand the limits of
analytical modeling it is worth spending some time on queuing theory. Queuing
theory is a mathematical approach to the analysis of dynamic systems with queues,
X1
X2
X3
X4
Y1
Y2
Y3
Y4
Rules to obtain the
next state of the
system from the
current state
Run!
…
…
…
…
time
Trajectory of the
system in time
Inputs
Outputs
6 The Big Book of Simulation Modeling · Multimethod Modeling with AnyLogic 8
such as computer transaction processing systems, call centers, transport, customer
support, healthcare service systems. Queuing theory was mostly developed in the
1950s and 1960s before the computers became powerful enough to perform
(resource-demanding) simulations. It addresses questions like: what is the average
number of customers in the queue, what is the distribution of the waiting time, or
what is the server utilization.
Consider an example: a bank. On average λ clients per hour enter the bank. At first,
we will assume there is only one cashier in the bank and on average he serves μ
clients per hour (mean service time is 1/μ). We are interested in the client’s waiting
time, queue length and cashier utilization.
Figure 1.5 A queue in a bank
Queuing theory gives us an easy solution, see case M/M/1 in Figure 1.6. The
formulas are very simple and give you the answer immediately. However, the
formula for the waiting time is essentially based on two important assumptions:
• A Poisson stream of clients, and
• Exponentially distributed service time
The first assumption means that the clients arrive at the bank independently, and
the time the next client enters the bank door does not depend on the previous
client. This looks like a fair assumption for the bank. However, the second
assumption does not conform with reality. The distribution of the time spent by a
customer at the counter should have some non-zero minimum, a major peak for the
most frequent operations, and maybe a second peak for less typical operations (see
case M/G/1 in Figure 1.6).The queuing theory does not give up and suggests
Queue
Server
Arrivals
Modeling and simulation modeling 7
another formula for the waiting time that is valid in case of arbitrary distributed
service time: Pollaczek–Khinchine formula.
Suppose now that there is not one but three cashiers in the bank. This does not
seem to be a big change in the service system. The analytic solution however starts
look scary, see case M/M/K. And, moreover, it exists only in the case of
exponentially distributed service time. For any other distribution there are no
formulas.
And this is it. Any further complication of the bank service process does not have an
analytic solution.
8 The Big Book of Simulation Modeling · Multimethod Modeling with AnyLogic 8
Figure 1.6 Queuing models of a bank
Arrivals
Queue Server (cashier)
Poisson stream (independent arrivals)
On average λ clients per hour
Service time
exponentially
distributed
On average μ per hour
Arbitrary distribution
of service time
On average μ per hour
Complex operations like
collect new credit card
Simple operations
like check cashing
Average queue length*: WL λ= (Little’s law)
Server utilization*: 𝜌𝜌 = 𝜆𝜆
𝜇𝜇
Average waiting time:
λµ
ρ
−
=W
where zC is coefficient of variation of service
time
Average waiting time:
( )
)1(
2
1
2
2
ρµ
λ
−
+
= zCW
Multiple (K) cashiers
Service time
exponentially
distributed
0)1(!
)( P
K
KP
K
ρ
ρ
−
=
11
0
0 !
)(
)1(!
)(
−−
=
+
−
= ∑
K
i
iK
i
K
K
KP ρ
ρ
ρ
Average waiting time:
)1( ρµ −
=
K
PW
Arbitrary
distribution of
service time
Analytic solution does not exist
M/M/1
M/G/1
M/M/K
M/G/K
Pollaczek–Khinchine formula:
*These formulas are valid for all cases
Any further complication of the
service process
Analytic solution does not exist
Modeling and simulation modeling 9
As you can realize, the process in a real bank is far more complex than even the
M/G/K case, for example:
• Some transactions can be done only by some particular employees
• The client can be redirected from one employee to another
• The cashiers may share resources, such as a printer or a copier
• Different cashiers may have different skills and performance
• Etc., etc., etc., …
Virtually any of those details are impossible to capture in an analytic solution. Even
if formulas exist for a particular configuration, a small change in the process may
make them void, and you will need a professional mathematician to fix them, most
probably from scratch.
Figure 1.7 Simulation model of a bank
Rate: ArrivalRate Delay time: ServiceTimeDistribution()
Capacity: NumberOfCashiers
Probability: NeedToPrintProbability
Delay time: PrintingTime
The same model extended to include
printing for a certain percent of clients:
M/G/K
10 The Big Book of Simulation Modeling · Multimethod Modeling with AnyLogic 8
Simulation modeling, on the contrary, can handle service systems of any complexity.
Simulation models scale well: adding more details to the service process or making
a local change is captured by a corresponding incremental or local change in the
simulation model rather than by re-creation of the model from scratch. At the top of
Figure 1.7 you can see the simulation model for a bank with an arbitrary number of
cashiers, Poisson arrivals and service time with the empirical distribution (M/G/K).
At the bottom of Figure 1.7 the model is extended to include printing in a certain
percent of cases and sharing a printer between cashiers.
Advantages of simulation modeling
There are six advantages to simulation modeling:
1. Simulation models enable you to analyze systems and find solutions where
other methods (like analytic calculations, linear programming, etc.) fail.
2. Once you have selected the appropriate level of abstraction the
development of a simulation model is a more straightforward process than
analytical modeling. It typically requires less intellectual efforts, is scalable,
incremental, and modular.
3. The structure of a simulation model naturally reflects the structure of the
real system. As simulation models are developed using mostly visual
languages, it is easy to communicate the model internals to other people.
4. In a simulation model you can measure any value and track any object that
is not below the level of abstraction. Measurements and statistical analysis
can be added at any time.
5. Ability to play and animate the system behavior in time is one of the
greatest advantages of simulation. Animation is used not only for demo
purposes, but also for verification and debugging.
6. Simulation models are a lot more convincing than Excel spreadsheets (not
to mention Power Point™ slides or reports with numbers). If you bring and
run a simulation to support your proposal, you will have an advantage over
those who bring just numbers.
1.3. Applications of simulation modeling. Level of abstraction.
Methods
Simulation modeling has accumulated a large number of success stories in a very
wide and diverse range of applications. And, as new modeling methods and
technologies are being developed, and as computer power grows, simulation
penetrates new areas.
Modeling and simulation modeling 11
Figure 1.8 Applications of simulation
In Figure 1.8 some applications of simulation are shown sorted by the abstraction
level of the corresponding models. The models at the bottom are physical-level
models where real-world objects are represented with maximum details. At this
level we do care about physical interaction, dimensions, speeds, distances, timings.
Anti-lock braking system of a car, evacuation of football fans from a stadium, car
traffic at an intersection controlled by a traffic light, soldier interaction on a
battlefield would be examples of problems that require modeling at a low
abstraction level.
The models at the top of the chart are highly abstract. Individual objects are
typically replaced there by aggregates. For example, instead of modeling each
individual consumer we model the number of consumers, maybe divided into
several categories; we model the number of jobs instead of individual jobs, etc.
Correspondingly, interaction between the model objects is raised to a high level. In
these models the amount of money invested into advertising may directly influence
sales, and we do not model the intermediate steps in that causal dependency.
And there are models whose abstraction level is intermediate between low and
high. For example, in a model of a hospital emergency department physical space
may matter as we do care how long it takes to walk from the emergency care room
to X-ray, but physical interaction between people walking in the building is
irrelevant because we assume there are no congestions in the building. In a model
of a business process or a call center we model the sequence and duration of
High abstraction level
(minimum details,
macro level,
strategic level)
Low abstraction level
(maximum details,
micro level,
operational level)
Medium abstraction level
(medium details,
meso level,
tactical level)
Aggregates, feedback loops, high level influences, …
Individual objects, exact sizes, speeds, distances, timing…
Social systems
Market and competition
Project management
Ecosystems
Human resources
Fleet management
Transportation
Supply chains
Warehouses
Multimodal terminals
Airports
Rail yards Manufacturing
Battlefield Traffic (microscopic)
Pedestrian movement
Control systems Computer hardware
Business processes
Call centers
Economics
Hospitals
12 The Big Book of Simulation Modeling · Multimethod Modeling with AnyLogic 8
operations and do not care about space where those operations take place. In a
transportation model we consider trucks or rail car’s movement, loading and
unloading, whereas in a higher level supply chain model we can assume that
shipment of the order takes from 7 to 10 days and we do not care how the shipment
is done.
Choosing the right abstraction level is critical to the success of the modeling
project. Once you have decided what do you include in the model and what is
left below the level of abstraction, the choice of the modeling method and the
actual “coding” of the model is quite straightforward.
In the model development process, it is normal and even desirable to
periodically reconsider the abstraction level. Typically, you would start with
high abstraction and add details as they are needed.
Figure 1.9 Methods in simulation modeling
In modern simulation modeling there are three methods, see Figure 1.9. Each
method serves a particular range of abstraction levels. System dynamics operates at
high abstraction level and is mostly used for strategic modeling. Discrete event
modeling with the underlying process-centric approach supports medium and
medium-low abstraction. Agent-based models can vary from very detailed where
agents are modeling physical objects to highly abstract where agents are competing
companies or governments. The three methods are considered in detail in Chapter
2.
High abstraction level
(minimum details,
macro level,
strategic level)
Low abstraction level
(maximum details,
micro level,
operational level)
Medium abstraction level
(medium details,
meso level,
tactical level)
Aggregates, feedback loops, high level influences, …
Individual objects, exact sizes, velocities, distances, timing…
Discrete event
(process-
centric)
modeling Agent-based
modeling
System
Dynamics
SD
DE
AB
-
Chapter 1. Modeling and simulation modeling
1.1. Types of models
1.2. Analytical vs. Simulation modeling
The limits of analytical modeling: queuing theory
Advantages of simulation modeling
1.3. Applications of simulation modeling. Level of abstraction. Methods