Agent based modeling

Agent based
modeling
Dr. Andrei Borshchev
CEO, The AnyLogic Company
[email protected]
Sydney, February 2013
© The AnyLogic Company | www.anylogic.com
Modeling
The model
The solution at the model level
RISK-FREE SPACE
The world of models
The real world
?
The problem
The solution
© The AnyLogic Company | www.anylogic.com
2
Types of models
Boxes connected with lines
Mental models
Physical models
Formulas of a sheet of paper
Excel spreadsheets
© The AnyLogic Company | www.anylogic.com
Simulation models
3
A simulation model
• This is an “executable” model
̶ A set of rules that allow us to obtain the next state of the system in
time from the current state
• The model produces the trajectory of the system in time
̶ Outputs are “observed” as we move
Inputs
X1
X2
X3
Simulation
Model
Y1
Y2
X4
Y3
© The AnyLogic Company | www.anylogic.com
Y4
4
The three methods in simulation modeling
• The three modeling methods are the three different viewpoints
̶ …the modeler can take when mapping the real world system to its
image in the world of models
High abstraction level
[minimum details
macro level
strategic level]
Aggregates, global feedback loops, influences, trends…
System
Dynamics
Medium abstraction
level
[medium details
meso level
tactical level]
Low abstraction level
[maximum details
Micro level
Operational level]
Discrete Event
(process based)
Modeling
Agent Based
Modeling
Individual objects, exact sizes, velocities, distances, timing…
© The AnyLogic Company | www.anylogic.com
5
System Dynamics (J. Forrester, 1950s)
• Bass diffusion model
̶ Diffusion of a new product, innovation, or idea
Sales
Potential
clients
B
+
Clients
+
+
R
Sales from
Advertizing
B
+
Advertizing
effectiveness
+
Sales
from Word of
Mouth
+
+
+
Contact
Rate
© The AnyLogic Company | www.anylogic.com
Adoption
Fraction
6
Discrete event modeling (G. Gordon 1960s)
• Entities and resources. Flowchart diagram
̶ Queues and delays
[source]
[decision]
[queue+service]
[sink]
yes
no
[entities]
[resources]
yes
no
[queue]
[delay]
[decision]
© The AnyLogic Company | www.anylogic.com
Bank
7
Agent based modeling (no “father”, 2000s)
• We focus on individual objects and describe their local behavior,
local rules
̶ Sometimes – also the dynamics of the environment
Environment
Agent’s behavior
Child
Junior
Adult
Senior
© The AnyLogic Company | www.anylogic.com
8
Example: Consumer market
© The AnyLogic Company | www.anylogic.com
9
DON'T be misguided by "academic" literature:
• Agents are NOT the same thing as cellular automata that live in discrete space
̶
There can be no space 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"
̶
Most well-built and efficient agent based models are asynchronous. 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
• Agents DON"T have to be intellectual, adaptive, learning, or exhibit goal-seeking behavior
̶
Agents can be very primitive, dumb, seeking nothing, and not able to learn
• Agents DON'T have to be active. A passive object can be an agent
̶
Consider a pipe segment of a water supply network with ist maintenance and replacement schedules,
cost, breakdown events, etc
• There can be many and there can be very few agents in an agent based model
̶
Compare a model of a consumer market and a model of a steel plant
• There are agent based models where agents do not interact at all
̶
Consider agents – patients with chronic non-contagious diseases
• There are agent based models with and without environment
© The AnyLogic Company | www.anylogic.com
10
Agents can be:
People:
consumers, habitants, employees,
patients, doctors, clients, soldiers, …
Non-material things:
Vehicles, equipment:
trucks, cars, cranes, aircrafts, rail cars, machines, …
Organizations:
companies, political parties, countries, …
projects, products, innovations, ideas, investments …
© The AnyLogic Company | www.anylogic.com
11
Example: Competition in pulp market
© The AnyLogic Company | www.anylogic.com
12
What is agent in my model?
• Sometimes this is obvious, sometimes not
̶ Example: agent based model of America's automotive market
Person
Person
Person
?
Household
?
?
Car
• How do I choose?
Car
?
̶ In this particular case: think, e.g. where the decisions are made
̶ In general: try, see which architecture results in more elegant model
© The AnyLogic Company | www.anylogic.com
13
Special/standard language for AB modeling…
• …does not exist
̶ AB models are very diverse
• However, there are “design patterns” common to many AB models
̶ Object-”based” architecture
̶ Time model: asynchronous or synchronous (steps)
̶ Space: no space, continuous (2D or 3D), GIS, discrete
̶ Mobility
̶ Networks and links
̶ Communication
̶ Between agents
̶ Between agents and environment
̶ Agent state information and behavior
̶ Statecharts
̶ “Rules”
̶ SD inside agents
̶ DE (processes) inside agents
̶ Statistics collection on populations of agents
© The AnyLogic Company | www.anylogic.com
14
Example: Field service
© The AnyLogic Company | www.anylogic.com
15
AB modeling has a lot in common with OO design
• Agent = object
• The model is designed as a set of agent/object classes
• Agents of the same class have common structure, but differ in
parameters/states
̶ Memory/state information is individual to every agent
• "Border" of agent/object, separation of interface and
implementation
• Agent/object communication: message passing, function calls
̶ Message sequence diagrams are useful in AB model design
• Agents/objects can be created and deleted dynamically
• [Inheritance and polymorhysm may be useful, but are not that
important in AB modeling]
© The AnyLogic Company | www.anylogic.com
16
Networks
• If agents have more or less stable connections, it may make sense to
create a network
̶ [If there is no network, it does not mean agents do not communicate.
They can communicate randomly, or establish short-term links]
• There are standard network types supported by AnyLogic
̶ Random
̶ Ring lattice
̶ Small world
̶ Scale free
̶ Distance-based
• Standard networks have bi-directional "unnamed" links
• You can create custom networks of any configuration
̶ For example, hierarchical, with unidirectional or “named” links, etc.
• Networks can be dynamically reconfigured
© The AnyLogic Company | www.anylogic.com
17
Network examples
Random network
Ring lattice
Scale free network
3 links per agent
50 agents on a ring layout
4 links per agent
10 agents on a ring layout
m=4
50 agents on a ring layout
Small world network
Distance-based network
Custom network
3 links per agent, 75% of neighborhood links
Range = 50
50 agents on a ring layout
100 agents on a random layout
© The AnyLogic Company | www.anylogic.com
50 initial agents small world
200 more agents linked to them
18
Example: HIV diffusion and syringe usage
© The AnyLogic Company | www.anylogic.com
19
Multi-method modeling. AnyLogic
• Support all three
modeling methods on a
single modern objectoriented platform
• The modeler can choose
from a wide range of
abstraction
levels/methods and can
efficiently vary them while
working on the model
• The modeler can combine
different methods in one
model
Dynamic
systems
System
dynamics
Agent based
modeling
Discrete event
(process based)
modeling
© The AnyLogic Company | www.anylogic.com
20
Model architectures
Agents
SD
Agents + SD environment
(e.g., population +
city infrastructure)
SD inside agent
(e.g. consumer’s individual
decision making)
DE (Process model)
Agents + process model
SD + process model
(e.g., clients + service)
(e.g., demand + production)
Process model inside agent
Agents become entities
(e.g. business process in a company
in a bigger supply chain model)
(e.g., patients with chronic diseases
return to hospital)
and so on in any combination…
© The AnyLogic Company | www.anylogic.com
21
Example: Aerated concrete factory
© The AnyLogic Company | www.anylogic.com
22
“Academic” agent based modeling
• Discrete time
Agent 0
Agent 1
Agent 2
0
• Discrete space
1
2
3
Time
columns
rows
{N,S,E,W]
© The AnyLogic Company | www.anylogic.com
{N,NE,E,SE,S,
SW,W,NW]
23
Example: Schelling segregation
© The AnyLogic Company | www.anylogic.com
24
Example: Air defense system
© The AnyLogic Company | www.anylogic.com
25
Do I need to have programming skills?
Classes,
interfaces,
inheritance,
polymorphism,
…
Some:
expressions,
function calls
More:
expressions,
function calls,
statements
Almost none
Software
development
SD
DE
AB
© The AnyLogic Company | www.anylogic.com
26
How many agents to simulate?
• If I need to model the US population do I need to simulate
300,000,000 agents?
Fortunately not!
• Two main “model scaling” techniques are used:
– Same agents,
– Environment
scaled down
– Same environment
– Agents represent
groups
© The AnyLogic Company | www.anylogic.com
27
Thank you!
• Questions?
• Links:
̶ AnyLogic website: www.anylogic.com
̶ AnyLogic models online: www.runthemodel.com
© The AnyLogic Company | www.anylogic.com
28
Supplementary materials…
© The AnyLogic Company | www.anylogic.com
29
Bass Diffusion – Agent Based version
SD AB
Adoption
Rate
Potential
Adopters
+
B
Total
Population
+
R
+
Adoption
from
Advertising
+
Potential
Adopter
Adopters
Adoption
from Word
of Mouth
B
Advertising
Effectiveness
“Buy!”
Guard:
randomTrue(AdoptionFraction)
-
Adopter
Adoption
Fraction
+
+
+
Rate:
AdEffectiveness
+
Contact
Rate
Rate: ContactRate
<random agent>.”Buy!”
Potential
Adopters
Adopters
Potential
Adopters
Adopters
100
agents
10,000
agents
© The AnyLogic Company | www.anylogic.com
30
Capturing more with AB Model
• Let the word-of-mouth influence of an adopter
depend on how recently he has purchased
Time Purchased
Potential
Adopter
Adoption Fraction vs
Time since purchase
0.03
Rate: AdEffectiveness
0.02
Time Purchased = Now
0.01
“Buy it!”
Guard:
randomTrue(AdoptionFraction (
Now – Time Purchased ) ))
Adopter
0
1
2
3
Time Purchased = Now
Rate: Contact Rate
<random agent>.”Buy it!”
Potential
Adopters
Adopters
• Can you build an SD
model that captures
such dynamics?
© The AnyLogic Company | www.anylogic.com
31
Correspondence between DE and AB
DE
Request
resource
AB
Arrival
Service
Decision?
Y
Wait Resource
Resource
granted
N
Resource
Delay
In Service
Exit
Finished
Release
resource
B
Request
resource
N
Idle
seized
Y
released
Delayed
Dispatcher
Delay Time
In Use
Delete this agent
© The AnyLogic Company | www.anylogic.com
32
Capturing more with AB model
Normal
Request …
Wait Resource
Resource
granted
In Service
Finished
Normal process
Emergency process
Release
resource
B
Alarm!
Y
Request
resource
N
Emergency Process…
Delayed
Delay Time
© The AnyLogic Company | www.anylogic.com
Delete
this agent
33