# Research on Dynamic Spectrum Allocation Algorithm Based on Cyclic Neural Network

Authors: Xiaomo Yu; Yonghua Cai; Wenjing Li; Xiaomeng Zhou; Ling Tang
Journal: Wireless Communications and Mobile Computing
 (2022)

---

## Abstract

Due to the wide application of cognitive wireless network, the network structure is becoming more and more complex. It is difficult to establish the corresponding mathematical model to simulate the high complexity network environment. The algorithm based on recurrent neural network in deep reinforcement learning can effectively solve this problem. In addition, with the rise of deep learning in recent years, the combination of reinforcement learning and deep learning shows excellent ability in dealing with complex problems and data operation. This paper is aimed at studying dynamic spectrum allocation based on cyclic neural network. This paper briefly introduces MATLAB, sets up the network environment of algorithm simulation, then analyzes the overall performance of the improved genetic algorithm, and explores the influence of genetic algorithm-related parameters and network environment-related parameters on the performance of the algorithm. The results show the improved genetic algorithm. The network efficiency can be improved by about 2%, but the spectrum switching frequency can be reduced by 69%. When the number of primary users in the network is large, the network benefit of improving the genetic algorithm is superior to the other two algorithms. In addition, when the crossover probability is 0.6 and 0.1, the fitness value is higher than the crossover probability of 0.9 and 0.5; the interference of authorized users in the network initially has less impact on the secondary user.


---

## Body

## 1. Introduction

The “object” in the Internet of Everything, that is, the sensor and other intelligent objects in the Internet, is used to detect various kinds of data that are artificially needed and timely guide the changes of various states and parameters in the current situation. It can be seen that the significance of sensor network for the era of Internet of all things is extraordinary [1, 2]. The wireless sensor network is an important part of the Internet of Things. It plays a role similar to the “sensory” and directly affects the Internet of Things to make the next judgment. The wireless sensor network is a multihop network formed by a large number of sensor nodes disposed in the detection area through self-organization. Its main function is data collection, processing, and transmission. When establishing a wireless sensor network, it can be manually deployed or directly use the flight device to scatter the sensor nodes to the monitoring area, and then, the nodes self-organize into a network [3, 4]. The main task of the wireless sensor network is to collaboratively sense and collect data between nodes and report the monitoring information to users; its advantages include rapid deployment, self-organizing into the network, and good concealment, so it is in intelligent transportation and battlefield targets. Applications in areas such as rapid positioning, physiological data collection systems, and marine data detection have excellent performance, but the limitations are that the energy of the sensor is limited and the communication capacity between nodes is limited [5, 6].At the same time, with the wide application of wireless communication in various industries, the number of various forms of wireless communication has increased dramatically, while the spectrum resources are very limited, and the frequency band becomes more and more crowded. Of course, scientists are constantly trying new wireless communication technology theory to alleviate this situation. Therefore, for traditional communication systems, scientists have proposed link adaptive technology and multiantenna technology to coordinate the contradiction between the high demand of wireless communication services and the scarcity of spectrum resources [7, 8]. However, due to the satisfaction of Shannon’s theorem, the transmission efficiency of the spectrum cannot be improved without limit, and the contradiction is not improved. The utilization of spectrum resources is still very unbalanced, although the spectrum resources at this stage have been saturated. The information transmission between wireless sensor network nodes adopts IEEE802.15.4 protocol. The IEEE802.15.4 protocol is the basis of Zigbee, MiWi, and Thread specifications. It works in the ISM frequency band and has the lowest transmission power, the smallest transmission distance, and short operation time and is easy to be subject to other communication system and noise interference characteristics. The ISM band is an unlicensed band and is used by many types of networks because it has no authorized use restrictions. Currently, at least three kinds of wireless communication protocols use this frequency band, which are IEEE802.11b/g protocol, Bluetooth, and IEEE802.15.4 protocol [9, 10]. Along with the wider application range of wireless sensor networks, the possibility of multiple wireless sensor networks in the same area is increasing, so the wireless sensor network itself will also cause interference, affecting the performance of both. Therefore, it is necessary to apply the dynamic spectrum allocation technology in cognitive radio to wireless sensor networks to solve the problem of imbalance in spectrum utilization [11, 12].Zhang proposed a new dynamic spectrum allocation method for hybrid accessed cognitive femtocell. In this method, a macro base station (BS) allocates a portion of the subchannels to a femto access point (FAP) to motivate the FAP to serve macro users (MUS). The FAP then allocates subchannels and power to maximize femtocell network utility while guaranteeing the throughput of the served MUS. In addition, we attribute the corresponding resource allocation problem to a utility maximization problem and propose a method to solve by the dual decomposition method. The simulation results show that the method has good effects on wireless service providers and femtocells [13, 14]. Touzri proposed a game-based design method for dynamic spectrum allocation mechanism of cognitive radio networks. The secondary user (SU) detects when channels can be used without disturbing any primary users and attempts to opportunistically use them. When the SU detects an idle channel, it estimates its capacity and sends its estimate to the central manager. The manager calculates the conflict-free allocation by implementing a real mechanism. SUS must pay the amount allocated, depending on a set of valuations, which are expressed as profit maximizers. Touzri proposed and tests two mechanisms for realizing this idea, which are proven to be real and easy to handle and approximately effective. We show the flexibility of these mechanisms and show how they can be modified to achieve other goals, such as fairness, and how they can run without actually charging SUS [15, 16]. In dynamic spectrum allocation (SA) of elastic optical networks (EONS), spectral fragmentation will have a significant impact on spectrum utilization. In order to reduce the segmentation, the SA algorithm should fully consider various factors to achieve the purpose of optimization. Prasan studied the SA problem with long-term awareness in dynamic scenarios. First, Prasan designed a new metric that considers the effects of debris from the perspective of occupied frequency slots (FSS) and idle frequency slots (FSS), measuring the fragmentation in the path. Using this metric, a hold time sensing algorithm is proposed, which considers the different overall fragment states in the network and selects the optimal spectrum allocation method. The performance of the algorithm is verified by simulation. Compared with the traditional algorithm, the algorithm has lower blocking probability and can better utilize network resources [17, 18]. The service provider and the D2D service group solved the user spectrum allocation problem by using Bertrand game theory. The utility functions of the D2D service group and the cellular service provider are improved, respectively. Hoffmann also proposed optimal pricing for cellular service providers and dynamic price adjustment strategies for D2D service groups. In addition, the existence of the Nash equilibrium state and the convergence of the algorithm are proved. Through simulation and experiment, the influence of different cellular users and different learning factors on the performance of the scheme is analyzed. Compared with the existing scheme, this scheme not only improves the spectrum utilization rate but also improves the system fairness [19, 20].The purpose of this paper is to study dynamic spectrum allocation based on cyclic neural network. This paper introduces several models of dynamic spectrum allocation. The improved genetic algorithm is simulated on MATLAB platform to verify the performance of the algorithm. The influences of network environment parameters on the network revenue are compared with CSGC, traditional genetic algorithm, and improved genetic algorithm. The conclusion is drawn that the improved genetic algorithm can guarantee the network revenue and reduce the energy loss caused by the spectrum switching frequency.


## 2. Proposed Method

### 2.1. Overview of Dynamic Spectrum Allocation

Dynamic spectrum allocation is a method of saving spectrum. The system assigns an idle channel to the mobile station in real time according to the call application of the mobile station. After the users are used, they will be redistributed by the system recycling channel.


#### 2.1.1. Wireless Sensor Network

Wireless sensor network (WSN) is a distributed sensor network, whose end is a sensor that can sense and check the outside world. Sensors in WSN communicate wirelessly, so the network settings are flexible, the location of devices can be changed at any time, and they can also be connected with the Internet in wired or wireless way. A multihop ad hoc network is formed by wireless communication. As a key field of Internet of Things applications, the task of wireless sensor network is to cooperate among nodes to sense and collect data. Its architecture is generally composed of three parts: cognitive node, sink node, and user management center. Its structure is shown in Figure1.Figure 1
Wireless sensor network structure.The transmission of wireless sensor networks is based on the spectrum resources in the network. However, in the process of the development of wireless communication technology, the limited spectrum resources are used by various wireless communication methods, and the problem of resource shortage is becoming more and more serious. In order to improve the utilization of spectrum resources and solve the problem of unbalanced spectrum utilization, various dynamic spectrum allocation methods are proposed.


#### 2.1.2. The Concept of Dynamic Spectrum Allocation

There are two types of basic users in cognitive radio networks, authorized users and unauthorized users, which are also called primary user (PU) and secondary users (SU), respectively. At present, the fixed spectrum allocation policy is to allocate the licensed spectrum to the main users, so they have the absolute priority to use the licensed spectrum. Secondary users have the ability to detect spectrum holes in real time (spectrum holes are frequency bands not occupied by PU in the spectrum domain), that is, when the authorized spectrum is idle at a certain moment and not occupied by the primary users, secondary users can access this spectrum and then use this spectrum for data transmission.Dynamic spectrum allocation technology is a cognitive radio-based spectrum switching technology. The two most important features of cognitive radio systems are the spectrum sensing and spectrum reconfiguration of the physical layer. The dynamic spectrum allocation technology can detect which channel frequency band is idle in the current state and record and share all the busy and idle states. In each cycle, the system parameters are adjusted in real time, and when there is a free frequency band, assign authorized users in a timely manner. When spectrum allocation is performed on cognitive users, it is necessary to dynamically detect whether there is a free spectrum or whether the authorized user is in a free time state. The spectrum allocation is based on the above-mentioned allocation method, and the frequency band resources are dynamically utilized to maximize the utilization of the spectrum and the transmission rate. The cognitive radio theory topology is shown in Figure2.Figure 2
Cognitive radio theory topology.As can be seen from Figure2, cognitive radio theory in other words is to use the spectrum for secondary utilization, that is, in the case where the spectrum resources are scarce, and the cognitive user and the authorized user need to occupy the channel information at the same time, the authorization is realized. Users and cognitive users can share spectrum resources fairly and efficiently with each other, maximizing the occupation of spectrum information and reducing waste of spectrum resources. Dynamic spectrum allocation follows the principle of authorized users, and the cognitive user is supplemented by the dynamic and flexible allocation of spectrum. In the cognitive wireless sensor network system, the bandwidth, user location, and number of channels are not fixed. Dynamic spectrum allocation can adaptively adjust the spectrum allocation strategy according to user requirements or the system’s own indicators, thereby improving system flexibility and avoiding waste of spectrum holes, so dynamic spectrum allocation has a great advantage over the static spectrum allocation method in solving the problem of spectrum resource sharing. According to the network structure, spectrum allocation is divided into centralized and distributed. The centralized allocation method collects spectrum resources by a dedicated network coordinator and establishes a schedule, broadcasts to the secondary users, and performs spectrum allocation according to the wireless environment monitoring information uploaded by the secondary users, and the cognitive users assigned to the spectrum start to transmit data. The centralized allocation method can take into account the different needs of different users. The network coordinator is responsible for coordinating the spectrum configuration of each user to avoid mutual interference. The information exchange causes a large amount of scheduling overhead and energy consumption. When the network scale is large, the disadvantage is as follows. Once the network coordinator fails or is damaged, the entire network will be partially or even completely paralyzed. Distributed requires each sensor node to have the ability to perceive global or local spatially available spectrum and compete for spectrum allocation based on monitoring information between local and neighbors. It is suitable for nonfixed networks with low complexity, but distributed allocation due to each node participates in the allocation and is more susceptible to wireless environments such as channel fading.


#### 2.1.3. Dynamic Spectrum Allocation Model

