1 Introduction

WSN consists of a huge number of deployed devices in an area of interest to sense various physical information from the surrounding environment. The information collected by these devices are periodically transmitted to the sink and will be processed depending on the application requirements [1,2,3,4]. The limitations of communication makes the far away nodes from the sink to send their data to the sink through multi-hop using intermediary nodes over a tree-based routing topology.

To access communication media, two main protocols are commonly used: contention-based and schedule-based. Contention-based protocols such as Carrier-Sense Multiple Access (CSMA) are inefficient and may fail if the communication media are highly utilized or when the number of sensors is large due to high probability of collisions causing re-transmissions. While, in schedule-based or contention-free medium access such as Time Division Multiple Access (TDMA), sensors have to communicate using distinct time slots to avoid collisions. TDMA offers considerable improvements for data collection as it allows sensor nodes to enter into sleep mode during inactive time, which implies: attaining low duty cycles, reducing energy consumption, eliminating conflicts, overhearing, and idle listening which are the major sources of consumption of energy in WSNs [5,6,7]. Furthermore, TDMA-based communications are robust during peak loads and can supply a demonstrable accomplishment time of collecting data, for example, in timely detection of events [8]. Also, in TDMA when nodes are not in the transmission or reception mode, they fall into sleep mode to reduce energy consumption. In TDMA, when a node is transmitting, its conflict nodes cannot transmit. The main types of conflicts are: primary conflict and secondary conflict. The principal strife happens when a sensor receives more than one destined transmissions or transmits and receives at the same time. The secondary strife occurs when the intended receiver of a specific transmission is within the range of another transmission proposed for other nodes.

TDMA scheduling protocols are classified as follows: pure MAC layer, hybrid and Cross-layer. In TDMA based MAC, time is split into a set of frames and every frame is split into fixed time slots and then every sensor node is designated to particular time slot in which transmission occurs. Hybrid algorithms integrate TDMA with other protocols, e.g., CSMA, etc. However, Cross-Layer algorithms utilize other layers in order to gain preferable schedules [9].

Minimizing latency in collecting data is essential for critical applications that take definite actions based on deadlines. In spite of the fact that minimizing the schedule length may minimize the latency under certain conditions, most of the existing protocls do not theorize the average latency experienced at each hop by individual packets [8]. Furthermore, some algorithms minimize the length of the schedule by maximizing the re-utilization of time slots, which does not necessarily result in schedules with minimal delay in some topologies. For example, a linear topology may permit higher spatial reuse, but due to larger number of hops from the sources to the sink, it may incur high latency. Therefore, minimizing the data collection latency may enforce more constraints along with minimizing the schedule length.

In the proposed work, WSN is composed of a finite set of sensor nodes and a sink. The sensors send their sensed data to the sink via a multi-hop path over the routing tree. Our contribution can be summarized as follows: Using the cross-layer aspect, we have used routing information tree based WSN. A new GA based approach is proposed that utilizes information from routing tree protocol to define communication time slots and reduces communication latency. Latency is expressed as the fitness function of GA and a two-dimensional chromosome matrix is employed to define TDMA schedule. Evaluation results demonstrate that the performance of the proposed approach exceeds several existing baseline tree based cross-layer approaches. Our main contribution can be summarized in the following points:

  1. 1.

    A new Genetic algorithm (GA) based ordering method is proposed where two-dimensional encoding representations are designed to allocate slots and minimizes the total network latency by using average time latency as the fitness function.

  2. 2.

    Extensive simulation results to prove the performance of the proposed technique are given. The comparison results with substantial approaches such as Rand-LO, Depth-LO, DepthRe-LO, IDegRe-LO and IDeg-LO using different routing trees and different locations of the sink show the following differences between our proposed ETDMA-GA and the existing algorithms.

    • ETDMA-GA has minimum average latency, minimum average schedule length and minimum normalized latency compared with the existing five substantial approaches in cases of DFSA tree, Min hop tree, even for three different sink locations

    • The duty cycle of ETDMA-GA has diminutive increase compared with the existing algorithms, while ETDMA-GA has remarkable gain in the average latency reduction.

The rest of this paper is tabulated as follows: the related research of the proposed approach is described in Section 2. In Section 3, the description of the proposed problem is given. In Section 4, we present the details of our proposed approach. The simulation results including the comparison with the existing baseline approaches are presented in Section 5. The work is concluded in Section 6,

2 Related research

WSN protocol stack typically contains the following layers: application, transport, network, data link, and physical, with each layer having its own responsibility. For example, the network layer has the responsibility to route the data supplied by the transport layer, and the transport layer assists in preserving the data flow. Data link layer responsibilities are multiplexing of data streams, data frame detection, medium access control (MAC) and error control [10]. The main function of the data link layer is MAC, where the main objective is to equitably and efficiently share the shared communication resources among all sensor nodes in order to accomplish enhanced performance of the network in terms of energy consumption, network throughput, and delivery latency.

The layered model works on the principle of separation which is neither effective nor guarantees optimal performance for WSNs as other features must also be taken into account, such as limited resources, e.g., energy, memory, radio interference or mobility and topology changes. These characteristics generate additional constraints while designing protocols in the layered model for an adaptive WSN. Therefore, cross-layer protocols are preferable as the dependencies between protocols from different layers can be exploited to overcome the limitations of each protocol and achieve an overall gain in performance [11].

Cross-layer protocols that allow flexibility between MAC sublayer and Network layer can be divided into three classes [12]: (a) Joining the functionality of MAC protocol and routing protocol (Joint MAC & Routing) (b) Routing protocols that use MAC protocol information (MAC-AWARE routing), and (c) MAC protocols that use routing protocol information (Routing-AWARE MAC). The block diagram of cross-layer approaches, along with the location of our proposed approach among these categories is given in Fig. 1.

Fig. 1
figure 1

Cross-Layer approaches between data link and network layers

