LINKING REPAST AND COMPUTATIONAL ... - CiteSeerX

5 downloads 407 Views 2MB Size Report
linked system for social agent simulation experimentation are presented. .... fully concurrent discrete event scheduler, a model visualization environment, ...
5

Paper extracted from Proceedings of the Agent 2005 Conference on Generative Social Processes, Models, and Mechanisms, ANL/DIS-06-5, ISBN 0-9679168-6-0, C.M. Macal, M.J. North, and D. Sallach (editors), co-sponsored by Argonne National Laboratory and The University of Chicago, October 13−15, 2005.

LINKING REPAST AND COMPUTATIONAL MATHEMATICS SYSTEMS: MATHEMATICA AND MATLAB C.M. MACAL* and T.R. HOWE, Argonne National Laboratory, Argonne, IL ABSTRACT This paper describes investigations into linking computational mathematics systems (CMSs) with the Java-based Repast agent-based modeling toolkit. The goal is to build an interactive and seamless agent simulation environment that benefits from the strongest points of each component. In general, CMSs such as Mathematica and MATLAB are fully integrated development environments. Their interpretative nature and seamless integration of graphical and statistical analysis capabilities provide immediate feedback to users during the model prototyping and development phases. These features make CMSs particularly useful as rapid prototype development tools or as part of large-scale model development efforts that use agent-based modeling toolkits. Large-scale agentbased modeling environments, such as Repast, support features specific to agent modeling, including the availability of sophisticated time schedulers, agent communications mechanisms, flexible interaction topologies, and facilities for storing and displaying agent states. Typically, Repast users build models by incorporating Repast library components into their own programs or by using a visual scripting environment that creates program code automatically. Of the two CMSs investigated, Mathematica was found to be more suitable for linking to Repast because of its sophisticated capabilities for linking to Java, as provided by the J/Link environment. In the system described here, Mathematica is used to implement the models of agent behavior and interaction, while Repast is used for its discrete-event simulation controls and features. In this configuration, Repast simulation classes are extended to call user-written Mathematica programs that model agent behaviors. Interactive simulation controls provided by Repast allow the user to control and interact with the simulation as it progresses through time. Mathematica’s full mathematical modeling libraries, visualization capabilities, statistical analysis routines, and database capabilities are available to the agent model during and after the simulation. The linked Mathematica-Repast system is an interpreted environment that requires no compilation or linking steps, which are needed by other general programming languages or by agentbased modeling toolkits alone. The linked system also allows users to access the full range of Repast-provided Java classes and Mathematica-provided Java classes through the J/Link libraries. One feature of the linked system is that it naturally provides a realtime, interactive animation system for agent-based simulations without accumulating the overhead entailed in storing a long stream of graphics images. Two examples of using the linked system for social agent simulation experimentation are presented. Keywords: Agent-based modeling, computational mathematics systems, Mathematica, Repast, toolkit, rapid prototype * Corresponding author address: Charles M. Macal, Decision and Information Sciences Division, Argonne National Laboratory, 9700 S. Cass Ave., Argonne, IL 60439; e-mail: [email protected].

6

Paper extracted from Proceedings of the Agent 2005 Conference on Generative Social Processes, Models, and Mechanisms, ANL/DIS-06-5, ISBN 0-9679168-6-0, C.M. Macal, M.J. North, and D. Sallach (editors), co-sponsored by Argonne National Laboratory and The University of Chicago, October 13−15, 2005.

INTRODUCTION This paper describes investigations into linking computational mathematics systems (CMSs) with the Java-based Repast agent-based modeling toolkit. The goal is to create an interactive and seamless agent simulation environment that can benefit from the strongest points of each system. In general, computational mathematics systems, such as Mathematica and MATLAB, are fully integrated development environments and offer linkages to Java in some form. After reviewing the Java linking capabilities of MATLAB and Mathematica, we conclude that Mathematica is more suitable for linking to Repast owing to its more complete capabilities for linking to Java, as provided by the J/Link environment. We go on to describe a new configuration for building agent-based models in which Repast simulation classes are extended to call Mathematica programs that model agent behaviors and interactions. Repast is used for its discrete-event (time-stepped) simulation features and interactive simulation controls. The interactive graphical user interface (GUI) is composed of components from both the Repast and J/Link GUI classes. This paper is organized as follows. The second section provides background information on agent-based modeling, computational mathematics systems (specifically, MATLAB and Mathematica), and agent-based toolkits (specifically, Repast). The third section presents the agent implementation approach through two examples, the Boids model by Reynolds (2005) and a social agent interaction model. The fourth section presents the architecture of the RepastMathematica system. The final section draws conclusions and identifies promising future directions. BACKGROUND Agent-based Modeling and Simulation (ABMS) ABMS is an active area of rapid growth and development in modeling and simulation. Social agent simulation offers new possibilities for gaining insights into fundamental social processes (Axelrod 1997; Axtell 2000; Bankes 2002; Bonabeau 2001; Cederman 2002; Epstein and Axtell 1996; Gilbert and Troitzsch 1999; Kohler et al. 2005; Sallach and Macal 2001; Schelling 1971). A social agent is a discrete entity with its own goals and behaviors. Agents have autonomy, and, in general, have capabilities to adapt and modify their own behaviors. Agents are diverse and heterogeneous. The key assumptions are as follows: •

