AnyLogic
Lilies Ratshidi
Installing AnyLogic
• Go to AnyLogic.com
• Download the student/free version
• Run and install the download
• Start AnyLogic
• Not sure if the free version requires activation key, but if so- please
follow the steps in p.16-p.19 of the “AnyLogic 8 in three days”
handbook pdf on iLearn
2
Recap on the AnyLogic GUI
Presentation Title
3
Navigation between palettes
9/3/20XX
Presentation Title
4
Adding items from the palette on the diagram
Presentation Title
5
Graphical editor
Presentation Title
6
Properties view
Presentation Title
7
Java Basics in AnyLogic
Please note:
• Java is case-sensitive: MyVaris different from myVar!
• Spacesare not allowed in names: “My Var” is illegal name!
• Each statement has to be finished with “;”: MyVar= 150;
• Each function has to have parentheses: time(), add(a)
• The most important part: Dot “.” brings you “inside” the object: agent.event.restart()
• Array elements have indexes from0toN-1
8
Data types
Primitive Types:
• double–represent real numbers: 1.43, 3.6E18, -14.0
• int–represents integer numbers: 12, 16384, -5000
• boolean–represents Boolean (true/false) values. Boolean values are only trueand false, you cannot
use 1and 0
Compound Types –Classes:
• String–represents textual strings, e.g. “MSFT”, “Hi there!”, etc
• ArrayList,LinkedList–collections of objects
• ShapePolyLine–represents AnyLogic polyline shape
• … many others. See AnyLogic and Java Class References
9
Expressions
10
Some examples
• 5%2 ≡ ?
• 5/2 ≡?
• 5.0/2=5/2,0 ≡ ?
(double)5/2 ≡ ?
a+=b; ≡ ?
a++; ≡ ?
“Any” + “Logic” ≡ ?
• Let x=14,3, so then:
• “x=“+ x ≡ x= ?
• y=x>0?x:0 ≡ ?
• x==5 ≡ ?
• x=5 ≡ ?
11
Calling functions and accessing fields
Accessing object fields and functions
• To access a field or function of a model element (statechart, event, animation
shape), use the element name followed by dot ‘.’ followed by the field/function
name. Example:
rectangle.setFillColor(red);
Function call
• To call a function, type its name followed by parentheses. If necessary, put
parameters separated by commas within the parentheses. Examples:
x = time();
moveTo( getX(), getY() + 100 );
12
Agent population
13
Built-in functions
14
Probability distributions
15
Agent based modeling
It was triggered by:
• A desire to gain deeper insights into systems that traditional modeling
approaches do not capture well;
• Advances in modeling technology made possible by computer science, such
as object-oriented modeling, UML, and statecharts;
• The rapid growth of CPU power and memory. Agent based models are more
demanding than system dynamics and discrete event models
Agents:
vehicles, units of equipment, projects, products, ideas, organizations,
investments, pieces of land, people in different roles, etc.
16
Discrete Event Modeling in Anylogic
17
Statecharts
Statecharts consists of states and transitions
Always have a statechart entry point
Used to show the state space of a given
algorithm, the events that cause a transition
from one state to another, and the actions that
result from state change
Used to visually capture a wide variety of
discrete behaviors
18
Statecharts: states
• State represents a location of control with a
particular set of reactions to conditions and/or
events.
• A state can be either simple or, if it contains
other states, composite. Control always resides
in one of simple states, but the current set of
reactions is a union of those of the current
simple state and of all composite states
containing it – i.e., a transition exiting any of
these states may be taken.
• States in the statechart may be hierarchical,
i.e. contain other states and transitions
9/3/20XX
Presentation Title
19
Statecharts: transitions
• A transition denotes a switch from one
state to another.
• A transition indicates that if the specified
trigger event occurs and the specified guard
condition is true, the statechart switches from
one state to another and performs the
specified action. When this occurs, we say
that the transition is taken
• Transitions may be triggered by userdefined conditions (timeouts or rates,
messages received by the statechart, and
Boolean conditions)
20
Example of agent-based modeling in Anylogic
Market model in Anylogic 8 in the three days handbook p.2479
• An agent-based model of a consumer market – one where each consumer will be
an agent – to help us understand how a product enters the market. Since human
decisions always include stochastics, agent-based modeling is ideal for modeling
market simulations
• The model includes 5000 people who do not use the product, but a combination of
advertising and word of mouth will eventually lead them to purchase it.
21
System dynamics modeling
System dynamics is a methodology to study dynamic systems.
It suggests you:
• Model the system as a causally closed structure that defines its own
behavior.
• Discover the system's feedback loops (circular causality) balancing or
reinforcing. Feedback loops are the heart of system dynamics.
• Identify stocks (accumulations) and flows that affect them.
22
System Dynamics example: SEIR model
p.100-p.120
• A model that displays the spread of a contagious disease among a large population. Our
sample model will have a population of 10,000 people – a value we call TotalPopulation –
of which one person is infectious.
• During the infectious phase, a person comes into contact with an average of
ContactRateInfectious = 1.25 people each day. If an infectious person comes into contact
with a susceptible person, the susceptible person's probability of infection is Infectivity =
0.6.
• After a susceptible person is infected, the infection latent phase lasts for
AverageIncubationTime = 10 days. We will use the word exposed to describe people who
are in the latent phase.
• After the latent phase, infectious phase starts. This phase lasts for AverageIllnessDuration
= 15 days.
• Persons who have recovered from the disease are immune to a second infection.
23
Market model
• Aim: to help us understand how a product enters the market.
• Human decisions always include stochastics(random probability distribution or pattern that
may be analysed statistically),
• Agent-based modeling is ideal for modeling market simulations
• Assumption:
The model includes 5000 people who do not use the product, but a combination of
advertising and word of mouth will eventually lead them to purchase it.
The model’s consumers will not use the product at first, they are all potentially interested
in using it.
There is also advertising’s influence on consumer demand by allowing a specific
percentage of them to become interested in purchasing the product during a given day.
For this purposes, Advertising effectiveness = 0.1 determines the percentage of potential
users that become ready to buy the product during a given day.
24
Discrete event modeling
Discrete event modeling requires a modeler to think about the system that he or she
wants to model as a process - a sequence of operations that agents perform.
A model’s operations can include delays, service by various resources, process branch
selections, splits and many others. As long as agents compete for limited resources and can be
delayed, queues will be part of nearly all discrete event models.
The model is specified graphically as a process flowchart where blocks represent operations.
The flowchart usually starts with "source" blocks that generate agents and inject them into the
process and ends with "sink" blocks that remove them.
Typical output expected from a discrete event model includes:
• Utilization of resources
• Time spent in the system or its part by an agent
• Waiting times
• Queue lengths
• System throughput
• Bottlenecks
25
Discrete event modeling
26
Banking model example
27
Resources
Static (can’t move and can’t be moved): a
room, a non-portable equipment, a
passage, etc.
•Portable (can’t move on their own, but can
be moved): a wheelchair, portable x-ray,
etc.
•Moving (can move, can carry portable
resources): a doctor, a nurse, a forklift
truck, etc.
28
Discrete event modeling (G. Gordon ’60s)
29
Processing modeling library: essential blocks in
discrete event
30
Example of process-based model in discrete
event
31
Properties of process modeling
32
Example
33
Agent flow: N:1 and 1:N connections
34
Call center model
Description is added on iLearn
35