The current models for dynamic spectrum allocation mainly include interference temperature, auction bidding, graph theory coloring, and game theory. The game theory model and the auction bidding model are mainly used in the distributed spectrum allocation model, while the graph theory coloring model and the interference temperature model are mostly used in centralized spectrum allocation. The four spectrum allocation models are briefly described below.(1) Interference Temperature Model. The interference temperature model is an underlay spectrum access method, which means that the power of the receiver is reduced to the extent that the primary user can withstand by adjusting the power of the transmitter, as long as the transmission power of the secondary user does not exceed that set by the primary user. Interfering with temperature, you can coexist with authorized users, wherein the interference temperature is quantized as the ratio of the interference power to the bandwidth, and the representation method is
(1)TIfc,B=PIfc,BkB.In formula (1), TI is the interference temperature, PIfc,B is the average noise power (unit W) of the receiving device with fc as the center frequency, B is the bandwidth, k is the Boltzmann constant, and 1.38∗10−23J/C∘ is received by the main user. The sum of the temperature corresponding to the transmission power of the secondary user and the interference temperature TI is less than the threshold TL, that is, according to
(2)TI+PSLkB≤TL.This means that the secondary user can use the same frequency within the same communication range as the primary user without affecting the primary user.(2) Auction Bidding Model. The auction bidding model performs spectrum allocation based on the bidding idea of the most profitable person in economics. The auction bidding model is usually applied to the centralized spectrum allocation. Each secondary user passes its own network revenue to the BS, and there is no information transmission between the secondary users. Therefore, the centralized allocation method can reduce the overhead and be closer to the principle of wireless sensor network energy saving. When using the auction bidding model for spectrum allocation, the auctioneers in the auction are usually simulated by the base station or the fusion center, and each cognitive node is a bidder. For each auction, the cognitive node will price and bid on the demand for spectrum resources, and the auctioneer will determine the spectrum allocation scheme for the purpose of maximizing network revenue. In the auction bidding model, the network can formulate rules according to its own needs, such as maximum throughput, time fairness, and fairness of opportunity. The bidder obtains the relevant spectrum allocation scheme according to the rules.(3) Graph Theory Coloring Model. Graph theory is a mathematical model function in discrete mathematics. First, the specific practical problems are abstracted into graphs, and the constructed graphs are discussed and studied. Shading a graph means that all the vertices of the graph are colored, but adjacent nodes must use different colors and then the minimum number of colors to use. This is the research background of the graph theory coloring model. Figure 3 is a schematic diagram of a graphing coloring model. In the figure, the A area is adjacent to the B area and the C area, and the B area is adjacent to the D area so that the colors of the three areas A, B, and C are different, and the color of the B area and the D area are also different, which can satisfy the requirements of different colors of adjacent areas in the graph coloring. In a distributed network, the graph theory coloring model maps the network distribution of authorized cognitive radios to cognitive users, as shown in Figure 3.Figure 3
Graph coloring model.As can be seen from Figure3, the topology diagram shown in Figure 2 shows the network structure in which the primary and secondary users coexist in cognitive radio. If two network common channels A, B, and C are assumed, we use the aggregate symbol channel−A,B,C to represent the user. The symbol of -IV is used to indicate, and the authorized users occupy channels A, B, C, and C, respectively. The range within the circle indicates that the authorized users cannot share the same channel, and the spectrum occupancy of the cognitive user cannot affect the normal spectrum usage of the authorized user. For example, in the topology diagram, if the channel occupied by the authorized user IV is channel C, the cognitive user cannot use channel C within the coverage of the authorized user IV, so the available channel set is channel5−A,B; other cognitive users and authorized users should also follow such rules. The line in Figure 2 indicates that there is interference at two points of the line segment, that is, if the two vertices in the figure are connected by a common line, it means that the two lines share the same frequency band. At the same time, each vertex exists in a set, which represents the spectrum resources that can be used in the area, because the spectrum usage information of the authorized users changes in real time. As the network environment changes, each node in the network topology updates the network topology information in the database in each cycle of the system through interaction and exchange of information.


### 2.2. Dynamic Spectrum Allocation Algorithm Based on Cyclic Neural Network

The main problems caused by channel allocation in available spectrum space are adjacent channel interference and cochannel interference. For adjacent channel interference, nonoverlapping channels can be used to eliminate it. For cochannel interference, it is necessary to carry out optimal channel allocation in cognitive wireless networks to avoid conflicts caused by selecting the same channel. Aiming at the joint problem of dynamic power control and channel allocation, in order to overcome the large amount of computation caused by the large space state and partial observability of complex problems, a joint algorithm of dynamic power control and channel allocation based on cyclic neural network is proposed. So that the secondary users can successfully access the channel, make the best use of the optimal power control strategy, avoid harmful interference to the primary users, and improve the overall performance of cognitive wireless networks and the utilization of spectrum resources.


#### 2.2.1. Long- and Short-Term Memory Cycle Neural Network

Long-term and short-term memory is a special cyclic neural network, which mainly includes forgetting stage, selective memory stage, and output stage. It is realized through forgetting gate, input gate, and output gate, respectively. The core of long-term and short-term memory is to control the unit state through three interactive gating states, remember the information that needs to be remembered for a long time, and forget the unimportant information. Therefore, it shows excellent performance in solving the problems of gradient disappearance and gradient explosion in the process of long sequence training.(1) Forgetting Stage. The first stage of long-term and short-term memory is the forgetting stage, which is mainly to selectively forget the input transmitted from the previous node, which is determined by the sigmoid activation function of the forgetting gate, as shown in the following formula.
(3)f=σWfnht−1,xt+bf.(2) Selective Memory Stage. It is mainly to memorize and select the input value and determine the new information that should be stored in the unit state. Firstly, the sigmoid function layer determines the updated value, and then, the tanh function layer creates the candidate value vector C~ to help adjust the neural network and then creates the state combined with the updated value and the candidate value, as shown in the following formula.
(4)it=σWinht−1,xt+bi,(5)C~=tanhWCnht−1,xt+bC.(3) Output Phase. In this stage, the results of forgetting stage and selective memory stage are summed, and the output value is obtained by sigmoid function and tanh function, as shown in the following formula. The new cell state and the new hidden state are then transferred to the next step.
(6)C=ft∗Ct−1+it∗C~,(7)ot=σWonht−1,xt+bo,(8)ht=ot∗tanhC.


#### 2.2.2. Algorithm Flow

We consider using long-term and short-term memory combined with deepQ network to integrate some known observation information collected and obtain the optimal control strategy through online learning and distributed methods. The unique network structure of long-term and short-term memory can better estimate the state of the channel and improve the probability of successful access to the channel, as shown in Figure 4.Figure 4
Structure of long-term and short-term memory depthQ network.


### 2.3. Research on Dynamic Spectrum Allocation Algorithm Based on Genetic Algorithm

#### 2.3.1. Characteristics and Processes of Traditional Genetic Algorithms

The genetic algorithm performs search calculation and problem-solving according to the law of natural selection. In recent years, through in-depth research by scholars at home and abroad, many problems that cannot be solved by traditional mathematics have been solved. The advantages of genetic algorithms are as follows:(1)
Searching in units of populations, multiple individuals simultaneously comparing with inherent parallelism(2)
The search ability size has nothing to do with the problem to be solved(3)
It has strong scalability and can be combined with other models and algorithms to optimize the performance of the algorithm(4)
The evaluation function mechanism is adopted in the search process to reduce the complexity(5)
Iteratively using the probability mechanism, the randomness is strongGenetic algorithm as a classical evolutionary algorithm also has its own drawbacks:(1)
The initial population has a great influence on the performance of the algorithm, which can be improved by adding some prior knowledge(2)
The three operations of selecting, crossing, and mutating in the algorithm involve multiple parameters, such as crossover probability and mutation probability. The difference of these parameters will affect the performance of the algorithm. In practical applications, multiple tests are needed to find the optimal parameters(3)
The genetic algorithm does not use the feedback information of the network in time, so it takes a lot of training to get an accurate solution, but this reduces the efficiency of the algorithm(4)
It is prone to “premature” phenomenon


#### 2.3.2. Adaptive Genetic Algorithm

Adaptive genetic algorithm means that some parameters in the genetic algorithm can change with the evolution process, which increases the diversity of the algorithm population. The adaptive genetic algorithm is a derivative algorithm based on traditional genetic algorithm. It inherits the advantages of traditional genetic algorithm and abandons the shortcomings of traditional genetic algorithm so that the algorithm performs crossprobability and mutation probability in the process of implementing adaptive genetic algorithm. It will change with the increase of evolutionary algebra and the change of population fitness value, so it fills the inadequacies of traditional genetic algorithm to some extent. Adaptive genetic algorithm can be adaptive from various angles, such as fitness function, crossover probability, mutation probability, selection probability, and population size. The most commonly used are crossover probability and mutation probability. Generally, in the early stage of evolution, crossoperation can produce individuals with high fitness values. Therefore, increasing the probability of crossover and reducing the probability of mutation can speed up the optimization process. In the later stage of evolution, crossoperation cannot produce better individuals, and mutation operation is required for global optimization, so reduce the crossover probability, reduce the probability of mutation, reduce the amount of redundant operations, continue to enhance the diversity of the population, and avoid the phenomenon of “premature.”


### 2.4. Improved Genetic Algorithm

#### 2.4.1. Improve the Background Proposed by Genetic Algorithm

The routing protocol or any algorithm in the wireless sensor network should be based on energy conservation. The cognitive radio and the wireless sensor network are combined to make the spectrum resources be used in a rational and balanced manner. The wireless sensor network can transmit data more smoothly. However, this combination also invisibly adds to the WSNS, the burden of nodes detecting spectrum holes and increasing traffic. At the same time, in the process of dynamic spectrum allocation, the nodes continuously switch the frequency to gain greater bandwidth gain, which makes the energy consumption problem more serious. In terms of reducing energy consumption, domestic and foreign experts and scholars have done research on reducing the number of transmission nodes and node dormancy and reducing the number of secondary user perceptions and achieved certain results. In terms of dynamic spectrum allocation, many domestic and foreign research scholars have carried out research and proposed model algorithms such as game theory model, graph theory coloring model, and interference temperature model to allocate spectrum. Later, many scholars used the improved intelligent optimization algorithm to distribute. The intelligent optimization algorithm has the characteristics of simple and easy to use, multi-issue, and robust, among which quantum genetic algorithm, leapfrog algorithm, and immune cloning algorithm have achieved good results. As a mature search-based heuristic algorithm used in computational science to solve optimization problems, genetic algorithm also has a good performance in spectrum allocation. Because wireless sensor networks have limited energy characteristics and spectrum switching will bring about data packet collision, data transmission failure retransmission, redetection of spectrum holes and spectrum allocation, the algorithm proposed in this paper is aimed at maximizing network benefits and minimizing the frequency of spectrum switching to ensure that the entire network consumes the least amount of energy in spectrum allocation. The improved genetic algorithm has improved in coding, crossover, mutation, and fitness function. The simulation results show that the algorithm improves the network revenue, reduces the energy consumption caused by the spectrum switching process, and avoids the genetic algorithm convergence too fast.


#### 2.4.2. Algorithm Theory Model

Solving problems in the field of computing often comes down to a model that uses models to describe specific problems. The establishment of the theoretical model requires specific analysis of specific problems. The models used in different problems are different, and the problems applied by different models are different. There is no fixed match between the two. The model chosen is not good or bad, only suitable and inappropriate; there is no universal model for all problems. When using the search optimization algorithm to solve the dynamic spectrum allocation problem, based on the existing model, the optimal solution obtained by the optimization algorithm is replaced by the optimization algorithm, which is the allocation scheme for the spectrum allocation. For the centralized spectrum allocation method, the graph theory coloring model or the interference temperature model is adopted, and the graph theory coloring model itself has the advantage of avoiding mutual interference between cells. The dynamic spectrum allocation problem channel assignment model is mathematically described, then the objective function is formulated according to the actual network conditions, and the genetic algorithm is used to find the optimal solution under the objective function.


#### 2.4.3. Encoding

