1 Introduction

The presence of internet in all places, developments and advances in wired and wireless communication technologies, network development (especially in wireless domain), IT developments (such as high-power processers, large random access memory chips, digital signal processing and network computations) are all regarded as instances of recent engineering developments. All these advances have opened the door to a new generation of cheap sensors which have high temporal and special detection power. Researchers consider WSNs as an interesting emerging domain which includes wireless network systems with limited power, processing capacity and memory size. In these systems, sensor nodes constitute a large interconnected and unified network which is used for high-resolution measurement [1]. WSN is considered to be a cheap network which has been planned for new applications in areas such as physical security, health care and business. These networks are regarded as a multi-disciplinary field which includes radio and network signal processing, artificial intelligence, database management, system architecture for operator-compatible infrastructures, resource optimization, power management algorithms and technology platforms (hardware and software such as operating systems) [2]. It should be noted that the applications, network principles and the protocols of these systems are constantly evolving and developing.

Measurement and control technologies include the following sensors: electric and magnetic field sensors, radio frequency sensors, infrared, vision and electro-optic sensors, radars, lasers, position gauging and navigation sensors, seismic and wave pressure sensors, sensors of environmental parameters (wind, moisture and heat) and national security and biochemical sensors. Nowadays, these sensors can be defined as cheap smart devices which are equipped with various measurement factors. They are low-cost, low-power multitask nodes which are logically connected to a sink node [3]. Sensors are connected to the network via a set of low-power wireless links within multi-hop distance (they are specifically defined within a sensor domain). They usually use the internet and other networks for transmitting information to remote spot (spots), for collecting final data and analyzing them. In general, within a sensor domain, a WSN uses competitive random access channels and transitional technologies which are currently located within the set of IEEE 802 standards. Moreover, these techniques have been originally developed in the later 1960s and early 1970s especially for wireless areas and for a large set of scattered nodes with limited channel managerial information [4]. In a WSN, the required power of sensor nodes for transmitting and receiving data is supplied by battery. Given the fact that sensor nodes’ battery volume is limited, new protocols should be designed in a set of domains such as information transmission, operation and network management, privacy, integrity, local access and processing within the network [5].

The main objective of routing protocols in WSNs is to minimize sensor nodes’ power consumption. Samples of environmental data should be collected by sensor nodes; then, they should be transmitted via low-cost links (in terms of number of hops and power consumption) to the data consuming spot (sink) so that they can be analyzed and manipulated. Regarding architecture, WSNs are generally divided into two categories: flat and hierarchical distribution [6]. Firstly, sensor nodes are randomly distributed in the area. Then the network of sensor nodes is organized with a particular topology distribution such as clustering or tree. Sensor nodes usually have very limited resources (in terms of power, computations, communications and storage). They can carry out three key tasks, namely measuring physical quantities (such as temperature or light) of the environment, processing and storing evaluated data and transmitting data to the gathering spot (sink) so that they can analyzed in the future and accessed by the consumer. WSN routing is regarded as a research domain which focuses on the communication among sensor nodes via single-hop or multi-hop routes for transmitting data packets from the occurring areas to the sink. A routing protocol finds the data transmission route from the source node to the destination node and impacts on the status of links in the discovered route regarding packet delivery rate (PDR) in data flows. As a case in point, if a routing protocol finds a route with overcrowded and congested links, data flow might experience high end-to-end delay and low PDR. For discovering a route, routing protocol uses a routing parameter such as the shortest route. Selecting a routing parameter may affect the quality of discovered routes. For example, routes which are established based on the parameter of the shortest route might include links with excessive data traffic. Hence, data flow may encounter high delay and low PDR. The number of routes which are discovered and maintained by the routing protocol towards the sink node can influence the operation of a data flow. However, in case data packets are transmitted to the sink through low-power routes, nodes might be turned off and the costs increases due to data re-transmission. Finding appropriate routes for data transmission reduces the number and size of transmission; also, power consumption is reduced since data retransmission is not needed. Accordingly, in this paper, an effort was made to use low-cost links for transmitting data flow to the sink. One method for finding low-cost links is to use clustering in network topology. Nonetheless, the majority of available clustering methods select cluster-heads randomly. Consequently, due to sensor nodes’ limited power resources and the active nature of wireless communication links, this condition leads to imbalanced power consumption and optimal route may not be selected. Hence, in this research study, using AFSA (artificial fish swarm algorithm), we present an energy-aware routing protocol for WSNs which can find optimal routes towards the sink node; as a result, by transmitting data through the optimal route, power consumption reduced. In this way, network lifetime is enhanced.

2 Related Works