In Joint MAC and Routing, the information and functionality of the Network and Data Link layers are grouped together and combined into a single layer. Address-Light Integrated MAC and Routing Protocol (AIMRP) [13], RSSI-Based Forwarding (RBF) [14], State-free Implicit Forwarding (SIf) [15] and IDeg-Routing & MAC [12] are examples of JOINT MAC & ROUTING. AIMRP, RBF and SIf are very similar and use the same principle by arranging the sensor nodes around the sink. The routing of data to the sink is also done by the same way, even if the names given to packages and messages are different. On the other hand, IDeg-Routing & MAC [12] is an approach that combines a contention-free MAC protocol with routing. IDeg-Routing & MAC is based on BFS traversal of the graph network. The contention-free schedule for the communications between sensor nodes and the geographic routing tree is obtained from IDeg-Routing & MAC.

In the MAC-AWARE ROUTING, the MAC protocol sends information time to the routing protocol and then the routing protocol finds the next hop for each sensor node such as ORW [16] (Opportunistic Routing in WSNs) and MAR-WSN (MAC-aware routing in WSNs) [17]. In the ROUTING-AWARE MAC category, the data link layer and more particularly the protocol MAC waits for routing protocol information to establish an order of communications for the sensor nodes. In this paper, we are concerned with the ROUTING-AWARE MAC protocol in a contention-free environment.

As with conventional MAC protocols, MAC cross-layer approaches can have two forms: contention-based approaches and contention-free approaches. MAC-CROSS [18], RMAC [19], CL-MAC [20] and AreaCast [21] are examples of contention–based approaches. While CoLaNet [22], Rand-LO, Depth-LO, DepthRe-LO [23], IDeg-LO, and IDegRe-LO [24] are examples of contention-free approaches.

The main objective of MAC-CROSS [18] is to minimize the consumption of energy by decreasing the number of sensor nodes that need to remain awake to participate in the data transmission, where control packets: Request To Send (RTS) and Clear To Send (CTS) are slightly modified by adding a new field to each packet. RMAC (Routing enhanced MAC protocol) [19] is also a cross-layer MAC protocol with contention. It reduces end-to-end communication latency using a single control packet called PION that plays the role of RTS and CTS at the same time. Cross-Layer MAC protocol (CL-MAC) proposed in [20] efficiently manages multi-stream traffic and reduces communication latency. The communication in CL-MAC is performed using Flow Setup Packet (FSP) package which contains the transmitter address, the final destination address and the addresses of next hops. FSP serves as RTS message for the receiver node and at the same time as CTS message for the transmitter node. It also has the particularity to address several recipients at the same time. In [21], AreaCast is presented to improve the robustness of routing protocols and the rate of delivery of packages, while ensuring less energy consumption.

Unlike MAC-CROSS [18], RMAC [19], CL-MAC [20] and AreaCast [21] almost operate by the same way (based on RTS/CTS message exchange). CoLaNet [22], is a centralized contention-free approach that aims to save energy from sensors by building a routing tree called MinDegree; then, it uses a coloring algorithm on this tree to establish a TDMA for each sensor node. CoLaNet is a TDMA without contention and has two limitations: the sensor node with the largest number of neighbors in MinDegree routing tree can have any position in the tree and all neighbors of an already colored knot do not reflect the direction of communications. Moreover, CoLaNet is not oriented to optimize the communication latency.

Based on cross-layer decisions, communication latency is reduced [23] by the three proposed different slot allocation methods: Rand-LO, Depth-LO and DepthRe-LO. Rand-LO randomly schedules the leaves of the routing tree, then it schedules the others while ascending the tree. Depth-LO improves the Rand-LO by giving privilege to the faraway leaves from the sink to be scheduled earlier. In DepthRe-LO, scheduling priority is given to the sensors on the long paths in the routing tree.

In [24], the authors proposed two TDMA scheduling techniques called IDeg-LO and IDegRe-LO which use routing tree information and interference degree of each sensor. In IDeg-LO, according to interference degree, the leaf nodes and then internal nodes are scheduled in descending order. Each sensor is scheduled as close as to its children slots. In IDegRe-LO, based on the interference degree, the scheduled leaf is removed from the routing tree and the process is continued with other sensor nodes, which gives a chance to internal sensor nodes with greater interference degree to be scheduled earlier.

As in [24] and [23], our target is to determine the efficient and best design for TDMA schedule, correlated with information from routing protocol, to allocate a slot for every sensor node. However, the proposed ETDMA-GA is based on GA to efficiently schedule all sensor nodes and reduce communication latency for tree-based WSNs. ETDMA-GA uses a heuristic search, that randomly enumerates some possible solutions and generates other solutions which increases the search space for finding the best schedule in terms of reduced latency better than Rand-LO, Depth-LO, DepthRe-LO, IDeg-LO, and IDegRe-LO algorithms which use the traditional blind search methods to generate only one solution and improve it to get the final solution, i.e., the generated solution is always based on the starting point whether the start point is good or bad. However, ETDMA-GA can start from many points and evaluate every solution to select the best candidates. ETDMA-GA repeats these steps until it finds the best solution.

Other approaches are based on metaheuristics techniques such as [25,26,27,28,29,30,31]. In [26], a hybrid algorithm called HPSO is proposed that combines Particle Swarm Optimization (PSO) with simulated annealing (SA). HPSO finds the global optimal slot allocation by using the benefit of SA and PSO. A multi-objective optimization framework for TDMA scheduling is proposed in [27], where PSO is embedded with GA and it is used to enhance the searching ability. The PSO part avoids empty slots during scheduling, while the GA part ensures a powerful search ability to determine the optimal slot allocation. PSO-based scheduling algorithm called PSOSA which benefits from the search capability of PSO is proposed in [28]. In [25] a multi-objective immune algorithm is introduced for finding an optimal solution to TDMA scheduling problems. A hybrid algorithm is utilized in [29] by comparing both the evolutionary algorithm (EA) and PSO. In [30], the authors proposed two scheduling algorithms: level based and node-based. In node-based, the sensor nodes of the color corresponding to each slot with at least one packet are selected first and more sensor nodes are included afterwards. However, in level-based scheduling, the original network is first transformed to a linear network and the schedule of the original network is then obtained based on the coloring of the linear network.

