modelling and simulation of complex systems...identified in systems, up to the definition of a well...

136
Modelling and simulation of complex systems Michele Sonnessa Dottorato in “Cultura e Impresa” Modelli matematici/informatici per l'impresa – Simulazione, rappresentazione della conoscenza e impresa Supervisori: Antonio Di Leva, Università di Torino Pietro Terna, Unversità di Torino

Upload: others

Post on 10-Jul-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Modelling and simulation ofcomplex systems

Michele Sonnessa

Dottorato in “Cultura e Impresa” Modelli matematici/informatici per l'impresa – Simulazione,

rappresentazione della conoscenza e impresa

Supervisori:Antonio Di Leva, Università di Torino

Pietro Terna, Unversità di Torino

Page 2: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity
Page 3: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Index

Acknowledgements.......................................................................................... vii

1 Introduction...................................................................................................... 9

Thesis structure....................................................................................................... 10

The theoretical foundation of simulation ..................................................... 10 The tools for simulation.................................................................................. 11 The applications............................................................................................... 12

2 Simulation and complexity....................................................................... 13

Introduction............................................................................................................ 13

Complexity.............................................................................................................. 13

Complex adaptive systems...................................................................................... 16

Non-linearity and detailed representations........................................................... 18

Simulation................................................................................................................ 19

The scientific method of simulation..................................................................... 21

The system-environment modelling in simulation............................................... 22

The levels of simulation.......................................................................................... 24

Radical openness and contextuality....................................................................... 25

Simulation purposes................................................................................................ 26

Modelling adaptive behaviours.............................................................................. 27

The Artificial Neural Networks...................................................................... 28

i

Page 4: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

The Classifier Systems..................................................................................... 28 The Genetic Programming.............................................................................. 28 The Avatars...................................................................................................... 29

3 Simulation formalisms................................................................................ 31

Introduction............................................................................................................ 31

Simulation................................................................................................................ 31

The time representation in simulation.................................................................. 32

The discrete event formalisms................................................................................ 34

The Event Scheduling world view................................................................. 34 The Activity Scanning world view................................................................. 34 The Three Phase Approach world view......................................................... 35

The time continuous formalisms............................................................................ 35

The modular approaches to discrete event simulation......................................... 37

The Process-Interaction world view.............................................................. 37

The object oriented programming and discrete simulation ................................. 39

The Message-Passing world view................................................................... 39

The DEVS formalism.............................................................................................. 41

Modular designing of simulation models............................................................... 42

4 Simulation techniques................................................................................ 45

Introduction............................................................................................................ 45

The languages of simulation................................................................................... 45

The Business Process Modelling............................................................................ 46

ii

Page 5: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

The business process simulation............................................................................. 46

Tokens.............................................................................................................. 46 The token generators....................................................................................... 47 Activities.......................................................................................................... 47 Routers............................................................................................................. 48 Split and join.................................................................................................... 48 The resources................................................................................................... 49 Building blocks................................................................................................ 49 The main software........................................................................................... 50

The System Dynamics............................................................................................. 50

The feedback and cause-effect diagrams........................................................ 51 The cause-effect diagrams............................................................................... 51 The stock-flow diagram.................................................................................. 52 The lookup functions...................................................................................... 53 Material and information delays..................................................................... 54 Building blocks................................................................................................ 55 The main software........................................................................................... 56

Agent based models, equation based models and object based models................ 56

An agent definition................................................................................................. 56

Diagrams for agent based models................................................................... 59 The main applications..................................................................................... 60

The levels of simulation.......................................................................................... 61

5 Unified Modelling Language for Simulation..................................... 63

Introduction............................................................................................................ 63

UML and the discrete simulation formalisms........................................................ 63

The conceptual model of the system...................................................................... 64

The role of UML...................................................................................................... 64

The class diagram.................................................................................................... 65

iii

Page 6: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

The actions....................................................................................................... 66 The state variables........................................................................................... 67 The relationships............................................................................................. 68

The sequence and interaction diagrams................................................................. 69

The activity diagram............................................................................................... 72

The use cases diagram............................................................................................. 73

6 JAS: Java Agent-based Simulation library.......................................... 75

Introduction............................................................................................................ 75

A brand new tool.................................................................................................... 75

The JAS library...................................................................................................... 76

Simulation experiments................................................................................... 77 The Java classes dynamic loading................................................................... 78 The engine package......................................................................................... 78 The SimModel class......................................................................................... 78

The events package................................................................................................. 79

SimEvent.......................................................................................................... 80 SimSimpleEvent............................................................................................... 81 SimCollectionEvent......................................................................................... 81 SimMultiCastEvent.......................................................................................... 81 SimSystemEvent.............................................................................................. 82 SimGroupEvent............................................................................................... 83 EventFactory.................................................................................................... 83

Static and dynamic binding.................................................................................... 84

The EventList class.......................................................................................... 85 The RealTimeEventList class.......................................................................... 86 MultiRun.......................................................................................................... 86 The AgentList class ......................................................................................... 87

The ai package......................................................................................................... 87

iv

Page 7: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Neural networks.............................................................................................. 88 Genetic algorithms.......................................................................................... 88

The random number generators............................................................................. 89

Coordinating random number generation in Agent-Based Models..............90

The graph package.................................................................................................. 92

The statistical package............................................................................................ 93

How JAS retrieves data from objects.............................................................. 93 The statistics encapsulation system................................................................ 94 How statistics are updated.............................................................................. 96

The database support.............................................................................................. 96

The output database structure........................................................................ 97 The agent id definition.................................................................................... 97

The space ................................................................................................................ 98

Sim2Web................................................................................................................. 99

Business process package...................................................................................... 100

7 Agent-based Genetic Daisyworld........................................................ 101

Introduction.......................................................................................................... 101

The Daisyworld..................................................................................................... 101

The model.............................................................................................................. 103

The agent based model.......................................................................................... 104

The genetic algorithm................................................................................... 109 The system-environment view of the model............................................... 109

The results of the non-genetic model.................................................................. 109

v

Page 8: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

The results of the genetic model.......................................................................... 111

8 An auction approach to the WLANs formation............................ 115

Introduction.......................................................................................................... 115

On-the-fly formation of local area networks...................................................... 115

The optimal solution............................................................................................. 117

The agent based simulation model....................................................................... 119

The connection algorithm.................................................................................... 122

The system-environment view..................................................................... 123

The results............................................................................................................. 124

Conclusions........................................................................................................... 127

References.......................................................................................................... 128

vi

Page 9: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Acknowledgements

I am grateful to my supervisors Pietro Terna and Antonio Di Leva, forhaving introduced me to the world of simulation, for their their interestingand ever stimulating contributions to my work during all these years.

This thesis is the result of my interest in the world of complexity and mypassion in hacking computers.

I have also to remember for their moral support and for their friendshipall the members of the NeMoTe group: Riccardo Boero, Gigi Ferraris andMatteo Morini.

A particular thanks goes to Riccardo Boero for his irreplaceablecontribution in criticizing my work.

I am also grateful to Matteo Richiardi for his friendship besides his greatcontribution to my knowledge about simulation and for having everencouraged me.

A great thanks goes to all the people who participated to the JASdevelopment: Riccardo Boero, Gigi Ferraris and Matteo Richiardi.

Thanks to all, friends and colleagues, whose help I greatly benefited.Finally I want send my love to Roberta who stood by me all the time as

well as to my family.

vii

Page 10: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

viii

Page 11: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 1

1 Introduction

This thesis explores the computer based simulation techniques to dealwith the modelling and analysis of the complex systems. The science ofcomplexity is a fascinating topic, since provides a new view of many realphenomena which in the past have seemed to be inexplicable, suggesting acharming interpretation of reality.

This science goes beyond the traditional separation between social andphysical sciences, since some properties of collective systems are explainedwith the formation of recurrent network structures and co-evolvingphenomena. Moreover, the study of complex systems requires a multi-level,multi-domain approach to scientific research and gives great importance toa micro-level detailed description of the world.

This approach is of great usefulness both in the exploration of scienceswhose prediction capabilities are nowadays lacking, like economics orsociology, and in traditional 'predictive' sciences, like physics, whosenowadays challenges mainly deals with complexity and non-linearity.

So studying phenomena, characterised by the interaction of manyindividuals, the micro simulation assumes a crucial role and computersbecome more and more scientific instruments.

The analysis of such systems requires high detailed models in order toincrease the realism of the assumptions they are based on. Theseassumptions may regard the way the atomic elements of the model perceiveand behave, or the interaction structure itself.

The close relationships among ecological, economical, biological andsocial aspects of reality are an example of how complexity has to face theradical openness of reality.

The main argument of the thesis is that agent-based modelling is apowerful tool for the study of distributed and decentralized system, as

9

Page 12: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Introduction

evolving systems of autonomous interacting agents. Nevertheless traditionalsimulation techniques have still great practical advantages over it, likegraphical formalisms, close mathematical foundations and a well defined setof problems they are typically applied to.

For this reason, I think that simulation techniques have to be integratedas much as possible in order to have various views of a system, assuring amore reliable model and a better representation of the knowledge we haveon it.

The use of simulation, mostly in the field of social sciences, is seen in asceptical way. This is probably due to three main reasons: (i) the simulationentails great problems in result interpretation and generalisation; (ii) thecomputer languages are much less expressive than the mathematical ornatural ones; (iii) scientists have often not much familiarity with computerprogramming languages and tend to omit the description of the modelimplementation. This implies a low reliability of results since the modelcannot be often easily reproduced by other researchers.

In order to improve the agent-based modelling methodology, in terms ofmodel portability and openness to extensions, I realised a brand new object-oriented toolkit to build simulation models, using a standard programminglanguage (Java) and the Open Source development philosophy.

Thesis structure

The thesis is organized in three main sections, which discuss aboutsimulations from different standpoints. The first section provides atheoretical foundation, the second one presents the tools to createsimulation models and the last introduces some applications.

The theoretical foundation of simulation

The first chapter (chapter 2) focuses on how complexity arises and can beidentified in systems, up to the definition of a well identified class ofsystems: the complex adaptive systems.

The study of complexity and its representation through digital computersis the main topic of this work, so a theoretical discussion of the use of

10

Page 13: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 1

simulation in scientific research is introduced, along with a detailed analysisof it advantages and limitations.

In order to introduce and understand the characteristics of the threemain simulation techniques, the chapter 3 provides an analysis of how thesimulation models are representation of real systems filtered by digitaldeterministic machines. The discrete representation of time and physicalelements introduce some ticklish questions, mainly concerning how thecomputer limitation may affect the validity of a simulation model.

Due to the necessity to create models ever richer in details, it is discussedabout the encapsulation of atomic models into building blocks, such thatthey can become the atoms of a federation of models. The strategies of theintegration of multi-formalism multi-domains simulation models arepointed out.

The tools for simulation

The chapter 4 presents the three main simulation techniques: the systemsdynamics (SD), the discrete-event business-process simulation (BPS) andthe agent-based modelling (ABM).

More than on their technical differences, the attention is put on the waythey represent the knowledge about the systems, particularly in terms oftheir dynamical behaviour.

Taking into account the great interest in plugging model into a set ofcooperating models, the three techniques are analysed considering theirpotential for the building block integration.