Several clustering algorithms have been developed and proposed for saving power consumption in WSNs some of which are briefly reviewed here. AN energy-aware routing protocol, called ERA (energy-aware routing algorithm), was reported in study [7] for clustering WSNs. For selecting cluster-head in this algorithm, the remaining energy and within-cluster distance were taken into consideration; also, a direct virtual backbone of cluster-heads was established which was rooted in the sink node. This method consisted of two phases: clustering phase and routing phase. In the clustering phase, sensor nodes are grouped within separate clusters. Before starting its competition for becoming cluster-head, each sensor node independently adjusts its scheduling. According to this algorithm, a node with further remaining energy is selected as the cluster-head. When the scheduling is over, the node with higher remaining energy selects itself as the cluster-head and broadcasts a message introducing itself as the cluster-head within the related domain. If a neighbor receives this message, it quits its candidacy for becoming cluster-head and adjusts its scheduler t zero. Hence, in the next round, it will be a usual node. Then, by sending a message, the neighbor node announces its joining to the closest cluster-head with the most remaining energy. For routing data towards the sink, a direct virtual backbone which is rooted in the sink is created for all the cluster-heads. Researchers in [8] proposed RTGOR (reliability and timeliness guaranteed opportunistic routing) for meeting the operational needs of the cyber-physical information transmission system in WSNs. This protocol is based on opportunistic routing along with reliability at the transmission time. Here, researchers used two service quality coefficients, namely delay and reliability. Prediction of transmission delay has been defined according to bilateral transmission success rate as the routing criteria. The node with smaller delay is selected as the next transmission for guaranteeing the lowest delay. In this method, network load is reduced and network communication capability is optimized.

Adaptive threshold sensitive energy efficient network (APTEEN) was proposed in [9]. Here, due to the imbalanced power consumption of CH (cluster-head), CH is turned off after a while. Hence, researchers used ant colony algorithm for avoiding this problem. As a result, they called the second algorithm ADCAPTEEN (adaptive threshold-sensitive energy efficient network based on ant colony) which operates better than the first one in clustering and selecting CHs. In this method, main clusters are selected and a CH is selected in each cluster. The two CHs cooperate in collecting data, fusion, data transmission, etc. In each round, CH within each cluster is selected based on ant colony algorithm. As a result, several data transmission routes are established. ADCAPTEEN was simulated in OPNET which proved that, when compared with APTEEN, ADCAPTEEN reduces power loss, enhances node survival rate and expands network life cycle. Nodes are randomly deployed and are divided into networks. Each network is regarded as a cluster where CH is definitely selected based on two parameters: remaining energy and distance from the station. Accordingly, network lifetime will be enhanced by reducing the number of unauthorized and invalid communications and data processing [10].

CBA (Cluster-Based client/server data Aggregation routing protocol) was proposed in [11]. Using light-weight clustering approach and Hamming distance, this protocol dynamically divides network into a set of data-oriented clusters. Then, it establishes a tree backbone and transmits the results of each cluster to the sink. The objective of this protocol was to maximize energy efficiency and the precision of data accumulation and minimize end-to-end delay. Dynamic data-based clustering enables CBA to collect and accumulate desirable samples of data without considering distribution model or heterogeneity. An algorithm was proposed in [12] for finding optimal CH in distributed WSNs. CH is randomly selected and a threshold value is considered. If its probability value is less than threshold in each round, CH will be selected as the temporary CH. After a number of CHs are randomly selected in the network, temporary CHs will send an announcement message; as normal nodes receive this message, they will select the closest CH based on their distance and they will transmit a connection message to the temporary CH. Then, in case the remaining energy of the entire cluster is more than 50% of its initial energy, the node with more energy will become the new CH. Otherwise, the node with more neighbours will be selected as the new CH. In the next rounds, as the remaining energy of the CH drops to less than 50% of the total initial energy of the cluster, re-clustering will be done. Simulation results indicated that this method optimized power consumption and enhances network lifetime.

Swarm optimization-based energy-efficient clustering and sink mobility in wireless sensor network was proposed in [13]. This work uses the PSO to deal with both cluster head selection problems and sink mobility problems. In the proposed method, five factors such as residual energy, distance, node degree, average energy, and energy consumption rate are considered for CH selection. Also this method the concerned with relaying the data traffic in a multi-hop network by introducing sink mobility. Simulation results indicated that this method optimized stability period, network, and longevity, number of dead nodes, throughput, and network's remaining energy.

In [14], an energy optimization way for target tracking is carried out using Particle Swarm Optimization is proposed. The proposed work has two phases clustering phase and the target tracking phase. Clustering is performed using maximum entropy method with modified shortest path algorithm comprises of localization operation, Clustering mechanism using Genetic Algorithm. The target tracking phase has been implemented using particle swarm optimization with the coverage model. Tracking is performed with the help of node's position, velocity, acceleration, and angle. The next position of the target is estimated with the current location, speed, and angle of movement. Performance evaluation is carried out for the proposed target tracking method shows slightly better results than the existing system.

In [15] proposed a hybrid optimization algorithm for clustering of the wireless sensor networks. The proposed method has three phases includes the setup phase, transmission phase, and measurement phase. In the setup, phase proposed the choosing CH using the rider cat swarm optimization algorithm; the CH is chosen using multi-criteria, which involves distance, energy, and delay. In the transmission phase, data transmission begins from CHs to the sink. In the measurement phase, the residual energies produced from the nodes are updating. Simulation results indicated that this method optimized energy consumption, throughput, and the number of alive nodes.

