1 Introduction

Computer networks play a vital role in today's world of communication. Various types of computer networks have emerged in the world, such as the Internet of Things [1], Wireless sensor networks [2], Wireless Body Area Networks (WBAN) [3], and Vehicular ad hoc networks (VANET) [4]. Most modern computer networks in the world use wireless communication. Wireless networks have the advantage that they do not require unique infrastructure to set up and use a vacuum or air transmission media to communicate. An advantage of network types is that they have high scalability. The wireless sensor network topology is autonomous and dynamic [5].

The wireless sensor network is used in various applications. The field of rescue, military, environmental, and health is one of the applications of wireless sensor networks. The number of nodes in sensor networks can be significant, and these nodes require a precise mechanism for sending packets to the base node. Each node can send the collected information directly to the station, but this strategy consumes more energy. In this scenario, the nodes use all their power to send packets to the base station. If the distance of a node from the base station is too long, then the energy consumption of the sensor node will also increase [5].

Another approach to routing is to use a hierarchical process. In the hierarchical routing process [6], unlike the flat routing process [7], Multi-Hop sending is used instead of single-Hop sending. In hierarchical routing, one cluster head is selected for each cluster. The role of the cluster is to receive cluster sensor packages. Header sends this information to the base station by receiving the data of the sensor nodes inside the cluster as intermediaries. Different problems need to be considered when choosing a cluster head, such as the residual energy of each node. Using multi-Hop and hierarchical routing reduces the energy of the nodes to send packets and increases network life [7].

The problem of cluster head selection is an optimization problem. For this reason, optimization algorithms such as meta-heuristic algorithms have been used to solve it. The genetic algorithm [8], particle swarm optimization algorithm [9], Firefly algorithm [10], Bat algorithm [11], Whale optimization algorithm [12], and Butterfly optimization algorithm [13] are the most popular selection cluster header algorithms. An effective way to reduce energy consumption in WSN is to collect the headers' information after selecting them and then send it to the base station. Applying this strategy makes the headers not need to consume high energy to send packets. In this case, the moving sink can receive their information by approaching the headers.

One of the most critical challenges in wireless sensor networks is optimal routing in these networks. Non-optimal routing in the wireless sensor network reduces the wireless sensor network's lifetime; on the other hand, the delay in sending packets increases. Optimal routing increases the lifetime of the network and the duration of its deployment, which is a practical problem in wireless sensor networks. Our motivation for this research is to provide an optimal routing method with optimization methods and swarm intelligence to increase the network lifetime.

The optimal choice of cluster head in routing protocols makes nodes with more power play a more active role in routing. The optimal clustering approach in the routing of WSN networks makes the nodes with low power to be connected with the nearest cluster head and send the packets to the nearest cluster head. They were not sending packets from a node to a base station that is far away from the sensor node saves energy and increases network life. Optimum routing by mobile sing makes the cluster heads waste less energy to send the collected packets, increasing network life. Increasing the lifetime of network nodes increases the network coverage because, in this case, the older cells lose their sensor nodes.

The purpose of the proposed method is to collect information in the headers by a moving sink and send it to the base station. With this mechanism, energy consumption in the network is reduced, and network life is increased. In the proposed method, two main steps are used. The first phase is clustering by the WSA algorithm [14] in the wireless sensor network. Then, in the second phase, a mobile sink selects the optimal path between the cluster header by selecting the threads. The role of the mobile sink is to collect information from clusters in the wireless sensor network and send the collected data to the base station. The ACO algorithm reduces the path length and the delay in sending packets by the mobile sink. The role of the ACO algorithm is to select the optimal path for navigating the clusters. The importance of the proposed method is in reducing energy consumption by intelligently selecting clusters and navigating the short path between the heads of clusters with the ant colony optimization algorithm.

Several studies have been done so far for optimal routing in wireless sensor networks. Some studies use meta-heuristic methods to select the cluster head. In this case, the data collected by the cluster heads are collected and sent to the base station. In these studies, the objective function for clustering is Euclidean distance, and a time node is a cluster head member with a small distance to it. Unlike other research, the innovation of the proposed method is to provide a more optimal objective function for clustering sensor nodes and to select the cluster head. In the objective function, a sensor node is selected as the cluster head when the path of sending packets from it to the base station has a low error. In addition, a node is the head of the cluster when it reduces the energy consumption of the path of sending packets and the error rate of sending packets and minimizes the node's distance from the cluster head.

The innovation of the proposed method is that in none of the studies, these parameters and criteria have been used simultaneously to select the cluster head. Another innovation of the proposed method is finding the optimal cluster head with the WSA algorithm, presented in 2020. This paper is the first research using the WSA algorithm for routing the WSN network. Another innovation of this paper is that instead of sending packets from the cluster head to the base station, a mobile sink is used to collect the packet from the cluster head and send the packets from the mobile sink to the base station. In other words, a mobile sink goes to the heads of the clusters and collects its packets, and sends them to the base station. The advantage of the mobile sink is that the energy of the cluster heads will be consumed later, and the network's life will increase. Another innovation of the paper is that the traversal path of the moving cluster head is formulated as the Traveling Salesman Problem (TSP). In this case, each cluster head is coded as a city in the TSP problem. The mobile sink is like a traveling salesman by the ACO algorithm looking for an optimal tour to collect information from the cluster heads.

