## 2 Theoretical Basis of Time-Varying Target Formation
### Improved Hungarian Algorithm Design
After traversing the distance from all points to the target point, the distance matrix is obtained. Each element of the original distance matrix is normalized in the form of \(a_{ij}=\left[\frac{c_{ij}-c_{\min}}{c_{\max}-c_{\min}}\right]\) to obtain its equivalent distance matrix \(A\). \(c_{\min}=\min\{c_{ij},i=1,\cdot\cdot\cdot,n,j=1,\cdot\cdot,n\};c_{\max}=\max \{c_{ij},i=1,\cdot\cdot\cdot,n,j=1,\cdot\cdot,n\}\); At this point the maximum element \(E\) of the equivalent matrix \(A\). At this time, the \(i\)-th row/column elements are sorted incrementally to get \([b_{1},\cdot\cdot\cdot b_{n}]\), The combined weighted sum of each step of the gradient is calculated as follows:  
\[ \begin{array}{l}S_{i}=\sum\limits_{j=2}^{n}\frac{b_{j}-b_{j-1}}{E^{j-1}}= \sum\limits_{j=2}^{n}\frac{b_{j}}{E^{j-1}}-\sum\limits_{j=2}^{n}\frac{b_{j-1} }{E^{j-1}}\\ =\sum\limits_{j=1}^{n}\frac{b_{j}}{E^{j-1}}-\sum\limits_{j=1}^{n}\frac{b_{j}} {E^{j}}-\frac{b_{1}}{E^{j}}+\frac{b_{1}}{E^{j}}\\ =\sum\limits_{j=1}^{n}\frac{(E-1)\cdot b_{j}}{E^{j}}+\frac{b_{1}}{E^{j}}\end{array}  \tag{11}\]  
The initial treatment of the distance matrix is determined using the auction algorithm, where the sorted minimum is 0, i.e., \(b_{1}=0\). Since this paper adopts the leader-follower formation control strategy, and the selection of the leader has been given in the previous section, it is assumed that only the followers are damaged during the maneuver. The distance matrix \(C_{ij}\) is taken as an example to illustrate the concrete implementation steps of the improved Hungarian algorithm in the case of failure:  
1. Before each calculation, use conditional statements to judge, and check the number of agents in the system, and feedback the number of agents in the system;
2. Determine whether the agent is disabled in the current system; if failed, skip to step (3); if not, skip to step (6);3. According to the number of smart bodies, find and call the corresponding number of formation configurations in the graphics library; use the formations of the graphics library to generate new adjacency matrix and stress matrix, and renumber the smart bodies in order;
4. Set the distance matrix of the agent. The improved Hungarian algorithm traverses the distance between the agent and each target point and calculates the cost matrix. Find the minimum value of each row/column of the distance matrix, and subtract the minimum value of all the elements in this row/column at the same time to get a new distance matrix. The matrix is constantly reduced by rows and columns until the 0 element appears in each row and column. We sort the elements of each row and column, and calculate the weighting factors of each order. Then we adjust the sorting results of the elements in each row and column, according to the sorting value assigned above. The non-zero minimum value is subtracted from the unassigned rows and the column element ordering result is adjusted. The same calculation needs to be done for unassigned columns. The algorithm counts the comprehensive gradient weighted sum of elements in each row and column. \[ \begin{array}{l}SR_{i}=\sum\limits_{j=1}^{n}\frac{(E-1)Rb_{j}}{E^{j}}+\frac{ Rb_{n}}{E^{k}}\\ SC_{i}=\sum\limits_{j=1}^{n}\frac{(E-1)Cb_{j}}{E^{j}}+\frac{Cb_{n}}{E^{k}}\\ \end{array} \] (12)
5. Among them, \((Rb_{1},\cdots,Rb_{n})\), \((Cb_{1},\cdots,Cb_{n})\) are the incremental sorting results of the \(i-th\) row and \(i-th\) column elements respectively. For the unallocated row and column elements, the weighted sum of the comprehensive gradients is sorted from large to small, and the row or column with the largest comprehensive gradient is selected for trial allocation. To reduce the order of the distance matrix, the algorithm deletes the rows and columns allocated above. If the number of rows of the distance matrix is less than or equal to the number of columns, the weighted sum of the comprehensive gradients of the unallocated column elements is sorted from large to small, and the column with the largest comprehensive gradient is selected for trial allocation.