# D2D-Assisted Adaptive Federated Learning in Energy-Constrained Edge Computing
## 4 Partite Graph-Based FL Scheme with Adaptive D2D Pairing and Aperiodic Local Iterations
```
1:\(\mathcal{O}(N^{2})


```
0: Initial \(E_{n}^{\max},D_{n,k},t_{n},c_{n},p_{n},d_{n,m},e^{h}\) Set \(V_{n}=0\) and \(\rho_{n,m,k}^{\text{del}}=0\)
1:for\(n=1\) to \(N\)do
2:\(\alpha_{n}=0\);
3:for\(m=1\) to \(N\)do
4:if\(E_{n,m,k}^{\text{del}}+E_{m,0,k}^{\text{del}}<E_{n,\alpha_{n},k}^{\text{del}}+E_{ \alpha_{n},0,k}^{\text{del}}\)then
5:\(\alpha_{n}=m\);
6:endif
7:endfor
8:\(V_{\alpha_{n}}=V_{\alpha_{n}}+1\);
9:endfor
10: Select \(Z_{1}\) servers from set \(\mathcal{N}\) according to their \(V_{n}\) values from large to small, which are denoted as \(F_{n^{*}}\), and take them to form \(Z_{1}\) clusters;
11:for\(n=1\) to \(N\)do
12:if\(\alpha_{n}\in F_{\alpha_{n}^{*}}\)then
13:\(F_{\alpha_{n}^{*}}=n\bigcup F_{\alpha_{n}^{*}},\rho_{n,\alpha_{n},k}^{\text{del }}=1\);
14:endif
15:endfor
16: Set k = 0;
17:while\(T^{\max}-\sum_{i=0}^{k}T_{i}>0\) and \(E_{n}^{\max}-\sum_{i=0}^{k}E_{n,i}>0\)do
18:\(k=k+1\), and \(\rho_{n,k}^{\text{max}}=0\);
19:\(K_{k}=\{T^{\max}-\sum_{i=0}^{k-1}T_{i}-\max\{(E_{n}^{\max}-\sum_{i=0}^{k-1}E_{ n,i})\}/D_{n,k-1}e_{n}\cdot t_{n}\cdot|D_{n,k-1}|\}r_{n,0}/C_{n}\);
20: Randomly select \(\tau_{n,k}\) from range \([\frac{(E_{n}^{\max}-\sum_{k=0}^{k}E_{n,i})/D_{n,k}e_{n}}{K_{k}},\frac{(2K_{k} -2+2H)}{(K_{k}-1+2H)\sum_{i=0}^{k}\tau_{n,i}/K_{k}}]\) following a continuous uniform distribution;
21:\(S_{n,k}=\theta_{1}\frac{E_{n}^{\max}-\sum_{i=0}^{k}E_{n,i}}{e_{n}|D_{n,k}|}+ \theta_{2}t_{n}\);
22:\(O_{k}=\text{Softmax}([S_{1,k},S_{2,k},...,S_{N,k}])\);
23:for\(F_{n^{*}}\) in \(\{F_{n^{*}}\}_{n^{*}}^{2}\)do
24: Construct particle graph \(G_{f}(V_{f},E_{f})\);
25:for\((v_{n},v_{n^{\prime}})\in V_{f}\)do
26:if\(\min\{T^{\text{tra}}_{n,k}+\frac{C_{n}}{\pi_{n}\alpha_{n}}-T^{\text{tra}}_{n^{ \prime},k},T^{\text{tra}}_{n^{\prime},k}+\frac{C_{n^{\prime}}}{\pi_{n^{\prime }}\alpha_{n^{\prime}}}\) \(-T^{\text{tra}}_{n,k}\}>0\)then
27:\(G_{f}=G_{f^{*}}-c_{v_{n},v_{n^{\prime}}}\);
28:endif
29: Divide vertices \(V_{f}\) of graph \(G_{f}\) into \(J_{f,k}\) subsets;
30:endfor
31: Select client servers for local training \(n^{\prime}=\operatorname*{arg\,max}_{n}\{O_{k}(n\in F_{n^{*}})\}\);
32:\(V_{f}^{h}=V_{f}-J_{i},(n^{\prime}\in J_{i})\);
33:while Randomly select \(\varepsilon<\varepsilon^{h}\) and \(V_{f}^{h}\
eq\varnothing\)do
34:\(n^{\prime}=\operatorname*{arg\,max}_{n}\Bigl{\{}O_{k}(n\in\aleph_{n^{\prime},k} \bigcap V_{f}^{h})\Bigr{\}}\), and \(\rho_{n^{\prime},k}^{train}=1\);
35:\(V_{f}^{h}=V_{f}^{h}-J_{i},(n^{\prime}\in J_{i})\);
36:endwhile
37:\(\tau_{n,k}=\rho_{n,k}^{\text{tra}}\tau_{n,k}\);
38:endfor
39:endwhile
```
**Algorithm 1** Partite graph-based FL algorithm

During the operation of the partite graph-based D2D pairing scheme, when a server fails, it will be handled in two cases. First, if the server has been selected as a relay node, the scheme needs to proceed from step 10 of Algorithm 1 to re-select the relay nodes and further reconfigure the D2D pairing relations. On the other hand, if the server is not acting as a relay node, then the failed server only needs to be removed from the partite graph and stopped from sending its local model to its pairing server. When the network is split and some paired servers lose their pairing relationship due to unreachable communication, it is necessary to perform step 23 of Algorithm 1 to re-match relay servers for these independent client servers. ## 5 Graph Learning-Enabled D2D Pairing in Dataset-Correlated FL

When taking FL to obtain IoT application models, the information contained in the datasets collected by each agent may seriously affect the training performance. Moreover, the correlation between the datasets used by client agents may also affect the efficiency of the FL model aggregation. For instance, for using sensors to monitor mountainous areas and constructing their environmental models, the model generated by aggregating sensor datasets with overlapping or adjacent monitoring areas is always more accurate than the model corresponding to aggregating non-correlated areas.