The most relevant aspects of behaviors (at least the most relevant to the model application) can be described.



Mechanisms by which agents interact can be described and represented algorithmically.



Complex social processes can be modeled by building a system “from the bottom up.”

Examples of agents include people, groups, and organizations; social insects and swarms; robots and systems of autonomous vehicles, and many others.

7

Paper extracted from Proceedings of the Agent 2005 Conference on Generative Social Processes, Models, and Mechanisms, ANL/DIS-06-5, ISBN 0-9679168-6-0, C.M. Macal, M.J. North, and D. Sallach (editors), co-sponsored by Argonne National Laboratory and The University of Chicago, October 13−15, 2005.

An agent-based model consists of three elements: •

Set of agents,



Set of agent relationships, and



Framework for simulating agent behaviors and agent interactions.

In an abstract view of an agent-based model, an agent includes a representation for the agent and its behaviors; that is, how the agent processes information (updates its state) on the basis of current events and references to past events (memory). An agent relationship exists for a pair of agents and includes a representation of the relationship’s characteristics and the mechanisms that act on the relationship to update its state. A framework for simulating agent behaviors and interactions is the mechanism that updates the universe of agents and their relationships in the model; the simulation framework is provided by agent-based modeling toolkits. A defining principle of ABMS is the assumption that agents have access to only local information. The visibility of agents is constrained to be within an agent’s local neighborhood, where the extent of the neighborhood is open to the discretion of the modeler. This characteristic has important implications for the structure of ABMS. A more complete overview of ABMS can be found in Macal and North (2005). Agent-based Modeling Toolkits: Repast Substantial public research and development investments have produced many ABMS software environments that are now freely available. These include Repast, Swarm, NetLogo, and MASON, as well as numerous others. Large-scale ABMS toolkits, such as Repast, extend agent modeling beyond simple desktop environments and allow thousands to millions of agents to engage in sophisticated interchanges. Proprietary toolkits are also available. For a recent review and comparison of Java-based agent modeling toolkits, see Tobias and Hoffman (2004). Large-scale agent-based modeling environments generally support features specific to ABMS, including: •

Availability of sophisticated time schedulers,



Facilities for storing and displaying agent states,



Agent communications mechanisms, and



Flexible agent interaction topologies (grids, networks, and geographical information-system [GIS]-based structures)

