## 3 Control Layer Architecture
### Context Measurements Aggregation  
Considering \(\{n_{1},\ldots,n_{z}\}\) as the set of nodes in the network at time \(t\), we represent the aggregated context measurement generated by node \(n_{i}\) for \(1\leq i\leq z\) as the tuple \(m_{i}=(v_{i},\eta_{i},t_{c_{i}})\), where \(v_{i}\) is the aggregated result, \(\eta_{i}\) is the number of measurements used for the calculation of \(v_{i}\), and \(t_{c_{i}}\) is the time when the calculation was made. The node \(n_{i}\)'s local context measurement is represented as \(m_{l_{i}}=(v_{l_{i}},1,t_{c_{i}})\), where \(\eta_{i}=1\) as \(v_{l_{i}}\) is a straight reading, not the result of an aggregation.  
The process that performs the aggregation is _getAggregatedContextMeasurement_ (_line 2_) in Algorithm 1. First of all, the node \(n_{i}\) gets the local context reading, \(v_{l}\) (_line 2_). The node uses a two-factor weighted average to aggregate all the context measurements stored in  
Figure 2: Context measurements dissemination when two nodes are in range.  
\(M_{i}\) and its own context reading \(v_{l}\). Each of the context measurements (\(m_{j}\)) stored in \(M_{i}\) is weighted by two factors: (1) the number of aggregations used to create it (\(\eta_{j}\))--in the case of the local measurement, this value would be 1--and (2) its decay (\(d_{j}\)) at the current time \(t\). In the case of the local measurement, the decay would be 1 (no decay).  
The following logistic function calculates the decay of a measurement at time \(t\):  
\[d(t)=\frac{1}{1+r^{2}t} \tag{1}\]  
where \(r\) is the reduction factor or decay degree to apply to obtain a certain decay. By isolating this variable we obtain:  
\[r(t)=\bigg{(}\frac{1-d}{td}\bigg{)}^{\frac{1}{2}}. \tag{2}\]  
This resulting equation is used to obtain the necessary decay degree (\(r\)) to be used in (1) to obtain the desired decay at a particular time \(t\). The decay is inversely proportional to time (\(t\)), and it ranges from 0 to 1, where a decay of 1 means no decay. With a decay of 1, the congestion reading is not lowered when aggregated. In contrast, the older the reading is, the higher the decay (lower value), hence the more diminished the reading is when the controller aggregates it along with the other readings received during the aggregation interval.  
The aforementioned two-factor weighted average used to aggregate the context measurements in \(M_{i}\) along with the perceived local context reading \(v_{l}\) (_lines 33-41_) is:  
\[v_{i}=\sum_{j=1}^{k}v_{j}(\alpha\frac{\eta_{j}}{\sum_{p=1}^{k}\eta_{p}}+(1- \alpha)\frac{d_{j}}{\sum_{p=1}^{k}d_{p}}) \tag{3}\]  
where \(v_{i}\) is the value resulting from this aggregation; \(k\) is the size of \(M_{i}\) plus one (to include the local context reading), \(v_{j}\) is the _value_ of the measurement being aggregated (\(m_{j}=M_{i}[j]=(v_{j},\eta_{j},t_{c_{j}})\)); \(\eta_{j}\) is the number of aggregations used to generate \(m_{j}\), \(d_{j}\) is the decay of \(m_{j}\) at the current time, and \(\alpha\) is the weight factor, specified as a control setting (see Section 5.4.2), used to weigh the two factors of the weighted average. The function _getSumOfNrofgAsgts_ at _line 17_, calculates the normalizing factor applied in (3) over the number of aggregations the context measurement being processed is formed by (\(\sum_{p=1}^{k}\eta_{p}\)). Similarly, the function _getSumOfDecays_ (_line 1_) calculates the normalization factor to be applied over the decay of a measurement (\(\sum_{p=1}^{k}d_{p}\)).  
Finally, the node \(n_{i}\) creates the aggregated measurement \(m_{i}=(v_{i},\eta_{i},t_{c_{i}})\) where \(v_{i}\) is the calculated aggregation value, \(\eta_{i}\) is the number of entries in \(M_{i}\) that have been aggregated plus the node's own reading (_lines 32, 39_), and \(t_{c_{i}}\) is the current time. At this point, _step 3_ in the flowchart in Figure 2, the calculated aggregated measurement \(m_{i}\) is transferred to the contacted node.