# On-Demand Charging Management Model and Its Optimization for Wireless Renewable Sensor Networks
## 4 Implementation of Proposed ERMS-PSO  
### Energy Renewable Management System (ERMS)  
ERMS implementation consists of two primary steps. The initial stage is to optimize the first part of the total energy usage \(\sum_{i,j\in N}p_{i}\) Secondly, we create a collaborative design to reduce the WMCD's trip distance. The flow rate from node \(i\) to node \(j\) is represented by \(W_{ij}\), the flow rate from node \(i\) to base station BS is represented by \(W_{\beta}\), and \(W_{\beta}\) represents the bit flow rate coming from node \(k\) to \(i\) and. The flow balance constraint is then applied to each node \(i\) (Equation (6)). \[\sum_{k\in N}^{k\
eq i}w_{ki}+R_{i}=\sum_{j\in N}^{j\
eq i}w_{ij}+w_{iB} \tag{6}\]  
where \(\sum_{j\in N}^{j\
eq i}w_{ij}+w_{iB}\) represents the data flow rate of energy transmission from node \(i\) to \(j\) or the base station, and \(\sum_{k\in N}^{k\
eq i}w_{ki}\) is the data flow rate of energy reception from node \(k\) to \(i\). To transmit and receive data, each sensor node consumes energy. We use the energy consumption model [16] in this article, which has been widely used in previous studies [12; 13; 14]. \[p_{i}(t)=\rho\sum_{k\in N}^{k\
eq i}w_{ki}+\sum_{j\in N}^{j\
eq i}v_{ij}\cdot w _{ij}+v_{iB}\cdot w_{iB} \tag{7}\]where \(\rho\) is the constant coefficient, and \(V_{ij}\) and \(V_{iB}\) are the energy consumption for transmitting a unit of data from node \(i\) to node j or the base station, respectively, which is expressed as follows:  
\[V_{ij}=\beta_{1}+\beta_{2}\cdot d_{ij}^{\alpha} \tag{8}\]  
Here, \(\beta_{1}\) is a distance-independent constant term and \(\beta_{2}\) is a distance-dependent term coefficient, \(d_{ij}\) describes the distance between nodes \(i\) and \(j\), while \(\alpha\) is the path-loss index and is \(2\leq\alpha\leq 4\). We can develop a non-linear function of the BS position (\(X_{B}\), \(Y_{B}\)) from Equation (7):  
\[V_{iB}=\beta_{1}+\beta_{2}\bigg{[}\sqrt{\left(X_{B}-X_{i}\right)^{2}+\left(Y_{ B}-Y_{i}\right)^{2}}\bigg{]}^{\alpha} \tag{9}\]  
The energy consumption rate for reception in this model is \(\rho\sum_{k\in N}^{k\
eq i}w_{ki}\), while the energy consumption rate for transmission is \(\sum_{j\in N}^{j\
eq i}v_{ij}\cdot w_{ij}+v_{iB}\cdot w_{iB}\) We assume that the network's flow rates (\(W_{ij}\) and \(W_{iB}\)) are time-invariant. The optimization goal is to minimize the total energy consumption of nodes (i.e., \(\sum_{i,j\in N}p_{i}\)), which is the first part of \(P_{total}\) in Equation (4). Each node must meet the basic flow balancing constraint in Equation (6), as well as the energy consumption model in Equation (7). As a result, the optimal problem can be expressed as a linear programming problem as follows:  
\[ \begin{array}{ll}\min&\sum_{i\in N}p_{i}\\ \text{s.t.}&\sum_{k\in N}^{k\
eq i}W_{ki}+R_{i}=\sum_{j\in N}^{j\
eq i}W_{ij}+ W_{iB}\quad(i\in N)\end{array}  \tag{10}\]  
\[ \begin{array}{ll}p_{i}(t)=\rho\sum_{k\in N}^{k\
eq i}w_{ki}+\sum_{j\in N}^{j \
eq i}v_{ij}\cdot w_{ij}+v_{iB}\cdot w_{iB}\\ &W_{iB}\geq 0\end{array}  \tag{11}\]  
The optimization variables in this problem are \(W_{ij}\), \(W_{iB}\) and \(p_{i}\), while constants are \(R_{i},\rho,~{}v_{ij}\), and \(v_{iB}\). After solving the optimization problem in Equations (10) and (11), the energy consumption rate \(pi\) can be determined for each node \(i\). In this section, we develop a system that combines the charging period \(T_{i}\), the visiting set \(Cth\) in each cycle and the WMCD traveling path. This work aims to solve the problem of WET by investigating the mobile charging request strategy, where two sets of variables are introduced: \(e_{min}\) and \(e_{thresh}\). If the maximum energy in the battery of nodes is \(E_{max}\) (usually 10.8 KJ) and the minimum energy is \(E_{min}\) (usually 0.05 \(\times\)\(E_{max}\)), then the \(e_{min}\) is a low battery indicator, which must be higher than the \(E_{min}\) value, at which the nodes eventually die. The value of \(e_{min}\) is carefully selected to ensure that the nodes in WSN never approach \(E_{min}\).