The contribution of the authors in this research is as follows:

  • Optimal cluster head selection with criteria such as Euclidean distance, the error rate of sending packets, energy, and reporting rate of receiving packets.

  • Selection of cluster heads with maximum energy and receiving report rate by WSA algorithm

  • Selecting the cluster heads with the lowest error and energy consumption by the WSA algorithm

  • Presenting a new coding of WSA algorithm in optimal routing in wireless sensor network

  • Modeling cluster head traversal like the Traveling Salesman Problem(TSP)

  • Finding the optimal net tour by the mobile sink with Ant Colony Optimization(ACO) algorithm

  • Applying swarm intelligence and combined WSA and ACO algorithm in optimal routing in wireless sensor network

In this paper, several fundamental assumptions are presented as follows:

  • Combining the WSA algorithm and ACO algorithm optimizes routing in WSA and reduces energy consumption.

  • Using a mobile sink reduces energy consumption compared to hierarchical routing.

  • The WSA algorithm reduces energy consumption more than meta-heuristic methods such as PSO.

This paper has been prepared and compiled into several sections. In the second part, the related works to the research are reviewed. The third section introduces the proposed method for optimal routing with the approach of reducing energy consumption. In the fourth section, the proposed method is analyzed. The fifth section presents the results of the research and future works.

2 Related works

There are two types of routing in computer networks, such as wireless sensors. In flat routing, each node decides directly to send packets and sends the packets directly to the base station. In hierarchical routing, a node does not send packets directly to the base station but sends packets to the cluster head. The cluster heads send the received packets to the base station. Figure 1 shows a hierarchical routing with a node clustering mechanism [15, 16].

Fig. 1
figure 1

Hierarchical routing in a wireless sensor network and clustering of network nodes

In Fig. 1, a clustering of the wireless sensor network nodes is performed, and each node sends information to its headers. The cluster head also sends information to the base station. Due to the limited energy resources, optimal routing methods are used in wireless sensor networks. Optimal routing reduces node power consumption and increases network life.

Routing protocols in a wireless sensor network are divided into four groups, according to Fig. 2, based on the processing method, network structure, network operators, and communications. Data-Centric Protocols, Hierarchical Protocols, Location-Based Protocols, Identity-based protocols, and distributed hash tables (DHT) protocols are routing methods in the wireless sensor network [17]. So far, several methods for optimal and low-consumption routing in the wireless sensor network have been presented.

Fig. 2
figure 2

Types of routing methods in the wireless sensor network

In [18], they presented a model for reducing energy consumption based on data collection techniques in wireless sensor networks. This model can effectively optimize energy consumption when designing a data collection technique based on pressure measurement for a wireless sensor network.

In [19], they proposed the wireless sensor network's adaptation and adequate energy consumption using source coding methods and sample distribution. This study proposes a unique method to provide simple routing services by reducing traffic latency and end-to-end network performance and achieving better performance using distributed source coding and energy efficiency.

In [20], they presented a hybrid approach for clustering and routing low power consumption in wireless sensor networks. In this method, the optimal positions of the cluster center are calculated using the Krill algorithm, and the Cuckoo search is used to select the optimal cluster head. The simulation results show that the proposed protocol effectively improves the lifespan of the wireless sensor network compared to other existing methods such as GAECH, Hybrid HSAPSO, and ESO-LEACH.

In [21], a new hybrid optimization for the cluster-based routing protocol in information-based wireless sensor networks for IoT computing is proposed. The simulation results show that the proposed strategy is better than other communication techniques in successfully removing malicious nodes, energy consumption, stability period, and network life.

In [22], they proposed a new hybrid optimization for the cluster-based routing protocol in information-based wireless sensor networks for IoT-based mobile edge computing. The results of the experiments show that their proposed method has surpassed the compared methods in terms of grid life and energy efficiency.

In [13], they proposed an energy-based cluster routing protocol for the wireless sensor network using BOA and ACO algorithms. This study uses a BOA algorithm to select an optimal cluster head from a group of nodes. The path between the head of the cluster and the base station is determined using the ACO algorithm, which selects the optimal path based on the node's distance, residual energy, and degree.

In [23], a clustering algorithm based on chicken optimization is proposed to improve energy efficiency in wireless sensor networks. Their proposed method combines CSOCA algorithms with genetic algorithms such as CSOCA-GA and is used to cluster sensor nodes.

In [24], a clustering algorithm has been proposed that selects the heads of clusters using an improved ABC algorithm. This research uses an improved bee algorithm to optimize FCM clustering to find the optimal clustering method.

In [25], they presented a routing protocol inspired by biological methods for the wireless sensor network to minimize energy consumption. The research's weakness is presenting an efficient and accurate objective function to reduce energy consumption in wireless sensor networks.

In [26], the interest, energy, and physically aware coalition and resource allocation in intelligent Internet of Things applications have been investigated and reviewed. The performance of their proposed approach has been evaluated through modeling and simulation, and its superiority over other advanced approaches has been proven.

In [27], they presented a dual algorithm analysis method for optimal cluster head selection in a wireless sensor network. Experiments showed that their method increases the network's lifetime more than the firefly algorithm.

In [28], a meta-heuristic energy-based cluster-based routing scheme for wireless sensor networks is presented with the help of the Internet of Things. The proposed IMD-EACBR model aims to achieve maximum energy utilization and lifetime in the network. In the IMD-EACBR model, they first presented an improved Archimedes Optimization Algorithm (IAOAC) based clustering method to select and organize cluster heads. This study uses the multi-hop routing method based on the TLBO algorithm to select the optimal routes to the destination. Simulation results show improvements in performance in terms of dead node ratio, network lifetime, amount of energy consumed, packet delivery ratio (PDR), and latency.