In [16] proposed an energy-efficiency clustering protocol, in which the monitor area is divided into several annuluses with different width. By considering the distance between sensor nodes and sink, sensor nodes are classified into different levels in other steps, cluster head selection and cluster formation are conducted independently in each annulus. Then, data transmission paths are established among annuluses, and a strategy of cluster head rotation and cluster adjustment is proposed also. In this method, the clustering is conducted in each annulus independently, to save a large amount of energy. The simulation results illustrate the effectiveness of ADEC in terms of energy efficiency and energy balance.

3 The Proposed Method

In this paper, we used FSA for clustering WSNs. Artificial fish swarm optimization algorithm (AFSA) is one of the algorithms which is based on swarm intelligence (SI); AFSA was proposed by Lee et al. [17] in 2002 according to the social behavior of fish. This algorithm has features such as high convergence speed, no sensitivity to the initial values of artificial fish, flexibility and error tolerance which make it appropriate for solving optimization problems. The underlying rationale of AFSA is based on functions which have been derived from the social behavior of fish swarm. In the underwater world, fish can find areas where there are more prey. This situation is realized by the individual or group search of food by fish. The area in which artificial fish live is fundamentally the solution space and area of other artificial fish. Degree of prey density in the water zone is a function of objective algorithm. Finally, artificial fish reach a location where the degree of density and concentration of prey is more (global optimization). As shown in Fig. 1, artificial fish understands external concepts through vision.

Fig. 1
figure 1

The concept of vision in artificial fish

The current status of artificial fish is denoted by the vector of X position. Visual refers the visibility of artificial fish. Xv is a position within the visibility field where the artificial fish wants to go there. If the status of Xv is better than the current status in terms of prey density, it moves one hop to the front in such a direction that the status of the artificial fish changes from X to Xnext. However, if the current status is better than X, the fish keeps patrolling within its visibility field. Step is equal to the maximum length of hop move. The other artificial fish that are within the visibility field of another artificial fish are its neighbors. As a result, there is no need for complicated search or countless modes which is, consequently, appropriate for finding global optimum. If X = (x1, x2, x3, …., xn) and \(x = \left( {x_{1}^{v} ,x_{2}^{v} ,x_{3}^{v} , \ldots x_{n}^{v} } \right),{ }\) this process can be illustrated through Eqs. (1) and (2):

$$x_{i}^{v} = x_{i} + visual \cdot rand (),\quad i \in \left( {0,n} \right]$$
(1)
$$x_{next} = x + \frac{{x_{v} - x}}{{x_{v} - x}} \cdot step \cdot rand ()$$
(2)

where rand refers to random numbers between 0 and 1; step denotes the length of hop and xi stands for optimization variable and n refers to the number of variables.

Now, the proposed method which is aimed at clustering sensor nodes by using FSA is described below. In the proposed method, each node is modeled as an artificial fish and sink node is regarded as the main food resource or the global optimum. Artificial fish model includes two parts: variables and functions. Variables include X, Y, Z (current position of artificial fish or sensor node), step refers to the length of movement step which was assumed to be 100 in the proposed method); \(\updelta\) refers to crowdedness factor (0 > \(\updelta\)< 1, this factor determines the number of a sensor node’s neighbors from which it has received the announcement message of CH). In the proposed method, the value of \(\updelta\) factor was 0.9. Also, functions include: follow (AF_Follow), movement (AF_Move), group movement (Af_Swarm) and prey search behavior (AF_Prey). Fish stay in locations where there are more available foods. Hence, fish behavior can be used based on this feature for finding global optimum in AFSA.

The proposed method is FSA-based clustering which uses the parameters of remaining energy, within-cluster distance and distance to sink for selecting CH. This algorithm consists of three phases: clustering phase, routing phase and route maintenance phase. In the clustering phase, sensor nodes are classified into clusters. Before each node starts the competition for becoming CH, it broadcasts a hello message within its radio range. The nodes receiving this hello message produce a response message which includes the physical position and their IDs; they send it towards the node which has transmitted the hello message. It should be stated that nodes are equipped with GPS and they can detect their own physical positions. Message transmitting node receives the response message and extracts nodes’ IDs from the response messages. Then, it registers IDs as the neighboring nodes’ IDs in its neighborhood table. In this way, each sensor node’s neighbors are identified. Furthermore, each sensor node independently adjusts its scheduler. If T(i) is the scheduler of sensor node i, its value will be measured according to Eq. (3).

$$T\left( i \right) = \frac{{E_{p} \left( i \right) - E_{r} \left( i \right)}}{{E_{p} \left( i \right)}} \times T_{CH} \times D_{iS}$$
(3)

In this formula, TCH denotes maximum allocated time for selecting CH. Ep(i) and Er(i) stand for maximum initial energy and the remaining energy of sensor node i; Dis refers to the distance of fish or the ith node from the sink; the value of this parameter is equal to the Euclidean distance of each node such as i from the sink node s which is measured according to formula (4):