Coding is the first step of the genetic algorithm. It is the bridge between the genetic algorithm and the problem to be solved. It has a decisive influence on the performance of the algorithm. If the coding method is not properly selected, the algorithm search space will be greatly increased, and the coding will be increased. And the amount of computation of the decoding process would take up too much memory. The purpose of the encoding process is to construct the chromosome according to certain rules and follow the process in the genetic algorithm with the chromosome as the basic unit. When the algorithm initializes the network environment, the primary user and the secondary user position are randomly determined. The algorithm obtains the benefit matrixB, the available channel matrix L, and the interference constraint matrix C in the graph theory coloring model according to the location information of the two. The operation of the genetic algorithm is based on chromosomes. If the chromosomes are represented by S and each chromosome S represents a conflict-free and feasible spectrum allocation scheme, then the chromosome S should correspond to the element an,m in the distribution matrix A=an,man,m∈0,1N×M. This coding method will generate a lot of redundant bits in the chromosome S, which makes the algorithm search space increase, and it is more difficult to find the optimal solution and reduce the performance of the algorithm. At the position where the available channel matrix L is 0, the channel is definitely not allocated to the user, so the allocation matrix is A definitely 0 at the corresponding position. Since there is such a relationship between the available channel matrix L and the distribution matrix A, we can only use the chromosome S to record the allocation matrix elements at the position where the available channel L element is 1. The chromosome S length LS obtained after such mapping is shown in formula (3), which is the number of nonzero elements in the available channel matrix L.
(9)LS=∑ln,m−1ln,m,(10)L=101001000110010001000100100000,(11)S=011011010A=001001000010010000000100000000.The mapping relationship between the chromosomeS and the available channel matrix L and the distribution matrix A is as shown in Figure 5, and the elements of the distribution matrix corresponding to the nonzero position in the available channel matrix A are recorded in the chromosome S. Since the available channel matrix L for each allocation process is unchanged and the location of the nonzero elements in the channel matrix L is determined, the chromosomes do not change the number of bits due to the different allocation scheme. It should also be noted that the interference constraint matrix C=cn,k,mcn,k,m∈0,1N×N×M specifies that when the user cn,k,m=1 and the user n jointly use the channel k when m, interference may occur. If an,m=ak,m is satisfied in the allocation matrix A, an,m or ak,m need to be randomly set to zero. That is, the channel m is not allowed to be simultaneously allocated to user n and user k, and only one of the users can be assigned to channel m. At this time, the corresponding position in the chromosome S should also be set to zero.Figure 5
Mapping process of chromosomes.


#### 2.4.4. Cross and Variation

Crossover and mutation operations are the core of the whole genetic algorithm. Since both crossover and mutation are random operations, there may be disadvantages to the performance of the convergence efficiency of the algorithm. Crossoperation is a kind of local optimization process. It is suitable for individuals with higher fitness in the early stage of evolution. When the population is large, the mutation operation can optimize the problem globally. It is suitable for the late evolution and the population fitness value is universal. It is too high, and the difference between individuals is very small, which is close to the optimal solution. At this time, the cross process can no longer produce better individuals, so the mutation process is needed to produce individuals closer to the optimal solution. The crossover probability and the mutation probability are fixed constants in the traditional genetic algorithm and are independent of each other. Their size needs to be determined empirically. The crossover probability ranges from 0.40 to 0.99, and the variation probability is a constant between 0.0001 and 0.1. Fixed crossover probability and mutation probability often reduce the convergence rate of the algorithm, causing the algorithm to “prematurely mature” and reduce the efficiency of the algorithm to find the optimal solution. This section adds adaptive crossover probability and mutation probability to the traditional genetic algorithm so that the crossover probability and mutation probability can be adjusted in real time according to the chromosome being operated. Appropriately increasing the crossover probability and reducing the mutation probability in the early stage of evolution can shorten the process of finding the optimal solution by using the cross process and reduce the calculation amount. In the later stage of evolution, it is suitable to reduce the calculation amount of the cross operation, and the crossover probability should be reduced to increase the mutation probability. It can avoid the algorithm falling into local optimum, prevent the genetic algorithm from converge too fast, and speed up the search for the global optimal solution. We assume that the crossover probability and the mutation probability are represented bypc and pm, respectively. The adaptive mathematical expressions for pc and pm are
(12)pc=pc1∗pc1−pc2f−favgfmax−favgf≥favg,pc1f<favg,(13)pm=pm1∗pm1−pm2fmax−f′fmax−favgf′≥favg,pm1f′<favg.In equations (6) and (7), fmax is the maximum value of the fitness value in the current population, favg is the average value of the fitness values in the current population, and f is the larger fitness value of the two individuals to be crossed. f′ is the fitness value of the individual to be mutated; pc1, pc2, pm1, and pm2 are constants. The individual’s crossover probability and mutation probability are linearly transformed between the average fitness and the maximum fitness value according to the individual’s fitness value. In order to ensure that the superior individuals of each generation do not participate in the crossvariation process, the genetic algorithm proposed in this paper adopts adaptive crossover probability and mutation probability. If the optimal individual fitness value of the current population is better than the optimal individual fitness value of the next generation population, then all the individuals whose fitness value is greater than the optimal fitness value of the next generation are directly replaced by the individuals whose fitness value is the worst in the next generation. When the individual’s fitness value is greater than the group average fitness value, the individual’s crossover probability and mutation probability will be reduced so that the solution can be protected into the next generation; when the individual fitness value is less than the group average fitness value, both take larger values, making the solution easier to eliminate, ensuring population diversity and avoiding “premature” phenomena.


#### 2.4.5. Fitness Function

In genetic algorithms, the pros and cons of an individual are represented by the size of the fitness value. The fitness value has a certain mapping relationship with the objective function in the actual problem. In some problems, the objective function can be directly used as the fitness function, but the fitness function must be nonnegative and continuous and needs to consider the complexity of the overall algorithm, convergence time, etc., and then, the target function needs to be processed accordingly to achieve adaptation, meeting the requirements of fitness function. The fitness function of the improved genetic algorithm proposed in this paper is determined by the special conditions of wireless sensor network energy limitation. In the wireless sensor network, the sensor as a network node has the characteristics of difficulty in replacing the battery and limited energy. In addition, the cognitive radio technology is added to the wireless sensor network, and the node needs to constantly perceive the spectrum hole to maintain the network system. The revenue frequently switches the spectrum, and the switching spectrum is bound to bring problems such as packet transmission failure and retransmission. These additional functions greatly increase the node energy consumption. The node energy imbalance is easy to cause the node to fail. After the node fails, it needs to be restarted. Building a network topology and reallocating the spectrum put a heavier burden on the nodes. From this point of view, it is necessary to reduce the overall spectrum switching frequency for the network, so the minimum spectrum switching frequency is added to the objective function. The current spectrum allocation strategy makes the spectrum utilization low, and the generation of cognitive radio technology solves this problem. In order to avoid the imbalance of spectrum allocation, the network function is maximized in the objective function. In a conflict-free allocation case, the usern return is rn, and the network system revenue is represented by U, and its size is related to the distribution matrix and the benefit matrix. The mathematical expression is shown in equation (8).
(14)U=∑n−1Nrn=∑n−1N∑m−1Man,m⋅bn,m.Assuming that the spectrum allocation scheme before the spectrum allocation is the initial allocation matrixA1, the switching frequency is determined by the current allocation matrix A and the initial allocation matrix A1, and him is used to indicate the frequency switching frequency of the node i on the spectrum m, and then, him mathematical expression is shown in (9).
(15)him=1−a1i,m⋅bn,m,i∈N,m∈M.Then, the mathematical expression of the frequency switching frequencyH of the overall spectrum allocation system of the WSNS is shown in equation (10).
(16)H=∑iN∑m−0Mhim,i∈N,m∈M.For each spectrum allocation, the larger theH value, the more users need to switch the frequency compared with the original allocation scheme, and the smaller the H value, the smaller the number of users who need to switch frequency, the more in line with the principle of low switching frequency. If the objective function itself meets the requirements of the fitness function, it can be directly used as the fitness function. The objective function is represented by Obj_F. The mathematical expression of Obj_F is as shown in formula (11). The larger the network gain, the larger the objective function close to the demand; because the switching frequency takes the minimum value, it should be negative to ensure that the fitness value is larger, and the chromosome is closer to the optimal solution to be searched.
(17)Obj_F=U−H=∑n−1N∑m−1Man,m⋅bn,m−∑iN−1∑m−0M−1him.Shown in Figure6 is a flowchart to improve the hybrid algorithm of genetic algorithm and recurrent neural network.Figure 6
Hybrid algorithm of improved genetic algorithm and recurrent neural network.


## 2.1. Overview of Dynamic Spectrum Allocation

Dynamic spectrum allocation is a method of saving spectrum. The system assigns an idle channel to the mobile station in real time according to the call application of the mobile station. After the users are used, they will be redistributed by the system recycling channel.


### 2.1.1. Wireless Sensor Network

Wireless sensor network (WSN) is a distributed sensor network, whose end is a sensor that can sense and check the outside world. Sensors in WSN communicate wirelessly, so the network settings are flexible, the location of devices can be changed at any time, and they can also be connected with the Internet in wired or wireless way. A multihop ad hoc network is formed by wireless communication. As a key field of Internet of Things applications, the task of wireless sensor network is to cooperate among nodes to sense and collect data. Its architecture is generally composed of three parts: cognitive node, sink node, and user management center. Its structure is shown in Figure1.Figure 1
Wireless sensor network structure.The transmission of wireless sensor networks is based on the spectrum resources in the network. However, in the process of the development of wireless communication technology, the limited spectrum resources are used by various wireless communication methods, and the problem of resource shortage is becoming more and more serious. In order to improve the utilization of spectrum resources and solve the problem of unbalanced spectrum utilization, various dynamic spectrum allocation methods are proposed.


### 2.1.2. The Concept of Dynamic Spectrum Allocation

There are two types of basic users in cognitive radio networks, authorized users and unauthorized users, which are also called primary user (PU) and secondary users (SU), respectively. At present, the fixed spectrum allocation policy is to allocate the licensed spectrum to the main users, so they have the absolute priority to use the licensed spectrum. Secondary users have the ability to detect spectrum holes in real time (spectrum holes are frequency bands not occupied by PU in the spectrum domain), that is, when the authorized spectrum is idle at a certain moment and not occupied by the primary users, secondary users can access this spectrum and then use this spectrum for data transmission.Dynamic spectrum allocation technology is a cognitive radio-based spectrum switching technology. The two most important features of cognitive radio systems are the spectrum sensing and spectrum reconfiguration of the physical layer. The dynamic spectrum allocation technology can detect which channel frequency band is idle in the current state and record and share all the busy and idle states. In each cycle, the system parameters are adjusted in real time, and when there is a free frequency band, assign authorized users in a timely manner. When spectrum allocation is performed on cognitive users, it is necessary to dynamically detect whether there is a free spectrum or whether the authorized user is in a free time state. The spectrum allocation is based on the above-mentioned allocation method, and the frequency band resources are dynamically utilized to maximize the utilization of the spectrum and the transmission rate. The cognitive radio theory topology is shown in Figure2.Figure 2
Cognitive radio theory topology.As can be seen from Figure2, cognitive radio theory in other words is to use the spectrum for secondary utilization, that is, in the case where the spectrum resources are scarce, and the cognitive user and the authorized user need to occupy the channel information at the same time, the authorization is realized. Users and cognitive users can share spectrum resources fairly and efficiently with each other, maximizing the occupation of spectrum information and reducing waste of spectrum resources. Dynamic spectrum allocation follows the principle of authorized users, and the cognitive user is supplemented by the dynamic and flexible allocation of spectrum. In the cognitive wireless sensor network system, the bandwidth, user location, and number of channels are not fixed. Dynamic spectrum allocation can adaptively adjust the spectrum allocation strategy according to user requirements or the system’s own indicators, thereby improving system flexibility and avoiding waste of spectrum holes, so dynamic spectrum allocation has a great advantage over the static spectrum allocation method in solving the problem of spectrum resource sharing. According to the network structure, spectrum allocation is divided into centralized and distributed. The centralized allocation method collects spectrum resources by a dedicated network coordinator and establishes a schedule, broadcasts to the secondary users, and performs spectrum allocation according to the wireless environment monitoring information uploaded by the secondary users, and the cognitive users assigned to the spectrum start to transmit data. The centralized allocation method can take into account the different needs of different users. The network coordinator is responsible for coordinating the spectrum configuration of each user to avoid mutual interference. The information exchange causes a large amount of scheduling overhead and energy consumption. When the network scale is large, the disadvantage is as follows. Once the network coordinator fails or is damaged, the entire network will be partially or even completely paralyzed. Distributed requires each sensor node to have the ability to perceive global or local spatially available spectrum and compete for spectrum allocation based on monitoring information between local and neighbors. It is suitable for nonfixed networks with low complexity, but distributed allocation due to each node participates in the allocation and is more susceptible to wireless environments such as channel fading.