GAs have been utilized to solve many problems in WSN. The most common utilization of GAs in WSN is to attain an energy-aware network under specific routing conditions as in [32, 33], improve localization accuracy as in [34] and deploy nodes to provide k-coverage and m-connectivity as in [35]. All previous works [25,26,27,28,29,30,31] are based on metaheuristics techniques and the routing information is not considered during the generation of TDMA scheduling, i.e., TDMA scheduling is generated without using any information from the routing protocol. Therefore, their schedules could be deficient in terms of latency reduction because the path is not selected by the routing protocol [23]. Moreover, algorithms such as CoLaNet do not optimize communication latency. In contention-free MAC approaches, TDMA communication latency is affected by non-correlation spatial decisions made in the routing protocols. In addition, TDMA is important because it allows for an explicit estimate of the end-to-end routing time by accurately calculating the delay of a packet sent by a node and transferred by its parent into the routing tree.

3 TDMA scheduling problem description

In our proposed approach, WSN is represented as a graph G = (V,E), where V is the set of deployed sensor nodes and E is the set of communication links between nodes. There exist an edge between two nodes i and j, if i is within the communication range of j. Let sensor node SrootV is the root such that all data traffic from every sensor node iV is routed through Sroot using routing path. We assume that all sensor nodes have the same communication range, i.e., the links between nodes are symmetric. Moreover, each node cannot transmit and receive simultaneously and cannot hear two messages at the same time (half-duplex radio transceiver). Figure 2 shows an example of a WSN graph and its routing tree rooted at node 1.

Fig. 2
figure 2

Example: A WSN graph with its minimum hop routing tree

In TDMA scheduling, the time frame is divided into equal intervals called time slots. Each time slot is intended to receive or transmit a single packet from/to a neighboring sensor node. The main objective of TDMA scheduling is to assign different transmission and reception time slots to sensor nodes without collisions while using minimum energy consumption and minimum total number of slots for transmission and reception. According to the work in [36], TDMA scheduling constraints can be summarized as follows:

  1. 1.

    Transmission and reception of a sensor node at the same time slot are not allowed.

  2. 2.

    Simultaneous reception between several 1-hop neighbors are prohibited.

Moreover, the immediate neighborhood of a sensor node s and its 2-hop neighborhood sensor nodes should guarantee that no interference occurs during the transmissions by a sensor node.

A WSN of N sensor nodes can be represented by a symmetric connectivity matrix CN×N, which is defined as C[i][j] = 1, if eij = 1; else C[i][j] = 0, where eij is the minimum number of edges between sensor node i and sensor node j and ij. In addition, the conflict relationship in the network can be represented by an interference matrix IN×N, where if eij ≤ 2, I[i][j] = 1; else I[i][j] = 0, where ij. As a result, sensor nodes i and j can transmit data at the same time if eij is larger than 2. For example the corresponding connection matrix and interference matrix for the network in Fig. 2 is given below in Eqs. 1 and 2:

$$ C[10][10]= \begin{array}{llllllllll} 0 &1 &1 &0 &0 &0 &0 &0 &0 &0 \\ 1 &0 &1 &0 &1 &0 &0 &0 &1 &0 \\ 1 &1 &0 &1 &0 &1 &0 &0 &0 &0 \\ 0 &0 &1 &0 &0 &0 &0 &1 &0 &1 \\ 0 &1 &0 &0 &0 &1 &0 &0 &1 &0 \\ 0 &0 &1 &0 &1 &0 &1 &0 &0 &0 \\ 0 &0 &0 &0 &0 &1 &0 &1 &0 &0 \\ 0 &0 &0 &1 &0 &0 &1 &0 &0 &1 \\ 0 &1 &0 &0 &1 &0 &0 &0 &0 &0 \\ 0 &0 &0 &1 &0 &0 &0 &1 &0 &0 \end{array} $$
(1)
$$ I[10][10]= \begin{array}{llllllllll} 0 &1 &1 &1 &1 &1 &0 &0 &1 &0 \\ 1 &0 &1 &1 &1 &1 &0 &0 &1 &0 \\ 1 &1 &0 &1 &1 &1 &1 &1 &1 &1 \\ 1 &1 &1 &0 &0 &1 &1 &1 &0 &1 \\ 1 &1 &1 &0 &0 &1 &1 &0 &1 &0 \\ 1 &1 &1 &1 &1 &0 &1 &1 &1 &0 \\ 0 &0 &1 &1 &1 &1 &0 &1 &0 &1 \\ 0 &0 &1 &1 &0 &1 &1 &0 &0 &1 \\ 1 &1 &1 &0 &1 &1 &0 &0 &0 &0 \\ 0 &0 &1 &1 &0 &0 &1 &1 &0 &0 \end{array} $$
(2)

The TDMA scheduling problem in tree-based WSN can be formulated as follows: Sensor nodes generate data packets and they need to transfer these packets to the root node along the routing tree. The main objective is to schedule a time for each node, i.e., to allocate a slot for every sensor node without collision during transmission, minimize data delivery time and the total number of slots and maximize the network lifetime.

Optimal scheduling can be obtained by enumerating all valid schedules. But the complexity of such a solution will be exponential and hence heuristic solution within a reasonable time is desirable [24]. In this paper, GA is used as a heuristic approach to get the best schedule for sensor nodes in a WSN.

4 TDMA scheduling based on genetic algorithm

This section describes our proposed technique for scheduling the sensor nodes in a WSN. The algorithm is divided into two phases: initialization and TDMA schedule construction. In the initialization phase, the sink generates the routing tree using sensor nodes information such as Min Hop tree [37] or Depth First tree [38]. In TDMA schedule construction phase, the sink constructs the routing tree traversal, calculates the TDMA schedule and broadcasts the routes and the TDMA to all sensor nodes in the WSN. The used definitions and notations in the algorithm are provided first, and then we provide full description of each phase.

Definition 1 (Collision between nodes j and i)