$$r_{is} = \sqrt {\left( {x_{i} - x_{s} } \right)^{2} + \left( {y_{i} - y_{s} } \right)^{2} + \left( {y_{i} - y_{s} } \right)^{{2{ }}} }$$
(4)

where (\(y_{i} ,x_{i} ,z_{i}\)) refer to the position and location of the ith fish and \(\left( {y_{s} ,x_{s} ,z_{s} } \right)\) refer to the position of sink or the food source of the fish. When the scheduler is over, node i is selected as the temporary CH which broadcasts an advertisement message for becoming CH within its own transmission range. In this way, it informs its neighbors about the fact that it is located in a better position. By sending this message, that node announces its neighbors that it is close to the food source or the sink; as a result, the remaining neighboring nodes or neighboring fish should follow it and become members of that node’s cluster by sending a connection message. The advertisement message for becoming CH includes the respective sensor node’s ID, remaining energy Er (i) and temporary CH’s position. Now, in this stage, AF-follow function is executed so that in case the neighboring node j receives this message (CH advertisement), it will quit the candidacy for becoming CH and will cancel its scheduler. Hence, it will remain as a normal until the next round. Moreover, node j saves the list of sensor nodes from which it has received the message for becoming CH as the set of neighboring CHs (\(N_{Ch} \left( j \right)\)). Sensor node j specifies and announces its membership within the related cluster by using a follow function. That is, sensor node j would like to join one of the available CHs in the list \(N_{Ch} \left( j \right)\). Sensor node j computes the degree of fitness of the available CHs within the list \(N_{Ch} \left( j \right)\) by means of formula (5).

$$Y_{K,j} = E_{r} L_{Ch} \left( j \right) + \left( {1/\left( {r_{k,j}^{2} } \right)} \right)$$
(5)
$$E_{r} L_{Ch} \left( j \right) = \frac{{\mathop \sum \nolimits_{k = 1}^{n} E_{r} \left( {v_{k} } \right)}}{n}$$
(6)

where Yk,j indicates the degree of fitness of cluster-head K from the view of sensor node j. \({E}_{r}{L}_{Ch}\left(j\right)\) refers to the average remaining energy of the available CHs in the list of the jth sensor node’s neighboring CHs (\({N}_{Ch}(j)\)) which is computed via formula (6). rk,j stands for the jth node’s distance from the available Kth CH in the list \(N_{Ch} \left( j \right).\)

According to formula (6), node j selects a sensor node from among the available CH nodes in the list Nch(j) which has a higher degree of fitness. Also, the number of cluster member nodes and the selected CH should not be large. That is, the surroundings of the selected CH should not be crowded. In other words, the condition \(\frac{{n_{f} }}{{\text{n}}} < \delta\) should be met; \(n_{f}\) refers to the number of available CH nodes in the list \(N_{Ch} \left( j \right)\) of the sensor node j. In the simulation, n denotes the total number of candidate nodes for becoming CH. \(\delta\) stands for the crowdedness factor; here, it was considered to be 0.9. Next, node j sends a connection message to the neighboring CH with the highest fitness. AF-Follow move occurs when there is a node with a better fitness in the list Nch(j) with the position (\(y_{j} ,x_{j} ,z_{j}\)). Otherwise, node j moves towards the node with the highest energy level in the CH list of its neighbor. This move is called AF_Swarm. In the algorithm, AF_Follow and AF_Swarm are done only for the nodes which have neighbors. One of the features of fish which live collectively is that they try to move together with the other members of the group. This feature guarantees the life of the fish group and prevents them from danger. The function should be executed according to AF_Swarm. Let’s assume that \(\left( {y_{j} ,x_{j} ,z_{j} } \right)\) is the current position of the sensor node j and \(\left( {y_{c} ,x_{c} ,z_{c} } \right)\) is the position of sensor node c with the highest energy level in the list NCH(j). nf denotes the number of nodes in the list of neighbouring CH (dij < Visual); n indicates the total number CH nodes. The condition Yc > Yj and \(n_{f} /n < \delta\) indicates the existence of more food in the cluster-head C with high energy (it has higher fitness function); also, it means that congestion condition is not large. The next step is the move towards the cluster-head c. Node j should send a connection message towards the cluster-head c which has the highest energy level.

