# A Pervasive Collaborative Architectural Model at the Network's Periphery
## 3 Collaborative Architectural Model of Mobile Pervasive Computing
### Constructing Connectivity Algorithms to Manage the APCAM Model  
The processes of synthesizing, managing and connecting materials in our network model are based on the following algorithms, which design the network as a series of mobile device groups. All the variables used in these algorithms are summarized in Table 2.  
(1) Algorithm 1 to calculate the score of device d: CalculatingScores(d): This algorithm, as presented in [54], calculates the score of each device based on five criteria. This score is required to select a group manager (or a group owner) and in the process of routing messages between devices. For the sake of clarity and completeness, it is described below. \begin{table}
\begin{tabular}{l l} \hline \hline
**Variable** & **Description** \\ \hline ValBattery & Battery energy \\ ValStock & Storage capacity \\ ValBandwidth & Bandwidth \\ ValRam & RAM capacity \\ ValCPU & CPU capacity \\ ValScore & Score value \\ PrcBattery & Percentage of battery influence \\ PrcStock & Percentage of storage influence \\ PrcBandwidth & Percentage of bandwidth influence \\ PrcRam & Percentage of RAM influence \\ PrcCPU & Percentage of CPU influence \\ lp\_d, ip\_q, or ip\_go & The IP address of device d, q or group owner \\ \(list_{d}(2,n)\) & An array of two rows and n columns for device d \\ \(n=list_{d}.length\) & Number of devices in \(list_{d}\) \\ tmp\_dvc & Temporary device \\ tmp\_scr & Temporary score \\ \hline \hline \end{tabular}
\end{table} 
Table 2: The variables of APCAM models and their description. Figure 5: A visualization of the APCAM Model. ```
Begin get factor capacity values of d; ValScore = ValBalattery * PrcBattery + ValStock * PrcStock + ValBandwidth * PrcBandwidth + ValRam * PrcRam + ValCPU * PrcCPU; return ValScore; End
```  
**Algorithm 1** CalculatingScores(d)  
Algorithm 2 that allows a device to create a list of its connected devices and their scores: This algorithm allows a device such as \"d\" to create a list of devices connected to it with their scores. When device \"q\" is connected to device \"d\", it sends its resource information to device \"d.\" Then, device \"d\" calculates the score of device \"q\" by applying the algorithm CalculatingScores(q), then it adds device q to its list identified by two parameters: IP address and score. ```
int i = 0, j = 0, score = 0; while connection is active and \(i\leq n\)// In case of Wifi and P2P, a group does not exceed n = 12 devices { If device q is connecting to device d { list_d[i][j] = \(ip\_q\);  score = CalculatingScores(q);  j = j + 1  if\(i[i][j]=score\);  i = \(i+1\);  j = \(j-1\); // value of j is 0 or 1, ex: list_d[0][0] = \(ip\_q\), // list_d[0][1] = \(score\), list_d[1][0] = \(,list_{d}[1][1]=\), etc. }//End if //End while Return list_d End
```  
**Algorithm 2** Creating_List_Devices_Scores(d)  
```
// sorting based on the scores int i, j, n, k; Begin \(n=list\_{d}\_length\);  For (i = n; i = 1; i -) { For (j = 2; j <= i; j ++) { k = 1; // rank of the line  If list_d[k][j][-1] > list_d[k][j] Then { tmp_scr = list_d[k][j-1];  tmp_dvc = list_d[k+1][j-1];  list_d[k][j-1] = [list]_d[k][j];  list_d[k][j] = tmp_scr;  list_d[k+1][j] = tmp_dvc; } End If } End For return list_d; End
```  
**Algorithm 3** Sorting_Devices_By_Scores (ip\({}_{d}\), list\({}_{d}\))  
```
// Find the list_d[k][j][-1] > list_d[



4. Algorithm 4 to select the group manager: Selecting_Group_Manager: Let us randomly choose one of the \(n\)-connected devices \(d_{i}\), \(i=1\),..., \(n\), to be the group owner (GO). It periodically receives data, including scores, from other members at various moments in time, such as every 5 min. At each of these moments, the GO begins to compare iteratively the scores of the members of its group. It starts by comparing itself with resources and scores such as \(d_{i}\) with \(d_{i+1}\). Consequently, the new GO becomes the device with the highest score. Again, by increasing index \(i\) by 1, the group owner GO will be compared with \(d_{i+1}\) to determine the new group owner until \(i=n-1\).