The message of sensor node j collides with the message of sensor node i if the value of I[i][j] is 1, which means that sensor nodes i and j cannot transmit data at the same time. For example, in Eq. 2, I[1][2]= 1, i.e., sensor nodes 1 and 2 cannot transmit at the same time.

Definition 2 (Free slot for node i)

A slot x is said to be free for node i, if its allocation won’t create a collision with node j, i.e., I[i][j]≠ 1. For example, in Fig. 3, slot 2 is assigned to node 6 and it is free for node 10, because I[6][10]≠ 1 (see Eq. 2).

Definition 3 (Traversal List (TL))

TL list contains the traversal order of the sensor nodes in the routing tree. For example, TL1= 7, 6, 10, 8, 4, 3, 9, 5, 2, 1 is the traversal for the tree in Fig. 2.

Definition 4 (Transmit/Receive slot)

Schedule Slot[i][j] = k means that slot i is allocated for node j and it can be used for transmitting if j = k, for receiving if jk, and otherwise if Slot[i][j] = 0, i.e., k = 0, node j cannot communicate in this slot. For example, in Fig. 3, node 5 can transmit using slot 3 and nodes 2 and 6 can receive using slot 3.

Fig. 3
figure 3

TDMA scheduling example for the WSN in Fig. 2

In the next section, the description of each phase of the proposed algorithm is given.

4.1 Initialization phase

In the initialization phase, using the information of sensor nodes, the sink generates the routing tree such as Min Hop tree [37] or Depth First tree [38]. Then, the sink constructs the traversal of the routing tree and calculates the TDMA schedule and broadcasts the routes and the TDMA in the WSN.

4.2 TDMA schedule construction phase

Using GA, a new scheduling algorithm called ETDMA-GA is proposed. ETDMA-GA finds the best routing tree traversal ordering and the corresponding TDMA schedule. The flow chart of GA-Schedule process is shown in Fig. 4, where the population of candidate solutions to an optimization problem is evolved towards better solution. Each candidate solution is based on a set of properties that can be mutated and altered; traditionally, solutions are represented in binary as strings of 0 s and 1 s. But other encodings are also possible.

Fig. 4
figure 4

Flowchart of GA

GA is an iterative process and the population in each iteration is called a generation. It starts from randomly generated individuals as initial population and in every generation, the fitness will be estimated for each individual. Fitness is usually the value of the objective function when the problem is being optimized. Fit individuals will be selected from the ongoing population, and each individual’s genome is modified to create a new generation. The new generation of candidate solutions is used in the next iteration. The algorithm terminates when either a maximum number of generations has been generated or a satisfactory fitness level has been reached. Modeling GA needs Genetic representation of the solution and Fitness function to evaluate the generated solution. In the next subsections, the adaptation of GA stages to schedule slots for sensor nodes are presented.

4.2.1 Representation of TDMA slots using GA

In a given GA, integer representation is used to encode the chromosome. Each gene in the chromosome is mapped into a time slot vector and the gene’s value indicates a single slot number of sensor nodes that are included to form a TDMA schedule. Each chromosome can be represented by a two-dimensional matrix with R rows where R is the number of slots. The number of slots is computed as the maximum interference degree (IDegree) in the network, where \(IDegree = \arg ~ \max \limits _{1\leq i \leq n } ({\sum }_{j=1}^{n} I[i][j])\) and W columns (the number of sensor nodes).

4.2.2 Initial population

The first step in the GA process is the generation of an initial population. The initial population will be randomly generated as a predefined number of chromosomes in the population. Each chromosome is generated by executing the following slot allocation algorithm (see Algorithm 1):

  1. 1.

    Generate random routing tree traversal list (TL) ordering.

  2. 2.

    For the first node j in TL, allocate the first slot in the scheduling to j (Slots[i][j] = j, i = 1).

  3. 3.

    For each node k that has connection with j, i.e., C[j][k] = 1, allocate the current slot to k, i.e., Slots[1][k] = j as a receiving slot.

  4. 4.

    For each next node l in TL do the following:

    • Starting from the first slot of the scheduling, search for a free slot (find the slot that does not have a collision node with l).

    • If no free slot is found, then allocate a new slot for l at the end of the scheduling (Slots[i + 1][l] = l).

    • For each node k that has connection with l, i.e., C[l][k] = 1, allocate the current slot for k, i.e., Slots[i + 1][k] = l as a receiving slot for k.

  5. 5.

    Repeat Step 4 till all nodes in TL are scheduled.

Note that the generated scheduling matrix Slots[m][n] with m slots and n sensor nodes are considered as the chromosome and if m is less than the chromosome length, zeros are added to the end of the chromosome matrix (padding slot).

figure d

For clarification, consider a randomly generated TL lists TL1={7, 6, 10, 8, 4, 3, 9, 5, 2, 1} and TL2={10, 9, 8, 7, 5, 2, 4, 6, 3, 1}, respectively for the networks in Fig. 2.

Considering TL1, the algorithm starts by generating a new transmitting slot for node 7, i.e., Slots[1][7] = 7. Then, we find the list of nodes that are in connection with node 7 from matrix C in Eq. 1 which is Clist = 8,6 (row 7, the column that has 1 value). Assign the current slot as a receiving slot for nodes 8 and 6 for node 7, i.e., Slots[1][6] = 7 and Slots[1][8] = 7. After the first sensor node in TL1 is allocated in the schedule, the next node (node 6) in TL1 is allocated in the schedule as follows: search Slots matrix for free slot for node 6. Slot 1 in the Slots matrix is transmitting slot for sensor node 7 and since sensor node 7 is a collision node with sensor node 6; we cannot allocate slot 1 for node 6 (since from I matrix in Eq. 2, I[6][7] = 1). Therefore, the new slot will be allocated for node 6 (Slot 2), i.e., Slots[2][6] = 6. As before, the list of nodes that have connection with node 6 will be Clist = 3,5,7 and so Slot 2 will be allocated as receiving slot for nodes 3, 5, and 7. The same processes are repeated for nodes 10, 8, 4, 3, 9, 5, 2 and 1. The generated slots matrix is assigned to chromosome and padding slots are added to the chromosome matrix if the generated matrix length is less than the chromosome length. Figure 5a shows the chromosome obtained for TL1 and Fig. 5b shows the chromosome obtained for TL2. Note that slots 8 and 9 are padding slots (padding slots are removed before latency calculations).