Crowdedness or congestion factor reduces the probability for the occurrence of excessive congestion. In case none of the above-mentioned conditions occurs or the jth node does not have any neighbours or the available nodes in the list NCH(j) do not satisfy connection conditions, AF_Prey will be executed for the jth node. The tendency and inclination towards prey is regarded as a biological and fundamental behavior; hence, as fish see or sense a prey source in the water, they determine their movement destination according to AF_prey function. Here, the position of the sink is regarded as the main source of the prey (the value of objective function). The larger the value of the Visual, the easier the AF or sensor node can find the prey source and converge with it. Indeed, if the sensor node j cannot get connected to a CH and none of the available CHs in the list NCh(j) cannot get connected to a CH by executing AF_Follow and AF_Swarm functions, the position of the CH will be randomly selected. Also, if node j randomly sends a connection message to one of the available nodes in the list NCh(j), AF can, indeed, randomly swim; in this case, the probability of being trapped in local optimum is reduced. Noticing the fish position synchronization relations indicate that the distance of the mobile fish’s location from the destination location plays a significant role in this synchronization. The smaller the distance of the two positions, the closer the mobile fish to the destination. That is, the degree of closeness of the mobile fish has reverse relation with the location of this fish from the destination location. In other words, sensor nodes which are close to the sink can easily find the sink. In this way, clusters are formed. Then, the second phase, which is routing data to the sink, starts. In this phase, a direct virtual backbone which is rooted in the sink is created for all the CHs. At the begging, the sink node sends a route request message to all the CHs which are within its radio range. This message includes information such as node ID, node L (level) and its position. It was assumed that the level of the sink node is zero. When the cluster-head u receives a message, it increases its level by one unit and selects the sink node as its father. In other words, the level of all the CHs, located within 3R range, will be one. In this way, the cluster-head u will send a route request message to all the cluster-heads which are located within its range. The message includes information such as ID, L(u), Er (u) and location information p(u). If a CH receives v messages and if its level is smaller than or equal to the level of node u, it will ignore that message; otherwise, it will increase the level to the one bigger than u and will consider it as one of the parents. In this way, these stages will continue and all the CHs will broadcast route request message for completing the process of creating direct virtual backbone. In the direct virtual backbone, a CH might have several parents. Hence, it will have several routes to the sink. In this phase, during the formation of the routing tree, each node which is selected as the cluster-head should send the parent set as well as the scheduler pack; the parent set indicates the respective node’s parent cluster-heads. As a result of sending the parent set, nodes are informed of the parent nodes of the cluster-head. That is, they learn the IDs of the parent cluster-heads and the location of the parent nodes. In this way, in case any problems occur for the current CH, they can quickly restore the tree so that node can keep their operations. With respect to the direct virtual backbone presented in phase two for facilitating data routing, the problem regarding the routing tree is that the issue of error creation in CHs should be meticulously noticed because error creation can effectively impact on network lifetime. As a result, the overall network performance is reduced. Nonetheless, the failure of a CH is considered as a limitation in accessing sensor nodes which are members of that cluster which prevents data collection and data dissemination. Thus, it should be maintained that the proposed method should have the capability of error tolerance in CHs. Given the routing phase in the proposed method, each CH with the level of n-1 should have several parents in the routing tree. In return, such a CH itself is the parent of a higher-level CH. On the other hand, it is the CH of a cluster with n sensor nodes. When a CH makes an error due to battery depletion or a hardware-related reason, its communication with the cluster members is cut off. As a result, it can no longer operate as the parent of the higher-level nodes. Furthermore, it fails to communicate with its parents. Consequently, in phase three, a solution is presented for enhancing CHs’ error-tolerance capability. When a CH isolates from direct virtual backbone, it may get to create a new direct virtual backbone on the sink part; in such a case, by changing all the routes, the CH consumes huge energy for constructing the new direct virtual backbone. Consequently, in phase three, the problem of error occurrence in CHs is sorted out for avoiding this condition. If a CH makes an error within a cluster, the member nodes of that cluster can easily notice the CH’s error because they receive no ACK in return for the data packets they send to it. At this time, phase three begins and member nodes of the CH which has made an error broadcast a help message within their own radio range; this message includes information such as battery level, node ID, previous CH’s ID and distance from the base station or sink. In case a node is a member of another CH and it receives a help message related to a different CH, it will destroy it; otherwise, it will begin the competition with the other nodes for becoming CH.

Upon receiving help message, each sensor node adjusts its scheduler according to Eq. 3. When the scheduler is finished, the sensor node with the highest remaining energy and the shortest distance from the sink selects itself as the CH and broadcasts a declaration message within its communication range for announcing its selection as the CH; this message includes node’s ID, remaining energy, node’s position and a set of parents which indicates the parents of the previous CHs. In fact, the selected CH considers the parents of the previous CH as its own parents. Hence, like the previous CH, the new CH sends its input data packets to the CHs which are its parents. Also, a node such as j, which has received CH selection announcement message, stops its scheduler and functions as a member node of that CH in the next communication round. Thus, in case CH node makes an error, it restores the cluster by selecting one of the cluster members as the CH. That is, by selecting a new CH, it establishes the communication of the cluster and cluster members with the parent nodes of the previous CH. In this way, the communication of the CH and cluster with the sink is established through parent nodes. When an n − 1 level CH operates as the parent of an n-level CH and it makes an error, n-level CH can easily detect it. That is, as it sends each data packet, it does not receive any ACK from it. Hence, for identifying the new n − 1 level CH as its own parent, this new n − 1 level CH broadcasts its announcement message within its radio range. With respect to the ID of the previous available CH in this message, CHs can compare the ID with the IDs which they have in the list of their parents; if the ID is available in the list of their parents, they will eliminate the specification of the previous CH from the list of their parents. Hence, they will replace it with the new CH. Then, they compute the average remaining energy of the available CHs in the list of parents. Next, they establish the new parent which includes CHs with more remaining energy than the average remaining energy level or equal to that level. The members of this set operate as the parent nodes of those CHs. The new CH may or may not be a member of this new parent set. Hence, using the proposed method, in this phase, in case a problem occurs for the CH, the available routing tree is restored which prevents the creation of a new routing tree. Figure 2 shows the pseudo-code of the fish swarm algorithm.

