2.1 Classical antcolonyalgorithm framework
The principle of the antcolony algorithm originates from simulating the foraging behavior of ants. Foraging ants may secrete a pheromone along the search route. The more ants that travel a route, the higher the pheromone concentration becomes. The pheromone serves as a positive attraction for arriving additional ants; the higher the pheromone concentration, the greater the probability for the arriving ant to choose a particular route. At the same time, the pheromone will also evaporate, which allows the ants search for other routes, improves the global search capability, and avoids falling into a local optimum.
To fully describe the antcolony algorithm, several elements must be defined:
\(m\) is the number of ant colonies; \(i\) and \(j\) represent the nodes that the ant passes through; \(\tau_{ij} \left( t \right)\) represents the pheromone concentration between nodes \(i\) and \(j\) at time t, which reflects the importance of moving from node \(i\) to node \(j\); \(\alpha\) represents the significance of the pheromone; \(\eta_{ij} \left( t \right)\) is the expected heuristic function, which represents the inverse of the distance from node i to node j at time t; \(\beta\) is the expectation factor; \(p_{ij}^{k} \left( t \right)\) is the statetransition probability formula, representing the possibility of ants moving from node \(i\) to node \(j\) in the kth iteration; \(\rho\) is the pheromone evaporation rate, which avoids the infinite accumulation of pheromones that is usually set to be less than 1. Taboo records the nodes each ant passes through to prevent the ant from passing through the node again. When the ant passes through all of the specified nodes, it completes an iteration.
The statetransition probability formula of the antcolony algorithm is then
$$p_{ij}^{k} \left( t \right) = \left\{ {\begin{array}{*{20}c} {\frac{{\left[ {\tau_{ij} \left( t \right)} \right]^{\alpha } \left[ {\eta_{ij} \left( t \right)} \right]^{\beta } }}{{\sum\limits_{{s \in {\text{allow}}}} {\left[ {\tau_{is} \left( t \right)} \right]^{\alpha } \left[ {\eta_{is} \left( t \right)} \right]^{\beta } } }},s \in {\text{allow}}} \\ {0{\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} ,{\kern 1pt} s \notin {\text{allow}}} \\ \end{array} } \right.,$$
(1)
where allow represents the next node for the ant to go to next. Hence,
$$\eta_{ij} \left( t \right) = \frac{1}{{d_{ij} }}$$
(2)
where d_{ij} is the distance from node i to node j.
After the completion of each cycle by the ant, the path pheromone is updated to
$$\tau_{ij} (t + 1) = (1  \rho )\tau_{ij} (t) + \Delta \tau_{ij} (t)$$
(3)
$$\Delta \tau_{ij} \left( t \right) = \sum\limits_{k = 1}^{m} {\Delta \tau_{{_{ij} }}^{k} \left( t \right)}$$
(4)
where \(\tau_{ij} \left( {t + 1} \right)\) is the updated intensity of the pheromone from node i to node j, and \(\Delta \tau_{ij} \left( t \right)\) is the pheromone increment from node i to node j. Three models are used to compute \(\Delta \tau_{ij} \left( t \right)\), i.e., the antdensity, antquantity, and antcycle models, as shown in Eqs. (5), (6), and (7), respectively,
$$\Delta \tau_{{_{ij} }}^{k} \left( t \right) = \left\{ {\begin{array}{*{20}c} Q & {{\text{Ant passed}}(i,j)} \\ 0 & {{\text{Ant did not pass}}(i,j)} \\ \end{array} ,} \right.$$
(5)
$$\Delta \tau_{{_{ij} }}^{k} \left( t \right) = \left\{ {\begin{array}{*{20}c} {\frac{Q}{{d_{ij} }}} & {{\text{Ant passed}}(i,j)} \\ 0 & {{\text{Ant did not pass}}(i,j)} \\ \end{array} } \right.,$$
(6)
$$\Delta \tau_{{_{ij} }}^{k} \left( t \right) = \left\{ {\begin{array}{*{20}c} {\frac{Q}{{L_{k} }}} & {{\text{Ant passed}}(i,j)} \\ 0 & {{\text{Ant did not pass}}(i,j)} \\ \end{array} } \right.$$
(7)
Here, Q is the intensity coefficient of the pheromone increase, and L_{k} is the path length traversed by the ant after the cycle ends. In the antdensity and antquantity models, updates are based on local information, while updates are based on global information in the antcycle model. Experimental results have also shown that the best performance is obtained from the update method of the antcycle model.
2.2 Spectrallineextraction algorithm based on antcolony algorithm
When extracting the signal of a spectral line, the lofargram of the signal is often obtained first. According to the description in Sect. 2, the spectral lines in a lofargram may be regarded as the various paths to apply the antcolony algorithm to extract spectral lines.
2.2.1 Issues when applying antcolony algorithm to linespectrum extraction
First, the grid method is applied to divide the lofargram into small squares. The ants are then randomly placed in the small squares to begin a search over the entire lofargram. The following issues are considered when applying the antcolony algorithm.

1.
In the classical antcolony algorithm, the search is conducted with the ants randomly selecting any of the eight surrounding directions, as shown in Fig. 1. In the figure, a fivepointed star represents an ant. In the lofargram, the line spectrum is usually a relatively straight, bright line, which means each spectral line has a unique frequency at any given time; that is, an ant can only forage along the directions of increasing or decreasing time and cannot forage laterally. If the ants forage laterally, the calculation overhead of the algorithm will increase, and there may be more than one frequency point at a time that is unreasonable.

2.
In the classical antcolony algorithm, the starting point and destination of the ants are generally fixed. However, in the lofargram, they are unknown.

3.
In the classical antcolony algorithm, updates of the heuristic function and pheromone are determined by the distance of the ant from the destination. However, the destination is unknown in the lofargram, so this distance cannot be used as a standard for updates.
2.2.2 Algorithm improvements
A spectrallineextraction method based on the antcolony and optimal path algorithms is proposed, and the following improvements are made to address the problems described above:

1.
The search area of the ants is limited; that is, each ant can only search in the direction of the time axis, and an ant cannot search horizontally. As shown in Fig. 2, the ordinate represents time, and the abscissa represents frequency.

2.
Inspired by the characteristic function advanced by Di Martino et al. [14], a new cost function is proposed as a standard for determining the updates of the heuristic function and the pheromone:
$$P\_\cos \left( \xi \right) = \sum\limits_{i \in \xi } {\frac{d(i)}{{A(i) + G(i) + {\text{eps}}}}} ,$$
(8)
where \(\xi\) represents the path of the spectral line; d (i) represents the frequency continuity of the line spectrum, which reflects the frequency fluctuation of the line spectrum; G (i) represents the trajectory continuity of the line spectrum, which reflects whether the line spectrum is broken; A (i) represents the intensity of the line spectrum, namely the amplitude at each frequency point on the linespectrum path; and eps represents the accuracy of the algorithm that prevents the occurrence of zeros in the denominator. Equation (8) shows that the greater the intensity of the line spectrum, the greater A (i), the better the frequency continuity, the smaller d (i), and the better the continuity of the path, the greater G (i). Alternatively, the smaller the cost function of the line spectrum, the smaller \(P\_\cos (\xi )\). In the processing of underwater acoustic signals, a spectral line is often a straight line with a certain energy. Therefore, the definition of the cost function in Eq. (8) is consistent with the characteristics of the line spectrum. The definitions of d (i), G (i), and A (i) are
$$d\left( i \right) = \left {f(P_{i} )  f(P_{i + 1} )} \right + {\text{eps,}}$$
(9)
$$G\left( i \right) = \sum\limits_{i \in \xi } {g\left( {P_{i} } \right)} ,$$
(10)
$$g\left( {P_{i} } \right) = \left\{ {\begin{array}{*{20}c} {1,{\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} A(i) > {\text{count}}} \\ {0,{\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} {\kern 1pt} A(i) < {\text{count}}{\kern 1pt} {\kern 1pt} } \\ \end{array} } \right.$$
(11)
In Eq. (9), f (P_{i}) represents the value of the frequency of spectral line P_{i} at point i. In Eq. (10), g (P_{i}) is a flag variable defined in Eq. (11). That is to say, when g (P_{i}) is less than the threshold count, a break is considered to have occurred at this point; otherwise, g (P_{i}) is set to 1. Usually, count is set to the mean value of background noise in the frequency domain.
The new heuristic function is then
$$\eta_{ij} = \frac{1}{P\_\cos (\xi )},$$
(12)
which shows that the smaller \(P\_\cos (\xi )\), or rather, the closer the search path is to the spectral line, the greater the value of the heuristic function, which is consistent with the design principles of the heuristic function. With the progress of the ant search process, the value of \(P\_\cos (\xi )\) is constantly changing, so the heuristic function is continuously updated.

3.
A considerable amount of calculation is required if all the frequency states in the lofargram are simultaneously detected. A blockprocessing framework is introduced to reduce the computational complexity of linespectrum extraction and improve calculation speed. As shown in Fig. 3, the lofargram is divided into four parts, and there is a certain degree of overlap between adjacent blocks in the frequency dimension.
In Fig. 3, the abscissa represents frequency and the ordinate represents time. It is supposed that there are 17 N frequency points and K time points. The lofargram is divided into four parts in the frequency direction, i.e., 1 N–5 N, 4 N–9 N, 8 N–13 N, and 12 N–17 N, and the length of the overlapping part is N. Fiveline spectra in the lofargram are represented by different colors. The function of the overlap is to prevent the loss of linespectrum extraction. For example, the red line spectrum is incomplete in the first part (1 N–5 N in the frequency direction), which is difficult to extract successfully. However, the red line spectrum is complete and easily extracted in the second part (4 N–9 N in the frequency direction).
2.2.3 Algorithm processing flow
Figure 4 shows the algorithm processing flow, where C represents the set number of iterations.
The algorithm processing steps are as follows.

1.
A fast Fourier transformation is performed for the acquired signal to obtain the lofargram spectrum and subject it to a grid process.

2.
The taboo table is used to record the nodes visited by the ants. The taboo table is initialized to 1, and the node of the taboo table is set to 0 when the ant passes through the node.

3.
M ants are placed randomly in the lofargram at the starting time, and the cost function \(P\_\cos (\xi )\) for each ant to proceed to the next node is calculated according to (8).

4.
The heuristic factor \(\eta_{ij} \left( t \right)\) is calculated from the cost function \(P\_\cos (\xi )\) according to Eq. (12).

5.
The statetransition function \(p_{ij}^{k} \left( t \right)\) for each ant to proceed to the next node is calculated, and the direction of each ant is determined using the roulette rule.

6.
The taboo table is updated, and the node passed by the ant is set to 0. The path taken by each ant in each generation is recorded.

7.
When the ants traverse the time axis of the entire lofargram, it marks the end of one iteration, and the above process is repeated.

8.
The n paths with the minimum cost function are recorded, and a second threshold determination is performed to remove the false line spectra. Finally, the desired spectral line is obtained.