Repast (REcursive Porous Agent Simulation Toolkit; see Repast 2005, http://repast.sourceforge.net/) is the leading free and open-source, large-scale ABMS library (Collier and Sallach 2001; Collier et al. 2003). Repast seeks to support the development of extremely flexible models of agents with an emphasis on social interactions. It has been used extensively in social simulation applications. North and Macal (2005) has an overview of Repast applications in the social sciences.

8

Paper extracted from Proceedings of the Agent 2005 Conference on Generative Social Processes, Models, and Mechanisms, ANL/DIS-06-5, ISBN 0-9679168-6-0, C.M. Macal, M.J. North, and D. Sallach (editors), co-sponsored by Argonne National Laboratory and The University of Chicago, October 13−15, 2005.

Repast is a pure Java modeling environment that supports the development of large-scale agent models and linkages to other software systems. It includes a variety of features, such as a fully concurrent discrete event scheduler, a model visualization environment, integration with GISs for modeling spatially situated agents on real maps, and adaptive behavioral tools (e.g., neural networks, genetic algorithms). Repast includes a full range of time-stepped simulation run controls that are useful in driving simulation models written in other languages, such as Mathematica, which is the focus of the remainder of this paper. Users build simulations by incorporating Repast library components into their own programs or by using the visual Repast for Python Scripting environment (Collier et al. 2003). More information on Repast, as well as downloads, can be found at the Repast home page (Repast 2005). Repast is maintained by the Repast Organization for Architecture and Design (ROAD). Computational Mathematics Systems: Mathematica and MATLAB Mathematica (see Wolfram Research, Inc. 2005, www.wolfram.com) and MATLAB (see MathWorks 2005, www.mathworks.com) are examples of CMSs, which allow users to apply powerful mathematical algorithms to solve problems through a convenient and interactive user interface. CMSs supply a wide range of built-in functions and algorithms. Their origins go back to the late 1980s. CMSs are structured in two main parts: (1) a user interface that allows dynamic user interaction and (2) an underlying computational engine, or kernel, that performs the computations according to the user’s instructions. Unlike conventional programming languages, CMSs are interpreted rather than compiled, so there is immediate feedback to the user, but some performance penalty is paid. The underlying computational engine is written in the C programming language for these systems, but the user does not see the C coding. The most recent releases of CMSs are fully integrated systems that combine capabilities for data input and export, graphical display, and the capability to link to external programs written in conventional languages such as C or Java by using interprocess communication protocols. The powerful features of CMSs, their convenience of use, the need for the user to learn only a limited number of instructions, and the immediate feedback provided to users make CMSs good candidates for developing agent-based social simulations. However, it should be noted that unlike dedicated agent-based toolkits like Repast, CMSs have not, to date, provided specific capabilities or resources for modeling agents. A further distinction can be made among CMSs. A subset of CMSs — called computational algebra systems (CASs) — are interactive programs that, in contrast to numerical processing systems, allow mathematical computations with symbolic expressions. Computations are carried out exactly, according to the rules of algebra, instead of numerically with approximate floating point arithmetic. In contrast, a numeric processing language requires that every variable have a value assigned before it is used. Typical uses of CASs are equation solving, symbolic integration and differentiation, exact calculations in linear algebra, simplification of mathematical expressions, and variable precision arithmetic. Computational mathematics systems consist of numeric processing systems or symbolic processing systems, or possibly a combination of both. Especially when numeric and algebraic capabilities are combined into a multi-paradigm programming environment, new modeling possibilities for developing sophisticated agent-based social simulations with minimal coding open up. The core MATLAB system is strictly a numeric CMS, with limited symbolic processing capabilities

9

Paper extracted from Proceedings of the Agent 2005 Conference on Generative Social Processes, Models, and Mechanisms, ANL/DIS-06-5, ISBN 0-9679168-6-0, C.M. Macal, M.J. North, and D. Sallach (editors), co-sponsored by Argonne National Laboratory and The University of Chicago, October 13−15, 2005.

provided by an add-on module; Mathematica, however, combines numeric and extensive symbolic processing capabilities. The symbolic processing capabilities in Mathematica greatly extend its ability to represent abstract data types and generalized data structures. The flexibility of data types plays an important role in developing large-scale, extensible models for agentbased social simulation. Macal (2004) has a more extensive review of CMS applications to agent simulation. In-depth reviews of the system documentation and testing concluded that MATLAB’s current implementation allows Java GUIs and graphics to be driven by MATLAB programs, but it does not allow the two-way linkage (i.e., only the MATLAB-to-Java linkage is implemented). Furthermore, Mathematica’s underlying architecture and J/Link class library permit it to be extended to allow the two-way linkage requirements to be met (Gayley 2004a,b). Therefore, the remainder of this paper describes the Repast-Mathematica system that was successfully implemented. Mathematica Mathematica’s symbolic processing capabilities allow programming in multiple paradigms, either as alternatives or in combination (Wolfram 2003). Programming paradigms include functional programming, logic programming, procedural programming, rule-based programming, and object-oriented programming. Mathematica is an interpreted language with the C-based kernel of Mathematica running underneath the notebook interface. In terms of data types, everything in Mathematica is an “expression.” An expression is a data type with a head and a list of arguments in which even the head of the expression is part of the expression’s arguments. The Mathematica user interface consists of a notebook. A notebook is a fully integratable development environment plus a complete publication environment. The Mathematica application programming interface (API) allows programs written in C, Fortran, or Java to interact with the kernel. The API has facilities for dynamically calling routines from Mathematica as well as for calling Mathematica as a computational engine. Capabilities of Mathematica for Linking to Java Computational social scientists have identified the need for a rapid social science discovery process in which computational experimentation and electronic laboratories would be key instruments facilitating rapid progress (Sallach 2003). A linked Repast-CMS system would provide a unique set of benefits for rapid prototype development of social agent models, including these: •

Access to Repast’s scheduler and simulation controls (SetUp, Initialize, Step, Run, Pause, Stop, Exit), which allow users to interactively control a timestepped simulation;



Mathematica’s mathematical modeling libraries, visualization capabilities, and statistical analysis routines;

10

Paper extracted from Proceedings of the Agent 2005 Conference on Generative Social Processes, Models, and Mechanisms, ANL/DIS-06-5, ISBN 0-9679168-6-0, C.M. Macal, M.J. North, and D. Sallach (editors), co-sponsored by Argonne National Laboratory and The University of Chicago, October 13−15, 2005.



Database capabilities available to the real-time agent-based modeling environment and for post-simulation analysis;



Spatial and geodesic data and analysis capabilities such as geographical information systems (GIS) provided through Repast and Mathematica;



Access to the full range of Repast-provided Java classes, as well as the Mathematica Java classes provided through J/Link;



Interpreted environment, requiring no compilation or linking steps needed by general programming languages and agent-based modeling toolkits alone; and



A real-time, interactive animation system for agent-based simulations.

The linkage is created by developing a software component — a Java class — that wraps communication protocols between Java and Mathematica. AGENT IMPLEMENTATION Boids Model Example We next implement and describe the “Boids” model, developed by Craig Reynolds (Reynolds 2005). Boids is an interesting example of a very simple agent simulation that demonstrates emergent group behavior based on simple rules for agent behaviors. (Note that the rules do not include learning or adaptation on the part of the agents.) There are three main rules (Rules 1–3) and one rule that has been added for the demonstration example (Rule 4). The rules, which treat the agents as a “flock,” are: •

Rule 1 (cohesion). An agent steers to move toward the average position of local flockmates.



Rule 2 (separation). An agent steers to avoid crowding local flockmates.



Rule 3 (alignment). An agent steers toward the average heading of local flockmates.



Rule 4 (containment). An agent heads toward in-bounds if it strays out of bounds.

The agent behaviors implied by the four rules are illustrated in Figure 1. Agents move in continuous space and discrete time. This allows them to move at different speeds according to their individual characteristics, as opposed to a grid-based model, which would enforce movement over discrete space and constant speeds.

11

Paper extracted from Proceedings of the Agent 2005 Conference on Generative Social Processes, Models, and Mechanisms, ANL/DIS-06-5, ISBN 0-9679168-6-0, C.M. Macal, M.J. North, and D. Sallach (editors), co-sponsored by Argonne National Laboratory and The University of Chicago, October 13−15, 2005.

Cohesion: Steer to move toward the average position of local flockmates

Separation: Steer to avoid crowding local flockmates

Alignment: Steer toward the average heading of local flockmates

FIGURE 1 Agent rules in the Boids model

We next demonstrate the Boids model by using the Repast-Mathematica system. We may ask some questions in advance of the demonstration, such as: •

How do we expect the agents to behave as they operate according to the simple rules just described?



Will the agents randomly mill around, stand still, or exhibit other behavior?



How can we statistically characterize the behavior of the agents that we observe during the simulation?

A snapshot of the Boids simulation is shown in Figure 2.

12

(a) Initial random configuration

(b) After 650 updates FIGURE 2 Boids model simulation

Paper extracted from Proceedings of the Agent 2005 Conference on Generative Social Processes, Models, and Mechanisms, ANL/DIS-06-5, ISBN 0-9679168-6-0, C.M. Macal, M.J. North, and D. Sallach (editors), co-sponsored by Argonne National Laboratory and The University of Chicago, October 13−15, 2005.

13

Paper extracted from Proceedings of the Agent 2005 Conference on Generative Social Processes, Models, and Mechanisms, ANL/DIS-06-5, ISBN 0-9679168-6-0, C.M. Macal, M.J. North, and D. Sallach (editors), co-sponsored by Argonne National Laboratory and The University of Chicago, October 13−15, 2005.

Figure 3 shows an analysis of the simulation results. The statistics recorded during the simulation are available for post-simulation analysis in the Mathematica notebook from which we launched the simulation. The center of mass (CM) for the agents is plotted over the simulation time along with the distance of the CM from the original CM. Further time-series analysis done in the Mathematica notebook (not shown here) on the data series logged during the simulation reveals that the time series is of a chaotic nature. Agent Representation Here we briefly describe the agent implementation in Mathematica that underlies the Boids model. The representation is based on defining abstract data types and associated attributes and functions, similar to an object-oriented (O-O) implementation. Maeder (2000) describes this approach for implementing models in Mathematica. This approach most closely aligns the Mathematica implementation of the agent model with the representation that would be most natural to implement directly in Repast or any other O-O agent-based modeling toolkit. This is desirable from the standpoint of having a smooth transition path for the Repast-CMS system to a full Repast implementation, should this transition become advantageous at some point in the development cycle. Furthermore, the Mathematica agent model can be easily described via a unified modeling language (UML) representation (Booch et al. 1998), which separates the model specification from its implementation, whether the implementation is in Mathematica, Repast, or another O-O programming language.

FIGURE 3 Post-simulation analysis of Boids simulation time-series data

14

Paper extracted from Proceedings of the Agent 2005 Conference on Generative Social Processes, Models, and Mechanisms, ANL/DIS-06-5, ISBN 0-9679168-6-0, C.M. Macal, M.J. North, and D. Sallach (editors), co-sponsored by Argonne National Laboratory and The University of Chicago, October 13−15, 2005.

An agent type or pattern is represented by an abstract data type, agent. This is a Mathematica expression with a head agent and a sequence of patterns that corresponds to agent attributes. The agent data type is a template for the specific instance of agents in the model and corresponds directly to a class in Java or Repast. For example, in the Boids model, the agent data type is defined as: agent[name (string), location: x coordinate, location: y coordinate, velocity: x component, velocity: y component, other attributes (e.g., color)]. Agent Operations Agent Creation All of the agents in the model are represented by a list called agents. Agents are created and updated in user-written Mathematica programs. An example of the agents list is: agents ={ agent["#26", 26.0, -50.9, -19.8, 38.7, «JavaObject[java.awt.Color]», 42, False, 16.0, False, 0, 1, TargetNone, 2.6, {}], …, agent[…] }; Agent Updating Agent states are updated at every time step in the simulation. Updated agent attributes include location and status. Mathematica allows for a functional programming style and has the capacity for mapping a function onto a list such that the function is applied to every element in the list in one statement. For example, the function agentRulesBoid is a user-written Mathematica program that updates the status of an agent. This is accomplished via the following statement, which is applied to agents each time period: agents = agentRulesBoid /@ agents; where /@ is shorthand for the mapping function applied to the list agents. Note that the order in which the agents are updated is the order in which the agents appear in the list agents. This order is arbitrary. Since the order of agent interactions in the Boids model has no effect on the final states of the updated agents, this arbitrary ordering is adequate. If, on the other hand, the ordering of agent updating was a significant factor in determining model results, other agent ordering schemes could be invoked before the agentRulesBoid program was applied. For example, the agents list could be randomized each time before applying agentRulesBoid, as in: agents = agentRulesBoid /@ randomizeList[agents];

15

Paper extracted from Proceedings of the Agent 2005 Conference on Generative Social Processes, Models, and Mechanisms, ANL/DIS-06-5, ISBN 0-9679168-6-0, C.M. Macal, M.J. North, and D. Sallach (editors), co-sponsored by Argonne National Laboratory and The University of Chicago, October 13−15, 2005.

where randomizeList is a program that simply randomizes an arbitrary list. The agentRulesBoid is a program structured as follows in Mathematica notation: agentRulesBoid[a:agent[id_, x_, y_, vx_, vy_, col_, sz_, fil_, v0_, sel_, nColl_, 0, target_, orient_, leat_]] := Module[... ... (*CALCULATE prey exclusive center of mass* cmXPrey = If[neighborsXPreyLocs === {}, {0,0}, Mean[neighborsXPreyLocs] - {x,y}] (*prey XCM*); ... (*RULE 1: COHESION Move rule1Param % way toward XCM.*) v1 = rule1Param * cmXPrey; xx =…; yy =…; wx =…; wy =…; ... (*RETURN updated agent with new position, velocity and orientation*) agent [id, xx, yy, wx, wy, col, sz, fil, v0, sel, nColl, 0, target, newOrient, leat] ]; The agentRulesBoid program is structured to take an individual agent as input and to return that agent, with its attributes updated, to reflect the results of agent decision making and interaction. The agentRulesBoid program is a modular representation of agent behavior. All the rules of agent behavior and interaction are included in this single program. A similar program can be written to represent the behaviors of each of the other types of agents in the model. For example, a predator agent was developed and instantiated with behaviors to chase and prey upon the other agents in the Boids model. Social Agent Interaction Model We next describe a social agent interaction model (SAIM) and implement it in the Repast-Mathematica system. Agents in this example have two types of social behaviors: movement and influence. The movement rules are motivated by the “mobile heterogeneous agent model” of Gaylord and D’Andria (1998). The influence rules are based on opinion change as applied to social influence (Friedkin and Johnsen 1990). The SAIM combines both of these behaviors into a single model at the agent level. This model turns out to be an interesting example that demonstrates the highly nonlinear behavior of a complex system composed of agents with very simple rules for agent behaviors. The social agent mobility update rules are as follows: •

Rule 1 (sequencing). Agents move (or not) in random order at each simulation time step. (This assumption eliminates contention for moving into unoccupied spaces.)

16

Paper extracted from Proceedings of the Agent 2005 Conference on Generative Social Processes, Models, and Mechanisms, ANL/DIS-06-5, ISBN 0-9679168-6-0, C.M. Macal, M.J. North, and D. Sallach (editors), co-sponsored by Argonne National Laboratory and The University of Chicago, October 13−15, 2005.



Rule 2 (stationarity). If the nearest neighbor site that the agent is facing is occupied by another individual, the individual remains in place and chooses a new random direction to face.



Rule 3 (mobility). If the nearest neighbor site that the agent is facing is unoccupied, the individual moves into that space and chooses a new random direction to face.

The social agent influence update rules are as follows: •

Rule 1. If an agent is surrounded by more red neighbors than blue neighbors, the agent changes to red



Rule 2. If an agent is surrounded by more blue neighbors than red neighbors, the agent changes to blue.



Rule 3. Ties are resolved randomly.

SAIM is a grid-based (lattice) model in which agents move in discrete space and discrete time. In each time period, agents either remain stationary or move to an adjacent grid cell. Next we demonstrate the SAIM by using the Repast-Mathematica system. We set up an experimental simulation in which there are two types of agents: blue and red. Initially, there are twice as many blue agents as red agents. Each side tries to convince the other side of its position. An agent surrounded by more agents of one color than another adopts the position of the dominant agent. There is one stipulation: Each red agent is twice as convincing as each blue agent. An agent surrounded by only half as many red agents as blue agents is just as likely to adopt red’s position. Thus, the total convincing power of the red and blue agents is equal. In the event that an agent is surrounded by an equal number of red and blue agents in terms of their relative convincing power, the agent randomly chooses a color. We begin an experimental simulation by randomly placing the red and blue agents across the grid. Simulation experiments suggest some interesting questions: Will one type of agent have its opinion dominate, or will there be a stable mix of positions in the long run? What agent and system behaviors will we observe during the simulation? A snapshot of the agent simulation is displayed in Figure 4. Figure 5 shows the results of a single simulation run, which are available for postsimulation analysis in the Mathematica notebook from which we launched the simulation. The numbers of red and blue agents are plotted over the simulation. The plot for this case indicates an extensive initial period of give-and-take between the red and blue agents, which ultimately gives way to what appears to be some kind of phase transition that leads directly to the complete dominance of the red agent population. It should be noted that other random initial placements of red and blue agents may result in different outcomes, such as blue agents winning.

17

(a) Initial agent distribution

(b) After 50 generations FIGURE 4 SAIM

Paper extracted from Proceedings of the Agent 2005 Conference on Generative Social Processes, Models, and Mechanisms, ANL/DIS-06-5, ISBN 0-9679168-6-0, C.M. Macal, M.J. North, and D. Sallach (editors), co-sponsored by Argonne National Laboratory and The University of Chicago, October 13−15, 2005.

18

Paper extracted from Proceedings of the Agent 2005 Conference on Generative Social Processes, Models, and Mechanisms, ANL/DIS-06-5, ISBN 0-9679168-6-0, C.M. Macal, M.J. North, and D. Sallach (editors), co-sponsored by Argonne National Laboratory and The University of Chicago, October 13−15, 2005.

Agent Mix Over Time 50

number agents

40

30

20

10

0

20

40

60 80 generation

100

120

FIGURE 5 Post-simulation analysis of SAIM time-series data

ARCHITECTURE OF REPAST-MATHEMATICA The interactive Repast simulation controls (buttons of the user interface) for controlling the course of a time-stepped simulation include Setup, Initialize, Step, Run, Pause, Stop, and Exit. Mathematica’s J/Link classes provide functionality to the user for interacting with and controlling the simulation as it progresses via the Repast controller through the Repast GUI. A single Mathematica notebook corresponds to a single agent simulation model and includes these programs. The simulation user interface for the Repast-Mathematica system is shown in Figure 6. The details of the Repast-Mathematica architecture for a typical agent simulation model are shown in Figure 7. User-written Mathematica Simulation Control Programs The following user-written Mathematica programs are the core of an agent simulation application: Simulate, init, step, stop, exit, and plotCMX. •

Simulate is a Mathematica program that creates an instance of the Repast class controller. Simulate loads any needed Java classes, creates the GUI objects and event handlers, and assigns Mathematica simulation parameters applicable to all simulation runs. Once called, Simulate hands over program control to the Repast controller for the duration of the simulation. The controller calls various Mathematica programs in response to user actions on the Repast control panel.

19

Paper extracted from Proceedings of the Agent 2005 Conference on Generative Social Processes, Models, and Mechanisms, ANL/DIS-06-5, ISBN 0-9679168-6-0, C.M. Macal, M.J. North, and D. Sallach (editors), co-sponsored by Argonne National Laboratory and The University of Chicago, October 13−15, 2005.

FIGURE 6 User interface for the Repast-Mathematica simulation system



init initializes parameters for the Mathematica simulation, creates the agents, and initializes the GUI. The init program is called when the user presses the Initialize button.



step is called by the Repast controller at each time-step. step calls Mathematica programs that are the heart of the agent simulation model. These programs update agent locations and status. The step program is called once when the user presses the step button or called repeatedly when the user presses the Run button. The calls to step are interrupted when the user presses the Pause, Stop, or Exit buttons.



stop resets the simulation and GUI object parameters. stop is called when the user presses the Stop button.



exit disposes of user-created GUI objects (in Mathematica and Java) and returns control of the program to Mathematica. exit is called when the user presses the Exit button.

20

Paper extracted from Proceedings of the Agent 2005 Conference on Generative Social Processes, Models, and Mechanisms, ANL/DIS-06-5, ISBN 0-9679168-6-0, C.M. Macal, M.J. North, and D. Sallach (editors), co-sponsored by Argonne National Laboratory and The University of Chicago, October 13−15, 2005.

FIGURE 7 Repast-Mathematica agent model architecture



plotCMX is called at the end of each time-step to return the data to the controller for plotting on the Repast/Java side. For the Boids example, plotCMX returns the x and y coordinates of the center of mass of the flock.

User-written Mathematica Interactive GUI Programs In addition to the user-written Mathematica programs involved in the simulation, there are also user-written Mathematica GUI programs. This part of the Mathematica GUI allows the user to interact directly with the agent model. For the Boids Model, there are four main GUI components that are written in Mathematica using J/Link: •

Agent Action frame displays the agents and their animation.



Rule Parameter window allows the user to dynamically vary the agent rule parameters during the simulation.

21

Paper extracted from Proceedings of the Agent 2005 Conference on Generative Social Processes, Models, and Mechanisms, ANL/DIS-06-5, ISBN 0-9679168-6-0, C.M. Macal, M.J. North, and D. Sallach (editors), co-sponsored by Argonne National Laboratory and The University of Chicago, October 13−15, 2005.



Global Parameter window allows the user to dynamically vary global parameters, such as zooming.



Probe window allows the user to view the dynamically changing attributes of a selected agent as the simulation progresses.

An example GUI is shown in Figure 6. These GUI components are implemented via Java and the J/Link GUI classes, which include versions of slider panels and mouse event handlers. It should be noted that a great deal of flexibility exists in terms of which GUI components are implemented as Repast/Java classes versus J/Link-Mathematica classes. Java Classes for Linking Repast and Mathematica •

JLink-Repast.jar is the main entry point for using Repast from Mathematica. It provides a simple class called MathematicaModel along with some helper classes that allow the user to expose his Mathematica functions to the Repast toolkit. It also allows the user to exploit the simulation scheduling facilities, the user interface facilities, and the charting and data collection facilities present in the Repast toolkit. It uses the J/Link library to allow the user to expose his functions and data to Repast.



Repast.jar includes the classes that make up the full Repast library. It stores the Scheduler, which is the heart of the Repast library. The scheduler manages the execution of actions that drive the simulation. It also provides tools for data collection and analysis, reusable agent components, and the user interface. These wrapper classes put all of these pieces into one simple “facade” class that can be easily used by Mathematica. The wrapper exposes many of the useful tools from the Repast.jar without requiring the user to understand how they all relate to one another.



Plot.jar is a set of two-dimensional signal plotter components written in Java to provide real-time animated plots, as used in the Boids model simulation.



Trove.jar is a library that generates Java byte-code that allows Repast to create new classes (create and alter compiled Java code) at runtime on the basis of simple specifications provided by the user.



Colt.jar consists of support libraries for Repast numerical computations and for simulating concurrency.

To complete the linkage of Repast and Mathematica, the five jar files described above are placed in a directory, whose location is added to the JavaClassPath, which makes them accessible to Mathematica. The J/Link libraries are automatically accessible, since they are a standard part of the Mathematica distribution.

22

Paper extracted from Proceedings of the Agent 2005 Conference on Generative Social Processes, Models, and Mechanisms, ANL/DIS-06-5, ISBN 0-9679168-6-0, C.M. Macal, M.J. North, and D. Sallach (editors), co-sponsored by Argonne National Laboratory and The University of Chicago, October 13−15, 2005.

SUMMARY AND CONCLUSIONS We have demonstrated that the linked Repast-Mathematica system is a viable candidate for a rapid prototyping agent modeling environment. This environment is flexible enough to model different agent interaction topologies (grids, networks, free space, etc.). The system allows the user to observe agent behaviors in real time for simulations over extended time horizons, and it allows real-time user interaction to explore agent behaviors and interactions. Results from the simulation are readily available for post-simulation analysis in Mathematica. Future activities include exploring scale-up issues associated with the simulation and display of very large numbers of agents and implementing the Repast-Mathematica agent modeling system on cluster or grid computing platforms. ACKNOWLEDGMENT This work is sponsored by the U.S. Department of Energy, Office of Science, under contract W-31-109-Eng-38. REFERENCES Axelrod, R., 1997, The Complexity of Cooperation: Agent-based Models of Competition and Collaboration, Princeton University Press, Princeton, NJ. Axtell, R., 2000, “Why Agents? On the Varied Motivations for Agent Computing in the Social Sciences,” Working Paper 17, Center on Social and Economic Dynamics, Brookings Institution, Washington, DC. Bankes, S.C., 2002, “Agent-based Modeling: A Revolution?,” Proceedings of the National Academy of Sciences 99(Suppl. 3):7199–7200. Bonabeau, E., 2001, “Agent-based Modeling: Methods and Techniques for Simulating Human Systems,” Proceedings of the National Academy of Sciences 99(Suppl. 3):7280–7287. Booch, G., J. Rumbaugh, and I. Jacobson, 1998, The Unified Modeling Language User Guide, Addison-Wesley, New York, NY. Cederman, L.-E., 2002, “Endogenizing Geopolitical Boundaries with Agent-based Modeling,” Proceedings of the National Academy of Sciences 99(Suppl. 3):7796–7303. Collier, N., et al., 2003, “Onward and Upward: The Transition to Repast 2.0,” in Proceedings of the First Annual North American Association for Computational Social and Organizational Science Conference, Pittsburgh, PA. Collier, N., and D.L. Sallach, 2001, Repast, REcursive Porous Agent Simulation Toolkit; available at http://repast.sourceforge.net/. Epstein, J.M., and R. Axtell, 1996, Growing Artificial Societies: Social Science from the Bottom Up, MIT Press, Cambridge, MA.

23

Paper extracted from Proceedings of the Agent 2005 Conference on Generative Social Processes, Models, and Mechanisms, ANL/DIS-06-5, ISBN 0-9679168-6-0, C.M. Macal, M.J. North, and D. Sallach (editors), co-sponsored by Argonne National Laboratory and The University of Chicago, October 13−15, 2005.

Friedkin, N.E., and E.C. Johnsen, 1990, “Social Influence and Opinions,” Journal of Mathematical Sociology 15:193–206. Gayley, T., 2004a, J/Link User Guide, Version 3.0; available from Wolfram Research, Inc., Champaign, IL, Sept. Gayley, T., 2004b, “Building User Interfaces Using J/Link,” The Mathematica Journal 9(1). Gaylord, R.J., and L. D’Andria, 1998, Simulating Society — A Mathematica Toolkit for Modeling Socioeconomic Behavior, TELOS/Springer Verlag, New York, NY. Gilbert, N., and K.G. Troitzsch, 1999, Simulation for the Social Scientist, Open University Press, Buckingham, UK. Kohler, T.A., G.J. Gumerman, and R.G. Reynolds, 2005, “Simulating Ancient Societies,” Scientific American 293:77−84. Macal, C., 2004, “Agent-based Modeling and Social Simulation with Mathematica and MATLAB,” in C.M. Macal, D. Sallach, and M.J. North, eds., Proceedings of the Agent 2004 Conference on Social Dynamics: Interaction, Reflexivity and Emergence, ANL/DIS-05-6, co-sponsored by The University of Chicago and Argonne National Laboratory, Oct. 7–9. Macal, C.M., and M.J. North, 2005, “Tutorial on Agent-based Modeling and Simulation,” in M.E. Kuhl, N.M. Steiger, F.B. Armstrong, and J.A. Joines, eds., Proceedings of the 2005 Winter Simulation Conference, Orlando, FL, Dec. Maeder, R.E., 2000, Computer Science with Mathematica, Cambridge University Press, Cambridge, UK. MathWorks, 2005, MATLAB home page; available at www.mathworks.com. North, M.J., and C.M. Macal, 2005, “Escaping the Accidents of History: An Overview of Artificial Life Modeling with Repast,” in A. Adamatzky and M. Komosinski, eds., Artificial Life Models in Software, Springer-Verlag: Dordrecht, Netherlands. Repast, 2005, Repast home page; available at http://repast.sourceforge.net/. Reynolds, C., 2005, Boids; available at www.red3d.com/cwr/boids/. Sallach, D., 2003, “Social Theory and Agent Architectures: Prospective Issues in RapidDiscovery Social Science,” Social Science Computer Review 21:179–195. Sallach, D., and C. Macal, 2001, “The Simulation of Social Agents: An Introduction,” Special Issue of Social Science Computer Review 19(3):245–248. Schelling, T.C., 1971, “Dynamic Models of Segregation,” Journal of Mathematical Sociology 1:143–186.

24

Paper extracted from Proceedings of the Agent 2005 Conference on Generative Social Processes, Models, and Mechanisms, ANL/DIS-06-5, ISBN 0-9679168-6-0, C.M. Macal, M.J. North, and D. Sallach (editors), co-sponsored by Argonne National Laboratory and The University of Chicago, October 13−15, 2005.

Tobias, R., and C. Hofmann, 2004, “Evaluation of Free Java-Libraries for Social-Scientific Agent Based Simulation,” Journal of Artificial Societies and Social Simulation 7(1), Jan. 31. Wolfram, S., 2003, The Mathematica Book: 5th Edition, Wolfram Media, Champaign, IL. Wolfram Research, Inc., 2005, Mathematica home page; available at www.wolfram.com.