Fig. 2
figure 2figure 2

Pseudo-code of the artificial fish swarm optimization algorithm

4 Simulation of the Proposed Method

4.1 Simulation Environment

In this paper, we used OPNET 11.5 for simulating the proposed method and comparing it with ERA protocol [18]. Simulation parameters are given in Table 1. In the proposed method, a network topology with 50 nodes was taken into consideration which is depicted in Fig. 3. Two scenarios were considered; in the first scenario, sensor noes are randomly distributed in the environment based on protocol ERA [7]; in the second scenario, sensor nodes were randomly distributed in the environment which were clustered by AFSRP (artificial fish swarm routing protocol). An identical connectivity was assumed for both scenarios. Simulation results based on the above-mentioned scenarios are discussed below. Figure 4 shows node editor for the proposed scenarios in the form of hardware which constitutes the components of a sensor node.

Fig. 3
figure 3

Network topology with 50 sensor nodes

Fig. 4
figure 4

Node editor for the simulated protocol

4.2 Efficiency Criteria in the Proposed Method

The following criteria were used for investigating the efficiency of the proposed method.

  • Power consumption: it refers to the total energy used by the nodes within the network for establishing communication which includes transmission and transmission and wait.

  • End-to-end delay: it denotes the time length during which a data packet is transmitted from the sender to the receiver. For measuring average end-to-end delay, end-to-end delays of all the packets which are received by receivers are computed and their mean value is calculated.

  • Media access delay: it refers to the time length between data packet reception by MAC layer up to the time it is completely placed on wireless media. The justification for investigating media access delay is that the majority of multi-media access applications have delay limitation and they no longer have any applications after this time.

  • Throughput rate: it indicates signal to noise ratio which is regarded as a criterion for illustrating useful signal versus disturbing signal or noise. The value obtained for this criterion reveals the strength degree of the noise imposed to a signal versus the strength of the signal itself. The higher this index, it will be more desirable which indicates more useful signal.

  • Success probability of data transmission to a sink node: it indicates data rates which have been successfully delivered to the sink.

4.3 Simulation Results

Average power consumption of the network for the scenarios of the proposed algorithm and ERA protocol are shown in Fig. 5. Both algorithms have significantly high power consumption during the first 5 s of their executions which is attributed to a high number of data packet exchange among network nodes for selecting CHs and the communication route between CHs and the base station. This issue results in the major energy depletion of nodes in the initial formation of clusters and routes. As depicted in Fig. 5, at the next execution times, power is consumed steadily and uniformly because clusters and communication routes have already been established and algorithms have become stable. As expected, ERA protocol had the highest power consumption because network nodes select CHs only based on the remaining energy level. However, thanks to using clustering by artificial fish swarm algorithm in the proposed method, a node is selected for data transmission which has higher fitness. That is, it has more energy and less distance from the sink. On the other hand, since member nodes join CH with regard to their distances, there is no need for high power consumption for sending data from a member node to the CH. Furthermore, in case an error occurs to a CH, according to phase three of the proposed algorithm, an alternative node is quickly found which replaces the erroneous CH; hence, there is no need for re-formation of routing tree. This condition attributes to the reduction of power consumption among sensor nodes; that is, when a problem occurs, all the sensor nodes do not have to construct a new routing tree. Only those nodes which depend on the respective CH have to carry out processing for selecting a new CH. In this way, the degree of optimization of the proposed method is about 40%.

Fig. 5
figure 5

Average network power consumption

The comparison of the average end-to-end delay for the two scenarios is depicted in Fig. 6. The vertical axis denotes end-to-end delay and the horizontal axis stands for simulation time. Average delay indicates the required time for transmitting a data packet from the source node to the sink. According to the conducted related works on this issue, for measuring packet delay on the route, we should compute the total delays of all data packets in each link and their stops. The proposed algorithm for routing underscores and considers the distance of nodes from the sink. That is, for selecting the next node in the route, each node considers the distance of the neighbouring node from the sink node. Hence, thanks to taking the distance index into account, it uses the short route. It was observed that delay in the ERA protocol scenario increases because some of network nodes may send data to the sink through a longer route. As shown in Fig. 6, large delay of ERA protocol is attributed to the increased distance of the nodes which send data to the sink. Given the issue that as the time goes by, the remaining energy of the nodes surrounding the sink depletes; as a result, nodes which are farther from the sink are responsible for transmitting data to the sink. In this way, as the distance increases, end-to-end delay increases. On the other hand, ERA protocol uses single-route routing protocol for transmitting data. In case the main route fails, route identification process is re-launched; consequently, it results in a delay in data transmission. However, in the proposed protocol scenario, the nodes with shorter distance from the sink are selected as CHs and cluster members join the CH according to the same distance factor. Thus, end-to-end delay decreases. Moreover, in ERA protocol, CH is selected solely based on remaining energy level but other significant criteria such as distance which plays a key role in delay creation in data transmission are not taken into consideration. The degree of optimization of the proposed method is about 82.7%.

