## 4 Fuzzy Logic Model
### Inference Engine  
The most common way to represent human knowledge in the field of artificial intelligence is to show the knowledge as natural language expressions, such as _IF premise (antecedent)_, _THEN conclusion (consequent)_, where the premise is composed of fuzzy input variables connected by logical functions and consequent result is a fuzzy output variable. The _IF-THEN_ rule-based knowledge representation is based on natural language representations and models, which are themselves based on fuzzy sets and fuzzy logic. Thus, the fuzzy engine calculates the value of the output variables based on rules that capture the experts' knowledge of the controlled system. In the proposed fuzzy controller, the output variables _Active mode_ and _ETR_ indicate the scale of change imposed by fuzzy inference rules, as shown in the membership function in Figure 2. In the proposed scheme, the rules indicate that the linguistic variables are changing for the _Active mode_ and _ETR_ based on the crisp values of input variables, as shown in Table 1. The inference engine performs different calculations in fuzzy logic-based systems. In this paper, the Mamdani inference engine [25] works with the input of a Mamdani fuzzy logic system, that is a crisp value. Thus, the input fuzzy values from the fuzzification stage apply to all fuzzy rules by the inference engine. The control output derived from the combination of input, output membership functions and fuzzy rules are still a fuzzy element. To make fuzzy output accessible to real applications, a defuzzification process is required. In order to guarantee the network lifetime \(\alpha\), the integration of fuzzy logic with the decision process is proposed in this section. In the proposed fuzzy controller scheme, the output variable selection directs the scale of change imposed to the active or sleep mode of a sensor node. The ratio of active time \(A_{Time}\) to \(\alpha\) represents an optimal energy consumption rate. If a sensor node consumes energy with this rate, the node will remain alive until the required lifetime. Let \(\gamma\) represent the difference between the optimal and the computed energy consumption rates. Figure 2: Comparison of fuzzy set, crisp selection and fuzzy selection. \[\gamma = \frac{A_{Time}}{\alpha}-\frac{E_{con}}{\beta} \tag{1}\]  
In Equation (1), the ratio of energy consumption \(E_{con}\) and initial energy \(\beta\) represents the energy consumption rate of a sensor node in the current and previous round, respectively. If \(\gamma\geq 0\), then a sensor node is regarded to have more remaining energy to last for the required guaranteed lifetime \(\alpha\) at the cost of the optimal energy consumption rate. If \(\gamma<0\), then a sensor node has already consumed more energy, so it cannot remain alive until \(\alpha\) with the current energy consumption rate. Thus, the sensor node having \(\gamma<0\) is expected to go into sleep mode for the next round to save its energy towards \(\alpha\). The input descriptors, energy and active time, in a proposed fuzzy control system have the linguistic values _VL_, \(L\), \(M\), \(H\) and _VH_, and the membership functions are shown in Figures 3 and 4a. The membership functions indicate that if the energy and active time of a sensor node increases or decreases, the change occurs accordingly. The fuzzy controller output becomes successful if each sensor node \(i\) has remaining energy greater than zero and unsuccessful if any node \(i\) exhausts its energy level. The proposed scheme ensures that a fuzzy controller keeps the energy consumption balance among sensor nodes to achieve \(\alpha\). Figures 3 and 4a show the degree of membership functions for the inputs and outputs of energy and active time, respectively. To consider each node's energy and active time, the fuzzy controller assigns a triangular fuzzy value that specifies the range for a given level instead of a particular discrete value.