# Fuzzy-Based Multi-Modal Query-Forwarding in Mini-Datacenters
## 4 Modeling the Query Flow Within the Mini-Datacenter
### Modeling Fine-Grain Forwarding
#### 4.2.1 Modeling Redundancy  
A redundant query flow enhances the system's reliability by creating backup channels for data and commands. We have modeled the redundancy based on two factors: the buffer capacity of gateways and the backlog of incoming queries in the command center's queue. A redundant gateway list is defined to hold the fitted gateways, where the fitness \(\Fit(g_{i})\) of each gateway \(g_{i}\) at a given time t evaluates its readiness to handle additional traffic. This is determined by the gateway's current buffer occupancy \(B_{i}(t)\), relative to the maximum buffer capacity \(B_{max}\), as stated in Equation (2). The fitness value ranges from 0 to 1, and it is defined in a piecewise manner to account for varying levels of buffer occupancy:  
* When the buffer capacity of the gateway is less than or equal to half of the maximum capacity, the fitness is equal to 1, representing a state where the gateway has sufficient capacity.
* As the buffer occupancy increases from 50 to 100%, the fitness value decreases proportionally.
* Once the buffer is full, the fitness becomes equal to 0, indicating that the respective gateway cannot accept further data. This formulation ensures that gateways with sufficient buffer space are preferred for redundancy, while those nearing saturation are gradually excluded from the forwarding process.  
\[\Fit(g_{i})=\left\{\begin{array}{ll}1&if\ B_{i}(t)\leq 0.5*B_{max}\\ 1-\frac{B_{i}(t)-0.5*B_{max}}{0.5*B_{max}}&if\ 0.5*B_{max}\leq B_{i}(t)\leq B_{ max}\\ 0&if\ B_{i}(t)=B_{max}\end{array}\right. \tag{2}\]  
The gateways in the redundant list are sorted based on their fitness values, and those with a fitness value greater than a selected threshold (_th_) are designated as fitted gateways, as presented in Equation (3). The threshold value is determined according to the sensitivity requirements of the selected application, such as its accuracy or responsiveness.  
\[G_{fitted}(t)=\left\{\ g_{i}|Fit(g_{i})>th\right\} \tag{3}\]  
We have added the influence of incoming query backlog at the command center (CC) on redundancy by introducing a gamma factor \(\gamma(t)\), as stated in Equation (4). A high backlog may indicate a surge in queries awaiting processing. At this point, selecting all fitted gateways will ramp up the buffer occupancies, leading to delays or data loss. To mitigate this, the gamma factor \(\gamma(t)\) is modeled as a decreasing function that reduces the proportion of redundant gateways selected as the CC backlog \((BkLog_{CC}(t))\) increases. The term \(\alpha\) is a constant that controls the sensitivity of \(\gamma(t)\) to changes in the backlog, and the term \(BkLog_{CC}(t)\) represents the current query backlog at the command center at time \(t\). The term \(q_{\max}\) refers to the maximum queue capacity of the CC's input queue, while the term \(q_{occupancy}(t)\) refers to the current occupancy of the queue. The gamma factor \(\gamma(t)\) ranges from 0 to 1, representing the system's adaptation from maximum backlog to no backlog.  
\[\gamma(t)=\frac{1}{1+\alpha*BkLog_{CC}(t)}*\left(1-\frac{q_{occupancy}(t))}{ q_{max}}\right) \tag{4}\]As the backlog of queries increases, the term \(1+\alpha*BkLog_{CC}(t)\) increases, which makes \(\gamma\)(t) to decrease. The second term, \(\left(1-\frac{q_{occupancy}(t))}{q_{max}}\right)\) reduces the redundancy based on the queue occupancy. If \(q_{occupancy}(t)\) approaches \(q_{max}\), then the gamma factor \(\gamma(t)\) decreases; thus, it reduces redundancy to avoid overwhelming the system when it is already heavily loaded. The number of redundant gateways selected from the fitted gateways is represented as in Equation (5). This mechanism helps maintain a balance between reliability and resource efficiency in real-time IIoT query processing.  
\[R(t)=\min\Bigl{(}\gamma(t)*\left|G_{fitted}\right|,\ \left|G_{fitted}\right| \Bigr{)} \tag{5}\]