Fig. 5
figure 5

Generated chromosomes: Two different TDMA schedules for the WSN example in Fig. 2a for TL1b for TL2

4.2.3 Selection

The chromosomes with good fitness rates have higher opportunity to be chosen in the next population. The selection process decides which chromosomes of the current population will be transferred to the next population without change. To differentiate proper individuals, the selection method is adapted based on the principle of elitism where the best chromosomes (a few) in the current population are copied as they will be included in the next population, i.e., the individual with the highest fitness succeeds and will be added in the next population. Such individuals can otherwise be lost if they are not chosen to reproduce; or the crossover or mutation may destroy them. This elitist strategy of selection remarkably enhances the performance of the GA [39].

4.2.4 Crossover

Crossover is a process to generate the next population from the previous one. This process takes more than one parent from the current population to create a new child for the next population. For the two-dimensional representation, the crossover operation must be modified [40]. The crossover operation could be horizontal or vertical. In this work, the selection method is adapted based on the principle of Tournament [41], where k is the number of individuals randomly chosen from the population to form a group, then the best individual from this group is selected for further processing. The selection process from the population will be repeated until k groups are obtained and the best individual will be selected from each group. Finally, the individual with the highest fitness succeeds and will be added in the next generation.

After parents selection, to generate the two children chromosomes gchild1 and gchild2 from the selected two parents gparent1 and gparent2; the crossover is performed horizontally over the rows of the parent chromosomes by generating a random integer r in range [1,R] where, R is the chromosome length. Then the following steps are executed:

  • If row ir (1 ≤ iR) then copy from gene 1 to gene i, i.e., from gparent1 to gchild1 and from gparent2 to gchild2

  • Otherwise, if row i > r (1 ≤ iR), then copy from gene i to gene R, i.e., from gparent2 to gchild1 and from gparent1 to gchild2

Figure 6 shows the generated children Child1, Child2 after crossover operation using the two parent chromosomes Parent1 and Parent2.

Fig. 6
figure 6

Crossover operations Example

4.2.5 Mutation

Mutation is used to preserve the genetic diversity of the population from inter-generational chromosomes [40]. A common mutation operator for permutation represents interchanges in the contents of two randomly selected genes, i.e., one or more parts of a chromosome are changed [39]. In mutation, the important parameter is the mutation probability which determines the frequency of mutation of the parts of the chromosome. If there is no mutation, the offsprings are generated immediately after crossover or directly copied without any changes. The proposed mutation operation is performed horizontally over the rows of the chromosome by executing the following steps:

  • Generate a random number r ∈ [0,1].

  • If r > mutation rate, then stop; otherwise,

    • Generate two random integers r1,r2 (1 ≤ r1,r2R)

    • If r1 = r2, go to the previous step,

    • Otherwise, swap the two rows r1 and r2.

Figure 7 shows the generated modified children Child1, Child2 after executing mutation operation over the two children chromosomes Child1, Child2.

Fig. 7
figure 7

Mutation operations

4.2.6 Fitness function

The probability of an individual to reproduce is computed using fitness function. The higher the fitness of an individual, the higher the opportunities to reproduce and mutate. In the proposed technique, the fitness function is used to represent the performance. The aim is to discover an arrangement for sensor nodes to be scheduled and to assign slot for each sensor node without collisions during data transmission while minimizing the data delivery time. The average latency for WSN with n sensor nodes is given by:

$$ L_{average}= \frac{{{\sum}^{n}_{i}}{L_{i}}}{n-1}, $$
(3)

Here, Li is the latency of sensor node i which is computed as the total number of waited slots of i till its data reaches the root node.

For clarification, consider the schedule in Fig. 3, the latency of sensor node 9 is 6 slots since node 9 has no waiting slots before starting transmission, plus 4 waiting slots for sensor node 2 (the parent of node 9) before transmission plus 1 slot for sensor node 2 to send. Similarly, L2 = 6, L3 = 5, L4 = 5, L5 = 6, L6 = 5, L7 = 5, L8 = 5, L9 = 6, and L10 = 5. According to Eq. 4, this schedule has average latency Laverage=(6 + 5+ 5 + 6+ 5 + 5+ 5 + 6+ 5)/9 = 5.33 The objective is to minimize average latency for WSN (minimizing Eq. 4). The fitness of each chromosome is evaluated by setting \(\frac {1}{1+ L_{average}}\) for valid chromosome and set to a very small number for invalid chromosomes.

4.3 Example scenario

Figure 8 shows a network example with 8 sensor nodes and its routing tree with node 1 as a sink [24].

Fig. 8
figure 8

A WSN graph with its routing tree [24]

In the case of Rand-LO allocation, first leaves in a random order of the routing tree will be scheduled. Then, it schedules sensor nodes in the ascending order of the routing tree. As a result, the traversal order of the routing tree in Fig. 8 will be 6-8-3-7-2-4-1-5. The resulting schedule is presented in Fig. 9a, with an average latency of 5.71. Depth-LO algorithm improves Rand-LO by assigning scheduling priority to the leaves that are far from the sink than the other leaves. Using Depth-LO, the traversal order of the routing tree in Fig. 8 will be 8-6-7-3-4-2-5-1. The Depth-LO’s schedule is presented in Fig. 9b, with average latency 5.57.

Fig. 9
figure 9

TDMA schedule for WSN in Fig. 8 using a Rand-LO b Depth-LO

In DepthRe-LO, sensor nodes on long paths in the routing tree are privileged and scheduled earlier than other sensor nodes. Using DepthRe-LO, the traversal order of the routing tree in Fig. 8 will be 8-6-7-4-3-5-2-1. The DepthRe-LO’ schedule is presented in Fig. 10a with average latency 5.43. In IDeg-LO the order of the allocation is based on the interference degree of the sensor nodes, by considering leaves to be scheduled in the descending order of the interference degree and a random node is chosen if interference degrees are equal. Using IDeg-LO, the traversal order of the routing tree in Fig. 8 will be 8-6-7-4-3-2-5-1. The IDeg-LO’s schedule is presented in Fig. 10b, with an average latency 5.57.