### 2.1.3. Dynamic Spectrum Allocation Model

The current models for dynamic spectrum allocation mainly include interference temperature, auction bidding, graph theory coloring, and game theory. The game theory model and the auction bidding model are mainly used in the distributed spectrum allocation model, while the graph theory coloring model and the interference temperature model are mostly used in centralized spectrum allocation. The four spectrum allocation models are briefly described below.(1) Interference Temperature Model. The interference temperature model is an underlay spectrum access method, which means that the power of the receiver is reduced to the extent that the primary user can withstand by adjusting the power of the transmitter, as long as the transmission power of the secondary user does not exceed that set by the primary user. Interfering with temperature, you can coexist with authorized users, wherein the interference temperature is quantized as the ratio of the interference power to the bandwidth, and the representation method is
(1)TIfc,B=PIfc,BkB.In formula (1), TI is the interference temperature, PIfc,B is the average noise power (unit W) of the receiving device with fc as the center frequency, B is the bandwidth, k is the Boltzmann constant, and 1.38∗10−23J/C∘ is received by the main user. The sum of the temperature corresponding to the transmission power of the secondary user and the interference temperature TI is less than the threshold TL, that is, according to
(2)TI+PSLkB≤TL.This means that the secondary user can use the same frequency within the same communication range as the primary user without affecting the primary user.(2) Auction Bidding Model. The auction bidding model performs spectrum allocation based on the bidding idea of the most profitable person in economics. The auction bidding model is usually applied to the centralized spectrum allocation. Each secondary user passes its own network revenue to the BS, and there is no information transmission between the secondary users. Therefore, the centralized allocation method can reduce the overhead and be closer to the principle of wireless sensor network energy saving. When using the auction bidding model for spectrum allocation, the auctioneers in the auction are usually simulated by the base station or the fusion center, and each cognitive node is a bidder. For each auction, the cognitive node will price and bid on the demand for spectrum resources, and the auctioneer will determine the spectrum allocation scheme for the purpose of maximizing network revenue. In the auction bidding model, the network can formulate rules according to its own needs, such as maximum throughput, time fairness, and fairness of opportunity. The bidder obtains the relevant spectrum allocation scheme according to the rules.(3) Graph Theory Coloring Model. Graph theory is a mathematical model function in discrete mathematics. First, the specific practical problems are abstracted into graphs, and the constructed graphs are discussed and studied. Shading a graph means that all the vertices of the graph are colored, but adjacent nodes must use different colors and then the minimum number of colors to use. This is the research background of the graph theory coloring model. Figure 3 is a schematic diagram of a graphing coloring model. In the figure, the A area is adjacent to the B area and the C area, and the B area is adjacent to the D area so that the colors of the three areas A, B, and C are different, and the color of the B area and the D area are also different, which can satisfy the requirements of different colors of adjacent areas in the graph coloring. In a distributed network, the graph theory coloring model maps the network distribution of authorized cognitive radios to cognitive users, as shown in Figure 3.Figure 3
Graph coloring model.As can be seen from Figure3, the topology diagram shown in Figure 2 shows the network structure in which the primary and secondary users coexist in cognitive radio. If two network common channels A, B, and C are assumed, we use the aggregate symbol channel−A,B,C to represent the user. The symbol of -IV is used to indicate, and the authorized users occupy channels A, B, C, and C, respectively. The range within the circle indicates that the authorized users cannot share the same channel, and the spectrum occupancy of the cognitive user cannot affect the normal spectrum usage of the authorized user. For example, in the topology diagram, if the channel occupied by the authorized user IV is channel C, the cognitive user cannot use channel C within the coverage of the authorized user IV, so the available channel set is channel5−A,B; other cognitive users and authorized users should also follow such rules. The line in Figure 2 indicates that there is interference at two points of the line segment, that is, if the two vertices in the figure are connected by a common line, it means that the two lines share the same frequency band. At the same time, each vertex exists in a set, which represents the spectrum resources that can be used in the area, because the spectrum usage information of the authorized users changes in real time. As the network environment changes, each node in the network topology updates the network topology information in the database in each cycle of the system through interaction and exchange of information.


## 2.1.1. Wireless Sensor Network

Wireless sensor network (WSN) is a distributed sensor network, whose end is a sensor that can sense and check the outside world. Sensors in WSN communicate wirelessly, so the network settings are flexible, the location of devices can be changed at any time, and they can also be connected with the Internet in wired or wireless way. A multihop ad hoc network is formed by wireless communication. As a key field of Internet of Things applications, the task of wireless sensor network is to cooperate among nodes to sense and collect data. Its architecture is generally composed of three parts: cognitive node, sink node, and user management center. Its structure is shown in Figure1.Figure 1
Wireless sensor network structure.The transmission of wireless sensor networks is based on the spectrum resources in the network. However, in the process of the development of wireless communication technology, the limited spectrum resources are used by various wireless communication methods, and the problem of resource shortage is becoming more and more serious. In order to improve the utilization of spectrum resources and solve the problem of unbalanced spectrum utilization, various dynamic spectrum allocation methods are proposed.


## 2.1.2. The Concept of Dynamic Spectrum Allocation

There are two types of basic users in cognitive radio networks, authorized users and unauthorized users, which are also called primary user (PU) and secondary users (SU), respectively. At present, the fixed spectrum allocation policy is to allocate the licensed spectrum to the main users, so they have the absolute priority to use the licensed spectrum. Secondary users have the ability to detect spectrum holes in real time (spectrum holes are frequency bands not occupied by PU in the spectrum domain), that is, when the authorized spectrum is idle at a certain moment and not occupied by the primary users, secondary users can access this spectrum and then use this spectrum for data transmission.Dynamic spectrum allocation technology is a cognitive radio-based spectrum switching technology. The two most important features of cognitive radio systems are the spectrum sensing and spectrum reconfiguration of the physical layer. The dynamic spectrum allocation technology can detect which channel frequency band is idle in the current state and record and share all the busy and idle states. In each cycle, the system parameters are adjusted in real time, and when there is a free frequency band, assign authorized users in a timely manner. When spectrum allocation is performed on cognitive users, it is necessary to dynamically detect whether there is a free spectrum or whether the authorized user is in a free time state. The spectrum allocation is based on the above-mentioned allocation method, and the frequency band resources are dynamically utilized to maximize the utilization of the spectrum and the transmission rate. The cognitive radio theory topology is shown in Figure2.Figure 2
Cognitive radio theory topology.As can be seen from Figure2, cognitive radio theory in other words is to use the spectrum for secondary utilization, that is, in the case where the spectrum resources are scarce, and the cognitive user and the authorized user need to occupy the channel information at the same time, the authorization is realized. Users and cognitive users can share spectrum resources fairly and efficiently with each other, maximizing the occupation of spectrum information and reducing waste of spectrum resources. Dynamic spectrum allocation follows the principle of authorized users, and the cognitive user is supplemented by the dynamic and flexible allocation of spectrum. In the cognitive wireless sensor network system, the bandwidth, user location, and number of channels are not fixed. Dynamic spectrum allocation can adaptively adjust the spectrum allocation strategy according to user requirements or the system’s own indicators, thereby improving system flexibility and avoiding waste of spectrum holes, so dynamic spectrum allocation has a great advantage over the static spectrum allocation method in solving the problem of spectrum resource sharing. According to the network structure, spectrum allocation is divided into centralized and distributed. The centralized allocation method collects spectrum resources by a dedicated network coordinator and establishes a schedule, broadcasts to the secondary users, and performs spectrum allocation according to the wireless environment monitoring information uploaded by the secondary users, and the cognitive users assigned to the spectrum start to transmit data. The centralized allocation method can take into account the different needs of different users. The network coordinator is responsible for coordinating the spectrum configuration of each user to avoid mutual interference. The information exchange causes a large amount of scheduling overhead and energy consumption. When the network scale is large, the disadvantage is as follows. Once the network coordinator fails or is damaged, the entire network will be partially or even completely paralyzed. Distributed requires each sensor node to have the ability to perceive global or local spatially available spectrum and compete for spectrum allocation based on monitoring information between local and neighbors. It is suitable for nonfixed networks with low complexity, but distributed allocation due to each node participates in the allocation and is more susceptible to wireless environments such as channel fading.


## 2.1.3. Dynamic Spectrum Allocation Model

The current models for dynamic spectrum allocation mainly include interference temperature, auction bidding, graph theory coloring, and game theory. The game theory model and the auction bidding model are mainly used in the distributed spectrum allocation model, while the graph theory coloring model and the interference temperature model are mostly used in centralized spectrum allocation. The four spectrum allocation models are briefly described below.(1) Interference Temperature Model. The interference temperature model is an underlay spectrum access method, which means that the power of the receiver is reduced to the extent that the primary user can withstand by adjusting the power of the transmitter, as long as the transmission power of the secondary user does not exceed that set by the primary user. Interfering with temperature, you can coexist with authorized users, wherein the interference temperature is quantized as the ratio of the interference power to the bandwidth, and the representation method is
(1)TIfc,B=PIfc,BkB.In formula (1), TI is the interference temperature, PIfc,B is the average noise power (unit W) of the receiving device with fc as the center frequency, B is the bandwidth, k is the Boltzmann constant, and 1.38∗10−23J/C∘ is received by the main user. The sum of the temperature corresponding to the transmission power of the secondary user and the interference temperature TI is less than the threshold TL, that is, according to
(2)TI+PSLkB≤TL.This means that the secondary user can use the same frequency within the same communication range as the primary user without affecting the primary user.(2) Auction Bidding Model. The auction bidding model performs spectrum allocation based on the bidding idea of the most profitable person in economics. The auction bidding model is usually applied to the centralized spectrum allocation. Each secondary user passes its own network revenue to the BS, and there is no information transmission between the secondary users. Therefore, the centralized allocation method can reduce the overhead and be closer to the principle of wireless sensor network energy saving. When using the auction bidding model for spectrum allocation, the auctioneers in the auction are usually simulated by the base station or the fusion center, and each cognitive node is a bidder. For each auction, the cognitive node will price and bid on the demand for spectrum resources, and the auctioneer will determine the spectrum allocation scheme for the purpose of maximizing network revenue. In the auction bidding model, the network can formulate rules according to its own needs, such as maximum throughput, time fairness, and fairness of opportunity. The bidder obtains the relevant spectrum allocation scheme according to the rules.(3) Graph Theory Coloring Model. Graph theory is a mathematical model function in discrete mathematics. First, the specific practical problems are abstracted into graphs, and the constructed graphs are discussed and studied. Shading a graph means that all the vertices of the graph are colored, but adjacent nodes must use different colors and then the minimum number of colors to use. This is the research background of the graph theory coloring model. Figure 3 is a schematic diagram of a graphing coloring model. In the figure, the A area is adjacent to the B area and the C area, and the B area is adjacent to the D area so that the colors of the three areas A, B, and C are different, and the color of the B area and the D area are also different, which can satisfy the requirements of different colors of adjacent areas in the graph coloring. In a distributed network, the graph theory coloring model maps the network distribution of authorized cognitive radios to cognitive users, as shown in Figure 3.Figure 3
Graph coloring model.As can be seen from Figure3, the topology diagram shown in Figure 2 shows the network structure in which the primary and secondary users coexist in cognitive radio. If two network common channels A, B, and C are assumed, we use the aggregate symbol channel−A,B,C to represent the user. The symbol of -IV is used to indicate, and the authorized users occupy channels A, B, C, and C, respectively. The range within the circle indicates that the authorized users cannot share the same channel, and the spectrum occupancy of the cognitive user cannot affect the normal spectrum usage of the authorized user. For example, in the topology diagram, if the channel occupied by the authorized user IV is channel C, the cognitive user cannot use channel C within the coverage of the authorized user IV, so the available channel set is channel5−A,B; other cognitive users and authorized users should also follow such rules. The line in Figure 2 indicates that there is interference at two points of the line segment, that is, if the two vertices in the figure are connected by a common line, it means that the two lines share the same frequency band. At the same time, each vertex exists in a set, which represents the spectrum resources that can be used in the area, because the spectrum usage information of the authorized users changes in real time. As the network environment changes, each node in the network topology updates the network topology information in the database in each cycle of the system through interaction and exchange of information.