In [35], they presented a method of reducing energy consumption and optimal routing using an ant colony optimization algorithm for wireless sensor networks. The results of the experiments show that the proposed algorithm reduces energy consumption by 52.36% and increases data transmission efficiency by 61.11% compared to similar algorithms.

In [36], they proposed a routing method based on the PEGASIS routing protocol to reduce energy consumption. In this approach, cluster head selection is considered based on thresholding.

In [37], they presented a routing method in WSN based on an ABC algorithm. In their proposed method, an improved algorithm based on the ABC algorithm is proposed to improve the LEACH protocol. The simulation results show that compared to the LEACH protocol, this algorithm reduces the energy consumption of nodes more. Their routing algorithm increases network lifetime by 33.83% compared to the LEACH protocol.

In [38], they proposed an energy-aware routing protocol based on the genetic algorithm for a wireless sensor network. The experimental results show that their proposed scheme reduces the number of stations by 36.8% and 20% in a network with 100 nodes compared to FF and HL.

In [45], they presented a hybrid algorithm based on ANFIS for routing in wireless sensor networks. In this paper, an inter-cluster routing algorithm with an error management approach in sending packets is proposed to increase the quality of service. The proposed model has achieved lower energy consumption than the existing inter-cluster routing algorithms.

In [46], they presented a mobile sink routing method for wireless sensor networks using the Coyote optimization algorithm. Their proposed technique includes an efficient coyote optimization algorithm for locating nodes. In this paper, Euclidean distance is used as the objective function. Seagull optimization is used to find the optimal path. In their method, a mobile sink is used to navigate the heads. The challenge of their method is to use the Euclidean function as the objective function without considering the packet sending rate. Another challenge of this research is not finding the optimal tour in moving cluster head navigation.

In [47], they presented a routing method in an underwater sensor network using a crow optimization algorithm. This research uses the CROW optimization algorithm to improve AODV routing performance. The simulation of this paper is done in NS 2 tool. SPSS was used to analyze the experiments. Tests showed that the new CROW optimization algorithm had reduced energy consumption by 15% compared to the AODV algorithm. On the other hand, it has also reduced the delay by 25%.

In [48], they presented an efficient energy routing method in the Internet of Things and wireless sensor network with a fuzzy neural approach. In this paper, several parameters for routing in WSN, such as CH to sink distance, cluster size, and residual energy of CH, are obtained by a fuzzy neural network. Experiments show that their method increases the network lifetime compared to PSO-Kmean, BMHGA, and FSO-PSO.

Table 1 compares and evaluates the different routing methods reviewed in the wireless sensor network.According to the studies conducted in most studies, the clustering mechanism of nodes in the wireless sensor network has been used for optimal routing. The problem of cluster header selection is an optimization problem, and the goal is to find optimal clusters to reduce energy consumption in the wireless sensor network. A review of research conducted for routing and reducing energy consumption shows that these methods face the following limitations:

  • In some studies, a GA algorithm has been used to optimize energy consumption and routing. In these studies, algorithms such as the genetic algorithm lack high intelligence, so their routing protocol could be more intelligent. Unlike swarm intelligence algorithms, GA algorithms lack the intelligence to search the problem space.

  • Some studies have used swarm intelligence algorithms such as genetic algorithms; however, the cluster heads collect and send the packet. Sending packets from cluster heads can increase the energy consumption of cluster head nodes and reduce network lifetime. Unlike these approaches, a moving sink mechanism is used in the proposed method so that the cluster heads waste less energy.

  • In some studies, an optimization algorithm such as ABC has been used to find the optimal path to navigate the cluster heads. Investigations show that the ACO algorithm used in the proposed method can navigate the cluster heads and find the shortest path for navigation.

  • Most meta-heuristic methods, such as HHO and WOA algorithms for clustering, have a lot of complexity. In contrast, the WSA algorithm used in the proposed method has less complexity and more superficial relationships.

  • The methods used are less scalable due to a fixed sink, but the proposed method uses a moving sink to solve this challenge.

Table 1 Results, advantages and disadvantages of different routing methods

In addition to the examined approaches, several other approaches have been compared in routing in Table 2 in the Internet of Things network routing. In this Table, routing approaches are discussed in terms of their strategies, performance, advantages, and challenges, and here a relevant paper is considered for each approach:

Table 2 Comparison of routing approaches in Internet of Things network

Routing in wireless sensor networks is in the optimization field because it tries to send packets through optimal routes. To solve optimization problems in routing, one of the efficient methods is meta-heuristic algorithms. Meta-heuristic algorithms are used to solve optimization problems based on the laws of nature. In [39], a category of meta-heuristic algorithms for solving optimization problems in 9 different classes is shown in Fig. 3.

Fig. 3
figure 3

Classification of meta-heuristic methods [39]

According to [39], meta-heuristic algorithms are classified into Physical-based, Social-based, Swarm-based, Chemistry-based, Biology-based, Sports-based, Math-based, and Hybrid categories. Each meta-heuristic algorithm is classified into Single-Point and Multi-Point based on the number of solutions they produce in each step. In Single-Point methods, there is one solution in each step, and in Multi-Point methods, in each step, there are several solutions in the problem space.

