1 Introduction

Algorithms of intelligent computing have achieved rapid development, and many animal swarm phenomenon inspires people to propose related new algorithms, such as whale optimization algorithm(WOA) [15], particle swarm optimization (PSO) [69], grey wolf optimization (GWO) [10, 11], cat swarm optimization (CSO) [12, 13], and artificial bee colony (ABC) [14]. They are successful examples of imitating intelligent behaviors of animals. In addition, in order to advance the performance of these algorithms, several methods are proposed [1519]. The algorithms randomly separate individuals into a limited area in the first phase, and then they use a large variety of equations to update the positions of individuals. The PSO uses two-elements, i.e., pbest and gbest. They are used to adjust the velocity of individuals. The pbest attracts particles exploiting around the self-best position and the gbest attracts particles exploiting around the global best position. When pbest has a relatively large weight, the algorithm has more chances to explore the promising area; on the contrary, the algorithm spends more time in exploiting around the global best position. The running process of CSO is similar to PSO, and it is inspired by cats. In the real world, the cats do not spend all time to catch prey, and they usually take more time to observe the around environments, so the algorithm introduces the modes of seeking and tracing to mimic the action of cats. In the first mode, each individual explores as many as possible areas around its position. While in another model, the population does something similar with PSO, and each individual aggregates to global best position. The ABC algorithm cancels the influence of the global best individual, and the bees have the probability to become onlooker bees or employed bees. The latter explores the environment around its position and according to fitness value, the former chooses one employed bee to follow. A better employed bee has a larger probability to be followed. Finally, the algorithm returns the best fitness value found by all bees. GWO algorithm makes subtle changes about the influence of the global best individual. In addition, the algorithm proposes an elaborate equation to imitate the catch movement of the grey wolf. The algorithm regards the average value of three elites as the prey, and other individuals exploit by far from or close to the prey.

With the development of WSN, there are many problems of security and data fusion in transmitting procedures [2026]. People can conveniently obtain important information in many scenes, for example, forest fire-prevention, predict nature disaster [27, 28], and rescue action after a disaster and marine monitoring. Utilizing the amount of data, we can predict something [29, 30]. To get correct information about monitor objects, the lives and positions of sensors are important for WSN [3135]. A simple solution of this problem is to attach GPS to each node, but this way has a disadvantage, that is GPS is an expensive module, and the sizes of most sensor nodes are minor to conveniently layout, so it is not a practical way that all nodes equip with GPS modules. The node location of WSN usually consists of a range phase and evaluation phase. In the former phase, the distances of sensor nodes to anchors are evaluated by receiving signal strength indicator (RSSI) [3638] and distance vector-hop (DV-Hop), and so on. This paper applies an intelligence computing algorithm to compensate for the deviation between the estimated position and actual position in the last phase.

In this paper, communication strategies are accustomed to advancing the property of WOA. We use 23 traditional mathematical test functions to indicate the performance of the novel algorithm, and the simulation results show it has better searchability than other existing algorithms. Furthermore, the new algorithm is applied to WSN localization and gets an excellent result.

The structure of this paper is as follows. In Section 2, we mainly introduce the WOA algorithm and DV-Hop method used in WSN localization. Section 3 explains in detail the proposed communication strategies of PWOA and how to combine the novel algorithm with DV-Hop method. The data from the simulation results are used to discuss the efficiency of the algorithm and the effectiveness of applying in the DV-Hop method in Section 4 and the summary of this paper in Section 5.

2 Related work

2.1 Whale optimization algorithm

Mirjalili et al., inspired by the prey action of whales, proposes the WOA algorithm, and this algorithm is a promising intelligence computing algorithm. The humpback whales’ hunting method is so interesting. They prefer to catch prey closing to the surface and this behavior is called bubble-net feeding method by people, because the hunting trails sometimes look like circles, and sometimes they look like the number nine.

The author provides the mathematical model about whale hunt action, and this model divides the hunt action into two phases, i.e., surrounding prey and bubble-net attacking method. The algorithm mimics the action of the whale population surrounding the prey. In the real world, the whale can recognize the position of prey, but we do not know where target prey is in a mathematical model, so the algorithm hypothesis the current global best position as the target prey and other whales gradually move to this position. The process of surrounding prey is presented as the following equations:

$$\begin{array}{@{}rcl@{}} D=|U\cdot P_{\text{best}}^{t}-P^{t} | \end{array} $$
(1)
$$\begin{array}{@{}rcl@{}} P^{t+1}=P_{\text{best}}^{t}-V\cdot D \end{array} $$
(2)

The t in the above equation means the current iteration number, V and U are variables that vary with the number of iterations. Pt and \(P_{\text {best}}^{t}\) are the individual locations and the global best position at the tth iteration and \(P_{\text {best}}^{t}\) will update when finding a better position. The values of V and U are calculated by the following equations:

$$\begin{array}{@{}rcl@{}} V&=&2v\cdot r-v \end{array} $$
(3)
$$\begin{array}{@{}rcl@{}} U&=&2\cdot r \end{array} $$
(4)

The v decrease from 2 to 0 as the number of iterations increases and r is a random number between 0 and 1. The value of v is changing along with iteration, so the value of V is a variable between − 2 and 2. In the exploitation phase, the V is set to [ − 1, 1], and individuals can travel anywhere between their current locations and their prey. As V gets smaller and smaller, the population gets closer and closer to the prey, so the algorithm exploits promising areas around the current global best position.

The bubble-net attacking method mimics whale attacking the prey. This method consists of two approaches: shrinking encircling mechanism and spiral updating position. The former depends on the value of V in the Eqs. (2) and (3), on account of the v decrease, the encircle range is smaller gradually. In the next iteration, the position of the individual may be anywhere between the prey and its own position.

The spiral updating position makes full use of the cos function to simulate the shape of the whale’s hunting path. The equation below is used to update the position of an individual:

$$ P^{t+1}=D\cdot e^{\text{sh}}\cdot \text{cos}(2\pi h)+P_{\text{best}}^{t} $$
(5)

where D is calculated by Eq. (1), and it means the distance of the individual to the global best position ever found. The form of the logarithmic spiral is defined by s, and h is a rand number between − 1 and 1.

This algorithm uses probability to determine which approach is adopted, and the above two approaches have an equal chance to update the position of the individual. A question we must consider is that if the algorithm exploits around only one prey, the algorithm easily be trapped into local optimal value, so the algorithm uses a similarity equation to achieve explore operation. When |V|>1, the algorithm will randomly choose an individual as prey instead of the global best position. In other words, the algorithm randomly chooses an individual to replace the \(P^{t}_{\text {best}}\) of Eqs. (1) and (2). The below equations are used to present the mathematical model:

$$\begin{array}{@{}rcl@{}} D=|U\cdot P_{\text{rand}}^{t}-P^{t}| \end{array} $$
(6)
$$\begin{array}{@{}rcl@{}} P^{t+1}=P^{t}_{\text{rand}}-V\cdot D \end{array} $$
(7)

The \(P^{t}_{\text {rand}}\) is an individual chosen randomly from the current population.

2.2 Localization problem in WSN

WSN has been widely used in our life, for example, forest fire-prevention, rescue action after a disaster, and marine monitoring. In order to obtain correct information, it is particularly important to accurately identify the location of nodes in the real world. Now the common methods are RSSI and DV-Hop, and the details of DV-Hop will be introduced in this section.

When solving the problem of localization in WSN, people often consider using the DV-Hop method [39]. This method estimates the linear distances between nodes by calculating the distance between each node, so it does not need complex hardware. Low cost and convenience to implement is the advantage of this method. The disadvantage of this method is the hop distance is used instead of the linear distance, so the results obtained by the DV-Hop method exists a larger error between actual distance and estimate distance.

Estimating distance about each hop is the key operation to recognize the positions of nodes in DV-Hop. After randomly decorating nodes, the method calculates the distances between anchor nodes and then calculates the distance of each hop of anchor nodes. Assume the method calculates the distance of each hop of A anchor node. Firstly, the method looks for the path with the least hops between A and the other anchor nodes. Then the method computes the distance of each hop of node A, which is the sum of their distances divided by the number of hops between them. To better illustrate the process of DV-Hop, we present Fig. 1.

Fig. 1
figure 1

DV-Hop nodes distribution shows the distribution information of sensor nodes in WSN

