## 4 Proposed Solution
### Objective Function  
Flow scheduling needs to optimize transmission performance while meeting the above constraints. Therefore, we construct a cost function to evaluate the routing and scheduling scheme, which consists of different optimization objective functions. For each flow \(f_{k}\), its best route \(best\_route(f_{k})\) is defined by  
\[best\_route(f_{k})=\min\{\sum_{f_{m}\in\{F-S\}}\sum_{f_{k}\in S} \frac{1}{F_{\mathit{corr}}(f_{m},f_{k})}\] \[+K\times\sum_{(i,j)\in E}r[k,i,j]\} \tag{19}\]  
which considers each flow have a greater number of scheduling situations and also introduce a user-defined positive integer to limit the hops of each route. The FC-based flow correlation objective intends to carry more flows in the network, additionally, flow classification and sorting can reduce the execution time of the routing and scheduling method. The objective function of the scheduling model is to minimize the end-to-end flow latencies and the sending start time of the flow, which is defined as  
\[schedule(\mathbf{\varphi})=\sum_{f_{k}\in F}f_{k}.l+\varphi[k,R_{k}[0]] \tag{20}\]  
We optimize the sending time of each flow to make the remaining time slots more available. It breaks up a large number of time slices so that some flows with large frame size cannot be scheduled if the model does not consider that. The overall procedure of the multiperiod flow routing and scheduling algorithms with flow classification (MPFRS-FC) is shown in Algorithm 2. Given a TSN network \(G\) and a flow set \(\mathrm{E}\), the output is a mapping \(\mathbf{S}[f_{k},R[k]]\) of routes and transmission time slots. In the initialization step, MPFRS-FC groups call the flow classification function so that thepaths can be better shared for routing without conflict (line 1). The schedule is built over \(num_{F}=len(\mathcal{G})\) iterations and each iteration handles a flow group. The ILP constraints are generated for \(\mathcal{G}_{i}\), where \(i=0,1,\ldots,num_{F}-1\). The function \(ILP\) searches for a feasible solution that satisfies the time-sensitive routing, scheduling, and application constraints. Since the next group of flows cannot use the link contained in the path of the current group, we remove the links which the current group of flow passes through from the graph \(G\) and then find the route for the next group of flows (line 11) if the routing or schedule results are empty, i.e. it is infeasible for that flow to be scheduled in the current network. ```
Input: network architecture \(G\), flow collection \(F\) Output: Mapping of paths to transmission time slots \(S_{(path,t)}\), unscheduled flow set U
1\(\mathcal{G}\gets flows\_preprocessing(F)\)
2 Init \(\mathbf{S}\), U
3 for\(j\in\{1,2,3\}\)do
4 Generate constraints for this group of flows \(G[j]\)
5\(\Xi_{1}\leftarrow\) routing constraints (7)-(11)
6\(R[k]=ILP(\Xi_{1})\)
7 if\(R[k]\
eq\emptyset\)then
8\(\Xi_{2}\leftarrow\) time-sensitive constraints (12)-(18)
9\(S_{f}^{*}=ILP(\Xi_{2})\)
10 if\(S_{f}^{*}\
eq\emptyset\)then
11\(\mathbf{S}[k,R[k]].append(S_{f}^{*})\)
12\(G\gets G-R[k].edge\)
13
14 end if
15\(\mathbf{U}.append(f_{k})\)
16 else
17\(\mathbf{U}.append(f_{k})\)
18
19 end if
20
21 end for
```  
**Algorithm 2**Multiperiod flow routing and scheduling algorithms with flow classification  
Furthermore, we found that in some topologies or some network localities, we could not find multiple disjoint paths and could not implement the MPFRS-FC algorithm to improve the schedule success rate. We can use the MPFRS-FC algorithm to quickly locate groups of unschedulable flows, but we cannot schedule them without conflicting routes. Therefore, an adaptive period compensation routing and scheduling algorithm with flow classification (APCRS-FC) is designed to handle the simple network architecture. There may not be more than one route to pick between the two end systems in this condition. We add optimal compensated value \(\Delta\) based on the original period. Flows with class 3 can be carried on the same path as flows with class 1 or 2 in that way.