You are on page 1of 8

IE 603: Discrete Event System Simulation IIT Bombay

INTRODUCTION TO ANYLOGIC

AnyLogic is a Java based simulation software that can be used to develop:


Discrete Event Models: Here the process/flow chart (sequence of operation) of the
system is given importance. The simulation abstracts important events of the
continuous process.
Agent Based Models: The simulation is individual centric. We identify the agents,
their behaviour, put them in a system and run the simulation. E.g. traffic jam on a
busy road, where each vehicle owner can be modelled as an agent with
independent decision characteristics.
System Dynamics Models: State variables, differential equations, concept of
feedback/loops etc is used to model the system and then simulate it. It is a high
level abstraction of the system.
Tutorials will focus on building Discrete Event Simulation Models.
Feel free to use AnyLogic Help Files and the Sample Models provided to learn
to build good models!
Each building block of AnyLogic is called an OBJECT or BLOCK.
o Can be thought as a procedure or a function
These objects are grouped under panels called PALETTE, positioned on right
side of screen.
The palette we will mainly use (at least in the beginning) is called ENTERPRISE
LIBRARY.
Enterprise Library supports discrete-event, or, to be more precise, process-centric
modeling paradigm. Using Enterprise Library objects you can model the real-
world systems in terms of entities (transactions, customers, products, parts,
vehicles, etc.), processes (sequences of operations typically involving queues,
delays, resource utilization), and resources. The processes are specified in the
form of flowcharts. AnyLogic flowcharts are hierarchical, scalable, extensible and
object oriented, which enables user to model large complex systems at any level
of detail. Enterprise Library contains a set of objects specifically designed for
"space-aware" processes - those that take place in a certain physical space and
involve movement of entities & resources.

Lets start playing with AnyLogic

SCENARIO: Consider an ATM where customers arrive at an exponentially


distributed inter-arrival time of 5 min. There is only 1 ATM. The customers spend
an exponentially distributed time with a mean of 4 min once they reach the ATM. If
ATM is busy, arriving customer waits in a queue. Simulate the system for 1 day.

1
IE 603: Discrete Event System Simulation IIT Bombay

What is the expected number & waiting time in queue?


What is the expected time in system? What is the utilization of the ATM?

Open AnyLogic software. Go to menu, File >> New>> Model. In the dialog
that opens, given model name as FirstModel. Note the location where the files
are stored. Click Next. Select Start creating a new model from scratch (blank
canvas) option. Click Finish.
AnyLogic Model Building Environment will open.
o Graphical editor (at the center) is where you build your simulation model.
o The Projects view (on the left side) provides access to models currently
opened in the workspace.
o The Palette view (on the right) provides list of model elements grouped by
categories.
o The Properties view (at the bottom) is used to view and modify the properties
of currently selected model item(s).

Menu & Toolbar

Graphical editor
Project view
or
area Palettes.
Model Workspace
Enterprise Library
is at the bottom

Properties view
area

Building the Model


Click on Enterprise Library Palette. Click, drag & place SOURCE, QUEUE,
DELAY, SINK into workspace.

and others..
Connect them as shown in the figure below. To connect them double click on the
squares in the figure (the squares are called as ports) then drag click on the next
block to join them
2
IE 603: Discrete Event System Simulation IIT Bombay

Single click on SOURCE, and in the Properties view of SOURCE, do:


