Learning Book - AnyLogic 6 Enterprise Library Tutorial PDF
Learning Book - AnyLogic 6 Enterprise Library Tutorial PDF
Learning Book - AnyLogic 6 Enterprise Library Tutorial PDF
Contents
CONTENTS ............................................................................................................................... 3
Bank Model
AnyLogic provides the Enterprise Library, a discrete-event simulation library containing
objects you can use to rapidly simulate complex discrete-events systems like:
The Enterprise Library allows you to create flexible models, collect basic and advanced
statistics, and effectively visualize the process you are modeling to validate and present your
model.
In this tutorial you will learn how to create models with the Enterprise Library in the fields of
manufacturing and business processes.
We will create a simple service system of a bank department, consisting of an automatic teller
machine and teller lines. ATM provides people with a quick self-service for cash. More
complex transactions, e.g. paying bills, are completed by tellers, allowing customers more
time without inconveniencing those customers looking for quick cash.
1. Click the New Model toolbar button. The New Model dialog box is displayed.
2. Specify the name of the model. In the Model Name edit box, type Bank.
3. Specify the location where you want to store your model file. Browse for the existing
folder using the Browse buton, or type the name of the folder you want to create in
the Location edit box.
4. Click Finish.
New model is created. It already has one active object class called Main and experiment
called Simulation.
Active objects are the main building blocks of AnyLogic model. They can be used to model
very diverse objects of the real world.
In the center of the workspace you will see the graphical editor. It shows the diagram of the
Main class. By default it does not contain any elements.
To the left of the graphical editor you can see the Project view. The Project view provides
access to AnyLogic models currently opened in the workspace. The workspace tree provides
easy navigation throughout the models.
On the right side of the workspace you can see the Palette view, and at the bottom - the
Properties view. The Palette view simplifies the process of drawing diagrams, providing the
list of model elements grouped by categories in a number of stencils.
The Properties view is used to view and modify the properties of a currently selected model
item(s). When you select something – e.g., in the Project view or in a graphical editor – the
Properties view displays the properties of the selection.
To add a object of the library on the diagram, first open the library stencil in the Palette view,
then click on the object in the library stencil and finally, click in the graphical editor where you
want to place the object.
2. Add Source object. Source object generates entities with the specified interarrival
time. In our example, it models customer arrival.
Please refer to Enterprise Library Reference Guide for the description of all the Enterprise
Library objects. You can find there all object functions and their parameters. To open
Enterprise Library Reference Guide, choose the corresponding item from the AnyLogic Help.
To invoke AnyLogic Help, choose Help|Help Contents from AnyLogic menu.
3. Add Queue object to model a queue of customers waiting for the moment they can
be served.
4. Add Delay object. The Delay object models the ATM that is spending some time
serving the customer.
5. Add Sink object. This object indicates the end of the flowchart.
First, connect the port of source with the left port of queue (this port plays the
role of the input port). Generally, input ports are placed on the left side of the
object, while output ports - on the right.
To connect ports of objects, double-click the first port and then click the second
port. The connector linking two ports appears.
Cyan points inside ports indicate the correct connection. In the case you do not
see cyan circles, it probably means that you put connector's point close by a
port and you need to move it onto it.
2. Connect the output port of queue with the input port of delay.
Now we will define the data of our model, adjusting the properties of the flowchart blocks.
o Specify how often customers arrive. Type 0.67 for Interarrival rate.
If we start the model, it will work for 100 time units and then will stop. We want to study the
process over a long period of time, therefore configure the model to work infinitely.
2. On the Model Time tab of the Properties window, clear the Stop model at
specified time check box.
After the model is successfully built, you can start it. Running the simulation, you
automatically bring the current model up to date.
1. Click the Run toolbar button and choose the experiment you want to run from the
drop-down list. Your simulation experiment is called Bank/Simulation.
In the case this model is the only one opened in the workspace at the moment you will
be prompted to run this particular experiment. Later on this button will start the
previously run experiment. To run any other experiment, right-click the experiment in
the Project view and choose Run from the context menu.
Having started the model, you will see the presentation window. It displays the presentation
designed for your simulation experiment.
Click the button to Run the model and switch to Main view. and observe the process
dynamics. You will see animated flowchart. Each model created with Enterprise Library
instantly has animated flowchart where you can see detailed current object status, for
example queue size, number of entities left and so on – completely in graphics!
If needed, adjust the execution speed to your needs using Slow down and Speed up toolbar
buttons.
You can inspect flowchart objects to get the detailed information on their current state. Click
on the object to open its inspect window. Inspect window show statistics on the object, e.g.
Queue object's inspect shows the queue capacity, the number of entities passed through
either port of the object and also whether the timeout option is enabled for this
queue. Contains string displays the number of entities currently being in the object along with
IDs of these entities.
Now we will draw the layout of our bank. You draw the layout on the same diagram where you
draw a flowchart. However, if you have existing image of the layout, you can simply import
this picture as the bank layout instead of drawing it by yourself.
1. Draw ATM as an oval. First, open the Presentation stencil of the Palette view. This
stencil contains shapes and controls you can add on your presentation.
To open some stencil of the Palette view, just click on the corresponding tab of the view.
3. Select the Oval element in the Presentation stencil.
4. Click in the graphical editor to draw the oval on the diagram. Place it in the place
shown in the figure below.
2. Successively click at each polyline point on the diagram and finally double-click
where you want to place the end point of the polyline to finish drawing.
Draw queue path as shown in the figure below. Start drawing it from left to right and
place the final polyline's point near the ATM oval. The starting point—that is, the point
you click first to draw a polyline—is important. By default, entities will be moving from
the point you draw first to the point you draw last.
2. Drag the rectangle in the graphical editor. Place it between the queue path and the
ATM oval.
Set up some properties for the ATM drawn. Click the Dynamic tab of the Properties
view to open dynamic properties of the rectangle. Type run-time color expression for
the shape in the rectangle's Fill Color dynamic property: ATM.size() > 0 ? red
: green
3. Note that ATM here is the name of the Delay object we created. The expression
determines the rectangle color at run time. The size() function returns the number
of entities currently being processed. The color will be red, if a customer is served at
this time, and green otherwise.
Now we are ready to animate the layout. This is done by setting up the animation properties
for the logic flowchart objects.
To modify properties of the object, first open its properties in the Properties view by clicking
on the object in the graphical editor or in the Project view.
1. Set up queue animation. To animate a queue, just specify the queue path. Therefore,
set polyline as the Animation guide shape.
2. Change Animation type to Single. Many objects of the Enterprise Library support
several animation styles. For example, a queue can show its contents like a line of
items, a disordered heap of items, arranged items, and so on. For more information
on animation styles please refer to Enterprise Library Reference Guide, Animating
Enterprise Library Objects help topic. In this case, the ATM will be animated by a
single animation of a customer being served.
Now you can run the model and observe its behavior. If you want to speed up the simulation
significantly, switch to virtual time mode by clicking the Toggle real/virtual time mode
toolbar button. Switching to virtual time mode allows you to view simulation run at its
maximum speed. Therefore, you can simulate a long period of time.
Note that when the ATM station is serving a customer, it becomes red, and when it is idle, it is
green.
We want to observe how mean ATM utilization and mean queue length change with time.
1. Open the Analysis stencil of the Palette view. This stencil contains charts and data
objects used for collecting data and performing various statistical analysis on
them. Select the Bar Chart element in the stencil.
2. Click the place in the graphical editor where you want to place the chart and then
resize it.
4. Go to the Properties of the chart. Click Add Data Item to add data item to be
displayed by this chart.
1. Add one more bar chart in the same way. Resize it to look like the one in the figure.
2. Open the Appearance tab of the Properties view and choose the first option from
the Bars Direction section to make bars grow to the left.
3. Add a data item to be displayed by the chart. Set Title: Queue length and Value:
queue.statsSize.mean() Here statsSize is the data set of type
StatisticsContinuous that collects the statistics on the Queue size.
Run the model and observe the ATM utilization and mean queue length with just created
charts.
1. Draw animation for customer as shown in the following figure. Draw it using polyline
and oval.
4. Select the group and modify its properties.Name the group customerShape.
Successfully added shapes will move along with the group. If some shape stays where it is, it
means it was not added to the group and you need to redo the previous steps.
Now tell the source object that generated entities should be represented by this group of
shapes.
You can see customers are represented by our custom shapes now.
This model demonstrated the basics of the Enterprise Library. Now we are ready to create
more advanced model.
Service seizes resource units for the entity, delays the entity, and releases the seized units.
• There is one queue for all tellers. Set up Queue capacity to be of 20 places.
• We assume that service time is triangularly distributed with the min value of 2.5,
average value of 6, and the max value of 11 minutes. Set Delay time: triangular(
2.5, 6, 11 )
Name the object tellers. Specify that this resource object has only four resource units: define
its Capacity: 4
Leave the default object properties. The entity routing condition randomTrue(0.5)
defines that the number of customers competing for ATM and teller service will be
approximately equal.
Since the model changed, we need to alter the model animation as well.
1. Draw a polyline to animate the waiting customers queue. Draw it from left to right.
Name the polyline queueBeforeTellers.
2. Draw a polyline with four points to the right of queueBeforeTellers. This polyline
will indicate where teller animations are placed. Name it tellerPlaces.
Now we will animate our tellers by defining two images representing tellers being idle and
busy. AnyLogic will automatically switch between these images when the resource unit
becomes seized and released.
Animate tellers
1. Add Image from the Presentation stencil to the place shown in the figure with a blue
crossed rectangle.
3. Define the image that this shape will display. Use Add Image button to add Teller
Busy.png. You can find this file in the folder where Billing Department sample model
is located (somewhat like AnyLogic 6/examples/Billing Department).
4. Select the Original Size check box. If Original size option is not selected, the picture
is shown to fit the rectangle of the image shape, and otherwise the picture is shown
without any distortions.
5. Create one more image to show relaxing teller. Name it idleTeller and choose Teller
Idle.png as the image displayed by this shape.
Now we will animate the flowchart by setting up animation properties of the flowchart objects.
1. Now we need to animate customers queue. Therefore, modify the service properties:
In the current model the number of tellers is fixed. However, we may need to vary it
dynamically at the model run time. AnyLogic provides a set of controls enabling changing the
model parameters. Now we will add a slider to vary the number of tellers at run time.
1. Add a slider. Controls are drawn in the same way as animation shapes. Open the
Presentation stencil of the Palette, select the Slider element there and then click in
the graphical editor where you want to place the slider. Place it below our
ResourcePool object to let the user know that this slider will vary the capacity of this
particular object.
2. We want to vary the number of tellers in the system from 0 to 4. Therefore, set 4 as
slider’s Maximum value.
3. Type tellers.capacity as the slider's Default value.
4. Specify tellers.set_capacity((int)value); as slider's Action.
Run the model. You can see tellers being animated with our images. Now you can change the
number of tellers with the slider. Therefore, you can see how many tellers you need for the
specific customer arrival rate.
First, we will create new entity class Customer to represent customers in our model. This
class will have parameters to carry the required time information.
1. Right-click model item and choose New|Java Class from the popup menu.
2. This opens New Java Class dialog. Type the name of the new Java class:
Customer. Specify that Customer is derived from Entity. Therefore, select
com.xj.anylogic.enterprise.Entity from the Superclass drop-down list.
3. Click Next to open the next page of the wizard. On the second page of the wizard,
define the parameters of the class. Create startWaiting parameter of type double to
store the time when the customer starts waiting in the ATM queue.
4. Click Finish. You will see the code editor for the created class opened.
Type double enteredSystem; in the class body to define one more class
parameter. This parameter will store the time when the customer enters the bank
department.
5. When finished, close the code editor by clicking on the “cross” button in the upper
right corner of the editor.
Add histogram data objects to store statistics on customer's waiting time and time in system.
Histogram data objects suppport standard statistical analysis on the data values being added
(calculate mean, minimum, maximum, deviation, variance and mean confidence interval).
1. To add histogram data object on the diagram, select Histogram Data in the Analysis
stencil of the Palette and then click on the class diagram.
2. Set up the properties of the element.
o Change the Name to waitTimeDistr.
o Change the Title to Waiting time distribution.
o Set the Number of intervals equal to 50.
o Set the Initial interval size: 0.01.
3. Create one more histogram data object. Ctrl+drag histogram data object to create
its copy. Change the Name to timeInSystemDistr. Change the Title to Time in system
distribution.
o Specify new Customer() as New entity. Now this object wiil generate
entities of our Customer class. Type Customer in Generic parameters field.
This enables direct access to the fields of the Customer entity in the dynamic
parameters of this object.
Run the model and view the statistics using inspect window of the data set. Open inspect
window for data set by clicking on it. Here you can see standard statistical analysis on the
data values being added to this data object.
Add two histograms to display distributions of customer's waiting time and time in
system
1. To add histogram on the diagram, select Histogram in the Analysis stencil of the
Palette and then click on the class diagram where you want to place the histogram.
2. Define the data object to be displayed by this histogram. Click the Add Histogram
Data button and specify the Histogram to be displayed: waitTimeDistr.
Run the model. Set virtual time mode and observe distribution of customer's time in system
and waiting time.