## Appendix B Algorithm of Time Allocation for the Proxy Nodes
```
Function:timeAllocate(\(KSD,\Upsilon,T_{slot}\)) /* allocate times slots and assign proxy nodes to them, given the expected amount of data is maximized */ input :\(KSD\): set of key stationary durations; \(\Upsilon\): time length of data gathering; \(T_{slot}\): minimal data gathering duration output :\(\Psi\):\(compatible\) schedule of data gathering
1\(ps\)=\(\phi\); /* ps: set of points from the key stationary durations */
2 foreach\(ksd\) in \(KSD\)do
3\(ps.\)add(\(ksd.t_{n}\)); /* \(t_{m}\): begin point of the key stationary duration */
4\(ps.\)add(\(ksd.t_{n}\)); /* \(t_{n}\): end point of the key stationary duration */
5 sort(\(ps\)); /* sort the points in ascending order */
6\(maxAmount=0\) /* maximal expected amount of data */
7\(p\)=\(ps.\)next(); /* get the next point from the set */
8 while\(p\)!=\(\phi\)do
9\(SLOT=\)split(\(p,\Upsilon,T_{slot}\)); /* get slots starting at \(p\) */
10\(nodes=\phi\);
11\(amount=\)getAmount(\(p,SLOT,knodes\)); /* get the maximal expected amount of data and node assignment when data gathering starts at \(p\) */
12 if\(amount>maxAmount\)then
13\(maxAmount=amount\);
14\(\Psi=\)new\(schedule(p,SLOT,nodes)\);
15\(p=ps.next()\);
16 return\(\Psi\);
```  
**Algorithm B2** Get expected amount of data  
```
Function:getAmount(\(p,SLOT,\&nodes\)) /* get the maximal expected amount of data */ input :\(p\)start point of data gathering; \(SLOT\): set of slots; output :\(max\): expected amount of gathered data; \(\&nodes\): set of proxy nodes assigned to \(SLOT\)
1\(max=0\);
2 if\(SLOT==\phi\)then /* exit the recursion when \(SLOT\) is empty set */
3\(max=0\);
4 return\(max\);
5 foreach\(slot\) in \(SLOT\)do
6\(proxies=\)availeProxies(\(slot,nodes\)); /* get available proxies that could be assigned to \(slot\) */
7 if\(proxies!=\phi\)then
8\(array\)=new\(int[proxies.size()+1]\); /* temp array recording the expected amount of data on \(proxies.size()+1\) cases */
9\(array[0]=max\); /* array[0]: the amount when current \(slot\) is not assigned */
10\(p^{\prime}=p+|slot|\); \(SLOT^{\prime}=SLOT-slot\);
11 for\(i\) in \([1,proxies.size()]\)do /* for each possible case, move forward and record the expected amount of data */
12\(ns=nodes.copy()+proxies[i]\);
13\(array[i]=proxies[i].amount()+\)getAmount(\(p^{\prime},SLOT^{\prime},ns\));
14\(k=array.indexofmax()\); /* get the index of maximal element in \(array\) */
15 if\(k==0\)then /* get the maximal if\(slot\) not assigned */
16\(nodes.add(null)\);
17
18 else /* assign proxy node to \(slot\) */
19\(max+=proxies[k].amount()\);
20\(nodes.add(proxies[k])\);
21
22
23 else /* no proxy nodes are assigned to current \(slot\) */
24\(nodes.add(null)\);
25\(p+=|slot|\); \(SLOT-=slot\); /* move forward to next slot */
26 return\(max\);
```  
**Algorithm B3** Get expected amount of data  
```
Function:getAmount(\(p,SLOT,\&nodes\)) /* get the maximal expected amount of data */ input :\(p\)start point of data gathering; \(SLOT\): set of slots; output :\(max\): expected amount of gathered data; \(\&nodes\): set of proxy nodes assigned to \(SLOT\)
3\(max=0\);
4 return\(max\);
```  
**Algorithm B4** Get expected amount of data  
```
Function:getAmount(\(p,SLOT,\&nodes\)) /* get the maximal expected amount

+++ ==WARNING: Truncated because of repetitions==
of data */ input :\(p\)start point of data gathering; \(SLOT\): set of slots; output :\(max\): expected amount of gathered data; \(\&nodes\): set of proxy nodes assigned to \(SLOT\)
5\(max=0\);
6 if\(SLOT==\phi\)then /* exit the recursion when \(SLOT\) is empty set */
7\(max=0\);
8 return\(max\);
```  
**Algorithm B5** Get expected amount of data  
```
function:getAmount(\(p,SLOT,\&nodes\)) /* get the maximal expected amount of data */ input :\(p\)start point of data gathering; \(SLOT\): set of slots; output :\(max\): expected amount of gathered data; \(\&nodes\): set of proxy nodes assigned to \(SLOT\)
9\(max=0\);
10\(max=0\);
11\(max=0\);
12\(max=0\);
13\(max=0\);
14 return\(max\);
```  
**Algorithm B5** Get expected amount of data  
``` function:getAmount(\(p,SLOT,\&nodes\)) /* get the maximal expected amount of data */ input :\(p\)start point of data gathering; \(SLOT\): set of proxy nodes assigned to \(SLOT\)



++

## References

* (1) [PERSON]; [PERSON]; [PERSON]; [PERSON] Data mules: Modeling and analysis of a three-tier architecture for sparse sensor networks.