We can see the distribution condition of the WSN in Fig. 1. Orange indicates the unknown nodes and unknown nodes mean they are not equipped with GPS models. The blue nodes are anchor nodes. There are ten routes from A to D. The method chooses the route that has minimal hops between A and D, so we utilize the same method to get the number of hops from A to B, C, D, and E, and they are 3, 2, 2, and 4, respectively. Assume the distances from A to B, C, D, and E are 12m, 8m, 12m, and 20m, respectively, and the distance of one hop of A is calculated by the equation below.

$$ \text{HopD}_{i}=\frac{\sum\limits_{j=1,j\neq i}^{n}\sqrt{(p_{i}-p_{j})^{2}+(q_{i}-q_{j})^{2}}}{\sum\limits_{j=1,j\neq i}^{n} \text{hop}_{i,j}} $$
(8)

HopDi indicates the distance of one hop of ith anchor node. The coordinates of the ith and jth anchor nodes are represented by (pi,qi) and (pj,qj). The hopij is minimal counts of hops from ith to jth anchor node. Then we acquire the distance that one hop of A anchor node is 4.73m. The distance is computed by multiplying the number of hops with the distance per hop.

3 A PWOA with two communication strategies applied in DV-Hop localization method

This section mainly introduces the communication strategies of PWOA. The communication strategy can transfer effective information between groups, so the performance of this algorithm is improved by using these communication strategies. After this, the localization problem in WSN is solved by the new algorithm.

3.1 Tribal annexation communication strategy

Normally, the swarm intelligence computing algorithm has one or two influence vectors, such as PSO, ABC, and CSO. The fewer influence vector leads to algorithms with faster convergence rates, but the algorithms are not rich in diversity. Traditional communication strategy in parallel algorithms is trying to change the information exchange way rather than the account of groups. In the process of civilization development, there are often annexation and integration between civilizations. In this way, although the weak civilization is annexed, as a new group, they learn the culture and technology of another advanced civilization.

Inspired by this, this communication strategy divides the population to many groups and starts to explore and exploit, respectively. This operation is similar to the self-development of the tribe, then after a certain number of iterations, two neighbor groups are merged to be a new group. For example, the first group and second group become a first group in the future iteration. Through this process, the new group has information about two groups before merging, so the global best individual of the new group needs to update. Figure 2 helps us better understand the merged process.

Fig. 2
figure 2

Tribal annexation communication strategy shows the running process of this communication strategy

In the initial phase, this communication strategy divides the population into eight subgroups, so that the algorithm has more chances to avoid the local optimal value. At the later running process, this strategy by merging groups delivers the optimal information to a new group. In other words, the final group contains information about eight groups in the initial phase. Because this strategy explores the more promising area than the original WOA algorithm, so it has more chances to avoid local optimal value.

3.2 Herd mentality communication strategy

One of the challenges in our lives is to avoid doing the same things with others or being influenced by the actions of those around us. This phenomenon may make it difficult for us to do something. For example, more and more people study the knowledge about computers, and if you major computer, you would have the challenge of finding a comfortable job after graduating from university or college. But this phenomenon also can efficiently make sure you avoid some terrible things sometimes. Most people study computer knowledge, and although it is hard for you to find a comfortable job, you have more work chance, so you have a smaller probability of losing your job. This paper proposes a communication strategy that mimics the above phenomenon. This strategy divides the population into some groups, then respectively runs the traditional WOA algorithm. When the number of iteration reaches R2, Eq. (9) is used to update the positions of some individuals which can be chosen randomly:

$$ X_{R,d}^{t+1}=r\cdot 0.4+0.8\cdot P_{\text{mean}_{d}^{t}} $$
(9)

where the \(X_{R,d}^{t+1}\) indicates the value of a random individual in the dth dimension at the (t + 1) iteration and R is a random number between zero and group population size. The \(P_{\text {mean}_{d}^{t}}\) is the dth dimensional value of the mean position of all individuals at the tth iteration. This communication strategy randomly selects the same quantity of individuals from every group, and they are replaced by the Pmean in some dimension; if the algorithm produces a better position than a group’s best position, the algorithm would update the group’s best position. This communication strategy increases the diversity of the population by introducing the average position of the population so that individuals can have more choices to avoid the whole species having a similar value.

3.3 Apply the PWOA in DV-Hop localization method

In the second phase of localization, this paper utilizes the distance that has obtained in the first phase to recognize the position of the unknown node, and it applies PWOA in solving this problem. There are some distance errors between anchor nodes and unknown nodes, and it is calculated by the below equation:

