CommunicationHelper

The natural extension to the RlApplicationHelper is the CommunicationHelper. It can work with RlApplicationContainers to create communication channels between the applications and configure them accordingly. The CommunicationHelper simplifies this procedure and reduces the risks of bugs.

First, create an instance of CommunicationHelper and set the different applications:

1CommunicationHelper commHelper = CommunicationHelper();
2
3commHelper.SetObservationApps(observationApps);
4commHelper.SetAgentApps(agentApps);
5commHelper.SetRewardApps(rewardApps);
6commHelper.SetActionApps(actionApps);
7commHelper.SetIds();

The different Set methods expect an object of type RlApplicationContainer. See chapter ApplicationHelper for more information on how to create one. After the helper received all RlApplicationContainers, the IDs of these applications need to be assigned (line 7). The IDs are used to identify the instances of RlApplication and are required for the next step.

Once the IDs are assigned, the actual connection can be configured. This can be done by passing a vector of type CommunicationPair to the CommunicationHelper. To create an instance of CommunicationPair, the IDs of the two RlApplications and a CommunicationAttributes object have to be provided. The CommunicationAttributes object describes the type of connection. If no argument is passed, a SimpleChannelInterface is created. To create a socket connection via TCP or UDP, a SocketCommunicationAttributes object with TypeId protocol set accordingly can be passed as CommunicationAttributes. The following code is a simple example that creates CommunicationPairs of different types.

 1// UDP
 2CommunicationPair actionCommPair = {
 3    actionApps.GetId(0),
 4    agentApps.GetId(0),
 5    SocketCommunicationAttributes{"7.0.0.2", "1.0.0.2", UdpSocketFactory::GetTypeId()}};
 6
 7//TCP
 8CommunicationPair observationCommPair = {
 9        observationApps.GetId(0),
10        agentApps.GetId(0),
11        SocketCommunicationAttributes{"7.0.0.2", "1.0.0.2", TcpSocketFactory::GetTypeId()}};
12
13//SIMPLE
14CommunicationPair actionCommPair = {actionApps.GetId(0),
15                                                agentApps.GetId(0),
16                                                {}};

The method GetId(i) allows to retrieve the RlApplicationId by passing the index i to the RlApplicationContainer (as used in e.g. line 3–4). When creating SocketCommunicationAttributes, the passed IP addresses have to match the addresses of the node the application is installed on.

Once these CommunicationPairs are created, collect them in a vector and pass it to CommunicationHelper::AddCommunication as a parameter. Finally, the configuration can be finished by calling Configure on the CommunicationHelper. Now all channel interfaces are created accordingly, ready for sending and receiving data. An explanation of the Configure method can be found in section Helper of the design documentation.