## 4 Proposed Approach
### Priority Assignment Unit
#### 4.3.1 Priority Association Module  
Sensor nodes are scattered over a Smart City to retrieve some kind of information. As defined before, it is assumed in this article that sensor nodes are fixed and do not move during the network operation time. For any event \(e=(p,x_{1},y_{1},x_{2},y_{2})\), a sensor \(s=(p,c,x,y)\) may be located inside or outside the rectangle defining the influence area of an event \(e\). If the sensor \(s\in S\) is inside that rectangle, it receives the same priority associated to that event (\(s.p=e.p\)). The Priority Association module computes a list of all sensors with the corresponding priorities, \(PS\). To reduce the number of information that has to be inserted into the network, only modifications of priorities need to be transmitted. For that, \(PS\) contains only the sensors that need to have a new priority assignment, since sensors in the network keep the same priority until a new priority assignment is performed (priorities do not expire). When a list of events is received from the Priority Computing Unit every \(\Delta_{t}\) seconds, defined as \(EoI\), the Priority Association module processes it for all sensors, associating each of the selected sensors to the proper priority, as specified in the Priority Association Algorithm (Algorithm 2). One should note that the PAA is valid for a single WSN, but, for multiple wireless sensor networks, this algorithm has just to be executed for each considered network, since the proper parameters are supplied. ```
Input:\(EoI\)//List of all detected and classified events Input:\(S\)//List of all deployed sensors Input:\(C\)//Persistence parameter for the network Input:\(P_{min}\)//Lowest priority Output:\(PS\)//List of sensors that need assignment of a new priority
1\(PS\leftarrow\emptyset\)
2 foreach\(s\in S\)do
3\(p=0\)
4 foreach\(e\in EoI\)do
5 if\(isInside(s,e)\)then
6 if\(p<e.p\)then
7\(p=e.p\)
8 end if
9
10 end for
11
12 end for
13 if(\(p>0\)) AND (\(s.p\
eq p\))then
14 \"Sensors that must to be assigned to a new priority greater than 0\"
15\(s.p=p\)
16\(s.c=C\)
17\(PS.insert(s)\)
18 elseif(\(p==0\))then
19 if(\(s.c==1\))then
20 \"Sensors that must to be assigned to a new priority equal to 0\"
21\(s.p=P_{min}\)
22\(s.c=0\)
23\(PS.insert(s)\)
24 else
25\(s.c=(s.c-1)\)
26
27 end if
28 return\(PS\)
```  
**Algorithm 2**Priority Association Algorithm (PAA)  
As can be seen in Algorithm 2, sensors are always associated to the highest priority of the detected events (line 13). If a sensor is inside the area of influence of more than one event of interest (line 5), it is associated to the highest priority value among those events (lines 4-10). This is performed because sensors must be associated to the priority of the most relevant event, in the case sensors are under the influence of more than one event of interest, keeping the network operation reasonable for event-based optimizations. To avoid unnecessary transmission of messages over the network, only new priorities (lower or higher) will be assigned to sensor nodes. In other words, if a sensor is under the influence of only an event in time \(t\) and it is under the influence of only the same event on time \(t+\Delta_{t}\), it is not necessary to \"refresh\" the assigned priority to that sensor node, since priorities do not expire. By doing so, the number of control messages transmitted to the considered wireless sensor network is reduced. The PAA does not change the values of \(s.p\) and \(s.c\) of such sensors, nor it includes those sensors in _PS_. When an event is detected, sensors inside the rectangle of the area of influence of that event are associated to the event's priority. It is natural to expect that sensors will keep that priority until they are associated to a new event. However, if a sensor is not associated to at least one event, it should be assigned to the lowest priority, \(P_{min}\) (line 19).