## 7 SMEP Algorithms
### AuxDataQueue Compression Algorithm
```
Constant
01_cmax: the maximum number of compressions
02 Global Variables
01_DataQueue[0.. 2^k_] _a data queue array for saving sensor data or compressing a sensor data sequence_
02_Zones[0.. - 1]; an array of zones with respect to DataQueue[0.. 2^m], where Zont[1] \(\leq\) cmax_
03_AuxDataQueue[0.. 2^2^m]_: an auxiliary data queue for the compressing a sensor sequence in the last \(m-1\) zone
04_ZoneBySeq[0.. - 1]: an array of pointers to nfr to 1-bit position sequences of the sensor data sequences corresponding to each zones_
05_ZoneCompHistory[0.. - 1, 1..cmax]; an array of pairs, [S, pIs, where ZoneCompHistory[i, c] = [S, p] and S and p are the sensor data value and its absolute position of the last c-th compressed sensor data in the zone i_
06_Ap: a variable for the absolution position of the latest ground sensor data Local Variables
01_DQix: an index variable for the latest sensor data insertion to DataQueue
02_ZNix: an index variable in Zones array
03_Procedure
04_1_for each \(k\) such that \(0\leq k\leq m-1\)do
05_Initialize Zones[k] = 0
06_for each \(l\) such that \(0\leq l\leq c\)max do
07_Initialize ZoneCompHistory[k], l = [ko, - 1]
08_endfor
09_endfor
07_Initialize Ap = 0, DQixx = 0, and ZNixx=0
08_while(true) do
09_Read a ground sensor data \(S_{0,Ap}\) from a sensor
101_Insert \(S_{0,Ap}\) into DataQueue[DQix];
11 if (\(DQix\leq 2^{m}\))
12_chen if (reactive(CRmessage) = true)
13_then return [DataQueue, Zones, ZonesBySeq, ZoneCompHistory, Ap]
14_else Set Ap=Ap+1, DQixx=Qixx+1
15_Continue
16_endif
17_else Set ZNix=un - 1
18_while(Zones[ZNixx-1] < Zones[ZNixx]) do
19_Set FFsute=LastZoneCompression[DataQueue, m)_
20_if(_IFState=FinisMap_)
21_then return [DataQueue, Zones, ZonesBySeq, ZonesCompHistory, Ap, AuxDataQueue]
22_endif
23_Set Zones[ZNixx]=Zones[ZNixx]+1
24_endwhile
25_Find \(Start=min\) [ \(k\) ] \(Zones[k]=Zones[ZNixx]\) ]
26_Set ZoneCompHistory[Start, ZoneStart] = EquivalentZonesCompression[DataQueue, StartZone, m)_
27_Set Zones[Start]=ZoneStart]+1
28_for each \(k\) such that Start + \(1\leq k\leq m-1\)do
29_Set Zones[k]=0
30_Set ZoneBySeq[k]=null
31_for each \(l\) such that \(0\leq l\leq ZoneSt\)do
32_Initialize ZoneCompHistory[k] = [ko, - 1]
33_endfor
34_endfor
35_Set DQix = \(\sum_{j=0}^{j-Start}2^{m-j-1}+1\)
36_endif
37_endwhile Endprocedure
```
**Algorithm 4**_Main SMEP (Selection by Minimum Error and Pattern)_

Then, the procedure calls the _EquivalentZonesCompression_ procedure to compress these zones into the start zone and it saves the return values, which are the last selected sensor data and its absolute position, to _ZoneCompHistory_ for the future compression preparation as the base sensor data and its absolute position of the next zone (procedure line 26). The procedure also increases one more the number of compressions of the last zone (procedure line 27) because the sensor data sequence in equivalent consecutive zones has been one more compressed into the start zone. As the sensor data sequence from the start zone to the last zone shrinks to only the start zone through the consecutive equivalent zones compression, the _DataQueue_ memory spaces corresponding to the remaining zones are empty and the first position of the immediate zone of the start zone is the beginning _DataQueue_ location to save the new ground sensor data. Thus, the procedure must initialize the data structure parts corresponding to these empty zones, such as the values from the immediate zone to the last zone in _Zones_, _ZoneBpSeq_, and _ZoneCompHistory_. The lines from procedure line 28 to line 34 reflect these initializations. The first position to save a new sensor data is calculated to the _DQinx_ variable in procedure line 35. ## 8 Compressed Sensor Data Decompression and Lost Sensor Data Recovery

The final consumers of the return values from _SMEP_ main are one or more destinations that receive the values via a wireless sensor network and one or more existing networks, and use them with their own purpose.