## 4 Our Work
### Phase II (Post-Deployment Phase)
```
Input :
1 system state (\(X_{t}\)), battery levels (\(L_{t}\)), event generation process (\(E_{t}:\{p_{on},p_{off}\}\rightarrow\{flag_{on},flag_{off}\}\)), packet transmission rate (\(PR_{t}\)) and link quality (\(LQ_{t}\))
2 Data structure (\(DS_{j}\)):[\(X_{t}\), \(P_{tx}\)] Output :
3 Conditions for direct data delivery or multi-hop routing with optimal transmission power for sending data repeat
4 if (\(flag_{on}==true\))then
5\(receive((data)_{j})\) from upper layer with probability \(p_{on}\);
6 else
7\(receive((data)_{j})\) from upper layer with probability \((1-p_{off})\);
8
9 end if
10 if (\(data\))then
11\(flag_{off}=false\);
12\(Obtain(X_{t})_{j}\) as in Equation (6);
13\(Obtain(P_{tx})\) from \(DS_{j}\);
14 repeat
15\(Broadcast(SETUP\_REQ)\);
16 if\(Receive(SETUP\_RES\_SINK)\)then
17\(connectedToSink=True\);
18\(Destination=Sink\)
19 else
20\(Destination=Relay\)
21 end if
22 if\(Receive(SETUP\_REQ)\)then
23 if\((isSink||connectedToSink)\)then
24\(Send(SETUP\_RES)\)
25
26 end if
27
28 end if
29 if\((PR_{t}==0)\)then
30\(Send(data_{j})\) to Destination;
31\(flag_{on}=true\)
32
33 end if
34 if\((PR<PR_{th})\)then
35\(PR_{t}=0\);
36 else
37\(PR_{t}=1\);
38
39 end if
40 if\((LQ<LQ_{th})\)then
41\(LQ_{t}=0\);
42 else
43\(LQ_{t}=1\);
44
45 end if
46
47 untilforN data;
48
49 else
50\(flag_{off}=true\);
51\(flag_{on}=false\)
52
53 end if
54
55 untilevery\(t\) time slot;
```  
**Algorithm 1**EstimateTransmissionPower (). In the proposed algorithm, a node needs to execute simple local computations, conditional statements and simple table lookup that consume computation power denoted by \(e_{compute}\), \(e_{condition}\) and \(e_{lookup}\) respectively. As noted in step 10 of Algorithm 1, if a node finds data to transmit in its queue, it will perform simple computational steps to come up with suitable transmission power (throughsteps 11-13) and broadcasts setup request if sink information is not cached. After receiving setup reply, the node can assign the sink or relay information and send data accordingly with given transmission power if it is not heated (according to step \(28\) of Algorithm 1) Thus, to send data, following the algorithm, \((2\epsilon_{condition}+4\epsilon_{compute}+\epsilon_{lookup})\) is consumed initially and \((2\epsilon_{condition}+2\epsilon_{compute}+\epsilon_{lookup})\) is consumed if the destination information is cached. In other words, to send a single data packet the associated computational complexity of the proposed algorithm is O (1). However, if n messages are sent in between two successive setup phases the computational complexity becomes O (n). Thus, the nodes need not perform complex computational steps such as fuzzy logic as in [17] or linear programming as in [33]. These works involve distance calculation between the nodes that require incorporation of path loss models. Moreover, generation of routing query, fuzzy inference system [17] or linear programming [33] are not simple conditional and assignment statements. Instead, each of these models requires multiple assignment and conditional statements, loops etc. that makes the system computationally complex. Thus, MDP formulation in the pre-deployment phase makes the routing algorithm for the nodes simple as far as the calculation of transmission power and decisions about single-hop and multi-hop are concerned.