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.

Let’s 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

o The Properties view (at the bottom) is used to view and modify the properties of currently selected model item(s). Model Workspace Enterprise Library is at the bottom Properties view area Building the Model • Click on Enterprise Library Palette. Click Finish. 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 . DELAY. Note the location where the files are stored. Click. Select ‘Start creating a new model from scratch (blank canvas)’ option. Click Next. drag & place SOURCE. o The Projects view (on the left side) provides access to models currently opened in the workspace.. SINK into workspace.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. o Graphical editor (at the center) is where you build your simulation model. In the dialog that opens. and others. ƒ AnyLogic Model Building Environment will open. • Connect them as shown in the figure below. File >> New>> Model. o The Palette view (on the right) provides list of model elements grouped by categories. Menu & Toolbar Graphical editor Project view or area Palettes. QUEUE. Go to menu. given model name as ‘FirstModel’.

do: o Change ‘Arrivals defined by’ to inter-arrival time o Change ‘Interarrival time’ to exponential(0. • Single click on QUEUE. DELAY and SINK blocks to view default dynamic statistics that are collected. simulation time. and in its Properties view.IE 603: Discrete Event System Simulation IIT Bombay • Single click on SOURCE. you can find out the Run number. • 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. You should see your model working o At the top of the screen there are buttons to increase/decrease the speed of the simulation.25) o Change ‘Capacity’ to 1 o Tick ‘Enable Statistics’ • In the Projects view (left side panel). we need to simulate model for 1 day). o At the bottom of the window. Now. do the following: o Change ‘Name’ to ATMQueue o Change ‘Capacity’ to 25 o Tick ‘Enable Statistics’ • Single click on DELAY. and other details. 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. and in its Properties view. do the following: o Change ‘Name’ to ATM o Change ‘Delay time’ to exponential(0.2) Æ Note that you specify the λ or rate parameter for the exponential distribution. click on ‘Simulation:Main’. and in the Properties view of SOURCE. click ‘Run the Model and Switch to Main View’ button. 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 . in the Properties view. o Click on the SOURCE. QUEUE.

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

• Drag and drop TWO sets of ‘TimeMeasureStart’ and ‘TimeMeasureEnd’ blocks from Enterprise Library and connect them as shown in figure below • Click on timeMeasureEnd1. as per the step given earlier. Under General: o Enter for ‘TimeMeasureStart objects’ as {timeMeasureStart} o Enter for ‘Dataset capacity’ as 1000 Now. respectively. you will see that the Average Number in queue and Utilization statistics are collected by default! Let’s now collect time in system/ time in queue statistics • We shall use ‘TIMEMEASURESTART’ and ‘TIMEMEASUREEND’ blocks from Enterprise Library. Run the model. • During the run if you click on TimeMeasureEnd and TimeMeasureEnd1 you can view the time in system and time in queue statistics. as per the step given earlier. In its Properties view. Under General: o Enter for ‘TimeMeasureStart objects’ as {timeMeasureStart1} o Enter for ‘Dataset capacity’ as 1000 • Click on timeMeasureEnd. 5 .IE 603: Discrete Event System Simulation IIT Bombay Your model should look as follows: Person entity Polyline queue Oval resource • Run the model. In its Properties view. to view the animations • When the model is run. • TimeMeasureStart as well as TimeMeasureEnd compose a pair of objects that measure the time the entities spend between them.

• From Analysis palette. Drag & place ‘Bar Chart’ block in graphical editor area. In its Properties view. Interesting Modelling scenarios ƒ What if a total of (say) 75 customers are alone to be processed/simulated? Implies. ƒ Select ‘Limited number of arrivals’ ƒ Change ‘Maximum number of arrivals’. 6 . Drag & place ‘Histrogram’ block in graphical editor area. 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. click on the time plot chart. as 75 Æ When the number of entities created by this module reaches 75.statsUtilization. In its Properties view.dataset o Change ‘Time Window’ as 1440 To display the utilization of the delay resource as it changes. creation of new entities by this module ceases. under General: o Click ‘+ Add data item’ o Enter ‘Title’ as ATM Utilization o Change ‘Value’ as ATM. • From Analysis palette. click on the bar chart. RUN the model.IE 603: Discrete Event System Simulation IIT Bombay Let’s visualize the statistics To display the pdf of the time in system observations • Open Analysis Palette. as per the step given earlier. • Now.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. In its Properties view. no more than 75 entities are to be created! o Go to ‘Source’ properties. • Now.distribution To display the time in system observations as they are collected over time. • Now. under General: o Click ‘+ Add Histogram data’ o Enter ‘Title’ as Time in System PDF o Change ‘Histrogram’ as timeMeasureEnd. Drag & place ‘Time Plot’ block in graphical editor area. click on the historgram chart.

drag & drop another ‘Sink’ module near queue. drag & drop a ‘Sink’ module near queue. they should leave the system.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. change ATMQueue capacity to 7 in ATMQueue properties. If their actual wait time is more than their threshold (they are not serviced by then). Now. How to model this? o Suppose customers wait time tolerance threshold is about 4 to 8 minutes. ƒ Now. ƒ 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. 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. To model this: ƒ Go to Properties of ATMQueue: • Tick ‘Enable exit on timeout’ • Enter ‘Timeout’ as uniform(4. then they will leave the queue (and perhaps come some other time). 8) ƒ From Enterprise Library palette. This behavior is termed as balking or preemption. in the ATMqueue there are 4 ports (the 4 small squares). and leave. ƒ Customers get frustrated after waiting in queue for sometime. To model this: ƒ Go to Properties of ATMQueue and tick ‘Enable Preemption’ ƒ From Enterprise Library. ƒ 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. ƒ Make ‘Entities per Arrival’. 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. Note down the results. ƒ How do I get the same result each time I run the model? ƒ Now. customers arriving at a hotel) o To model this: ƒ Go to Properties of ‘Source’. o Now. run the model repeatedly. In that choose ‘Fixed seed’. click on ‘Simulation:Main’. click ‘General’. 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. o To model above scenario of 2 ATMS. as 2. o RUN your model! Observe simulation results 8 .g. Now. in the Properties view. o Remember to increase ATM queue capacity to say 50 or 100. Change ‘Capacity’ to 2 o Run and compare results with single ATM case. 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. you must have seen that each time you run the model you are getting different results. ‘Entities per arrival’ is the number of entities that will enter the system at a given time with each arrival. we need to increase resource capacity to 2! ƒ Open ATM (DELAY) block. To get reproducible results we need to use the same set of random numbers. o In the Projects view (left side panel). To do this.