Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Exploring Agent-Based Modeling: A Case Study using RepastPy, Repast Simphony, and breve, Papers of Physics

The development and visualization of increasingly sophisticated agent-based models using toolkits repastpy, repast simphony, and breve. Simple network-interaction diagrams, boids 3d flock simulation, 3d collision and gravity system, chaotic gray scott diffusion reaction, and a complex boids evolutionary swarm simulation. The document also discusses the impact of technological advancements on problem-solving capabilities and the principles of bounded rationality, interactivity, mobility, and adaptation in agent-based modeling.

Typology: Papers

Pre 2010

Uploaded on 07/30/2009

koofers-user-7rl
koofers-user-7rl 🇺🇸

10 documents

1 / 30

Toggle sidebar

Related documents


Partial preview of the text

Download Exploring Agent-Based Modeling: A Case Study using RepastPy, Repast Simphony, and breve and more Papers Physics in PDF only on Docsity! Agent-based Modeling Adam Getchell Department of Physics University of California, Davis acgetchell@ucdavis.edu June 9, 2008 Abstract The theory and practice of agent-based modeling is reviewed, and agent-based modeling toolkits are evaluated and discussed. A tractable selection of toolkits, RepastPy, Repast Simphony, and breve are then employed to develop and visualize a series of increasingly sophisticated agent-based models, starting with a simple network-interaction diagram and proceeding onto the Boids 3D flock simulation, a 3D collision and gravity system, the chaotic Gray Scott diffusion reaction, a sophisticated agent behaviors game of Capture the Flag, finally culminating with an complex Boids evolutionary swarm simulation. To accomplish the latter, genetic programming techniques are briefly reviewed. Finally, an overview is presented with future directions. INTRODUCTION The use of computer systems to solve problems of interest in physics, biology, chemistry, economics, and social sciences has been well-established for decades. The great advances in computing power, software development, computer graphics, communications networks, and a host of other technologies have elevated the domain of applicability to problem solving from simple arithmetic calculations to advanced numerical methods and the creation of large simulations solving myriad systems of complex equations in real-time. A recent development has been the introduction of the Agent-Based Modeling paradigm, which has proven useful for a wide range of problems in physics and chaotic attractors [1], biology [2], economics [3], social science [4], and geospatial simulations [5]. Commensurate with this new paradigm has been the development of a range of toolkits to apply Agent-Based modeling to a particular range of problems. This purpose of this paper is to provide a general introduction to Agent-Based modeling and demonstrate its use in the modeling of a chaotic system. Organization is as follows: Section I begins with a general discussion of Agent-Based Modeling (hereafter ABM), including definitions and characteristics of systems amenable to this approach. Section II will provide an up-to-date review of the various Swarm modeling toolkits currently available at this time of writing. Section III will show the use of a particular toolkit, Repast, using both the simplified RepastPy interface and the more complex RepastS integrated development environment (IDE), and cover the development of a simple swarm model. Section IV will cover the simulation of the chaotic system ______, and Section V will wrap-up with conclusions and further references. SECTION I - OVERVIEW Following the general overview by Castle and Crooks [6] and elsewhere [7], a dynamic model is defined as a simplified representation of reality that evolves over time. The unstated art behind this method is the intuition/experience in creating a simulation that is sufficiently complex enough to show interesting dynamics of the system, while being simple enough to have a tractable software representation on a computing system. In particular, “dynamics” is defined in as the study of change and evolving systems [8], while “tractable” is an artifact of the particular tool used. As we shall see, ABM makes particular classes of problems very easy to solve, that would otherwise be very difficult to attack using more traditional dynamical methods. For the purposes of this paper, an Agent, as part of an ABM system, is defined with the following characteristics:  Activity: Each agent independently acts according the rules of the simulation and their own pre- programmed behaviors. These rules and behaviors can take one or more of the following features: o Goal-direction: The agent acts in such a way as to achieve a particular goal, which can be either a relative or extremal value. For example, an agent may be designed to maximize accumulation of a particular resource. o Reactivity/Perceptivity: The agent senses its surroundings, or is supplied with a map such that it is aware of its environment. For example, an agent could be aware of resource node locations. o Bounded Rationality: Generally, goal-direction in agents operates on the rational-choice principle, which generally implies unlimited access to information and computational resources. However, experimental evidence suggests that non-optimal decisions are often closer to reality. Therefore, in order to provide greater predictive power, the agents can be constrained in terms of information resources or analytical ability. For example, an agent might be able to sense only those resource nodes within a finite range, or possess a map of resources that does not take into account the actions of other agents. o Interactivity: Continuing on the principle of bounded rationality, agents may interact or exchange information with other agents. These interactions may have particular effects on the agent, including its destruction or change in goal-seeking behavior. o Mobility: Interactivity with the environment and other agents is vastly improved if the agent can roam the model space independently. o Adaptation: Alteration of an agent’s current state based upon interactions with the environment or other agents provide a useful form of learning or memory. This adaptation can be provided for at the level of the individual agent, or groups of nearby agents, all the way up to the population level of the entire set of agents .  Autonomy: Each agent is free for activity as defined above, with the ability to make independent decisions. written against the .NET 1.1 runtime, and appears not to have been updated since. The software source code contains project files which are not compatible with later versions of Visual Studio (Visual Studio 2008 was tried), and so extensive troubleshooting to correct this issue was skipped in favor of using other versions of Repast. Repast Simphony is the latest version of Repast, combining the powerful Eclipse integrated development environment with automated connectors to additional tools such as R, VisAD, Weka, MATLAB, and iReport. This paper will showcase both RepastPy and Repast Simphony. MetaABM is a powerful agent-based modeling system written by Miles Parker and including a neutral, standards-based representational format using the Eclipse Modeling Framework. MetaABM also features a powerful GUI environment based on Eclipse which can export models to other environments, including Repast Simphony and Ascape (another Swarm successor). SECTION III – RESULTS – REPAST, REPASTPY, REPAST SIMPHONY, AND BREVE All toolkits and software listed above, with the exception of Swarm (due to the existence of newer systems) and NetLogo (due to its Logo foundations) were installed and run using two machines: a Dell D830 Laptop with 2.4 GHz Core 2 Duo with 4GB of RAM, and a MacBook running MacOSX 10.5.3. Repast was initially designed to meet the needs for ABM in social sciences , including the use of geographic information systems. Repast Simphony offers a more robust toolset for 2 and 3D lattice simulations in the physical sciences. Repast was chosen for several reasons:  Ability to use several languages (Python, Java, .NET)  Quality of documentation  Quality of Repast Simphony IDE o Currently uses Groovy, a dynamic language for the Java Virtual Machine that compiles to Java byte-codes, but offers features like Domain-Specific Language support, annotations, generics, and meta-programming. [26] o Ability to “freeze-dry” simulations. Models can be run, serialized to a flat file structure (similar to Python’s pickle), and then re-hydrated to pick up where the simulation left off on a different system. o Built-in support for the export of data to movies, VisAd (interactive visualization toolkit) [27], Weka (machine learning toolkit) [28], or MatLab.  Currency of Implementation – In particular, Simphony installs on current versions of operating systems such as Windows Vista. (Although RepastPy must run as Administrator, which presents issues of file storage in that the user must be able to access the same directory used by the Administrator to save the model, and the default Documents directory is the Administrators’ Document directory, hence inaccessible to the typical user. Likewise, networked user directories are unavailable to the Administrator without an explicit network share.) Given the heavy Python use in current class work, the first model chosen was done using RepastPy. However, RepastPy quickly showed limitations in the original design slant towards social science modeling. For example, only 2D grids could be generated. Nevertheless, a nicely illustrative network simulation model showing agent based interactions was created and run in a very short time. Figure 1: RepastPy network model setup screen Figure 2: RepastPy agent actions behavior using Python scripting if (self.getNumOutEdges()): otherAgent = (TutorialThreeAgent)self.getRandomNodeOut() otherWealth = otherAgent.getWealth() if (otherWealth > self.wealth and otherWealth > 2): self.wealth = self.wealth + 2 otherAgent.setWealth(otherWealth - 2) else: self.removeEdgesTo(otherAgent) otherAgent.removeEdgesFrom(self) self.makeRandomOutEdge(self.model.getAgentList(), DefaultDrawableEdge(), false) else: self.makeRandomOutEdge(self.model.getAgentList(), DefaultDrawableEdge(), false) self.setNodeLabel(String.valueOf(self.wealth)) /** * * Import the needed packages. * */ import java.io.* import java.math.* import java.util.* import javax.measure.unit.* import org.jscience.mathematics.number.* import org.jscience.mathematics.vector.* import org.jscience.physics.amount.* import repast.simphony.context.* import repast.simphony.context.space.continuous.* import repast.simphony.context.space.gis.* import repast.simphony.context.space.graph.* import repast.simphony.context.space.grid.* import repast.simphony.engine.environment.* import repast.simphony.engine.schedule.* import repast.simphony.engine.schedule.* import repast.simphony.engine.watcher.* import repast.simphony.groovy.math.* import repast.simphony.integration.* import repast.simphony.matlab.link.* import repast.simphony.parameter.* import repast.simphony.random.* import repast.simphony.space.continuous.* import repast.simphony.space.gis.* import repast.simphony.space.graph.* import repast.simphony.space.projection.* import repast.simphony.ui.probe.* import simphony.util.messages.* import static java.lang.Math.* import static repast.simphony.essentials.RepastEssentials.* /** * * This is an agent. * */ public class BoidsAgent { /** * * This is an agent property. * @field xyAngle * */ @Parameter (displayName = "XY Angle", usageName = "xyAngle") public double getXyAngle() { return this.xyAngle } public void setXyAngle(double finalValue) { this.xyAngle = finalValue } public double xyAngle = 0 /** * * This is an agent property. * @field xzAngle * */ @Parameter (displayName = "XZ Angle", usageName = "xzAngle") public double getXzAngle() { return this.xzAngle } public void setXzAngle(double finalValue) { this.xzAngle = finalValue } public double xzAngle = 0 /** * * This is an agent property. * @field speed * */ @Parameter (displayName = "Speed", usageName = "speed") public double getSpeed() { return this.speed } public void setSpeed(double finalValue) { this.speed = finalValue } public double speed = 0 /** * * This value is used to automatically generate agent identifiers. * @field serialVersionUID * */ private static final long serialVersionUID = 1L /** * * This value is used to automatically generate agent identifiers. * @field agentIDCounter * */ protected static long agentIDCounter = 1 /** * * This value is the agent's identifier. * @field agentID * */ protected String agentID = "BoidsAgent " + (agentIDCounter++) /** * * This is the family finding behavior. * @method findFamily * */ @ScheduledMethod( start = 0d, priority = -1.7976931348623157E308d, shuffle = true ) public void findFamily() { // Note the simulation time. def time = GetTickCountInTimeUnits() // Use the Repast Simphony Groovy math tools. use (MathOperations.mathCategories()) { // Find the 3D space Context context = FindContext("Boids") ContinuousSpace space = (ContinuousSpace) context.getProjection("Space") setXyAngle RandomDraw(0, 2 * Math.PI) setXzAngle RandomDraw(0, 2 * Math.PI) setSpeed RandomDraw(-2, 2) // Make a decision. for (neighbor in (new repast.simphony.query.space.continuous.ContinuousWithin(space, this, 25).query())) { // Link to neighbors CreateEdge("Boids/Family", this, neighbor, 1.0) CreateEdge("Boids/Friends", this, neighbor, 1.0) } // Exit this scope. return } // End the method. return } /** * * Move Behavior * @method move * */ @ScheduledMethod( start = 1d, interval = 1d, shuffle = true As can be seen from a comparison of Figure 4 and Figure 5, model building with the GUI is easier. Finally, here are the visual results of the Boids simulation compiled as a Java/Repast application, with the model data initialized. Note the connecting lines between Boids represent affinity (either Friend or Relative) with other agents in the simulation. Figure 6: Boids model with network graph representing affinity between various Boids. MetaABM – After encountering the various Repast Simphony issues, MetaABM looked like a nice, elegant solution. It suffered some of the same types of Eclipse issues as Repast Simphony, as MetaABM is actually loaded on top of Repast (as it can emit models for use with the Repast framework). Getting a working version could only be done using the all-in-one bundled distribution, which then suffered maintenance issues with Eclipse itself. The model building is very heavily GUI oriented, which is a disadvantage when subtle bugs were discovered in the documentation (e.g., the basic test model would not actually work). Troubleshooting these issues meant taking screenshots of the GUI and posting them to a discussion board, which ironically had quite severe limits on both the data and pixel size of graphics. In the end, MetaABM required too much setup/troubleshooting time, and to complete work on time efforts focused on other toolkits. Breve – The author wishes to have found this earlier. Although the modeling is strictly a 3D simulation for multi-agents (hence lacks some of the more sophisticated network or more general mathematical models that can be done with Repast), what it does it does well. Scripts can be separately loaded, in a proprietary scripting language, steve, or much better, using Python (though only v2.3 at present). Scripting environment limited compared to other Python IDEs, but it is efficient in loading. Breve has some limitations. As mentioned, it is only suitable for 3D modeling. It also has certain magic methods, init() and iterate() that must be called to initialize agents and perform actions. Unlike Repast, you cannot set variable steps to do actions, they always happen each time. To get around computational issues, there is a separate post-iterate() method. Figure 7: Basic breve controller/agent model structure using Python Figure 8: Basic breve controller/agent model structure using steve import breve class HelloWorld( breve.Control ): def __init__( self ): breve.Control.__init__( self ) def iterate( self ): print '''Hello, world!''' breve.Control.iterate( self ) breve.HelloWorld = HelloWorld # Create an instance of our controller object to initialize the simulation HelloWorld() @include "Control.tz" Controller HelloWorld. Control : HelloWorld { + to iterate: print "Hello, world!". super iterate. } On the plus side, it supports model serialization to XML, and networking to other servers. This allows a web interface to a breve simulation, using a very simple RESTful type method calls: http://myserver:<port>/set-agent-color_.2_.4_.6 Breve has a nice intuitive user interface, and comes with dozens of models with viewable source code. The UI is slightly more powerful on MacOS X due to inclusion of a Cocoa application which allows one to view and edit model settings for particular agents on the fly; this capability is not available in other versions of Breve. Documentation on the system is extensive, but the best form of documentation is the models themselves, which mostly come in both steve and Python versions for inspection. As mentioned, the text editor is serviceable but somewhat limited; it is possible to edit files in other programs, although they aren’t able to be developed in breve by a simple save settings and run inherent with the basic editor. Still, breve was extremely powerful, easy to learn, and productive – a refreshing contrast to most of the other systems. The author was able to modify most of the simulations to save movie clips of the resulting runs with very little effort If the model being developed is best represented using a 3D graphical display, breve is probably the best tool for the job. Future versions of breve will concentrate on the use of Python as the standard modeling language going forward. As can be seen from a comparison of Figure 7 and 8, at present steve has an advantage in brevity and expressiveness. At last, onto doing some actual modeling! The first model shows the action of gravity and 3D collisions upon a randomly generated collection of spherical agents. # Note: this file was automatically converted to Python from the # original steve-language source code. Please see the original # file for more detailed comments and documentation. import breve class Gravity( breve.PhysicalControl ): def __init__( self ): breve.PhysicalControl.__init__( self ) self.theBall = None Gravity.init( self ) def init( self ): self.setIntegrationStep( 0.000100 ) breve.createInstances( breve.Step, 1 ).create( breve.vector( - 0.500000, 0, 0 ), breve.vector( 1.000000, 0.020000, 1 ) ) breve.createInstances( breve.Step, 1 ).create( breve.vector( 0.200000, -0.200000, 0 ), breve.vector( 0.200000, 0.020000, 1 ) ) Figure 11: Gray Scott mathematical model # Note: this file was automatically converted to Python from the # original steve-language source code. Please see the original # file for more detailed comments and documentation. import breve class GS( breve.Control ): def __init__( self ): breve.Control.__init__( self ) self.U = None self.V = None self.cube = None self.delta = None self.deltareact = None self.inflow = None self.texture = None GS.init( self ) def init( self ): n = 0 m = 0 self.setBackgroundColor( breve.vector( 1, 1, 1 ) ) self.setIterationStep( 1.000000 ) self.setIntegrationStep( 1.000000 ) self.pointCamera( breve.vector( 0, 0, 0 ), breve.vector( 0, 0, 70 ) ) self.U = breve.createInstances( breve.Matrix2D, 1 ) self.V = breve.createInstances( breve.Matrix2D, 1 ) self.inflow = breve.createInstances( breve.Matrix2D, 1 ) self.delta = breve.createInstances( breve.Matrix2D, 1 ) self.deltareact = breve.createInstances( breve.Matrix2D, 1 ) self.U.setSize( 128, 128 ) self.V.setSize( 128, 128 ) self.delta.setSize( 128, 128 ) self.deltareact.setSize( 128, 128 ) self.inflow.setSize( 128, 128 ) self.texture = breve.createInstances( breve.MatrixImage, 1 ) self.texture.initWith( self.U, 1.000000 ) self.texture.setRed( self.V ) self.texture.setBlue( self.U ) self.cube = breve.createInstances( breve.Mobile, 1 ) self.cube.setShape( breve.createInstances( breve.Cube, 1 ).initWith( breve.vector( 400, 400, 1 ) ) ) self.cube.setTextureImage( self.texture ) self.cube.setTextureScale( 40 ) n = 0 while ( n < 128 ): m = 0 while ( m < 128 ): self.U.setValue( ( ( 0.500000 + breve.breveInternalFunctionFinder.sqrt( self, breve.length( ( 0.250000 - ( ( 0.010000 * ( 1.000000 + ( 0.040000 / 0.010000 ) ) ) * ( 1.000000 + ( 0.040000 / 0.010000 ) ) ) ) ) ) ) + ( 0.020000 * ( breve.randomExpression( 1.000000 ) - 0.500000 ) ) ), m, n ) self.V.setValue( ( ( ( 1.000000 - self.U.getValue( m, n ) ) / ( 1.000000 + ( 0.040000 / 0.010000 ) ) ) + ( 0.020000 * ( breve.randomExpression( 1.000000 ) - 0.500000 ) ) ), m, n ) self.inflow.setValue( 0.010000, n, m ) m = ( m + 1 ) n = ( n + 1 ) def iterate( self ): self.deltareact.copy( self.U ) self.deltareact.multiplyWithValues( self.V ) self.deltareact.multiplyWithValues( self.V ) self.delta.computePeriodicDiffusionMatrix( self.U, 0.078000 ) self.delta.addValues( self.deltareact, -1.000000 ) self.delta.addValues( self.U, ( -0.010000 ) ) self.delta.addValues( self.inflow ) self.U.addValues( self.delta, 1.000000 ) self.delta.computePeriodicDiffusionMatrix( self.V, 0.022000 ) self.delta.addValues( self.deltareact ) self.delta.addValues( self.V, ( -( 0.040000 + 0.010000 ) ) ) self.V.addValues( self.delta, 1.000000 ) breve.Control.iterate( self ) breve.GS = GS # Create an instance of our controller object to initialize the simulation GS() Figure 12: Python source code for Gray Scott simulation Figure 13: breve Gray Scott simulation. Note, a video of this model has been generated and is available at the following location: http://insecure.ucdavis.edu/Members/adam/physics The third model examined was a fairly sophisticated agent behavior simulation playing the game Capture the Flag. Breve has a separate section dedicated to the programming and development of sophisticated winning strategies for this game, which involves the following simple rules: 1. Ten agents per side The main trick is to devise programs that actually produce changeable behaviors in the agents, so they can be selected for or against. In breve, one can do a sophisticated version of the Boids simulation, using evolving swarms and the following additional rules:  Seek out food, which randomly teleports around  Feed their friends with excess food  Reproduce when energy (food) hits certain threshold  Die when they run out of energy, or reach maximum age  Land on the ground, rest, fly around again  Mutate in such a way as to improve/reduce reproduction The breve model initially starts off with 10 Boids, which reproduce and die according to the given rules above. After 6000 iterations, the simulation stops, although depending upon the state of the model this takes an extended amount of time. Repeated runs of the model showed widely varying results in Boid populations; some models capped at 10 (the default model auto-generates a new Boid whenever the count drops below 10), or zero when the auto-growth code was removed. Other models generated flocks of 50, 60, 100, 200 or more Boids with high levels of “evolution”. In general, this is quite a sophisticated simulation that would be incredibly difficult to reproduce via other means. In the author’s opinion, this evolving swarms really demonstrate the utility and value of agent-based modeling and toolkits. Figure 15: Evolving Boid swarms using breve Again, due to the size of the simulation, source code will not be explicitly detailed in this paper. However, it is available for inspection in breve, and a video of this model has been generated and is available at the following location: http://insecure.ucdavis.edu/Members/adam/physics SECTION IV – CONCLUSION This paper has explored the theory and practice of agent-based modeling and tools. The toolkits themselves were found to be, at the time of this writing, of varying degrees of usefulness and power, and their use generated a greater-than-anticipated learning curve during the development of this paper. Agent-based modeling toolkits are subtle and sophisticated, and the freely available ones involve quite a bit of setup, fine-tuning, and tinkering before even a single line of model code is written. The modeling frameworks evaluated all used open-source languages and libraries, usually either Java or Python, though Python was preferred for its simplicity, expressiveness, and ease of use. Particular toolkits had decided advantages depending upon the type of simulation desired. For 3-D modeling, breve was far and away the best tool in terms of setup, ease of use, and sophistication of agent behaviors. For network and grid models with visualization of non spatio-temporal data, Repast Simphony was the best solution evaluated, though not without a steep learning curve and setup issues. Finally, for prototyping of network/grid models (which could be redone in a more complex tool), RepastPy was the clear winner. Future work entails the development of specific breve and Repast models in the author’s area of interest, particularly modeling of 4D general relativity.
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved