## 2 Theoretical Basis of Time-Varying Target Formation
### Improved Hungarian Algorithm Design
By deleting the rows and columns of the above allocation, the order of distance matrix is reduced. Repeat the above process to determine whether the end condition is met and obtain the allocation result. 6. According to the method of the minimum objective function, the target points to be reconstructed is reprogrammed, and the desired position to be achieved is assigned;
7. Based on the above numbering method, use the leader-follower control law based on the consensus algorithm to control the system to achieve the formation and reconstruction of the overall goal. The process of the trial allocation part is as follows:  
1. Initialize the algorithm and related parameters;
2. The number of rows and columns in the distance matrix was compared. If the number of rows and columns are equal, go to the next step. If the number of rows is larger, go to step5, otherwise go to step7. 3. We sort the comprehensive weighted values of each row and column from large to small, so that the subscript of the row (column) with the largest comprehensive weighted value is;
4. If the row (column) with the smallest element in the row (column) \(k\) of the distance matrix is \(i_{k},j_{k}\) respectively, then assign the row \(i_{k}\) to column \(j_{k}\) and go to step9. 5. Sorting the combined weighted values of the rows from the largest to the smallest, and let the subscript of the row with the largest combined weighted value be \(k\);
6. If the smallest element in row \(k\) of the distance matrix is located is \(j_{k}\), and assign row \(k\) to column \(j_{k}\) and go to step9. * Sorting the combined weighted values of the columns from the smallest to the largest, and let the subscript of the column with the largest combined weighted value be;
* If the smallest element in the column \(k\) of the distance matrix is in the column \(i_{k}\), then assign the row \(k\) to the column \(i_{k}\) and go to step9. * End the target trial assignment. Figure 3 shows the process of time-varying target formation after using the improved Hungarian algorithm. The following will give the allocation and planning of the improved Hungarian algorithm when failure occurs in the static formation. It is more intuitive to understand the path planning scheme of the improved Hungarian algorithm. Numbers 1-7 in the figure represent different agents and their locations. The red circle and the blue circle denote the leader and the follower, respectively. The gray circle represents the failed agent, the blue-green circle represents the initial position of the filled-in agent, and the dashed line shows its moving trajectory under static conditions. Figure 4a,b are the different situations in which agents are disabled from seven to six, respectively. If they are disconnected in sequence, the best allocation scheme obtained using the improved Hungarian algorithm, in this case, is the fourth and fifth agents remaining unchanged and the sixth agent moving down according to the reconstructed formation in the graphics library, filling the vacant position. If the fourth agent is randomly disabled, the optimal allocation of the target point after replanning is that the sixth agent fills the fourth position, and the seventh agent moves up to fill the sixth empty position and reconstitut  
Figure 3: Flow chart of time-varying formation based on improved Hungarian algorithm. Figure 4c,d show two cases of the accidental failure of six agents, respectively. Using the improved Hungarian algorithm to redistribute the target points at the first time can significantly save the overall path cost and quickly form a new reconfiguration pattern.