© Copyright JASSS

  JASSS logo

Economic Simulations in Swarm: Agent-Based Modelling and Object Oriented Programming

Edited by Francesco Luna and Benedikt Stefansson
Dordrecht: Kluwer Academic Publishers
Cloth: ISBN 0-792-38665-5

Order this book

Reviewed by
Paul E. Johnson
Department of Political Science, University of Kansas, Lawrence, KA 66045, USA.

Cover of book

The plan for this book was just about perfect. Collect articles using Swarm and provide working example code for each article. Combine it with an overview of the philosophy of agent-based modelling in general and Swarm in particular. And, in order to give the articles some coherence and readability, concentrate the substance in a particular field, in this case, economics. People who are interested in learning about agent-based modelling can dig through the source code of working examples, while experts can inspect the work of their colleagues and consider the impact of modifications. Because all of these models use Swarm, a set of code libraries that can be put to use in virtually any kind of simulation model, there is a good chance that a reader's study of these models will lead naturally to an enhancement of the personal research enterprise.

In many respects, the plan is implemented effectively. The Introduction, by the editors does a fine job of explaining what agent-based modelling is and how it can be useful. Swarm is described as a mid-level library, one which relieves the user of the need to write everything from scratch, but does not go so high as to block the user's effort to customise and craft a program to suit a research mission. I agree very strongly with this description.

Benedikt Stefansson's tutorial essay, which is called "Simulating Economic Agents in Swarm," is an extremely good introduction to Swarm as a programming library. Over the years, Stefansson has played an important rule in the development of the Swarm community. He was both an early user and educator, teaching courses with Swarm at UCLA and also offering tutorial presentations at the Swarm users annual meetings. His essay steps through an example of the Iterated Prisoner's Dilemma model, showing the ins-and-outs of Swarm model construction. When I started with Swarm in 1997, Stefansson's online resources, which included an earlier version of his IPD model, were an invaluable aid, and I expect his essay will be a great help to many would-be Swarm users in the future. Simply put, this a very useful chapter.

Before I address the applications that are presented in following chapters, I have to admit that I was rather frustrated because I was not able to easily obtain the source code for all of the articles. There are two web pages where one might look for code. A page first appeared on the Swarm Development Group page, http://www.swarm.org, and then later at the address mentioned in the book itself, http://www-ceel.gelso.unitn.it. At the current time, one cannot find the code for all the articles on either of these sites. Code for some, but not all, of the articles can be obtained directly from the authors. My opinion is that the editors should have a duty to make sure the code for all articles is available and in a common format. I focus my comments below on the articles for which I was able to obtain code.

There is one other issue I would like to mention. The currently released version of Swarm is version 2.1.1. Most of the models in this book were written for Swarm 1.0 (or an earlier version) and I don't care to install an old version of Swarm in order to run the code. In addition, there have been changes in other support libraries. As a result, several of the models required some pretty significant updating. In some cases, the ones in which the changes were the most difficult, I've made packages available at : http://lark.cc.ukans.edu/~pauljohn/Swarm/OtherPeoplesCode/LunaStefanssonVolume. I have done this because I believe the code for the models in this book is a highly valuable thing. And, I believe most novice programmers or beginning Swarm users would not be able to make this code work without a substantial investment of effort.