## 2.2. Dynamic Spectrum Allocation Algorithm Based on Cyclic Neural Network

The main problems caused by channel allocation in available spectrum space are adjacent channel interference and cochannel interference. For adjacent channel interference, nonoverlapping channels can be used to eliminate it. For cochannel interference, it is necessary to carry out optimal channel allocation in cognitive wireless networks to avoid conflicts caused by selecting the same channel. Aiming at the joint problem of dynamic power control and channel allocation, in order to overcome the large amount of computation caused by the large space state and partial observability of complex problems, a joint algorithm of dynamic power control and channel allocation based on cyclic neural network is proposed. So that the secondary users can successfully access the channel, make the best use of the optimal power control strategy, avoid harmful interference to the primary users, and improve the overall performance of cognitive wireless networks and the utilization of spectrum resources.


### 2.2.1. Long- and Short-Term Memory Cycle Neural Network

Long-term and short-term memory is a special cyclic neural network, which mainly includes forgetting stage, selective memory stage, and output stage. It is realized through forgetting gate, input gate, and output gate, respectively. The core of long-term and short-term memory is to control the unit state through three interactive gating states, remember the information that needs to be remembered for a long time, and forget the unimportant information. Therefore, it shows excellent performance in solving the problems of gradient disappearance and gradient explosion in the process of long sequence training.(1) Forgetting Stage. The first stage of long-term and short-term memory is the forgetting stage, which is mainly to selectively forget the input transmitted from the previous node, which is determined by the sigmoid activation function of the forgetting gate, as shown in the following formula.
(3)f=σWfnht−1,xt+bf.(2) Selective Memory Stage. It is mainly to memorize and select the input value and determine the new information that should be stored in the unit state. Firstly, the sigmoid function layer determines the updated value, and then, the tanh function layer creates the candidate value vector C~ to help adjust the neural network and then creates the state combined with the updated value and the candidate value, as shown in the following formula.
(4)it=σWinht−1,xt+bi,(5)C~=tanhWCnht−1,xt+bC.(3) Output Phase. In this stage, the results of forgetting stage and selective memory stage are summed, and the output value is obtained by sigmoid function and tanh function, as shown in the following formula. The new cell state and the new hidden state are then transferred to the next step.
(6)C=ft∗Ct−1+it∗C~,(7)ot=σWonht−1,xt+bo,(8)ht=ot∗tanhC.


### 2.2.2. Algorithm Flow

We consider using long-term and short-term memory combined with deepQ network to integrate some known observation information collected and obtain the optimal control strategy through online learning and distributed methods. The unique network structure of long-term and short-term memory can better estimate the state of the channel and improve the probability of successful access to the channel, as shown in Figure 4.Figure 4
Structure of long-term and short-term memory depthQ network.


## 2.2.1. Long- and Short-Term Memory Cycle Neural Network

Long-term and short-term memory is a special cyclic neural network, which mainly includes forgetting stage, selective memory stage, and output stage. It is realized through forgetting gate, input gate, and output gate, respectively. The core of long-term and short-term memory is to control the unit state through three interactive gating states, remember the information that needs to be remembered for a long time, and forget the unimportant information. Therefore, it shows excellent performance in solving the problems of gradient disappearance and gradient explosion in the process of long sequence training.(1) Forgetting Stage. The first stage of long-term and short-term memory is the forgetting stage, which is mainly to selectively forget the input transmitted from the previous node, which is determined by the sigmoid activation function of the forgetting gate, as shown in the following formula.
(3)f=σWfnht−1,xt+bf.(2) Selective Memory Stage. It is mainly to memorize and select the input value and determine the new information that should be stored in the unit state. Firstly, the sigmoid function layer determines the updated value, and then, the tanh function layer creates the candidate value vector C~ to help adjust the neural network and then creates the state combined with the updated value and the candidate value, as shown in the following formula.
(4)it=σWinht−1,xt+bi,(5)C~=tanhWCnht−1,xt+bC.(3) Output Phase. In this stage, the results of forgetting stage and selective memory stage are summed, and the output value is obtained by sigmoid function and tanh function, as shown in the following formula. The new cell state and the new hidden state are then transferred to the next step.
(6)C=ft∗Ct−1+it∗C~,(7)ot=σWonht−1,xt+bo,(8)ht=ot∗tanhC.


## 2.2.2. Algorithm Flow

We consider using long-term and short-term memory combined with deepQ network to integrate some known observation information collected and obtain the optimal control strategy through online learning and distributed methods. The unique network structure of long-term and short-term memory can better estimate the state of the channel and improve the probability of successful access to the channel, as shown in Figure 4.Figure 4
Structure of long-term and short-term memory depthQ network.


## 2.3. Research on Dynamic Spectrum Allocation Algorithm Based on Genetic Algorithm

### 2.3.1. Characteristics and Processes of Traditional Genetic Algorithms

The genetic algorithm performs search calculation and problem-solving according to the law of natural selection. In recent years, through in-depth research by scholars at home and abroad, many problems that cannot be solved by traditional mathematics have been solved. The advantages of genetic algorithms are as follows:(1)
Searching in units of populations, multiple individuals simultaneously comparing with inherent parallelism(2)
The search ability size has nothing to do with the problem to be solved(3)
It has strong scalability and can be combined with other models and algorithms to optimize the performance of the algorithm(4)
The evaluation function mechanism is adopted in the search process to reduce the complexity(5)
Iteratively using the probability mechanism, the randomness is strongGenetic algorithm as a classical evolutionary algorithm also has its own drawbacks:(1)
The initial population has a great influence on the performance of the algorithm, which can be improved by adding some prior knowledge(2)
The three operations of selecting, crossing, and mutating in the algorithm involve multiple parameters, such as crossover probability and mutation probability. The difference of these parameters will affect the performance of the algorithm. In practical applications, multiple tests are needed to find the optimal parameters(3)
The genetic algorithm does not use the feedback information of the network in time, so it takes a lot of training to get an accurate solution, but this reduces the efficiency of the algorithm(4)
It is prone to “premature” phenomenon


### 2.3.2. Adaptive Genetic Algorithm

Adaptive genetic algorithm means that some parameters in the genetic algorithm can change with the evolution process, which increases the diversity of the algorithm population. The adaptive genetic algorithm is a derivative algorithm based on traditional genetic algorithm. It inherits the advantages of traditional genetic algorithm and abandons the shortcomings of traditional genetic algorithm so that the algorithm performs crossprobability and mutation probability in the process of implementing adaptive genetic algorithm. It will change with the increase of evolutionary algebra and the change of population fitness value, so it fills the inadequacies of traditional genetic algorithm to some extent. Adaptive genetic algorithm can be adaptive from various angles, such as fitness function, crossover probability, mutation probability, selection probability, and population size. The most commonly used are crossover probability and mutation probability. Generally, in the early stage of evolution, crossoperation can produce individuals with high fitness values. Therefore, increasing the probability of crossover and reducing the probability of mutation can speed up the optimization process. In the later stage of evolution, crossoperation cannot produce better individuals, and mutation operation is required for global optimization, so reduce the crossover probability, reduce the probability of mutation, reduce the amount of redundant operations, continue to enhance the diversity of the population, and avoid the phenomenon of “premature.”


## 2.3.1. Characteristics and Processes of Traditional Genetic Algorithms

The genetic algorithm performs search calculation and problem-solving according to the law of natural selection. In recent years, through in-depth research by scholars at home and abroad, many problems that cannot be solved by traditional mathematics have been solved. The advantages of genetic algorithms are as follows:(1)
Searching in units of populations, multiple individuals simultaneously comparing with inherent parallelism(2)
The search ability size has nothing to do with the problem to be solved(3)
It has strong scalability and can be combined with other models and algorithms to optimize the performance of the algorithm(4)
The evaluation function mechanism is adopted in the search process to reduce the complexity(5)
Iteratively using the probability mechanism, the randomness is strongGenetic algorithm as a classical evolutionary algorithm also has its own drawbacks:(1)
The initial population has a great influence on the performance of the algorithm, which can be improved by adding some prior knowledge(2)
The three operations of selecting, crossing, and mutating in the algorithm involve multiple parameters, such as crossover probability and mutation probability. The difference of these parameters will affect the performance of the algorithm. In practical applications, multiple tests are needed to find the optimal parameters(3)
The genetic algorithm does not use the feedback information of the network in time, so it takes a lot of training to get an accurate solution, but this reduces the efficiency of the algorithm(4)
It is prone to “premature” phenomenon


## 2.3.2. Adaptive Genetic Algorithm

Adaptive genetic algorithm means that some parameters in the genetic algorithm can change with the evolution process, which increases the diversity of the algorithm population. The adaptive genetic algorithm is a derivative algorithm based on traditional genetic algorithm. It inherits the advantages of traditional genetic algorithm and abandons the shortcomings of traditional genetic algorithm so that the algorithm performs crossprobability and mutation probability in the process of implementing adaptive genetic algorithm. It will change with the increase of evolutionary algebra and the change of population fitness value, so it fills the inadequacies of traditional genetic algorithm to some extent. Adaptive genetic algorithm can be adaptive from various angles, such as fitness function, crossover probability, mutation probability, selection probability, and population size. The most commonly used are crossover probability and mutation probability. Generally, in the early stage of evolution, crossoperation can produce individuals with high fitness values. Therefore, increasing the probability of crossover and reducing the probability of mutation can speed up the optimization process. In the later stage of evolution, crossoperation cannot produce better individuals, and mutation operation is required for global optimization, so reduce the crossover probability, reduce the probability of mutation, reduce the amount of redundant operations, continue to enhance the diversity of the population, and avoid the phenomenon of “premature.”


## 2.4. Improved Genetic Algorithm

### 2.4.1. Improve the Background Proposed by Genetic Algorithm

The routing protocol or any algorithm in the wireless sensor network should be based on energy conservation. The cognitive radio and the wireless sensor network are combined to make the spectrum resources be used in a rational and balanced manner. The wireless sensor network can transmit data more smoothly. However, this combination also invisibly adds to the WSNS, the burden of nodes detecting spectrum holes and increasing traffic. At the same time, in the process of dynamic spectrum allocation, the nodes continuously switch the frequency to gain greater bandwidth gain, which makes the energy consumption problem more serious. In terms of reducing energy consumption, domestic and foreign experts and scholars have done research on reducing the number of transmission nodes and node dormancy and reducing the number of secondary user perceptions and achieved certain results. In terms of dynamic spectrum allocation, many domestic and foreign research scholars have carried out research and proposed model algorithms such as game theory model, graph theory coloring model, and interference temperature model to allocate spectrum. Later, many scholars used the improved intelligent optimization algorithm to distribute. The intelligent optimization algorithm has the characteristics of simple and easy to use, multi-issue, and robust, among which quantum genetic algorithm, leapfrog algorithm, and immune cloning algorithm have achieved good results. As a mature search-based heuristic algorithm used in computational science to solve optimization problems, genetic algorithm also has a good performance in spectrum allocation. Because wireless sensor networks have limited energy characteristics and spectrum switching will bring about data packet collision, data transmission failure retransmission, redetection of spectrum holes and spectrum allocation, the algorithm proposed in this paper is aimed at maximizing network benefits and minimizing the frequency of spectrum switching to ensure that the entire network consumes the least amount of energy in spectrum allocation. The improved genetic algorithm has improved in coding, crossover, mutation, and fitness function. The simulation results show that the algorithm improves the network revenue, reduces the energy consumption caused by the spectrum switching process, and avoids the genetic algorithm convergence too fast.


### 2.4.2. Algorithm Theory Model

