# An On-Demand Charging for Connected Target Coverage in WSRNs Using Fuzzy Logic and Q-Learning +
## 4 Fuzzy Q-Charging Algorithm
### Charging Time Determination  
We aim to design a charging strategy so that the number of sensors reaching a safe energy level is as big as possible after each charging round. Here, the safe energy level means the energy amount that is sufficiently greater than \(E_{th}\). We define the safe energy level, \(E_{sf}\), as  
\[E_{sf}=E_{th}+\theta E_{max}, \tag{5}\]  
where \(E_{max}\) is the maximum energy capacity of the sensors. \(\theta\) is an adaptive parameter, named safe energy factor, which is determined by Fuzzy logic. The algorithm determining \(\theta\) algorithm will be described in Section 4.4. A sensor node has the _critical status_ if its remaining energy is smaller than to \(E_{sf}\). The sensor with a critical status is named as _critical sensor_. Otherwise, a sensor node is called a _normal sensor_. For each charging location \(D_{i}\) (\(1\leq i\leq l\)), we want to determine the optimal charging time \(\mathcal{T}_{i}\) to minimize the number of critical sensors. We adopt the multi-nodes charging model, in which the MC can simultaneously charge to all sensors. We leverage the charging model proposed in [31], which has been widely used in most research in the WRSN-related studies. This model follows the RF-power harvesting. The authors in [31] have performed experiments to verify the model in the real environment. Following the experiment results shown in the paper, the charging  
Figure 4: An illustration of the Q-table. energy is about \(12\times 10^{-4}\) W when the distance is 1.6 m. According to [31], the per second energy that a sensor \(S_{j}\) is charged when the MC stays at \(D_{i}\) is given by  
\[p_{j}^{i}=\frac{\lambda}{(d(S_{j},D_{i})+\beta)^{2}}, \tag{6}\]  
where \(\lambda\) and \(\beta\) are known constants decided by the hardware of the charger and receiver. \(d(S_{j},D_{i})\) is the Euclidean distance between \(S_{j}\) and \(D_{i}\). We denote \(e_{j}\) as the energy consumption rate of \(S_{j}\), which is estimated by the MC. Suppose that the MC charges \(S_{j}\) at \(D_{i}\), we denote the remaining energy of \(S_{j}\) when the charging process starts and finishes as \(E_{j}\) and \(E_{j}^{{}^{\prime}}\), then \(E_{j}^{{}^{\prime}}=E_{j}+(p_{j}^{i}-e_{j})\times\mathcal{T}_{i}\). At the charging location \(D_{i}\), we call \(p_{j}^{i}-e_{j}\) the _energy gain_ of \(S_{j}\). The remaining energy of \(S_{j}\) will increase if its energy gain is positive and decreases otherwise. Note that the energy of \(S_{j}\) equals the safety energy level, if the charging time equals to \(\frac{E_{sf}-E_{sf}}{p_{j}^{i}-e_{j}}\), which is named as the _safety charging time_ of \(S_{j}\) with respect to the charging location \(D_{i}\) and denoted as \(\Delta_{j}^{i}\). The sensors can be classified into four groups. The first and second ones contain normal sensors with positive energy gain and critical sensors with negative energy gain, respectively. The third and fourth groups contain normal sensors with negative energy gain and critical sensors with positive energy gain, respectively. Obviously, the first and second groups' sensors do not change their status no matter how long the MC charges at \(D_{i}\). In contrast, a sensor \(S_{j}\) in the third group will fall into the critical status, and a sensor in the four groups can alleviate the critical status, if the charging time \(\mathcal{T}_{i}\) is greater than or equals to its safety charging time, i.e., \(\mathcal{T}_{i}>\Delta_{j}^{i}\). Hereafter, we call the sensors in the third group _negative normal sensors_ and the sensors in the fourth group _positive critical sensors_. Let \(e_{1},e_{2}\) denote the number of sensors belonging to the third and fourth groups whose status changes after being charged (from critical to normal and vice versa). It is worth noting that the greater the value of \(\mathcal{T}_{i}\), the greater \(e_{1}\), and the greater \(e_{2}\), also. Our objective is to determine the optimal value of \(\mathcal{T}_{i}\) to maximize \(e_{1}-e_{2}\). This goal can be achieved by using the following algorithm.