$$ \text{error}_{j}=\sum\limits_{i=1}^{m}\sqrt{(p_{i}-p_{j})^{2}+(q_{i}-q_{j})^{2}}-d_{ij} $$
(10)

The errorj indicates the sum of distance errors of jth unknow node to all anchor nodes. The (pi,qi) is the coordinate of ith anchor node, and the position of the jth unknown node is represented by (pj,qj). The m is the account of anchor nodes, and dij is the distance from the ith anchor node to jth unknow node estimated by the DV-Hop localization method. In order to improve the accuracy of localization, we utilize the following fitness equation and PWOA to achieve this object:

$$ \text{Fun}(p,q)=\text{min}\sum\limits_{i=1}^{m}\sqrt{(p-p_{i})^{2}+(q-q_{i})^{2}}-d_{i} $$
(11)

The di is the estimated distance between unknown nodes and ith anchor node. The actual position of the unknown node is (p,q) and the coordinate of the ith anchor node is represented by (pi,qi). All individuals of WOA represent the positions of sensor nodes, then we use Eqs. (1), (2), (5), and (11) to find the best position in a limited area; in other words, we minimize the error of the unknown node.

4 Results and discussion

The simulation results that the novel algorithm under mathematical test functions and application effect in the DV-Hop localization method are shown in this section.

4.1 Simulation results on mathematic test function

Twenty-three classical mathematical test functions in [10] are used to verify the performance of the novel algorithm in this paper. Although these functions are simple, they can distinguish the performance difference between the new algorithm and other algorithms.

To evaluate the performance of the novel approach, this paper compares the novel algorithm with the conventional optimization algorithm PSO and the original WOA algorithm. Table 1 shows the parameter settings of those compared algorithms.

Table 1 Parameter setting shows the parameter setting of algorithms

The first communication strategy of PWOA (PWOAS1) is tribal annexation communication strategy, and the number of groups is reduced from eight to one in four separate processes. The iteration number is one thousand, so R1 is set to 250. The second communication strategy of PWOA (PWOAS2) is herd mentality communication strategy, and the value of R2 is smaller than R1 because the second communication strategy moves the population toward the mean position of the whole population. The more frequent communication between groups, the more stable the algorithm, and the algorithm has more chances to avoid trapping in a local optimal area.

In Table 2, we can see the results that the novel algorithm compares with PSO and original WOA algorithm in mean value and standard deviation of 30 runs. The PWOAS1 obtains 16 better results and 4 same results compared with PSO in all test functions. It has stronger searchability than original WOA in 10 test functions, and in 6 test functions, they produce similar results. The PWOAS2 acquires 15 better results and 4 same results than PSO, and in 9 test functions, it has better performance than the original WOA algorithm. The performance is the same for 6 test functions. In addition, we utilize the Wilcoxon method making non-parametric statistical hypothesis test [40], and we can see the test results from Table 3. The data is obtained by run 30 times for every test function. Some values are “NaN” because WOA under f9 or f11 test functions has the same value as PWOAS1 or PWOAS2. If the values of Table 3 are less than 0.05 means the performance of the novel algorithm is obviously better than other algorithms.

Table 2 The results of simulation experiment shows the experimental results of algorithms under 23 classical test functions
Table 3 The non-parametric statistical hypothesis test results of simulation experiment

The test functions are chosen in this paper including unimodal functions and multimodal functions. From Fig. 3, we can obtain the convergence details of PSO, WOA, and PWOA under 23 classical mathematics test functions. To be faired prove the PWOA has better performance than PSO and WOA, the data used for plotting is the average result of 30 runs and the parameters of the algorithms as Table 1 shows.

Fig. 3
figure 3

Resules of simulation experiments shows the optimization process of the novel algorithm

As the novel algorithm has two communication strategies, it has more choices to avoid the local optimal value. Tribal annexation communication strategy separates the population into several groups in the initial phase and the groups merge into one group gradually. In this process, the final group contains all information of the initial groups, so this communication strategy has more chance to find the optimal value. Herd mentality communication strategy introduces the mean position value of the whole population to increase the diversity of the algorithm, so the algorithm can avoid local optimal value.

