# On-Demand Charging Management Model and Its Optimization for Wireless Renewable Sensor Networks
## 4 Implementation of Proposed ERMS-PSO
### Energy Renewable Management System (ERMS)
The value ethesh is the allowable threshold of energy, which must be higher than the emin but lower than the \(E_{max}\). \(E_{max}\) is a safe charging value that ensures the continuous lifetime of the network while minimizing the charging time. By communication, when the first node reaches the low battery energy level \(e_{min}\) in Equation (12), it initiates a charging request for the WMCD; then, the base station queries all the nodes and identifies nodes with battery energy less than the allowable energy threshold \(e_{thresh}\) (Equation (13)); these nodes are lined up as target nodes. The WMCD is required to visit these target nodes in the particular charging cycle. Reference [13] showed that the TSP charging route improves the energy efficiency of the WMCD, but it is believed that this increases the waiting time of the nodes to be charged because some nearby nodes may possess more battery life while some far-away nodes are at the verge of being extinguished. When the WMCD visits each of the target nodes, it charges the battery in the node to the \(E_{max}\). Our two energy variables are calculated as follows:  
\[e_{min}=E_{min}+\left(E_{max}-E_{min}\right)*X_{1} \tag{12}\]  
\[e_{thresh}=E_{min}+\left(E_{max}-E_{min}\right)*X_{2} \tag{13}\]\[0\leq X_{1},\ X_{2}\leq 1\]  
These particular recharging thresholds \(0\leq X_{1},\ X_{2}\leq 1\) are shared by all network nodes. If \(P_{max}\) and \(P_{min}\) are the energy consumed by the node with the highest data rates and the lowest data rates, respectively, then the minimum and maximum charging time in a single operating cycle can be evaluated as follows:  
\[T_{min}=\frac{(E_{max}-E_{min})}{P_{max}} \tag{14}\]  
\[T_{max}=\frac{(E_{max}-E_{min})}{P_{min}} \tag{15}\]  
Thus, if the nodes are fully charged, it will take \(T_{min}\) time before the first charging request is sent and \(T_{max}\) before the last charging request is sent. To demonstrate the link between the solutions to the two challenges, the proposed strategy initially sets the WMCD at the site of the base station. Vacation refers to the state in which the mobile recharger is stationed at the sink node. During the vacation state, the mobile recharger:  
1. [label=()]
2. Recharges its battery;
3. Replaces its battery;
4. Becomes aware of the received recharging requests. Denote g as the number of sets to be classified, which is set up as follows:  
\[g=log_{2}\frac{T_{max}}{T} \tag{16}\]  
During this phase, we establish the charging period \(T_{i}\) for every node \(i\) and categorize the set \(Z_{k}\). To begin, we set each node \(i\) (\(i\in\) N)'s charging period \(T_{i}\) as:  
\[T_{i}=2^{a-1}*T\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (1\leq a\leq g) \tag{17}\]  
Here, \(a\) is the approximate logarithm of the \(T_{i}\) and \(T\) ratio, obtained as follows:  
\[a=log_{2}\bigg{(}\frac{E_{max}-E}{p_{i}*T}-1\bigg{)}+1 \tag{18}\]  
We define set \(Z_{k}\) (\(1\leq k\leq g\)) and let \(i\in Za\); the WMCD will visit node \(i\) in the (\(n\times 2^{a-1}\))th trip cycle. During the Lth cycle and the design of the WMCD's travel path, we can obtain \(F_{j}\), which is the set of sensor nodes that should be charged in the \(L\)th cycle. We can express \(L\) (\(1\leq L\leq 2^{8-1}\)) as \(j=n\). \(2^{\circ}\), where \(n\) is an odd number and can integer and, here, \(c\geq 0\). \[F_{j}=\left\{ \begin{array}{cc}Z_{1}&(c=0)\\ Z_{1}\cup Z_{2}\cup Z_{3}\ldots.Z_{c+1}&(c\geq 0)\end{array} \right. \tag{19}\]  
The steps explained above are given in the Algorithm 1 below.