Fig. 10
figure 10

TDMA schedule for WSN in Fig. 8 using a DepthRe-LO b IDeg-LO

In IDegRe-LO, the order of the allocation is based on the interference degree of leaf sensor nodes, then the leaves removed from the routing tree and the allocation process is repeated over new leaves. Using IDegRe-LO, the traversal order of the routing tree in Fig. 8 will be 8-6-7-3-2-4-5-1. The resulting schedule is presented in Fig. 11a, with average latency 5.14. Using the proposed ETDMA-GA, the traversal order of the routing tree in Fig. 8 will be 8-6-3-2-7-4-5-1. The ETDMA-GA’ schedule is presented in Fig. 11b with an average latency 4.71.

Fig. 11
figure 11

TDMA schedule for WSN in Fig. 8 using a IDegRe-LO b proposed algorithm

5 Simulation results and performance analysis

Here, the simulation setup, the performance metrics and the simulation results along with discussions of the proposed ETDMA-GA and comparison of its results with the baseline algorithms such as Rand-LO, Depth-LO, DepthRe-LO, IDegRe-LO, and IDeg-LO are presented.

5.1 Simulation setup

The used WSN simulator is designed by David J. Stein and Esq [42]. The simulation consists of two stages: deploying the network and running simulations. The simulator is written in C# using Microsoft Visual Studio.NET. The simulator is modified to cope with our desired mission such as adding the identification number for each sensor node to easily control and identify the position of each sensor and its status. For deployment method, we adopt MAXDPA algorithm [43] to generate random networks. In our simulation we have the following:

  • 100 sensor nodes are deployed randomly on a 2D plane with sink placed at the corner of the deployment area.

  • The communication range rc is fixed as 30 m.

  • Different network densities are simulated from 5 to 20 with increment of 5 by changing the network area size. The network density can be roughly calculated as \(\rho =(\pi \times {r_{c}^{2}} \times n)/A\), where rc is the communication range, n is the number of nodes, and A is the deployed area [23, 24].

  • The parameters of GA are as follows: population size= 25, maximum generation= 4000, crossover probability = 0.8, and mutation probability = 0.05.

The performance of the proposed ETDMA-GA is evaluated using minimum hop routing tree [37] and Depth-First Search Aggregation tree (DFSA) [38]. Then the performances results are compared with DepthRe-LO, Depth-LO, Rand-LO [24], IDeg-LO, and IDegRe-LO [23]. For confidence, the results are averaged using 100 different randomly generated networks using MAXDPA algorithm [43]. Figure 12 shows examples of used generated graphs with different densities 5, 10, 15, and 20.

Fig. 12
figure 12

Examples: Randomly generated graphs with densities 5, 10, 15 and 20

5.2 Performance metrics

The used performance metrics as in [23, 24] to compare the performances of different approaches are as follows:

  • Average Latency is computed as the sum of the latency of each sensor averaged by the total number of sensors and it is calculated as follows:

    $$ L_{average}= \frac{{{\sum}^{n}_{i}}{L_{i}}}{n-1}, $$
    (4)

    where, Li is the latency for sensor i.

  • Schedule Length is the number of slots used in the schedule.

  • Average Normalized Latency is the average per link latency for all sensors in the network and it is computed as follows:

    $$ L_{normalized}= \frac{{{\sum}^{n}_{i}}{L_{i}}/h_{i}} {n-1} $$
    (5)

    where Li is the latency, hi is the number of hops to sink for sensor node i.

  • Duty Cycle is calculated as the ratio of the number of used slots in transmission or reception to the schedule length.

5.3 Simulation results and discussion

5.3.1 The overhead and convergence

Overhead of ETDMA-GA: :

As in CoLaNet [22], Rand-LO, Depth-LO, DepthRe-LO [23], IDeg-LO, and IDegRe-LO [24] approaches, ETDMA-GA is a centralized contention-free approach which will be executed by the sink. As we discussed above, the network is brought to a stable state without collisions by finding the best routing tree traversal order and the best TDMA schedule using suitable mapping to GA. The chromosomes are generated by executing the proposed slot allocation algorithm, which successfully finds the best scheduling matrix using the GA operations. The routing tree generated using sensor nodes information such as Min Hop tree [37] or Depth First tree [38] in the initialization phase will be used in the TDMA schedule construction phase to determine the best traversal order by the sink, which will then be used to create the best TDMA scheduling matrix. Finally, the sink will broadcast the best TDMA schedule to all sensor nodes in the network. At this stage, the nodes will be able to transmit messages without collisions making use of the best scheduling found by the ETDMA-GA. We measure the quality of our TDMA scheduling in terms of the number of control messages exchanged. The overall message complexity of ETDMA-GA will be O(n) since it requires n messages to inform the generated scheduling to n nodes. This is the same as that of the overhead complexity of existing algorithms.

Convergence Time: :

It is crucial to identify whether the algorithm can reach the solution or not. The convergence time of GA based procedures is very important to be estimated to know for how long the procedure will run to get results. This time is surely dependent on the complexity of the algorithm, the defined fitness function and the GA parameters. When convergence occurs the difference between fitness functions is very small, meaning that there is no further progress to be gained, which in turn denotes the convergence of the algorithm.

However, the prediction is complicated to be computed because of its dependence on the application domain. Uniting fitness prediction with hamming distance prediction [44] provides an idea on this, where the predicted average fitness denotes the possible progress using GA and the predicted hamming average that denotes the remaining work. The average hamming distance (hamming average) is used as a measure of population diversity in GA to express convergence. The convergence rate has been used to determine the population size in micro GA [45]. The authors used an experimental approach primarily because of the complexity of the problem under consideration. It is mathematically difficult to identify the characteristics of the best solution. They reached a conclusion that micro GA could be converged in reasonable time. The convergence rate of GA has been discussed using the minorization condition in the Markov chain theory in [46]. They classified genetic algorithms into two cases: time-invariant genetic operators and time-variant genetic operators. For the former case, they have obtained the bound on its convergence rate on the general state space; for the latter case, they have bounded its convergence rate on the finite state space, i.e., the convergence in GA could be occurred and predicted.

