A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2,...

35
16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 1 A Java-Based Simulator for Agent-Object- Relationship Simulation based on the results of my PhD thesis at FU Berlin Wolf-Ulrich Raffel ([email protected])

Transcript of A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2,...

Page 1: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 1

A Java-Based Simulator for Agent-Object-

Relationship Simulation

based on the results of my

PhD thesis at FU Berlin

Wolf-Ulrich Raffel

([email protected])

Page 2: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 2

Motivation

Simulation is easier

than a reality

experiment

Agent-based Simulation helps

to structure simulation studies:

encapsulation of system

elements

For a domain expert,

specifying visually is

easier than programming.

IF (a1 > a2) THEN

WHILE (x>0) DO {

...

}

ELSE {

...

}

Page 3: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 3

Outline• Introduction

– Discrete-Event Simulation (DES)

– Agent-Based Simulation (ABS)

– Example application: Automatically Guided Vehicles (AGV)

• Agent-Based simulation model– Demands for a simulation specification language

– Object-Based Simulation (OBS)

– Agent-Based Simulation (ABS)

– Reaction rules

• Visual specification of ABS (not focussed in this talk)

• Implementation of a simulator– Architecture of simulator

– Demonstration

– Simulation study AGVs

• Summary

Page 4: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 4

Outline

• Introduction– Discrete-Event Simulation (DES)

– Agent-Based Simulation (ABS)

– Example application: Automatically Guided Vehicles (AGV)

• Agent-Based simulation model

• Visual specification of ABS

• Implementation of a simulator

• Summary

Page 5: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 5

Discrete-Event Simulation (DES)

• System state changes uncontinuously when an event occurs

• Between two events, system state is constant

• Event set contains unprocessed events

• When processing an event, resulting events are generated

+ Popular, established

+ Clear, understandable structure

- Restricted expressiveness for complex systems

- No support for structuring systems

- No unique formalisation in the literature

Page 6: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 6

Base model DES

• System state S ���� State

• Simulation time c

• Event set E ⊆⊆⊆⊆ Event

• Event function f: (State ×××× Event) →→→→ (State ×××× ℘℘℘℘(Event))

• Discrete-Event Simulation in 2 lines:

δ ( S, c, E ) = ( S', t, ( E \{ e_min }) ∪∪∪∪ E' ), where

e_min @ t ���� E, t minimal and ( S', E' ) = f ( S, e_min )

Page 7: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 7

Agent-Based Simulation (ABS)

• Approach separated to DES

• Suitable for complex systems

• Active entities (agents)

– interact with each other and with environment

– do actions

– percept and change their environment

– have a mental state: knowledge, goals, memories, commitments, ...

Page 8: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 8

Automatically Guided Vehicles (AGV)• Tasks: awarding of transport orders,

route scheduling, traffic regulation

• Decentrally controlled AGV systems are

more robust than centrally controlled

• Perfect example for ABS

• Agent types:

– TOM (Transport Order Manager)

– Machine

– AGV

– TrafficController

Page 9: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 9

Outline

• Introduction

• Agent-Based simulation model– Demands for a simulation specification language

– Object-Based Simulation (OBS)

– Agent-Based Simulation (ABS)

– Reaction rules

• Visual specification of ABS

• Implementation of a simulator

• Summary

Page 10: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 10

Demands for a simulation

specification language• Language and simulator must base on an agent-

based meta model

– Theoretical base for simulator

• Language must be declarative

– Decoupling of specification and execution

– Execution on different platforms

– Natural and readable specification

• Language visual and UML-based

– Easier to understand and to communicate

– UML established as standard in science and industry

Page 11: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 11

State of the art

---------UML-based

--++-+-++Visual

-----+---Declarative

--+++-++-Meta Model

TACRobo-Cup

JADECOR-MAS

MadKitSeSAmSpadesRePastSwarm

Page 12: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 12

Object-Based Simulation (OBS)• Extension of DES

• Splitting of system state

into entities (object

oriented system state)

• Distinction between

exogenous events and

resulting events

• State conditions and state

effects

Base Model of

Discrete EventSimulation

Object-Based

Simulation

Object-orientedsystem state

exogenousevents /

resulting events

state condition /state effect

Page 13: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 13

Object-Based Simulation (2)

• Event function f realized by reaction rules (objects react on events)

{ ProductionFinished ( i ) @ t + Equal_RV ( a, b ) }Resulting Events

in = in@pre - 1State Effect

in > 0State Condition

Machine [ i ]Reactor

-Trigger Condition

Machine_pickup_TI ( i ) @ tTrigger (=event)