Solving problems in the field of computing often comes down to a model that uses models to describe specific problems. The establishment of the theoretical model requires specific analysis of specific problems. The models used in different problems are different, and the problems applied by different models are different. There is no fixed match between the two. The model chosen is not good or bad, only suitable and inappropriate; there is no universal model for all problems. When using the search optimization algorithm to solve the dynamic spectrum allocation problem, based on the existing model, the optimal solution obtained by the optimization algorithm is replaced by the optimization algorithm, which is the allocation scheme for the spectrum allocation. For the centralized spectrum allocation method, the graph theory coloring model or the interference temperature model is adopted, and the graph theory coloring model itself has the advantage of avoiding mutual interference between cells. The dynamic spectrum allocation problem channel assignment model is mathematically described, then the objective function is formulated according to the actual network conditions, and the genetic algorithm is used to find the optimal solution under the objective function.


### 2.4.3. Encoding

Coding is the first step of the genetic algorithm. It is the bridge between the genetic algorithm and the problem to be solved. It has a decisive influence on the performance of the algorithm. If the coding method is not properly selected, the algorithm search space will be greatly increased, and the coding will be increased. And the amount of computation of the decoding process would take up too much memory. The purpose of the encoding process is to construct the chromosome according to certain rules and follow the process in the genetic algorithm with the chromosome as the basic unit. When the algorithm initializes the network environment, the primary user and the secondary user position are randomly determined. The algorithm obtains the benefit matrixB, the available channel matrix L, and the interference constraint matrix C in the graph theory coloring model according to the location information of the two. The operation of the genetic algorithm is based on chromosomes. If the chromosomes are represented by S and each chromosome S represents a conflict-free and feasible spectrum allocation scheme, then the chromosome S should correspond to the element an,m in the distribution matrix A=an,man,m∈0,1N×M. This coding method will generate a lot of redundant bits in the chromosome S, which makes the algorithm search space increase, and it is more difficult to find the optimal solution and reduce the performance of the algorithm. At the position where the available channel matrix L is 0, the channel is definitely not allocated to the user, so the allocation matrix is A definitely 0 at the corresponding position. Since there is such a relationship between the available channel matrix L and the distribution matrix A, we can only use the chromosome S to record the allocation matrix elements at the position where the available channel L element is 1. The chromosome S length LS obtained after such mapping is shown in formula (3), which is the number of nonzero elements in the available channel matrix L.
(9)LS=∑ln,m−1ln,m,(10)L=101001000110010001000100100000,(11)S=011011010A=001001000010010000000100000000.The mapping relationship between the chromosomeS and the available channel matrix L and the distribution matrix A is as shown in Figure 5, and the elements of the distribution matrix corresponding to the nonzero position in the available channel matrix A are recorded in the chromosome S. Since the available channel matrix L for each allocation process is unchanged and the location of the nonzero elements in the channel matrix L is determined, the chromosomes do not change the number of bits due to the different allocation scheme. It should also be noted that the interference constraint matrix C=cn,k,mcn,k,m∈0,1N×N×M specifies that when the user cn,k,m=1 and the user n jointly use the channel k when m, interference may occur. If an,m=ak,m is satisfied in the allocation matrix A, an,m or ak,m need to be randomly set to zero. That is, the channel m is not allowed to be simultaneously allocated to user n and user k, and only one of the users can be assigned to channel m. At this time, the corresponding position in the chromosome S should also be set to zero.Figure 5
Mapping process of chromosomes.


### 2.4.4. Cross and Variation

Crossover and mutation operations are the core of the whole genetic algorithm. Since both crossover and mutation are random operations, there may be disadvantages to the performance of the convergence efficiency of the algorithm. Crossoperation is a kind of local optimization process. It is suitable for individuals with higher fitness in the early stage of evolution. When the population is large, the mutation operation can optimize the problem globally. It is suitable for the late evolution and the population fitness value is universal. It is too high, and the difference between individuals is very small, which is close to the optimal solution. At this time, the cross process can no longer produce better individuals, so the mutation process is needed to produce individuals closer to the optimal solution. The crossover probability and the mutation probability are fixed constants in the traditional genetic algorithm and are independent of each other. Their size needs to be determined empirically. The crossover probability ranges from 0.40 to 0.99, and the variation probability is a constant between 0.0001 and 0.1. Fixed crossover probability and mutation probability often reduce the convergence rate of the algorithm, causing the algorithm to “prematurely mature” and reduce the efficiency of the algorithm to find the optimal solution. This section adds adaptive crossover probability and mutation probability to the traditional genetic algorithm so that the crossover probability and mutation probability can be adjusted in real time according to the chromosome being operated. Appropriately increasing the crossover probability and reducing the mutation probability in the early stage of evolution can shorten the process of finding the optimal solution by using the cross process and reduce the calculation amount. In the later stage of evolution, it is suitable to reduce the calculation amount of the cross operation, and the crossover probability should be reduced to increase the mutation probability. It can avoid the algorithm falling into local optimum, prevent the genetic algorithm from converge too fast, and speed up the search for the global optimal solution. We assume that the crossover probability and the mutation probability are represented bypc and pm, respectively. The adaptive mathematical expressions for pc and pm are
(12)pc=pc1∗pc1−pc2f−favgfmax−favgf≥favg,pc1f<favg,(13)pm=pm1∗pm1−pm2fmax−f′fmax−favgf′≥favg,pm1f′<favg.In equations (6) and (7), fmax is the maximum value of the fitness value in the current population, favg is the average value of the fitness values in the current population, and f is the larger fitness value of the two individuals to be crossed. f′ is the fitness value of the individual to be mutated; pc1, pc2, pm1, and pm2 are constants. The individual’s crossover probability and mutation probability are linearly transformed between the average fitness and the maximum fitness value according to the individual’s fitness value. In order to ensure that the superior individuals of each generation do not participate in the crossvariation process, the genetic algorithm proposed in this paper adopts adaptive crossover probability and mutation probability. If the optimal individual fitness value of the current population is better than the optimal individual fitness value of the next generation population, then all the individuals whose fitness value is greater than the optimal fitness value of the next generation are directly replaced by the individuals whose fitness value is the worst in the next generation. When the individual’s fitness value is greater than the group average fitness value, the individual’s crossover probability and mutation probability will be reduced so that the solution can be protected into the next generation; when the individual fitness value is less than the group average fitness value, both take larger values, making the solution easier to eliminate, ensuring population diversity and avoiding “premature” phenomena.


### 2.4.5. Fitness Function

In genetic algorithms, the pros and cons of an individual are represented by the size of the fitness value. The fitness value has a certain mapping relationship with the objective function in the actual problem. In some problems, the objective function can be directly used as the fitness function, but the fitness function must be nonnegative and continuous and needs to consider the complexity of the overall algorithm, convergence time, etc., and then, the target function needs to be processed accordingly to achieve adaptation, meeting the requirements of fitness function. The fitness function of the improved genetic algorithm proposed in this paper is determined by the special conditions of wireless sensor network energy limitation. In the wireless sensor network, the sensor as a network node has the characteristics of difficulty in replacing the battery and limited energy. In addition, the cognitive radio technology is added to the wireless sensor network, and the node needs to constantly perceive the spectrum hole to maintain the network system. The revenue frequently switches the spectrum, and the switching spectrum is bound to bring problems such as packet transmission failure and retransmission. These additional functions greatly increase the node energy consumption. The node energy imbalance is easy to cause the node to fail. After the node fails, it needs to be restarted. Building a network topology and reallocating the spectrum put a heavier burden on the nodes. From this point of view, it is necessary to reduce the overall spectrum switching frequency for the network, so the minimum spectrum switching frequency is added to the objective function. The current spectrum allocation strategy makes the spectrum utilization low, and the generation of cognitive radio technology solves this problem. In order to avoid the imbalance of spectrum allocation, the network function is maximized in the objective function. In a conflict-free allocation case, the usern return is rn, and the network system revenue is represented by U, and its size is related to the distribution matrix and the benefit matrix. The mathematical expression is shown in equation (8).
(14)U=∑n−1Nrn=∑n−1N∑m−1Man,m⋅bn,m.Assuming that the spectrum allocation scheme before the spectrum allocation is the initial allocation matrixA1, the switching frequency is determined by the current allocation matrix A and the initial allocation matrix A1, and him is used to indicate the frequency switching frequency of the node i on the spectrum m, and then, him mathematical expression is shown in (9).
(15)him=1−a1i,m⋅bn,m,i∈N,m∈M.Then, the mathematical expression of the frequency switching frequencyH of the overall spectrum allocation system of the WSNS is shown in equation (10).
(16)H=∑iN∑m−0Mhim,i∈N,m∈M.For each spectrum allocation, the larger theH value, the more users need to switch the frequency compared with the original allocation scheme, and the smaller the H value, the smaller the number of users who need to switch frequency, the more in line with the principle of low switching frequency. If the objective function itself meets the requirements of the fitness function, it can be directly used as the fitness function. The objective function is represented by Obj_F. The mathematical expression of Obj_F is as shown in formula (11). The larger the network gain, the larger the objective function close to the demand; because the switching frequency takes the minimum value, it should be negative to ensure that the fitness value is larger, and the chromosome is closer to the optimal solution to be searched.
(17)Obj_F=U−H=∑n−1N∑m−1Man,m⋅bn,m−∑iN−1∑m−0M−1him.Shown in Figure6 is a flowchart to improve the hybrid algorithm of genetic algorithm and recurrent neural network.Figure 6
Hybrid algorithm of improved genetic algorithm and recurrent neural network.


## 2.4.1. Improve the Background Proposed by Genetic Algorithm

The routing protocol or any algorithm in the wireless sensor network should be based on energy conservation. The cognitive radio and the wireless sensor network are combined to make the spectrum resources be used in a rational and balanced manner. The wireless sensor network can transmit data more smoothly. However, this combination also invisibly adds to the WSNS, the burden of nodes detecting spectrum holes and increasing traffic. At the same time, in the process of dynamic spectrum allocation, the nodes continuously switch the frequency to gain greater bandwidth gain, which makes the energy consumption problem more serious. In terms of reducing energy consumption, domestic and foreign experts and scholars have done research on reducing the number of transmission nodes and node dormancy and reducing the number of secondary user perceptions and achieved certain results. In terms of dynamic spectrum allocation, many domestic and foreign research scholars have carried out research and proposed model algorithms such as game theory model, graph theory coloring model, and interference temperature model to allocate spectrum. Later, many scholars used the improved intelligent optimization algorithm to distribute. The intelligent optimization algorithm has the characteristics of simple and easy to use, multi-issue, and robust, among which quantum genetic algorithm, leapfrog algorithm, and immune cloning algorithm have achieved good results. As a mature search-based heuristic algorithm used in computational science to solve optimization problems, genetic algorithm also has a good performance in spectrum allocation. Because wireless sensor networks have limited energy characteristics and spectrum switching will bring about data packet collision, data transmission failure retransmission, redetection of spectrum holes and spectrum allocation, the algorithm proposed in this paper is aimed at maximizing network benefits and minimizing the frequency of spectrum switching to ensure that the entire network consumes the least amount of energy in spectrum allocation. The improved genetic algorithm has improved in coding, crossover, mutation, and fitness function. The simulation results show that the algorithm improves the network revenue, reduces the energy consumption caused by the spectrum switching process, and avoids the genetic algorithm convergence too fast.


## 2.4.2. Algorithm Theory Model

Solving problems in the field of computing often comes down to a model that uses models to describe specific problems. The establishment of the theoretical model requires specific analysis of specific problems. The models used in different problems are different, and the problems applied by different models are different. There is no fixed match between the two. The model chosen is not good or bad, only suitable and inappropriate; there is no universal model for all problems. When using the search optimization algorithm to solve the dynamic spectrum allocation problem, based on the existing model, the optimal solution obtained by the optimization algorithm is replaced by the optimization algorithm, which is the allocation scheme for the spectrum allocation. For the centralized spectrum allocation method, the graph theory coloring model or the interference temperature model is adopted, and the graph theory coloring model itself has the advantage of avoiding mutual interference between cells. The dynamic spectrum allocation problem channel assignment model is mathematically described, then the objective function is formulated according to the actual network conditions, and the genetic algorithm is used to find the optimal solution under the objective function.