o Change Arrivals defined by to inter-arrival time
o Change Interarrival time to exponential(0.2) Note that you specify
the or rate parameter for the exponential distribution.
Single click on QUEUE, and in its Properties view, do the following:
o Change Name to ATMQueue
o Change Capacity to 25
o Tick Enable Statistics
Single click on DELAY, and in its Properties view, do the following:
o Change Name to ATM
o Change Delay time to exponential(0.25)
o Change Capacity to 1
o Tick Enable Statistics
In the Projects view (left side panel), click on Simulation:Main. Now, in the
Properties view, click Model Time. In that:
o See that Time Units is minutes this time unit is used in the entire model
o Change Stoptime to 1440 (recall, we need to simulate model for 1 day).
Run the model:
Click from the Menu at the top of screen: Model>>BUILD ALL
Then click Model>>Run>>FirstModel or click PLAY button in menu bar
In the popup window that appears, click Run the Model and Switch to Main
View button. You should see your model working
o At the top of the screen there are buttons to increase/decrease the speed
of the simulation.
o At the bottom of the window, you can find out the Run number,
simulation time, and other details.
o Click on the SOURCE, QUEUE, DELAY and SINK blocks to view
default dynamic statistics that are collected.
o You will see that the Average Number in queue and Utilization statistics
are collected by default!
Congrats you have built & run your first simulation model!

3
IE 603: Discrete Event System Simulation IIT Bombay

Lets build some animation


RESOURCE ANIMATION
Draw oval to depict ATM machine
o Open Presentation Palette. Drag & place oval into graphical editor area.
o Now, click on the oval. In its Properties view:
Under General, change Name to ATManimation
Under Dynamic, enter Fill color as ATM.size() > 0 ? red
: green If ATM is idle, then its color will be green, and if
busy it will be red.
Associate the oval shape to the resource
o Click ATM (delay module). In its Properties view:
Under General, enter for Animation guide shape as ATManimation
Under General, choose Animation type as Single
QUEUE ANIMATION
Draw line to depict queue in front of ATM machine
o Go to Presentation Palette. Double click on the polyline (the picture of
polyline will turn into a pencil)
o In the graphical editor area, draw the line pattern from left to right as shown
in figure below by clicking. Double click to finish.
o Now, click on the polyline. In its Properties view:
Under General, change Name to Qanimation
Associate the line with the queue
o Click ATMQueue (queue module). In its Properties view:
Under General, enter for Animation guide shape as Qanimation
Under General, Animation type to be Path
ENTITY ANIMATION
Choose a picture to represent the entity
o From Pictures Palette, drag the person picture to the graphical editor area.
o Now, click on the person picture. In its Properties view:
Under General, change Name to customer
Associate the picture with the entities created
o Click source module. In its Properties view:
Under General, enter for Entity animation shape as customer

4
IE 603: Discrete Event System Simulation IIT Bombay

Your model should look as follows:

Person
entity

Polyline
queue Oval
resource

Run the model, as per the step given earlier, to view the animations
When the model is run, you will see that the Average Number in queue and
Utilization statistics are collected by default!

Lets now collect time in system/ time in queue statistics


We shall use TIMEMEASURESTART and TIMEMEASUREEND blocks from
Enterprise Library.
TimeMeasureStart as well as TimeMeasureEnd compose a pair of objects that
measure the time the entities spend between them.
Drag and drop TWO sets of TimeMeasureStart and TimeMeasureEnd blocks
from Enterprise Library and connect them as shown in figure below

Click on timeMeasureEnd1. In its Properties view, Under General:


o Enter for TimeMeasureStart objects as {timeMeasureStart1}
o Enter for Dataset capacity as 1000
Click on timeMeasureEnd. In its Properties view, Under General:
o Enter for TimeMeasureStart objects as {timeMeasureStart}
o Enter for Dataset capacity as 1000
Now, Run the model, as per the step given earlier.
During the run if you click on TimeMeasureEnd and TimeMeasureEnd1 you can
view the time in system and time in queue statistics, respectively.

5
IE 603: Discrete Event System Simulation IIT Bombay

Lets visualize the statistics


