## 3 Proposed Schemes: Midpoint Relay Selection Using Social Trust and Battery Level
### An Example Scenario of Our Proposed Schemes
These devices are not considered as potential relays. Therefore, they are filtered out. Among the list of remaining devices, let us consider devices 2 and 14 have battery level less than \(B_{tlres}\). These devices (2 and 14) are also not considered for relay selection because they may not relay the data successfully. The source then filters at most \(l\) (let us say probe limit = 10) devices that have large social trust values among the remainingdevices in the list. In the considered scenario, devices 6, 10 and 15 are sequentially probed by the source. The source compares the data rate offered by each of them. Let us say, device 6 offers the maximum data rate. This data rate is compared against the data rate of direct communication. If the data rate through the device 6 is higher than that of direct communication, then device 6 is selected as a relay. Otherwise, the source communicates directly with the destination. ```
// This algorithm consists of sequence of tasks performed by a node for midpoint relay selection using social distance 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_{thres}\), \(B_{thres}\), \(P_{max}\), \(l\), \(T\) and \(\tau\) Output: \(t_{s,r,d}\)
1:if len(\(n_{circle}\)) = 0 then
2: Calculate \(C_{s,d}\) as in equation 4
3:\(t_{s,r,d}=C_{s,d}\)
4:else
5:if Friends in \(n_{circle}\) = 0 then
6: Relay = Nearest to midpoint
7:\(t_{s,r,d}=C_{s,r,d}\)
8:else
9:\(n_{battery}\) = Identify nodes having battery level above \(B_{thres}\)
10:if len(\(n_{battery}\)) = 0 then
11: Relay = Nearest to midpoint
12:\(t_{s,r,d}=C_{s,r,d}\)
13:else
14:if len(\(n_{battery}\)) > \(l\)then
15:\(n_{battery}\) = \(l\) nodes nearest to midpoint
16:endif
17: Identify node above social threshold, \(n_{S_{thres}}\)
18:if len(\(n_{S_{thres}}\)) = 0 then
19: Relay = Nearest to midpoint
20:\(t_{s,r,d}=C_{s,r,d}\)
21:else
22: Sequentially probe nodes in \(n_{S_{thres}}\) and \(d\)
23:for\(i=1:\) len(\(n_{S_{thres}}\)) do
24: Power of \(n_{S_{thres}}\)(\(i\)) = Transmission power proportional to social trust
25:endfor
26: Calculate \(C_{s,r,d}\) through each of nodes in \(n_{S_{thres}}\) as in equation 5
27: Select maximum \(C_{s,r,d}=max(C_{s,r,d})\)
28:if\(max(C_{s,r,d})>C_{s,d}\)then
29: D2D via a relay is selected
30:\(t_{s,r,d}=max(C_{s,r,d})\times(T-(\tau\times len(n_{S_{thres}})))\)
31:else
32: Direct D2D is selected
33:\(t_{s,r,d}=C_{s,d}\times(T-(\tau\times len(n_{S_{thres}})))\)
34:endif
35:endif
36:endif
37:endif
```
// This algorithm consists of sequence of tasks performed by candidate relay node for relay selection. Input: \(s\), \(d\), \(P_{max}\) and probe Output: SNR values
1: Receive probe message from \(s\)
2: Send SNR value of probe received to \(s\)
3: Check the battery power level
4:if battery \(<B_{thres}\)then
5: Transmission power = Minimum transmission power possible
6:else
7: Transmission power = Transmission power proportional to social trust
8:endif
9: Send probe to \(d\) with transmission power as calculated above
```
**Algorithm 4**Tasks performed at Candidate Relay Nodes
```
// This algorithm consists of sequence of tasks performed by a relay node in D2D communications. Input: \(s\), \(d\), \(P_{max}\) and user data Output: relay data
1: Receive user data from \(s\)
2: Check the battery power level
3:if battery \(<B_{thres}\)then
4: Transmission power = Minimum transmission power possible
5:else
6: Transmission power = Transmission power proportional to social trust
7:endif
8: Send probe to \(d\) with transmission power as calculated above
```
**Algorithm 5**Tasks performed at a Relay Node
```
// This algorithm consists of sequence of tasks performed by destination node for relay selection.