Temperature and humidity control method based on improved genetic algorithm
Technical Field
The invention relates to the technical field of data processing, in particular to a temperature and humidity control method based on an improved genetic algorithm.
Background
At present, a traditional PID algorithm is generally adopted to carry out temperature and humidity self-adaptive control on a server room, and in the process, a cloud server is required to bear huge calculation pressure.
Based on the method, research and development personnel find that the searching direction can be adaptively adjusted through a genetic algorithm by utilizing the edge computing capability of the Raspberry Pi, so that the optimal temperature and humidity of a server room can be rapidly found, and the computing pressure of a cloud server is reduced.
The genetic algorithm (Genetic Algorithm, GA) is a method for searching an optimal solution by simulating a natural evolution process, and is mainly characterized in that the method directly operates a structural object, is free from limitation of derivation and function continuity, can automatically acquire and guide an optimized search space without determining rules, and can adaptively adjust the search direction.
The Raspberry Pi is a microcomputer main board based on RAM, an SD/MicroSD card is used as a memory hard disk, 1/2/4 USB interfaces and a 10/100 Ethernet interface are arranged around the card main board, a keyboard, a mouse and a network cable can be connected, and meanwhile, a television output interface with video analog signals and an HDMI high-definition video output interface are all integrated on a main board which is only slightly larger than a credit card, so that the device has the advantages of small size, low power consumption and rich functions, and is very suitable for being used as an embedded home gateway.
The Langchao cloud server provides storage of mass equipment data, opens rich equipment management interfaces, saves the cost of management data, and simultaneously provides the capabilities of remote control, remote debugging, remote upgrading and remote equipment configuration, so that equipment can be managed without going to the equipment site.
Disclosure of Invention
Aiming at the needs and the shortcomings of the prior art development, the invention provides a temperature and humidity control method based on an improved genetic algorithm.
The invention discloses a temperature and humidity control method based on an improved genetic algorithm, which solves the technical problems and adopts the following technical scheme:
a temperature and humidity control method based on an improved genetic algorithm comprises the following steps:
collecting temperature and humidity data of the environment where the server is located;
the Arduino carries out analog-to-digital conversion on the temperature and humidity data and transmits the temperature and humidity data to an edge service node Raspberry Pi through serial port communication;
the method comprises the steps that on one hand, temperature and humidity data are summarized by an edge service node Raspberry Pi, the data are processed by an improved genetic algorithm, the optimal solution of temperature control equipment and dehumidification equipment is determined, temperature and humidity control is performed by adaptively controlling the start and stop of the temperature control equipment and the dehumidification equipment, the improved genetic algorithm is obtained by introducing gene clusters after improving fitness functions, selection operators, crossover operators and mutation operators of a standard genetic algorithm, on the other hand, the edge service node Raspberry Pi is used as a gateway, and the processed data are uploaded to a Langchao cloud server for persistence;
a user logs in the Langchao cloud server through a Web page, remotely checks real-time temperature and humidity data and historical temperature and humidity data of the environment where the server is located, and manually remotely controls the temperature control equipment and the dehumidification equipment.
Optionally, the adaptation function of the standard genetic algorithm is modified as follows:
designing a fitness function capable of dynamically changing the change scale of the fitness value according to the population evolution process, as shown in a formula (1)
Wherein f is the fitness value of a certain individual, f min Is the minimum fitness value of individuals in the current generation population, f max Is the maximum fitness value of individuals in the population of the generation, and alpha is a constant.
Further optionally, the improvement of the selection operator of the standard genetic algorithm is as follows: in the selection of individuals, a selection strategy of multiple copies of excellent individuals without replacement is adopted, and individuals with fitness values exceeding a set threshold value in the population are reserved, wherein the process specifically comprises
(2.1) setting the number n of individuals to be selected;
(2.2) selecting n individuals without replacement according to a roulette selection algorithm;
(2.3) ranking the n individuals according to fitness values from large to small, respectively duplicating the first 1/3 excellent individuals into two and the middle 1/3 individuals into one;
(2.4) after intersecting and mutating the mating population of the father, retaining individuals with fitness values exceeding a set threshold in the population.
Further optionally, the improvement of the crossover operator and the mutation operator of the standard genetic algorithm is as follows: the self-adaptive groups of the crossover operator and the mutation operator are pre-configured, so that the crossover operator and the mutation operator of different self-adaptive groups are dynamically selected according to different stages of population evolution, and the specific expression is as follows: in the initial stage of population evolution, selecting an intersection operator and a mutation operator in a self-adaptive group capable of realizing strong intersection and weak mutation, and when the population evolves slowly and falls into a local optimal solution, selecting the intersection operator and the mutation operator in the self-adaptive group capable of realizing weak intersection and strong mutation;
before the adaptive set of crossover operators and mutation operators is pre-configured, the following calculation needs to be performed:
calculating the maximum fitness value f of individuals in the generation population through a formula (2) max Average fitness value with all individuals in the generation populationIs used for the difference deltaf between the two,
the fitness value is mapped to a 0-1 probability interval by equation (3),
where σ is a sigmod function.
Further alternatively, the operation flow of the improved genetic algorithm to determine the optimal solution is as follows:
(1) Encoding;
(2) Determining an fitness function;
(3) Initializing a population, calculating individual fitness values, and calibrating the fitness values;
(4) When selecting individuals, adopting a selection strategy of multiple replications of excellent individuals without replacement, and reserving individuals with fitness values exceeding a set threshold in the population;
(5) The self-adaptive groups of the crossover operator and the mutation operator are pre-configured, and the crossover operator and the mutation operator of different self-adaptive groups are dynamically selected according to different stages of population evolution to perform crossover operation and mutation operation;
(6) The optimal solution is determined by adopting a gene cluster strategy of optimizing the intergeneration subspace, and the specific implementation flow is as follows:
(6.1) dividing the optimizing space: finding out the orderly sets of cities in all continuous non-intersecting paths in the individuals, wherein the number of sets is n, one set is called a gene cluster, dividing m individuals by n gene clusters, arranging m individuals into a formula (4) according to the descending order of fitness value, putting the ordered individuals into a set S,
B 1 ,B 2 ,...,B i ,...,B m ,f(Bi)≥f(B i+1 ),i=1,2,...,m (4);
(6.2) gene cluster optimization: selecting the first eta m individuals after sequencing, as shown in a formula (5), respectively giving a weight lambda to the eta m individuals according to the principle that the weights of the individuals before sequencing are high i Finding out the same gene cluster among individuals, recording the same gene cluster among individuals, and according to the fitness value g (G.) and the weight lambda of the gene cluster i The value of the product, retaining gene clusters larger than the set value,
B i ∈S i ,i=1,2,...,ηm (5),
wherein η is the probability set by the person;
(6.3) crossover of the parents to generate a progeny gene cluster: each gene cluster is regarded as a gene, when crossing, two individuals exchange part of the gene clusters, genes except the gene clusters are freely crossed, and after generating offspring individuals, new gene clusters are searched;
(6.4) increasing the adaptability of the gene cluster through continuous evolution, and randomly selecting an individual from the gene cluster as an optimal solution when the adaptability of the gene cluster reaches a set maximum threshold;
(7) And (3) judging whether the optimal solution meets a preset termination condition, outputting the optimal solution if the optimal solution meets the preset termination condition, and returning to the execution step (3) if the optimal solution does not meet the preset termination condition, and recalculating the individual fitness value.
Optionally, the temperature and humidity digital signals of the environment where the server is located are collected through the temperature and humidity sensor DHT11, the Arduino processes the temperature and humidity digital signals to obtain visual temperature values and humidity values, and then the visual temperature values and humidity values are transmitted to the edge service node Raspberry Pi through serial port communication.
Further optionally, the temperature and humidity sensor DHT11 is installed at the machine room and the server air outlet.
Optionally, the ECharts component is deployed in the wave cloud server, and the wave cloud server displays the received data on the Web page in a line graph, a histogram or a chart style through the ECharts component.
Optionally, the moquito is installed on the Langchao cloud server and the edge service node Raspberry Pi, and the edge service node Raspberry Pi performs data transmission with the Langchao cloud server through an MQTT protocol.
A user logs in a Langchao cloud server through a Web page, and performs manual control of temperature control equipment and dehumidification equipment through an MQTT protocol;
and the edge service node Raspberry Pi performs self-adaptive control on the temperature control equipment and the dehumidification equipment through an MQTT protocol.
Compared with the prior art, the temperature and humidity control method based on the improved genetic algorithm has the following beneficial effects:
(1) According to the temperature and humidity data collection method, temperature and humidity data are collected through the Raspberry Pi, the Raspberry Pi processes the data through an improved genetic algorithm, the optimal solutions of the temperature control equipment and the dehumidification equipment are determined, automatic adjustment of the temperature control equipment and the dehumidification equipment is carried out, and the calculation force pressure of a cloud server can be reduced;
(2) According to the invention, the data is uploaded to the cloud server through the Raspberry Pi, and the data display is realized through the ECharts component of the cloud server, so that the user can conveniently view the environmental data in real time; after the data is uploaded to the Langchaws cloud server for persistence, the ECharts component can also draw historical temperature and humidity data into a curve, and the historical temperature and humidity data are convenient to view.
Drawings
FIG. 1 is a structural hierarchy diagram of a temperature and humidity control method of the present invention;
FIG. 2 is a flow chart of an improved genetic algorithm of the present invention.
Detailed Description
In order to make the technical scheme, the technical problems to be solved and the technical effects of the invention more clear, the technical scheme of the invention is clearly and completely described below by combining specific embodiments.
Embodiment one:
referring to fig. 1, this embodiment provides a temperature and humidity control method based on an improved genetic algorithm, which includes the following steps:
a temperature and humidity sensor DHT11 is installed at the machine room and the server air outlet, and the temperature and humidity sensor DHT11 collects temperature and humidity digital signals of the environment where the server is located.
And (II) carrying out analog-digital conversion on the temperature and humidity digital signal by Arduino to obtain an intuitive temperature value and an intuitive humidity value, and then transmitting the temperature value and the humidity value to an edge service node Raspberry Pi through serial port communication.
And thirdly, the temperature and humidity data are summarized by the edge service node Raspberry Pi, the data are processed by utilizing an improved genetic algorithm, the optimal solutions of the temperature control equipment and the dehumidifying equipment are determined, the temperature and humidity control edge service node is carried out by adaptively controlling the start and stop of the temperature control equipment and the dehumidifying equipment, and the processed data are uploaded to a Langchao cloud server for persistence by taking the Raspberry Pi as a gateway.
The improved genetic algorithm is obtained by introducing gene clusters after improving fitness functions, selection operators, crossover operators and mutation operators of the standard genetic algorithm.
(i) The adaptation function of the standard genetic algorithm is improved as follows:
designing a fitness function capable of dynamically changing the change scale of the fitness value according to the population evolution process, as shown in a formula (1)
Wherein f is the fitness value of a certain individual, f min Is the minimum fitness value of individuals in the current generation population, f max Is the maximum fitness value of individuals in the population of the generation, and alpha is a constant.
(ii) The improvement of the selection operator of the standard genetic algorithm is as follows: in the selection of individuals, a selection strategy of multiple copies of excellent individuals without replacement is adopted, and individuals with fitness values exceeding a set threshold value in the population are reserved, wherein the process specifically comprises
(2.1) setting the number n of individuals to be selected;
(2.2) selecting n individuals without replacement according to a roulette selection algorithm;
(2.3) ranking the n individuals according to fitness values from large to small, respectively duplicating the first 1/3 excellent individuals into two and the middle 1/3 individuals into one;
(2.4) after intersecting and mutating the mating population of the father, retaining individuals with fitness values exceeding a set threshold in the population.
(iii) The improvement of the crossover operator and the mutation operator of the standard genetic algorithm is as follows: the self-adaptive groups of the crossover operator and the mutation operator are pre-configured, so that the crossover operator and the mutation operator of different self-adaptive groups are dynamically selected according to different stages of population evolution, and the specific expression is as follows: in the initial stage of population evolution, selecting an intersection operator and a mutation operator in a self-adaptive group capable of realizing strong intersection and weak mutation, and when the population evolves slowly and falls into a local optimal solution, selecting the intersection operator and the mutation operator in the self-adaptive group capable of realizing weak intersection and strong mutation;
before the adaptive set of crossover operators and mutation operators is pre-configured, the following calculation needs to be performed:
calculating the maximum fitness value f of individuals in the generation population through a formula (2) max Average fitness value with all individuals in the generation populationIs used for the difference deltaf between the two,
the fitness value is mapped to a 0-1 probability interval by equation (3),
where σ is a sigmod function.
With reference to fig. 2, the operation flow of determining the optimal solution by the improved genetic algorithm is as follows:
(1) Encoding;
(2) Determining an fitness function;
(3) Initializing a population, calculating individual fitness values, and calibrating the fitness values;
(4) When selecting individuals, adopting a selection strategy of multiple replications of excellent individuals without replacement, and reserving individuals with fitness values exceeding a set threshold in the population;
(5) The self-adaptive groups of the crossover operator and the mutation operator are pre-configured, and the crossover operator and the mutation operator of different self-adaptive groups are dynamically selected according to different stages of population evolution to perform crossover operation and mutation operation;
(6) The optimal solution is determined by adopting a gene cluster strategy of optimizing the intergeneration subspace, and the specific implementation flow is as follows:
(6.1) dividing the optimizing space: finding out the orderly sets of cities in all continuous non-intersecting paths in the individuals, wherein the number of sets is n, one set is called a gene cluster, dividing m individuals by n gene clusters, arranging m individuals into a formula (4) according to the descending order of fitness value, putting the ordered individuals into a set S,
B 1 ,B 2 ,...,B i ,...,B m ,f(B i )≥f(B i+1 ),i=1,2,...,m (4);
(6.2) gene cluster optimization: selecting the first eta m individuals after sequencing, as shown in a formula (5), respectively giving a weight lambda to the eta m individuals according to the principle that the weights of the individuals before sequencing are high i Finding out the same gene cluster among individuals, recording the same gene cluster among individuals, and according to the fitness value g (G.) and the weight lambda of the gene cluster i The value of the product, retaining gene clusters larger than the set value,
B i ∈S i ,i=1,2,...,ηm (5),
wherein η is the probability set by the person;
(6.3) crossover of the parents to generate a progeny gene cluster: each gene cluster is regarded as a gene, when crossing, two individuals exchange part of the gene clusters, genes except the gene clusters are freely crossed, and after generating offspring individuals, new gene clusters are searched;
(6.4) increasing the adaptability of the gene cluster through continuous evolution, and randomly selecting an individual from the gene cluster as an optimal solution when the adaptability of the gene cluster reaches a set maximum threshold;
(7) And (3) judging whether the optimal solution meets a preset termination condition, outputting the optimal solution if the optimal solution meets the preset termination condition, and returning to the execution step (3) if the optimal solution does not meet the preset termination condition, and recalculating the individual fitness value.
And fourthly, a user logs in the Langchao cloud server through a Web page, remotely checks real-time temperature and humidity data and historical temperature and humidity data of the environment where the server is located, and manually remotely controls the temperature control equipment and the dehumidification equipment.
The ECharts component is deployed in the Langchaws cloud server, and the Langchaws cloud server displays the received data on the Web page in a line graph, a histogram or a chart mode through the ECharts component.
In this embodiment, moquito is installed on the Langchao cloud server and the edge service node Raspberry Pi, and the edge service node Raspberry Pi performs data transmission with the Langchao cloud server through an MQTT protocol.
A user logs in a Langchao cloud server through a Web page, and performs manual control of temperature control equipment and dehumidification equipment through an MQTT protocol;
and the edge service node Raspberry Pi performs self-adaptive control on the temperature control equipment and the dehumidification equipment through an MQTT protocol.
In summary, by adopting the temperature and humidity control method based on the improved genetic algorithm, the temperature control equipment and the dehumidification equipment can be automatically adjusted through the Raspberry Pi, the calculation force pressure of the cloud server is reduced, the data presentation can be realized through the ECharts component of the cloud server, and the user can conveniently check the environmental data in real time; operation and maintenance personnel can acquire the machine room environment information outside the machine room in real time, so that the life of people is facilitated.
The foregoing has outlined rather broadly the principles and embodiments of the present invention in order that the detailed description of the invention may be better understood. Based on the above-mentioned embodiments of the present invention, any improvements and modifications made by those skilled in the art without departing from the principles of the present invention should fall within the scope of the present invention.