To give some organising framework for these comments that follow, let me explain that I think simulations can often be fruitfully categorised according to the level of aggregation in the information that is made available to the agents. A "global indicator" model is one in which the agent is able to obtain information about the state of the system as a whole from some kind of over-arching entity. In such a case, the agent has information about global events, for example, the system-wide price of margarine or some other aggregate quality of the system. A "local indicator" model is one in which the agent has limited information, perhaps only information that can be directly obtained by the agent from inspecting its immediate surroundings. The agent does not know the price of margarine in the market, but it might find out what its neighbours are paying for margarine. Many market models are, by historical tradition, designed as global indicator models. They typically posit the existence of a market-maker, one who sets the prices and makes sure that supply equals demand. Some market models are more decentralised, of course, and it is often interesting to consider the implications of changing a model to alter information availability. (This is not an original point, in fact, it is one the most compelling insights in Epstein and Axtell's Growing Artificial Societies.)

Pietro Terna's essay, "Economic Experiments with Swarm: A Neural Network Approach to the Self-Development of Consistency in Agents' Behavior" is accompanied by a very clear and well-developed set of computer code. The article outlines a proposed framework for multi-agent simulations, which (put bluntly) is a conceptual toolkit to help model builders separate the work they must do within their agents from that which can be done by other classes. Terna's approach is to build classes that can hold environmental data and calculating machinery which can be accessed by agents. When an agent wants to decide what to do, for example, it may gather facts from the environment object (dubbed the "DataWarehouse") and pass this to an instance of the "RuleMaster" class in order to obtain a calculation. From a student's point of view, this code is worthy of study because it demonstrates the importance of modularity in model design. One of the most exciting aspects of the article is the contention that it is possible to design, in my terminology, a "local indicator" model that produces the same results as a "global indicator" model. Terna shows that a decentralised market, one in which the agents negotiate trades directly with each other - there is no market maker or price-adjusting agent - may result in a "consistent" marketplace. I'd recommend that people with an interest should grab a copy of the source code and do some investigating. This code base is clear and easy to read, and it offers some general purpose classes that can be put to use in other projects.

Charlotte Bruun and Francesco Luna's essay, "Endogenous Growth with Cycles in a Swarm Economy: Fighting Time, Space, and Complexity," explores questions that have long interested macro economists. Perhaps most importantly, where do economic swings come from, and are they an inherent part of a capitalist economy? In the model, there are spatially distributed economic agents. Each agent can be either a firm or a worker, depending on whether it chooses to produce goods with the assistance of others, or to assist others in production. The main dynamic of the model is found in the process through which firms attract other would-be firms to become workers. In almost all respects, agents obtain information locally, ascertaining the availability of labour from neighbouring cells and also selling either their product or their labour to agents who are nearby. Money supply and other accounts are kept in a centralised object, and it appears to me that many parameters that govern the economy, such as the wage rate, are set exogenously at the same level for all firms. The most substantively important result is that growth in such a model is accompanied by boom-bust cycles. The code base for this model is smaller, and perhaps easier to decipher, than it is for some of the others. For beginners, this code has many features worth study, including a multipurpose class which keeps information about the state of the grid in which the agents are embedded.

Massimo Sapienza's "An Experimental Approach to the Study of Banking Intermediation: The Banknet Simulation," is interesting in several respects. First, it uses an add-on Swarm library, the Graph library (not to be confused with the Graph class in Swarm's GUI library). As far as I know, the Graph library is not in extremely wide usage, but it is kept up to date with the Swarm package and helps when building models in which interconnections between agents are visually displayed. Second, Sapienza's simulation begins with one of the most famous Swarm applications, the Banknet model, which was created by Manor Askenazi, a member of the original Swarm software team at the Santa Fe Institute. Sapienza observes, quite rightly, that one of the major advantages of a toolkit like Swarm is that people can share terminology and code, so that cumulative progress in the research enterprise can be accelerated. The code base for this model required a significant amount of updating in order to work with the current Swarm libraries. The model begins with completely individualised agents who borrow and save money with each other. A financial intermediary has been created when an agent begins to make loans and accept savings deposits from other agents. Under some conditions, it appears that some agents become increasingly large intermediaries, and in the end, almost all agents are borrowing and saving with a small number of largish financial centres. Conditions are demonstrated which can thwart the development of such a consolidated banking system, such as a dramatic rise in financial uncertainty. When times are bad, there are "bank runs" and the number of large intermediaries drops dramatically.

Tim Jares's essay, "Numerical Modeling, Noise Traders, and the Swarm Simulation System," has a fairly large code base that one can easily decipher and also an excellent substantive motivation. The code is distributed with a small set of scripts that can assist in automating model runs. The basic question addressed in the article is this. Suppose that we have a traditional stock market model with global information about prices available to all agents. Suppose further that there is uncertainty among agents about how profitable a company will be, but that as time goes by, the profitability of a firm's past performance is revealed simultaneously to all agents. In such an environment, much literature would lead us to expect that agents which trade on the basis of the fundamental value of a company will succeed, while the "noise" traders, who simply gamble on technical trends, will be driven out. Jares shows that, contrary to expectation, the introduction of noise traders can change the trajectory of the market, in a way that reduces the general welfare of all agents. Jares offers a clear, systematic investigation of the conditions under which the influence of noise traders can be minimised.

Marco Corazza and Alessandro Perrone present a contrast of traditional mathematical modelling and simulation in their essay, "Nonlinear Stochastic Dynamics for Supply Counterfeiting in Monopolistic Markets." To a greater degree than is typical in this volume, the authors formalise their mathematical theory of the demand and supply of counterfeit products. The analysis of the simulation model is quite succinct, presenting snapshots from a few example parameter settings. The code for this model required some significant updating, but I'd recommend readers who are interested in the creation of line plots in Swarm to dig into it. Like many users, I had become accustomed to using Swarm's simple EZGraph class, which is tailored for plotting of time series. This code makes use of the more general Graph class, which offers many more features.