In this paper, we use an experimental approach to determine the convergence time because of the complexity of the problem under consideration (NP-hard [47]) and the difficulty to identify the characteristics of its best solution [47]. In the first test, we run the programs with different network density, observing the best fitness reached with each density, see Fig. 13, where sufficient number of generations have been run such that convergence to near-optimal values was apparent. Figure 13 shows that the average latency (objective function) becomes converged in different densities 5, 10, 15, 20 at generation 1500, 3000, 2000, and 2300 respectively. It shows the values to which the proposed algorithm converged, as well as the time needed.

Fig. 13
figure 13

Effect of number of generations on objective value

The algorithm stops when the number of generations reaches a specific value which satisfies a specific condition such as stability of average latency etc. Determining stopping criteria is an important factor in the design of GA. The experiment is performed to determine stopping criteria for the proposed algorithm. Different network densities are simulated from 5 to 20 in increment of 5 by changing the network area size with fixed deployment of 100 nodes. The sink is placed at the corner of the network field (0, 0) and the average latency is taken as a decision criterion. To determine the criteria for stopping the GA, the experiment is performed by varying the number of generations for a given population (25). Figure 13 shows the relationship between the objective value (i.e, average latency) and the number of generations for different densities. The graph is obtained by plotting the average latency of the best chromosome of each generation for the same experiment. As the number of generations increase, the value of the average latency decreases. In fact, the weak chromosomes of each generation will be filtered by the fitness function. Thus, the average latency will be improved over successive generations. We can observe that the average latency becomes stable towards the generation 4000 and increases slightly with the increase in the number of generations, i.e., the chances of making significant changes in the future generations are considerably low.

5.3.2 The average latency and the average normalized latency computing

In the second test, we compute the average latency and the Average normalized latency for the proposed ETDMA-GA and compare the results with the algorithms IDegRe-LO, DepthRe-LO, Depth-LO, Rand-LO, and IDeg-LO.

Figures 14 and 15 show that the proposed ETDMA-GA has the best reduction in average latency and average normalized latency among the others regardless of the routing tree type. Where, in case of DFSA tree, the best reduction in average latency is of the proposed ETDMA-GA followed by IDegRe-LO, DepthRe-LO, Depth-LO, Rand-LO, and then IDeg-LO. While in case of Min-Hop tree, also the proposed algorithm has the best latency reduction in average, followed by IDegRe-LO, DepthRe-LO, Depth-LO, IDeg-LO, and then Rand-LO. Because IDeg-LO prioritizes the leaves of the routing tree with much interference while IDegRe-LO privileges internal sensor nodes with a lot of interference which shows that IDegRe-LO has better latency reduction than IDeg-LO. Moreover, with DFSA tree and Min-Hop tree, IDegRe-LO is better than DepthRe-LO, Rand-LO, IDeg-LO and Depth-LO because IDegRe-LO prefers to schedule first the critical sensors and sensors that are far from the sink which creates a lot of interference in the network. DepthRe-LO has better performance than Depth-LO as it allocates the first slots of TDMA to nodes with long paths.

Fig. 14
figure 14

Average latency of Rand-LO, Depth-LO, DepthRe-LO, IDegRe-LO, IDeg-LO, and proposed ETDMA-GA algorithms based on the information of DFSA and Min-Hop routing trees

Fig. 15
figure 15

Average normalized latency of DepthRe-LO, Depth-LO, Rand-LO, IDeg-LO, IDegRe-LO, and proposed ETDMA-GA algorithms based on the information of DFSA and Min-Hop routing trees

In the third test, the average schedule length for the proposed ETDMA-GA is computed and the result is compared with the algorithms IDegRe-LO, DepthRe-LO, Depth-LO, Rand-LO and IDeg-LO. Figure 16 shows that the proposed ETDMA-GA has longer TDMA length than IDeg-LO by 0.2% in average for Min-Hop tree, and than IDegRe-LO by 3% in average for DFSA tree. The proposed ETDMA-GA has these additional slots due to the latency minimization.

Fig. 16
figure 16

Average schedule length of DepthRe-LO, Depth-LO, Rand-LO, IDeg-LO, IDegRe-LO, and proposed algorithms based on the information of DFSA and Min-Hop routing trees

In the fourth test, the Average latency for ETDMA-GA for different densities is computed and the comparison with the baselines algorithms is performed in the case of Min-Hop and DFSA trees. Figure 17 shows the Average gain in latency reduction by the proposed ETDMA-GA with different densities compared with Depth-LO, IDeg-LO, Rand-LO, IDegRe-LO and DepthRe-LO. It shows for Min-Hop tree that, for all densities, the latency average of the proposed algorithm is improved by 26.47%, 27.19%, 28.27%, 15.01%, 21.14% as compared to the latency of Depth-LO, IDeg-LO, Rand-LO, IDegRe-LO, DepthRe-LO, while for DFSA tree, the latency average of the proposed ETDMA-GA is improved by 33.55%, 35.61% , 35.04%, 25.22%, 30.81% as compared with the latency of Depth-LO, IDeg-LO, Rand-LO, IDegRe-LO and DepthRe-LO.

Fig. 17
figure 17

Average gain in latency reduction with different densities by proposed ETDMA-GA, IDegRe-LO, DepthRe-LO, Depth-LO, Rand-LO, and IDeg-LO algorithms

Figure 18 shows the standard deviation for latency with different densities for proposed ETDMA-GA, IDegRe-LO, DepthRe-LO, Depth-LO, Rand-LO and IDeg-LO algorithms. It is clear from Fig. 18 that the proposed approach has less standard deviation than the other approaches.

Fig. 18
figure 18

Standard deviation for latency with different densities of proposed ETDMA-GA, IDegRe-LO, DepthRe-LO, Depth-LO, Rand-LO, and IDeg-LO algorithms