In most research, such as [40], benchmark functions, which are mathematical functions, are used to evaluate meta-heuristic methods. Swarm intelligence algorithms behave more intelligently than other meta-heuristic algorithms. Swarm intelligence algorithms are modeled on animals' behavior: hunting, finding food, mating, escaping from attackers, etc. The advantage of swarm intelligence algorithms is the swarm's parallel navigation of the problem space. In swarm intelligence algorithms, other members can find the global optimum if one or more solutions are stuck in the local optimum. The WSA and ACO algorithm is a clear examples of swarm intelligence algorithms. The WSA algorithm has various search strategies, such as foraging, mating, escape, and death. Due to the presence of four different types of search in the WSA algorithm, this algorithm has high accuracy in finding the optimal solution.

For this reason, it is used to solve the complex clustering problem and find the optimal cluster head in the proposed method. The ACO algorithm is also a swarm intelligence algorithm. The ACO algorithm is modeled based on finding food by ants and traveling the shortest path, and for this reason, it is used in the proposed method to find the optimal tour by the mobile sink.

Meta-heuristic algorithms, in combination with machine learning and deep learning methods, are also used in wireless sensor networks. For example, in [42], RPLNN were used to optimize the wireless sensor network, and the results show that their method is more efficient than the genetic algorithm. The ultimate goal of this paper is to present and evaluate a way of modeling and to optimize nonlinear RNP problems utilizing artificial intelligence techniques. Neural networks, like meta-heuristic algorithms, are also used in various applications such as routing and Effective Active Suspension Systems. Artificial intelligence is used to predict the path of sending packets in WSNwsn [43, 44].

Clustering is an effective method in designing routing algorithms for wireless sensor networks and the Internet of Things, which improves network lifetime and energy efficiency. Cluster heads have to do more work, so they consume more energy. Therefore, choosing the optimal cluster head is an important issue. Unlike other studies, the proposed method for optimal routing does not only consider reducing energy consumption. Various factors, such as low error paths, low latency, and high power nodes, have provided an optimal routing algorithm. The proposed method performs clustering with the WSA algorithm presented in 2020. The reason for using the WSA algorithm in the proposed method and the clustering phase is the following:

  • More accurate than proposed algorithms such as GA and PSO

  • It has several advanced strategies for searching the problem space.

  • Unlike many swarm intelligence methods, it has a mechanism of competition among population members to find the optimal solution.

Unlike many studies, the proposed method uses a moving sink mechanism after selecting the cluster head. The mobile sink collects information from the clusters header and eventually sends this information to the base station. Using a mobile sink reduces energy consumption at the top of the clusters. In the proposed method, the ACO algorithm is used to make the moving sink a shorter path between the heads of the clusters.

3 The proposed method

The steps of the proposed method for low consumption and optimal routing in the WSN network are as follows:

  • By the WSA algorithm, network nodes are clustered, and the WSA algorithm selects cluster heads.

  • A moving sink meets the threads by selecting the cluster header. The optimal path between the clusters is selected using the ACO algorithm.

In the continuation of this section, the steps of the proposed method are explained.

3.1 Proposed framework

The framework of the proposed method is shown in Fig. 4 to select the optimal headers and find the optimal path between the cluster headers. According to the proposed framework, a water strider of the WSA algorithm is coded as a set of cluster heads. Each member of the WSA algorithm is a suggestion for selecting clusters.

Fig. 4
figure 4

Optimal routing framework with WSA and ACO algorithms

Each component of a WSA is a node number to select the head of the cluster. The proposed method creates several random members in the WSA algorithm. Each water strider is evaluated with the objective function described below. The population’s feeding, mating, and removal can be applied to select the optimal cluster heads. The most optimal water strider is selected in the last iteration, and this solution has the optimal solutions as a herd.

The second phase can be performed by calculating the optimal clusters by the WSA algorithm. In the second phase, there is a set of cluster headers whose information is collected by a moving sink. The moving sink uses the ant colony optimization algorithm to find the optimal path. In the proposed method, each chooses a path and tries to choose the next step based on the amount of pheromone in each path.

In the ACO algorithm, a pheromone matrix is updated at each iteration. Each path is affected by evaporation to avoid convergence of the solutions to the local optimal. The ant colony algorithm updates the optimal path in each iteration. In the last iteration, the optimal path between the heads of the clusters is selected. The mobile sink receives packets from the earthenware according to this path. The moving sink collects the data and sends it to the base station.

3.2 Objective function

There are several factors to consider when choosing a header in this paper. The first factor is the energy consumption of a node that must be minimized. The second factor is the average error rate of sending packets from one node to another, and it should be minimized.

The third factor is the ratio of the number of packets sent to the packets received at the destination, the minimum of which is desirable. The proposed objective function for selecting a header can be formulated as in Eq. (1)