The article by Fu-ren Lin, Troy Strader, and Michael Shaw, "Using Swarm for Simulating the Order Fulfillment Process in Divergent Assembly Supply Chains," explores the co-ordination of behaviour among firms in a multi-stage production process. The code for this model was more difficult for me to decipher than the others were. This is partly because it does not use the standard Swarm approach of determining whether or not the model is being run in a graphical interface or batch mode and partly because several test versions of various classes are packaged with the final product. In its "native" state, the code assumes that the user supplies a set of command line arguments for a batch run of the model, but the authors do not provide clear instructions on what these options must be. As a result I was unable to run the simulation. Without actually running the model, I hesitate to recommend that readers ought to dig into it, but I can say this much about it. The article describes an extremely rich model of order fulfilment which takes into account the interaction of many separate types of agents, and if the code could be brought into a usable state, I expect it would be very interesting.

The code for Francesco Luna and Alessandro Perrone's essay, "The Coevolution of Human Capital and Firm Structure," is presented as an invitation to the reader to take a "hands on" approach. The authors contend that the populations of workers and firms co-evolve. The differences in economic development across countries, which are often attributed to their natural resource bases, may instead be due to path-dependent phenomena, such as accumulated human capital of a society. The model presents two classes of agents, workers and firms.

Worker output translates a pair of binary inputs, such as (1,1) or (-1,1) into a binary output, 1 or -1. Firms hire workers at random and then attempt to match the abilities of the workers to the demands of their consumers. This is somewhat confusing, because the model does not have a class of consumers, but rather the efficiency of firms is subjected to a formal test during each period. After updating the code, I found some beautiful histograms and rasters appearing on the screen as the model ran. The code in this package is not as easy to read as some of the others, partly because it does not follow a consistent rule for indentation and parentheses.

I was not able to obtain code for two articles. "Imitative Behavior and Tax Evasion," by Luigi Mittone and Paolo Patelli, is an interesting paper in which different models of tax-payer behaviour and government tax enforcement policy are compared. This is a global information model, as agents are offered precise information about the state of the world as the simulation develops. Christoph Schlueter-Langdon, Peter Bruhn and Michael Shaw presented the article, "Online Supply Chain Modeling and Simulation." The authors offer a PDF file in which one can read the source code, but I can't find a way to export the code from that format.

I have one general remark of criticism which applies to almost all of these applications. The authors present the results of one or two runs, but in some cases it would be better to offer the results of hundreds or thousands of simulations for each parameter setting. That would allow readers to ascertain the variety of behaviours that are observed. Since the models generally begin by the assignment of random numbers, the effect of repetition should be taken into account.

After working through the models, I had a few thoughts I would like to share. First, the Swarm philosophy is highly sound. The Swarm community - a diverse collection of people from various fields and walks of life - strives for a common vocabulary and "scientific workbench" for the investigation of artificial societies. Even though these models were written for various purposes, with a couple of days effort one can track through their code and understand the intention of the authors. Where the intention of the author is not clear, perhaps because a complicated technical issue is being discussed, or because English is the author's second language, the source code sits as an objective, complete record that a third party can investigate.

Second, the Swarm libraries themselves have made a great deal of progress. The Swarm developers have gone to great lengths to simplify some common programming tasks, to clarify the libraries, and add features that prevent users from making mistakes. In Swarm 1.0.5, for example, the library followed the Objective C policy that allows users to send messages to "nil" (non-existent) objects without raising an error message. Most users do not intend to send messages to nil objects, of course, and so Swarm 2.0 introduced a feature that halts the simulation and warns the user that this has occurred. Some of the simulations described in this book caused nil method exceptions. I've fixed them according to my best guess of the author's intention, but it would be better if the authors themselves were aware of this situation. Another significant advancement in Swarm is in the serialisation of simulations, which refers to the saving of object states between runs and accessing saved information in future runs. Several of these models use an older style of data input, one which is more prone to error and more difficult to maintain.

Third, Swarm has grown beyond its Objective C roots in the time since this book was prepared. If prospective users are put off by the fact that these programs are written in Objective C, they will be glad to learn they can write their programs in the increasingly popular language called Java. After Spring 2000 (the release of Swarm 2.0) Swarm programs could be written in Java and access to the Swarm library has been allowed through the Java Native Interface. At the current time, work is underway to support access to Swarm from other languages. The groundwork is also being laid to allow Swarm simulations to be run over the Internet in modern web browsers. I hesitate to guess when these possibilities will be fully functional, but would invite programmers to join in the software development effort. The Swarm Development Group (http://www.swarm.org) is an open, user-driven entity and the code base is open and available under the GNU general public license. Users are free to check out snapshots of the Swarm libraries, add new features that suit their needs, and propose changes back to the community.

ButtonReturn to Contents of this issue

© Copyright Journal of Artificial Societies and Social Simulation, 2001