# Heuristic Routing Algorithms for Time-Sensitive Networks in Smart Factories
## 5 Adversarial Ant Colony Optimization Algorithm for Solving Non-TT Routing Problem
### Definition of the Optimization Problem in Non-TT Routing  
Based on the above conditions, the non-TT routing problem in TSNs could be defined as follows: in a given \(G(V,E)\) with \(n\) nodes, the planning of \(m\) routes for \(m\) non-TT flows with the sets of source nodes of these routes was defined as \(SRC=\{v_{src_{1}},v_{src_{2}},\ldots,v_{src_{n}}\}\), where the nodes are all repeatable. The destination of all non-TT flows was a centralized data server node \(v_{dst}\). The priority of the \(k\)th non-TT flow was \(p_{k}\), which was also repeatable, and the set of its packet lengths was \(PCK=pck_{1},pck_{2},\ldots,pck_{m}\). The route of the \(k\)th non-TT flow was denoted as \(\omega_{k}=(v_{src_{k}},v_{2},v_{3},\ldots,v_{dst})\), which represented a path passing through \(n\) nodes of \(v_{src_{k}}\to v_{2}\to v_{3}\rightarrow\cdots\to v_{dst}\).  
We retained the description of the time delay from Section 4.1, with the difference that for this problem, the non-TT flow did not need to traverse each ES node inside the subnetworks, so the time delay of the \(k\)th non-TT flow between \(v_{i},v_{j}\) nodes in the routes \(\omega_{k}\) was:  
\[d^{k}_{ij}=c_{ij}+q^{k}_{ij}, \tag{8}\]  
where \(q^{k}_{ij}\) is the queueing delay of the \(k\)th non-TT flow between \(v_{i},v_{j}\). The higher the number of non-TT flows involved in queuing on any single SW node, the larger the WCD of the flows with a higher priority than the current \(k\)th flow, thereby making \(q^{k}_{ij}\) increase correspondingly. The correspondence between the number of non-TT flows in a queue  
Figure 8: TAS scheduling mechanism with GCLs in a TSN.  
Figure 7: An example of TAS scheduling timing in a TSN (corresponds to Figure 8).  
and \(q_{ij}^{k}\) was determined by the GCL-based scheduling mechanism in the TSN, which was obtained through the simulation experiments detailed in later sections of this paper.  
Since the traffic scheduling principle of a TSN requires planning higher priority non-TT flows first, the \(\omega_{i}\) with the highest \(p_{i}\) had to be prioritized, followed by planning the rest of flows in order of priority. The minimum value of the overall time delay \(T\) was:  
\[T=\sum_{k=1}^{m}\sum_{i=1}^{n}\sum_{j=1}^{n}d_{ij}\cdot\rho_{ij}^{k}, \tag{9}\]  
where \(\rho_{ij}^{k}\) is the transmission direction of the non-TT frame between nodes \(v_{i}\) and \(v_{j}\), which was defined as follows:  
\[\rho_{ij}^{k}=\begin{cases}1,&\text{non-TT frame $k$ goes from $i$ to $j$}\\ 0,&\text{non-TT frame $k$ goes from $j$ to $i$}\end{cases}. \tag{10}\]  
In addition, we defined \(y_{i}^{k}\) to mark whether the \(k\)th non-TT frame had visited the node \(v_{i}\). Similarly, each node updated, the pheromone left by the ant colonies with higher priorities greatly suppressed the pheromone increment of the weak colonies and reduced the probability of picking identical routes. Weak ant colonies would rather choose detouring than repeating the route of stronger colonies. Meanwhile, the distance to be detoured was also taken into account. When the extra cost of detouring was too large, weak ant colonies would choose to participate in the queuing process with stronger ant colonies, after weighing up the costs. Taking a small network consisting of six SWs with \(m=3\) as an example, a sample procedure of the AACO algorithm solving the non-TT route assignment problem is shown in Figure 9.