## 2.4.3. Encoding

Coding is the first step of the genetic algorithm. It is the bridge between the genetic algorithm and the problem to be solved. It has a decisive influence on the performance of the algorithm. If the coding method is not properly selected, the algorithm search space will be greatly increased, and the coding will be increased. And the amount of computation of the decoding process would take up too much memory. The purpose of the encoding process is to construct the chromosome according to certain rules and follow the process in the genetic algorithm with the chromosome as the basic unit. When the algorithm initializes the network environment, the primary user and the secondary user position are randomly determined. The algorithm obtains the benefit matrixB, the available channel matrix L, and the interference constraint matrix C in the graph theory coloring model according to the location information of the two. The operation of the genetic algorithm is based on chromosomes. If the chromosomes are represented by S and each chromosome S represents a conflict-free and feasible spectrum allocation scheme, then the chromosome S should correspond to the element an,m in the distribution matrix A=an,man,m∈0,1N×M. This coding method will generate a lot of redundant bits in the chromosome S, which makes the algorithm search space increase, and it is more difficult to find the optimal solution and reduce the performance of the algorithm. At the position where the available channel matrix L is 0, the channel is definitely not allocated to the user, so the allocation matrix is A definitely 0 at the corresponding position. Since there is such a relationship between the available channel matrix L and the distribution matrix A, we can only use the chromosome S to record the allocation matrix elements at the position where the available channel L element is 1. The chromosome S length LS obtained after such mapping is shown in formula (3), which is the number of nonzero elements in the available channel matrix L.
(9)LS=∑ln,m−1ln,m,(10)L=101001000110010001000100100000,(11)S=011011010A=001001000010010000000100000000.The mapping relationship between the chromosomeS and the available channel matrix L and the distribution matrix A is as shown in Figure 5, and the elements of the distribution matrix corresponding to the nonzero position in the available channel matrix A are recorded in the chromosome S. Since the available channel matrix L for each allocation process is unchanged and the location of the nonzero elements in the channel matrix L is determined, the chromosomes do not change the number of bits due to the different allocation scheme. It should also be noted that the interference constraint matrix C=cn,k,mcn,k,m∈0,1N×N×M specifies that when the user cn,k,m=1 and the user n jointly use the channel k when m, interference may occur. If an,m=ak,m is satisfied in the allocation matrix A, an,m or ak,m need to be randomly set to zero. That is, the channel m is not allowed to be simultaneously allocated to user n and user k, and only one of the users can be assigned to channel m. At this time, the corresponding position in the chromosome S should also be set to zero.Figure 5
Mapping process of chromosomes.


## 2.4.4. Cross and Variation

Crossover and mutation operations are the core of the whole genetic algorithm. Since both crossover and mutation are random operations, there may be disadvantages to the performance of the convergence efficiency of the algorithm. Crossoperation is a kind of local optimization process. It is suitable for individuals with higher fitness in the early stage of evolution. When the population is large, the mutation operation can optimize the problem globally. It is suitable for the late evolution and the population fitness value is universal. It is too high, and the difference between individuals is very small, which is close to the optimal solution. At this time, the cross process can no longer produce better individuals, so the mutation process is needed to produce individuals closer to the optimal solution. The crossover probability and the mutation probability are fixed constants in the traditional genetic algorithm and are independent of each other. Their size needs to be determined empirically. The crossover probability ranges from 0.40 to 0.99, and the variation probability is a constant between 0.0001 and 0.1. Fixed crossover probability and mutation probability often reduce the convergence rate of the algorithm, causing the algorithm to “prematurely mature” and reduce the efficiency of the algorithm to find the optimal solution. This section adds adaptive crossover probability and mutation probability to the traditional genetic algorithm so that the crossover probability and mutation probability can be adjusted in real time according to the chromosome being operated. Appropriately increasing the crossover probability and reducing the mutation probability in the early stage of evolution can shorten the process of finding the optimal solution by using the cross process and reduce the calculation amount. In the later stage of evolution, it is suitable to reduce the calculation amount of the cross operation, and the crossover probability should be reduced to increase the mutation probability. It can avoid the algorithm falling into local optimum, prevent the genetic algorithm from converge too fast, and speed up the search for the global optimal solution. We assume that the crossover probability and the mutation probability are represented bypc and pm, respectively. The adaptive mathematical expressions for pc and pm are
(12)pc=pc1∗pc1−pc2f−favgfmax−favgf≥favg,pc1f<favg,(13)pm=pm1∗pm1−pm2fmax−f′fmax−favgf′≥favg,pm1f′<favg.In equations (6) and (7), fmax is the maximum value of the fitness value in the current population, favg is the average value of the fitness values in the current population, and f is the larger fitness value of the two individuals to be crossed. f′ is the fitness value of the individual to be mutated; pc1, pc2, pm1, and pm2 are constants. The individual’s crossover probability and mutation probability are linearly transformed between the average fitness and the maximum fitness value according to the individual’s fitness value. In order to ensure that the superior individuals of each generation do not participate in the crossvariation process, the genetic algorithm proposed in this paper adopts adaptive crossover probability and mutation probability. If the optimal individual fitness value of the current population is better than the optimal individual fitness value of the next generation population, then all the individuals whose fitness value is greater than the optimal fitness value of the next generation are directly replaced by the individuals whose fitness value is the worst in the next generation. When the individual’s fitness value is greater than the group average fitness value, the individual’s crossover probability and mutation probability will be reduced so that the solution can be protected into the next generation; when the individual fitness value is less than the group average fitness value, both take larger values, making the solution easier to eliminate, ensuring population diversity and avoiding “premature” phenomena.


## 2.4.5. Fitness Function

In genetic algorithms, the pros and cons of an individual are represented by the size of the fitness value. The fitness value has a certain mapping relationship with the objective function in the actual problem. In some problems, the objective function can be directly used as the fitness function, but the fitness function must be nonnegative and continuous and needs to consider the complexity of the overall algorithm, convergence time, etc., and then, the target function needs to be processed accordingly to achieve adaptation, meeting the requirements of fitness function. The fitness function of the improved genetic algorithm proposed in this paper is determined by the special conditions of wireless sensor network energy limitation. In the wireless sensor network, the sensor as a network node has the characteristics of difficulty in replacing the battery and limited energy. In addition, the cognitive radio technology is added to the wireless sensor network, and the node needs to constantly perceive the spectrum hole to maintain the network system. The revenue frequently switches the spectrum, and the switching spectrum is bound to bring problems such as packet transmission failure and retransmission. These additional functions greatly increase the node energy consumption. The node energy imbalance is easy to cause the node to fail. After the node fails, it needs to be restarted. Building a network topology and reallocating the spectrum put a heavier burden on the nodes. From this point of view, it is necessary to reduce the overall spectrum switching frequency for the network, so the minimum spectrum switching frequency is added to the objective function. The current spectrum allocation strategy makes the spectrum utilization low, and the generation of cognitive radio technology solves this problem. In order to avoid the imbalance of spectrum allocation, the network function is maximized in the objective function. In a conflict-free allocation case, the usern return is rn, and the network system revenue is represented by U, and its size is related to the distribution matrix and the benefit matrix. The mathematical expression is shown in equation (8).
(14)U=∑n−1Nrn=∑n−1N∑m−1Man,m⋅bn,m.Assuming that the spectrum allocation scheme before the spectrum allocation is the initial allocation matrixA1, the switching frequency is determined by the current allocation matrix A and the initial allocation matrix A1, and him is used to indicate the frequency switching frequency of the node i on the spectrum m, and then, him mathematical expression is shown in (9).
(15)him=1−a1i,m⋅bn,m,i∈N,m∈M.Then, the mathematical expression of the frequency switching frequencyH of the overall spectrum allocation system of the WSNS is shown in equation (10).
(16)H=∑iN∑m−0Mhim,i∈N,m∈M.For each spectrum allocation, the larger theH value, the more users need to switch the frequency compared with the original allocation scheme, and the smaller the H value, the smaller the number of users who need to switch frequency, the more in line with the principle of low switching frequency. If the objective function itself meets the requirements of the fitness function, it can be directly used as the fitness function. The objective function is represented by Obj_F. The mathematical expression of Obj_F is as shown in formula (11). The larger the network gain, the larger the objective function close to the demand; because the switching frequency takes the minimum value, it should be negative to ensure that the fitness value is larger, and the chromosome is closer to the optimal solution to be searched.
(17)Obj_F=U−H=∑n−1N∑m−1Man,m⋅bn,m−∑iN−1∑m−0M−1him.Shown in Figure6 is a flowchart to improve the hybrid algorithm of genetic algorithm and recurrent neural network.Figure 6
Hybrid algorithm of improved genetic algorithm and recurrent neural network.


## 3. Experiments

### 3.1. Experimental Methods

The improved genetic algorithm is simulated on the MATLAB platform to verify the performance of the algorithm. The experimental process mainly includes the deployment of the network environment, experimental parameter setting, simulation of the algorithm, obtaining relevant data, and finally analyzing the data to obtain conclusions. For parameter setting, refer to the parameters recognized by many people in previous studies.


### 3.2. Experimental Environment and Parameters

In the experiment, a square network area of10m∗10m is constructed. In this network area, all interference factors such as noise are ignored. All users use the same transmit power, and the coverage radius and interference radius are the same. The node position of the wireless sensor network does not change substantially, ensuring that the network topology does not change during the primary spectrum allocation process. The benefit matrix B, the available matrix L, and the interference constraint matrix C in the graph theory coloring model do not change. In terms of network environment parameters, it is assumed that the primary and secondary user transmission distance is a minimum of 1 m, the maximum value is 4 m, and the primary user’s coverage radius is 2 m, that is, the primary user is the center, within 2 m radius, and the secondary user shall not use the same spectrum as the primary user to transmit data. In the experiments in this paper, in order to avoid the existence of accidental errors, the average of 40 experimental results was taken for each set of data. In addition to studying the effects of primary users, secondary users, and available channels on algorithm performance, other experiments were set to 15 primary users, 10 secondary users, and 10 available channels.


### 3.3. Improve the Overall Performance Simulation of Genetic Algorithm

The improved genetic algorithm will be compared with the color-sensitive coloring algorithm in the traditional genetic algorithm and graph theory coloring model in terms of switching frequency, network benefit, and fitness value. Color-sensitive graph theory coloring is an important branch of the graph theory shading model algorithm. It can set whether the relationships between users are coordinated and can also set six different labeling criteria as needed. Since the fitness value is only set in the genetic algorithm, the color-sensitive coloring algorithm only compares the network revenue and the switching frequency and does not involve the comparison of the fitness values. The fitness value is limited to the genetic algorithm for comparison.


## 3.1. Experimental Methods

The improved genetic algorithm is simulated on the MATLAB platform to verify the performance of the algorithm. The experimental process mainly includes the deployment of the network environment, experimental parameter setting, simulation of the algorithm, obtaining relevant data, and finally analyzing the data to obtain conclusions. For parameter setting, refer to the parameters recognized by many people in previous studies.


## 3.2. Experimental Environment and Parameters

In the experiment, a square network area of10m∗10m is constructed. In this network area, all interference factors such as noise are ignored. All users use the same transmit power, and the coverage radius and interference radius are the same. The node position of the wireless sensor network does not change substantially, ensuring that the network topology does not change during the primary spectrum allocation process. The benefit matrix B, the available matrix L, and the interference constraint matrix C in the graph theory coloring model do not change. In terms of network environment parameters, it is assumed that the primary and secondary user transmission distance is a minimum of 1 m, the maximum value is 4 m, and the primary user’s coverage radius is 2 m, that is, the primary user is the center, within 2 m radius, and the secondary user shall not use the same spectrum as the primary user to transmit data. In the experiments in this paper, in order to avoid the existence of accidental errors, the average of 40 experimental results was taken for each set of data. In addition to studying the effects of primary users, secondary users, and available channels on algorithm performance, other experiments were set to 15 primary users, 10 secondary users, and 10 available channels.