Page 14: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 14

Agent-Based Simulation (ABS)• Extension of OBS

• Distinction: agents/objects

– objects: passive entities

– agents: active entities

• Agents can send messages to each other

• Distinction between internal and external agent state

• Distinction between environmental simulator and agent simulators

Object-Based

Simulation

Agent-Based

Simulation

MessagesInternal/external state

+ environmental

simulator

Page 15: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 15

Environmental simulator and

agent simulatorsenvironmental simulator ES

environmental state S

A1 A2 A3 O1 O2

event set E

Res Exog

simulation time c

agent simulator A1

internal

state Int

A1

time event set TE

ResTE Perio

simulation time cagent simulator A2

agent simulator A3

A3

A2

Page 16: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 16

Progress of a cycle

environmental simulator ES

environmental state S

A1 A2 A3 O1 O2

event set E

Res Exog

simulation time c

agent simulator A1

internal

state Int

A1

time event set TE

ResTE Perio

simulation time c

Step 1:

compute current

events

Step 2:

execute environmental

function e

Step 3:

send perceptions

(incl. messages) to

agent simulators

Step 4:

compute current

internal events

and execute agent

function a

Step 5:

send actions

(incl. messages)

to environmental

simulator

Page 17: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 17

Exog

Step 1: compute current events

Current events:

– Resulting events in this cycle

– Exogenous events in this cycle

– Actions of agents from the end of last cycle

agent

simulator A1

agent

simulator A2

agent

simulator A3current events

actions

Folg Exog

environmental simulator ES

environmental state S

A1 A2 A3 O1 O2

event set E

Folg Exog

simulation time c

Res Exog

E_cur

Page 18: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 18

Step 2: environmental function e

e ( S, E_cur) = ( S´, E_new, P1, P2, P3)

S <- S´

E <- E \ Res ∪ E_new

environmental simulator ES

A1 A2 A3 O1 O2

event set E

Res Exog

simulation time c

agent

simulator A1

agent

simulator A2

agent

simulator A3current eventse

E_cur

S

perceptions

environmental state

Page 19: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 19

Step 3: perceptions to

agent simulators

The environmental simulator sends a message to each

agent simulator, containing the perceptions of the

simulated agent.

environmental simulator ES agent

simulator A1

agent

simulator A2

agent

simulator A3

perceptions

Page 20: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 20

Step 4: agent step

agent simulator A1

A1

time event set TEsimulation time c

current internal eventsa

Current internal events:

– Received perceptions

– Resulting time events in this cycle

– Periodical time events in this cycle

Agent function a:

a ( Int, TE_cur) =

( Int´, TE_new, Act)

environmental

simulator ES ResTE PerioInterner

Zustand Int

TE_cur

Page 21: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 21

Step 5: actions from

agent simulators

environmental simulator ESagent

simulator A1

agent

simulator A2

agent

simulator A3

• The environmental simulator waits, until each agent

simulator has sent the set of taken actions.

• It sets the time on cycle length forward.

environmental state S

A1 A2 A3 O1 O2

event set E

Res Exog

simulation time c + ∆c

actions

Page 22: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 22

Reaction rules

• Distribution of functions e and a into reaction rules

{Machine

[AGV[i].location.machine]:

{TIArrives()}}

Perceptions

Ø Resulting

Events

context

a:AGV[i]

m:Machine[a.location.machine]

m.in=m.in@pre + 1 and

a.loadState=unloaded

State Effect

-State

Condition

-Event

Condition

AGV[i]:PutDownTI() @ tEvent

{checkPO()@ c} Resulting

Time Events

{ pickUpTI( ) } Actions

Ø Messages

orderedTI =

orderedTI@pre-1 and

prodState=producing

State Effect

prodState=idle State

Condition

-Event

Condition

TIArrives() Event

An E-Rule: An A-Rule for Machine:

Page 23: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 23

Outline

• Introduction

• Agent-Based simulation model

• Visual specification of ABS (not focussed in this talk)

• Implementation of a simulator

• Summary

Page 24: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 24

Visual specification of ABS

• Visual models are easier to understand and to

communicate

• UML models used, because UML is established as

standard in science and industry

• In theory: each UML tool is suitable

• In practice: only ArgoUML can be used without

problems

Page 25: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 25

Outline

• Introduction

• Agent-Based simulation model

• Visual specification of ABS

• Implementation of a simulator– Architecture of simulator

– Demonstration

– Simulation study AGVs

• Summary

Page 26: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 26

Implementation of a simulator• With the aid of Duc Minh Nguyen (diploma thesis)

• UML tool exports model as XMI

