## 3 Proposed Schemes: Midpoint Relay Selection Using Social Trust and Battery Level
### An Example Scenario of Our Proposed Schemes  
Let us consider that the mobile devices are under the coverage of a base station (BS) as shown in Figure 1. Each mobile devices are moving with different velocities at random direction. We assume that the BS knows location and battery level information of devices in the network. Suppose a mobile device (source) wants to have D2D communication with another mobile device (destination). The source can either have direct D2D communication with the destination or select a relay for D2D communication. The source selects a direct D2D communication only when its data rate is higher compared to that offered by a D2D communication via a relay. We propose MRS-ST-BL and MRS-SD-BL relay selection schemes that maximizes throughput of D2D communications by taking location, battery level and social trust information into account for relay selection. ```
// Given a source and a destination pair, BS determines candidate relay nodes and their corresponding battery power level and maximum allowable transmission power. Input: \(s\), \(d\), \(R\) and battery percentage of nodes Output: \(n_{\textit{circle}}\) along with battery percentage and location, and \(P_{\textit{max}}\)
1: Receive D2D request from \(s\)
2: Calculate Midpoint, \(m=\) Midpoint(\(s\), \(d\))
3:for\(radius=1:R\)do
4: Identify \(n_{\textit{circle}}=\) NodesWithinCircle(\(m\), \(radius\))
5: Identify battery percentage of devices in \(n_{\textit{circle}}\)
6:endfor
7: Determine \(P_{\textit{max}}\)
8: Send \(n_{\textit{circle}}\) along with battery percentage and location, and \(P_{\textit{max}}\) to \(s\)
```  
**Algorithm 1**Tasks performed at Base Station```
1:// This algorithm consists of sequence of tasks performed by a node for midpoint relay selection using social trust and battery power. If a relay is to be used, it selects a relay that maximizes the throughput of D2D communication. Input: \(s\), \(d\), \(n_{circle}\), battery level of nodes listed in \(n_{circle}\), location of nodes listed in \(n_{circle}\), \(S_{tlres}\), \(B_{tlres}\), \(P_{max}\), \(l\), \(T\) and \(\tau\) Output: \(t_{s,r,d}\)
2:if len(\(n_{circle}\)) = 0 then
3: Calculate \(C_{s,d}\) as in equation 4
4:\(t_{s,r,d}\) = \(C_{s,d}\)
5:else
6:if Friends in \(n_{circle}\) = 0 then
7: Relay = Nearest to midpoint
8:\(t_{s,r,d}\) = \(C_{s,r,d}\)
9:else
10: Identify \(n_{S_{tlres}}\)
11:if len(\(n_{S_{tlres}}\)) = 0 then
12: Relay = Nearest to midpoint
13:\(t_{s,r,d}\) = \(C_{s,r,d}\)
14:else
15:\(n_{lattery}\) = Identify nodes having battery level above \(B_{tlres}\)
16:if len(\(n_{lattery}\)) > \(l\)then
17:\(n_{lattery}\) = \(l\) nodes with high social trust values
18:endif
19: Sequentially probe nodes in \(n_{lattery}\) and \(d\)
20:for\(i=1:len(n_{lattery}\)) do
21: Power of \(n_{S_{tlres}}(i)\) = Transmission power proportional to social trust
22: Calculate \(C_{s,r,d}\) through each of nodes in \(n_{S_{tlres}}\) as in equation 5
23:endfor
24: Select maximum \(C_{s,r,d}\) = \(max(C_{s,r,d})\)
25:if maximum \(C_{s,r,d}\) > \(C_{s,d}\)then
26: D2D via a relay is selected
27:\(t_{s,r,d}\) = \(max(C_{s,r,d})\times(T-(\tau\times len(n_{battery})))\)
28:else
29: Direct D2D is selected
30:\(t_{s,r,d}\) = \(C_{s,d}\) \(\times(T-(\tau\times len(n_{battery})))\)
31:endif
32:endif
33:endif
```

**Algorithm 2**Tasks performed at Source for MRS-ST-BL

When a source (let us say device 1) wants to have D2D communication with a destination (let us say device 7), it sends a D2D request to the BS. The BS sends list of devices (let us say 2, 5, 6, 10, 11, 14, 15) within a circular region of radius \(R\) centered at the midpoint between source and destination, battery of the devices along with other necessary information for D2D communications. In our proposed scheme MRS-ST-BL, the source initially filters the devices that have social trust above social threshold (let us say \(S_{tlres}\) = 0.3) and also have battery above battery threshold (let us say \(B_{tlres}\) = 30%). Let us consider devices 5 and 11 are not friends of source.