## 4 Intelligent Agent Algorithms
### Directional Source Packets for Multi-Agent Routing Planning
#### 4.2.1 Directional Source Grouping Algorithms  
As shown in Figure 10, PE area refers to the circular with radius \(\alpha R_{\text{max}}\) and the center of PE, \(R_{\text{max}}\) refers to the maximum transmission range (0,1). \(K\) refers to the number of neighbors of the source node in PE area. These nodes may become the starting nodes of each MA movement, as shown in Figure 10. When \(K=4\), up to four routes can be created by algorithm. Through controlling \(\alpha\) parameter, the size of PE region can be adjusted, so that the number of MA can be adjusted.  
Algorithm 2 is an algorithmic pseudocode for oriented source grouping. Firstly, the source node grouping (such as T) is initialized. \(Z_{PE}\) refers to the direct neighbor of Sink node in PE area, with radius \(SN_{j}\) (within \(R_{\text{max}}\)). As the algorithm iterates, the number of available start nodes decreases; \(Z_{PE}\)' refers to the remaining start nodes. If \(|Z_{PE}\)' = 1, all remaining nodes are selected into T. In Figures 3-12, \(\text{VCL}_{2}\) is selected to generate the second proxy route. And the node closest to \(\text{VCL}_{2}\) line in PE (such as node \(e\)) is selected as the initial node. Secondly, the center line of the directional sector can be obtained by connecting \(\text{VCL}_{2}\) and \(e\). As is shown in Figure 10, given the angle \(\theta\), the directional sector can be obtained.  
```
Input: V is the set of source nodes, CL is the central location of source nodes Output: T denotes the set of source nodes to be grouped, SN represents sensor node j within \(Z_{\text{pe}}\) Notation: V' is the set of remaining sources, part of which will be allocated to an MA. n is the total number of sources. \(\alpha\) is a constant, which is set to 70% in this paper. \(R_{\text{Max}}\) is the maximum transmission range of the sensor node. \(Z_{\text{pe}}\) is the PE-zone which includes the sink node and its one hop neighbors within a radius of \(\alpha R_{\text{Max}}\). SNj represents sensor node j within \(Z_{\text{pe}}\). K is the maximum number of the starting points for MA itineraries, K =\(|Z_{\text{pe}}|\). \(Z_{\text{pe}}=\left[\text{SNj}:\text{d}\left(\text{PE},\text{SNj}\right)\leq \alpha R_{\text{Max},j}=1,\ldots,\text{K}\right]\). \(Z_{\text{pe}}\) is the set of remaining starting points, one of which will be allocated to an MA. \(Z_{\text{j}}\) is the j-th directional sector zone for source-grouping. \(\theta\) is the selection angle of a directional sector zone. \(1\). \(\text{T}\leftarrow\left|\right|\); if \(\left|\right.Z\)\(\prime_{\text{pe}}\)= 1\(\left|\right|\)then \(\text{T}\leftarrow\text{V '}\); else for each SNj in \(Z\)' \(\prime_{\text{pe}}\) do  set line(VCL,PE) as the line connection PE and CL;  calculate the distance d(SNj, line(VCL,PE) between SNj and line(VCL,PE); if d (SNj, line(VCL,PE)) = min{d(SNk, line (VCL,PE)) } \(|\) SNk \(\in Z\)' \(\prime_{\text{pe}}\) \(|\) then  select SN+-SNj as the starting point;  break;
```  
**Algorithm 2** Directional source-grouping(V,CL).  
Figure 10: Explanation of Directional Source Grouping Algorithms.  
```
11 end if
12 end for
13 set line(SNj,VCL) as line connecting
14 partition Zj with line(SNj, VCL) as the central line, and \(\theta\) as the selection angle;
15 for each source v in V' do
16 if v \(\in Z_{\text{j}}\) then
17 T \(\leftarrow\) T \(\cup\) [v];
18 end if
19 end for
20 end if
21 return T and SN;
```  
**Algorithm 2**_Cont._