• XMI is transformed via XSLT to ABSimML (all relevant information for ABS)

• ABSimML can directly used as specification language as well

• A centralistic Java program reads ABSimML and generates code

• Automatical execution of generated code

agv : int

node : int

«EnvironmentalEvent»

NodeReached

<event>

<name>NodeReached</name><parameter>

<name>agv</name><type>int</type>

<name>node</name><type>int</type>,

</parameter>

...

<stereotype>EnvironmentalEvent</stereotype>

</event>

public class NodeReached

extends absimulation.EnvEvent {

int agv; int node;

...

}

UML ABSimML Java

Page 27: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 27

Simulator kernel

• Centralistic Java program

• 1100 lines of code, Jar file 34 KB

• Set of abstract Java classes

• User (e.g. code generator) uses inheritance

to specify concrete instances

• Main program connects environmental

simulator and agent simulators

=> Extension for threading and distribution

to several computers easy to realize

Page 28: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 28

UML diagram environmental simulator

simulate()

time

rules

EnvEventtriggeredByEventType() : booleantriggerCondition() : boolean

stateCondition() : booleanstateEffect() : voidresultingEvents() : EventSet

perceptions() : PerceptionSet

EnvRule

1 *

stopCondition() : booleantimeToNextEvent() : double

ExogenousEvent ResultingEvent

envSimulatorStep()currentEvents()

DELTA_C : double

clock : double

EnvSimulator

1*

id : int

SimAgent

id : int

SimObject1

*

Message

0..1

future_messages *

resulting_events*

1

1

exogenous_events *

MessageEvent MessageRule

1 1

0..1

1

ActionEvent

Action

1

1

Page 29: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 29

Transformations• Transformation XMI -> ABSimML

– Extraction of relevant information

– XSLT Processor Xalan used

• Transformation ABSimML -> Java code

– Adaptation to Java syntax and simulator classes

– XML parser Xerces used

– Parser for OCL subset generated using JavaCC

• Transformation Java code -> Java classes

– Direct call of javac in a Java program (com.sun.tools.javac)

• Transformation Java classes -> running program

– Direct call of java in a Java program (Runtime.exec())

Page 30: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 30

Demonstration

• Transformation of a UML simulation model

into a running simulation

• Demonstration example: Automatic Door

– 1 motion sensor

– 1 door

– Sensor notifies door about movement, door

opens and closes again after a period of time

Page 31: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 31

Simulation study AGV

• Production hall

250x250m

• 18 Machines

• 5 working steps

• 36 nodes

• 120 Segments

• 1-20 AGVs

• 24 hours

Eingangs-

lager 1 2 3 2

2 1 3 10

1 3 8 4 3 5

4 2 7 1

3 4 5 5 3

2 9 5 6 4Ausgangs-

lager

0

0 50 100 150 200 250

50

100

150

200

250

Page 32: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 32

Results simulation study

79,6

194,1

311,4

425,3

541,7

672,1 691,1 691,7 691,0 691,0 686,3 681,8

0,0

100,0

200,0

300,0

400,0

500,0

600,0

700,0

800,0

1 2 3 4 5 6 7 8 9 10 15 20

number of AGVs

pro

du

ced

tra

nsp

ort

ite

ms

number of produced transport items with and without exchange of transport orders

Number of TOMs

(transport order

managers)

produced

transport items

without exchange

(6 AGVs)

produced

transport items

with exchange

(6 AGVs)

produced

transport items

without exchange

(5 AGVs)

produced

transport items

with exchange

(5 AGVs)

1 672,1 690,0 541,7 574,4

2 669,0 690,0 542,3 574,6

4 669,1 690,5 542,0 578,1

Page 33: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 33

Outline

• Introduction

• Agent-Based simulation model

• Visual specification of ABS (not focussed in this talk)

• Implementation of a simulator

• Summary

Page 34: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 34

Summary• Agent-Based simulation model

– Formal execution semantics

– Distinction between internal and external agent state

– Environmental simulator and agent simulators

– Based on Discrete-Event simulation

• Specification language– Based on simulation model

– Visual language: UML-based

– XML-based specification language: ABSimML

• Implementation– Automatical transformation and execution

• of visually specified simulation models

• of simulation models specified via ABSimML

– Extensive simulation study of AGVs

Page 35: A Java-Based Simulator for Agent-Object- Relationship ... · e ( S, E_cur) = ( S´, E_new, P1, P2, P3) S

16.02.2006 W.-U. Raffel: A Java-Based Simulator for Agent-Object-Relationship Simulation 35

Thank you!

Questions?