The chapter 5 presents the UML: a very promising graphical descriptivelanguage, basically aimed at representing the structure and dynamics ofobject-oriented systems. Due to its generality and its close orientation to theprogramming language representation, it can be very effectively used torepresent the internal logic of a system and of a model such that itsimplementation faithfully corresponds to the conceptual one (the scientist'sidea of the observed system).

11

Page 14: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Introduction

The chapter 6 is a technical description of the simulation platform Idesigned with the aim of creating a flexible toolkit to build discretesimulations: JAS. It is based on a pure discrete event simulation engine andit is open source.

The applications

The chapter 7 applies most of the concepts presented in the thesis toshow how the agent-based technique may radically change the modellingapproach. Not only, but it provides an easy way to implement evolutionarytechniques to make the system capable of adapting to the environment.

It is presented an agent-based version of the Lovelock's Daisyworldmodel, originally written to show how biota can alter the environmentalconditions to their advantage. The ABM version is equipped with a GeneticAlgorithm which mimics the genetic recombination of organisms' DNAduring the reproduction. The Darwinian reproduction shows how the biotaare able to better adapt to the environment.

The chapter 8 presents the construction of an agent-based model whichis aimed at simulating the coordination strategies and mechanisms thatwireless mobile devices have to carry out to create on-the-fly local areanetworks.

The traditional Operation Research approaches to the optimization arenot suitable to manage such problems, since the devices can move and havea limited vision capacity. No elements in the system can have a full view inorder to optimize it. The configuration and the connectivity must begranted by a distributed and localized information-based approach, mostlydepending on local cooperation among devices.

12

Page 15: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 2

2 Simulation and complexity

Introduction

This chapter introduces some theoretical issues concerning the study ofcomplex phenomena and the new challenges the science of complexitybrought in scientific research both in social and physical sciences. It is,then, given a definition of complexity and its relationships with non-linearand chaotic phenomena.

This new subject requires a new approach in modelling, since it is oftenaimed at finding distinctive evolution patterns within collective systemsrather than general laws. This is due to the great number of details thatcharacterize complex systems as well as their capabilities to evolve andchange continuously.

These new challenges require the use of new methodologies and newtools. The computer simulation seems the most promising technique tostudy the complex and complex adaptive systems.

In fact, their analysis often requires the use of numerical techniques,conferring on the digital computers an important role in carrying outresearch in the field.

Finally it is proposed a discussion about simulation advantages andlimitations.

Complexity

The term “complexity” is largely used in the scientific literature, butwith different meanings. Something complex is commonly considered assomething difficult to be understood or to be managed.

In order to get a more rigorous interpretation we have to look at theetymology. The term 'complex' comes from the Latin complexus, which

13

Page 16: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Simulation and complexity

literally means intertwined. Thus, in order to have complexity we need toobserve a system with many components and they have to beinterconnected such that they are objectively difficult to be isolated(Bertuglia et al. 2003).

Nevertheless, in Sterman (2000) it is proposed a large definitionembracing two types of complexities: what he calls detail complexity anddynamic complexity.

Most people think of complexity in terms of the number of componentsin a system or the number of combinations one must consider in makinga decision. The problem of optimally scheduling an airline's flights andcrews is highly complex, but the complexity lies in finding the bestsolution out of an astronomical number of possibilities. Such needle-in-a-haystack problems have high levels of combinatorial complexity (alsoknown as detail complexity). Dynamic complexity, in contrast, can ariseeven in simple systems with low combinatorial complexity. [...] Dynamiccomplexity arises from the interactions among the agents over time.

Sterman does not exactly define what the term dynamic complexitystands for. He makes implicit reference to a particular behaviour of a systemwhich has been described in Forrester (1961): the possibility that simulatingthe dynamics of multiple non-linear equations, “counterintuitive” andsurprisingly discontinuous outcomes may arise.

Only some of these analytical models show these properties, while themost part of systems are said complex with the meaning of detailcomplexity, since they are rich of interacting elements that however can beisolated.

The detail complexity is a typical property of mechanical systems, whoseparts play a well defined role and have a defined set of possible relations.The overall outcomes of the systems can be produced only with thecollaboration of all this elements, although the contribution of each partcan be well identified.

For instance, the painting machine in a car production line is essential tothe packaging of the final product, but we know exactly which contribute itgives to its realisation. Such systems can be analysed with a reductionistapproach, since we can break up them and study each part separately.

Due to its decomposability the detail complexity does not properly

14

Page 17: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 2

match the original meaning of the word complexity, notwithstanding it islargely used.

A more rigorous interpretation of the Forrester's idea of complexity isgiven in Day (1994). He says that a dynamical system is complex if itendogenously does not tend asymptotically to a fixed point, a limit cycle, oran explosion.

This definition is implicitly referred to systems whose dynamics isdetermined by the presence of strange attractors. According to the chaostheory, a strange attractor acts like a magnet and constrains the system tolie within certain ranges. The system orbits around these attractors butnever in exactly the same way. Although a pattern can be observed from adistance, close-up the behaviour of the system is unpredictable. The mostfamous example of strange attractor is the Lorentz's one (Lorenz, 1963),whose phase diagram is shown in figure 1.

figure 1 The Lorenz's strange attractor

The presence of strange attractors determines new dynamic patterns incomparison to the ones we were accustomed to observe in traditionalmodels, that is tendency to reach equilibria, linear causalities (a directedlink between an input phenomenon and its effects on the outcomes) andnegative feedback.

Both the Forrester's and the Day's definitions of a dynamic complex

15

Page 18: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Simulation and complexity

system seem to be referred to a particular behaviour of the system, insteadof a well-defined class of systems.

Even if theoretically correct, this approach is quite fuzzy and does nothelp us to define which properties of a system determine complexity andwhich are the most suitable tools and methodologies to study it.

If we consider that the focus of chaos theory is on the manner in whichsimple systems give rise to very complicated unpredictable behaviour, whilethe complexity theory focuses on how systems consisting of many elementscan lead to well-organised structures, we notice that the Day's approach ismore similar to the chaos theory's one.

In other words, the science of complexity not only takes into account thestudy of chaotic phenomena but moves the attention to a class of systemswith well-defined characteristics. It studies collective phenomena asturbulence in fluids, evolution of weather conditions, the spontaneousformation of organized structures in societies, traffic flow patterns, urbandevelopment, epidemics, the behaviour of people in groups.

So forth, the strange attractors becomes the explanations of the tendencyof real social systems to change temporal equilibria in correspondence ofphenomena like economic, social or political revolutions which determinethe formation of new social structures, new kind of relationships, newnetwork hierarchies.

Complex adaptive systems

The science of complexity has been defined in Waldrop (1992) as a newkind of science. It is certainly a provocative assertion, even if we have toacknowledge the study of complexity introduces two novelties in research:the interest for a new class of systems and the theoretical discussion on therole of computers in doing science.

The main interest in the science of complexity regards the study of thecomplex adaptive systems (CAS), whose definition highlights theimportance of adaptation and evolution in the determining their everchanging behaviour.

A CAS can be defined as a complex, non-linear, highly interactive

16

Page 19: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 2

system, that emerges over time into a coherent form, and adapts andorganizes itself without any singular entity deliberately managing orcontrolling it (Holland, 1995). Their ability to adapt to the environment isdue to their potential for self-organization, evolution and specialization.

Usually they are distributed, asynchronous, decentralized and haveendogenous dynamic connection topologies. Examples include livingorganisms, the nervous system, the immune system, the economy,corporations, societies, and so on.

The properties of adaptation and evolution are referred to two different,sometimes coexisting, phenomena. The adaptation is the ability to modifythe system state according to the changes in the environment, while theevolution is the capability of modifying the behaviour, optimizing theresponse mechanisms to the environmental changes, as well as thecapability of specializing in performing some activities.

The CAS ability to evolve is traditionally explained with the presence ofrandom mutation, natural selection, reactivity, while the adaptation andself-organization is reached through the numerous presence of semi-autonomous agents. Usually agents interact according to certain rules ofinteraction, evolve to maximize some measure like fitness and are able togain experience.

Great importance is given the way agents interact with other agents,exchanging information and/or resources. These flows may be non-linearand determine multiplier effects that spread across the network ofinteraction, which are often determined by the topology of therelationships, the spatial distribution, the local visibility, and thehierarchies.

The nature of interconnectedness in the system becomes one of the keyaspects, deeply affecting the behaviour of the system and the tendency toform temporal equilibria. In fact, throughout the agents, the CAS distributeand decentralize functionalities, allowing diversity to thrive andspecialization to occur.

This way, complex adaptive systems evolve over time taking into accounttheir experience, determining ever different evolution paths. Moreover,unanticipated, emergent structures can play a determining role in the

17

Page 20: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Simulation and complexity

evolution of such systems, which is why they often show a great deal ofunpredictability (Dooley, 1997).

The ability to adapt and evolve is not only referred to the whole system,but also to the agents constituting it. The agents may be able to adaptthemselves according to the state of the surrounding environment and theymay evolve through reproduction or learning mechanisms.

The science of complexity teaches that only the use of fuzzy, multi-leveland multi-domain representations of reality can took us to find patternswithin its complexity. Traditional scientific approach gives us not enoughtools to study systems which dynamic is determined by environmentaladaptation and self-organization, which control and order is emergentrather than predetermined (Lewin, 1992).

Non-linearity and detailed representations

A definition of what are complex systems and how to recognizecomplexity is given, but it is now necessary to point out how to representtheir models and which are the effective tools to analyse and understandthem.

Generally, the dynamics of a system can be modelled with twoapproaches. An analytical methodology involves differential equationsmodels, while an experimental one is based on computer simulation.

Concerning the modelling of complex systems, two problems come out.The first is the presence of non-linear phenomena and the second is thenumber of details to be represented.

The non-linearity has to be intended, in a general way, as the breaking ofthe proportionality between a causal event and its overall effect on thesystem. The non-linearity may be explicit, when a macro-founded model ofa system is based on non-linear differential equations, while, in case ofmicro-founded models, it may implicitly arise, due to the presence ofadaptive behaviour, that leads to very different outcomes in correspondenceof similar input patterns.

The complex systems are hard to be treated with the analytical approach,because they are difficult to be compressed in synthetic general laws and

18

Page 21: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 2

they cannot be decomposed in sub-systems. Not only but the constantpresence of non-linearity in such systems often makes them analyticallyuntreatable, entailing the use of numerical solutions methods.

Particularly for micro-founded models, a mathematical description isproblematic, because it is necessary to represent the dynamics of manyentities at the same time, and an analytical model may require to manage avery large set of equations.

The computer simulation approach is less 'sensitive' to non-linearity,since it treats functions numerically. Moreover it can easily manage a largequantity of variables, so it very suitable to represent complex systems,particularly when they consist in collective interaction among numerousentities.

Obviously, an experimental methodology does not provide the samerichness of information in comparison with an analytical solution. Notonly but it introduces some epistemological issues, like the difficulty ofinterpretation and generalisation of results (Contini et al., 2004). On theother hand, it provides the scientists a flexible, powerful, detailed and highexpressive methodology to represent scientific models.

Simulation

Models based on non-linear differential equations are usually hard to besolved analytically. Often the only way to solve them is a numericalcomputation, based on iterative algorithms.

This consideration leads us to look at the computer programminglanguages as a good formalism to describe this class of systems, mostlybecause they allow a detailed description, they are flexible andautomatically computable.

Besides, in Epstein (1999) it is pointed out that any simulation model is acomputer program, which can be turned out in a Turing machine rule set.But for every Turing machine there is a unique corresponding andequivalent Partial Recursive Function (Rogers, 1967). In theory, this meansthat for any simulation equivalent equations exist, even if they are equationinvolving recursive functions. So we have that simulation is analogous to

19

Page 22: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Simulation and complexity

mathematics, with some additional features and some limitations.The computer simulation techniques allow to satisfy two main needs of

scientists: a formal language to represent models and a laboratory to makeempirical verifications. It is expressed in a formal language, even if it ismuch less synthetic than mathematical one. It represents a virtualenvironment which can be used as it were a laboratory to produce pseudo-empirical results.

In Gilbert and Terna (2000) it is observed that the computerprogramming language represents the third symbolic way of describingmodels, besides the natural and the mathematical ones.

They stress that the simulation represent an experiment of mind which isnumerically computable:

we build a model of the target through a theoretically motivated processof abstraction (this model may be a set of mathematical equations, astatistical equation, such as a regression equation, or a computerprogram). We then examine the behaviour of the model and compare itwith observations of the social world. If the output from the model andthe data collected from the social world are sufficiently similar, we usethis as evidence in favour of the validity of the model (or use a lack ofsimilarity as evidence for disconfirmation).

If the model is a mathematical equation, it may be possible to infer itsbehaviour by a process of mathematical reasoning. If the model is astatistical equation, we run it through a statistical analysis program suchas SPSS. If the model is a computer program, its behaviour can beassessed by 'running' the program many times to evaluate the effect ofdifferent input parameters. It is the behaviour of the program that we calla computer simulation.

So, the computer program, called simulation model, becomes itself therigorous description of the interpretation the scientist made about the targetsystem.

Although mathematical models and computer programs are formallyequivalent, they are deeply different in the way they express relations andin the approach to carrying out research they are related to.

20

Page 23: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 2

The scientific method of simulation

Axelrod (1997a) does not limit himself to consider simulation as a newlanguage for science, but he suggests that it is the third way of doingscience. He says that

simulation is a third research methodology. Like deduction, it starts witha set of explicit assumptions. But unlike deduction, it does not provetheorems. Instead, simulation generates data that can be analyzedinductively. Unlike typical induction, however, the simulated data comefrom a specified set of rules rather than direct measurement of the realworld. While induction can be used to find patterns in data, anddeduction can be used to find consequences of assumptions, simulationmodeling can be used to aid intuition.

In my opinion the simulation can be effectively used to support thedeductive approach to research. It is not important if it does or does notprove theorems: it is only a virtual laboratory useful to verify hypothesis.

The real problem is how to guarantees that the virtual environmentsimulated by computers is equivalent to reality. With this concern in mind,the inductive method has to be used carefully. In fact, the assumptionscoming from simulation data outcomes may be deeply affected by themodel of the world, since the observed data depend simultaneously on themodel of the simulated system and on the model of the simulatedenvironment.

When results of simulation are different from empirical ones, themismatch may be originated from an erroneous interpretation of thesystem's cause-effect relationships as well as from wrong assumptions aboutthe environment rules used to build the computer simulation laboratory.

When a model is empirically verified, the results can be directlyinterpreted, while in the case of computer simulations, the experimentoutcomes depends on two degrees of freedom: the system and the parts ofthe environment the system interacts with.

In my opinion the Axelrod's comparison of simulation with traditionalresearch approaches is affected by his interpretation of simulation models asmonolithic representations of the target system.

In order to correctly compare simulation models with analytical ones Ipropose to describe each model explicitly separating system characteristics

21

Page 24: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Simulation and complexity

from the environmental rules.

The system-environment modelling in simulation

When a scientist designs a model of a system, he or she takes intoaccount only the elements that considers important to explain itsbehaviour. In doing that there is an implicit definition of the boundariesseparating what is part of the system and what is part of the surroundingenvironment.

A simulation model often has to represent elements of the system (themodel) and elements of environment. A model may ignore aspects of realitythat are not considered crucial, while for its computer implementation thischoice is more subtle.

figure 2 The system-environment modelling in simulation

The figure 2 shows the different process of the empirical validation thatinvolves a traditional model and a simulation one. The A and B elements of

22

Page 25: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 2

the world are not parts of the system but they are crucial because thesystem S interact with them. In order to simulate the computer model ofthe system S it is necessary to create a computer model of A and B, too.

The creation of the virtual environment may require additionalassumptions that introduce another degree of complexity in theinterpretation of simulation outcomes.

The car designers, before producing a real scale prototype of a car, createa reduced scale model of the car body and test its behaviour in the windtunnel. In this case the car prototype is based on designer's model, but thethe wind tunnel represent a real element of the surrounding environment.A computer simulation, cannot be realised without explicitly modelling thewind behaviour, too.

Let's consider for instance the Heatbugs agent based simulation model,introduced as demo application in the Swarm simulation platform. Itrepresents an artificial world populated by bugs moving around to find idealtemperature conditions.

The same model could be replicated in the real world using some robotssuitably programmed.

In this case the model specification is only represented by the robot'smind, as a set of rules driving its behaviour. The experiment is executed in aphysical space, without making any assumption about the environment: itsimply exists.

The computer version specifies some environmental constraints: thespace is divided into cells; each cell may contain one bug at a time; the heatspreads uniformly at the same rate.

There is no way to ensure that the robotic version of the model willgenerate the same outcomes, since some aspects of the real world mighthave not been modelled properly.

On the contrary the Sum model presented in Terna (2000) simulates anartificial stock market which is based on the real rules in force in the Italianstock market. Although the agents simulated do not have the samemacroeconomics inputs, the real ones have, but the simulation is based on avirtual environment which is closely similar to the real one.

I think that the designing of simulation model should take care of the

23

Page 26: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Simulation and complexity

separation between the system and the environment, in order to highlightwhich assumption it is based on.

Obviously this approach cannot be considered universally applicable,since many models are abstracts and does not represent real contexts. Whenpossible, the representation of the system-environment separation could beof help in improving the use of simulation as scientific tool.

The levels of simulation

An interesting classification of the simulation models is provided inBoero (2004). It can be used as a good method to understand when themodel of the environment becomes an important aspect in the simulationdesigning.

According to the level of abstraction, the model can be classified as anabstract model, a prototype or a simulation.

Even if this classification is ascribed to agent based models, I think it isan effective way to represent the aim of any simulation model whateversimulation technique is used.

figure 3 Abstractions, prototipes and simulationsas different types of ABM (Boero 2004)

The abstractions, according to the Boero's definition, tend to bedisjointed from the environmental constraints, since they are aimed at

24

Page 27: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 2

exploring systems at an high level of abstraction.A typical example is represented by the models of the small-worlds

network formation (Watts, 1999). This phenomena can be observed inmany real systems and so they can be considered intrinsic properties ofmany networked systems, with an irrelevant correlation to thecharacteristics of the world (Buchanan, 2002).

On the contrary, the more the model tends to be a simulation (accordingto the previous classification), the more its relationships with theenvironmental characteristics becomes a key aspect of the model. Forinstance, the simulation of the Italian stock exchange deeply depends fromthe Italian laws as well as from the Italian economic structure.

Radical openness and contextuality

Chu et al. (2003) introduce some important issues in the bounding of thecomplexity, by pointing out how simulation models can be effectively usedto overlap multi-domain representation of the target systems. They asserteach model is a simplified representation of a real system, which is oftencharacterized by two phenomena:• radical openness, and• contextuality.

A system is radically open when it can be modelled from differentdomains standpoint and each model depends from the other views. Anecosystem has to be studied as network of relation among species, and theecological view depends on the economical choices, while economy of thesystem is at the same time closely dependent to the ecosystem.

The artificial social system unavoidably links demography, economics,cultural adaptation, environmental effects and epidemiology.

Contextuality is referred to the models which are able to catch only someaspects of the real nature of the world. Obviously, the context or thedomain of the model affects its prediction potential.

Taking into account the radical openness of the systems we are able toexplain the overlapping study of complex phenomena in so differentdomains and formalisms.

25

Page 28: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Simulation and complexity

The phenomenon of contextuality is closely related to the representationof the environment. In fact, the traditional reductionist models tended toisolate phenomena and reproduce them in controllable situations. Thecomplexity often involves radical openness, so that the realisation ofdetailed environment representation in simulation allows to reduce thephenomenon of model contextuality, even if the reduction of contextualityimplies ever increasing difficulty of result interpretation.

Simulation purposes

Along with the theoretical view of the simulation, it is important topoint out what kind of uses simulation is aimed at supporting.

In Axelrod (1997a) it is proposed a classification of the simulationpurposes, which he identifies in prediction, performance, training,entertainment, education, proof and discovery.

The prediction, proof and discovery aims are the same of any scientificmodel and the simulation becomes different for the reasons just treated. Thetraining, entertainment and education purposes are similar and they can bereferred to their essence of being computer programs. The performancepurpose is considered by Axelrod the use of simulation technique to buildwhat artificial intelligence calls Multi-Agent Systems (MAS). I think it canbe a little bit confusing, since MAS are not simulations models butcomputer network based systems representing environments to makesoftware agents to collaborate. Often the agents are involved in DistributedArtificial Intelligence (DAI) paradigms, but their aims is not to simulatemodels of the worlds. If the worst comes to the worst they are emulations ofthe humans mental processes and cannot be considered simulationtechniques.

Simulation is not often used as rigorous scientific tools. In fact,particularly in social and enterprise systems, it is often used as a knowledgerepresentation technique.

The visual modelling languages are fundamental to have a detaileddescription of how a system is, at least in the mind of the observer. Thepowerful property of the empirical verification by simulation experiments

26

Page 29: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 2

gives a greater reliability on the assumption of the modeller. The author's opinion is that simulation modelling teaches that a formal

representation of a mental model is important because forces the researcherto make assumption on unknown parameters.

Another important virtue of the simulation is its interactivity openness,which allows the user to learn and to practice in a virtual world.

Moreover the simulation forces the researcher to explicitly identify onlythe interesting state variables of the system and the type of dynamicrepresentation.

Modelling adaptive behaviours

The generativist1 literature of agent based models considers thecapabilities of CAS to evolve and adapt as a collective result of themodifications occurring in the relational networks of agents. Concerningthe single agent's mind, in Axelrod (1997b) it is defined the KISS (Keep ItSimple and Stupid) principle, which leads to create simulation models associeties of no-minded agents.

This methodology considers only one face of the coin, since the agentsare themselves able to adapt and evolve. The reason of this approach isprobably the lacking in software techniques to implement self-organisingand evolving programs.

The adaptation implies the use of an algorithm which are able to mapsome inputs received from the environment to the most suitable response oraction. This mapping is not defined a priori, but it comes from continuousadaptation to the feedbacks the agent receives from environment.

The feedback can be of two types. When the result of an action showswhat the right actions for that input was, the learning can based on a socalled input-target pattern. When the right answer is not known, eitherafter the action is concluded, but we are able to estimate the effectiveness ofthe action, the learning is based on the so called fitness feedback.

Obviously the computation of a fitness rather than the exact target value

1For a definition of generativism see Epstein (1999)

27

Page 30: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Simulation and complexity

is often the only practicable path.

The Artificial Neural Networks

The Artificial Neural Networks (ANN) mimic the human brain's neuronsand they can be adapted to the input patterns. There are many learningalgorithms which are divided into supervised and unsupervised ones.

The unsupervised learning cannot be used in teaching agents to properlyreact to input patterns without considering the feedback of their actions.On the other hand, the supervised learning2 can only work with the exacttarget patterns associated with input ones.

The applicability of this reactive model in simulation is reduced to thesituations in which agents have to forecast the future behaviour of somevariables, according to the past.

The Classifier Systems

The Classifier Systems (CS) mimic the natural genetic evolution ofbiological systems. They extend the genetic algorithms, working as evolvingexpert systems. The evolution is executed using a fitness value of theagents' actions.

The optimization of local fitness allows differentiation andnovelty/diversity to emerge. The mechanism of the fitness function is veryeffective since it does not require a complete knowledge of the problemrepresented in the evolving technique. It only ask to suggest a reasonablemeasure of goodness for the suggested action.

The Genetic Programming

The Genetic Programming (GP) is the extension of the genetic model oflearning into the space of programs. The representation is a tree ofsolutions, and is very special, and the population is not a set of fixed−lengthcharacters, but is variable, it is a program that represents a candidatesolution.

This simple introduction to genetic algorithms described the main ideaof genetic evolution, but the simple concepts do not mean that their

2 The most used algorithm is called backpropagation.

28

Page 31: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 2

implementation is simple, too.Publications about the topic emphasize that designing genetic algorithms

is still an art, and no standard methods exist. That is why their application isnot as widely accepted as that of other heuristics, novice engineers easilybuild algorithms which perform only as well as a random search.

The Avatars

With the term avatar3 we make reference to a natural internal agentbehaviour. While the simulation model is composed by a set of softwareentities, the actions performed by some agents are not driven by softwarealgorithms but directly by humans.

Many simulation models can be used to drive pseudo-real experiments,in which the real and artificial are mixed together.

This approach is obviously expensive and does not contribute tounderstand how the mind works. It is useful to study collective behavioursin a controlled pseudo-laboratory.

3 The term avatar has been introduced by Pietro Terna

29

Page 32: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Simulation and complexity

30

Page 33: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 3

3 Simulation formalisms

Introduction

Computer simulation has been often considered an extreme technique tosolve hard problems in many different field of research, as Queue Theory,Control Theory, Numerical Analysis, Computer Science, ArtificialIntelligence, Operation Research (Vangheluwe, 2001).

In the previous chapter it has been shown how it has recently beenintroduced as promising approach to study social systems, with particularinterest in the complex adaptive systems.

In order to integrate the different approaches and sketch out a welldefined role for simulation in modelling, an overview of the most usedformalisms is introduced.

This chapter presents a technical comparison among the simulationformalisms, and in particular, the difference between continuous anddiscrete time representations.

Then I stress that in order to improve simulation the use of buildingblocks paradigm is necessary, since through the cooperation of atomicmodels more and more detailed models can be realised. Moreover thefederation of models allows to reduce the complexity of code, granting thedesigner a better control on the code.

The building block approach can effectively take advantage of the object-oriented software paradigm to encapsulate the atomic models and toassemble them in wide-context highly realistic simulation experiments.

Simulation

With both the growth in the personal computer power and theeffectiveness of computer programming formalisms, the simulation becomes

31

Page 34: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Simulation formalisms

more and more a paradigm for representing, and modelling complexsystems, and eventually, for optimizing them.

A simulation experiment consists in the execution of a computerprogram (the simulation model) with a given set of initial parameters. Theoutcome of the experiment is a partially ordered sequence of the states ofthe system, where the concept of state is defined as the set of variablesdescribing the system and which are considered relevant for the observer.

From the scientist's mental experiment to the computable simulationsome additional elements are necessary: the choice of the right timerepresentation, the number and the type of the state variables. This is animportant task since the representation modeller's idea cannot exactly bemapped onto a computer program. This gap is better known as thedifference between the conceptual model and the simulation model.

A simulation model, independently from the formalism it is expressedwith, is always composed by the following elements:• a set of parameter variables;• a set of entities or objects, which can be structurally present as well as

volatile, when they are created, live for a time, and then they aredropped;

• a set of relations among entities, which, in some cases, are fixed, and inother cases, change over time;

• a well-defined time representation or formalism.

The time representation in simulation

A simulation model is aimed at reproducing real systems, with a differentscale of space and of time. Concerning the time, systems can be divided intocontinuous and discrete ones, although real systems, they are referred to,exist in a continuous time world.

Trying to consider the dynamics of a post office, the observer may beinterested in analysing the behaviour and the evolution of the queue overtime. From this point of view, the system can be considered discrete. Infact, the evolution of the queue is interesting only in some discrete instantsof time: when a client enters or exits the queue. During the service time,

32

Page 35: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 3

the queue does not change and the simulation model can ignore it. Adiscrete view of this system is shown in figure 4.

figure 4 A discrete representation of a queue

In most cases systems are intrinsically continuous and they have to besimulated in every instant of time. Such kind of models are often expressedas sets of ordinary differential equations (ODE), which interesting propertyis to correlate state variables with time. Theoretically, through ODE it ispossible to analytically compute the exact sate of the system in every instantof time, but often differential equations are not so kind to be analyticallysolved, and numerical integration methods are used.

The literature on numerical integration of ordinary differentialequations4 shows a wide variety of techniques. All the integration methodshave something in common: they discretize the time. In other words, theresulting simulation model turns always in a discrete time representation.

Here, the name discrete time systems refers to systems which change in asynchronous way only in some given instants of time, just like the model infigure 4.

It is important to remember that a discrete representation is alwaysaffected by the lost of information. If the system is directly representedwith a discrete formalism, the choice of the events that considered relevantinevitably excludes other possible events.

When the system is represented with a continuous formalism, the lost of

4 See for instance Press et al. (1986)

33

Page 36: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Simulation formalisms

information is due to the discretization which the numerical integrationmethods are constrained to operate.

Trying to summarize, a simulation can be referred to two differentcategories of time representation: the time stepped models and the discreteevent models. The time stepping is the procedure the continuous simulatorsuse to make a numerical integration of the system. The state of the model isupdated at regular intervals of time, at which each entity in the systemcomputes its evolution during the last time interval. In this case the lost ofprecision increases with the size of the time step interval.

The discrete event approach alter the system states only incorrespondence of some particular events. In this case the lost of precisiondepends on the level of details introduced by the simulation designer.

The discrete event formalisms

The discrete representation of a system can be carried on with differentperspectives. Such perspectives are called world-views, and make referenceto a set of hypothesis through which the system dynamics is filtered. Adetailed overview of these formalisms are given in Vangheluwe (2001).

The Event Scheduling world view

The event scheduling view describes the future behaviour of the system,scheduling a set of events in particular instants of time.

Each system has a set of state variables and a collection of routines, calledevent handlers, which are invoked by events. One event handler for eachtype of event is required.

The simulation engine iterates over a time ordered list of events, takingthe one at the head of the list, raising it and ordering the new added events.

The simulation experiment is started by at least one event scheduled inthe event list. The end of the execution is caused by a special eventrecognized by the simulation engine or when the event list is empty.

The Activity Scanning world view

The activity scanning view requires some conditions which activates the

34

Page 37: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 3

activities. Each system has a set of state variables and a set of routinescoupled with boolean conditions. The simulation engine advances timeclock using a constant time interval, which is called step. For each step thesimulation engine checks the conditions associated with each routine ofeach object and if the system state meets the conditions the methods areactivated.

The start and the end time of the simulation are explicitly defined beforethe execution.

The Three Phase Approach world view

The three phase approach combines the event scheduling and theactivity scanning to reduce the inefficiency of the activity scanningtechnique yet preserving its pros. In the activity scanning the choice of thetime interval wideness is a critical matter. In fact, the precision increases asdelta time becomes shorter, but the less the delta time is the more thecomputation requirement raises.

Each system in this approach contains a set of shared state variables andmay contain event driven routines as well as conditional activities. Thesimulation engine works scheduling user events in an event list. Moreover,at regular intervals, the engine checks and eventually activates theconditional activities.

The time continuous formalisms

The continuous time representation is based on a set of differentialequations describing the behaviour of some variables over time. So acontinuous simulation model is nothing else than a computer programwhich executes a numerical integration method to those set of equations.

In order to pick the right computation method, it is necessary to groupanalytical models into two different categories: the causal and non-causalmodels.

A typical analytical model is expressed by a system of equations, whichcan be often solved analytically and sometimes only numerically. Since thesimulation of such systems is strictly based on numerical integration

35

Page 38: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Simulation formalisms

methods, their solution algorithms depends on the type of causal relationsamong variables.

An equation system like the one in figure 5 can be hierarchicallydecomposed, in order to determine the sequence of dependencies.

figure 5 The sequential reprentation of an equation system

The implicit causal relations can be explicitly described with thefollowing relations:• y depends on k, b• b depends on k• k is independent.

In order to simulate this system the simulation engine is able to sort theequations according the causal relation diagram and so computes thevariables in the right order.

On the contrary, when a model cannot be sorted, due to a dependencycycle or algebraic loops, it is considered a non-causal model.

The numerical computation of non-causal set of equations iscomplicated, since they must be transformed into an equivalent set of causalrelations. This operation involves techniques coming from the bond graphtheory and its presentation is out of the scope of the present work. For adetailed description see Vangheluwe (2001, p. 100).

Once the continuous model is expressed as a causal and ordered set ofequations it can be numerically solved by a computer. The most usedalgorithms to do the numerical integration are the Euler and Runge-Kuttaones.

36

Page 39: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 3

The integration method introduced by Leonard Euler in the XVIIIcentury is the simplest and most used one (Atkinson, 1985). It is based onthe assumption that the functions remain constant during the time intervaldt. This method is simple and adequate to simulate the most part of thecontinuous simulation models, even if it may be affected by a significanterror when the time interval is not short enough.

In this case many other more precise methods can be used. The mostfamous and used is the Runge-Kutta. It finds a better approximation of therate between t and t+dt, computing the average of the rates at t and at t+dt,which has been previously estimated with the Euler method.

Although the Runge-Kutta method reduces the integration error it mayalter the effect of sudden shocks, deliberately introduced by the modeller(random noise, step or pulse functions, and so forth).

The modular approaches to discrete event simulation

The discrete event approach typically utilizes three data structures: thestate variables, the event list and the clock. The simulation executiondepends on two types of procedures: the so called scheduling and the eventhandler routines. The scheduling operation is a crucial task since it createsand sorts events in time.

More recently a new perspective has established itself moving the worldviews to the modularity, particularly to face the ever increasing complexityin simulation models. A process oriented approach has introduced theobject-oriented simulation techniques.

The Process-Interaction world view

Banks et al. (1999) define the process interaction view as follows:When using a package that supports the process-interaction approach, asimulation analyst thinks in terms of processes. The analyst defines thesimulation model in terms of entities or objects and their life cycle asthey flow through the system, demanding resources and queuing to waitfor resources.

[...]

37

Page 40: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Simulation formalisms

In more precise terms, a process is a time-sequenced list of events,activities, and delays, including demands for resources, that define thelife cycle of one entity as it moves through a system.

A simulation process is intended to model a specific entity in thesimulation with a well defined behaviour. The behavioural description ofthe entity is encapsulated by the process, defining the actions performed bythe process throughout its lifetime.

A process is defined as the sequence of operations through which anentity passes during its life within the system. Each separate class of entityhas its own process which stops and starts as the simulation proceeds.

Conceptually, a process-oriented simulation can be viewed as collectionsof processes, each advancing in a somewhat autonomous fashion throughsimulation time and interacting with other processes by competing forshared resources.

Typically this simulation technique is implemented over an event-oriented simulation mechanism. Moreover they use the same event list andtime advance mechanisms but provides additional mechanisms formanaging simulation processes. Therefore, the main difference between theprocess-interaction view and the event-scheduling one is that the eventmanagement is encapsulated into a procedure.

This world view is generally embodied in a simulation language. Twowell known languages which use the process modelling approach areSIMULA and GPSS. GPSS is more restrictive since it only allowsdescriptions of processes for temporary entities (transaction approach)while SIMULA allows for temporary and permanent (server approach)entities.

In this view, processes suspended due to an unconditional delay are heldin an event list ordered according to the time of re-activation. Thus thenext event to occur will always be the next action of the process at the headof the event list. If this next action releases resources to the system, it is theresponsibility of the releasing process to test and awaken other processeswhich may now continue.

38

Page 41: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 3

The object oriented programming and discrete simulation

The Message-Passing world view

Many physical systems can be viewed as collections of components thatinteract in some way. Thus it is natural to model these systems ascollections of interacting objects. For this reason, object-oriented paradigmshave become popular modelling paradigms.

An object consists of a collection of fields and a set of methods, typicallyimplemented as procedures, that model the behaviour of the component.Objects are created (instantiated) dynamically during the execution of theprogram.

Logically, invoking a method can be viewed as sending a message to theobject and requesting it to execute an action.

Systems that require the simulation to be structured as collection ofinteracting objects are often referred to as object-oriented systems.

Among the object-oriented simulation formalisms a new technique isestablishing more and more: the agent based simulation modelling, that willbe presented in the next chapter.

Taking into account this object-oriented technique a new different worldview can be defined. I will call it the Message Passing world view.

In fact, the agent based models are characterized by the presence ofnumerous agents, which are independent units of software, whose actionsare decided and executed by themselves. Their actions must besynchronized so it is necessary to schedule a minimal event structure withthe aim of coordinating their execution.

Since they act autonomously the most used approach to design theirdynamics over time consist in defining a schedule which made of asequence of operations, defined on particular instances of agents as well aswhole classes of agents, executed with a constant frequency.

This world view is different from the process-interaction one because the'process' driving each agent is determined at experiment run time by theagent itself.

The figure 6 shows an example of the message-passing world view. The

39

Page 42: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Simulation formalisms

events are scheduled by a central coordinator, who defines the structureand sequence of events which are executed at every period of time. At thesame time some elements in the system use a discrete-event approach toschedule themselves independent events in time.

figure 6 The Message-Passing world view

The system modelling and simulation theoretical approach whichseparates the representation of a system in a conceptual model and itsimplementation, is going to the unification of the two view thanks to theobject-oriented programming paradigm.

The nowadays simulation is more and more based on the OOP, enablingthe model reuse, network based simulation, open architectures. In fact, dueto the increasing complexity of the systems being analysed with simulation,it is necessary a wide description of the systems using different levels ofcomposition as well as different techniques (Zhang et al. 2000).

In Oses et al. (2003) is pointed out how, since the 1980s, the simulationtechniques are going more and more to the graphical simulation systems.They are usually called Visual Interactive Modelling Systems (VIMS)because they are able to hide the user the technical implementation,concentrating her or his attention to the conceptual model more than itsdetails.

The VIMS are nowadays largely spread both in the discrete andcontinuous simulation fields. Their success depends on the easiness and the

40

Page 43: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 3

reduced time they require to develop a simulation model. Particularly inthe enterprises management, the simulation is used at first as a knowledgerepresentation technique, and the model design comes out from a round-trip engineering approach, in which model designer and enterprisemanagement continuously modify their perception of the businessprocesses.

In this context the VIMS are used to design the processes and todocument the knowledge embedded in the organizations. The simulation isnot the core of this activity, even if its use can very effectively drive thedesign process.

On the other hand, the visual simulation tools are affected by two limits,particularly from a scientific research point of view. They are mostlycommercial tools and their source code is not shared, often limiting thepossibility of result validation. But more important is the limitations in themodelling flexibility. A scientific model is rarely bounded to a specificmodelling domain, and the specific languages limit the interdisciplinaryapproach to research.

The DEVS formalism

Zeigler et al. (2000) introduced a new methodology to integrate thecontinuous and discrete time formalisms in a unified discrete event basedapproach. The DEVS (Discrete EVent System) specification provides amathematical equivalence between continuous and discrete timerepresentations. The way DEVS manages the continuous models usingdiscrete events is based on what Zeigler calls the quantization of acontinuous system.

The quantization consists in a partition of the trajectory into a finitenumber of segments each of which has a finite computation associated withit. An event is raised every time the delta in the trajectory is greater then athreshold value, called quantum. This method mathematically transformscontinuous into discrete models.

DEVS models can be decomposed in simple atomic units which arecoupled in a federated model allowing to easily manage large and detailed

41

Page 44: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Simulation formalisms

systems. Not only but a federated model can contain both discrete andcontinuous representations at the same time.

This way through the coupling of such atomic models into a more andmore complicated hierarchy, the DEVS formalism allows to designsimulation models with a component based approach.

It is no accident that, it is also the designing paradigm used to build theHigh Level Architecture (HLA), a standard mandated U.S. Department ofDefense for simulator interoperability and reuse to be adopted by alldefence contractors and agencies.

The DEVS approach has been originally designed in the simulation ofcontrol systems5, but it is a general formalism. Unfortunately, due to itsrigid and rigorous formalism it does not well adapt to simulate socialsystems and complex adaptive systems in general.

The atomic models has got a fixed number of input/output ports, andthey cannot change dynamically. This constraint limits the capability tomanage changing relational structures among agents in the model.

The standard object-oriented programming approach does not solve theproblem of mimic adaptive behaviours, since also the object interfacescannot change dynamically, however they are more flexible, thanks toconcepts like polymorphism and hereditariness.

Modular designing of simulation models

Although DEVS simulation technique provides a coherent formalism, itis closed towards the representation of evolution and adaptationphenomena. It reduces the flexibility and the potential of standardprogramming languages, by limiting a priori the number of connections andthe type of communication two models can use.

Notwithstanding this limitations, the DEVS approach propose asuccessful way to integrate building blocks into a federation of concurrentmodels.

The study of complex systems needs multi level abstractions, ranging

5 For a brief history of the modern control theory see Lewis (1992).

42

Page 45: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 3

from detailed to high level processes representations. The figure 7 presents how object-oriented simulation models can be

integrated in a wider simulation system. According to DEVS, both discreteand continuous models can be part of the system, with the only constraintthat the continuous ones are encapsulated in atomic objects providing adiscrete-compliant interface.

It is rigorously based on a hierarchy, so each model knows only onemodel of the higher level and a set of models of the lower level. This ruleensure the manageability of the whole system, since modifications havelocalized effects.

The abstract architecture is proposed to support the use of standardobject-oriented programming languages, instead of making reference to acustom simulation language.

The aggregation of models is always done via a rigorous discrete eventsequence. This is the only approach capable of decomposing an hybridsystem into sub-units, with a more control on the dynamic and morecoordination among the system entities.

It means that the sequence of events must be rigorously managed by aunique time manager.

figure 7 Component based simulation abstraction

43

Page 46: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Simulation formalisms

Trying to summarize, the diagram proposed in figure 7 is based on thefollowing three principles:• each model must behave as a discrete event based simulation;• the time and the sequence of events must be managed by a unique entity;

the communications between two atomic models has to be coordinatedby an higher level model.

44

Page 47: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 4

4 Simulation techniques

Introduction

In the previous chapters it has been shown under what conditions asimulation model can be compared to a traditional analytical one. Theprogramming language used to design the simulation plays the same role ofthe mathematics for the traditional quantitative models.

Unfortunately, the programming languages often require a detaileddescription of the systems they reproduce, contrary to mathematical modelswhich are usually concise.

This is the reason why the most of the scientific works based onsimulation tend to leave out the description of how the model isimplemented, because it is too technical and prolix, and it is often deeplydependent from the software tool it has been designed with.

In order to increase the effectiveness of the simulation modeldescription, in this chapter I focus on the existing graphical formalisms usedby the three main simulation techniques, highlighting their advantages anddrawbacks. The aim of this analysis is the definition of a unified approachto describe simulation models.

In particular, the business process modelling, the system dynamics andthe agent based modelling techniques are introduced, together with theirgraphical formalisms.

The languages of simulation

One of the main challenges of simulation languages and tools is the thevalidity (Axelrod, 1997a).

A simulation model is said valid when there is an exact correspondencebetween the conceptual model and its implementation. In fact, the

45

Page 48: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Simulation techniques

limitations introduced by the computers architectures and their languagessometimes deeply affect the translation of a conceptual model into acomputer program.

The simulation tools have to be more and more capable of representingmodels in a faithful way and this is possible with the use of standardlanguages, of code encapsulation, of effective documentation throughgraphical languages.

The Business Process Modelling

The enterprise modelling is the ideal framework to compare andeventually integrate different simulation techniques. Since the enterprise isa complex social adaptive system, it can be simulated at a very differentscale and from many different points of view.

In Lindsay et al. (2003) it is well pointed out how the business processmanagement and re-engineering (BPM/R) literature gives prominence toeffectiveness of process oriented implementation structures in helpingorganizations to be more flexible and responsive to the changingenvironment. Usually business processes are simulated with discrete eventsoftware which adopt a well-established graphical formalism.

Nevertheless the modelling of enterprises requires a wider perspectiveand the use of all the available simulation techniques.

The business process simulation

The most common discrete event process simulators are fulfilledthrough a well defined set of objects, which are here briefly described.

Tokens

A token is a concept borrowed from the Petri nets formalism (Petri,1962). It represents a logical or physical entity moving along the processand causing the activities objects to spend time processing it. The token canrepresent a product which is originated from an order posted by a customerand that is step by step assembled in a production line as well as a document

46

Page 49: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 4

representing a file processed by different offices.A token can only be in one place at a time, it can change state, physically

move, transformed or delayed.Contrary to the Petri Net language, in which a token is a logical element

representing a state, the business process adopt a richer definition of token:it is uniquely identified, and it can be attached a set of attributes.

The token generators

A simulation model needs a starting point from which tokens begin theirpath. The token generator can be based on a fixed list of future events,explicitly set by the user. More frequently it generates tokens randomly,according to a well known stochastic distribution. A token generator block • creates the tokens, • initializes their attribute values and • forwards them into the process path.

Activities

An activity represents a job that some actors of the system are able toperform on a set of tokens. They are graphically depicted using boxesconnected to other activities through lines. Each box has a set of input andoutput ports through which tokens jump from an activity to the subsequent.

The activities can require the presence of some particular resources tocarry out the job. They spend time in waiting for the expected quantity oftokens and of resources, then block the token flow for the time necessaryfor the current job.

An example of activity chain representing a process is shown in thefigure 8.

47

Page 50: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Simulation techniques

figure 8 An example of process diagram

Each activity needs to be attached to a queue manager, in order to keepwaiting tokens and to manage the queue policy.

Some activities are able to stop the current transaction, when a morepriority token enters the activity box. They are called preemptableactivities.

Each activity can be associated with a given set of resources (human andtechnical), they can vary their behaviour according to the attributes of thecurrent processed token.

Some activities are able to perform the so called batch operations, whichconsist in grouping a given number of tokens before starting the job.

Routers

A router is a block containing one or more input ports and one or moreoutput ports. They make logical operations on tokens attributes, processglobal state variables or random number to decide on which output port atoken has to be routed.

The routers play an important role, since the processes are never uniquelines connecting the begin to the end. Often a process is characterized bythe different possible paths chosen dynamically according the type of objectprocessed or the overall condition of the simulated system.

Split and join

Since the tokens do not ever represent physical entities they can belogically cloned, split, joined or merged, in order to map logical pathsfollowed in parallel by some production activities.

Imagine a process followed by a file of a customer asking a certificate

48

Page 51: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 4

issuing. In some circumstances the file can be separated because some sheetscan be processed at the same time by different officers. When the two tasksare completed, the sheets are joined back into the file, which can continueits path.

The split and join blocks are designed to clone and join tokens,opportunely managing the attributes setting.

The resources

Resources are a crucial aspect of business process simulation. They arepools of humans or machines capable of performing some jobs. Sometimesmore then one resource is necessary to begin the current task. Theiravailability often determines the formation of queues and bottlenecksthroughout the process flow.

The computation of the resource utilization is one of the most importantroles of simulation in the business process modelling. In fact, the oversizingor the undersizing of the resources may be the main causes of inefficiency.

Unfortunately no graphical languages have been defined to represent thisimportant view of a BP. They are usually enumerated in tables containingthe pools, their composition and the shifts of each single resource. Theassociation between a resource and the activities it is involved in is notenvisaged in traditional BP diagrams.

Building blocks

The logic of the component designing approach, used in the discreteevent BP simulators, is based on the input/output ports. Each activity orbuilding block can be independently programmed by defining a set of inputand output points through which information and tokens can flow.

The ports represent the visible interface of each component, along withgraphical symbolic aspects, which are not standardized: each simulationtool uses different symbols to represent different types of blocks.

The port formalism is a key aspect of the BP diagrams. They are the onlyvisible element of a box, whose internal logic can be completely hidden.The ports describe how the component is able to link to other components.

Thanks to the input/output ports the logic of a process can be

49

Page 52: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Simulation techniques

represented at very different levels of detail, since each block can be ascomplex as a whole process.

Moreover, this approach helps the component reuse, through thedefinition of specialized building block.

The main software

The most diffused software in the field of business process simulation arecommercial.

Unfortunately these applications are deeply different in the languagethey use and in the way they represent processes. This limits the possibilityof exchanging models and to form a spread community.

For instance, the Extend platform uses a like-C language, Arena is basedon the SIMAN one, while Process provides a Visual Basic for Applicationlanguage to program the blocks. They are not only based on differentlanguages, but often allows the user different levels of customizablefeatures.

The System Dynamics

John Sterman, one of the main experts in System Dynamics, gives aninteresting definition of this method (Sterman, 2000):

System dynamics is a method to enhance learning in complex systems.Just as an airline uses flight simulators to help pilots learn, systemsdynamics is, partly, a method for developing management flightsimulators, often computer simulation models, to help us learn aboutdynamic complexity, understand the sources of policy resistance, anddesign more effective policies.

I think that not only system dynamics, but any other simulationtechnique is aimed at helping us to learn about complexity. Typically thebusiness process simulation is also aimed at creating 'management flightsimulators', since they are often used in modelling and optimizing theproduction activities.

50

Page 53: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 4

The feedback and cause-effect diagrams

The system dynamics is mainly aimed at describing systems in term offeedback chains. The general behaviour of an even complex organization isalways driven by deterministic cause-effect relationships.

Since system dynamics models are based on differential equations, therelationships among state variables are well known, and it is always possibleto describe the model behaviour in terms of cause-effect phenomena.

The system dynamics formalism introduces a well defined schema toexplicitly design the feedback loops characterising the model.

In particular, two types of feedback can be observed. The negativefeedback loops are cyclic relations characterized by opposite sign effects.They bring the systems from out-of-equilibria states or exogenous inputs tothe stable equilibria.

On the contrary, the positive feedback are self nourishing relationswhich drive the system to explode and tend to cause the so called pathdependency phenomena. An initial unbalanced situation tends to amplifythe unbalance over time.

The cause-effect diagrams

The cause-effect diagrams are very useful to explicit the phenomenawhich determine the behaviour of the system.

The figure 9 shows an example of cause-effect diagrams, with the twotypes of feedback loops. The positive feedback is determined byrelationships of the same sign, which continuously increase the growth ofthe state variables.

On the contrary, the negative feedback loop tends to balance the system,because some flows are of different signs and produce opposite effects.

The cause-effect diagrams are very effective representation of aggregatebehaviour of the system. They are very useful to express the modeller's ideaof determinant relationships underneath the model. This diagram is notclosely related to the model implementation, since it is used as a generaldocumentation schema. It is only a formalism to represent cause and effectloops.

51

Page 54: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Simulation techniques

figure 9 Cause-effect diagrams

Even in micro-founded simulation model, it can be very useful torepresent both the local phenomena and the aggregate hypothesis on themacro-level relationship among the observed state variables.

The stock-flow diagram

The simulation models in the system dynamic formalism are mainlyrealised with the use of three types of variables: the stocks, the flows andthe auxiliary ones.

The stock variables make reference to level variables, which areincreased and decreased by the flows over time.

As for the example in figure 10, the stocks are represented within a box,while the flows are drawn as pipes (arrows) suggesting the direction of theflows.

52

Employee'smotivation

Productivity

Income

Dividends

+

+

+

+

Demand

Market price Gap between real andnominal value

Offer

Real value

+

+

-

+ -

Positive feedback loop

Negative feedback loop

Page 55: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 4

The other variables are called auxiliary and can represent constant valuesas well as functions, which dynamically compute values.

figure 10 Stock-flow diagram

From a mathematical standpoint stocks accumulate or integrate theirflows; the net flow into the stock is the rate of change of the stock. Thefollowing equation describes the mathematical form of the stock-flowdiagrams:

stock t =∫t0

t

[inflow s−outflow s]∂ sstock t0

The lookup functions

Since the system dynamics is aimed at representing models at a very highlevel of abstractions, the use of stock and flows is not enough flexible torepresent non-linear phenomena emerging from micro-level dynamics,whose dynamic is omitted and is considered exogenous.

In order to make models more flexible, the system dynamics often makesuse of the so called lookup functions. They are non linear functionsmapping some input values in corresponding outputs, whose level is

53

Page 56: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Simulation techniques

empirically determined by the shape of the lookup function.

figure 11 An example of lookup function

The figure 11 shows an example of lookup function, which reproduce anon-linear relationship between the number of potential customers and theeffectiveness of the marketing sales drives. It is reasonable to imagine thatthe more the the potential customers decrease the more is their resistance tomarketing claims. Mostly because a fixed part of the market is insensitive tothe sales campaigns. Since the model does not simulate the choices of eachsingle customer, the aggregate effect of the market resistance is modelledwith these empirical functions.

Material and information delays

The delay between an event and its effect on the system is a crucialaspect of this type of models. Contrary to the discrete event simulation, inwhich delay is an effect of the time passing in executing some job, thesystem dynamics needs to represent delay mathematically.

Two types of delay have been defined. The material delay is used tomimic the time passing to execute some job on physical objects. This delayimplies a constraints: the sum of inputs must be equal to the sum of outputsin the long term. It doesn't matter when an object exits from the delayblocks, it is important that sooner of later it will exit.

The information delays are not liable to this constraint. Simulating adecisional process, sometimes happens that older information are replacedby newer ones. In this case the impulse given by the older information will

54

Page 57: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 4

not exit from the delay block: it is ignored.The modelling of fixed delays is intuitive: each input quantity remains

into the level variable for a given time, then exits as one output impulse ofthe same quantity.

The SD formalism provides other sophisticated delay functions, whichare able to simulate smoothed delay effects. Imagine that a manufacturecompany receives a big order. Due to its limited production capacity, theoutput will be spread over time.

Unfortunately the SD graphical formalism does not provide a symbol tospecify the type of delay it is applied to a variable. It is only able to showthat a specific flow is applied a delay, by drawing a double lineperpendicular to the flow line. An example is presented in the figure 10.

Building blocks

Since system dynamics is based on mathematical functions, it is naturalto imagine that the simulation models can be composed of sub-models. Amodel can be joined to another simply inserting into diagrams a referenceto some variables of the other one. The simulation engine will manage thisoperation by properly ordering the causal set of equations and verifying thewhole model.

The designing of models based on the composition of building blocks ispossible in theory, but it presents a lot of traps. In fact, system dynamicsmodels analyse system from a very abstract standpoint and the internalmicro dynamics are represented with aggregate functions, like lookups anddelays.

This approach leads to calibrate a model as a whole and makes difficult toplug together models without recalibrating them.

A good use of the building block can be represented by the plugging ofcomputational blocks, which reads values of other models but does notmodify them. It could be useful, for instance, to plug a block, which is ableto compute an enterprise balance, into a business model.

The problem of the model re-calibration is common to each simulationtechnique, even if, in the case of system dynamics, it is more delicate.

55

Page 58: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Simulation techniques

The main software

The System Dynamics software are very limited to three well-knowncommercial applications. Stella, I-think, VenSim and PowerSim are themain used applications. Differently from discrete event software, the systemdynamics tools can exchange models from a platform to the others, sincethey are based on an ordered list of differential equations.

Unfortunately there are no open source applications, even if thecomputation engines are based on well known numerical integrationmethods.

Agent based models, equation based models and object basedmodels

The agent based simulation technique is less identifiable than the otherspresented before. In fact, while the system dynamics defines three types ofvariables and business process simulation is based on the concept of thetoken flowing throughout the process, the agent based models do not makereference to a set of well-defined building blocks.

The only one concept identifying such kind of models is represented bythe “agent”, whose exact definition is difficult to be provided. What isparticularly lacking in this simulation methodology is the representation ofrepresentation with graphical diagrams.

An agent definition

The agent concept is the basis of the new research field in simulation:the agent based modelling. In order to explain the agent role is interestingto analyse what do we intend for agent. A good definition is found inHolland (1998):

Ants in a colony, neurons in neural networks, or particles in physics – allare described in terms of rules or laws that determine their behavior in alarger context. In each case we can describe these agents as processingmaterial, energy, or information to produce some action which is usuallythe transport of material, energy, or information. More generally, we candescribe the agent as processing an input to produce an output. We can

56

Page 59: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 4

go further using the notion of state: we can talk of an input state beingprocessed to produce an output state. The input state is determined by theimmediate environment of the agent, an the output state determines theagent's effect on its immediate environment.

The Holland's definition of agent is very generic, but according to theABM literature it well fits the wide range of subjects ABM has been used torealise models.

From the Artificial Intelligence (AI) point of view the agent is boundedby a more specific role. The most commonly referenced definition isprovided in Russel and Norvig (1995):

An agent is anything that can be viewed as perceiving its environmentthrough sensors and acting upon that environment through effectors.

Russel and Norvig consider an agent a production system: a systemwhich gets information from the outside, elaborates them and changes itsstate and eventually the environment. Upon this definition they definedfour categories of agents: simple reflex agents, goal-based ones, agents thatkeep track of the world and utility-based agents.

The following definition, from Franklin and Graesser (1996), is aneffective representation of an agent, as considered by the ArtificialIntelligence:

Intelligent agents are software entities that carry out some set ofoperations on behalf of a user or another program with some degree ofindependence or autonomy, and in so doing, employ some knowledge orrepresentation of the user's goals or desires.

The Multi-Agent Systems are software architectures populated by suchkind of agents. This is the key concept separating the MAS form the ABM.An agent based model is a conceptual model of a social system and its aim isto investigate collective behaviours: the study is usually carried out withsimulation.

On the other hand, MAS are aimed at realising a communicationframework that enables the agent to coordinate themselves to act in realsystems (Brustoloni 1991).

Even if agents do not operate in the real world they are designed andconceived to “live” in a hardware environment as computers, operatingsystems, networks, etc. (Franklin and Graesser, 1996).

57

Page 60: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Simulation techniques

It is no accident that the ABM are “models” of social systems, while MASare systems themselves.

Comparing the agent based models to the equation based models theconcept of agent becomes the discriminating factor. This is not the case ofthe relation between agent based models and discrete event simulationmodels.

In fact, they are made of entities which change their state over time andtheir actions may affect other entities' state. So the distinction betweenABM and DE models is more vague.

The main difference between ABM and DE models can be identified bythe multiplicity. Agent based models are typical swarms of similar entitiesinteracting among them and the environment. The relational structure isoften loosely uncoupled, with aggregation phenomena which arecompletely endogenous to the model. On the contrary, process models areclosely referred to a given hierarchy and a well defined set of relationshipsamong objects. Process simulations are designed as flows of possible paths,each single token may follow. The possible paths are predetermined by themodeller.

From this description emerges that ABM have been introduced to bettermanage and study the complex adaptive systems, since the traditionaltechniques are limited in modelling adaptive behaviours and ever changingrelational structures.

The aim of these swarm based models is to find emergence phenomenacaused by the cooperation rather than by the each single agent's will. Theconcept of “Society of Mind”, elaborated in Minsky (1985), a good metaphorof how aggregation of simple elements can determine intelligentbehaviours.

According to this definition of agent based model, there is a cleardifference with the process simulation one. Since the activities, the tokens,the flow controllers can be considered agents on the basis of the givendefinition, they do not form swarms. We can divide such kind of models inAgent Based Models and Object Based Models.

58

Page 61: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 4

Diagrams for agent based models

Unfortunately the agent based modelling is not provided with a rich andwell-defined set of diagrams to visually describe the internal logic of themodel. This is actually the main drawback of simulation approach,particularly because the visual languages increase the effectiveness and theeasiness in designing models and in sharing them with the community.

Actually the only attempt to graphically represent an agent based modelis the ERA (Environment Rules Agents) scheme introduced in Gilbert andTerna (2000).

figure 12 The ERA scheme (Terna and Gilbert, 2000)

The ERA diagram highlights the type of agents involved in thesimulation model and the way their “mind” is implemented, as shown infigure 12. In particular, the ERA scheme is a methodology to separate theagent as a player from its mind, whose choices are determined by a rulemaster. The rule master can eventually have its rules changed by a rulemaker. The rule master represents the adaptive proxy for the model, whilethe rule maker represents the evolutionary one.

Differently from the other techniques, the ABM often represent societies

59

Page 62: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Simulation techniques

of agents which live in a space or are connected to a network ofrelationships. For this reason a good graphical representation is sometimes adisplay showing the state and the dynamics of the simulated world on thecomputer screen.

This diagram can represent the architecture of the model at a very highlevel of abstraction, while the logic of the single agent's behaviour cannotbe represented.

The most promising graphical language to represent simulation models isthe Unified Modelling Language (UML), since it is generally accepted,diffused and extensible. In the next chapter I will introduce some hints toextend the UML and the Agent-UML to be adapted to the agent-basedsimulation models.

The main applications

The ABM tools are divided into three main groups:• the language-specific modelling environments;• the open libraries or frameworks, based on standard programming

language;• the computer network based architectures, particularly used to enable

mobile autonomous agents (MAS).The Starlogo and Netlogo environments represent integrated

applications, which provide the user a language specifically designed tomodel spatial agent based environments.

This approach has two main advantages. First they are very easy to beused, since the language provides a reduced set of instructions and hides thetechnicalities to the final user. Moreover the modelling environment cancount of a ready to use two dimensional space, dramatically reducing thecode typing and the design time.

The close dependence to the spatial representation is an advantage but, atthe same time, a great limit for the tools flexibility.

The most important network based frameworks are Cougaar and JADE.These framework are designed to create networks services used byautonomous agents to perform some particular goals or to coordinate with

60

Page 63: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 4

other agents in the network, according to the Distributed ArtificialIntelligence paradigm. Such kinds of architectures are not specificallydesigned for simulation, but defining an appropriate time manager it ispossible to simulate virtual environments populated by intelligent agents.

Obviously these kind of platform cannot represent a general purposesimulation environment, since they are particular complex in the modelimplementation and require a network of computers to perform asimulation run.

The third category, the open libraries, is composed of simulation toolkits,based on standard programming languages, like C++ or Java. The users'simulation models are stand-alone programs which are written using thefeatures provided by those libraries.

The model implementation follows a well defined schema, since someimportant objects have to implement specific interfaces of the library, inorder to be simulated.

The most diffused tools are part of this category. Unless they require alow-level programming skill, the ABM requirements are closely dependsfrom the context they are aimed at simulating. They are applied in a widerange of domains and they make reference to adapting environments whosecharacteristics change time-to-time.

The interaction among agent can exist, at same time, on differentsemantic levels. The most diffused type of interactions are:• non-spatial: agents meet other agents simply because they are part of the

same social group;• spatial: agents meet other agents when they are in the same local area;• hierarchical: agents meet other agents because they are part of a network

of relations which are hierarchically ordered.

The levels of simulation

The techniques presented in this chapter are different and providedifferent visual representation languages. This is mainly due to the type ofproblems they have been designed to model.

61

Page 64: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Simulation techniques

In the table 1 I summarized their effectiveness in managing the detailcomplexity, the dynamic complexity6 and the capability of representingadaptive behaviours (internal adaptation) and adaptive relationships(external adaptation).

Technique Detailcomplexity

Dynamiccomplexity

Externaladaptation

Internaladaptation

Businessprocess

Yes No No Possible

Systemdynamics

Possible Yes No No

Agent based

modelling

Yes Possible Yes Yes

table 1 How the simulation techniques are able to model complexity

Due to their different approaches they have to be used to representspecific types of system, but the way they express the conceptual modelsmay be integrated.

Through the use of different views and diagrams the conceptual model ofthe system can be more clear and can improve the validity of its simulationmodels.

6 See chapter 1 for a detailed description of detail and dynamic complexity.

62

Page 65: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 5

5 Unified Modelling Language for Simulation

Introduction

This chapter introduces the Unified Modelling Language (UML), astandard visual modelling language designed to support software engineersin documenting information systems and applications.

Since simulations are computer applications, the UML is a goodformalism to represent the conceptual model.

I propose to extend some UML diagrams to effectively describe modelswith a view of the system, the characteristics of its entities and theirbehaviour.

UML is an open and extensible paradigm, and it is actually evolvingtowards the software agent representation, with the contribution of theAgent UML project (AUML, 2003) and, concerning the agent interactionprotocols, of the FIPA organism (FIPA, 1996).

The need to adapt UML to simulation depends on the particular featuresthese special applications have in comparison with the traditional computerprograms.

It is necessary to have a description of system dynamics at differentlevels of abstractions and with different time representations.

UML and the discrete simulation formalisms

The use of a software designing approach, like UML, in representingsimulation models is much more useful concerning discrete ones.

In fact, since the continuous time approaches are based on mathematicalequations, they are compact and easy to be represented. As a matter ofcourse, the system dynamics technique provides a set of self-explanatoryvisual diagrams.

63

Page 66: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Unified Modelling Language for Simulation

Nevertheless they are affected by some expressive lacks. For instance, itis not able to discriminate the difference between parameters andendogenous state variables; it lacks in the representation of the lookupfunctions, which are drawn as they were standard auxiliary variables.Besides, they do not highlight the type of delay applied to the stockvariables, limiting the intelligibility of the model structure, mostly becausethe delays have a great impact on the overall outcomes of the simulation.

Taking into account the discrete techniques, the implementation ofagent based models and business process simulations can be reduced to ageneric object-oriented modelling approach. So the UML becomes asuitable choice to represent those models.

The conceptual model of the system

Both the system dynamics and business process approaches provide away to describe high level views of system entities and their relationships,while both of them envisage a limited formalism to graphically describe thebehavioural view of the system.

The system dynamics detailed behaviour is represented by the equations,often involving more or less complicated functions. This makes the visualrepresentation unnecessary (or impossible).

The business process approach does not define a specific representationof the activities' internal behaviour, since they are hard coded into theblock source code. Often these implementations are deeply dependent tothe simulation tool language.

The case of agent based simulation models is more distressing. It does notprovide a single diagram of the model structure, nor of its behaviour.

The role of UML

A good approach to represent discrete simulation models is the UMLlanguage, particularly because it is extensible and rich of flexible diagrams.

The unified modelling language, developed by the Object ModellingGroup, is an attempt to create a formalism, independent from the

64

Page 67: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 5

development methodology, which can be used to represent both staticapplication structure and different aspects of dynamic behaviour.

To use an official definition (OMG, 2001): The Unified Modeling Language (UML) is a language for specifying,visualizing, constructing, and documenting the artifacts of softwaresystems, as well as for business modeling and other non-softwaresystems.

Even if the UML is closely oriented to software designing, it is genericenough to be adapted to the description of any algorithmic and object-oriented systems.

Concerning this framework there are good opportunities to use UML indesigning discrete simulation models, independently from the languagethey are implemented with.

The UML specifications defines a lot of official diagrams and rules, but itis not very normative, since the approach of OMG is to acknowledge themost diffused uses in the new releases. From the simulation standpoint,only a subset of the UML official views are presented and eventuallyextended.

It is clear that the UML is not properly designed to represent conceptualmodels of virtual environments, but fortunately the OMG decided to designUML as an open and extensible standard. Therefore I try to focus on theextensions that are necessary to describe simulation models.

Basically the use of UML is the most standard and universally recognizedway to share the knowledge and idea of the system architecture (the staticview) and its behaviour over time (the dynamic view).

Starting from the works on the UML extensions in representing agentswithin the framework of the Multi-Agent Systems, I try to define a reducedset of UML diagram, providing some extension to the standard symbolic set,to provide a generic representation of the model, independently from itsdetailed implementation.

The class diagram

The class diagram is the most diffused schema of UML. It is aimed at

65

Page 68: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Unified Modelling Language for Simulation

representing a static overview of the system entities and their relationshipsas well as their hierarchical tree. In particular, the class diagram containsthe interfaces of the classes and four type of possible relationship amongthem.

The interface of a class is symbolized by a squared box containing theclass name, its state variables, called attributes, and the operations it is ableto perform, called methods.

The methods react to some types of messages. In Page-Jones (2000) threetype of messages are identified: • information messages, give the object some data about something

happened somewhere else;• question messages, are requests made by an object which is supposed to

wait for an answer;• imperative messages, ask the receiver to perform a well-defined action.

The UML class diagram does not provide a notation to specify whichmessage a method is designed to receive, although software developers usesome custom notations to identify the nature of the methods.

The actions

Typically the methods attached to question messages are named usingthe get prefix7. If, for instance, we had to design a class that is able to returnits temperature we should define a getTemperature() method.

The methods used to change the state of a private attribute are usuallynamed using the set prefix. In case we want to change the temperature ofthe object in the previous example, we have to define a setTemperature()method.

The imperative messages usually correspond to all the methods which donot contain the get (sometimes is) or set prefix.

The imperative messages assume greater importance when thesimulation model is based on agents: pieces of software which are able totake decision internally and to act autonomously. The explicit identificationof how methods are involved in the agent's 'autonomous' process can be

7 In case the return value is a boolean value the word is becomes the prefix.

66

Page 69: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 5

useful to point out the interactive capability of the agents.In Bauer (2002) and Huget (2003) some extensions to the standard UML

class diagram are proposed, even if they are specifically oriented to designthe interface of BDI (Belief Desires Intentions) agents.

In Odell et al. (2004) it is stressed the importance of agent classificationby roles they can play and groups they belong to.

Here it is proposed a simplified approach extending the semantic of theschema, without introducing new symbols or notations.

Each active element in the simulation has to show its capabilities or roleswith the UML socket notation, commonly used to represent the interfaces.In a broad sense each capability or role is itself a sort of interfacecharacterizing the external behaviour of the object.

figure 13 An example of class diagram with the socket notation

The figure 13 shows an example of the use of socket notation to point outthe interaction capability of the RadioScanner agent. It is able to performthe scanning, which is an action some elements in the system may require.In this case the patient who requires a scintigraphy will require thescanning action provided by the radio scanner.

The state variables

Another important issue concerning the class diagram is the missing ofdetails about the nature of a variable.

As observed many times a simulation experiment consists of a sequenceof states. An object-oriented model can have many state variables, spread in

67

Page 70: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Unified Modelling Language for Simulation

different objects. If an object is conceived as a finite state machine (FSM),its state dynamics can be represented in a UML state diagram. Often theobjects are not FSMs and their states are represented by some particularcombinations of variables.

The representation of a class which embodies an agent, has to show someadditional details in respect with a traditional class. In fact, the properties ofan object do not self specify a semantic and each property may be the fieldof a database, a state variable, a characteristics of the object, a reference toother objects and so on.

My proposal is to attach some stereotypes to the attribute in order to welldefine their roles. The possible stereotypes for simulation objects are:• <<state>>, indicates that the variable assumes a particular role in the

definition of a simulation state;• <<param>>, indicates that the variable is an input parameter.

Together with the state variables it might be useful to highlight theconstraints associated with them. Often a constraints is used to verify avariable range of existence.

The constraints can be specified using the UML note symbol, whichconsists in an external box linked by a line connecting the variable and thenote box.

The relationships

The relationships between two classes can be of one of the followingtypes: • the inheritance, when a class extends the other (the generalization

relationship);• the association, when an instance of a class has a reference to the

instance of another one (it can express the multiplicity by indicating thepossible number of relations they can have;

• the dependency, when a class generically makes use of another, such thatin case of its modification, the dependent class will be affected in itsbehaviour;

• the aggregation and composition, when a class is composed by objects of

68

Page 71: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 5

other class types. This relationship is less related to the implementationand it is more interesting in designing of conceptual models.The different type of relationships are shown in the figure 14. Since they

have been designed to represent OOP concepts like inheritance andpolymorphism, their role in simulation concerns concepts like acquaintanceamong agents.

The association relationships indicates that one object “knows” the one itis associated with.

figure 14 The types of legal relationships defined by UML

Together with the class diagram it is often used the object diagram,which does not only shows the hierarchical relationship among classes, butfocuses on some particular implementation scenarios composed of specificclasses instances. It can be useful to represent possible states where someobjects set themselves in particular connections.

The class diagram is not particularly interesting for simulation, because itis aimed at representing a static view of the system. Nevertheless it isimportant to create a proper representation of the element involved in thesimulation and their relationships.

69

Page 72: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Unified Modelling Language for Simulation

The sequence and interaction diagrams

The sequence and interaction diagrams are mainly aimed at showing thesequence of the calls among classes and objects within a particularprocedure. The two diagrams contain the same information, even if theyshow a sequence with different views. The first ones highlight the sequenceof the calls, while the interaction ones emphasize the link among objects.

These kind of representations are effective in showing the collaborationamong object in performing some jobs, but they are much less effective inshowing their behaviour in detail.

Recently, with the introduction of the UML second release, the sequencediagram have been extended with the possibility of displaying the loops(cyclic repetition of some blocks of operations). Nevertheless they are notso easy to be used, and they do not completely solve the limitations ofsequence diagrams in representing complex algorithms.

figure 15 FIPA Contract Net Protocol inUML

Conditions cannot be effectively represented, such that in Odell et al.(2001) it is proposed an extension of the sequence diagram. They proposed

70

Page 73: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 5

the introduction of a diamond, symbolizing a conditional action. It is usefulto design interaction patterns among communicative agents. The figure 15shows an example of how a contract can be carried on by two agents.

In case of a discrete event simulation models the sequence diagram canbe used to show how events interact with the objects in the simulation. Inorder to achieve an effective view of the events affecting the systems Ipropose an extension of the sequence diagram.

The time-sequence diagram extends the UML sequence one, indicatingon the left side a special actor: the time manager.

From the time line some single, cyclic or group of events may begenerated. They show the operation chain that is originated by the eventraising.

figure 16 An example of time-sequence diagram

As shown in figure 16, the line connecting time and the object receivingthe event notification is labelled with the @ symbol. It points out when ithas to be raised and the name of the event.

In case of looped ones the @t..r notation is used, where t is the time of

71

Page 74: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Unified Modelling Language for Simulation

the first event raising and r the repetition frequency.The group of operations are indicated between square parenthesis and

the group time execution is indicated only once in the diagram.If a group is complicated it can be exploded into sub-diagrams.

The activity diagram

The activity diagram comes from the well-known flowchart one. In theUML context it has been enriched with a set of very interesting additionalfeatures, which perfectly match with the needs of representing businessprocesses and discrete event simulations.

The additions are in particular represented by the presence of the socalled swimlanes (see figure 17), through which each activity can bevisually associated with an organizational unit. This schema is very similarto the one developed by the most famous discrete event business processsimulation packages. This UML definition provides a useful standardizationin the representation of the business processes.

figure 17 Acrivity diagram of an hospital process

72

Page 75: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 5

From the discrete event simulation standpoint, this diagram can quitecompletely describe the simulation behaviour.

The activity diagrams can be used to show both the high level behaviourof the model, particularly in the process simulation, and the detaileddescription of an algorithm which plays an important role in the model.

Unfortunately this diagram tends to be prolix and often requires muchspace.

The use cases diagram

The use case diagram is the most abstract view in the UML collection. Itis aimed at showing some particular scenarios of interaction betweenphysical entities, like humans or server machines, and software procedures.

Even if the agent is considered something external to the system itinteracts with, the use case diagram can be very effectively used torepresent the interaction between the entities of the system and theenvironment, within the simulation models.

It can be also used in representation of resources management within abusiness process model, taking into account the limitations of businessprocess diagram in representing this particular and important aspect of thesystem. Often the human and machine resources are not represented in theprocess schema so that the use case diagram can shows in which operationsthe resources are involved in.

The process in the figure 17 shows a part of a complicated process of thepatient requiring hospital services. It passes a lot of information to thereader, but a crucial aspect of the simulation model is omitted: the role ofthe employees and of the machines within the process. The onlyinformation comes from the subdivision of the process across the functionalunits. The use case diagram can integrate this diagram, pointing out the roleeach resource plays in the process. The figure 18 shows the use casediagram which shows the duties of laboratory technicians within theprocess.

73

Page 76: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Unified Modelling Language for Simulation

figure 18 A use case diagram representing the hospital personnel's duties

The use case formalism is very useful in representing scenarios, so it canbe used to integrate any kind of simulation model, showing the interactionof some entities of the system in particular common situations. Even if theydo not represent every possible future evolution of the simulation model,gives the reader a clear idea about the nature of the model dynamics.

74

Page 77: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 6

6 JAS: Java Agent-based Simulation library

Introduction

As previously shown in this work, the agent based simulation formalismis algorithm-intensive and requires the massive use of the programminglanguages. This is perhaps the main reason explaining the high diffusion ofopen source tools, particularly in comparison with the system dynamics andthe business process applications.

From the scientists point of view, the open source approach is a greatadvantage, particularly because the scientific research is interested inimproving the formalisms and in having a fine control on the logic and thealgorithms driving the experiments.

This chapter introduces and discusses about technical aspects of JAS, anopen source platform designed to create agent based as well as object basedsimulation models8. It is founded on a multi purpose discrete eventsimulation engine and provides a rich set of facilities typically used in ABM.

A brand new tool

Often the choice of designing specific languages is due to the necessity togive the user a reduced set of commands, specifically designed for a specificdomain.

Commercial simulation tools are often based on context-specificlanguages, which limit the capabilities of experimenting new approaches inmodelling systems and reality.

The designing of generic and extensible architectures mainly depends ontwo factors:

8 I designed and implemented it with the preciuos contribution of Riccardo Boero, GianluigiFerraris, Matteo Richiardi and using some third-party open source libraries.

75

Page 78: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

JAS: Java Agent-based Simulation library

• the use of a standard, generic and portable programming language,• the open source development approach.

In the JAS development I used Java. This choice is due to many reasons.The most important one is that Java is more and more diffused in theprogrammers' community, that means it is standard. Its platformindependence guarantees to involve a very large community of users anddevelopers.

Java is also the natural language for the Open Source community. Thechoice of open source is crucial. I think that public scientific research mustbe carried on, as much as possible, with public domain software, in order toguarantee controllability of results and continuous improvements in thedirections scientific researchers consider more promising.

The Open Source license allows the developers to reuse the code,reducing the development costs, increasing the software testing andavoiding to “reinvent the wheel” every time a well known feature isrequired (Zhao and Elbaum, 2003; Krogh and Hippel, 2003).

Thanks to the open source approach, JAS has been developed takingadvantage of other open source tools.

The JAS library

The logical unit which represents a simulation model is a class creatingand coordinating a set of agents and some objects representing theenvironment. In particular, a model has to perform the following fouroperations:1. it has to manage the parameter setting, before the simulation

experiments starts;2. when parameter are finally set up, it has to create some agents' instances

in the computer memory;3. in order to execute the simulation experiment, it has to define an event

schedule, which lets the things to happen;4. it might eventually manage the simulation end event.

Since each model shares the same centralized event list, more than one

76

Page 79: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 6

model can be execute at the same time. They schedule events synchronizedby the JAS event list and so they can be executed together, enabling themodel federation paradigm.

Since the ABM is aimed at simulating virtual societies there is the needof an actor/agent which “observes” the virtual world from the outside andproduces an aggregate view of the system. This paradigm, called model-observer, has been introduced by Minar et al. (1996) in the Swarm platform.In the Swarm system it is hierarchical since the observer creates the modeland observes it. In JAS the metaphor is more realistic, because the model-observer relationships has been uncoupled.

The model and the observer are created independently and run inparallel, sharing the same time manager: they are executed just like theywere a federated model.

This architecture allows the user to create models of models or plug-inmodels representing different aspects of the same system.

A model can be a unit representing the whole simulation application oronly one piece of it. The figure 19 graphically shows the relationshipsamong the models and the observers.

figure 19 The JAS hierarchical model-observer relationship

Simulation experiments

The JAS architecture is is able to join the models, as Java compiled code,

77

Properties

Methods

Schedule

Observer: SimModel

Properties

Methods

Schedule

Model: SimModelProperties

Methods

Schedule

Model: SimModel

Page 80: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

JAS: Java Agent-based Simulation library

at runtime. A simulation model is built as a standard Java program, butthough the ISimModel interface the JAS simulation engine is able todynamically load and execute them.

The dynamic loading of compiled modules is possible because of the Javaruntime architecture. Each compiled class is searched on the file system andloaded only when it is necessary, so that no early linking is necessary.Thanks to this features, the models can be used as building blocks.

A simulation experiment is defined through an XML file containing allthe information to find Java classes and to properly set the simulationparameters. The activation of the models as well as the observers dependsonly by this file. So the execution of a model without its graphicalrepresentation (without being observed) can simply obtained switching offthe observer from the experiment file definition.

The Java classes dynamic loading

In order to perform the dynamic loading of the Java compiled class andto manage the models as building blocks, I has to bypass a limitation of theJava architecture. In fact, only the classes stored in a specific path (theclasspath) can be dynamically loaded. So I9 designed a custom Java classloader, which works as a wrapper of the standard class loader searching forclasses outside the standard class path10.

The engine package

The engine package contains the core of the library and all is necessaryto design a user's model as well as the class jas.engine.Sim, containing globalstatic references to main tools and simulation status variables.

The simulation engine (the jas.engine.SimEngine class) is the centralcoordinator of the simulation experiments and, through it, the atomicmodels can dynamically obtain a reference to the other ones.

The SimModel class

The class jas.engine.SimModel is the main abstract class that each model

9 With the help of Riccardo Boero.10 The dynamic class loader is implemented in the jas.engine.DynamicClassLoader class.

78

Page 81: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 6

has to inherit from. This class force the user to override some methods inorder to create a sequence of necessary operations each model has toperform. The required methods are the following:• setParameters: is invoked before the simulation experiment is executed,

giving the user the possibility to require parameters to the user or toretrieve them from a repository;

• buildModel: is invoked to create the agents set and event schedule;• simulationEnd: is optional and it is called when the experiment ends.

The JAS engine manages a collection of SimModel heirs sharing the sameevent list, such that each events happen sequentially and independentlyfrom the model scheduled them.

A such kind of architecture must provide the user a mechanism to letparallel model to communicate. Since each running model is appended tothe simulation engine list, JAS is able to return a model a reference to anyother. The following instruction is user by a model to obtain a reference toa MyModel instance:

MyModel model = (MyModel) Sim.engine.getModelWithID("MyModel");11

The events package

The jas.events package is very important in the JAS architecture,particularly for the synchronization and the time management of thesimulation run. The figure 20 shows an overview of the event objecthierarchy.

SimEvent

According to the discrete event simulation formalism an event issomething that happens at a particular time. From an object-orientedprogramming standpoint, an event is an object that is able to call a methodof one or more target objects.

11 Obviously the required model may not be present and this event has to be opportunelymanaged by the modeller.

79

Page 82: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

JAS: Java Agent-based Simulation library

figure 20 The UML class hierarchy of the jas.events package

The jas.events.SimEvent is the basic type of event, as show in the figure20. It is an abstract class defining the minimum requirement for any kind ofevent. Any deriving event has to redefine the fireEvent() method, accordingto the type of target object it is designed to manage. In other words, anyinheriting class will change the way an event is fired.

The SimEvent class is equipped with an absolute time property,essentially to order events in time. Moreover, since agent based models areusually realised according to the message passing world view12, each eventcan be looped, too. If an event is looped it is rescheduled after every firing,otherwise it is trashed.

12 See chapter 2 for a definition.

80

Page 83: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 6

SimSimpleEvent

The jas.events.SimSimpleEvent is the simplest implementation of theSimEvent abstract class. It is used to schedule an event that will be notifiedonly to one agent.

SimCollectionEvent

The jas.events.SimCollectionEvent objects are able to invoke the samemethod of the agents populating a Java collection.

This event is important for agent based models because it allows the userto manage, with one call, an undefined set of agents.

Basically, the event firing consists in invoking a specific method of anobject, so this kind of event can be used only with homogeneouscollections, that is each object contained in the collection must be of thesame class type.

The target method of each agent is invoked strictly in a sequential order,defined by the collection iterator.

SimMultiCastEvent

When a collection event is fired, it sends a message in broadcast to all thecomponents of a collection. Sometimes it may be useful to select someparticular receivers for the broadcasted message. Technically this operationis called multicast communication.

The jas.events.SimMultiCastEvent can be effectively used to managesuch situation. A multicast event works like an information service, sendingmessages to all the service subscribers.

Each agent, independently from its class type, can subscribe itself to themulticast event and each time the event is fired it receives a call.

A typical example of the use of the multicast event is the management ofthe shifts in a production factory system. Both humans, machines and otherservice objects are interested in being informed about shift changes, inorder to change their state.

The following code shows how to create such information service:

81

Page 84: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

JAS: Java Agent-based Simulation library

public static final int EVENT_SHIFT_CHANGE = 1;…public void buildActions() {

… SimMultiCastEvent shiftEvent = new SimMultiCastEvent

(EVENT_SHIFT_CHANGE);eventList.scheduleMultiCast(0, Sim.toHours(8), “ShiftChange”, shiftEvent);

}

In order to receive the news, the agent has to be implemented as follows:public class Agent implements ISimEventListener {

public Agent() {SimMultiCastEvent ev = Sim.getMultiCastService(“ShiftChange”);ev.addEventListener(this);

}

public void performAction(int eventID) {if (eventID == Model.EVENT_SHIFT_CHANGE)

doSomething();}

As shown in the example code, the JAS engine is able to manage a list ofmulti cast services, such that any object within the model can directlyaccess it.

SimSystemEvent

A system event is a particular type of event directly notified to the JASengine. The most important system events are:

EVENT_SHUTDOWN makes JAS to exit, shutting down the JavaVirtual Machine.

EVENT_SIMULATION_END causes the simulation to be stopped,invoking the simulationEnd() method for each running model.

EVENT_SIMULATION_RESTART causes JAS to restart the currentsimulation.

Since the supported system events are defined in the Sim class, a typicalinstruction to schedule a system event is:

82

Page 85: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 6

eventList.scheduleSystem(1000, Sim.EVENT_SIMULATION_END);

SimGroupEvent

When at given point in time, a group of operations must be sequentiallyexecuted, they can be logically grouped into an instance of thejas.events.SimGroupEvent class.

A group of actions can be composed of heterogeneous events and theycan be easily scheduled with a unique instruction.

The grouping is also useful to closely control the execution order of theevents, since they are always executed in an atomic instant of time. Theyare executed in the same order they have been scheduled.

The following code is an example of how a group event can be used:SimGroupEvent s;

s = eventList.scheduleGroup(0, 1);s.addEvent(space, "diffuse");s.addCollectionEvent(heatBugList, HeatBug.EVENT_STEP);s.addEvent(space, Sim.EVENT_UPDATE);s.addEvent(unhapSeq, Sim.EVENT_UPDATE);

EventFactory

Taking into account that the simulation engine fires many events duringan experiment, the event objects have been design to be recyclable, in orderto dramatically reduce the memory occupancy.

Each event is an object, so it must be instanced and, after it is fired, nolonger used. Since the Java Virtual Machine does not release memory whenan object is no longer in use, but only under particular conditions (seeLindholm and Yellin, 1999), the event construction and destructionprocesses are to be managed.

In Armstrong (98) it has been noticed that the Java Virtual Machinespends about 20% of its execution time in dynamic memory management,thus, an high-performance memory manager can greatly reduce the overallexecution time. In order to increase the performance of the simulationengine the event generator recycles the events.

83

Page 86: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

JAS: Java Agent-based Simulation library

The jas.events.EventFactory is a custom garbage collector designed tomanage the event objects lifetime cycle. When a new event is required, theevent factory checks if a recyclable one is present within its cache beforecreating a new instance.

Static and dynamic binding

JAS supports two methodologies to invoke agents’ methods. The first oneis also known as dynamic binding.

The dynamic binding is very simple to be used since it requires a textualrepresentation of the method to be called. If, for instance, an event for theagent myAgent has to be fired at time 123, the user may schedule it withthe following instruction

eventList.scheduleSimple(123, myAgent, “doSomething”)13

The Java compiler does not check if doSomething really exists: it isverified only at runtime. This mechanism is based on the Java Reflectionfeature. Although the reflection mechanism is very simple and elegant, it isvery inefficient, since it is about 20 time slower than a native direct access.

Moreover the error trapping is filterer by reflection object and so thedebugging is more difficult.

These are the reasons why an alternative invocation method has beenprovided. It is called static binding and is much faster and more reliable.

The static binding access agents' methods through the ISimEventListenerinterface, any agent has to implement. The following code is an example ofhow agents has to be programmed to support static binding:

13 doSomething is supposed to be an agent's method associated with the event.

84

Page 87: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 6

public class MyAgent implements ISimEventListener {…

public static final int EVENT_DO_SOMETHING = 0;public static final int EVENT_DO_SOMETHING_ELSE = 1;

public void doSomething() {…}public void doSomethingElse() {…}

public void performAction(int actionID) {s witch (eventID) {

EVENT_DO_SOMETHING:doSomething();break;

EVENT_DO_SOMETHING_ELSE:doSomethingElse();break;

}}

Through the performAction() method it is possible to execute manyactions, using proper identifiers.

The previous scheduling instruction can now be modified as follows:eventList.scheduleSimple(123, myAgent, MyAgent.DO_SOMETHING)

As shown in this example, both the methods have advantages and limits,and this is why both of them have been implemented in JAS.

The EventList class

The event list is a crucial element of the JAS simulation enginearchitecture. It is a double linked list, whose role is the ordering of theevents submitted and their sequential execution. The event list extends thejava.lang.Thread class, so it works on an independent thread.

The static class jas.engine.Sim ensures that will exist only one event listper instance of the Java Virtual Machine. This way JAS guarantees thatevery running model is synchronized with the same time manager.

85

Page 88: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

JAS: Java Agent-based Simulation library

The RealTimeEventList class

The RealTimeEventList class extends the EventList one, coordinating theevent firing with the time of computer's clock.

The RealTimeEventList is useful to implement the so called emulationmodels. An emulation consist in a simulation experiment with theinteraction of the program with humans and other physical externalequipments. It can be also used to synchronize simulation executed over acomputer network.

MultiRun

Agent based models are often characterized by many parameters andthere is no explicit declaration of the cause-effect relationships betweenparameters and outcomes, so the only way to make general assumptions onthe model is to explore its solution state space, observing the simulationresults with many different initial conditions. It is a numerical sensitivityanalysis, obtained through the correlation of the outcomes with the inputs.

It has been defined an abstract template class (jas.engine.MultiRun) thathelps the user to build a automated parameters exploration. A multi-runclass is an autonomous application with the aim of calibrating theparameters and/or of generating a sensitivity analysis on some criticalvariables.

Obviously, the way parameters are changed from one run to the next istotally under control of the user.

The multi-tun template defines two stages, corresponding to twomethods to be overridden by the user.

First, the startModel() function is called every time a new simulation hasto be executed, so that the user can load the models and properly set theparameters.

When the model ends, the control is returned to the multi run managerand the nextModel method is invoked, so that the user can observe theoutcomes and decide dynamically the parameters for the next run or if theprocess must end.

The AgentList class

86

Page 89: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 6

The agent based models are often populated by groups of agents derivedfrom the same class and managed as a whole. Messages are sent in broadcastto collections of agents, instead of to some particular instances.

Due to the closely sequential architecture of the digital machines, themessages sent to a collection are sent sequentially from the first to the lastobject populating the list. The best choice in managing groups of agents isrepresented by the use of standard Java collections, which are reliable, fastand make the code portable.

The JAS engine package is provided with a particular implementation ofa Java ArrayList object, which extends the message broadcasting mechanismto support parallel execution.

In case a simulation model is executed over a network of computers orwithin a multi-processor machine, it could be useful to send the message toeach agent in a collection at the same time. This would reduce the controlover the sequence of the action but would increase the realism of theinteraction mechanism.

In order to implement such distributed simulation, the AgentList classprovides a mechanism to execute the same action for each agent in the listasynchronously.

A typical instruction to perform this call is:agentList. asyncExecute(eventId)

The agentList object executes one thread per agent and waits until everyagent terminates its own execution.

An interesting use of this feature is the parallel execution of heavy tasks(for instance, evolving a neural network) on different machines, whichmight dramatically reduce the execution time of the simulation.

The ai package

The jas.ai package contains the implementations of some evolutionarytechniques developed in the field of Artificial Intelligence, as parts of thesoft computing techniques. Soft computing differs from conventional (hard)computing in that, unlike hard computing, it is tolerant of imprecision,uncertainty, partial truth, and approximation.

87

Page 90: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

JAS: Java Agent-based Simulation library

As discussed in the first chapter, the ai package should support fourmethods,: the artificial neural networks, the genetic algorithms, theclassifier systems and the avatars.

Actually only the first two libraries have been developed. Unfortunatelyit is difficult to adapt traditional implementation of these well knownevolutionary techinques to the purposes of simulation. This is the reasonwhy their implementation in JAS have been done from scratch.

Neural networks

The neural network package has been based on the core back-propagation learning algorithm implementation by Pietro Terna, originallyintroduced in the bp-ct (back propagation-cross targets) package (Beltrattiet al., 1996).

The use of neural network in a simulation context is a little bit differentfrom traditional ANN learning approach. In fact, the typical use of thesestatistical multi-variate regressors is to recognize patterns within time seriesand estimate its future values.

Typically the learning process is closely controlled by the user, whocollects data, decides which data are to be used for training and which arethe correct values for the input patterns. The use of ANN into simulationmodels is typically connected to evolutive agents which have to be able toautonomously adapt in an ever changing environment.

This means that the training set has to be collected during simulationand the agent must be able to recognize a posteriori which are the correctvalues to be associated to the past input.

So that, the JAS ANN implementation is able to automatically collectdata patterns and store them in XML files.

Genetic algorithms14

The JAS GA package supports two different uses of genetic algorithms insimulation, as suggested in Chattoe (1998). They can be used with two aims:(i) optimizing and evolving individual strategies and (ii) optimizing and

14 The GA package has been developed with the precious contribution of Gianluigi Ferraris([email protected]).

88

Page 91: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 6

evolving a centralized strategy coordinator, with the cooperation of eachagent to the evolution process.

The genetic strings may represent the different strategies used by agentsto take decisions. The evolution of a strategy is operated by reinforcing thegood ones, and discarding the less effective ones.

The individual evolution approach is also known as the mind GA. It usesan independent GA evolver for each agent, such that anyone learns using itsown evolution process. In this case, the learning may require moreevolution cycles than in the centralized approach.

With a cooperative or centralized evolution method each individualagent is considered a single genotype, or part of the full one. A single GAdrives the evolution of the whole agent set. In this way the evolutionbecomes influenced by the evaluation made by all the agents, and each ofthem could indirectly exploit the results obtained by the others.

The difference between the two approaches is relevant. In fact, theindividual one mimics the possibility that a given agent evolves itsbehaviour ans skills over time, according to its experience.

The second approach is Darwinian, since each agent does not evolve itsbehaviour, but the evolution is carried on by the natural selection. Thestrongest or the most suited individuals live, the others die. The geneticrecombination takes the evolution to come out generation after generation.

The random number generators

Since computers are deterministic machines, they cannot act randomly,so some ingenious algorithms have been designed to generate pseudo-random number series. They use some mathematical properties of rationalnumbers to generate digits that seems to be extracted with a randomprocess.

Unfortunately those generation routines are not able to workindefinitely, but sooner or later they make a complete loop (called period)and begin to generate the exact same former sequence. So the choice of areliable algorithm is very crucial in for a simulator tool.

The JAS library contains, in the jas.random package, a set of pseudo

89

Page 92: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

JAS: Java Agent-based Simulation library

random number generators, based on the most common statisticdistributions. The generation engine is taken from the COLT library(Hoschek, 2002) and it is based on the Mersenne Twister generator.

Mersenne Twister (MT) is a pseudo random number generator developedby Matsumoto and Nishimura (1998). It is actually the most suitable andreliable generation algorithm, mostly because

• it has been designed considering the flaws of previous generators;• it is open source;• it has a far longer period and a far higher order of equidistribution

than any other implemented generators (the period is 2^19937-1,and 623-dimensional equidistribution property is assured);

• it is a very fast generation algorithm• and it makes an efficient use of the memory.

Even if the user could choose other random generation libraries, the oneJAS provides has very useful features. The jas.engine.Sim class keeps a staticreference to a unique centralized generator, so that each object in thesimulation can get random samples from the same source. This guaranteesthe reproducibility of the simulation experiments, because setting the sameseed random number in the engine parameters, the simulation outcomeswill be exactly the same.

Coordinating random number generation in Agent-Based Models

Random numbers represent, together with parameters, the input of asimulation model.

As stressed in Contini et al. (2004), the general assumptions on asimulation model depend from a deep exploration of its state space. In orderto compare results obtained changing the initial conditions, the randomnumber sequence must be absolutely the same or, in case some structuralelements change, they have to be coherent with the previous experiments.

The sensitivity analysis of a given variable, realised varying a givenparameter cannot be affected by an ever changing random numbersequence.

The agent-based models are characterized by a continuous changing

90

Page 93: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 6

structure, so that it is very complex to generate set of results with differentparameters and equal random number patterns.

I suggest three approaches in normalizing the random number patternsand they are all supported by JAS:1. a unified random number source, synchronized by a unique seed

number;2. a set of random generators, synchronized by a seed number provided by

the same unique generator;3. a set of random generators, all synchronized with the same seed number.

The jas.engine.Sim class provides a getRnd() method which returns astatic reference to a centralized random generator. In order to implementthe first solution, each random number consumer will use the uniquegenerator.

This approach is very simple and easy to use but it might generatedifferent random patterns, in case two simulation runs are executed withdifferent number of agents or a different behaviour for at least one agent15.

The second approach requires that each agent creates an instance of aparticular distribution generator using a seed number provided by thecentralized generator. This method ensure that different behaviours of theagents over two runs are generated by the same random pattern. Obviouslythe comparability is granted until the number of agents is the same.

The third method requires that each agent creates an instance of aparticular distribution generator using always the same seed number. Itensures that the behaviour of each agent is driven by the same randomnumber sequence independently from the number of agents in the model.This technique has the drawback that agent will probably behave in thesame way.

The choice of the right method depends on the type of interactionsamong agents and on the agents' type of behaviour.

In order to implement the second and the third methods a dedicatedclass has been developed: the jas.random.DistributionFactory, which role isto create random generators with the same centralized random seed as well

15 It may determine a different request of random samples to the generator.

91

Page 94: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

JAS: Java Agent-based Simulation library

as with a specific seed.

The graph package16

The JAS graph package is designed to create societies of agents which areconnected in a network of relationships. The package provides a templateclass (jas.graph.RelationalAgent) and an interface (IRelationalAgent) thateach agent has to implement in order to participate to the relationalnetwork.

The IRelationalAgent assigns the agent a set of connections with otheragents and a weight for each connection. The graphs populated by thoseagents are always weighted directed graphs.

Two types of models can be realised with the current version of thepackage:1. the topological models entail that agents manage their position on the

space and the graph package does only manage the plotting of nodes andarcs;

2. the relational models do not consider the physical localization of agents.They are related to each other independently from space. In this case thegraph package provides a set of so called layout managers, whose role isto locate nodes on a map according to the layout algorithm. The star-circle-layout, for instance, places the most connected node at the centreof a circle populated by the other nodes.Once a graph is realised, a very rich set of Social Network Analysis tools

are automatically available on the net, as described in Boero (2004b).The package has been designed in a way that it is able to load the graph

from a GraphML file and, through a JAS driver, to transform the map into aset of instances of RelationalAgent objects. This facility is useful when theinitial graph structure is a parameter of the model. Thanks to the visualgraph editor JAS is equipped with, the user may generate different networkconfigurations to use in simulation experiments. This without modifyingthe model.

16 The jas.graph package has been designed and implemented by me and Riccardo Boero([email protected])

92

Page 95: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 6

The statistical package

The jas.statistics package has been developed with the contribution ofMatteo Richiardi17, whose interests in the application of statistical methodsin agent based models took to the designing of an advanced infrastructureto collect and analyse data generated by JAS models.

The jas.statistics package is a statistical library specifically designed to beexecuted in a simulation context, since data sets, collected from simulationsare frequently updated and sometimes data structures change at runtime.The code is optimized to reduce memory occupancy and CPU timeconsumption.

The package structure is composed by three sections:• the jas.statistics package contains the main interfaces and classes;• the jas.statistics.reflectors package contains classes that retrieve data from

common java objects;• the jas.statistics.functions package contains the functions that compute

statistics on data sets. The statistics computing algorithms are mainlybased on the cern.jet.stat package.

How JAS retrieves data from objects

In order to compute statistics, a statistical computer must be able todynamically collect data from simulation objects. It represents a problem,since the statistical library classes do not know the structure of the targetobjects (designed by users) and so they cannot access their internal datausing direct calls18.

This approach is based on the dynamic binding paradigm and a staticbinding approach is also provided. In fact, JAS defines a set of I*Source19

interfaces, for direct accessing objects' data. Each object containinginteresting data to be collected should implement one or more of thoseinterfaces, according to the type of data to be provided.

The following example shows how to implement the source interface for

17 [email protected] For instance, using instructions like myObject.getDatum().19 The * is to be considered as jolly character. The interfaces names are defined according to

the data type they have to export: IIntSource, IDoubleSource, etc.

93

Page 96: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

JAS: Java Agent-based Simulation library

an object containing integer values:public class MyAgent implements jas.statistics.IIntSource {

public static final int AGE = 0;public static final int INCOME = 1;

int income, age;

public int getIntValue(int variableID) {switch (variableID) {

case AGE: return age;case INCOME: return income;

}}

}

The statistic data collector can now directly access the data within theMyAgent instances.

The statistics encapsulation system

The I*Source interfaces are used to sequentially encapsulate differentcomputational operations.

Supposing the user has to compute, at every simulation time step, themoving average of the mean value of the agents’ income. This value mightbe useful to verify if the aggregate agents' income reached an equilibrium.

In order to compute the moving average at every time step the followingoperations are necessary:

1.collect data from all the agents contained in a list;2.compute the average value of the collected data; 3.store the value into a time series object; 4.use the series to compute the current moving average.The encapsulation system provides a way to create a stack of operations

and then obtain the value simply invoking one method. The following code shows the code implementing this example:

94

Page 97: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 6

CrossSection.Integer crossSection = new CrossSection.Integer(agentList, “income”, false);

Series.Double series = new Series.Double(new MeanFunction(crossSection));MovingAverageArrayFunction ma =

new MovingAverageArrayFunction(series, 3 /*moving average window*/);

Every time the ma object receives the updateSource() command, theentire stack is automatically updated and the current moving average of thelast three periods becomes available.

A comprehensive schema of the encapsulation system is shown in thefigure 21.

figure 21 The statistics encapsulation system

The statistic computers can return single values, via the I*Sourceinterfaces, and array of values, via the I*ArraySource ones. A data sourcecan be processed by a *Function20 object, which applies the function andreturn a value, via an I*Source interface.

Every time an object implements an I*Source interface it can be insertedin the encapsulation stack as a source of data used by the subsequent

20 The *Function notation makes reference to all the functions inheriting from theAbstractFunction, in the jas.statistics.functions package.

95

Page 98: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

JAS: Java Agent-based Simulation library

consumer in the stack. The encapsulation allows an infinite number ofoperations to be sequentially executed, with a single update operation.

Obviously, each array consumer requires as source a data array, whilesingle value consumers work only with single values sources.

The functions contained by the jas.statistics.functions package aredivided in two main groups:

The *ArrayFunction objects work on I*ArraySource data sources, whilethe *TraceFunction objects work with single value sources (I*Source). Evenif a single value seems to be unuseful to create statistics, these functionstrace the source over time and compute aggregate statistics.

How statistics are updated

If user should update all the elements in the encapsulation system, thearchitecture would be uneffective.

For this reason, JAS automatically updates the statistical widgets, via theIUpdatableSource interface. Each statistical computer which retrieves datafrom an I*Source source, checks if the source implements theIUpdatableSource interface and, if it does, updates it before reading data.

Through this method each object in the stack is recursively updated. Thismakes statistics very easy to be managed.

The database support

The support of a databases to store and manage large set of parametersand to collect data during simulation experiments, may be of greatusefulness in simulation.

In the regard of data input, databases can be easily interrogated using thestandard SQL query language and the Java standard library provides a richset of SQL tools.

On the contrary, the collection of data coming from the simulationexperiments is a little bit complicated and that is the reason why JASprovides a library automating the statistical data collection.

The data collection is particularly useful when the user has to collect

96

Page 99: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 6

huge quantities of data and make data mining on them.The JAS database package is based on the Hypersonic SQL database

(HSQL, 2004).

The output database structure

A JAS database may require the definition of a special table called“RUNS”, which stores the unique identifier for a simulation run, with itstimestamp.

Data tables can be designed using one of the following principles:• A table stores some data taken from one or more objects, and each record

refers to the same simulation time. It is useful to store some particularmacro values computed by statistical computer objects, for eachsimulation step.

• In case the user needs to store a time series of some variables for eachagent in a collection, the table must contain a special field pointing tothe unique agent's identifier. For each time of simulation, the table willcontains one record per sampled agent.

The agent id definition

The management of agents' unique identifiers require somespecifications. In fact, during an execution run the objects can be referredusing their pointers to memory locations. Unfortunately object pointers arenot persistent. This means that trying to execute a model with the sameinitial parameters will not necessarily produce the same object pointers.

When the database is used for only one run, the agent identification onthe database can be done using their pointers, but in order to refer to thesame agent across different simulation runs it is necessary to define apersistent way to identify agents.

JAS automatically stores the hash value of the objects when storing theirdata to database. This technique allows to manage both the situations abovementioned.

In fact, when data are not to be compared across different run, the hashvalue of the object will return the pointer itself. Just in case the user wants

97

Page 100: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

JAS: Java Agent-based Simulation library

to create a persistent reference to agents he or she has to redefine thehashCode() standard method of the object and return a non-volatileidentifier.

The space

The space package provides the user a set of tools to design spatialstructures within their models.

The logic beneath this package is very similar to the one introduced bythe Swarm simulation system. It represents space in a discrete way, as gridswhose cells may contain different types of objects or numbers.

The representation of space is realised with a very simple trick. The two-dimension space is characterized by a given width and length. Each logicalset of elements standing on the space are stored in matrixes whosedimensions are the same of the space. This way the space can be dividedinto logical layers which are overlapped and are drawn according theiroverlapping order.

The figure 22 shows an example of a rectangular space populated by bugsand units of food. They are stored on two different grids perfectlymatching.

When a bug moves it changes its position on the bugs' layer, but if itwants to eat food it has to look in the corresponding position of the foodgrid.

This approach is very flexible and it allows to manage different objectsand data types with a coherent representation. Unfortunately it is not soeasy to be managed in a three-dimensional representation.

figure 22 The multi layer representation of space

Sim2Web

98

Page 101: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 6

Many simulation platform are designed to publish simulation models onthe Internet. These feature is, in most cases, realised with the aim of easilyshow the simulation to the user without asking them to install anything ontheir computers.

It is a very useful feature, but it requires that the simulation platform isvery light, since it has to be executed locally by the users' Internet browser.JAS is a very complex tool, with a lot of built in libraries and so it cannoteffectively used to generate stand-alone web based models.

Another approach to the Internet-based simulation is the creation ofdistributed simulations in which many user can remotely interact.

With this concern in mind, Sergio Margarita and I (Margarita andSonnessa, 2003) developed an architecture to create asynchronous anddistributed simulation, with only one copy of the simulation running on acentralized server, coordinating the interaction of the remote users.

The most common approach to distributed simulation is based on acentral machine coordinating the schedule in a way that remote users areasked to interact with their browser when the central coordinator givesthem the control. This approach can be realised with a point-to-pointconnection based on one of the remote method invocation protocols (RMI,CORBA, SOAP, XML-RPC). The client have to be equipped with a lightinterface directly communicating with the server whose applicationcontains an image of the remote client.

This approach is very powerful, but requires good programming skills,since server and client modules are to be implemented.

The architecture proposed in JAS quite fully eliminate the programmingof the client-server infrastructure. The simulation model can be web-enabled simply publishing text and graphics in a list managed by thejas.net.InformationServer object. A simple web page, placed under the Zopeweb server, will publish those information to remote users, eventuallymanaging the users' privileges and identities and eventually receivingfeedback from them.

The communication is always asynchronous, so the commands sent byremote users are stored in a memory structure and they are processed onlywhen the simulation dedicated component decides to process the command.

99

Page 102: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

JAS: Java Agent-based Simulation library

This way the agent is supposed to follow its own strategy until it findsinto the information server that a reference human actor posted a specificstrategy.

Business process package

Since JAS is based on a flexible discrete event simulation engine, it couldbe used to design business process simulations.

Obviously, designing it from the scratch may require a lot of work, thecommercial tools do not require. The future development of JAS will gotowards the release of a BP package, containing a set of objects typicallyused in the business process modelling: activities, tokens, queue managersand so forth.

With this tool it will be possible to build BP simulations, with a standardlanguage and open source tool, even if it will not have a graphical editor aspowerful as the most famous BP applications.

100

Page 103: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 7

7 Agent-based Genetic Daisyworld

Introduction

In this chapter presents the agent-based modelling technique is appliedto a well known geophysical model showing some interesting effects of theinteractions between biota and the planet they live in.

The model, originally introduced in Watson and Lovelock (1983), isnamed Daisyworld, and is aimed at showing how some plants living on aplanet can usefully alter its global conditions.

Scientific literature is rich of works that analyses the Daisyworld frommany different points of view. In the present work, it is introduced a two-dimensional version with the aim of showing the effects of the topologicalinteractions between the plants and the planet and their capability to adaptto the environment through the genetic recombination.

Therefore, a comparison of the ABM version with the classical model isproposed. The behaviour of the system is analysed both when theenvironment conditions are stable and when some catastrophic eventshappen.

Moreover, it is presented a comparison between a static and evolving(genetic) version of the model.

The Daisyworld

As one of the authors stresses in Lenton and Lovelock (2001),the Daisyworld model was invented to demonstrate that global regulationcan emerge automatically from physically realistic feedback between lifeand its environment, in answer to the criticism that it demands foresightor planning on the part of unconscious organisms.

Daisyworld is a hypothetical world orbiting a sun, whose temperature is

101

Page 104: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Agent-based Genetic Daisyworld

continuously increasing and decreasing. The simulated planet is seededwith two different species of daisy: black and white daisies. White daisieshave white flowers which reflect light very well and grows best in warmtemperatures, and the other species has black flowers that absorbs light andgrows best in cool temperatures.

When the simulation is run without the daisies, the planet's temperatureproceeds in locksteps with that of the sun, but on the planet surface somewhite and black daisies can grow. The white daisies tend to reflect thesunbeams and their effect is the reduction of the planet temperature. Onthe contrary the black daisies absorb the sunbeams and increase the planet'soverall temperature. In this way the daisies are modifying the climate tomake conditions more hospitable for themselves.

figure 23 The most important result of the original Daisyworldmodel

The original model takes into account the modifications occurring whenthe sun irradiation increases over time. The result, obtained with a systemdynamics version21 of the original model, is shown in figure 23.

At the beginning of the simulation, Daisyworld is so cold that only a fewblack daisies, and almost no white daises, can survive. Whenever theaverage temperature decreases, the black flowers tend to predominate andthey cause the planet's temperature to rise, allowing their greater

21 The model has been written with VenSim. For brevity it is not presented here, but it can bedownloaded at http://jaslibrary.sourceforge.net/models/GeneticDaisy.html.

102

Avg T planet100

72.5

45

17.5

-100 25 50 75 100 125 150 175 200 225 250

Time (Month)

Avg T planet : Current

Page 105: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 7

proliferation, more absorption of heat, and so on. As the planet becomeshotter white daisies begin to breed as well, and eventually the planetreaches a point of temperature equilibrium. Such a system is stable againstclimatic variations and the entire planet maintains homoeostasis22. Thebalancing is carried out by the contrast between two feedback loops, asshown in figure 24.

Although the solar irradiation is able to warm the bare planet by 60oC,the presence of the daisies maintains the plant's surface within a 11oC rangearound the optimum temperature for daisy growth.

When the external temperature becomes too hot for the daisies, theplanet becomes unsuitable for life.

figure 24 The cause-effect diagram of the homeostatic effect in Daisyworld

The model

The key aspect of Daisyworld is that the two types of daisies havedifferent colours and thus different albedo. This way, the daisies can alterthe temperature of the surface they are growing on.

The temperature Te on the planet follows the sun irradiation, which isdetermined by equating emitted and absorbed radiation:

T e2734=S L 1−Ap , (1)

where σ is the Stefan-Boltzman constant (5.67e-8 Wm-2 K-4), S is aconstant energy flux (952,56 K4)23, and L is the luminosity of the sun. Theoriginal version of the model considers a constant growth of the L factor,

22 Homoeostasis is the property of an open system to regulate its internal environment so as tomaintain a stable condition, by means of multiple dynamic equilibrium adjustmentscontrolled by interrelated regulation mechanisms.

23 The constant energy flux is such that S/σ must be equal to 1,68e10..

103

Black daisiesgrowth

Planet temperature+

+White daisies

growth--

Page 106: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Agent-based Genetic Daisyworld

which increases from 0.5 to 1.7. The Ap parameter is the average albedo ofthe planet, which is supposed to be equal to 0.5, when its surface is bare.

Each daisy has a local temperature which is determined by the followingequation (Watson and Lovelock, 1983):

T i2734=q A p−AiT e2734 , (2)

which guarantees an energetic balance over time.The growth of the daisies is determined by the local temperature they

perceive and follows a non-linear relation, with the highest growth ratecorresponding to the temperature of 22.5oC and a decreasing rate in therange 5-40oC, according the following parabolic function:

i=max0,1− t i−T i

g i 2=max0,1− 22.5−T i

17.5 2 , (3)

where ti is the ideal temperature and gi is the growth factor. Even if the scientific literature investigated many aspects of the

Daisyworld model, like the effect coming from the introduction ofherbivores or how the planet reacts to catastrophic events, to the best of myknowledge, it has not been studied so far when the sun irradiationperiodically oscillates, just as happens on the Earth with the alternation ofseasons.

The presented version investigates the equilibrium of daisy populationsover cyclic temperature conditions and how daisies are able to adapt tosudden modifications in planet's temperature.

The agent based model

The original Daisyworld is a one-dimensional and aggregate model,which describe the planet's dynamics in terms of stocks and flows.

Von Bloch et al. (1999) proposed a two-dimensional version based on

104

Page 107: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 7

cellular automata, investigating some topological properties like themutation of some individuals, the formation of clusters and the percolationphenomena.

The version I propose here24 is two-dimensional, too. It is based on theABM technique, mostly because it is aimed at showing the effects of thegenetic recombination of daisies' DNA.

In order to give a local-oriented approach to the daisy's behaviour, Iintroduced a localized version of the thermodynamic balance. The (2) issupposed to be valid only locally, such that the average planet's temperatureTe and albedo Ap are computed only on the surrounding surface for eachgiven daisy. Even if the overall energetic balance is not guaranteed,temporal unsteadiness is possible.

The sun irradiation L oscillates according the following sinusoidalfunction:

Lt = sin tp

2 (4)

where γ is a multiplier coefficient, usually set to 1, and p is the length(measured in days) of a full cycle. With the γ coefficient equal to 1, thesolar luminosity oscillates between 0.5 and 1.5.

The agent based model is based on the following classes, as also shown inthe UML class diagram of figure 25: • the GeneticDaisyModel is the model coordinator, which is able to

manage the genetic algorithm evolution, the catastrophic events (herecalled glaciation and serra), and the periodic spontaneous germination;

• the Daisyworld class manages the planet surface, which is represented bya grid of double values. Each cell contains the local temperaturedepending on the type of daisy it is covered by. It computes the localtemperature for a given daisy and insulates the world at every time step;

24 An up-to-date version of the model can be found athttp://jaslibrary.sourceforge.net/models/GeneticDaisy.html

105

Page 108: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Agent-based Genetic Daisyworld

• the Daisy instances represent the single daisies on the planet. They areable to reproduce, by creating clones around them. The reproductionrate is governed by the (3) but it is deeply dependent on the localconditions, both for the detected temperature and for the space availablefor reproduction.Daisies can reproduce in two ways. The vegetative reproduction is a sort

of plants' capability to clone themselves, without changing their geneticcode. At the same time, through the insects' pollination the plants canreproduce from seed after a genetic recombination.

The model the daisies tend to grow around the parents, but sometimesthe seeds are spread randomly through the space, as effect of wind andinsects' pollination. The reproduction mechanism deeply depend from thelocal crowding: if the space surrounding a daisy is full, it cannot reproduceindependently from its potential.

The genetic version is a metaphor of the daisies' reproduction, it providesthe daisies to clone themselves and put their clones around them, but at thesame time, genetic children are seeded all over the planet's surface byinsects.

A more detailed description of the model behaviour is represented in thetime-sequence diagram of figure 26.

At every time step a group of actions is performed. The surfacetemperature is updated according the current sun irradiation level and thecurrent local albedo. Then each daisy is asked to reproduce and if the localtemperature conditions are right and there is available space around it, thevegetative cloning process takes place.

After the reproduction each daisy checks if it can still live, otherwise itdies.

106

Page 109: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 7

figure 25 The class diagram

Every one daisy lifetime period, the model randomly spread through thespace some daisy seeds. If the genetic algorithm is active, a new evolvedgeneration is spread, while if the model is executed in standard mode a newrandom generation of black and white daisies come up.

107

Page 110: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Agent-based Genetic Daisyworld

figure 26 The time-sequence diagram of the GeneticDaisyWorld

108

Time

: DaisyWorld population : Daisy

child : Daisy

spontaneous : Daisy

: GeneticDaisyModel

@0..1 [mainCycle]:insulate(): void

[mainCycle]:

reproduce()

[mainCycle]:

checkLife()

@daisyLifeTime..daisyLifeTime:

spontaneousGermination()

getLocalTemperature()

getMooreNeighborsPositions

placeMeAt(int,int,Daisy)

placeMeRandom(Daisy)

0..8

if (is day to die)die()

if (genetic)update fitness

daisyPopulation

Page 111: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 7

The genetic algorithm

The genetic algorithm is able to generate strings of 24 bits, which areused to map three characteristics of the daisy, as described in the followingtable:

Growth factor: bit 0..7 Ideal temp.: bit 8..15 Albedo: bit 16..23

gi = (k0..7 * 5) / 255 + 15 it = (k8..15 * 15) / 255 + 15 ai = (k16..23 * 0.8) / 255 + 0,1

Range: 15 - 20 Range: 15 – 30 Range: 0,1 – 0,9

table 2 The genetic string mapping

This mapping suggests the possibility for daisy to evolve changing theirreflection property (the albedo) as well as their ideal growing conditions.This should allow to generate stronger and more suited individuals.

The genetic recombination operates giving the strongest daisies moreprobability to have children. In order to determine the strongest or mostadapt daisy, the genetic algorithm needs to have each genoma assigned afitness measure. In this model, the fitness is represented by the absoultenumber of seeds that a given genoma generated during its life.

The more the daisy is within the ideal temperature range, the more itseeds and the more it seeds the more it is able to transmit its genetic set tothe children.

The results of the non-genetic model

The figure 27 shows the behaviour of the basic version of the model. Itcan be observed how after the time step 600, the model behaves similarly tothe original one. But, when the temperature conditions become suitable forthe growth of the white daisies, they cannot grow because the planetsurface is hold by the black ones. The situation is well visible in figure 28.The white daisies' growth is delayed, also because their perceivedtemperature depends of the local temperature conditions, rather than onthe global ones.

109

Page 112: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Agent-based Genetic Daisyworld

figure 27 The planet's temperature in the basic model

Another interesting result comes out: the daisies are able to create anhomoeostatic effect, only for high temperatures. When the world becomescold they all die. This phenomenon can also be observed in the originalmodel.

figure 28 The planet's surface

The figure 29 shows how the same model behaves in presence of somecatastrophic effects like glaciations or greenhouse. The daisy population istoo few diversified, and it is not able to absorb sudden temperaturevariations. In fact, they are developed only to live in a well definedtemperature range.

110

Page 113: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 7

figure 29 The planet temperature dynamics with catastrophicevents

Outside daisies' ideal temperature range the planet becomes a deadplanet and its temperature is only determined by its own albedo.

The results of the genetic model

The genetic model shows some interesting properties. The first result isthat comparing the results in figure 30 with the previous ones of figure 27,the genetic recombination very quickly creates a population which wellstabilize the planet's temperature. But a more surprising behaviour comesout, since no genetic species have a significantly greater benefit over theothers, and genetic algorithms creates ever changing set of individuals typeswhich often co-evolve and sometimes not.

Executing the model with different random seeds, ever changingpatterns come out, even if the capability to stabilize the planet'stemperature is always present. In fact, different generations of daisies tendto take over only for short periods.

This phenomenon can also be explained with the very close dependenceof one species with the topological conditions and with the contemporarypresence of other species.

111

Page 114: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Agent-based Genetic Daisyworld

figure 30 The planet's temperature in the genetic model

figure 31 The planet's temperature in a long run (genetic version)

The figure 31 shows the temperature dynamics over a long period. Thegenetic population does not evolve a superior species that dominates. Morefrequently cyclic populations of different albedo come out. The figure 32shows an example of how, after 104 steps, the population is composed ofsimilar species but they co-exist and season after season they alternate.

112

Page 115: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 7

figure 32 The surface status after 10000 steps.

Taking into account the behaviour of the system in correspondence ofcatastrophic events, the results show plausible outcomes. Since no particularspecies takes over, the genetic population is very capable of adapting.

figure 33 The planet temperature dynamics with catastrophic events inthe genetic version

According to the adaptability provided by the Darwinian GArecombination process, the genetic version allows the life forms to modifytheir population diversity and to evolve in more suitable species for themutated conditions.

During the greenhouse effect the life comes out, on the contrary to the

113

Page 116: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Agent-based Genetic Daisyworld

previous version.The results confirm some of the assumptions presented in Von Bloch et

al. (1999), where the cellular automaton based model capable of mutatingthe daisies' albedo shown a better response to the sun's oscillations.

114

Page 117: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 8

8 An auction approach to the WLANsformation

Introduction

This chapter presents an agent-based simulation model developed withthe aim of showing how this technique allows the implementation of thedistributed artificial intelligence (DAI) paradigm for the optimization andcoordination problems.

The wireless technologies opened the telecommunications to newpossibilities of application as well as new challenges. In particular, thedesigning and the management of local area networks (LAN) based onmoving devices cannot be faced with more traditional centralizedoptimization algorithms.

I propose a simulation model which is used to test and compare thebehaviour of two coordination algorithms in the wireless LAN (WLAN)formation.

On-the-fly formation of local area networks

The wireless technologies coupled with the increasing power of mobiledigital devices is opening the traditional networking to a new looselycoupled, agile and distributed way of exchanging information.

Imaging that a group of people participating to a conference needs toexchange data and no traditional network facilities are available. The newwireless devices are good candidate to solve the problem, but the formationof a network requires to known its topology, in order to design the routingtables and coordinate the data exchange.

Since the devices have limited visibility, battery and computationalpower, it is impossible that one device acts as a server with the aim of

115

Page 118: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

An auction approach to the WLANs formation

coordinating the network. In traditional wired networks, the system administrator has got all the

information about the network topology and he/she can design anoptimized architecture, placing router devices in strategic positions, suchthat every client within the area may access the net. In a slapdash networkthe optimization must come from the local collaboration of autonomousdevices.

The simulation model here presented is a virtual laboratory fordeveloping and testing of the algorithms which are used in the formation ofthe wireless connections, with respect of important characteristics likenetwork stability and redundancy.

It is based on a simplified version of the Bluetooth communicationprotocol (Bluetooth SIG, 2002). According to the Bluetooth technicalspecifications, each device can communicate with the other devices withina circular range of 10 meters25. Two devices are directly connectedaccording the peer-to-peer model, but thanks to the frequency hoppingtechnique one device can also become a member of a so called piconetformed by no more than 8 units. Each of them may play one of the threefollowing roles within a piconet.• A master is a devices directly connected to all the other devices in the

piconet. Each master identifies one and only one piconet and it has toroute all communication packets from a source device to the destinationone within the piconet.

• A slave device participates to only one piconet at a time and it is directlyconnected with its master device. Each output packet is sent to themaster and each input packet comes from it.

• A bridge device is a slave which is connected, at the same time, to twopiconets. Even if it is a member of one piconet it is also able to routesome packets to another one. The role of the bridge is crucial, since itrepresents the joining point of two piconet. Through the bridging morethan one piconet can form a so called scatternet, which assumes thetypical characteristics of a local area network (LAN).The overall connectivity of a scatternet is granted by the presence of

25 Up to 100 meters, in Bluetooth 1.0b.

116

Page 119: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 8

enough paths to connect each node with anyone else. An example is shownin figure 34.

figure 34 An example of scatternet (Ajmone et al. 2002)

As shown in Miklos et al. (2000) the configuration of a scatternet hasgreat effects on the performance of the network.

The optimal solution

In Ajmone et al. (2002) it is presented a centralized approach to theoptimal configuration of a wireless network. The result of this methodologyis the designing of the best network structure for each given topologicallydefined set of devices.

The optimal configuration is the one that simultaneously maximize theconnectivity, minimize the battery consumption and distribute as much aspossible the work load on the network.

The solution represents the optimal scenario for a given set of devices,but it does not consider the dynamics of the network over time. When anode enters or suddenly exits the network, the new optimal configurationmay be, and often is, very different from the previous one. This means thatthe concept of optimum for a distributed ever changing network is different

117

Page 120: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

An auction approach to the WLANs formation

from the one traditionally used in wired LANs.The optimal configuration depends from the dynamic formation of the

network, or in other words, from its history. So, in order to configure it in away that it can ensure the best dynamic solution it is necessary toinvestigate the algorithms each device has to use to self-configure when itenters the network or when it is no more able to communicate.

In Aggarwal et al. (2000) and Salonidis et al. (2001) two scatternetformation algorithms are presented. Both of them are based on the electionof one device to the role of super-master. This approach is clearly orientedto form a centralized structure in a way to apply the well-known optimalsolutions.

Unfortunately this approach tends to design weak configurations, sincethe sudden death of the master would cause the complete failure of the net.Moreover the super-master device would have an unbearable computationalload and battery power consumption.

A more suitable approach is proposed in Law and Siu (2001). They use arecursive algorithm, which ascribes roles to devices with a givenprobability. Networks tend to be formed autonomously and when twogroups are joined by a device, they try to merge in a larger group.

This algorithm is more robust than the previous ones, even if it is basedon very close assumptions. In fact, the algorithm can be applied only if allthe devices participating to the network are in the communication range ofeach other. This means that, potentially, any pair of devices can beconnected directly.

Not only but the solution they propose is designed to reach two targets: asmall number of piconets and a small number of connections for eachbridge node (a measure they call degree of the piconet).

For sure a small number of piconets optimize the battery consumption,since the number of master nodes is small, but at the same time the networkis less flexible and the bandwidth tends to become saturated.

This result is probably due to the fact that all the discussed approachesdisregard the problem of the packet traffic. In fact, they tend to find aconnectivity solution which does not consider the traffic demand.

The solution here proposed, is aimed at modelling the network

118

Page 121: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 8

dynamically. Concerning the current traffic condition, it tries to ensure theconnectivity only to the speaking devices. In other words, the algorithmproposed does not try to connect all the nodes but tends to createconnections only when they are necessary.

The agent based simulation model

Since a wireless network created on-the-fly does not contains a centralcoordinator which collects all the information about the elements in thenet, the optimal solution can be only used as a benchmark for the sub-optimal solutions obtained applying a self-organising algorithm.

Agent based models are very suitable to face this problems because theyare able to take decisions with few information and without knowinginformation and strategies of the others. These decisions require fewcomputational capabilities and are taken within a reasonable time. The needof few information implies a reduced need of information exchange, with agreat benefit in the speediness of decision process.

It is reasonable to imagine that these solutions will be sub-optimal, sincethe connection choice made by each agent in the network is based on alimited set of information and with a local validity.

An agent-based simulation model can be a low-cost and effectiveexperimental laboratory to develop and test rule sets, strategies andalgorithms that ensure good configurations in a so complex system.

The figure 35 shows the class diagram of the agent based model26. Themodel (BlueNetModel class) coordinates the virtual environment defining adevice map (DeviceMap class) that keeps track of devices' positions andstatus. The Device class represents each Bluetooth-enabled device trying toconnect to the scatternet. Each of them perform two main operations ateach time communication unit. In the so called protocol activity phase allthe protocol level information are exchanged. They are used by devices tocheck if others devices are alive and to exchange protocol-level data.

In the communication phase they route some data packets throughout

26 An up-to-date version of the model can be found athttp://jaslibrary.sourceforge.net/models/BlueNet.html

119

Page 122: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

An auction approach to the WLANs formation

the net, trying to reach the target device.

figure 35 The model class diagram

The FileTransfer object represents the need of a device to exchange datawith another one. It is used to store the current route the packets follow toreach the destination. Each file has a given dimension and it remains activesince all the packets composing it are successfully sent. In case theconnection fails for a long time, the file is dropped. This can be due to thescarce presence of devices that cannot physically connect, or to the currenttopology of the network that should completely reconfigured in order to letthe communication to be carried on.

120

Page 123: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 8

The figure 36 is the time-sequence diagram representing the dynamic ofthe simulation model. At every time step a sequence of operations areinvoked for each device in the play field. Each device performs the protocolactivity and, according to its current state, begins an auction or searches fora bridge and, then, communicates its price to all the devices that previouslyrequired it.

figure 36 The overall time-sequence diagram

After the protocol activity, the checkConnections() method is invoked.Each device verifies that its current connections are active. In particular, ifimportant connections are lost, the device begins a new inquiry (auction).

Then the communicate() method is executed. If the device is assigned a

121

Time

: BlueNetModel

: FileTransfer

: Device

new : Device

: DeviceMap

@0..1 [main]:

protocolActivity()

[main]:

checkConnections()

[main]:communicate()

@0..5 upto 200:newNode()

@1..6 upto 201

newFile()

placeDeviceRandomly()

setFileTransfer()

if (BROKEN)auction()

getReachableDevicesFrom()

if (MASTER && not enough bridges)searchForBridge()

receiveAnOffer()

routeForward()

Page 124: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

An auction approach to the WLANs formation

file (FileTranfer instance) to transfer, it sends the packet to its gateway,invoking the routeForward() method. Each device receiving the arouteForward call forward the call recursively, if they are not directlyattached to the target node. This recursive procedure explores the net tofind the destination node.

For the first given number of steps new nodes and new files areperiodically generated. Then the generation procedure stops in order to letthe user to observe the network evolution. During the generation phasesome nodes are also killed, in order to show the algorithm capability toreconfigure lost connections.

The figure 37 shows the state diagram representing how each devicechanges its state.

Typically when a device is not a master and is not connected to a masterbegins an auction with the neighbours devices, in order to decide whichrole it has to play to join the scatternet.

figure 37 The device's state diagram

It is interesting to observe how, when a device is not able tocommunicate for a given period of time, it tries to reconfigure, by executinga new inquiry (auction). When a slave or a bridge lose their connection

122

BROKEN

INQUIRY

SLAVE

MASTER

BRIDGE

auctionbecomeSlave[best offer]

becomeMaster[no good offers]

becomeBridge[master requires]

[file not deliverable]

auction

[file not deliverable]

[file not deliverable]

[lost master]

[lost master]

Page 125: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 8

with the master they go into the initial state (BROKEN) and restart theconnection procedure.

The connection algorithm

The role each device has to play in order to connect itself to thescatternet is determined mainly through an auction.

During the inquiry, the unconnected device asks to all the reachableneighbours to communicate their connection price R. The device waits forten seconds collecting the answers from the other devices. At the end of theauction time, the device searches for the minimum offer posted by themaster units and if it is less than the critical threshold (Rt = 100), it connectsas a slave to the select master.

All the prices it receives are stored in a cache memory and used, ifnecessary, to check if a given node, currently not in the reachable path canbe acquired in the net by making it a bridge.

In case no answers were received or the prices were all over the Rt value,the device becomes a master of a new piconet.

The price R is computed according the following function:

R= e si

S R1

e∑ t j

T S R2

,

where the R1 is the component concerning the current number of nodesconnected to the network and R2 represents the component relative to thecurrent level of traffic load for the piconet.

In particular si is the number of used slot for the master i, S is themaximum number of free slots for each device (actually equal to 7), tj is thebandwidth required by the slave j and T is the maximum availablebandwidth per node. The α and β represent the weight of each component.

123

Page 126: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

An auction approach to the WLANs formation

The results

The experiments have been executed testing two configurations. Thefirst does not use the R function, but each device always answers the sameprice (lower than the Rt value). In this case the slave choose the candidatemaster randomly, since they all offer the same price.

The second configuration makes use of the R function with the followingvalues: α is equal to 20 and β is equal to 40.

figure 38 The final configuration in the case of equal prices

The figure 38 shows the result of the experiment executed with in thefirst configuration, while the figure 39 presents the ones obtained from thesecond configuration.

In order to estimate the performance of the algorithm two parametershave been considered. The number of average nodes that each packets hasto cross to reach the target device and the overall time necessary to reach astable network topology. The first element deeply affects the batteryconsumption, while the second represent the level of satisfaction perceived

124

Page 127: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 8

by the network users.

figure 39 The final configuration in the case of dynamic prices

Taking into account the two graphs, it is clear how the use of a dynamicprice results in a better final configuration of the network. Particularly onthe left side of the graph, the second solution created a more rationalconfiguration.

This results is also observable analysing the dynamic of the average hopsnecessary to deliver network traffic. The figure 40 and figure 41 well showthe difference. In particular the second solution never required a meannumber of hops greater than 12, while the first reached the average value of26 hops.

Concerning the overall time required to reach a stable topology, the twoconfigurations took the same time.

125

Page 128: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

An auction approach to the WLANs formation

figure 40 The time series of the average hops used to send datapackets in the first experiment

figure 41 The time series of the average hops used to send data packets inthe first experiment

As proof of how this approach is traffic oriented, the figure 42 showshow in an other experiment, although the network could be completelyconnected, no devices of the first scatternet were interested tocommunicate with one of the other sub-net.

126

Page 129: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Chapter 8

figure 42 An example of clustered configuration

The algorithm did not connect the two scatternets because it was notnecessary, saving time and battery power. If in the future a device wouldask for a connection with a device of the other net, some connectionfailures would come out, forcing some devices to go into the inquiry stateand, if it is possible, the communication will go up.

Conclusions

The algorithm is not intended to provide the best solution for theBluetooth connection strategy, since many particular aspects have not beenconsidered. For a deeper analysis on the detailed problems on this protocolconnections see Felegyhazi and Miklos (2001).

Nevertheless it shows some interesting solutions the DAI systems canimplement with reduced and locally limited set of information.

127

Page 130: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

References

Aggarwal A., Kapoor M., Ramachandran L., Sarkar A. (2000).Clustering algorithms for wireless ad hoc networks. Proceedings of the 4th

Iternational Workshop on Discrete Algorithms and Methods for MobileComputing and Communications. Boston, MA. pp. 54-63.

Ajmone M., Chiasserini C. F., Nucci A., Carello G., De Giovanni L.(2002). Optimizing the Topology of Bluetooth Wireless Personal AreaNetworks. Proceedings Infocom.

Armstrong E. (1998). Hotspot, a new breed of virtual machine.JavaWorld March 98.

Atkinson K. (1985). Elementary Numerical Analysis. John Wiley. NewYork.

Axelrod R. (1997a). Advancing in Art of Simulation in the SocialSciences, in Simulating Social Phenomena edited by Rosaria Conte, RainerHegselmann and Pietro Terna pp. 21-40. Springer [also in Complexity 3:16-22]. New version for a special issue on agent based modelling in theJapanese Journal for Management Information Systems. University ofMichigan, August 2003.

Axelrod R. (1997b). The Complexity of Cooperation. Agent-BasedModels of Competition and Collaboration. Princeton University Press.

AUML (2003). [http://www.auml.org]

Banks J., Carson J.S., Nelson B.L., Nicol D.M. (1999). Discrete-EventSystem Simulation. Upper Sadle River, New Jersey. Prentice Hall, Inc.

Bauer B. (2002). UML Class Diagrams Revisited in the Context of

128

Page 131: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Agent-Based Systems. Lecture Notes in Computer Science. No. 2222, pp.101-118.

Beltratti A., Margarita S., Terna P. (1996). Neural Networks forEconomic and Financial Modelling. ITCP, London.

Bertuglia C. S. And Vaio F. (2003). Non linearità, caos, complessità. Ledinamiche dei sistemi naturali e sociali. Torino. Bollati Boringhieri. Italy

Bluetooth SIG (2002). Bluetooth Core Specification.[http://www.bluetooth.com]

Boero R. (2004). Inferire comportamenti economici da datisperimentali: un nuovo approccio alla microfondazione dei modelli basatisu agenti. Ph.D. Thesis in Political Economics. University of Pavia. Italy.

Boero R. (2004b). Network Statistics in JAS. [http://jaslibrary.sourceforge.net/files/GraphStatistics.pdf]

Brustoloni J. C. (1991). Autonomous Agents: Characterization andRequirements. Carnegie Mellon Techinal Report CMU-CS-91-204.Pittsburg: Carnegie Mellon University.

Buchanan M. (2002). Nexus: Small Worlds and the GroundbreakingScience of Networks. W. W. Norton & Company.

Chattoe E. (1998). Just how (Un)realistic are Evolutionary Algorithmsas Representation of Social Processes. Journal of Artificial and SocialSimulations Vol. 1, no. 3.

Chu D., Strand R., Fjelland R. (2003). Theories of Complexity.Complexity. Vol. 8, No. 3, pp.19-30.

Contini B., Leombruni R., Richiardi M. (2004). The Wild@Ace Project.Advances in Complex Systems. Vol. 7, No. 2.

Day R. H. (1994). Complex Economic Dynamics, Volume I: AnIntroduction to Dynamical Systems and Market Mechanisms. Cambridge,

129

Page 132: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

MA. MIT Press.

Dooley, K. (1997). A Complex Adaptive Systems Model ofOrganization Change. Nonlinear Dynamics, Psychology, & Life Science.Vol. 1, no. 1, pp. 69-97.

Epstein J. (1999). Agent-Based Computational Models and GenerativeSocial Science. Complexity. Vol. 4, No. 5.

Felegyhazi M. and Miklos G. (2001). Development and Evaluation of aDynamic Bluetooth Network Formation Procedure. InternationalConference and Workshop: Telecommunication and Mobile Computing,2001. Graz University of Technology.

FIPA (1996). [http://www.fipa.org]

Forrester J. (1961). Industrial Dynamics. Cambridge, MA. MIT Press.

Franklin S. and Graesser A. (1996). Is it an Agent, or just a Program?: ATaxonomy for Autonomous Agents. Third International Workshop onAgent Theories, Architectures, and Languages. Springer-Verlag.

Gilbert N. And Terna P. (2000). How to build and use agent-basedmodels in social science. Mind & Society, No. 1, pp. 57-72.

Odell J. J., Parunak H. V. D., Bauer B. (2001). Representing AgentInteraction Protocols in UML. Appeared in Agent-Oriented SoftwareEngineering, Ciancarini P. And Wooldridge M. Berlin. Springer-Verlag.pp. 121-140

Odell J. J., Nodine M., Levy R. (2004). A Metamodel for Agents, Roles,and Groups. Proceedings of AOSE04.

Oses N., Pidd M., Brookes R. J. (2003). Critical Issues in Developmentof Component-Based Discrete Simulation. Lancaster UniversityManagement School Working Paper 2003/062.

Page-Jones M. (2000). Fundamentals of Object-Oriented Design in

130

Page 133: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

UML. Addison-Wesley Longman.

Holland J. H. (1995). Hidden Order. Addison-Wesley. Reading, MA.

Holland J. H. (1998). Emergence. From Chaos to Order. Perseus Books,Cambridge, Massachusetts.

Hoschek W. (2002). The Colt Distribution. [http://hoschek.home.cern.ch/hoschek/colt/]

HSQL (2004). The Hypersonic SQL database. [http://hsqldb.sourceforge.net]

Huget M. P. (2003). Agent UML Class Diagrams Revisited. LectureNotes in Artificial Intelligence. No. 2592, pp. 49-60

Krogh G. and Hippel E. (2003). Special issue on open source softwaredevelopment. Research Policy. No. 32, pp. 1149-1157.

Law C. and Siu K.-Y. (2001). A Bluetooth scatternet formationalgorithm. Proceedings of the IEEE Symposium on Ad Hoc WirelessNetworks 2001, San Antonio, TX.

Lenton T. M. and Lovelock J. E. (2001). Daisyworld revisited:quantifying biological effects on planetary self-regulation. Tellus 53B,288-305

Lewin R. (1992). Complexity: Life at the Edge of Chaos. New York.MacMillan.

Lewis F. L. (1992). Applied Optimal Control and Estimation. Prentice-Hall.

Lindholm T. and Yellin F. (1999). The Java Virtual MachineSpecification (Second Edition). Addison-Wesley.

Lindsay A., Downs D., Lunn K. (2003). Business processes – attempts tofind a definition. Information and Software Technology (45) 1015-1019.

131

Page 134: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Lorenz E. N. (1963). Deterministic Nonperiodic Flow. J. Atmos. Sci. 20,130-141.

Matsumoto M. and Nishimura T. (1998). Mersenne Twister: A 623-dimensionally equidistributed uniform pseudorandom number generator.ACM Trans. on Modeling and Computer Simulation. Vol. 8, no. 1, Januarypp. 3-30.

Margarita S. and Sonnessa M. (2003). Sim2Web: an Open Sourcesystem for web-enabling economic and financial simulations. Journal ofArtificial Societies and Social Simulation. Vol. 6, no. 4.

Miklos G., Racz A., Turanyi Z., Valko A., Johansson P. (2000).Performance aspects of Bluetooth scatternet formation. Proceedings of theFirst Annual Workshop on Mobile Ad Hoc Networking and Computing.Vol. 2, pp. 1315-1319.

Minar N., Burkhart R., Langton C., Askenazi M. (1996). The SwarmSimulation System: A Toolkit for Building Multi-agent Simulations. SantaFe Institute Working Paper 96-06-042.

Minsky, M. (1985). The Society of Mind. New York: Touchstone,Simon & Schuster.

Nilsson J. N. (1998). Artificial Intelligence: a New Synthesis. MorganKaufman Publishers, Inc.

OMG (2001). OMG Unified Modeling Language Specification.[http://www.omg.org]

Petri C.A. (1962). Kommunikation mit Automaten. Ph.D. Thesis.Institut für Intrumentelle Matematik. Bonn.

Press W.H., Flannery B.P., Teukolsky S.A., Vetterling W.T. (1986).Numerical Recipes. Cambridge. Cambridge University Press.

Rogers, H. (1967). Theory of Recursive Functions and EffectiveComputability. New York. McGraw-Hill.

132

Page 135: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

Richiardi M. (2004). Interacting Agents. Ph.D. Thesis in Economics.University of Eastern Piedmont.

Russel, S and Norvig, P (1995). Artificial Intelligence: A ModernApproach. Upper Saddle River, NJ: Prentice-Hall, Inc.

Salonidis T., Bhagwat P., Tassiulas L., LaMaire R. (2001). Distributedtopology construction of Bluetooth personal area networks. Proceedingsof the Twentieth Annual Joint Conference of the IEEE Computer andCommunications Societies.

Sterman J. D. (2000). Business Dynamics. System Thinking andModeling for a Complex World. McGraw-Hill Higher Education

Terna P. (2000). SUM: a Surprising (Un)realistic Market: Building aSimple Stock Market Structure with Swarm. Presented at CEF 2000,Barcelona, June 5-8.

Vangheluwe H. (2001). Multi-Formalism Modelling and Simulation.PhD Thesis of Faculteit Wetenshappen, Universiteit Gent.

Von Bloch W., Block A., Parade M., Schellnhuber H. J. (1999). TutorialModelling of geosphere-biosphere interactions: the effect of percolation-type habitat fragmentation. Physica A. No. 266, pp. 186-196.

Waldrop, M.M. (1992). Complexity: The Emerging Science at the Edgeof Chaos. New York. Simon and Schuster.

Watson, A. J. and Lovelock J. E. (1983). Biological homeostasis of theglobal environment: the parable of Daisyworld. Tellus 35B, 286-289

Watts D. (1999). Small Worlds. Princeton University Press

Zeigler B.P., Praehofer H., Kim T.G. (2000). Theory of Modeling andSimulation, 2nd Edition. Academic Press.

Zhang T., Dewey A., Fair R. (2000). A hierarchical approach tostochastic discrete and continuous performance simulation using

133

Page 136: Modelling and simulation of complex systems...identified in systems, up to the definition of a well identified class of systems: the complex adaptive systems. The study of complexity

composable software components. Microelectronics Journal 31 p. 95-104.

Zhao L. and Elbaum S. (2003). Quality assurance under the open sourcedevelopment model. The Journal of System and Software. No. 66, pp. 65-75

134