Using object-oriented programming to develop simulation models of animal aggregation. Anissa Kennedy, Shubha Shrestha, and Steven V. Viscido Department of Biological Sciences, Winston-Salem State University, Winston-Salem, NC, USA Containment INTRODUCTION • Animal social behavior is often studied using computer simulation models. • Ordinarily, computer models are implemented using procedural programming (e.g., Warburton and Lazarus 1991, Huth and Wissel 1992, Romey 1996). Properties • Characteristics of procedural programming: • Based around variables and functions. • Emphasizes solving specific problems. • Modifications are increasingly difficult as the program grows. Methods • Object-oriented programming is used much less commonly to study animal aggregations. Inheritance Figure 2: A UML diagram showing the relationships among the classes. Inheritance is indicated by arrows (RomeyFish inherit properties and methods from the Flocker class). Containment is indicated by straight lines (Animal objects contain RadioTransmitter objects). • Characteristics of object-oriented programming (Miles and Hamilton 2006, Wiesfeld 2008): • Based around discrete objects. • Each object has its own state and procedures. • Modularity allows easy modification regardless of program size. MODEL DESIGN AND • There was a strong difference in population dispersion and group movement between homogeneous and heterogeneous populations (Figure 6). • • We used the following steps in designing our object-oriented model: • Step 1: We identified all the object classes needed for the model. • A class contains all the computer code for a particular kind of object. • Example: The “Flocker” class (Figure 1). • All animals that form groups (i.e., “flocks” or “herds”) belong to this class. To demonstrate the usefulness of the object-oriented approach, we performed simulations under two conditions (Figure 3). – Condition 1: 60 identical fish objects all following the movement rules from Romey (1996). – Condition 2: 60 fish objects following three different movement rules from Romey (1996), Huth and Wissel (1992), and Warburton and Lazarus (1991) (20 of each). • • Step 4: We specified the relationship between non-related object classes. • Containers – objects that store other objects. • Containers keep track of data inside them. • Example: Animal objects contain “radio transmitter” objects. Models were otherwise run using identical parameters – 10 replicates of each condition – 500 time steps of 1 second each – A starting area 100 body lengths (BL) in diameter – Constant velocity (1 BL/s) – Model-specific parameters are listed in Figure 4 WARBURTON AND LAZARUS • Step 5: We used object-oriented data storage. • Rather than store data in a flatfile, we stored data on the objects themselves. • “Radio Transmitter” objects: • Stored inside each animal object. • Record all data for a simulation. • Statistics are stored on a “statistics” object. • All data were stored as Matlab objects: • Allowed easy access to the data – no data conversion is required. HOMOGENEOUS POPULATION HETEROGENEOUS POPULATION HUTH AND WISSEL Figure 7: Mean expanse (squared distance to center, in Body Lengths) and polarity (1 = perfectly aligned) for our simulated fish populations. LEFT: Results for a population of 60 individuals using just the Romey (1996) model. RIGHT: Results for a mixed population of 20 using Romey (1996), 20 using Huth and Wissel (1992), and 20 using Warburton and Lazarus (1991). Black lines indicate means. Red lines indicate +/- 1 S.D. ROMEY CONCLUSIONS (B) GOOD PATH DETECTION Figure 4: shows the parameters under which the objects could operate. • Object-oriented design allowed mixed populations of organisms using different models for movement. • Heterogeneous and heterogeneous populations behaved in different ways. • Further research into groups of non-identical organisms is needed to understand the role of individuality in group behavior. • We used our object-oriented computer model to generate the results (Figure 5) Figure 5: The main User Interface for the Object Oriented computer model. • Figure 1: Flocker.m: An example class file. This class is a subclass of Prey, and contains two properties and two methods. • The model’s outcome depended greatly on both the algorithm used and the makeup of the population (homogeneous vs. heterogeneous). Figure 3: Animal configuration tool. The number of individuals of each class is shown. • Step 2: We defined the properties and methods for each class. • Properties are data stored on the object (e.g., position and velocity). • Methods are algorithms implemented by the object (e.g., the Movement Rule). • An object stores its states as properties and exhibits its behaviors through the methods. • Example: The Flocker class (Figure 1 ). • Step 6: We created a global simulation script to execute the model. • The script simply tells each object to execute its movement rules. • Objects are responsible for their own movement (position, velocity, collision-avoidance, etc.). • The heterogeneous population produced groups that were both more spread out (Figure 7, expanse), and more polarized (Figure 7, polarity) than the homogeneous population model. SIMULATION METHODS DEVELOPMENT • Step 3: We specified the relationships among related object classes (Figure 2). • Methods can be inherited by “child” objects. • Allows classes to inherit commonly used behaviors. • Example: RomeyFish, a subclass of Flocker, inherits the Movement Rule method (Figure 1, 2). RESULTS • Object-oriented design allowed for quick, efficient model implementation. • Due to these benefits, we developed a new simulation model of animal aggregation using objectoriented programming. Goal: The goal of this project is to use object-oriented programming to develop a useful tool for behaviorists interested in modeling the factors influencing animal behavioral patterns. Figure 6: Sample movement trails of individuals in a homogeneous population (LEFT) and a heterogeneous population (RIGHT). On the right, Red trails indicate fish following the Romey (1996) model. Blue trails indicate fish following the Huth and Wissel (1992) model. Green trails indicate fish following the Warburton and Lazarus (1991) model. We computed two example aggregation statistics – Expanse (mean squared distance to group centroid per group per time step) – Polarity (mean angle deviation of each individual velocity vector from the group’s velocity vector) • We scaled polarity so that perfect alignment =1 and traveling in opposite directions = 0 • Object-oriented design is an efficient way to tackle the problem of individuality. REFERENCES • Huth, A. and Wissel, C. 1992. The simulation of the movement of fish schools. Journal of Theoretical Biology 156:365-385. • Miles, R. and Hamilton, K. 2006. Learning UML 2.0. O’Reilly Media Inc. Sebastopol, CA. 290 pp. • Romey, W. L. 1996. Individual differences make a difference in the trajectories of simulated schools of fish. Ecological Modelling 92:65-77. • Warburton, K. and Lazarus, J. 1991. Tendency-distance models of social cohesion in animal groups. Journal of Theoretical Biology 150:473-488. • Wiesfeld M. 2008. The object-oriented thought process. 3rd edition. Addison-Wesley. Upper Saddle River, NJ. 330 pp. ACKNOWLEDGMENTS We thank the many individuals who assisted in the completion of this project. Winston Hill and Denise Lea assisted with various aspects of the project. Dr. Nick Hristov provided many useful suggestions during model development. Partial funding was provided to Anissa Kennedy by the Summer Undergraduate Research Experience (SURE) program at WSSU (funded by NSF Grant #0927905 to the WSSU Department of Chemistry). Primary funding was provided by NSF grant IOS-1149302 to Dr. Steven Viscido.