In most test functions, we can clearly see the difference in optimal results or convergence rates between 4 algorithms. But in f1 to f7, the PWOA obtains similar results with WOA, except for f3 and f4, because these functions are unimodal function. They are too simple to distinguish the performance difference between WOA and PWOA. In addition, the novel algorithm has a slower convergence rate than the WOA algorithm due to the communication action takes some time.

Compared with unimodal functions, there are many local optimal areas in multimodal function; if the algorithm has no powerful exploring ability, it would easily be trapped in a local optimal area. In f8 to f23 test functions, the PWOA algorithm is more competitive than other algorithms. In every certain number of iterations, the PWOA exchanges information between groups making the new algorithm obtain more exploration region information than the original algorithm. Through the comparison of the above experiments, we can get a conclusion that the PWOA algorithm has more outstanding performance than the original WOA and PSO algorithms.

4.2 Simulation results of PWOA applied in DV-Hop localization method

This paper combines PWOA with DV-Hop to solve the localization problem for WSN. We compare the simulation results of PWOA-based DV-Hop with DV-Hop, WOA-based DV-Hop, and PSO-based DV-Hop. The coordinates of sensor nodes are calculated by the least square method in DV-Hop, while other methods use intelligent computing algorithms. All simulation experiments are implemented by MATLAB 2014a and the data is the average of 30 runs of independent trials. The iteration is set as 100 and other parameters are shown as in Table 1. The average localization error is used to evaluate the property of the localization method, which is given as follows:

$$ \text{ALE}=\frac{\sum_{e=1}^{m}\sqrt{(P_{e}-p_{e})^{2}+(Q_{e}-q_{e})^{2}}}{m\times R} $$
(12)

The m is the number of unknown nodes, and ALE means average localization error of all unknown nodes in whole WSN. The (pe,qe) is the estimated coordinate of the eth unknown node and the actual position of the eth unknown node is represented by (Pe,Qe). Each node has the same communication radius R.

4.3 Sensitivity of varying anchor node amount

In this experiment, randomly dispersing 200 nodes in a 100 m ×100 m sensing region. In each test, the number of anchor nodes was 5, 10, 15, 20, 25, 30, 35, and 40, respectively.

From Table 4, we can see that by comparing the DV-Hop- and PSO-based DV-Hop, the PWOA is more competitive. The more anchor nodes are placed, the estimated position of the unknown node is more accurate. In other words, the problem is easier to solve, so if there are a large number of anchor nodes, the performance difference would difficulty be found between algorithms.

Table 4 The localization error of varying anchor node amount shows the experimental results of varying node amount

4.4 Sensitivity of node density

In order to know the influence of node density on experimental data, each test has the same amount of anchor nodes and a different number of unknown nodes in this experiment, and we randomly disperse nodes in a 100 m × 100 m sensing region. The communication radius of all nodes is 20 m.

Table 5 shows that the localization error increases with the number of unknown nodes. This is because the number of unknown nodes influences the complexity of the WSN localization problem. From Table 5, we can see that in the case of a large number of unknown nodes, the performance of PWOA-based DV-Hop is better than other localization methods. So, the novel algorithm we proposed is more suitable for solving complex problems.

Table 5 The localization error of varying node density shows the experimental results of varying node density

Figure 3 shows the variation of fitness value along with iteration number between algorithms, PWOAS1-based DV-Hop, and PWOAS2-based DV-Hop. There are 195 unknown nodes and 5 anchor nodes in this experiment, and the communication range of each node are 20 m. We can see the two novel communication strategies are both better than other algorithms. The proposed PWOA can be further improved by combining some useful methods [4145].

5 Conclusion

In this paper, PWOA is presented to solve the WSN localization problem, and it consists of two communication strategies. The first strategy is by merging groups to achieve information communication, and it adequately exploits the promising area. The second strategy introduces the influence of the average position of the whole population. Through the 23 classical test functions, we clearly understand the performance of the new algorithm, and from simulation, we see the novel algorithm has competitive performance and good stability. Finally, we apply the novel algorithm in DV-Hop localization method and compare it with DV-Hop, PSO-based DV-Hop, and WOA-based DV-Hop. Although the problem is so simple, the novel algorithm also gets excellent results.

In the future, we can further propose new communication strategies and combine the parallel method and other enhance ability method, and we believe that they can get excellent results.