Lab3: Communication Cyrille Berger September 15, 2015 Communication is a key aspect in coordination of a set of agents, it allows agents to request assistance from other agents as well as to share knowledge of the environment. The goal of this lab is to implement a basic communication framework, that should allow the agents to communicate changes in the environment and to request assistance. For this lab we have created a special map that you should use: /home/TDDD10/maps/Kobe2013stations, it is the regular Kobe map but with stations. 1 Communication The current version of the RoboRescue simulator uses a multi-channel communication system, the competition rules define three channels with various degree of range and reliability. For this lab, there are three channels and an extra, channel 0 that simulates voice, it has however a limited range of 30m. Message count There is a limit on number of messages that each agent can send and hear at each cycle. By default this limit is 4 messages for a platoon agent and 2n messages for a centre agent (n represents number of platoon agents of the same type with that centre agent). Note: Agents hear their own messages without any restriction. Hearing this message won’t fill their message capacity. Channels Agents should register for channels they wish to listen to. After that, kernel will send a limited number of messages on each of those channels to that agent. (Clarification: consider this situation, agent X has limit of 8 messages, X registers for receiving messages from channel 2, 3 and 4, from next cycle kernel will send (at most) 3 messages on channel 2, 3 messages on channel 3 and 2 messages on channel 4 to that agent. Please remember that since kernel handles communication asynchronously, agent X can not use remaining capacity of channel Y for receiving messages from channel Z.) Channel types By default channel 0 will simulate say behaviour that previously was handled by AK_SAY, So in addition to listening to channel 0 you should be around sender (ie 30m distance) to successfully hear his/her message. In practice To subscribe to a channel (for instance channel 1): 1 sendSubscribe(time, 1); 1 If you want to subscribe to more than one channel, you can pass multi channel numbers to sendSubscribe: 1 sendSubscribe(time, 1, 2); Example of code for sending the position of an agent: 1 2 3 4 5 6 7 8 9 10 try { Logger.debug("Send my position on channel 1 " + String.valueOf(me().getPosition().getValue())); sendSpeak(time, 1, String.valueOf(me().getPosition().getValue()) .getBytes("UTF-8")); } catch (java.io.UnsupportedEncodingException uee) { Logger.error(uee.getMessage()); } The messages will be received in the heard parameter of the function think, example of code showing the string received: 1 2 3 4 5 6 7 8 9 10 11 for (Command next : heard) { try { byte[] content = ((AKSpeak)next).getContent(); String txt = new String(content, "UTF-8"); Logger.debug("Heard " + next + txt); } catch (UnsupportedEncodingException uex) { Logger.error(uee.getMessage()); } } 2 2.1 Implementation consideration Messages The communication bandwidth is limited, it is therefore highly advised to optimize the length of the messages. A suggestion is to use the first byte of the message to define the type (1 civilian detected, 2 go extinguish building, 3 can you clear the road...). Then the content of the message is dependent on the type. For instance civilian detected is followed by the EntityID of the civilian and then the EntityID of the are where the civilian is located. 2.2 Channels Agents and centres have a limited capabilities in receiving messages, but you can use the different channels to filter the communication. For instance, you can use one channel 2 for world update, and only the centre are subscribed to that channel. And an other channel for the centre to give order to the various agents. 2.3 AbstractCommunicationStrategy In the agent project, you can find an AbstractCommunicationStrategy: 1 2 3 4 5 6 7 8 9 10 11 12 public abstract class AbstractCommunicationStrategy { /** * This function is called to broadcast observation */ public abstract void communicateChanges(ChangeSet changed); /** * This function is called with all the messages that are * received by the agent */ public abstract void handleMessages(Collection<Command> heard); } This class defines a basic interface to a communication strategy, in this lab, you should extend it with your own implementation and implements the two functions. • communicateChanges is called at the beginning of the think function to share the new information perceived by the agent to the world • handleMessages is called at the beginning of the think to find which order the agent is receiving from the station 2.4 Visualisation You should have a GUI that for each agent show the messages that were sent at the previous step and the message that were received at the current state. 3 Sharing knowledge about the environment Since agents have access to a limited view of the world and centre are completely blind, it is important to communicate information between agents and centres. The first part of this lab is to implement the communicateChanges and handleMessages of your communication strategy to exchange update to the world between agents. In handleMessages when you receive a message with knowledge about the world you should update the StandardWorldModel of the agent. Since the bandwidth is limited it will be important to prioritize which knowledge should be shared (informing about civilians might be more important than informing about fire or road blockade). An other point, the ChangeSet given as argument in communicateChanges (and think) might contains information that the agent already know (because it was communicated to the agent earlier), and you should take care of not sending that information again, for instance: 3 • At instant t, agent i perceive a fire Fk and send a message informing the other agent. • At instant t + 1, agent j receive the message from agent i and update his StandardWorldModel. • At instant t + 2, agent j perceive the fire Fk , which is listed in ChangeSet changed, but agent j knows that the information has already been communicated and agent j does not broadcast it again. 3.1 Visualisation To see the effect of your communication strategy, you should use a Viewer to show the StandardWorldModel of one of the centre. 4 Sending order The second part of the communication framework should be the ability for an agent to give orders to an other agent. To demonstrate that aspect of your framework, you should implement a centre that order agents to go to random location on the map. 4