## 3.3. Improve the Overall Performance Simulation of Genetic Algorithm

The improved genetic algorithm will be compared with the color-sensitive coloring algorithm in the traditional genetic algorithm and graph theory coloring model in terms of switching frequency, network benefit, and fitness value. Color-sensitive graph theory coloring is an important branch of the graph theory shading model algorithm. It can set whether the relationships between users are coordinated and can also set six different labeling criteria as needed. Since the fitness value is only set in the genetic algorithm, the color-sensitive coloring algorithm only compares the network revenue and the switching frequency and does not involve the comparison of the fitness values. The fitness value is limited to the genetic algorithm for comparison.


## 4. Discussion

### 4.1. Overall Performance Simulation of Improved Genetic Algorithm

The comparison results of fitness values of two genetic algorithms in the same network environment are shown in Figure7.Figure 7
Comparison of fitness values of two genetic algorithms.The abscissa in the figure is the evolution algebra, and the ordinate is the fitness value. It can be seen from Figure7 that with the continuous increase of evolution algebra, the fitness value of the improved genetic algorithm is not much different from that of the traditional genetic algorithm before the 18th generation, but the whole process of the improved genetic algorithm is constantly searching for the optimal solution, while the optimization speed of the traditional genetic algorithm is relatively slow; there are only some changes around the 63rd and 148 generations. Compared with the traditional genetic algorithm, the performance of the improved genetic algorithm is improved. The traditional genetic algorithm is easy to fall into the local optimal, but cannot find the global optimal solution.


### 4.2. Influence of Genetic Algorithm Parameters on the Performance of Improved Genetic Algorithm

The improved genetic algorithm with two sets of crossover probability is compared with the traditional genetic algorithm, comparing its optimization ability, and the results are shown in Figure8. The abscissa is the evolutionary algebra, and the ordinate is the fitness value.Figure 8
Comparison of fitness values when pc1 and pc2 take different values.It can be seen from Figure5 that when pc1=0.9 and pc2=0.5, the fitness value is even lower than that of traditional genetic algorithm, while when pc1=0.6 and pc2=0.1, the fitness value is much higher than that of traditional genetic algorithm, the optimization ability of traditional genetic algorithm is relatively poor, and the optimal solution is not much different from the initial solution. Comprehensive comparison shows that when the crossprobability is 0.6 and 0.1, the fitness value is higher than that when the crossprobability is 0.9 and 0.5, while the traditional genetic algorithm is between them, so when the crossprobability is not selected, the performance of the improved genetic algorithm is not as good as that of the traditional genetic algorithm, but the optimization ability of the improved genetic algorithm of the two groups of crossprobability is worth affirming. Therefore, it can be seen that the network allocation efficiency has been significantly improved when the number of household users is different.


### 4.3. Influence of Network Environment Parameters on Performance of Improved Genetic Algorithm

#### 4.3.1. Influence of Network Environment Parameters on Switching Frequency

The change of switching frequency in the process of increasing the number of main households from 5 to 50 is shown in Figure8. In the figure, the abscissa is the main number of users, and the ordinate is the switching frequency.As can be seen from Figure9, with the increase of the number of main users, the switching frequency of CSGC algorithm shows an overall upward trend, while the switching frequency of the two genetic algorithms tends to decline after a short rise in 5-10 main users. The interference of authorized users in the network has little effect on the secondary users at first, but the number of primary users is increasing, but the available channels are not increasing, which leads to less and less channels that the secondary users can allocate. Genetic algorithm, considering that it wants to switch less frequency, wants to find a stable and assignable channel to allocate to the secondary users, and the switching frequency is also becoming smaller and smaller.Figure 9
Relationship between switching frequency and number of main households.


#### 4.3.2. The Influence of Network Environment Parameters on Network Revenue

The relationship between network revenue and the number of primary users is shown in Figure10. The abscissa is the number of users, and the ordinate is the network revenue.Figure 10
Relationship between network revenue and number of main users.As can be seen from Figure7, with the increase of the number of main users, the overall trend of network revenue of the three algorithms is declining. It can be seen from the descending slope that CSGC algorithm declines the fastest, while the two genetic algorithms are relatively slow. When the number of primary users is less than 10, the network income of CSGC algorithm is the highest; when the number of primary users is between 10 and 18, the network income from high to low is improved genetic algorithm, CSGC algorithm, and traditional genetic algorithm; when the number of primary users is greater than 18, the network income of improved genetic algorithm is the highest, followed by traditional genetic algorithm. The network income of CSGC algorithm is the least. It can be seen that the improved genetic algorithm can improve the network efficiency by about 2%, but the spectrum switching frequency can be reduced by 69%. When the number of main users in the network is large, the improved genetic algorithm has advantages over the other two algorithms. In the follow-up experiments, the calculation time of the algorithm is also compared, and the result is very similar to that of Figure 9, so I will not explain it too much.


## 4.1. Overall Performance Simulation of Improved Genetic Algorithm

The comparison results of fitness values of two genetic algorithms in the same network environment are shown in Figure7.Figure 7
Comparison of fitness values of two genetic algorithms.The abscissa in the figure is the evolution algebra, and the ordinate is the fitness value. It can be seen from Figure7 that with the continuous increase of evolution algebra, the fitness value of the improved genetic algorithm is not much different from that of the traditional genetic algorithm before the 18th generation, but the whole process of the improved genetic algorithm is constantly searching for the optimal solution, while the optimization speed of the traditional genetic algorithm is relatively slow; there are only some changes around the 63rd and 148 generations. Compared with the traditional genetic algorithm, the performance of the improved genetic algorithm is improved. The traditional genetic algorithm is easy to fall into the local optimal, but cannot find the global optimal solution.


## 4.2. Influence of Genetic Algorithm Parameters on the Performance of Improved Genetic Algorithm

The improved genetic algorithm with two sets of crossover probability is compared with the traditional genetic algorithm, comparing its optimization ability, and the results are shown in Figure8. The abscissa is the evolutionary algebra, and the ordinate is the fitness value.Figure 8
Comparison of fitness values when pc1 and pc2 take different values.It can be seen from Figure5 that when pc1=0.9 and pc2=0.5, the fitness value is even lower than that of traditional genetic algorithm, while when pc1=0.6 and pc2=0.1, the fitness value is much higher than that of traditional genetic algorithm, the optimization ability of traditional genetic algorithm is relatively poor, and the optimal solution is not much different from the initial solution. Comprehensive comparison shows that when the crossprobability is 0.6 and 0.1, the fitness value is higher than that when the crossprobability is 0.9 and 0.5, while the traditional genetic algorithm is between them, so when the crossprobability is not selected, the performance of the improved genetic algorithm is not as good as that of the traditional genetic algorithm, but the optimization ability of the improved genetic algorithm of the two groups of crossprobability is worth affirming. Therefore, it can be seen that the network allocation efficiency has been significantly improved when the number of household users is different.


## 4.3. Influence of Network Environment Parameters on Performance of Improved Genetic Algorithm

### 4.3.1. Influence of Network Environment Parameters on Switching Frequency

The change of switching frequency in the process of increasing the number of main households from 5 to 50 is shown in Figure8. In the figure, the abscissa is the main number of users, and the ordinate is the switching frequency.As can be seen from Figure9, with the increase of the number of main users, the switching frequency of CSGC algorithm shows an overall upward trend, while the switching frequency of the two genetic algorithms tends to decline after a short rise in 5-10 main users. The interference of authorized users in the network has little effect on the secondary users at first, but the number of primary users is increasing, but the available channels are not increasing, which leads to less and less channels that the secondary users can allocate. Genetic algorithm, considering that it wants to switch less frequency, wants to find a stable and assignable channel to allocate to the secondary users, and the switching frequency is also becoming smaller and smaller.Figure 9
Relationship between switching frequency and number of main households.


### 4.3.2. The Influence of Network Environment Parameters on Network Revenue

The relationship between network revenue and the number of primary users is shown in Figure10. The abscissa is the number of users, and the ordinate is the network revenue.Figure 10
Relationship between network revenue and number of main users.As can be seen from Figure7, with the increase of the number of main users, the overall trend of network revenue of the three algorithms is declining. It can be seen from the descending slope that CSGC algorithm declines the fastest, while the two genetic algorithms are relatively slow. When the number of primary users is less than 10, the network income of CSGC algorithm is the highest; when the number of primary users is between 10 and 18, the network income from high to low is improved genetic algorithm, CSGC algorithm, and traditional genetic algorithm; when the number of primary users is greater than 18, the network income of improved genetic algorithm is the highest, followed by traditional genetic algorithm. The network income of CSGC algorithm is the least. It can be seen that the improved genetic algorithm can improve the network efficiency by about 2%, but the spectrum switching frequency can be reduced by 69%. When the number of main users in the network is large, the improved genetic algorithm has advantages over the other two algorithms. In the follow-up experiments, the calculation time of the algorithm is also compared, and the result is very similar to that of Figure 9, so I will not explain it too much.


## 4.3.1. Influence of Network Environment Parameters on Switching Frequency

The change of switching frequency in the process of increasing the number of main households from 5 to 50 is shown in Figure8. In the figure, the abscissa is the main number of users, and the ordinate is the switching frequency.As can be seen from Figure9, with the increase of the number of main users, the switching frequency of CSGC algorithm shows an overall upward trend, while the switching frequency of the two genetic algorithms tends to decline after a short rise in 5-10 main users. The interference of authorized users in the network has little effect on the secondary users at first, but the number of primary users is increasing, but the available channels are not increasing, which leads to less and less channels that the secondary users can allocate. Genetic algorithm, considering that it wants to switch less frequency, wants to find a stable and assignable channel to allocate to the secondary users, and the switching frequency is also becoming smaller and smaller.Figure 9
Relationship between switching frequency and number of main households.


## 4.3.2. The Influence of Network Environment Parameters on Network Revenue

The relationship between network revenue and the number of primary users is shown in Figure10. The abscissa is the number of users, and the ordinate is the network revenue.Figure 10
Relationship between network revenue and number of main users.As can be seen from Figure7, with the increase of the number of main users, the overall trend of network revenue of the three algorithms is declining. It can be seen from the descending slope that CSGC algorithm declines the fastest, while the two genetic algorithms are relatively slow. When the number of primary users is less than 10, the network income of CSGC algorithm is the highest; when the number of primary users is between 10 and 18, the network income from high to low is improved genetic algorithm, CSGC algorithm, and traditional genetic algorithm; when the number of primary users is greater than 18, the network income of improved genetic algorithm is the highest, followed by traditional genetic algorithm. The network income of CSGC algorithm is the least. It can be seen that the improved genetic algorithm can improve the network efficiency by about 2%, but the spectrum switching frequency can be reduced by 69%. When the number of main users in the network is large, the improved genetic algorithm has advantages over the other two algorithms. In the follow-up experiments, the calculation time of the algorithm is also compared, and the result is very similar to that of Figure 9, so I will not explain it too much.


## 5. Conclusions

In recent years, with the rapid development of wireless communication technology, the scarcity and low utilization of wireless spectrum resources become more and more prominent. With the increasing density of network systems, intelligent algorithms that can be adjusted quickly are needed for the management of spectrum resources. With the continuous development and technical maturity of cyclic neural network, it has gradually become an effective solution.In this paper, MATLAB is briefly introduced, the network environment of algorithm simulation is set up, then the overall performance of the improved genetic algorithm is analyzed, and the relevant parameters of genetic algorithm and the suitable network environment are explored. The performance of the improved genetic algorithm with different crossover probability and mutation probability is compared with that of the traditional genetic algorithm, and the influence of the number of main users on the network revenue and switching frequency of the improved genetic algorithm, the traditional genetic algorithm, and the CSGC algorithm is explored. The simulation results show that the improved genetic algorithm can improve the network revenue and reduce the switching frequency, which is more suitable for small networks with more primary users or networks with more primary users but less node density.In view of the scarcity of wireless spectrum resources, it can now be strengthened by networking technology. Therefore, for this research, the Internet of Things technology will be deeply discussed in the follow-up research.



---

*Source: 7928300-2022-03-23.xml*