$$Cost = \left\{ {\begin{array}{*{20}c} {\min En} \\ {\min Er} \\ {\begin{array}{*{20}c} {\min Se/Re} \\ \end{array} } \\ \end{array} } \right.$$
(1)

In this equation, En, Er, and Se / Re are the energy consumed in each node, the error of sending packets on a link, and the rate of sending packets to receive them at the source. The objective function in question can be rewritten as a linear and unit function such as Eq. (2):

$$Cost = \alpha .En + \beta .Er + \gamma .Se/Re$$
(2)

In this function, α, β and γ are three random numbers weighing between zero and one. Total α, β, and γ are equal to one. If a selected set of headers can minimize this objective function, it is considered the optimal header.

3.3 Selecting the optimal cluster head

The WSA algorithm has five stages, including birth, the establishment of territory, mating, feeding, and death mathematically. During the implementation of the algorithm, the search space is defined as a lake. The problem space contains different areas, and food is a metaphor for the performance of the goal. In the first stage, birth, several eggs are scattered in the problem space, and water striders are created in the random problem space.

Figure 5 shows the relationship process for mating between male and female species that find their place and position by vibration. Figure 6 shows the situation in which two species have succeeded in mating, and in Fig. 7, the female species escape from the male species, and mating does not occur. If mating is successful, their new position is within a specified range and radius R [14].

Fig. 5
figure 5

Establishing a relationship between male and female water strider [14]

Fig. 6
figure 6

Successful mating between male and female species [14]

Fig. 7
figure 7

Mating failure [14]

In case of mating or unsuccessful mating, the position of male and female species is updated. The mating process in water striders wastes a lot of their energy; therefore, they need to replenish food energy after participating in mating, whether successful or not. In this case, an aquatic insect, as in Fig. 8, goes to a place that has more food or merit in the population:

Fig. 8
figure 8

Feeding behavior of water strider [14]

The role of the water strider algorithm is to select the optimal clusters in the wireless sensor network. If the total population is the NWS and there are the NT groups, then the (NWS/NT) is the territory, and the most optimal insect of each female group and other male members are considered. The next phase of the algorithm is mating. There is a probability of p for mating, and the probability of non-mating is considered 1-p. Modeling of mating success behavior and mating failure can be formulated in Eq. (3) [14]:

$$WS_{i}^{t + 1} = \left\{ {\begin{array}{*{20}c} {WS_{i}^{t} + R.rand} & {Mating} \\ {WS_{i}^{t} + R.\left( {1 + rand} \right)} & {No mating} \\ \end{array} } \right.$$
(3)

In this equation, \({WS}_{i}^{t}\) is the position of a water strider in iteration t and \({WS}_{i}^{t+1}\) is the position of water strider in the new repetition or t + 1. In this regard, R, according to Eq. (4), is the distance between a male water strider such as \({WS}_{i}^{t}\) and a female water strider such as \({WS}_{F}^{t}\) [14]:

$$R = WS_{F}^{t} - WS_{i}^{t}$$
(4)

The feeding equation of water strider can be presented according to Eq. (5) [14]:

\(WS_{i}^{t + 1} = WS_{i}^{t} + 2rand.\left( {WS_{BL}^{t} - WS_{i}^{t} } \right)\) (5)

In this equation, the rand parameter is a random number between zero and one. In this equation, a water strider seeks the space between itself or \({WS}_{i}^{t}\) and the best solution to the problem or\({WS}_{BL}^{t}\). In some cases, it is observed that a water strider is transmitted instead of being transmitted, which has little food. In this case, the insect or the desired solution is destroyed and a new solution is created instead of in the problem space. Equation (6) is used to create a new solution [14]:

$$WS_{i}^{t + 1} = Lb + 2rand.\left( {Ub - Lb} \right)$$
(6)

Lb and Ub are each solution’s minimum and maximum ranges in this equation, respectively. The steps of the WSA algorithm are repeated and in each step, a counter is added to the algorithm counter. In each iteration, it is checked that the algorithm counter does not exceed the maximum value. In each iteration, the optimal cluster headers are updated, and in the last iteration, these headers are used to cluster the nodes in the wireless sensor network. In the next phase, the ACO algorithm selects the optimal path between the clusters.

3.4 Optimal tour

The ACO algorithm is a population-based meta-heuristic algorithm. In population-based algorithms, each member of the population tries to be optimally targeted. Each Ant is a solution to an optimization problem, such as the order of city visits in the TSP problem. In a problem such as a roundabout seller, each Ant uses the length of the path traveled to evaluate it and how optimal it is. The ACO algorithm population members randomly select a vertex of the problem graph and try to move from the vertex to other cities. In this case, their trajectory shows a tour of the traveling salesman's problem. Each Ant randomly selects a node's neighbors in the problem graph.

The members of the ACO algorithm population eventually travel each route from origin to destination to complete the Hamiltonian circuit. The shorter the path, the more qualified it is, and the more ants pass through it. Optimal routes have more ant pheromone or acid due to movement. In the next iteration of the ACO algorithm, the amount of pheromone poured on the edges can control and direct the movement of ants to the optimal points. The amount of pheromone poured on the edges of the graph, and the length of the path traveled on the graph determines a possible function such as Eq. (7) [41]:

$$p_{ij}^{k} = \left\{ {\begin{array}{*{20}c} {\begin{array}{*{20}c} {\frac{{\left( {\tau_{ij} } \right)^{\alpha } \left( {\eta_{ij} } \right)^{\beta } }}{{\mathop \sum \nolimits_{{m \in N_{i}^{k} }} \left( {\tau_{im} } \right)^{\alpha } \left( {\eta_{im} } \right)^{\beta } }}} & {j \in N_{i}^{k} } \\ \end{array} } \\ {\begin{array}{*{20}c} {0 } & {j \notin N_{i}^{k} } \\ \end{array} } \\ \end{array} } \right.$$
(7)

In this equation, \({p}_{ij}^{k}\) is the probability that the ant k can go from city i to city j. The parameter \({N}_{i}^{k}\) of the neighbors of node i in the graph is a problem that ant k has not yet met. In this equation, m is the number of a neighboring node. The parameter \({\eta }_{ij}\) is an exploratory function to go from city i to city j. The parameter \({\tau }_{ij}\) is the amount of pheromone poured in the path between vertices i and j. The parameter α is the group learning coefficient and β is the individual or greedy learning coefficient of each ant. The exploratory function \({\eta }_{ij}\) is traditionally determined by the distance between vertices i and j according to Eq. (8) [41]:

$$\eta_{ij} = \frac{1}{{d_{ij} }}$$
(8)

In this equation, \({d}_{ij}\) is the distance between two nodes, i and j. Each ant can add some pheromone to the edge between vertices i and j according to Eq. (9) [41]:

$$\tau_{ij} = \tau_{ij} + \mathop \sum \limits_{k} \Delta \tau^{k}_{ij}$$
(9)

In this equation, \({\tau }_{ij}\) is the number of pheromones released in the i to j path by members of the ant population. The parameter \(\Delta {{\tau }^{k}}_{ij}\) is the amount of pheromone poured by the ant in the path i to j. To prevent convergence to optimal local solutions and the dynamics of the ant colony algorithm, pheromones poured into a path with a certain probability evaporate and the pheromone content of that path is reduced as in Eq. (10) [41]:

$$\tau_{ij} = \left( {1 - \rho } \right).\tau_{ij}$$
(10)

In this equation, ρ is the pheromone evaporation coefficient in the ACO algorithm. By running the ACO algorithm, the moving sink finds the optimal path to navigate the ants. By moving this optimal path, the mobile sink collects the data and sends it to the base station.

4 Analysis

In this section, the proposed algorithm for reducing energy consumption is analyzed. In primary energy experiments, the nodes are assumed to equal 1 J. The population size of meta-heuristic algorithms is 10.

The number of iterations of WSA and ACO algorithms is 100. In simulations, the number of live nodes at the beginning of the simulation is 1000. The population size of meta-heuristic algorithms is equal to 10, and the maximum iteration of each meta-heuristic method is equal to 50. In the proposed method, the mating probability of each aquatic insect is equal to 0.5. The ACO algorithm’s alpha and beta coefficients equal 0.7 and 0.8, respectively. The initial value of the pheromone is equal to 1, and the evaporation coefficient of the pheromone is equal to 0.05. Individual and group learning coefficients in the PSO algorithm equal 2.0 each.

The value of the inertia coefficient in the PSO algorithm is equal to 0.9. The value of coefficient 'a' in the GWO algorithm equals 2.0 in the first iteration and is set to zero in the last iteration. The value of coefficient C in the GWO algorithm is randomly between [0,2]. The value of l and b in the WOA algorithm equals a random number in the interval [− 1,1] and 1, respectively. The value of E or initial energy in the HHO algorithm is equal to 2, and the escape coefficient or J in the HHO algorithm is between 0 and 2. The number of tests is equal to 30.

4.1 Residual energy analys

In Fig. 9, the residual energy in the Particle swarm optimization (PSO), Grey Wolf Optimizer (GWO), LEACH-Centralized Sleeping (CS), Clustering Communication Protocol Based on Intelligent Computing, Cluster based routing (CBR)- Information-centric wireless sensor networks (ICWSN) [34], and Water strider algorithm and Ant Colony Optimization(WSAACO) algorithms(proposed method) is shown from 0 to 20,000 depending on the implementation of the simulation steps.

Fig. 9
figure 9

Comparison of residual energy in WSA

The energy remaining in the nodes is a decreasing trend in all methods for repeating the simulation steps. The amount of residual energy decreases over time, and this reduction is made with a lower slope in the proposed method. The residual energy diagram in the proposed method is higher than PSO, GWO, CS, CCP-IC, and CBR-ICWSN. The residual energy in the proposed method is still present in the 1900 stage, but the residual energy in the other methods is zero. The more residual energy in the proposed method shows this method increases the network’s life.

4.2 Analysis of the number of living nodes

In Figure 10, the number of live nodes in the network in the proposed method and other methods is compared in WSN. Evaluations show that when the proposed method has 136 active nodes, other methods except CBR-ICWSN do not have active and live nodes. The competing algorithm for the proposed method at this stage is CBR-ICWSN. The number of live nodes per round is 16000, 17000, 18000, and 19000 for the CBR-ICWSN method are 270, 110, 80, 20, and 0, respectively. The number of live nodes in the 16000, 17000, 18000, and 19000 rounds for the proposed method is 295, 136, 97, 38, and 12, respectively. The proposed method has more live nodes at each stage than other methods, confirming that the network life is extended.

Fig. 10
figure 10

Comparison of live nodes in the proposed method and other methods

Evaluation of the residual energy diagram shows that the best method is the WSAACO algorithm, and the worst is the CCP-IC algorithm. The CS algorithm and the GWO algorithm also could improve performance. In most cases, the CBR-ICWSN method performs better after the proposed method, followed by the PSO method regarding energy storage performance. Graph analysis of the number of live nodes shows that the number of live nodes is decreasing according to the simulation steps, and this reduction in network life in all methods decreases over time. In step 19,000, only the proposed method and CBR-ICWSN have live nodes, and their number is 38 and 20, respectively. In the last step, or 20,000, only the proposed method has a live node, and their number equals 12. Among the methods compared, the best performance in the number of live nodes is related to the proposed method, and the worst performance is related to the CCP-IC method [34].

4.3 Network life analysis

This section analyzes the proposed method in three indicators related to network life. The first node die (FND) index is the death time of the first node in the network. The half-node die (HND) index is when half of the network nodes die. The last node die (LND) index is related to the death time of the last node in the network. Figures 11, 12, and 13 show the FND, HND, and LND indices in the proposed method and other methods [34].

Fig. 11
figure 11

Comparison of FND index in the proposed method and other methods

Fig. 12
figure 12

Comparison of HND index in the proposed method and other methods

Fig. 13
figure 13

Comparison of LND index in the proposed method and other methods

The FND index in PSO, GWO, CS, CCP-IC, CBR-ICWSN methods and the proposed method are 495, 675, 888, 1104, 1998, and 2135, respectively. The proposed method loses its first node later than other methods[34]. The HND index of PSO, GWO, CS, CCP-IC, CBR-ICWSN methods and the proposed method is 9111, 6253, 7514, 5212, 13,289, and 14,514, respectively. The proposed method based on the HND index loses half of its nodes later than other methods [34].

LND index of the PSO, GWO, CS, CCP-IC, CBR-ICWSN methods and the proposed method has values 16,521, 15,249, 13,186, 11,192, 19,174, and 19,742, respectively. The proposed method loses the last node later. Among the methods presented in the FND index, the worst performance is related to the particle algorithm. The best performance in the FND index is related to the proposed method. In the HND index, the worst performance is related to the CCP-IC method.

The best method is the proposed method. In the LND index, the CCP-IC method performs worst, and the proposed method is the best.

4.4 Packet delivery ratio (PDR)

The packet delivery ratio (PDR) is essential for evaluating the proposed and other methods. In Fig. 14, the PDR index in the proposed method is compared with similar algorithms [34]. Evaluations show that as the number of nodes increases, the PDR rate decreases in all methods. In this test, the number of network nodes equals 100; the highest PDR rate is related to the proposed method and is equal to 97.3%. At low sensor network density, the PDR rate of the particle swarm optimization algorithm is lower than other methods. At high density, the PDR rate of the proposed method is 87.1%.

Fig. 14
figure 14

Comparison of PDR index in the proposed method and other methods

The second is the CBR-ICWSN method, which has a PDR rate of 85%. The higher PDR rate in the proposed method indicates that the selection of headers is optimal, and the ACO algorithm used in the proposed method has delivered the packets to the destination more successfully.

4.5 Loss rates of packages

The reduction rate of packages is another important factor in evaluating the proposed method. A routing algorithm is booming in a wireless sensor network when the packet loss rate is minimal. Figure 15 show the PSO, GWO, CS, CCP-IC, CBR-ICWSN methods and the proposed method. Among the methods compared, the proposed method has a lower loss rate at different densities of sensor nodes. Because the packet loss rate in the proposed method is lower than in other methods, the resending of packets is less; and energy consumption will be reduced.

Fig. 15
figure 15

Comparison of packet loss index in the proposed method and other methods

If the packet loss rate in a routing method is low, this method is more intelligent for selecting the header, and the headers are selected more carefully. Optimal selection of headers allows packets to be sent in optimal and error-free routes. Since the proposed objective function has a factor for error minimization, the WSA algorithm selects the headers well to minimize packet-sending errors. Among the methods compared, the particle optimization method, both at low and high density, had the highest error in sending packets from origin to destination [34].

4.6 Complexity analysis

This section examines the proposed algorithm's complexity in the clustering and moving sink phase. WSA algorithm is used in the clustering phase. In this step, the WSA algorithm is repeated T times, and it is assumed that the population size of the meta-heuristic algorithm is N. The WSA algorithm has one loop for repetition and three loops for the foraging, mating, and death phase, so the algorithm's complexity in this phase is O(T.(N+N+N)). The complexity in the clustering stage is O(3×T×N).

In the ACO algorithm, similar to the WSA algorithm, three different phases are performed on the population of the ACO algorithm and in T times. The computational complexity in the moving sink stage is O(3×T×N). The total computational complexity of the proposed algorithm is equal to O(3×T×N) + O(3×T×N). The proposed algorithm is optimal routing and is compared with HHO, WOA, and GWO in the execution time index. The proposed algorithm in Figure 16 has been compared with three meta-heuristic algorithms, HHO, WOA, and GWO, in the execution time index.

Fig. 16
figure 16

Comparing the execution time of HHO, WOA and GWO algorithms with the proposed method for optimal routing

Experiments in MATLAB show that the execution time of the proposed algorithm is 1.14 seconds, and the execution time of HHO, WOA and GWO algorithms is 1.54, 1.21, and 1.39 seconds, respectively. Experiments showed that the execution time of the proposed algorithm is less than HHO, WOA, and GWO algorithms. Routing algorithms require a real-time mechanism, so the proposed algorithm implementing in WSN networks because its execution time is short. The execution time of the proposed method is less compared to HHO, WOA, and GWO due to fewer calculations of the WSA algorithm, and the complexity of this algorithm is also less. The proposed method calculates the optimal path for sending packets every 1.14 seconds; This does not mean the algorithm is executed every 1.14 seconds because the paths stay the same in a certain period.

Therefore, it is suggested that the proposed algorithm implements in specific time intervals for faster routing. Another suggestion is that if the delay of sending packets increases, the algorithm should be re-executed to find optimal routes. However, all meta-heuristic algorithms have a little delay in finding the optimal paths, but the delay of sending packets in the network is reduced after finding the optimal paths.

4.7 Scalability analysis

Algorithms used for routing and reducing energy consumption in wireless sensor networks are also evaluated with indicators such as scalability. The scalability of an energy consumption reduction algorithm shows that the proposed method implements any number of nodes and dimensions, and scale. One of the essential features of a wireless sensor network is its scalability, and the proposed method is implemented in this network.

The proposed method has two phases clustering by the WSA algorithm and finding the optimal path by the ACO algorithm. The proposed method can be applied to find cluster heads at any scale in the clustering stage. The proposed method for finding the optimal path between the cluster heads by the mobile sink is also highly scalable. Suppose the ACO algorithm is not used in finding the optimal path between the cluster heads. In that case, this problem is like a Traveling Salesman Problem(TSP), and it takes a lot of time to find the optimal path with non-meta-heuristic methods.

In simpler words, if meta-heuristic methods such as ACO are not used in finding the optimal paths between the cluster heads, then with the increase in the number of cluster heads, a lot of time is needed to find the optimal path, and the scalability will decrease. By the ACO algorithm, optimal or relatively optimal routes are calculated in polynomial time. Therefore, increasing the number of nodes and cluster heads makes the ACO algorithm faster and more scalable than deterministic methods.

4.8 Comparison with related works

Table 3 compares the proposed method with related works. The proposed method has been compared with related works in network life index, delay, PDR rate, and complexity.

Table 3 Comparison of the proposed method with related works

The proposed method increases the network's lifetime, its delay rate is low, and it has a high PDR index. The proposed method has moderate complexity of polynomial order.

5 Conclusion

The wireless sensor network uses in various applications. The wireless sensor network has several nodes that collect environmental information and send it to the base station. Routing with an energy reduction approach is a vital problem in a wireless sensor network. An effective routing method to reduce energy consumption is clustering nodes and selecting headers for several network nodes.

With the clustering approach, each node sends the data to the cluster instead of the base station. The cluster head receives the data and sends it to the base station. A routing approach aimed at reducing energy consumption is proposed in this paper. The sensor nodes are clustered in the first step using the WSA algorithm. In the proposed clustering, three factors of error rate, energy consumption, and the ratio of sent packets to received packets are formulated to select the cluster head. The ACO algorithm is implemented in the second phase to find the optimal path between the clusters. The role of the ACO algorithm is to find the optimal tour(path) for collecting information by a mobile sink. Evaluations and tests performed in MATLAB show that the proposed method increases the network life more than PSO, GWO, CS, CCP-IC, and CBR-ICWSN methods. Experiments show that the proposed method has a lower rate of packet loss. The proposed method has a higher receiving report rate than PSO, GWO, CS, CCP-IC, and CBR-ICWSN.

Experiments show that the proposed method requires less time for optimal routing than meta-heuristic algorithms such as HHO, WOA, and GWO. In other words, the proposed method has less delay in optimal routing due to its lower complexity than HHO, WOA, and GWO. The lower complexity of the proposed algorithm compared to the meta-heuristic algorithms of HHO, WOA, and GWO makes the nodes executing the proposed algorithm require less execution time. On the other hand, they need less battery consumption to run the proposed algorithm. The proposed method's advantage is providing a routing algorithm by reducing energy consumption and sending packets on routes with lower error rates. Increasing network lifetime compared to PSO, GWO, CS, CCP-IC, and CBR-ICWSN is one of the advantages of the proposed method. The proposed method in routing has more stability than similar algorithms. Another advantage of the proposed method is to collect data from the cluster heads and reduce the energy consumption of the cluster heads with this strategy.

One of the limitations of meta-methods and the proposed method is computation time and execution time overhead. Another limitation of using meta-heuristic algorithms in routing is uncertainty. In other words, meta-heuristic algorithms provide a different solution than the previous examination. This problem is due to the use of pseudo-random equations in meta-heuristic algorithms. Another limitation of the proposed method is that meta-heuristic algorithms are prone to converge to locally optimal solutions. There are solutions to each of these challenges. By increasing the number of tests and calculating the average of indicators and criteria, the uncertainty of the solution can be reduced. Improving the intelligence of meta-heuristic algorithms can reduce the meta-heuristic algorithms' convergence rate to locally optimal solutions, and this issue will be considered in future works.

The combination of the WSA and ACO algorithms reduced energy consumption compared to several routing protocols, and the first supposition is proven. Based on the tests, using the mobile sink has a lower energy consumption than the no-mobile-sink strategy, and the second supposition is also proven. Experiments show that the proposed method has less energy consumption than algorithms such as PSO, CS, etc., and the third supposition is also proven.

One of the proposed method's challenges is the congestion problem in network routes. In future research, ANNs will be used to predict congested paths. In future work, routes will be selected to send packages that are not congested. Congestion prediction methods are one method to control congestion and pass packets through uncongested routes. Deep learning and neural networks are used to select nodes to send packets that do not have congestion. The neural network can predict which paths are less congested to send packets. Providing an improved WSA and ACO algorithm is another future work for optimal routing in WSN. It is suggested that the problem of routing in the wireless sensor network and the Internet of Things should also be investigated with fields such as Task Offloading [49] and edge computing [50].