Fig. 6
figure 6

End-to-end delay

Moreover, the comparison of the media-access delay for both scenarios is shown in Fig. 7. The vertical axis denotes media access delay and the horizontal axis refers to simulation time. Sensor nodes usually establish communications via a shared wireless communication channel. The environments in which these networks operate do not usually allow for the creation of other infrastructures. Depending on the environmental conditions in which sensor nodes operate, different wireless communication media are used. Wireless communication media is a source which should be shared among all network members. Hence, a scheme should be proposed for the procession of the sharing process in such a way that the respective parameters are met. On the one hand, the issue of sharing communication media in sensor nodes is very important because all sensor nodes cannot share and use the media simultaneously due to the existence of a vast number of sensor nodes. On the other hand, information processing and storage capacities in these networks are often limited due to the energy and capabilities of the sensors. Because of the power limitation of sensors in these networks, their energy might be depleted after operating for a while and exit the network. In this way, the utilized bandwidth is wasted. One of the major problems in designing an effective media access protocol for sharing media is resulted from the spatial distribution of communication sensors. Some information should be exchanged for achieving an agreement on which sensor should use the channel at any given moment. In a similar vein, the information exchange itself requires the utilization of channel. This relation and the multiple access recursive appearance lead to the increased complexity of the access control protocol and needs a threshold for limiting and regulating active sensor nodes. Furthermore, the topology of sensors’ space makes it impossible for each sensor to be informed of the status of the remaining sensors. Media access delay refers to the time spent by a data packet in media access layers until it is successfully sent. This delay does not necessarily depend only on network traffic. That is, it also depends on the design of the media access. In the cases in which communication needs a certain time limitation, media access protocol guarantees a specific delay range so that the intended system quality is achieved. As shown in Fig. 7, it was observed that the delay of multi-media files increases in ERA protocol scenario; that is, due to very high data production rate and the explosive feature, the probability of congestion occurrence increases in transmitting data files. It leads to the reduction of accessible bandwidth and an increase in media access delay. However, in the proposed protocol, since CHs, in clustering, are selected from among nodes with more energy level and shorter distance, end-to-end delay decreases. Also, in ERA protocol, CH is prone to make an error; nonetheless, this protocol has no plan or procedure for dealing with such conditions. On the other hand, error can impact on network lifetime and result in reduced overall performance of the network. Nevertheless, the failure of a CH is regarded as a limitation in accessing sensor nodes which are under its supervision and prevents data gathering and data dissemination. As a result, media access delay increases so that the optimization of the proposed method is about 16.8%.

Fig. 7
figure 7

Media access delay

Furthermore, comparison of the degree of success of data transmission to the sink node for the proposed protocol scenario and ERA protocol scenario are shown in Fig. 8. One of the most serious issues in WSNs is information transmission from nodes within the network to the sink node. Another critical issue is related to the selection of the best possible route for transmitting information. The best route is selected according to various factors such as power consumption, responsiveness speed, delay, data transmission precision, etc. One very simple method for doing routing is that each sensor node should directly exchange data with the base station in a single hop; it should be noted that this method is very costly because the nodes which are far from the sink may deplete their energy very quickly. Thus, network lifetime is severely affected and limited. This problem is particularly of high significance in the case of wireless sensors which are arranged and aimed at covering a large geographical area; also, it is important in the case of mobile wireless sensors which are likely to move away from the sink. For sorting out shortcomings and the drawbacks of the single-hop method, data exchange between sensors and base station is usually carried out via multi-hop data packet transmission on a small communication radius. Such a data transmission method leads to saving certain amounts of power consumption and a reduction in telecommunication interference among sensor nodes which compete with each other for accessing channel. In multi-hop WSNs, the intermediate nodes should participate in forwarding data packets between source and destination. The most fundamental task of the routing algorithm is to determine which sort of intermediate nodes should be selected for constructing a route forwarding data from source to destination. In general, routing in large scale networks is a serious problem which should be solved by considering different factors such as accuracy, stability and optimality with respect to different operational criteria. The inherent features of WSNs have been mixed with severe bandwidth and energy limitations which result in further other challenges that should be responded for satisfying users’ traffic requirements. As a result, network lifetime should be enhanced. Hence, since the proper selection of intermediate nodes in WSNs can enhance the probability of successful data transmission, their accurate selection for telecommunicating information to the sink is of high significance. Consequently, data packets are more likely to be delivered to the sink node. The ratio of the total data received in the sink node (in kilobytes) to the total data produced in the network (in kilobytes) is referred to as the probability of successful data transmission. The higher the amount of data received by the sink in relation to the amount of produced data, the higher the success rate.