5.3.3 Effect of sink placement

In the fifth test, our target is to show the effect of moving the sink to different placements on the performance of proposed ETDMA-GA, DepthRe-LO, Depth-LO, Rand-LO, IDeg-LO, and IDegRe-LO algorithms. In this test, 100 sensor nodes with communication range fixed at 30 m are deployed randomly in 150 m × 150 m area. The sink is located at the following different places: the corner of the network (Location1), the middle of one edge of the network (Location2) and the center of the network (Location3). The performance is evaluated using Min-hop and DFSA routing trees. Figures 1920, and 21 show the average latency, average normalized latency and average schedule length of proposed ETDMA-GA, DepthRe-LO, Depth-LO, Rand-LO, IDeg-LO and IDegRe-LO algorithms in case of DFSA and Min-Hop routing trees with three different locations of the sink.

Fig. 19
figure 19

Average latency of proposed ETDMA-GA, DepthRe-LO, Depth-LO, Rand-LO, IDeg-LO and IDegRe-LO algorithms in case of DFSA and Min-Hop routing trees with three different locations of sink

Fig. 20
figure 20

Average normalized latency of proposed ETDMA-GA, DepthRe-LO, Depth-LO, Rand-LO, IDeg-LO and IDegRe-LO algorithms in case of DFSA and Min-Hop routing trees with three different locations of sink

Fig. 21
figure 21

Average schedule length of proposed ETDMA-GA, DepthRe-LO, Depth-LO, Rand-LO, IDeg-LO and IDegRe-LO algorithms in case of DFSA and Min-Hop routing trees with three different locations of sink

In Fig. 19, the latency is improved at Location2 by 21.80%, 22.59%, 22.74%, 22.89%, 23.46%, 17.74% for Depth-LO, IDeg-LO, Rand-LO, IDegRe-LO, DepthRe-LO, and the proposed ETDMA-GA, respectively as compared to Location1 in case of using Min-Hop tree. However, in case of DFSA tree, the latency is improved at Location2 by 18.09%, 15.54%, 18.51%, 22.38%, 24.93%, 9.33% for Depth-LO, IDeg-LO, Rand-LO, IDegRe-LO, DepthRe-LO, and the proposed ETDMA-GA, respectively compared to Location1.

Moreover, the latency is improved at Location3 by 41.04%, 42.77%, 42.08%, 39.96%, 39.61%, 33.92% for Depth-LO, IDeg-LO, Rand-LO, IDegRe-LO, DepthRe-LO, and proposed ETDMA-GA, respectively as compared to Location1 in case of Min-Hop tree. However, in case of DFSA tree, the latency is improved at Location3 by 21.82%, 17.28%, 20.80%, 30.05%, 34.55%, 11.48% for Depth-LO, IDeg-LO, Rand-LO, IDegRe-LO, DepthRe-LO, and the proposed ETDMA-GA, respectively compared to Location1.

Figures 1920, and 21 show that when the sink location is moved to the network center (Location3); the latency is minimized for all algorithms for both cases of routing trees because the paths from nodes to the sink is decreased.

5.3.4 Duty cycle

In the sixth test, the duty cycle of the proposed ETDMA-GA as the ratio of the active period (estimated by the number of slots used either in transmission or in reception) to the total period (the schedule length) is computed. The results are compared with the existing algorithms such as DepthRe-LO, Depth-LO, Rand-LO, IDeg-LO, IDegRe-LO. A lower duty cycle results in a lower energy consumption [48]. Figure 22 shows that for Min-Hop and DFSA trees, Rand-LO and Depth-LO have the best duty cycle due to their longer schedule length and then followed by DepthRe-LO, proposed ETDMA-GA, IDegRe-LO and IDeg-LO because their schedule lengths are smaller than those of Rand-LO and Depth-LO.

Fig. 22
figure 22

Duty Cycle of the proposed ETDMA-GA, DepthRe-LO, Depth-LO, Rand-LO, IDeg-LO, and IDegRe-LO algorithms in case of DFSA and Min-Hop routing trees

Moreover, Fig. 22 shows that in case of Min-Hop tree, the average percentages overall densities of duty gain of Depth-LO, Rand-LO, DepthRe-LO compared to the proposed ETDMA-GA are 3.3%, 3.4%,3.2%, respectively. While the average percentages overall densities of duty gain of proposed ETDMA-GA compared to IDeg-LO and IDegRe-LO are 0.7 % and 0.2%, respectively. In case of DFSA tree, the average percentages of duty gain of Depth-LO, IDeg-LO, Rand-LO, DepthRe-LO compared to proposed ETDMA-GA are 6.2%, 0.8%,6%, 1.5%, respectively. While the duty gain overall average percentages of proposed ETDMA-GA compared to IDegRe-LO is 3.3%. The main conclusion of this test is that the duty cycle of the proposed ETDMA-GA shows diminutive increase compared to other existing algorithms while the proposed ETDMA-GA achieves remarkable gain in average latency.

In summary, the proposed heuristic TDMA based genetic technique (ETDMA-GA) enumerates some of the possible solutions randomly and then generates other possible solutions by crossover and mutation operations. This makes the proposed algorithm to search better than existing blind search algorithms which start from initial point (may be bad point) and generate a solution. Such solution is based on this bad/good starting point. However, the proposed ETDMA-GA can start from many points, then evaluate each point and select the best and improve the worst. ETDMA-GA repeats these steps until it finds the final best solution.

6 Conclusion

In this work, a new TDMA scheduling based on genetic algorithm using latency as fitness function in order to reduce the latency of communications in tree based WSN have been proposed. Two dimensional chromosome matrix is designed to represent TDMA schedule and the required genetic operations are provided. The proposed algorithm utilizes the information that comes from routing protocol in order to find the best design for TDMA schedule. Simulation results show that the proposed algorithm has better performance than existing state-of-the-art approaches such as Rand-LO, Depth-LO, DepthRe-LO, IDegRe-LO and IDeg-LO in terms of average latency, average normalized latency and average schedule length.