# Cognitive Pervasive Service Composition Applied to Predatory Crime Deterrence
## 4 Implementation and Results  
This section describes the case study's implementation used to test our proposal, conditions of execution and some results according to our initial objectives. With this case study, we tested our proposed method of coordination and message passing among the agents using Gama version 1.8.1 as the framework for agents [60]. Gama allowed us to simulate our cognitive agents as species with different characteristics and behaviors which control the simulation's steps and coordination, passing the message in FIPA's ACL format [61]. Gama allows us to simulate the interaction with the messages. The first message sent is the Contract Net; this binds the different agents to the decision-making and the planning agents. With this binding, they can use the agents' functionalities to create the composite service. The Contract Net in Gama works as follows: The decision-making agent starts the conversation with a list of preloaded participants (the cognitive agents) with the protocol fipa-contract-net and the content is \"Join my system\"; then all agents respond with \"agree\". After starting the simulation, the planning agent sends a request to the relevant agents to notify them that they will start the service. The sensor agent senses the environment and sends the information obtained to the perception agent, which, with the memory agent's help, performs the scene recognition process. When the perception agent perceives the scene as risky, the perception agent notifies the decision-making agent that a crime might occur. The way all agents work inside Gama is with reflex; they react to certain changes within the environment and the messages that other agents send them, so every response in the simulation is controlled by the agents. In our implementation, black boxes represent the cognitive agents playing the roles of the different cognitive functions. The motivation agent has pre-loaded mugging detection as motivation. The memory agent has previous training to match risk situations, specifically mugging with firearms; i.e., it contains information regarding the possible plans to apply when a mugging crime is detected. Figure 5 shows the environment implemented. This environment shows the streets and circles, squares and arrows representing the different types of agents. Blue circles represent the passersby; green arrows represent the drones; red squares represent the criminals. For this simulation, we decided not to represent the other agents visually. However, these agents interact with the environment and are considered omnipresent for the sake of this simulation. Figure 5: Environment in Gama. The motor agent controls the drone that appears once the perception agent identifies a crime situation. The behavior of the passersby and criminals is to wander randomly through the streets. However, the criminals have additional behavior: to perform a direct contact crime using a firearm, starting randomly. For the system, the criminal and the victim are indistinguishable until the aggressor tries to commit the crime by showing the firearm. The simulation starts with the reflex \"wandering\" for all passersby. When one finds itself close to the aggressor (1-2 m), the criminal reveals his identity by exposing his firearm with the reflex \"attack.\" At this moment, the system starts its work, identifying this perilous situation represented in the simulation's snapshot as yellow tiles that surround the aggressor (see Figure 6); this action reflects perception's reflex \"detect.\" At this moment, the system starts its behavior to deter the aggressor, so we can see how the system deploys a composed service as a drone, represented as a green arrow. The control and deployment of the drone are the responsibility of the motor system agent and the reflex involved is \"detect.\" This service (the drone) reaches the crime scene to deter the crime: if the drone arrives within a predefined time threshold, it \"scares away\" the aggressor just by its presence.