# Device Centric Throughput and QoS Optimization for IoTsin a Smart Building Using CRN-Techniques
## 3 Problem Formulation  
To provide the desired QoS to SUs within a smart building, it is desirable to find an optimal schedule for channel assignment in such a way that the maximum numbers of requests (members of different classes) are handled. Given the demands of SUs and available channels, an optimization problem is formulated that tries to maximize the number of served SUs at a particular time. Mathematically, it can be represented as follows:  
\[\begin{array}{ll}\textbf{maximize}&\mathcal{F}=\sum_{c=1}^{C}\sum_{u=1}^{U }\sum_{k=1}^{N}\textbf{x}_{k}^{u,c}\\ \textbf{subject to}&a_{k}^{u,c}\textbf{x}_{k}^{u,c}\geq\alpha_{min}^{c}\\ &(1-b_{k}^{u,c})\textbf{x}_{k}^{u,c}\geq\beta_{min}^{c}\\ &\theta_{k}^{u,c}\textbf{x}_{k}^{u,c}\geq\gamma_{min}^{c,c}\\ &\sum_{l=0}^{|L|}\textbf{x}_{k}^{u,c}=0\quad\quad\forall\quad l\
eq k\\ &\textbf{x}_{k}^{c,u}=\{0,1\}\quad\quad\forall\quad k\end{array} \tag{5}\]  
where \(\textbf{x}_{k}^{c,u}\) is a binary variable, which is either zero or one. If \(\textbf{x}_{k}^{c,u}=1\), it means that the channel \(k\) is assigned to the \(u\)th user that belongs to class \(c\). The optimization problem tries to maximize the summation of \(\textbf{x}_{k}^{c,u}\) over the available channels, number of users and classes. Hence, it is equivalent to maximizing the number of served SUs. There are four constraints that ensure the minimum QoS requirements of an SU that belongs to a certain class. The first constraint makes sure that the selected channel meets the minimum data rate required by an SU. The second constraint guarantees the desired bit error rate. The smooth operation of SU over a channel is ensured via a third constraint by ranking and selecting the channels in terms of idle time. The last constraint ensures that a channel is used by an SU at a particular time instant. Algorithm 1 depicts the details about the PSO-based implementation of the proposed scheme. The computational complexity of Algorithm 1 is \(O(P\xi)\)[49], where \(P\) is the number of particles and \(\xi\) indicates the number of iterations to reach the global optimum.  
\begin{table}
\begin{tabular}{c c c c} \hline \hline \multirow{2}{*}{**Classes**} & \multicolumn{3}{c}{**Minimal QoS Requirement**} \\ \cline{2-4}  & **Data Rate (Kbps)** & **Bit Error Rate** & **Stability Index** \\  & **(\(\textbf{\emph{a}}_{min}\))** & **(\(\beta_{min}\))** & **(\(\gamma_{min}\))** \\ \hline Video & 90 & 5 & 0.5 \\ Voice & 9.6 & 10 & 0.75 \\ Web & 30.5 & 12 & 0.3 \\ Ivideo & 90 & 8 & 0.3 \\ Ismoke, ICO\({}_{2}\) & 5 & 10 & 0.8 \\ NM & 60 & 10 & 0.85 \\ \hline \hline \end{tabular}
\end{table}
Table 2: QoS parameters for different SUs. NM, networking monitor.  
```
0: * Available channels \(N\) * Traffic classes \(C\) * Minimum QoS of classes \(\alpha_{min}^{c}\), \(\beta_{min}^{c}\), \(\gamma_{min}^{c}\) * SUs of a class \(U\) * Acceleration coefficients \(\eta_{1}\), \(\eta_{2}\) * Random numbers \(\delta_{1}\), \(\delta_{2}\) * Resource allocation \(\phi[C\times U,N]\) while stopping criteria not meet do for(\(j\): \(1\) to \(P\))do for(\(d\): \(1\) to \(D\))do  Initialize position \(S_{jd}\)  Initialize velocity \(V_{jd}\) endfor  Initialize particle personal best \(Pb_{j}\) if\(Pb_{j}>Gb\)then \(Gb=Pb_{j}\) global best position endif endfor for(\(j\): \(1\) to \(P\))do for(\(d\): \(1\) to \(D\))do \(V_{jd}^{\tau+1}=V_{jd}^{\tau}+\eta_{1}\delta_{1}(Pb^{\tau}-S_{jd}^{\tau})+\eta_ {2}\delta_{2}(Gb^{\tau}-S_{jd}^{\tau})\) \(S_{jd}^{\tau+1}=S_{jd}^{\tau}+V_{jd}^{\tau+1}\) endfor endfor endwhile return\(\phi\)
```  
**Algorithm 1** PSO-based device-centric QoS provisioning for SUs in a smart building.