scieee AI-readable full text Open interactive document viewer

MASSIS: Multi-agent system simulation of indoor scenarios

Pax Sánchez, Rafael

Abstract

Testing applications for smart environments is a difficult task. It requires the installation of sensors and actuators, the communications and the software for the control system, and the participation of people playing different scenarios. This is costly, both in economic sense as well as in time. Also, there are some situations that cannot be tested for practical reasons (such as emergencies). The use of simulation tools that provide some support for the development of smart environment applications is interesting, at least for these reasons. One of the most relevant aspects to be considered in this kind of tests is the human and social behavior of individuals when simulating how people interact with their environment, including other individuals. If the simulation framework has to be used for different purposes and by other developers, it should have a clear agent model, with some support for the design at a higher level of abstraction that can be easily translated to an implementation. This is the main purpose of MASSIS (Multi-agent system simulation of InDoor Scenarios), an efficient framework for modeling and simulation of the decision-making process of agents in multiple situations in indoor scenarios domain. It extends the SweetHome3D environment with plugins for linking agent’s behavior in the simulation. Other functionality provided by MASSIS is the ability to visualize the simulation in 2D and 3D, and a rich log capability, which can be the basis for further analysis of the scenarios.

Full text

MASSIS – Multi-Agent System Simulation of Indoor Scenarios– Rafael Pax [email protected] Grado en Ingeniería en Informática Facultad de Informática Trabajo de Fin de Grado Director : Juan Pavón Mestras [email protected] Madrid, Junio 2015 Authorization For Dissemination And Use Autorizo a la Universidad Complutense de Madrid a difundir y utilizar con fines académicos, no comerciales y mencionando expresamente a su autor, tanto la propia memoria, como el código, la documentación y/o el software desarrollado. Rafael Pax Gracias por ayudarme con tus consejos, por fortalecerme con tu apoyo, por levantarme con tus ánimos, por confiar en mí. Gracias por alegrarme con tus risas, por enamorarme con tu mirada, por contagiarme tu locura, por hacerme feliz. Gracias por ser maravillosa, Pilar. Acknowledgements This work has been been supported by the Government of the Region of Madrid through the research programme MOSI-AGIL-CM (grant P2013/ICE-3019, co-funded by EU Structural Funds FSE and FEDER), and by the Spanish Ministry for Economy and Competitiveness, with the project Social Ambient Assisting Living - Methods (SociAAL) (grant TIN2011- 28335-C02-01). Resumen Las pruebas de aplicaciones para entornos inteligentes son una tarea difícil. Requieren de la instalación de sensores y actuadores, los sistemas de comunicación, software de control y la participación de personas representando diferentes roles. Esto es costoso, tanto en tiempo como en sentido económico. Además, existen muchas situaciones que, por razones prácticas, resultan bastante complicadas de probar (situaciones de emergencia, por ejemplo). Las herramientas de simulación pueden servir de considerable ayuda para el desarrollo de entornos inteligentes. Uno de los aspectos más relevantes a tener en cuenta en este tipo de pruebas es el comportamiento humano y social de los individuos, cuando se simula la forma de cómo las personas interactúan con su entorno, incluyendo otros individuos. Si se utiliza un framework de simulación multiagente para estos propósitos, debe constar de un modelo claro de agente, cuyos métodos de razonamiento puedan ser diseñados desde un nivel de abstracción más alto, que pueda transformarse en una implementación de forma sencilla. Éste es uno de los propósitos principales de MASSIS (Multi-agent system simulation of InDoor Scenarios), un framework de simulación multiagente eficiente que permite el modelado y la simulación de los procesos de toma de decisiones de los agentes en múltiples situaciones en el dominio de espacios interiores. Extiende las capacidades de SweetHome3D con ciertos plugins que permitan definir el comportamiento de los agentes en el entorno de la simulación. Otras funcionalidades que ofrece MASSIS son las visualizaciones 2D y 3D de la simulación, la capacidad de guardar las simulaciones para su posterior reproducción y análisis. Palabras clave •Modelado basado en agentes •Modelo de decisión de agentes •Simulación de multitudes •Escenarios de interiores •Entornos inteligentes •Framework de simulación Abstract Testing applications for smart environments is a difficult task. It requires the installation of sensors and actuators, the communications and the software for the control system, and the participation of people playing different scenarios. This is costly, both in economic sense as well as in time. Also, there are some situations that cannot be tested for practical reasons (such as emergencies). The use of simulation tools that provide some support for the development of smart environment applications is interesting, at least for these reasons. One of the most relevant aspects to be considered in this kind of tests is the human and social behavior of individuals when simulating how people interact with their environment, including other individuals. If the simulation framework has to be used for different purposes and by other developers, it should have a clear agent model, with some support for the design at a higher level of abstraction that can be easily translated to an implementation. This is the main purpose of MASSIS (Multi-agent system simulation of InDoor Scenarios), an efficient framework for modeling and simulation of the decision-making process of agents in multiple situations in indoor scenarios domain. It extends the SweetHome3D environment with plugins for linking agent’s behavior in the simulation. Other functionality provided by MASSIS is the ability to visualize the simulation in 2D and 3D, and a rich log capability, which can be the basis for further analysis of the scenarios. Keywords •Agent-based modeling •Agent decision model •Crowd simulation •Indoor scenarios •Ambient Intelligence •Simulation Framework Table of Contents 1 INTRODUCTION.......................................................................1 1.1 MOTIVATION OF THE WORK......................................................................................1 1.2 OBJECTIVES...........................................................................................................3 1.3 METHODOLOGICAL APPROACH..................................................................................4 1.3.1 Conception Phase............................................................................4 1.3.2 Agile Development...........................................................................4 Two E-mails per day, meeting whenever possible...................................................................4 Fast sprints and short iterations.............................................................................................5 1.4 DOCUMENT ORGANIZATION......................................................................................7 2 SIMULATION OF SMART ENVIRONMENTS.........................8 2.1 AGENT-BASED MODELING AND SIMULATION TOOLS........................................................9 2.2 SIMULATION OF INDOOR SCENARIOS.........................................................................11 2.3 CONCLUSIONS.......................................................................................................11 3 MASSIS OVERVIEW................................................................13 3.1 FRAMEWORK........................................................................................................14 3.1.1 SweetHome3D................................................................................14 3.1.2 MASON........................................................................................17 MASON Model.....................................................................................................................17 MASON Visualization..........................................................................................................18 MASON Utilities..................................................................................................................18 3.1.3 Pogamut's POSH Engine................................................................19 3.1.4 Saving & Loading Simulations.........................................................20 3.1.5 Visualization..................................................................................21 3.1.6 StraightEdge..................................................................................22 3.2 BUILDING REPRESENTATION....................................................................................23 3.3 PATH FINDING.....................................................................................................25 3.3.1 Visibility Graph..............................................................................25 Obstacle merging..................................................................................................................26 Obstacle flattening...............................................................................................................27 Using SweetHome3D rooms as search areas.........................................................................28 3.4 ELEMENTS LOCALIZATION......................................................................................29 3.4.1 Hybrid data structure: : A PR QuadTree...........................................30 3.4.2 Bottom-Up Propagation QuadTree Implementation.............................32 Parent nodes.........................................................................................................................32 Child nodes..........................................................................................................................33 Element – List node map.....................................................................................................33 Inserting...............................................................................................................................34 Range Querying...................................................................................................................34 VII 3.5 STEERING BEHAVIORS............................................................................................35 3.6 AGENT DECISION MODEL......................................................................................39 3.6.1 MASSIS' GOAP Behavior Model prototype.......................................40 Action-Condition-Effect blocks.............................................................................................41 Behavior...............................................................................................................................43 Behavior stack......................................................................................................................43 Case study for this decision model : Killer – Prey................................................................44 3.6.2 MASSIS' behavior model: POSH Plans.............................................45 A library of Behavior modules..............................................................................................46 POSH Dynamic action selection scripts................................................................................48 Drive collections..............................................................................................................48 Competences...................................................................................................................49 Action Patterns...............................................................................................................49 Case Study for this decision model : Emergency Simulation................................................50 3.7 SAVING & LOADING SIMULATIONS...........................................................................53 3.7.1 Saving the simulation.....................................................................54 Using SQLite........................................................................................................................54 Using Plain Text..................................................................................................................54 Saving Disk Space................................................................................................................55 ZIP compression..............................................................................................................55 String substitution...........................................................................................................55 Using concurrency for speeding up the process....................................................................56 3.7.2 Simulation Playback.......................................................................57 3.8 VISUALIZATION.....................................................................................................58 3.8.1 3D Visualization............................................................................58 3.8.2 2D Visualization............................................................................59 Layer-Based Display.............................................................................................................59 MASSIS' built-in layers........................................................................................................60 4 GETTING STARTED WITH MASSIS.....................................61 4.1 INSTALLATION.......................................................................................................61 4.1.1 Downloading MASSIS.....................................................................61 Windows...............................................................................................................................62 MAC OS X...........................................................................................................................62 Linux & Unix.......................................................................................................................62 4.2 ENVIRONMENT CREATION........................................................................................62 4.2.1 Launching the environment editor....................................................62 4.2.2 Designing the environment..............................................................62 Creating & Editing walls......................................................................................................62 Adding doors, windows & furniture......................................................................................63 Importing 3D objects...........................................................................................................64 Drawing rooms.....................................................................................................................64 Adding levels........................................................................................................................64 4.2.3 Metadata Editor.............................................................................65 4.2.4 Teleport Linking.............................................................................65 VIII 4.2.5 Other MASSIS' Design Utilities.......................................................66 Designer tools.......................................................................................................................66 Name Generation.................................................................................................................67 4.2.6 Final notes....................................................................................67 4.3 SPECIFYING BEHAVIORS WITH REACTIVE PLANS..........................................................68 4.3.1 Installing Netbeans and Pogamut's yaPOSH editor.............................68 Downloading & installing Netbeans......................................................................................68 YaPOSH editor.....................................................................................................................68 4.3.2 POSH Plan creation.......................................................................69 Basic Behaviors Design.........................................................................................................69 4.3.3 Linking with SweetHome 3D & MASSIS...........................................69 4.4 SIMULATION.........................................................................................................69 4.4.1 Running a new simulation...............................................................69 4.4.2 Loading a saved simulation..............................................................70 4.4.3 Help..............................................................................................70 5 CONCLUDING REMARKS.....................................................71 5.1 CONCLUSION........................................................................................................71 5.2 FUTURE WORK....................................................................................................72 Integration of existing analysis tools....................................................................................72 Different AI behavior models................................................................................................72 Using a more powerful 3D engine.........................................................................................72 Distributed Computing........................................................................................................72 6 REFERENCES..........................................................................73 7 APPENDICES.............................................................................I IX 1 . Introduction 1.3 Methodological Approach Art and science have their meeting point in method. Edward G. Bulwer-Lytton For the development of this project, Agile software development principles were followed. Due to the small size of the team (1 person), and the nature of this project, an adaptation of these principles was needed. 1.3.1 Conception Phase The project started with an analysis phase. This phase was necessary because the team had no domain-specific knowledge. A basic understanding of the domain was needed in order to be capable of determine potential problems and needs. In this phase a very simple process was followed: •Meeting with the advisor once a week. •Definition of the goals that should be accomplished for the next week. •Writing down new ideas, and defining project objectives. 1.3.2 Agile Development The development of the project started on October, 2014. It was decided to use a simplified agile methodology, adapted to take into account that there were only two main participants: the student and the advisor. In order to facilitate high interaction between them, two communication mechanisms were used: emails and meetings. Two E-mails per day, meeting whenever possible In order to keep constant communication between the student and the advisor, and monitoring of project progress, every day in the morning, an e-mail was written to the advisor, explaining the expected goals to be accomplished that day. At the end of the day, 4 1 . Introduction an email containing a brief summary of the achievements of the day, the problems faced, and occasionally, a new idea to consider. Face-to-face communication is one of the pillars of agile development. Whenever the team and the advisor found time to meet, they met. There was not a fixed day, but usually was once a week. Fast sprints and short iterations Following Agile Principles require frequent deliveries of prototypes of useful products. But one of the main problems of a one man team is that few tasks can be done in parallel. Focusing on a single sprint at a time, and limiting the amount of work-in-progress provides a better project development. For that reason, the iterations were composed of different sprint types, each one lasting one week. Different types of sprints were designed: •Literature review sprints: These sprints were intended for learning about new frameworks, reading and summarizing research papers, in order to make the team capable of making more difficult tasks. During this sprints, it was very common the emergence of new ideas. These new ideas were classified with a priority. These types of sprints were made only if the results of the previous sprints were satisfactory. •Implementation sprints: These sprints focused on the implementation of the highest priority feature to implement at the moment. They were focused primarily on implementing the tasks defined before. •Testing sprints: They were focused on testing the functionality of the system, bug fixing and performance analysis. •System architecture review sprints: After implementation and testing of the new feature/goal, the overall system architecture is revisited, in order to maintain coherence. The system architecture review sprints had at least one face-to-face meeting with the advisor. Figure 1 shows the development work flow of the iterations. 5 1 . Introduction 6 Figure 1: Development methodology Are the tasks for accomplishing the goal known? Highest priority goal chosen Consider leaving it as "Future work" Is it the cost worthwhile? Update Goals & priorities Prototype Is the performance of the new feature an issue? YES NO YES Research & Estimation Literature review Divide goal into sub-tasks Has been developed a library/tool already? Is it Open source? Estimate Integration vs implementation from scratch cost Estimate implementation from scratch cost Write down new ideas for discussing with the advisor NO YES YES NO NO Implementation YES Testing Functionality testing performance analysis System architecture review performance analysis 1 . Introduction 1.4 Document Organization The rest of the document is organized as follows: •Section 2 reviews the state of the art, where the most relevant aspects, both theoretical and technological are discussed. In its first section, the main tools are reviewed, along with their different characteristics. The second delves into the simulation of indoor scenarios, highlighting the most important problems. Finally, the potential of multi-agent tools is shown, and the need for a tool like MASSIS is explained. •Section 3 Introduces the MASSIS (Multi-agent System Simulation of InDoor Scenarios) architecture and components. Special attention is given to the definition of the behavior of humans under different situations, which includes the process for decision making of the agents. Other relevant aspects to model are interactions among agents and with their environment, the events on the environment, and the precise representation of the building, logging capabilities and visualization. •Section 4 Explains how to get started with MASSIS, the installation, environment creation, behavior modeling and simulation. •Section 5 Presents the conclusions and future work 7 2 . Simulation Of Smart Environments 2 Simulation Of Smart Environments The business of art is to reveal the relation between man and his environment. D. H. Lawrence Smart Environments[2] can be defined as “a region of the real world that is extensively equipped with sensors, actuators and computing components” [3]. That is, a smart environment is aware of what occurs within it and its surroundings, adapting how it behaves to achieve certain objectives (e.g. making easier the lives of the inhabitants of a building). Previous works [4] have proposed the approach of viewing smart homes as intelligent agents, that perceive their environment through the use of sensors, and can act upon the environment through the use of actuators, agents that constantly adapt their behavior to the behavior of the environment itself. Besides of the smart environment design, one of the main problems that arises during the development of these kind of environments is their heterogeneity: the entities which inhabit the environment may be very different to each other, not known a priori and dynamic: may change over time. Although there have been several researches on this topic, such as [5]–[7], testing applications for smart environments continues being a difficult task. It requires the installation of sensors and actuators, the communications and the software for the control system, and the participation of people who have to play the different scenarios. This is costly, both in economic sense as well as in time. Also, there are some situations that cannot be tested for practical reasons (e.g., a fire, people accidents). 8 2 . Simulation Of Smart Environments Furthermore, from the point of view of the developers, who are used to iterative processes, it is difficult to repeat the tests if they have to perform these with persons. At least for these reasons is interesting to use simulation tools that provide some support for the development of smart environment applications. A relevant aspect to be considered in this kind of tests is the modeling of the behavior of humans under different situations. The behavior for these scenarios requires at least the following: interactions among agents, with the environment, and the process for decision making. Although many agent-based modeling and simulation tools exist, framework, not specifically oriented to smart environments. 2.1 Agent-based Modeling And Simulation Tools Nowadays, there are many software tools for implementing agentbased models. Although many of them are of general purpose, the selection of one or another depends on many factors, such as the scope and objective of the model to develop, the execution platform, documentation and ease of use, or the reusability of the code. One of the most influential software packages, which has served as inspiration to current platforms is Swarm [8], which began in 1994. The most widely used platforms are based on the Swarm philosophy, which is oriented towards to the framework and library paradigm. A framework that defines the concepts of agent-based modeling, including also the libraries needed for implementing the concepts proposed according to the framework. In general, simulation platforms follow the OO paradigm, where the framework defines the object in charge of building and controlling the simulation, as well as the objects responsible for the graphic elements management and the representation of the execution results, along with the scheduler system, which controls the execution of the events that trigger the methods defining the behavior of the agents. 9 2 . Simulation Of Smart Environments Repast[9] has been one of the Swarm based frameworks has been more successful. It started at the University of Chicago, being oriented to the social sciences domain. The first versions of Repast facilitated the designing of models for users without an extensive knowledge of software development, but the fundamentals of objectoriented programming, and knowledge about the Java programming language were required. Today, Repast continues its development at Argonne National Laboratory. The latest version, Repast Symphony [10], has evolved significantly. MASON[11], developed at George Mason University, appeared shortly after Repast, as a computationally efficient alternative. Although MASON is also based on the Swarm model, it shares with Repast many of aspects mentioned before. MASON increases the independence of the application domain of the models and enhances substantially those characteristics necessary in very demanding computer models, such as hardware independence, independence interfaces display and serialization. Netlogo [12] is another one of the most widespread platforms. It was developed at Northwestern University. Unlike Repast or MASON, it is based on its own high-level language (based on Logo, a Lisp dialect). One of the differences that Netlogo has over other libraries is that Netlogo is well documented and its library has many examples. Also, the programming style of Netlogo, which provides many primitives and simple construction of graphical interfaces, makes easier the learning process of the platform, especially for users without deep training in software development. Although it does not present the advantages of modularity and reuse of code that platforms based on more general-purpose languages, the ease of use and the ability to generate and share the models as executable applets in any browser that Netlogo has, has made it one of the tools most used for simple models. 10 2 . Simulation Of Smart Environments 2.2 Simulation Of Indoor Scenarios Several tools for simulation and design of how people behave in indoor scenarios exist (many of them commercial), such as [13]–[18], among many others. They focus on scalability issues derived from the management of a large number of agents in real time, specially when considering their visualization or the way the agents find their way while avoiding obstacles and other agents [19]. Specially in the last years, focus has been on very large numbers of agents. Different techniques have been proposed to cope with the scalability issues, by relying on specific assumptions of the problem under study. This has an effect on limitation of the flexibility of agents' behavior, which is quite homogeneous in most of the cases. Although they are appropriate to simulate specific scenarios, it is important to consider the human and social behavior of individuals when simulating how people interact with their environment, including other individuals. Other works have better addressed the specification of the agent behavior, such as [1], [20]–[25]. However, they have not sufficiently taken into account the methodological aspects for a design process when developing the agents' behavior. This is relevant when the simulation framework has to be used for different purposes and by other developers. In those cases, there is a need for a clearer agent model, with some support for the design at a higher level of abstraction that can be easily translated to an implementation. 2.3 Conclusions Agent-based modeling provides many advantages over other modeling paradigms. In general, the process of abstracting the details of the target system and implementing them unambiguously on a computer is much more direct than other methods of abstrac- 11 2 . Simulation Of Smart Environments tion. Therefore, the model is more transparent, which facilitates the understanding of the hypotheses assumed and the inclusion of knowledge of domain experts. The result of this ease of abstraction is reflected in many ways. For example, the variety in behavior of agents is enormous. Agentbased modeling allows to consider the effect of agents having limited rationality, or agents with ability to learn; from classic probabilistic mechanisms (such as reinforcement learning), to complex models from cognitive psychology (e.g endorsement systems). Or even one step further: The agents could create their own models of the world they perceive. The options are almost limitless. The relaxation of the assumptions of representative agents, having the ability to interact with the entire population, and an optimized behavior of a utility function (very common in many social sciences) is done almost directly using this paradigm. As have been stated in sections 2.1 and 2.2, there is a gap between general purpose libraries and specialized tools: Some are too open, while others are too specialized, or they do not fully integrate design, modeling and simulation. Taking this into account, this work proposes an agent-based model for indoor scenarios where both performance and flexibility in the behavior of the entities are sought. Agents are specified and managed individually, but the effects of the crowd are taken into account by several methods that take advantage of characteristics of the indoor domain in order to cope with the efficiency and scalability issues in the processing of their movements and their visualization. At the same time, some alternative reasoning mechanisms are provided for each agent in order to allow modeling of rich and heterogeneous behaviors. Our approach has been to adopt an agent-based modeling framework, Mason, and provide on this several components as a kind of plugins that facilitate the modeling and simulation of indoor scenarios. Mason has been chosen because it can be easily integrated as a Java library, it clearly decouples model from views, it is light and has an efficient scheduler. The component-based architecture of Mason is shown in the next chapter. 12 3 . MASSIS Overview 3 MASSIS Overview A complex system that works is invariably found to have evolved from a simple system that worked. John Gall MASSIS is a simulation framework for scenarios in indoor environments, allowing to design spaces, and specifying the behavior of the elements and people in them. These behaviors specifications may vary substantially: From a simple presence detector to human behavior. It is capable of supporting thousands of agents, each one with an specific behavior. The behavior specification is done outside the simulation platform. Although currently MASSIS provides only one behavior model (the POSH model, see section 3.1.3), others can be integrated, but this is left for further study. The simulation progress can be visualized in 3D, from different perspectives, or in 2D. The 2D visualization library is based on layers (the elements of each layer are drawn on top of the previous layer), making easier the development of a new type of visualization for specific purposes. Also, it allows to save the simulation changes, recording each agent state in every step of the simulation. These changes are saved in an open and independent format (JSON), allowing the analysis of the results from any other platform and language. Both MASSIS and its components are open source, allowing the extension of its functionality by third parties. 13 3 . MASSIS Overview In addition to this, the set of plugins for Netbeans developed by the Pogamut team include a POSH plan editor (Fig. 9). This plan editor helps with the AI development, allowing the parallel development of a higher-level abstraction AI and program code. 3.1.4 Saving & Loading Simulations Also, the simulation events can be logged in JSON format, as a single zipped file or in a SQLite database for further analysis. Once a simulation is performed, the exported data can be used to playback all events that have occurred during the execution of the simulation, i.e., the agents will behave in the same way they did during the simulation. 20 Figure 9: Integrated POSH Plan editor in Netbeans { "velocity": { "x": 32,"y": 58}, "visionRadio": 300, "maxforce": 10,"maxspeed": 15, "properties": {"steering.separation": 70,...}, "locationState":{ "angle": 0.7853982,"floorId": 8, "centerX": 4975.2285,"centerY": 4108.2695,...}, "id": 3673 } Listing 1: Example of an agent's saved state 3 . MASSIS Overview This is interesting to allow the users to review the simulation when analyzing what has happened. 3.1.5 Visualization All the changes made in the environment are reflected in real time by 3D (Figure 10 ) and 2D displays (Figure 11). Although 3D display is more realistic, the 2D view is useful for analysis and debugging. Also, the 2D visualization API allows the creation of user-defined layers in order to filter the different elements involved in the simulation. 21 Figure 10: Simulation 3D view Figure 11: Simulation 2D view example : Crowd Density 3 . MASSIS Overview 3.1.6 StraightEdge Of the open source libraries that are used in MASSIS, Straight- Edge[32] deserves an special mention. It is a powerful polygon library, that provides great functionality to MASSIS engine. It provides several geometric utilities, path-finding , field of vision and utility classes for converting StraightEdge polygons to Java Topology Suite (JTS)[33] polygons, allowing to perform more complex geometric operations, such as polygon flattening and shrinking, intersections and unions. Several modules of StraightEdge were extended in order to improve their efficiency (Pathfinding) or to add new functionalities (e.g. vector operations or SweetHome3D polygon transformations). 22 3 . MASSIS Overview 3.2 Building Representation Everybody at the party is a many sided polygon. Nonagon, They Might Be Giants. How the environment is represented is one of the key elements in any simulation framework, because this representation is the basis of all the simulation system. It is very important to choose an appropriate way to model the environment depending on the domain. For example, an environment can be modeled as a continuous space, a grid, or a graph. Or even a combination of these. The underlying structures chosen to model the environments depend on the level of desired in the application. It is very common in the indoor scenario domain that elements are very close from each other. Agents are not the only ones considered here; tables, chairs, cabinets, sinks, even flowerpots or radiators. Therefore, MASSIS opts for a representation of the building in which the space is not discretized in cells that are occupied by one 23 Figure 12: In MASSIS, almost every element is a polygon. 3 . MASSIS Overview element or another. Instead, each element has a position in three dimensions: (x, y, building-floor), and a polygon that represents it. This can be seen in Figure 12 , where everything is represented in a polygonal way: agents (green arrows enclosed by circles), doors (thin green rectangles), walls (black rectangles),rooms (gray areas), stairs,(contiguous red and green rectangles), vision areas,etc. An example that illustrates this need for a model of this type are doors. The width of the doors is a crucial factor in determining several aspects of the model, such as crowd congestion or pathfinding. The discretization level necessary to achieve the same results using uniform grids in a building with several floors with thousands of agents is somewhat prohibitive. As it will be explained in subsequent sections, the use of points with particular data structures to manage them efficiently, rather than uniform grids has many advantages. One of them is shown in Figures 13 and 14 . 24 Figure 13: Movement in a continuous space model Figure 14: Movement in a low-resolution grid In indoor scenarios, the use of a low-resolution grid may cause strange behaviors X 3 . MASSIS Overview 3.3 Path Finding If you find a path with no obstacles, it probably doesn't lead anywhere. Frank A. Clark Pathfinding is one of the issues that has more impact when simulating crowd behaviors. Some models treat the crowd as a single entity or a group in order to simplify the number of calculations, such as in [34]–[36]. However, MASSIS, as it has been stated in the introduction, has as objective to support flexibility in agent behavior, therefore the path finding model is implemented individually for each agent, but taking advantages of some assumptions from the problem domain in order to gain in efficiency. As it is explained in previous sections, the building model is represented on a continuous space. Therefore, it makes sense to follow this kind of design when developing a pathfinding module. If obstacles are represented as polygons, building a path through a visibility graph is a good approach. 3.3.1 Visibility Graph A Visibility Graph is a graph whose nodes correspond to geometric components, such as vertices or edges, and the nodes of this graph are connected only if there is not any obstacle intersecting the segment between those two points. Each edge of this graph represents a visible connection between those two points (They can see each other). In Figure 26 shows an example of a visibility graph. 25 3 . MASSIS Overview As all the elements present in the simulation have a polygon associated to them, this representation of the elements is very handy for the obstacles preprocessing step. This preprocessing step is done before the simulation starts, in order to gain computational speed during the simulation. The main reason for this preprocessing step is that some components of the building, such as walls, or stairs, are never going to move, so there's no reason to recompute the visibility graph of the building every time a path is requested. The preprocessing step consists basically of the following parts: Obstacle merging As MASSIS is intended for indoor scenarios simulations, some characteristics of this domain are exploited, such as the high frequency of wall intersection. Usually the end of a wall is connected with another. In Sweet- Home 3D representations, each wall is considered as an individual polygon. This is very useful for the building design stage, but when the number of polygons becomes important, it could become a problem. The way the walls intersect makes possible the reduction of the number of edges. (See Fig.16 ) 26 Figure 15: Visibility graph 3 . MASSIS Overview Obstacle flattening The geometry of the obstacles is expanded by an amount proportional to the bounding radius of the agents. This process is done in order to make generated paths more realistic, because the path is generated with the vertices of the expanded obstacle, not from the obstacle itself, so the path that the agent tries to follow is slightly separated from the obstacles vertices and edges. Fig. 17, shows an example of how an agent (blue smiley) should follow the generated path. Also, this operation helps to obtain faster the visible edges from any point, as will be shown in subsequent sections. 27 Figure 16: Reduction of number of edges. Figure 17: Expanded obstacle polygon 3 . MASSIS Overview Using SweetHome3D rooms as search areas One of the most basic parts of the building designing with SweetHome3D is room creation. The program provides a simple way for naming areas and coloring the floor. MASSIS takes advantage of this way that SweetHome3D has for representing the building for speeding up the algorithm. Assuming simple statements, such as: 1. The agent is always inside a room. 2. The target (goal) is always inside a room. 3. A path from Room A to Room B (being A and B different) must cross at least a door. Although these assumptions seem quite obvious, they make a great improvement in the execution speed of the algorithm. As the obstacle polygons are inflated, their accessible vertices from the inside lie now in the interior of the room shape. The most expensive operation in terms of computation time is the finding of the visible nodes (vertices) from the start and the goal of the path, because the rest of the visible connections between vertices is precalculated in advance, and the path finding between two nodes in a precomputed graph is done very quickly. For increasing the algorithm execution speed, the only nodes to be taken into account as starting / ending nodes are the ones inside the room boundaries containing the start point and the end point. In this way, most of the nodes and line segments are discarded, boosting the algorithm speed. 28 3 . MASSIS Overview 3.4 Elements Localization There's nowhere you can be that isn't where you're meant to be John Lennon. People, sensors and actuators need real time information about the elements that surround them. This implies that, during simulation, lots of query ranges must be performed. It is obvious that iterating over every element on a floor checking distances and intersections is not a good idea. So, there is a need for a data structure capable of holding the simulation elements, being somewhat efficient in data insertion, and retrieval. An intuitive way for storing the locations of the elements involved during the simulation is using uniform grids. However, these types of data structures are useful when the spatial data is distributed in an homogeneous way, which is rarely seen in MASSIS' simulations. Also, depending on the required accuracy, they can consume too many resources. Using uniform grids with an appropriate cell size can be a good approach to the problem. But determining the cell size is not an easy task, and it depends on many factors. If they are small, there will be only a few elements per cell but many cells to check. The opposite case is analogous. If the cell size is large, few cells must be checked but there would be many elements per cell. Another solution could be using QuadTrees [37]. QuadTrees are variable resolution data structures that could be used to retrieve the agent's neighbors within a radius in an efficient manner. This data structure is useful for querying ranges, but it does not perform as well as a uniform grid when inserting and deleting elements. Figure 18 shows an example of space partition using a QuadTree (Only half of it is shown). Given these facts, the question of which of the two data structures is best for MASSIS arises. Both of them have their respective advantages and disadvantages. Uniform grids are created once, 29 3 . MASSIS Overview Fig 23 illustrates these definitions with some examples (Seek and Flee, obstacle avoidance and Path Following). MASSIS provides a flexible implementation of several behaviors of this type(e.g. seek, arrival, separation, collision avoidance, wall containment, and path following), that can be grouped into more complex behaviors (like flocking or queuing,for example). Although there are several steering behaviors implemented in MASSIS, for illustration purposes, one variant of the collision avoidance between agents used in MASSIS will be described. In this example, the initial positions of two agents, a and b are defined by their x,y coordinates; (xa1, ya1) and (xb1, yb1) . If there is a collision, the point where each agent collides with the other one is defined by (xa2, ya2) and (xb2, yb2) (See Fig. 24). There exists a relation between them, defined by: 36 Figure 23: Some steering behaviors: Seek and Flee, obstacle avoidance and Path Following Figure 24: Collision avoidance between two moving agents 3 . MASSIS Overview Where t is the time that must pass before the collision occurs. The distance between them should be greater than the sum of their radius. In the time t, the distance between the two elements will be Solving for t, in the above equations, two values are obtained: t1 and t2 ( t2 is analogous to t1 ): The lowest value of t should be chosen, in order to obtain the nearest point of the future collision. An special case must be considered: if the value of t1 or t2 is negative, must be discarded (The agents are always moving forward). This is illustrated in Figure 25. The pseudo-code of this algorithm is shown in Listing 2. 37 3 . MASSIS Overview 38 Figure 25: Region division done by the two solutions of t function collisionAvoidance returns repulsionVector minT = Infinity; for Agent other in getAgentsInRange(agent) distance = distance(other,agent) d = agent.radius + other.radius t = getTimeToCollision(agent, other, d); if t > 0 and t < minT minT = t futureA = futureLocation(agent, t) futureO = futureLocation(other, t) repulsionVector = normalize(futureA – futureO) Listing 2: MASSIS' Collision Avoidance pseudo code 3 . MASSIS Overview 3.6 Agent Decision Model Desires dictate our priorities, priorities shape our choices, and choices determine our actions. Dallin H. Oaks The aspects of human behavior that are of interest for modeling indoor scenarios in the MASSIS framework are the mechanisms that humans use to deal with problems reasoning from context, making use of collective intelligence, and how this intelligence is used in problem solving. For that reason, each agent in MASSIS must have its own behavior, computed by some high-level decision model and executed by a low low level module (speed, position, angles, etc.). Modeling human behavior with agents have to consider two main aspects: those related with their perception and the interaction with the environment, and those dealing with the reasoning on the context and the decision making. They are implemented as lowlevel and high-level behavior components, respectively. When the high level component decides what to do next, the action is executed by the low-level component, which performs all the necessary operations. The relationship between these components is illustrated in Fig. 26. 39 Figure 26: Relationship between high-level and low-level modules HIGH LEVEL Reactive Plans Primitives (Actions, Senses) LOW LEVEL Position, line of sight, speed, angle, force, mass SteeringPath finding Perception MotionLocomotion Path following, alignment, queuing,separation, collision avoidance... 3 . MASSIS Overview Both high-level and low-level behaviors should be affected by the state of the agent, altering the decision making process (e.g. a scared agent may choose a different route to reach a target, probably a longer one). During the development of MASSIS, several ways for implementing agent's high-level behavior were considered, and some prototypes were made in order to test which of the different reasoning methods would fit better in this project. It is obvious that there is no clear winner in this area, so MASSIS infrastructure was designed in order to allow an easy integration of different types of AI modules. Due to time constraints, only one AI module has been fully implemented, but various prototypes based on different techniques were developed, such as Goal Oriented Action Planning. This last one deserves to be explained; if more time and resources were available, it would have been released with the MASSIS final version. 3.6.1 MASSIS' GOAP Behavior Model prototype GOAP (Goal Oriented Action Planning)[39], [40] proposes a way for action planning in real time for NPCs (Non-Player Characters) in videogames. It was used firstly in F.E.A.R[41], an AAA first person shooter released for PC in 2005. The planning system it's based partially on the STRIPS Planning [42], consisting on goals and actions. Goals describe some desired state of the world, and actions are defined in terms of preconditions and effects. The actions only can be executed if all its preconditions have been met, and every action changes the world in one way of another. The way for linking preconditions, actions and effects is done using A*, where the world states are the nodes of the graph and edges are the actions to reach them. The MASSIS GOAP Prototype was based in this idea. The main concepts are the following: 40 3 . MASSIS Overview 1. (Pre)Condition: Circumstance necessary and indispensable for an action to be carried out. 2. Action: “Do something”. It requires certain preconditions to be executed, and causes effects. 3. Effect: Impact or consequence of an action. It Adds or changes the real or perceived world. 4. World: The building. 5. Perception (Sense): Information managed by the agent, in relation with its environment. There are two types of Senses: Real / External senses and Internal senses. ◦Real / External senses: They are the real world facts perceived from the agent. For example: ▪“There are 5 items on that table” ▪“There is a fire on this room” ▪“Somebody is looking at me” ◦Internal senses: They are the things perceived from the internal world of the agent. Internal senses are the result of processing the External senses into something that exists only in the agent's mind. For example: ▪“There are a lot of items on that table” ▪“I am not comfortable in this room” ▪“That person makes me nervous” The preconditions are tightly coupled with perceptions, being in most cases the same. Action-Condition-Effect blocks Different actions can provoke the same effect(s), but different preconditions. For example, if the goal is to have a comfortable chair, different actions can achieve this goal: Action: Buy a chair (we omit the going-to-Ikea part) Condition: Have money. Effects: Have a comfortable chair. Have less money Action: Buy tools for making chairs. 41 3 . MASSIS Overview Condition: Have money. Effect: Have tools for making chairs. Have less money. Action: Borrow tools for making chairs from a friend. Condition: Have friends with tools of this type. Effect: Have tools for making chairs. And much more of these Action-Condition-Effect blocks should be necessary for giving the agent the ability of making a decent plan. Depending on the agent's perception of the world, this blocks are linked together dynamically, and a graph search is performed on the 42 Figure 27: Joined Action-Condition-Effect blocks Have a father with lots of money. Have low moral standards AND Be a not-so-good person Ask Dad for money Have Money AND Steal other people Buy wood Have Wood Create a chair Have a saw AND Have a chair Have friends owning wood-working tools Ask a friend for wood-working tools Buy wood-working tools Be willing to work AND Have a job work hard Personal satisfaction Buy a chair 3 . MASSIS Overview Action-Condition-Effect graph. Figure 27 shows a simple example of joining the preconditions with the actions and effects. Behavior In this context, a behavior is a set of actions that must be performed (ordered or not) in order to reach a goal. Basically, it consists on some conditions, which “fire” its activation and other conditions which invalidates them. Behaviors are ordered by priorities: Some events in the world change the way we behave: For most people, seeing a dinosaur coming changes their short-term priorities. An example of behavior priorities is illustrated in Figure 28. Behavior stack When a behavior becomes invalidated by some event, the agent must continue doing whatever it was doing. That is the reason why events in the environment do not replace the current behavior, they add it to a behavior stack. The agent always has on the bottom of its behavior stack the lowestpriority behavior. When an event forces the agent to change it, a new behavior is added on the top of the stack. If a firing condition of a lower level behavior is satisfied, that behavior is not added to the stack; it has a lower priority and shouldn't be taken into account. Figure 29 illustrates an example of the management of a behavior stack depending in the environment. 43 Figure 28: Behavior priorities in MASSIS' GOAP Variant Flee from fire behavior See fire Be safe Flee from fire Plan execution to reach main goal Get out of the building behavior Being safe Be free Get out of the building Plan execution to reach main goal Escape from dinosaur behavior See a dinosaur Be safe Flee from dinosaur Plan execution to reach main goal Priority #1Priority #2Priority #3 3 . MASSIS Overview Case study for this decision model : Killer – Prey For testing this decision model, a Killer – Prey scenario was modeled. In this scenario, three roles were present: 1. Killer : Wants to kill every agent marked as Prey, but for killing a prey a Knife is needed. If it does not see any prey agent, wanders around. 2. Prey: Wanders around until it sees a Killer. When a Killer its seen by a Prey, this last one flees as fast as possible. 3. Knife: A simple knife. Can be taken by a Killer, and they are distributed through the building. For making the simulation more interesting, a knife can be used only once. 44 Figure 29: Behavior stack changes due to events in the environment Behavior stack Get out of the building Fire appears Behavior stack INSERT [Escape from fire] Get out of the building A dinosaur is seen Behavior stack INSERT [Flee from dinosaur] Escape from fire Get out of the building Dinosaur slips and falls from a window Behavior stack INVALIDATE [Flee from dinosaur] Escape from fire Get out of the building Behavior stack Escape from fire Get out of the building Suppose that the "Escape from fire" behavior does something to extinguish the fire Behavior stack INVALIDATE[Escape from fire] Get out of the building Figure 30: Killer – Prey Prototype screenshot 3 . MASSIS Overview Listing 3 shows part of the trace of the simulation, and Figure 30 shows an screenshot of it. The red agent is the killer, the yellow ones the preys, and the blue dots are knifes. 3.6.2 MASSIS' behavior model: POSH Plans While the method described above looks promising, the development and testing of it would have taken too much time. Therefore, it was decided to use a more mature behavior model, well known and tested: POSH[43] (Parallel-rooted, Ordered Slip-stack Hierarchical) dynamic plans. The architecture of this behavior follows the BOD (Behavior Oriented Design) method[43], [44]. This method for building agents combines the advantages of Behavior Based AI[45], [46] and objectoriented design approaches. In MASSIS this is applied to facilitate the design of agents that are capable of running in parallel and of generating a behavior that can satisfy multiple objectives that may conflict with each other. One of the main issues while designing an autonomous agent is that many of the goals that the agent wants to be accomplished 45 ============Begin Planning============ Initial state : {isPreyKilled=0.0, NumberOfKilledPeople=0.0, NumberOfKnifesVisible=0.0, isPreyVisible=0.0, NumberOfPreysVisible=0.0, isKnifeVisible=0.0, isAlive=1.0, isPerson=1.0} Available Actions : [TakeKnife, WanderAround, KillPreyAction, SearchKnife, SearchPrey] Planning for goal [WanderFinished:==1.0] -------------------------------------- Actions : [WanderAround] ============End Planning============ [STATE]Executing Action The perceived environment has changed, forcing a change on the agent behaviour. Firing condition: [isPreyVisible:==1.0] /* A prey was seen */ Current behaviour: Behaviour [Kill Prey Behaviour] Behaviour stack: [Behaviour [Wander around], Behaviour [Kill Prey Behaviour]] /* Behavior added to the stack */ [STATE]idle - Replanning next goal ============Begin Planning============ Initial state : {isPreyKilled=0.0, NumberOfKilledPeople=0.0, NumberOfKnifesVisible=0.0, isPreyVisible=1.0, NumberOfPreysVisible=1.0, isKnifeVisible=0.0, isAlive=1.0, isPerson=1.0} Available Actions : [TakeKnife, WanderAround, KillPreyAction, SearchKnife, SearchPrey] Planning for goal [isPreyKilled:==1.0] -------------------------------------- Actions : [SearchKnife, TakeKnife, SearchPrey, KillPreyAction] ============End Planning============ [STATE]Executing Action Action SearchKnife Finished. WorldState : {isPreyKilled=0.0, NumberOfKilledPeople=0.0, NumberOfKnifesVisible=1.0, isPreyVisible=1.0, NumberOfPreysVisible=3.0, isKnifeVisible=1.0, isAlive=1.0, isPerson=1.0} [STATE]Executing Action Action SearchKnife Finished [STATE]Executing Action [STATE]Executing Action Action TakeKnife Finished Action SearchPrey Finished. WorldState : {isPreyKilled=0.0, NumberOfKilledPeople=0.0, HasKnife=1.0, NumberOfKnifesVisible=1.0, isPreyVisible=1.0, NumberOfPreysVisible=1.0, isKnifeVisible=1.0, isAlive=1.0, isPerson=1.0} [STATE]Executing Action Action SearchPrey Finished [STATE]Executing Action /* Prey was stabbed */ The perceived environment has changed making the actual behaviour(Behaviour [Kill Prey Behaviour]) invalid. /*Prey is now dead and there is not any other visible*/ [STATE]idle - Replanning next goal Listing 3: MASSIS' GOAP Case study trace 3 . MASSIS Overview 52 Figure 36: Teacher going to the door Figure 38: Teacher going to take the nearest chair Figure 39: The students follow the teacher for escaping from the building. Figure 37: The students proceeding to close the windows. 3 . MASSIS Overview 3.7 Saving & Loading Simulations I think you can learn from history. Chuck Norris Although MASON provides a way for saving simulation states, it does not provide a way for storing some kind of record of the entire simulation. That's the reason why a new module for saving and loading the simulation results was developed. Two ways for saving simulations were considered when developing MASSIS: Java Serialization format and a plain-text format. •Java serialization: ◦Good points: ▪Easy implementation ▪If it is done carefully, the disk space used is relatively small. ◦Bad points: ▪It has high dependence from the codebase ▪Makes very difficult analyzing the simulation results from other platform/language. •Plain text: ◦Good points: ▪It can be parsed by any platform and language ▪It is human-readable ◦Bad points: ▪Can use high amounts of disk space ▪A custom parser is needed, and also an specification of the file format. ▪Making changes in the codebase may imply rewriting too much code, if everything is done “by hand”. 53 3 . MASSIS Overview Balancing the advantages and disadvantages of these two ways for storing the simulation timeline, the second approach (Plain – Text) was chosen, but using JSON (JavaScript Simple Object Notation)[47] as file format. JSON is a well known text format, suitable for storing object definitions. For logging the simulation state to this format, an extension of the well-known Gson [48] library, Gson on Fire [49] was used. It serializes the object attributes into JSON format, and also provides several utilities for solving typical issues when doing these things (e.g. circular references). 3.7.1 Saving the simulation The simulation changes can be saved directly in a (zipped) text file, or in a SQLite [50] database. Using SQLite SQLite was chosen because is a very portable database format. The database contains only 3 fields: <object-id>,<step-id>,<object-state>. <object-id> it's the simulation object unique id, <step-id> the time-step of the simulation and <object-state> is the actual state of the simulation object. The main advantage of this way of storing the simulation results is that making a simple select statement, all the changes that the agent made during simulation can be retrieved (See Listing 7). Although this is not a bad approach, the number of records in the table grows very quickly, and its file size has an extra overhead regarding the pure-plain-text approach. Using Plain Text Much more simple than the SQLite option: one line per step, containing the elements that changed in that step. Very fast to 54 select simulation_object_id, max(step_id), simulation_object_state from simulation_log where step_id < DESIRED_STEP group by simulation_object_id Listing 7: SQLite query to retrieve the changes made by an element of the simulation. 3 . MASSIS Overview write and to playback forward (but not backwards, that option is better with the SQLite approach). Saving Disk Space JSON is a compact text format (compared with XML). The file size can be reduced considerably, if some methods are applied. ZIP compression Applying ZIP compression to the simulation results reduces notoriously its file size: up to 75%. If the simulation results are saved into a SQLite database, the database must be compressed after, but if they are saved directly into a file, the stream can be compressed “on the fly” (That is, less space consumed overall). String substitution Although the ZIP compression achieves good results, some optimizations can be made in order to decrease even more the file size. Listing 8 shows an example of an agent state in a concrete simulation step. Blue strings are repeated with a very high frequency (they are object attributes, or class names). Attributes like “velocity” are common to every movement-capable agent, e.g. a person. If the 8 55 { "velocity": { "x": 1, "y": 1 }, "visionRadio": 300, "maxforce": 10, "maxspeed": 15, "properties": { "steering.alignment": 5, "isPrey": 1, "steering.separation": 70, "steering.followpath": 25, //... }, "locationState": { "angle": 0.7853982, "floorId": 8, "centerX": 4975.2285, "centerY": 4108.2695, "type": "SimLocationState" }, "id": 3673, "type": "AgentClassNameState" } Listing 8: Un-compressed agent state in JSON format. 3 . MASSIS Overview characters that “velocity” has can be substituted by something shorter, the overall size of the simulation results file would be considerably smaller. The keys (representing object attributes), and frequent string values (such as class names) can be replaced by a shorter string, something like a number preceded by an special character that serves as indicator, like “@”. But, why a number? Instead of a number can be an alphanumeric character, so, instead of working in base 10, we are working in base 62. Listing 9 shows how the agent state is represented after this “reduction” process. It is obvious that some kind of extra information must be stored in order to be capable of reverting the process. So, a mapping array must be saved together with the simulation results. An example of this mapping array is shown in Listing 10. Using concurrency for speeding up the process I/O operations are costly. As every simulation step implies writing to disk (if saving is enabled), the execution speed of the simulation can be reduced significantly. MASSIS uses an extra thread for writing this information. A synchronized queue is used as writing buffer. Every step, the infor- 56 { "@D": { "x": 1, "y": 1 }, "@E": 300, "@F": 10, "@G": 15, "@H": { "@6": 5,"@7": 1,"@8": 70,"@9": 2, "@A": 25,...}, "@I": { "@0": 0.7853982, "@1": 8, "@2": 4975.2285, "@3": 4108.2695, "@5": "@4" }, "id": 3673, "@5": "@J" } Listing 9: String substitution in an agent's saved state. [ ["@0","angle"],["@1","floorId"], ["@2","centerX"],["@3","centerY"], … ] Listing 10: Array mapping key alias with actual keys 3 . MASSIS Overview mation about the changes is pushed into the queue. The writing thread is continuously taking elements from the queue and writing that information to disk. In this way way, the impact of I/O operations is lower. 3.7.2 Simulation Playback A simulation playback is the reverse process mentioned above: The data is loaded from the file, and applied to the simulation objects. The way for doing this is fairly simple: If the simulation is started in Playback mode, the proper step() method of the agent is not called. Instead, the information retrieved from the simulation file is loaded into the agent, changing its properties directly. 57 3 . MASSIS Overview 3.8 Visualization You must see first before you can believe. Raymond Holliwell The visualization of what's happening during the simulation is one of the most important parts for any simulation framework. Although MASON provides good support for this, it is more oriented to grid-based models, and adapting the MASON display modules to meet the requirements of MASSIS entailed more work than creating a new display system. MASSIS visualization is composed in two parts: 3D visualization and 2D visualization. The 3D visual interface is more suitable for having a realistic view of the building, and what is happening inside, but the 2D display is more useful for testing and debugging the model. Also, it is easier to the programmer to extend and manage. 3.8.1 3D Visualization The 3D view is based on SweetHome 3D integrated view. It shows the building and the elements inside it in the same way that SweetHome 3D does, but some modifications must have been made in order to make it faster for displaying the model in real-time. That is because SweetHome3D is intended for being used as a home-design program, not as a simulation model display. Sweet- Home 3D it has been designed using a MVC pattern, and has lots of event listeners that are executed when an element of the building is changed. 58 3 . MASSIS Overview Although that's a good way for structuring an application like this, it's not needed for MASSIS. In addition, it is not thread safe. The events listeners were removed, and also some intermediate layers, in order to gain execution speed. MASSIS architecture accesses straightforward to the 3D modules, avoiding intermediate calculations. Figure 40 shows an example of MASSIS' 3D visualization. 3.8.2 2D Visualization Layer-Based Display MASSIS' 2D display is based on layers. Each layer can be designed independently, and it is intended for displaying the simulation in an schematic view. 59 Figure 40: MASSIS' Real-Time 3D Visualization Figure 41: MASSIS' Layer Selector 3 . MASSIS Overview Layers are drawn one on top of each other, following an order. They can be ordered, enabled and disabled. Listing 11 shows the code needed for one of the most basic layers: Walls. Figure 41 shows how the layers can be enabled or disabled directly from the GUI, from an user-friendly checkbox list. MASSIS' built-in layers MASSIS comes with several basic built-in layers, for showing rooms, doors, agents, radios, paths, pathfinding utilities...etc. Figure 42 shows a combination between the obstacle layer, agents layer, agent's radius layer, pathfinder layer,walls layer,rooms layer and doors layer. However, new layers can be designed without modifying the simulation engine. 60 public class WallLayer extends FloorMapLayer { public WallLayer(boolean enabled) { super(enabled); } @Override protected void draw(Floor floor, Graphics2D g) { g.setColor(Color.GREEN); for (SimWall wall : floor.getWalls()) g.fill(wall.getPolygon()); } @Override public String getName() { return "Walls"; } } Listing 11: Example of one of the most basic MASSIS' layers: Wall Layer. Figure 42: Layer combination example 4 . Getting started with MASSIS 4 Getting Started With MASSIS The secret of getting ahead is getting started. Mark Twain 4.1 Installation 4.1.1 Downloading MASSIS MASSIS can be downloaded from its main repository, https://github.com/rpax/MASSIS. The dependencies of the project have been managed with Maven, making easier the dependency management. For getting MASSIS and all its dependencies: 1. Download maven (https://maven.apache.org/download.cgi) 2. Clone MASSIS repository (or download it as a zip file) 3. generate MASSIS executable using Maven: mvn clean install 4. This should generate a zip file (MASSIS.zip) containing the executable jar file and all its dependencies. Some of the dependencies of the project aren't in any public maven repository (such as SweetHome3D). To solve this issue, a release tag has been created, containing these required libraries and MASSIS' plugins jar file. The contents of libs.zip must be placed under the folder rpax.tfg. The url of this tag is https://github.com/rpax/MASSIS/releases/tag/v1.0 The installation process of MASSIS is minimal. In fact, if the environment designer is not needed, it does not require installation at all. For using MASSIS' SweetHome3D plugins, the MASSIS plugin file (rpax.tfg.sh3d.plugins.metadata.MASSISMetadataPlugin.jar) must be 61 4 . Getting started with MASSIS 4.3 Specifying Behaviors With Reactive Plans 4.3.1 Installing Netbeans and Pogamut's yaPOSH editor Although POSH reactive plans can be designed by hand, it is much easier to do it graphically. Pogamut's plugins for Netbeans help to this task, integrating in the IDE a graphical plan editor. Note: This is only a suggestion for a faster development of POSH Reactive plans, it is not necessary for running or extending MASSIS. Downloading & installing Netbeans The Pogamut's plugin interesting for MASSIS is the POSH plans graphical designer (yaPOSH editor). It is developed for the Netbeans platform (sorry, eclipse lovers!), so a recent copy of Netbeans (7.3+) should be obtained. This can be done through Netbeans download page [51]. Also, Java JDK 1.6+ is also needed (It can be downloaded bundled with Netbeans, check the options in the download page). YaPOSH editor The Pogamut's yaPOSH editor comes with the Pogamut UT2004 installer. This installer can be downloaded from Pogamut download page [52]. The latest stable version is recommended (Fig 53). The installation is fairly simple, but in case of any trouble the Pogamut's download page has detailed information about the installation steps. 68 4 . Getting started with MASSIS 4.3.2 POSH Plan creation Basic Behaviors Design A good tutorial about how to create SPOSH plans with Pogamut can be found at : http://pogamut.cuni.cz/pogamut_files/latest/doc/tutorials/ch14s03.html 4.3.3 Linking with SweetHome 3D & MASSIS Using MASSIS metadata editor, the behavior of each agent can be specified in the fields planfile and classname. Figure 48 can serve as an example. The value of the planfile field must be relative, never absolute (As will be explained later, the location of the resources folder is a parameter of MASSIS launcher). 4.4 Simulation 4.4.1 Running a new simulation For running a simulation, the parameter run-as must have as value SIMULATOR. In addition, as every simulation (despite the type of it) meeds a building file, this should be provided also. The parameter build- 69 Figure 53: Pogamut Platform download page 4 . Getting started with MASSIS ing-path, tells MASSIS where is the building. The number of steps desired can be provided. If they are not, the simulation runs in an infinite loop. The parameter simulation-mode should be SIMULATION. For logging the simulation results into a file, the parameter save-simulation-to (optional) should contain a valid path for dumping the simulation timeline. java -jar MASSIS.jar --run-as=SIMULATOR –building-path \ <BUILDING_PATH> --run-for <STEPS> --simulation-mode SIMULATION \ --save-simulation-to <SIMULATION_RESULTS_FILE> The desired way of displaying the simulation progress (graphically or by console) should be specified with the display parameter (GUI or CONSOLE). 4.4.2 Loading a saved simulation For playing a previous saved simulation, the value of the parameter simulation-mode must be PLAYBACK and also, the parameter load-simulation-from should be provided. java -jar MASSIS.jar --run-as=SIMULATOR –building-path \ <BUILDING_PATH> --run-for <STEPS> --simulation-mode PLAYBACK \ --load-simulation-from <SIMULATION_RESULTS_FILE> 4.4.3 Help The MASSIS launcher contains a help with a brief explanation of these parameters mentioned before. Calling MASSIS with the argument -help shows all the parameters available and their explanation. 70 5 . Concluding remarks 5 Concluding Remarks It's more fun to arrive a conclusion than to justify it. Malcolm Forbes 5.1 Conclusion This work has presented MASSIS, a multiagent-based simulation framework that supports the decision making process of humans when solving problems. This is achieved by simulating each agent individually, but with the support of several methods and efficient data structures that take advantage of particularities of the indoor domain. The creation of the environments is done by SweetHome 3D, with some extensions for linking agent's behavior in the simulation. Agent behavior is structured in low-level and high-level behavior components, extending Pogamut’s POSH implementation model, with the addition of features that facilitate the separation of decision making process and low level actions. MASSIS provides a rich set of low-level behavior components for the simulation of indoor scenarios. This has required to MASSIS the extension of the SweetHome3D environment with plugins for linking agent’s behavior in the simulation. In order to apply MASSIS to other kind of scenarios (e.g., a city), new low-level behavior components should be implemented and integrated with another graphical design package that supports the definition of the new environment. In this sense, MASSIS can be easily extended. MASSIS provides as well a rich log capability, which can be the basis for further anal- 71 5 . Concluding remarks ysis of the scenarios. The extensibility of the MASSIS platform is well supported through its component based architecture. For instance, different visualizations can be managed during the simulation, new algorithms and agent attributes can be supported and monitored. 5.2 Future Work MASSIS framework is only in its beginning, and we believe has huge potential. In the next version of the framework, there will be many updates to the framework. The most relevant are shown below. Integration of existing analysis tools One of the most relevant issues in the next version of MASSIS will be the integration of existing analysis tools, in order to make this framework more independent and useful. Different AI behavior models It is interesting to add new, different reasoning models, in order to test different approaches. Using a more powerful 3D engine Although SweetHome3D is good for this initial version of MASSIS, there are better alternatives (such as Jmonkey Engine [53]), with which more realistic results can be obtained. Distributed Computing Another feature that is being considered is making MASSIS capable to run over cluster and cloud-computing architectures. Since MASSIS runs over MASON, and there is a version of MASON designed to run in parallel (D-MASON [54]), it would be relatively easy to implement it, and it would add more value to MASSIS. 72 6 . References 6 References [1] E. Serrano and J. Botia, “Validating ambient intelligence based ubiquitous computing systems by means of artificial societies,” Information Sciences, vol. 222, no. 0, pp. 3 – 24, 2013. [2] D. Cook and S. Das, Smart environments: Technology, protocols and applications, vol. 43. John Wiley & Sons, 2004. [3] P. Nixon, S. Dobson, and G. Lacey, “Managing Smart Environments,” in Proceedings of the Workshop on Software Engineering for Wearable and Pervasive Computing, 2000. [4] D. J. Cook, M. Youngblood, E. O. Heierman III, K. Gopalratnam, S. Rao, A. Litvin, and F. Khawaja, “MavHome: An agent-based smart home,” in 2013 IEEE international conference on pervasive computing and communications (PerCom), 2003, pp. 521–521. [5] J. C. Augusto and C. D. Nugent, Designing smart homes: the role of artificial intelligence, vol. 4008. Springer Science & Business Media, 2006. [6] S. K. Das and D. J. Cook, “Designing smart environments: A paradigm based on learning and prediction,” in Pattern Recognition and Machine Intelligence, Springer, 2005, pp. 80–90. [7] A. Omicini, A. Ricci, and G. Vizzari, “Building smart environments as agent workspaces,” in Enabling Technologies: Infrastructure for Collaborative Enterprises, 2007. WETICE 2007. 16th IEEE International Workshops on, 2007, pp. 92–97. [8] D. Hiebeler, “The swarm simulation system and individual-based modeling,” 1994. [9] N. Collier, “Repast: An extensible framework for agent simulation,” The University of Chicago’s Social Science Research, vol. 36, p. 2003, 2003. [10]M. J. North, N. T. Collier, J. Ozik, E. R. Tatara, C. M. Macal, M. Bragen, and P. Sydelko, “Complex adaptive systems modeling with repast simphony,” Complex Adaptive Systems Modeling, vol. 1, no. 1, pp. 1–26, 2013. [11]S. Luke, C. Cioffi-Revilla, L. Panait, K. Sullivan, and G. Balan, “Mason: A multiagent simulation environment,” Simulation, vol. 81, no. 7, pp. 517–527, 2005. 73 6 . References [12]U. Wilensky, “NETLOGO itself: NetLogo,” Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, http://ccl. northwestern. edu/netlogo, 1999. [13]Legion, “Science in Motion.” [Online]. Available: http://www.legion.com. [14]M. Owen, E. R. Galea, and P. J. Lawrence, “The EXODUS evacuation model applied to building evacuation scenarios,” Journal of Fire Protection Engineering, vol. 8, no. 2, pp. 65–84, 1996. [15]PedGo, “TraffGo HT.,” 2006. [Online]. Available: http://www.traffgoht.com/de/pedestrians/products/pedgo/index.html. [16]M. MacDonald, “STEPS,” 2009. [Online]. Available: http://www.steps.mottmac.com/. [17]Thunderhead Engineering, “Pathfinder,” 2006. [Online]. Available: http://www.thunderheadeng.com/pathfinder/. [18]Golaem, “Golaem Crowd: Artist-Driven Crowd Simulation,” 2011. [Online]. Available: http://www.thunderheadeng.com/pathfinder/. [19]M. Schuerman, S. Singh, M. Kapadia, and P. Faloutsos, “Situation agents: agent-based externalized steering logic,” Computer Animation and Virtual Worlds, vol. 21, no. 3–4, pp. 267–276, 2010. [20]L. Saîfi, A. Boubetra, and F. Nouioua, “Approaches to Modeling the Emotional Aspects of a Crowd,” in Modelling and Simulation (EUROSIM), 2013 8th EUROSIM Congress on, 2013, pp. 151–154. [21]T. Bosse, M. Hoogendoorn, M. C. Klein, J. Treur, C. N. Van Der Wal, and A. Van Wissen, “Modelling collective decision making in groups and crowds: Integrating social contagion and interacting emotions, beliefs and intentions,” Autonomous Agents and Multi- Agent Systems, vol. 27, no. 1, pp. 52–84, 2013. [22]Massive Software, “Simulating Life,” 2002. [Online]. Available: http://www.massivesoftware.com/. [23]S. Wu and Q. Sun, “Computer simulation of leadership, consensus decision making and collective behaviour in humans,” PloS one, vol. 9, no. 1, 2014. [24]A. C. Bicharra, N. Sánchez-Pi, L. Correia, and J. M. Molina, “Multiagent simulations for emergency situations in an airport scenario,” ADCAIJ: Advances in Distributed Computing and Artificial Intelligence Journal, vol. 1, no. 3, pp. 69–73, 2013. [25]R. Hocevar, F. Marson, V. Cassol, H. Braun, R. Bidarra, and S. R. Musse, “From their environment to their behavior: a procedural approach to model groups of virtual agents,” in Intelligent Virtual Agents, 2012, pp. 370–376. [26]E. Puybaret, “Sweet Home 3D,” 2005. [Online]. Available: http://www.sweethome3d.com/. 74 6 . References [27]J. Gemrot, R. Kadlec, M. Bída, O. Burkert, R. Píbil, J. Havlíček, L. Zemčák, J. Šimlovič, R. Vansa, M. Štolba, and others, “Pogamut 3 can assist developers in building AI (Not only) for their videogame agents,” Agents for Games and Simulations, pp. 1–15, 2009. [28]Epic Games, “Unreal Tournament 2004.” [Online]. Available: http://liandri.beyondunreal.com/Unreal_Tournament_2004. [29]Epic Games, “UE2 Runtime.” [Online]. Available: http://wiki.beyondunreal.com/Unreal_Engine_2_Runtime. [30]Epic Games, “UDK Documentation.” [Online]. Available: https://www.unrealengine.com/previous-versions/documentation. [31]Introversion Software, “Defcon: Everybody Dies.” [Online]. Available: http://www.introversion.co.uk/defcon/. [32]K. Woodward, “straightedge - 2D polygon library for games.” [Online]. Available: https://code.google.com/p/straightedge/. [33]V. Solutions, “JTS Topology Suite,” 2015. [Online]. Available: http://www.vividsolutions.com/jts/JTSHome.htm. [34]A. Treuille, S. Cooper, and Z. Popović, “Continuum crowds,” ACM Transactions on Graphics (TOG), vol. 25, no. 3, pp. 1160–1168, 2006. [35]J. Shopf and A. GPG, “Crowd Simulation in Froblins.” [36]J. Moersch and H. Hamilton, “Hybrid Vector Field Pathfinding.” [37]R. A. Finkel and J. L. Bentley, “Quad trees a data structure for retrieval on composite keys,” Acta informatica, vol. 4, no. 1, pp. 1–9, 1974. [38]C. W. Reynolds, Steering behaviors for autonomous characters, vol. 1999. 1999. [39]J. Orkin, “Symbolic representation of game world state: Toward realtime planning in games,” in Proceedings of the AAAI Workshop on Challenges in Game Artificial Intelligence, 2004, vol. 5. [40]J. Orkin, “Agent Architecture Considerations for Real-Time Planning in Games.,” in AIIDE, 2005, pp. 105–110. [41]Monolith Productions, “F.E.A.R.,” 2005. [Online]. Available: http://en.wikipedia.org/wiki/F.E.A.R. [42]R. E. Fikes and N. J. Nilsson, “STRIPS: A new approach to the application of theorem proving to problem solving,” Artificial intelligence, vol. 2, no. 3, pp. 189–208, 1972. [43]J. J. Bryson, “The behavior-oriented design of modular agent intelligence,” in Agent technologies, infrastructures, tools, and applications for e-services, Springer, 2003, pp. 61–76. [44]J. J. Bryson, “Intelligence by design: principles of modularity and coordination for engineering complex adaptive agents,” 2001. 75 6 . References [45]R. A. Brooks, “A robust layered control system for a mobile robot,” Robotics and Automation, IEEE Journal of, vol. 2, no. 1, pp. 14–23, 1986. [46]R. A. Brooks., “Intelligence without reason,” The artificial life route to artificial intelligence: Building embodied, situated agents, pp. 25–81, 1995. [47]Ecma-international.org, “Standard ECMA-404,” 2015. [Online]. Available: http://www.ecmainternational.org/publications/standards/Ecma-404.htm. [48]Google, “google-gson - A Java library to convert JSON to Java objects and vice-versa - Google Project Hosting.” [Online]. Available: https://code.google.com/p/google-gson/. [49]Julio Viera, “julman99/gson-fire,” 2015. [Online]. Available: https://github.com/julman99/gson-fire. [50]Sqlite.org, “SQLite Home Page,” 2015. [Online]. Available: https://www.sqlite.org/. [51]netbeans.org, “Netbeans download page,” 2015. [Online]. Available: https://netbeans.org/downloads/index.html. [52]P. Platform, “Pogamut Platform download page,” 2015. [Online]. Available: http://diana.ms.mff.cuni.cz/main/tiki-index.php? page=Download. [53]M. Powell, “JMonkey Engine,” Avaliable in: http://www. jmonkeyengine. com, 2008. [54]G. Cordasco, R. De Chiara, A. Mancuso, D. Mazzeo, V. Scarano, and C. Spagnuolo, “A framework for distributing agent-based simulations,” in Euro-Par 2011: Parallel Processing Workshops, 2012, pp. 460–470. 76 7 Appendices Appendix I: Rafael Pax, Juan Pavón: Agent-based Simulation of Crowds in Indoor Scenarios. 9th International Symposium on Intelligent Distributed Computing (IDC'2015), Guimaraes (Portugal), 7-9 oct. 2015 (accepted for oral presentation and full publication) E-mail of the notification acceptance: Subject: IDC'2015 notification for paper 20 From: "IDC'2015" <[email protected]> Date: 05/22/2015 05:49 PM To: Rafael Pax <[email protected]> Dear Rafael Pax, We are glad to inform that your submission Agent-based Simulation of Crowds in Indoor Scenarios was accepted for Oral Presentation at the 9th International Symposium on Intelligent Distributed Computing (IDC'2015) and for publication as a Full Regular Paper (max 10 pages) in the IDC'2015 Conference Proceedings. You can consult the detailed reviews at the end of this message. The Conference Proceedings will be edited by Springer in a volume of the Series Studies in Computational Intelligence. In a few days we will send you a separate message with instructions on how to prepare and submit the camera-ready version of your paper. The deadline for submitting is June 19th, 2015. All accepted papers must be presented orally at the Conference. At least one author for each accepted paper must register for the Conference. The strict deadline for author registration is June 19th, 2015. On behalf of the IDC'2015 organization team, thank you for submitting your work. We look forward to seeing you in Guimarães next October. Best regards, David Camacho Paulo Novais I