# An Energy-Efficient Approach to Enhance Virtual Sensors Provisioning in Sensor Clouds Environments
## 4 The Proposed Approach
### ACASIMv2--Adaptive Clustering Algorithm Based on Similarity  
Figure 5 depicts how the ACASIMv2 works. First, the middleware receives a new user query \(QUERY_{i}\). Then, the middleware searches in its local database for all active physical sensor nodes deployed in the interest region specified in the request parameters. Then, for each _dimension_, the middleware repeats the following procedure. Initially, each sensor node is treated as an individual cluster and its identifiers (ids) are added to a list called _list_clusters_. An empty list, called _compared_clusters_, is created and has the purpose of storing the clusters already compared. Next, the algorithm enters a loop and will be interrupted only when there are no longer any pairs of clusters that have not been compared. If there is at least one pair of non-compared clusters, the algorithm computes, based on Euclidean distance, the two nearest clusters (labeled \(A\) and \(B\)). Then, the algorithm takes the values of the measurements of the clusters' nodes and computes the mean (\(\overline{X}\)) and the standard deviation (\(\sigma\)). If the value of \(\sigma\) is below a predefined \(THRESHOLD\) value for that dimension, then the two clusters are merged into another cluster labeled \(C\). The new Cluster \(C\) is added to the _list_clusters_ list and the set (A,B) is added to the _compared_clusters_ list. This process is repeated until there are no more clusters to be compared. At the end of the clustering procedure, there will be clusters of sensor nodes for each _dimensions_, as depicted in Figure 4. In sequence, the middleware executes ACOSIMv2 to choose the sensor nodes to create the virtual sensors. The middleware then generates a model of the measurements, based on the ASLR algorithm [51], and sends to the sensors nodes. The objective is to exploits the temporal correlation between the measurements and executes ACASIMv2 as soon as there is some change in the environmental conditions. The sensor nodes, after received the models, compare the values of each new measurement with the value generated by the model. If there is a significant difference, the sensor node sends an alert to the middleware in order to rebuild the groups. Figure 6 depicts how the clustering process works. For the sake of simplicity, it considers measurements from one _dimension_ (i.e., temperature). There are five sensor nodes and the similarity of their measurements is represented by their relative position in the image (which does not necessarily correspond to their physical location). Thus, the closer the two sensor nodes, the more similar their measurements. Initially, the sensor nodes correspond to individual clusters (Figure 6a). Then, the ACASIMv2 estimates that \(A\) and \(B\) are the two closest groups and that the standard deviation of their measurement is below the predefined \(THRESHOLD\) for that dimension. In this case, \(A\) and \(B\) are  
Figure 4: AC\(\times\)SIMv2’s basic operation. merged into a new group (Figure 6b). In Figure 6c, the new group \((A,B)\) is also merged with \(C\), as the standard deviation of measurements \(A\), \(B\), and \(C\) was also below the threshold. As \(D\) and \(E\) are the two closest groups and the standard deviation of their measurements is also below the threshold, they are merged to form another group (Figure 6d). In Figure 6e, the ACASIMv2 attempts to merge the groups (\(A\),\(B\),\(C\)) and (\(D\),\(E\)). However, as the standard deviation of measurements from all sensor nodes is above the threshold, the groups are not merged (Figure 6f). Differently from our previous work [20], in ACxSIMv2, it is possible to configure different \(THRESHOLD\) values for each dimension, in order to reflect the difference between the range values and/or users' interest. For example, considering the Green Orb dataset, where temperature ranges from 13 \({}^{\circ}\)C to 31 \({}^{\circ}\)C and humidity ranges from 18% to 55%, some user could accept an error of \(\pm\)0.5 \({}^{\circ}\)C on temperature and \(\pm\)2.0% on humidity.