To display the pdf of the time in system observations
Open Analysis Palette. Drag & place Histrogram block in graphical editor area.
Now, click on the historgram chart. In its Properties view, under General:
o Click + Add Histogram data
o Enter Title as Time in System PDF
o Change Histrogram as timeMeasureEnd.distribution
To display the time in system observations as they are collected over time.
From Analysis palette, Drag & place Time Plot block in graphical editor area.
Now, click on the time plot chart. In its Properties view, under General:
o Click + Add data item
o Choose Data Set
o Enter Title as Time in System observations
o Change Data Set as timeMeasureEnd.dataset
o Change Time Window as 1440
To display the utilization of the delay resource as it changes.
From Analysis palette, Drag & place Bar Chart block in graphical editor area.
Now, click on the bar chart. In its Properties view, under General:
o Click + Add data item
o Enter Title as ATM Utilization
o Change Value as ATM.statsUtilization.mean()
o Note: statsUtilization is the statistics on delay utilization that is collected
by AnyLogic if the parameter enableStats is set to true in the delay block.
RUN the model, as per the step given earlier.

Interesting Modelling scenarios


What if a total of (say) 75 customers are alone to be processed/simulated?
Implies, no more than 75 entities are to be created!
o Go to Source properties.
Select Limited number of arrivals
Change Maximum number of arrivals, as 75 When the number
of entities created by this module reaches 75, creation of new entities
by this module ceases.

6
IE 603: Discrete Event System Simulation IIT Bombay

o RUN your model! See simulation results


Unselect Limited number of arrivals in Source Properties for following scenarios

What if there is not enough waiting space in the queue?


o We have given ATM queue capacity as 25. Now, change ATMQueue
capacity to 7 in ATMQueue properties.
What should new customer do if they see a full queue?
What happens when more customers arrive than the model can
handle?
o RUN your model to observe what happens
You should see that by default AnyLogic throws runtime error!
o When customers arrive and find that the queue is full, they should leave the
system. This behavior is termed as balking or preemption. To model this:
Go to Properties of ATMQueue and tick Enable Preemption
From Enterprise Library, drag & drop a Sink module near queue.
Now, in the ATMqueue there are 4 ports (the 4 small squares).
Connect the port marked P to the new Sink module
o RUN your model again to observe what happens The new sink module
counts the number customers who leave on seeing that the queue is full.

Customers get frustrated after waiting in queue for sometime, and leave. How
to model this?
o Suppose customers wait time tolerance threshold is about 4 to 8 minutes. If
their actual wait time is more than their threshold (they are not serviced by
then), then they will leave the queue (and perhaps come some other time).
To model this:
Go to Properties of ATMQueue:
Tick Enable exit on timeout
Enter Timeout as uniform(4, 8)
From Enterprise Library palette, drag & drop another Sink module
near queue.
Connect the port marked T to the new Sink module

7
IE 603: Discrete Event System Simulation IIT Bombay

o RUN your model again to observe what happens The new sink module
counts the number of customers who leave frustrated as their wait time is
too long.

How do I get the same result each time I run the model?
Now, you must have seen that each time you run the model you are getting
different results. To get reproducible results we need to use the same set of
random numbers. To do this.
o In the Projects view (left side panel), click on Simulation:Main. Now, in
the Properties view, click General. In that choose Fixed seed.
o Now, run the model repeatedly. You will get the same results and the
results should also match with that got by your friend working on other
computer!

If we have TWO ATMs to service the customers, how much will it reduce the
waiting time? % of customers who leave without using ATM? How are the
ATMs utilizations?
o Run the existing model. Note down the results.
o To model above scenario of 2 ATMS, we need to increase resource
capacity to 2!
Open ATM (DELAY) block. Change Capacity to 2
o Run and compare results with single ATM case.
o Do we need to use Random seed or Fixed Seed when we run the
models?

What if customers arrive in batches of 2? (e.g. customers arriving at a hotel)


o To model this:
Go to Properties of Source.
Make Entities per Arrival, as 2. Entities per arrival is the number
of entities that will enter the system at a given time with each arrival.
o Remember to increase ATM queue capacity to say 50 or 100.
o RUN your model! Observe simulation results

You might also like