AgentSimJS: A Web-based Multi-agent simulator with 3D capabilities Tobia Calenda, Massimiliano De Benedetti, Fabrizio Messina, Giuseppe Pappalardo, Corrado Santoro University of Catania – Dept. of Mathematics and Computer Science Viale Andrea Doria, 6 — 95125 - Catania, ITALY {m.debenedetti,messina,pappalardo,santoro}@dmi.unict.it Abstract—This paper describes the architecture of The paper is structured as follows. Section II discusses AgentSimJs, a web-based multi-agent simulator written in related work. Section III contains a detailed description of the Javascript. The simulator is capable to render a 3D scene architecture of the simulator. Section IV briefly describes a with objects and agents and allows the programmer to arrange case study in order to highlight the capabilities of the simulator. simulations by specifying the behavior of agents. The architecture Finally, Section V reports the conclusions. of AgentSimJs is highly modular, as several different components have been designed to enrich the simulator with the desired functionalities. AgentSimJs also has the capability of distributing II. R ELATED WORK the simulation among different machines and/or different thread, forming group of agents for broadcast communications. One of the most used graphical environments for agent simulation is NetLogo [32], Java-based tool started in 1999 and still active. The aim of NetLogo is mainly modelling I. I NTRODUCTION the evolution of complex systems where hundreds or thou- sands of agents can operate independently. It include also Agent-based modeling and simulation (ABMS) is a wide an authoring environment that allows researchers to publish used technique to model systems of autonomous, interacting their own models. In fact, it comes with the Models Library, agents [18], [13], [15], [7], [9], [8]. There are various ap- which is a collection of pre-built simulation models to use plications which range from stock market simulations [10], and modify for biology, physics, computer science and so on. [29] supply chains, consumer markets [27], [19], [22], as well NetLogo gives also the opportunity to the user to run into as problems related to complex networks [4], [3], [21], [20], a “classroom participatory-simulation” tool called HubNet, [21], as predicting the spread of epidemics, the threat of bio- which allows students to control an agent in a simulation warfare and multi-robot simulations [25], [26], [6], [12], [24] through the network. The theoretical and practical foundations of ABMS have been widely studied [18], and a wide variety of toolkits and methods Another tool, intended for SMP-aware, high performance, for developing agent models can be found in the literature [17]. complex network simulations is ComplexSim [23], a C-based simulation platform developed to support the study of complex In this work we present AgentSimJs, a JavaScript-based 3D networks. Its architecture is based on two layers, the parallel simulation framework developed to build web based, 3D multi- simulation kernel and the complex network data and runtime. agent simulations. Running this kind of simulation in a Web The simulator does not provide a graphical environment, and Browser has several advantages. The first benefit is that the offers a simple a C-based programming APIs which, although simulator is multi-platform, as browsers natively support the simple, leads the programmer to write C code and implement JavaScript language, which is used nowadays to develop web his own data structures to program the behaviors entities. application [11]. Moreover, AgentSimJs allows an easy collab- oration between researchers, since running a simulation simply Breve is a 3D simulation environment designed for sim- implies to start a web browser and connect to a specific link. ulation of decentralized systems and artificial life [16]. With Such a collaboration aspect is also stressed by AgentSimJs respect to NetLogo, Breve is able to simulate continuous time since, thanks to its modular architecture, algorithms and code and continuous 3D space, and, therefore,is suited to a different developed for agents behaviors can be easily rescued. class of simulations. Breve includes an interpreted object- oriented language, an OpenGL display engine, collision detec- The architecture of AgentSimJs is highly modular. Two dif- tion, and the support for articulated body physical simulation ferent components handle agent behavior and agent interaction. and collision resolution with static and dynamic friction. Agent The simulator also includes a component designed to manage behavior can be written in Python [1] or by through a language group of agents, while the simulated physical environment is named “steve”, which is easy-to-use. Nevertheless, Breve is no handled by a further dedicated component, which deals with longer maintained from 2009, but the simulation environment the computation of the interactions among agents and between is still used, indeed Jon klein, brave author, has partially agents and scene objects. Code reuse and information sharing restored the website1 . Furthermore, a JavaScript version of is properly managed in order to share all the algorithms and brave is available online 2 and it allows the researcher to build behaviors developed for the agents. Last but not least, the simple simulations. simulator offers the opportunity to distribute the simulation among several machines/thread through the component named 1 www.spiderland.org Web-API integrator. 2 http://artificial.com/breve.js/ 118 PALAIS [31] is a 3D virtual simulation environment for • Communication Bus. It allows the simulation of a artificial intelligence with a special focus on games. It pro- communication system during the multi-agent simula- vides functionality for prototyping, testing, visualization and tion and handles agent interaction. evaluation of game AI. It allows the definition and execution • Group controller. It enables the formation of groups of arbitrary, three-dimensional game scenes and behavior. It of agents that will perform different tasks. provides also a scripting environment along with a program- ming interface, simulation control and data visualization tools. • Environment. It is used to simulate the graphical As stated by the authors, the scripting interface is minimal and scenario and to handle physical interactions and (pos- can be accessed via simple JavaScript. PALAIS projects can sible) collision among agents and the other objects be easily shared, in order to, e.g., collaborate with peers and present on the scenario. build up showcases for algorithms and behaviors. • Algorithms Library. It is used by the programmer ARGoS [30] is an open source multirobot simulator ca- to design the algorithms that the agents will use to pable of simulating at real-time large heterogeneous swarms perform their task, as it provides an interface and some of robots. The authors state that ARGoS is highly modular, basic algorithms to be used by the simulation designer. therefore users can easily add custom features and allocate • IndexedDB Manager. This component is responsible further computational resources where needed. Furthermore, to store the simulation data in a temporary cache in multiple physics engines can be used and assigned to different order to be export after the simulation. parts of the environment. Results show that ARGoS is able to allocate and simulate about 10,000 simple wheeled robots • Web-API integrator. It enables the execution of 40% faster than real-time. several simulation on different machines by means of a shared environment (through a web-api or a socket FLAME [2] is another agent-based modelling framework interface). for high performance computing. The strength of the frame- work is that parallel programming expertise are not required to A. Agent modelers, that can concentrate only to design the model. The authors used half a million of agents and 432 processors to JavaScript class Agent is the main component of the show that a parallel efficiency of above 80% can be reached. framework, as it represents the agent abstraction at framework level and it contains the implementation of some methods III. A RCHITECTURE which implement several functionality, listed below: AgentSimJs is a tool exploiting the library threejs 3 for the • Movement: all the methods that can be used to set 3D engine. Furthermore, JavaScript Web Workers are used to the position of the Agent, type of motion and path to implement a sort of parallelism in executing agent behaviors follow. Indeed, each agent is able to perform a certain and the supporting message communication. number of predefined motions (e.g. parabolic, linear, circular). The architecture of AgentSimJs, which is depicted in Figure 1, is composed by the several components: • Status: the methods used to get the agents status (e.g. agent position, agent role, agent group). • Agent. It is core component of the framework, as it contains the primitives needed for the simulation of • Communication: it’s an interface of the communica- the behavior. tion system of the framework (bus) that allows the agent to exchange messages with the others agents. 3 http://threejs.org/ • Communication proxy: it’s an embedded message proxy that can be used to build an overlay network among the agents. • Environment: all the methods involved in the interac- tion between the agent and the environments. • Geometry: these primitives enables the definition of the agent shape and the related reference system on the 3D scene. • Proximity sensor: to make each agent aware of the environment a proximity sensor (laser scanner like) is simulated with a variable radius. The status of any agent is represented by a set of variables that are managed by the status primitives, which allow to each agent to send its own status to the peers through the communication bus. Class Agent may be extended by the programmer through the addition of specific methods. A (shared) data structure among agent instances is used to Fig. 1. Architecture of AgentSimJs store the history of the agent position or to set the path of 119 Fig. 2. Multiple movement workers Fig. 4. Communication bus the agents. Path planning can be performed by setting high other components of the framework to exchange simulation level strategies in the group controller. A fine tuning may data. be performed by means of the Algorithm API and methods available for setting the movement of the single agent. In The type of messages exchanged in the communication bus particular, the position methods of the agent instances – that can be listed as follow: compute/update the position of every agents – may be invoked run on a dedicated worker (movement worker) for each agent, • Agent Data Message: this type of message are ex- as depicted in figure III-A. changed among the agents to share information about position, objects, environments, task etc.; each mes- For a high number of agents the movement worker can sage will contain the Id of the sender and the Id of be centralized, i.e. a singleton instance may be used, in this the receiver. case all the operations related to the computation of the agent positions will be managed by a single worker. The worker • Group Data Message: this type of message are sent (Figure 3) has the responsibility to evaluate the position of each from the group controller to each member of the group simulated agent at each simulation step, by computing the next (a sub-set of agents); each message will contain the position of the agent by means of the motion equation in a fixed Id of the group that must receive the message. time interval. In order to update the agent position, the worker • Agent-Environment Collision/Interaction: this type of may use the native web-worker communication interface or the message contains information about the interaction bus communication of the framework. between the agents and the environment. The infor- In the centralized approach the movement worker will mation are computed by the environment and sent to publish a message containing the agent position and ID for a specific agent. each agent; then every agent will receive the message and will update it’s position if the Id of the message match with its As depicted in Figure 4, the communication bus can handle own ID, otherwise the agent will discard the message. several kind of messages sent by actors of different levels, e.g. a message can travel from agent to agent or from a group controller to an agent. It enables also a remote integration between several simulations that runs in different machine. Figure 5 shows that through the web-api integrator several different actors, e.g. group controller and agents, can exchange simulation data while running in different machine. By the web-api integrator, agents will be able to send and receive message with the same approach. Each agent is capable to join an overlay network with the other agents by communicating with within the maximum transmission range. In this case the communication bus is not needed, as only the agent communication proxy primitives of agents are used. In order to build an overlay network the message sent by the agent’s will contain the Id of the sender Fig. 3. Singleton worker and the number of agents that have to read the message. As in a real overlay network, if an agent is outside the range of another B. Communication Bus and Overlay network agents, it will not receive any message from it. Each agent that receive the message will perform the following operation: The communication bus is an important component of the simulation framework. Through the communication bus • check if its own Id is included in the Id list of the each agent can exchange information with other agents in a agents that have already read the message. If not, the centralized way; the communication bus can be also used by agent must add its own Id into the list and eventually 120 to the agents involved and this redundancy will make the simulation robust also when performed remotely. The slowest environment will receive the information and will align the scene to the others environment. D. Group Controller The group controller is used to create groups among the agents, to assign them several different tasks and manage the agents of the group. In particular, the group controller expose an interface with methods to select the agents that will form a specific group by assigning a GroupID to agents and group and manage the groups during the simulation. Groups can be modified at runtime by reassigning the agents to different groups. Through the communication bus the group controller can send a broadcast message to the agents of a single group in order to share specific information with them, as well as a heartbeat periodic message to monitoring their status. In particular, an agent can be considered off-line/not available if the environment detects a collision between the agent and another item (i.e. an object or another agents). In Fig. 5. AgentSimJs Communication bus this case the environment will send a message to the agent that will set its status as off-line, and the agent can send a store the information and re-send the message to the message to the group controller to notify its new status. As near agents. alternative, it may ignore the heartbeat message by the group controller which, after a timeout, will consider the agent as • If the Id is already included in the list, the agent will off-line. The group controller is capable to manage only the discard the message. agents that are running in the same machine, as it cannot send or receive message by the communication bus to the agents running in another machine. The main reason of this choice is C. Environment represented by the network latency which will may become a A component named Environment is responsible to create bottleneck. the 3D scene. Its geometry can be defined by a set of 3D primitives (that can be enhanced by the user). It is also capable E. Algorithms Library to place the objects on the scene in a specific position chosen The algorithms API provides an interface that can be used by the user and compute the potential collision among the to implements a specific algorithm that can be used during the agents and between the agents and the objects. The collision simulation. The interface defines how the agents have to send are evaluated by a batch process that compute the distance its status and how they’ll receive the result. This approach between every objects on the scene and then compare these allows to separate the agent low level model and primitives distances with a fixed threshold. If the distance is lower than from its behaviors. a given threshold a collision between the selected objects will occur. The methods exposed by the Algorithms Library can be invoked by each agent, such that the agents behaviors will Once a collision is detected the Environment will send a run in a distributed way through a shared knowledge (i.e. the message to the involved agent, the message will set the agent algorithms), which will represent the common logic of the status as off-line and will contain the Id of the scene object that agents. The Algorithms Library will define also a library that has caused the collision. The simulation of the collision can can be enhanced during time by all the users that will use the be avoided by setting a specific parameter. The environment is AgentSimJs framework. the only component that is aware of the positions and status of every object on the scenes. The object on the scene can be F. IndexedDB Manager placed also in a random way through a specific method during the scene initialization; the static objects can be added also at The design of the framework requires a DB which will run-time. If a simulation is executed on several machines, each store a cache of that can be hosted inside a web-browser. The environment component will set a sharing of the information IndexedDB manager, which relies on the IndexedDB API [28], about all the objects in the scene during the initialization is responsible to store all the simulation data on an embedded phase. This means that, at runtime, each environment will database that can be used as a data-cache for the client. The compute the collision and then will broadcast a message to information stored in the database can be sent to any database the involved agents and the others environments through the on cloud (eg. through a web-api) or can be exported in CSV communication bus. The environments that will receive the format to be further analysed by the user. The embedded data- message will update the scene and the information about the cache capability ensures that the simulation can be launched involved agents and objects. In this way each environment that without any remote connection requirement through a simple will detect the collision at the same time will send a message html page. 121 G. Web-API Integrator In order to add the capability of performing a simulation in several machine through a web-browser a specific component has been developed. The Web-API integrator is responsible to build a remote communication bus that can exchange messages through remote machines. The approach builds a shared communication bus composed by each embedded bus (that is hosted in each remote machine), each bus is connected to the others through a web-api or a socket. This means that each message in each bus will be sent in a bus overly network. To perform a remote connection the web-api integrator can use a custom web-api or a specific socket (cenno sui socket e su come si possono gestire tramite JavaScript). The web-api integrator will map each remote machine, will store simulation Id and status. The embedded data-cache can be connected to the web-api integrator to share data also in an asynchronous way or as a data-buffer. The remote machines are managed also through an “heartbeat” message Fig. 6. Design the circular area containing the information about the status of the single remote machine and connection data (e.g. IP address, timestamp, etc.). If the heartbeat is not received by a given time threshold the machine will be set as off-line. The simulation will run without the agents of the disconnected remote machine (the Web-api integrator will send a message to the environment to eliminate from the simulation the external agents, the static object will persist on the scene). IV. C ASE S TUDY: S IMULATION OF SENSOR RELEASING BY UAV S AgentSimJs has been recently employed to simulate a sce- nario on which a variable number of coordinated UAVs [14], [5] are employed to release sensors in a certain area of terrain, in order to accomplish the construction and management of a Wireless Sensor Network (WSN). The behavior of the UAVs has been set in order to perform a sensor releasing pattern which leads to a higher density towards the centroid of the zone. The simulator can be tested the following address: http://globus.dmi.unict.it/node. Fig. 7. A simulation running The UI of the simulator provides a first interface useful to design a single circular area (hot zone, Figure 6), and an overall graphical view useful to manage all the created areas. V. C ONCLUSIONS AND FUTURE WORK In particular, for each area, it is possible to set some parameters This paper has described the architecture of AgentSimJs, that relate to the designed releasing model. a web based based multi-agent simulation framework written in JavaScript. The simulator is capable to render a 3D scene with objects and agents and allows the programmer to arrange simulations by specifying the behavior of agents. The archi- Furthermore, a simulation can be executed in two different tecture of AgentSimJs is highly modular, as several different modes: graphical and batch. In both cases, there is an option components have been designed to endow the simulator with to stop the log stream which appears in the upper part of the the desired functionalities. With AgentSimJs the simulation simulation panel (see Figure 7). An interesting feature of the can be distributed among different machines and/or different simulator is the generation of the set of coordinates where thread, agents can form groups for broadcast communications. sensors have to be released. These data are used to perform Particular care was given to data storage, which has been the analysis needed to understand whether the deployment addressed by a component relying on IndexedDB API. schema gives real advantages in terms of energy consumption We are working to realize a web portal to give the op- and duration of the resulting wireless sensor network. portunity to use the framework to students and researchers, as well as releasing publicly the source code of the framework. The portal should provide the capability to store configurations 122 of simulations and code of agent behaviors developed by [15] M. Higashino, T. Hayakawa, K. Takahashi, T. Kawamura, and K. Sug- researchers. Furthermore, we planned to integrate the frame- ahara, “Management of streaming multimedia content using mobile work with a library for real time physics simulation. At the agent technology on pure p2p-based distributed e-learning system,” International Journal of Grid and Utility Computing 26, vol. 5, no. 3, moment there is an attempt of porting of Bullet physics engine pp. 198–204, 2014. to JavaScript, named ammo.js. Finally, we have planned to [16] J. Klein, “Breve: a 3d environment for the simulation of decentralized integrate the framework with the JavaScript interface provided systems and artificial life,” in Proceedings of the eighth international by ROS (Robotic Operating System) 4 . conference on Artificial life, 2003, pp. 329–334. [17] F. Klügl and A. L. Bazzan, “Agent-based modeling and simulation,” AI Magazine, vol. 33, no. 3, p. 29, 2012. VI. ACKNOWLEDGEMENTS [18] C. M. Macal and M. J. North, “Agent-based modeling and simulation,” This work is partially supported by projects PRISMA in Winter simulation conference. Winter simulation conference, 2009, pp. 86–98. PON04a2 A/F and CLARA funded by the Italian Ministry of [19] F. Messina, G. Pappalardo, D. Rosaci, C. Santoro, and G. M. Sarné, University. “A trust model for competitive cloud federations,” Complex, Intelligent, and Software Intensive Systems (CISIS), pp. 469–474, 2014. R EFERENCES [20] ——, “A distributed agent-based approach for supporting group for- mation in p2p e-learning,” in Congress of the Italian Association for [1] “The python language reference manual,” 2016, Artificial Intelligence. Springer International Publishing, 2013, pp. https://docs.python.org/3/reference/index.html. 312–323. [2] S. Coakley, M. Gheorghe, M. Holcombe, S. Chin, D. Worth, and [21] ——, “Hyson: A distributed agent-based protocol for group formation C. Greenough, “Exploitation of high performance computing in the in online social networks,” in German Conference on Multiagent System flame agent-based simulation framework,” in High Performance Com- Technologies. Springer Berlin Heidelberg, 2013, pp. 320–333. puting and Communication & 2012 IEEE 9th International Conference [22] F. Messina, G. Pappalardo, D. Rosaci, and G. M. Sarné, “An agent on Embedded Software and Systems (HPCC-ICESS), 2012 IEEE 14th based architecture for vm software tracking in cloud federations,” in International Conference on. IEEE, 2012, pp. 538–545. Complex, Intelligent and Software Intensive Systems (CISIS), 2014 [3] A. Comi, L. Fotia, F. Messina, G. Pappalardo, D. Rosaci, and G. M. Eighth International Conference on. IEEE, 2014, pp. 463–468. Sarné, “An evolutionary approach for cloud learning agents in multi- [23] F. Messina, G. Pappalardo, and C. Santoro, “Complexsim: a flexible cloud distributed contexts,” in 2015 IEEE 24th International Conference simulation platform for complex systems,” International Journal of on Enabling Technologies: Infrastructure for Collaborative Enterprises. Simulation and Process Modelling 6, vol. 8, no. 4, pp. 202–211, 2013. IEEE, 2015, pp. 99–104. [24] ——, “Integrating cloud services in behaviour programming for au- [4] ——, “Using semantic negotiation for ontology enrichment in e- tonomous robots,” in International Conference on Algorithms and Ar- learning multi-agent systems,” in Complex, Intelligent, and Software chitectures for Parallel Processing. Springer International Publishing, Intensive Systems (CISIS), 2015 Ninth International Conference on. 2013, pp. 295–302. IEEE, 2015, pp. 474–479. [25] ——, “Designing autonomous robots using golem,” in XV Workshop [5] M. De Benedetti, F. D’Urso, F. Messina, G. Pappalardo, and C. Santoro, ”Dagli Oggetti agli Agenti”, vol. 1260. CEUR-WS, 2014. “Uav-based aerial monitoring: A performance evaluation of a self- [26] ——, “A goal-centric framework for behaviour programming in au- organising flocking algorithm,” in 2015 10th International Conference tonomous robotic systems,” in Mechatronic and Embedded Systems and on P2P, Parallel, Grid, Cloud and Internet Computing (3PGCIC). Applications (MESA), 2014 IEEE/ASME 10th International Conference IEEE, 2015, pp. 248–255. on. IEEE, 2014, pp. 1–6. [6] M. De Benedetti, F. DUrso, F. Messina, G. Pappalardo, and C. Santoro, [27] F. Messina, G. Pappalardo, C. Santoro, D. Rosaci, and G. M. Sarné, “An “Self-organising uavs for wide area fault-tolerant aerial monitoring,” agent based negotiation protocol for cloud service level agreements,” in 2015. 2014 IEEE 23rd International WETICE Conference. IEEE, 2014, pp. [7] P. De Meo, F. Messina, D. Rosaci, and G. M. Sarné, “Recommending 161–166. users in social networks by integrating local and global reputation,” [28] M. D. Network, “Indexeddb api,” https://developer.mozilla.org/en- in International Conference on Internet and Distributed Computing US/docs/Web/API/IndexedDB API. Systems. Springer International Publishing, 2014, pp. 437–446. [29] M. R. Ogiela and U. Ogiela, “Linguistic approach to cryptographic [8] ——, “2d-socialnetworks: away to virally distribute popular information data sharing,” in 2008 Second International Conference on Future avoiding spam,” in Intelligent Distributed Computing VIII. Springer Generation Communication and Networking, vol. 1. IEEE, 2008, pp. International Publishing, 2015, pp. 369–375. 377–380. [9] ——, “An agent-oriented, trust-aware approach to improve the qos in [30] C. Pinciroli, V. Trianni, R. O’Grady, G. Pini, A. Brutschy, M. Brambilla, dynamic grid federations,” Concurrency and Computation: Practice and N. Mathews, E. Ferrante, G. Di Caro, F. Ducatelle et al., “Argos: a Experience, vol. 27, no. 17, pp. 5411–5435, 2015. modular, multi-engine simulator for heterogeneous swarm robotics,” [10] ——, “An agent-oriented, trust-aware approach to improve the qos in in 2011 IEEE/RSJ International Conference on Intelligent Robots and dynamic grid federations,” Concurrency and Computation: Practice and Systems. IEEE, 2011, pp. 5027–5034. Experience, vol. 27, no. 17, pp. 5411–5435, 2015. [31] P. Schwab and H. Hlavacs, “Palais: A 3d simulation environment for [11] D. Flanagan, JavaScript: the definitive guide. ” O’Reilly Media, Inc.”, artificial intelligence in games,” in Proceedings of the AISB Convention, 2006. 2015. [12] G. Fortino, W. Russo, and C. Santoro, “Translating statecharts-based [32] S. Tisue and U. Wilensky, “Netlogo: Design and implementation of a into bdi agents: The dsc/profeta case,” in German Conference on multi-agent modeling environment,” in Proceedings of agent, vol. 2004, Multiagent System Technologies. Springer, 2013, pp. 264–277. 2004, pp. 7–9. [13] T. French, N. Bessis, F. Xhafa, and C. Maple, “Towards a corporate governance trust agent scoring model for collaborative virtual organi- sations,” International Journal of Grid and Utility Computing, vol. 2, no. 2, pp. 98–108, 2011. [14] S. Gupte, P. I. T. Mohandas, and J. M. Conrad, “A survey of quadrotor unmanned aerial vehicles,” in Southeastcon, 2012 Proceedings of IEEE. IEEE, 2012, pp. 1–6. 4 http://www.ros.org/ 123