Fig. 8
figure 8

The rate of successful data delivery to the sink node

As shown in Fig. 8, it is observed that the success rate of ERA protocol is lower than that of the proposed method; this result is attributed to some network nodes which are turned off due to error occurrence or their battery depletion. As a result, data transmission operation to the sink may not be completed in ERA protocol. However, in the proposed protocol, due to the selection of a highly stable route which includes nodes with high energy, the probability of successful data transmission to the sink is enhanced so that the degree of optimization in the proposed method is approximately 0.37%.

Network throughput rate is shown in Fig. 9. The horizontal axis denotes simulation time and the vertical axis indicates the number of delivered data bits at the time unit. Throughput rate is a measurable criterion of the network which indicates the degree of data provision for being transmitted to the sink. Indeed, this criterion denotes the number of input packets to the sink per millisecond. In other words, this criterion refers to the average successful message delivery in a communication channel. Throughput rate is usually measured in bit per second and, sometimes, in data packets per second or data packets at time intervals. As depicted in Fig. 9, ERA protocol scenario has lower throughput rate than the proposed protocol scenario which is attributed to the failure in completing data transmission operation due to error occurrence. Nevertheless, in the proposed protocol, when clustering operation is done, clusters are formed by selecting nodes with the highest fitness. Also, since stable and error-tolerant routes are discovered, it is guaranteed that the route is kept and maintained at least until the end of data transmission phase and nodes’ energies on the selected route will not be depleted very soon. Hence, it should be pointed out that the number of delivered data packets to the sink node is higher in the proposed method. In ERA protocol, when a CH makes an error due to battery depletion or a hardware reason, its communication with cluster members is cut off. Also, it cannot operate as the parent of the next-level nodes. On the other hand, its communication with its own parent nodes is cut off. This problem reveals that ERA protocol has not considered any specific and planned procedure for dealing with such issues. In contrast, the proposed method not only prevents the generation of a new routing tree but also allows cluster member nodes to re-generate a new cluster with a new CH in the case of such a condition. In this way, the problematic part of the route is restored and revived. This procedure allows nodes to be optimized in terms of power consumption because all network nodes do not have to be create new routes when there is problem with the CH. Hence, energy is saved in this part and nodes energies are not depleted soon. As a result, data transmission rate or the number of input packets to the sink increases. The optimization of the proposed method was about 2.85%.

Fig. 9
figure 9

Throughput rate

The comparison of the proposed protocol and ERA protocol regarding signal to noise ratio is depicted in Fig. 9. The horizontal axis denotes simulation time and the vertical axis refers to signal to noise ratio; this criterion demonstrates the degree of useful signal versus disturbing signal or noise in WSNs. Disturbing or annoying signals are unwanted and random which impact on the main signal. Signal-to-noise ratio is expressed in decibels (dB). This criterion depends on different factors such as accessible bandwidth, etc. In fact, the higher this index, the better the status which indicates the intensity of useful signal. It was observed that ERA protocol has lower signal to noise ratio than the proposed protocol. In other words, since ERA protocol is not tolerant of errors, it may use unstable routes for data transmission. Also, while transmitting information packets, the number of erroneous bits increases and the information is lost. Thus, signal to noise ratio decreases. Furthermore, it is likely that the signal of the information transmitted by ERA protocol may be lost due to congestion and disturbance. As a result, noise probability increases which leads to the reduction of the quality of transmitted data including both text and multimedia data. In the proposed protocol, thanks to error tolerance capability and the selection of appropriate routes for data transmission, less information is lost due to noise and error. Hence, signal to noise ratio increases. The degree of the optimization of the proposed method is about 9.77% (Fig. 10).

Fig. 10
figure 10

Signal to noise ratio

5 Conclusion

In this paper, power consumption was assumed as the most challenging issue in WSNs. Clustering was introduced as an appropriate method for optimizing power consumption. Here, by capitalizing on artificial fish swarm optimization algorithm, we proposed a new method for clustering. The performances of the proposed algorithm and ERA protocol were simulated via OPNET simulator and were compared with each other. Simulation results were analyzed with respect to the following parameters: sensor nodes’ power consumption, end-to-end delay, media access delay, signal to noise ratio, the probability of successful data transmission to the sink and throughput rate. The proposed method had better behavior than ERA protocol; based on the obtained results, the proposed method had 40% optimization for sensor nodes’ power consumption, 82.7% optimization of end-to-end delay, 16.8% optimization of multimedia access delay, 9.77% optimization of signal-to-noise ratio, 0.73% optimization for the probability of successful data transmission to the sink node and 2.85% optimization for throughput rate. These results are attributed to selecting more stable routes with error-tolerance capability and the selection of high-power nodes with shorter distance from the sink and high overall fitness of the network.

Table 1 Simulation parameters