Disclosure of Invention
The invention aims to provide a routing method of a wireless sensor network, which ensures the network stability and the network energy load balance of the whole wireless sensor network; another object of the present invention is to provide a wireless sensor network routing apparatus, device and computer readable storage medium including the above method, which also ensure network stability and network energy load balancing of the whole wireless sensor network.
In order to solve the above technical problem, the present invention provides a routing method for a wireless sensor network, comprising:
dividing the wireless sensor network into k clusters according to a preset clustering algorithm; each cluster comprises a cluster head node and a plurality of cluster member nodes; the difference value of the distances between the cluster head node and each cluster member node is smaller than a preset error threshold value, and the preset error threshold value is minimum within an allowable range;
controlling transmission of communication data from the cluster member node to the cluster head node;
establishing a dynamic optimal inter-cluster routing path between the cluster head node and the sink node according to a preset routing algorithm;
and controlling the communication data to be transmitted from the cluster head node to the sink node through the dynamic optimal inter-cluster routing path.
Preferably, the preset clustering algorithm is a k-means algorithm, and the process of dividing the wireless sensor network into k clusters according to the preset clustering algorithm specifically includes:
step S1: selecting k nodes from the n nodes as historical optimal cluster head nodes, wherein the cluster where the historical optimal cluster head nodes are located is the historical optimal cluster;
step S2: calculating the distance between a residual node and each historical optimal cluster head node, and dividing the residual node and the historical optimal cluster head node closest to the residual node into a cluster;
step S3: obtaining a new historical optimal cluster head node of each cluster through calculation, wherein the cluster where the new historical optimal cluster head node is located becomes a new historical optimal cluster;
step S4: judging whether the difference value between the standard measure function value of the new optimal historical cluster and the standard measure function value of the previous optimal historical cluster is smaller than a preset standard threshold or reaches the maximum iteration number, if so, ending the clustering process; if not, returning to step S2, where the historical optimal cluster head node in step S2 is the new historical optimal cluster head node calculated in step S3.
Preferably, the standard measure function value is a square sum of errors in a cluster, and a formula for calculating the square sum of errors in the cluster is as follows:
wherein E is a standard measure function, k is the total number of clusters, C
iIs a set of said clusters, X is a member node of said clusters,
is said cluster C
iThe cluster head node of (1).
Preferably, the preset routing algorithm is an ant colony optimization algorithm.
In order to solve the above technical problem, the present invention further provides a wireless sensor network routing apparatus, including:
the wireless sensor network cluster system comprises a dividing unit, a clustering unit and a processing unit, wherein the dividing unit is used for dividing a wireless sensor network into k clusters according to a preset clustering algorithm, and each cluster comprises a cluster head node and a plurality of cluster member nodes; the difference value of the distances between the cluster head node and each cluster member node is smaller than a preset error threshold value, and the preset error threshold value is minimum within an allowable range;
a first control unit for controlling transmission of communication data from the cluster member node to the cluster head node;
the creating unit is used for creating a dynamic optimal inter-cluster routing path between the cluster head node and the sink node according to a preset routing algorithm;
and the second control unit is used for controlling the communication data to be transmitted to the sink node from the cluster head node through the dynamic optimal inter-cluster routing path.
Preferably, the dividing unit includes:
the selecting subunit is used for selecting k nodes from the n nodes as historical optimal cluster head nodes, and the cluster where the historical optimal cluster head nodes are located is a historical optimal cluster;
the first calculating subunit is configured to calculate distances between remaining nodes and each of the initial cluster head nodes, and divide the remaining nodes and the initial cluster head node closest to the remaining nodes into a cluster;
the second calculating subunit is configured to obtain a new historical optimal cluster head node of each cluster through calculation, where a cluster where the new historical optimal cluster head node is located becomes a new historical optimal cluster;
a judging subunit, configured to judge whether a difference between the standard measure function value of the new optimal historical cluster and the standard measure function value of the previous optimal historical cluster is smaller than a preset standard threshold or reaches a maximum iteration number, and if so, end the clustering process; if not, returning to step S2, where the historical optimal cluster head node in step S2 is the new historical optimal cluster head node calculated in step S3.
In order to solve the above technical problem, the present invention further provides a wireless sensor network routing device, including:
a memory for storing a computer program;
a processor for executing the computer program to implement the steps of the wireless sensor network routing method as described in any one of the above.
In order to solve the above technical problem, the present invention further provides a computer-readable storage medium, having a computer program stored thereon, where the computer program is executed by a processor to implement the steps of the wireless sensor network routing method according to any one of the above embodiments.
The invention provides a wireless sensor network routing method, a device, equipment and a computer readable storage medium, wherein the method comprises the steps of dividing a wireless sensor network into k clusters according to a preset clustering algorithm; each cluster comprises a cluster head node and a plurality of cluster member nodes; the difference value of the distance between the cluster head node and each cluster member node is smaller than a preset error threshold value, and the preset error threshold value is minimum within an allowable range; controlling communication data to be transmitted from the cluster member node to the cluster head node; establishing a dynamic optimal inter-cluster routing path between a cluster head node and a sink node according to a preset routing algorithm; and controlling the communication data to be transmitted from the cluster head node to the aggregation node.
By utilizing the invention, the wireless sensing network is divided into a plurality of clusters through the preset clustering algorithm, and the distances between the cluster head nodes and each cluster member node are ensured to be as equal as possible, so that the energy consumed when each cluster member node sends data to the cluster head nodes is as equal as possible, and because the cluster head nodes and the sink nodes transmit communication data through the dynamic optimal inter-cluster routing path, the energy consumed when each cluster head node transmits the communication data is also minimum.
Detailed Description
The core of the invention is to provide a routing method of a wireless sensor network, which ensures the network stability and the network energy load balance of the whole wireless sensor network; another core of the present invention is to provide a wireless sensor network routing apparatus, device and computer readable storage medium including the above method, which also ensure network stability and network energy load balancing of the whole wireless sensor network.
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The present invention provides a routing method of a wireless sensor network, as shown in fig. 1, fig. 1 is a flowchart of the routing method of the wireless sensor network provided by the present invention, and the method includes the following steps:
step 101: dividing the wireless sensor network into k clusters according to a preset clustering algorithm; each cluster comprises a cluster head node and a plurality of cluster member nodes; the difference value of the distance between the cluster head node and each cluster member node is smaller than a preset error threshold value, and the preset error threshold value is the minimum within an allowable range.
The invention relates to a wireless sensor network routing method based on two optimization algorithms, wherein the network structure is a hierarchical clustering algorithm, and compared with a planar structure, the network structure has higher working efficiency and is more suitable for monitoring areas with poor environment and complex terrain.
Firstly, a wireless sensor network is divided into a plurality of clusters through a preset clustering algorithm in a first stage, the node types of the wireless sensor network after clustering operation are divided into cluster head nodes, cluster member nodes and sink nodes, and different types of nodes undertake different work, wherein the distance between the cluster head nodes and other cluster member nodes is kept within a range as much as possible, namely the distances from the other cluster member nodes to the cluster head nodes are almost the same.
Step 102: control communication data is transmitted from the cluster member node to the cluster head node.
It should be noted that the cluster head node of each cluster allocates a Time slot for transmitting data to the member in the cluster in a TDMA (Time Division Multiple Access) manner, and the cluster member node transmits the acquired data to the cluster head node.
Step 103: and establishing a dynamic optimal inter-cluster routing path between the cluster head node and the sink node according to a preset routing algorithm.
It should be noted that, after the information collected by each cluster member node is collected, the cluster head node needs to fuse the collected information and transmit the fused information to the sink node, and the second stage of the present invention is to establish a dynamic optimal inter-cluster routing path between the cluster head node and the sink node by a preset routing algorithm after considering the communication between the clusters, where the path is a dynamic path, that is, the dynamic optimal inter-cluster routing path may change according to different actual conditions of the wireless sensor network.
Step 104: and controlling the communication data to be transmitted to the sink node from the cluster head node through the dynamic optimal inter-cluster routing path.
It should be noted that, after the cluster head node fuses the collected information and transmits the fused information to the sink node, the sink node uploads the information to the data processing center for data storage, processing and analysis. The whole wireless sensing network works by finally transmitting the monitored environmental information to the data processing center.
Preferably, the preset clustering algorithm is a k-means algorithm, as shown in fig. 2, and fig. 2 is a flowchart of a wireless sensor network clustering method provided in an embodiment of the present invention, and according to the preset clustering algorithm, a process of dividing a wireless sensor network into k clusters specifically includes:
step S1: and selecting k nodes from the n nodes as historical optimal cluster head nodes, wherein the cluster where the historical optimal cluster head nodes are located is the historical optimal cluster.
It should be noted that k nodes are selected from n nodes in the wireless sensor network as the historical optimal cluster head node, and the selection mode may be random selection, and of course, the present invention is not limited to a specific selection mode. The wireless sensor network is divided into k clusters by taking the k cluster head nodes as centers.
Step S2: and calculating the distance between the residual node and each historical optimal cluster head node, and dividing the residual node and the historical optimal cluster head node closest to the residual node into a cluster.
Step S3: and obtaining a new historical optimal cluster head node of each cluster through calculation, wherein the cluster where the new historical optimal cluster head node is located becomes the new historical optimal cluster.
Step S4: judging whether the difference value between the standard measure function value of the new optimal historical cluster and the standard measure function value of the previous optimal historical cluster is smaller than a preset standard threshold or reaches the maximum iteration number, if so, entering a step S5, and performing a step S5: finishing the clustering process; if not, returning to step S2, at this time, the historical optimal cluster head node in step S2 is the new historical optimal cluster head node calculated in step S3.
It should be noted that, after a new historical optimal cluster head node is obtained after step S3 is performed, the standard measure function value of the initial cluster and the standard measure function value of the historical optimal cluster are calculated, and it is determined whether a difference between the two is smaller than a preset standard threshold or reaches the maximum iteration number, if so, it indicates that the cluster members are not changed, and the clustering process may be ended.
It can be understood that the establishment of the clusters and the selection of the cluster heads are completed through a k-means algorithm, so that the cluster heads in each cluster keep proper distances from all other cluster member nodes in the cluster, the communication quality between the cluster member nodes and the cluster head nodes is improved, the data received by the monitoring environment is more accurate and more real-time, and the load balance and the network stability of the whole network are ensured.
Preferably, the standard measure function value is the square sum of the errors in the clusters, and the formula for calculating the square sum of the errors in the clusters is as follows:
where E is the standard measure function, k is the total number of clusters, C
iIs a set of clusters, X is a member node of a cluster,
is a cluster C
iThe cluster head node of (1).
Preferably, the preset routing algorithm is an ant colony optimization algorithm.
It should be noted that the ant colony algorithm is initially a probabilistic algorithm for finding the optimal path, which imitates the behavior of ants finding paths in the process of finding food. The ant can secrete a chemical substance 'pheromone' on the path from which the ant walks in the process of searching for food, the pheromones can attract other ants, when a subsequent ant touches the intersection again, the probability of selecting a path with high concentration of the 'pheromone' is relatively high, and an optimal path with the highest concentration of the 'pheromone' can be found out by the ant in the process of searching for food in the future. In the ant colony optimization algorithm implementation process. The pheromone comprehensively considers three factors of energy, distance and time delay.
In order to achieve relative balance of energy consumption of different nodes, it is necessary to avoid that each node transmits data through the same optimal path, so that the data packet flow of the path is too large, and the energy consumption of the node is caused. The algorithm is improved to accelerate convergence and avoid convergence to an optimal path, so that by adaptively changing the pheromone concentration of the algorithm, the routing consumption of ants, namely the energy required to be consumed by data packet transmission and the residual energy of nodes are both taken as factors influencing the pheromone concentration, and in the algorithm, the residual energy of the accessed nodes is taken as a parameter influencing the pheromone concentration. The specific implementation process is as follows:
assuming that an ant m is in cluster head node i, the probability that it selects the next cluster head node j for access:
(if j∈allowed
k) Wherein i and j are respectively a starting cluster head node and a next cluster head node;
the visibility is the reciprocal of the distance between two paths i and j; alpha is alpha
ij(t) pheromone concentrations from i to j at time t; allowed
kThe cluster head nodes which are not accessed are set; τ, β are two constants, weighted for pheromones and visibility.
And (3) updating pheromone: and (3) calculating the total path length CK of each ant every time iteration is completed, and updating the pheromone according to the following formula:
wherein m is the number of cluster head nodes, 0<ρ<1 is the evaporation rate of pheromone, Δ αij kPheromones left for the kth ant cluster head node on paths i to j.
The invention provides a routing method of a wireless sensor network, which comprises the steps of dividing the wireless sensor network into k clusters according to a preset clustering algorithm; each cluster comprises a cluster head node and a plurality of cluster member nodes; the difference value of the distance between the cluster head node and each cluster member node is smaller than a preset error threshold value, and the preset error threshold value is minimum within an allowable range; controlling communication data to be transmitted from the cluster member node to the cluster head node; establishing a dynamic optimal inter-cluster routing path between a cluster head node and a sink node according to a preset routing algorithm; and controlling the communication data to be transmitted from the cluster head node to the aggregation node.
By utilizing the invention, the wireless sensing network is divided into a plurality of clusters through the preset clustering algorithm, and the distances between the cluster head nodes and each cluster member node are ensured to be as equal as possible, so that the energy consumed when each cluster member node sends data to the cluster head nodes is as equal as possible, and because the cluster head nodes and the sink nodes transmit communication data through the dynamic optimal inter-cluster routing path, the energy consumed when each cluster head node transmits the communication data is also minimum.
The present invention also provides a routing apparatus for a wireless sensor network, as shown in fig. 3, and fig. 3 is a schematic structural diagram of the routing apparatus for a wireless sensor network provided in the present invention, and the apparatus includes:
the wireless sensor network cluster dividing device comprises a dividing unit 1, a clustering unit and a processing unit, wherein the dividing unit is used for dividing a wireless sensor network into k clusters according to a preset clustering algorithm, and each cluster comprises a cluster head node and a plurality of cluster member nodes; the difference value of the distance between the cluster head node and each cluster member node is smaller than a preset error threshold value, and the preset error threshold value is minimum within an allowable range;
a first control unit 2 for controlling transmission of communication data from the cluster member node to the cluster head node;
the creating unit 3 is used for creating a dynamic optimal inter-cluster routing path between the cluster head nodes and the sink nodes according to a preset routing algorithm;
and the second control unit 4 is used for controlling the communication data to be transmitted to the sink node from the cluster head node through the dynamic optimal inter-cluster routing path.
Preferably, the dividing unit 1 includes:
the selecting subunit is used for selecting k nodes from the n nodes as historical optimal cluster head nodes, and the cluster where the historical optimal cluster head nodes are located is the historical optimal cluster;
the first calculating subunit is used for calculating the distance between the remaining nodes and each historical optimal cluster head node and dividing the remaining nodes and the historical optimal cluster head node closest to the remaining nodes into a cluster;
the second calculation subunit is used for obtaining a new historical optimal cluster head node of each cluster through calculation, and the cluster where the new historical optimal cluster head node is located becomes a new historical optimal cluster;
the judging subunit is used for judging whether the difference value between the standard measure function value of the new optimal historical cluster and the standard measure function value of the previous optimal historical cluster is smaller than a preset standard threshold or reaches the maximum iteration number, and if so, ending the clustering process; if not, returning to step S2, at this time, the historical optimal cluster head node in step S2 is the new historical optimal cluster head node calculated in step S3.
The invention provides a wireless sensor network routing device, which comprises a wireless sensor network which is divided into k clusters according to a preset clustering algorithm; each cluster comprises a cluster head node and a plurality of cluster member nodes; the difference value of the distance between the cluster head node and each cluster member node is smaller than a preset error threshold value, and the preset error threshold value is minimum within an allowable range; transmitting communication data from the cluster member node to the cluster head node; establishing a dynamic optimal inter-cluster routing path between a cluster head node and a sink node according to a preset routing algorithm; and transmitting the communication data from the cluster head node to the sink node.
By utilizing the invention, the wireless sensing network is divided into a plurality of clusters through the preset clustering algorithm, and the distances between the cluster head nodes and each cluster member node are ensured to be as equal as possible, so that the energy consumed when each cluster member node sends data to the cluster head nodes is as equal as possible, and because the cluster head nodes and the sink nodes transmit communication data through the dynamic optimal inter-cluster routing path, the energy consumed when each cluster head node transmits the communication data is also minimum.
The invention also provides a wireless sensor network routing device, which comprises:
a memory for storing a computer program;
a processor for executing a computer program to implement the steps of the routing method of the wireless sensor network according to any one of the embodiments.
The invention further provides a computer-readable storage medium, on which a computer program is stored, which, when executed by a processor, implements the steps of any one of the wireless sensor network routing methods according to the embodiments.
For the introduction of the wireless sensor network routing device and the computer readable storage medium provided by the present invention, please refer to the above method embodiments, which are not repeated herein.
The present invention provides a wireless sensor network routing method, apparatus, device and computer readable storage medium. The principles and embodiments of the present invention are explained herein using specific examples, which are presented only to assist in understanding the method and its core concepts. It should be noted that, for those skilled in the art, it is possible to make various improvements and modifications to the present invention without departing from the principle of the present invention, and those improvements and modifications also fall within the scope of the claims of the present invention.