Method and device for generating test case for power grid and storage medium
By integrating power grid data to identify fault modes and using optimization and reinforcement learning algorithms to optimize test cases, it solves the problems of low efficiency and insufficient coverage of traditional power grid test case design, and achieves efficient power grid fault detection and adaptability.
Patent Information
- Application Number
- CN202410877238.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-02
- Publication Date
- 2024-10-01
AI Technical Summary
Traditional power grid test case design relies on expert experience, and manual adjustment is inefficient and insufficient in coverage. It is especially difficult to adapt quickly when the power grid changes.
By integrating power grid operation data, fault data and test data, fault modes are identified, test cases are generated, and test cases are optimized using optimization and reinforcement learning algorithms to improve their quality and adaptability.
It improves the generation efficiency and coverage of test cases, realizes efficient detection of power grid faults, adapts to dynamic changes in power grid operating status, and reduces the manual operation of generating test cases.
Smart Images

Figure CN118733467A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of power grids, and in particular to a method, device and storage medium for generating test cases for a power grid. Background Art
[0002] The power grid is one of the important infrastructures in society. Its operation stability and reliability are related to the normal progress of social life and development. In order to ensure the safe operation of the power grid, various tests can be performed on the power grid using test cases.
[0003] Test cases in traditional power grids mainly rely on expert experience and rule-making. However, the process of manually designing test cases is cumbersome. Especially when the power grid changes, manual adjustment of test cases is inefficient. In addition, test cases are mainly aimed at the normal operation process of the power grid, and the test coverage is low. Summary of the invention
[0004] In view of this, the present invention provides a method, device and storage medium for generating test cases for a power grid, so as to improve the efficiency and coverage of generating test cases for the power grid.
[0005] A first aspect of the present invention provides a method for generating a test case for a power grid, comprising:
[0006] Integrating operation data, fault data and test data of the power grid into sample data, and identifying fault modes in the operation data, the fault data and the test data;
[0007] Generate multiple test cases based on the sample data and the failure mode;
[0008] Performing an optimization operation on each of the test cases to optimize the parameters in the test cases;
[0009] If the optimization operation is completed, the test quality of the test case is predicted based on the sample data;
[0010] When the test quality value meets the preset test requirement, reinforcement learning is performed on the test case to optimize the test case.
[0011] A second aspect of the present invention provides a device for generating a test case for a power grid, comprising:
[0012] A historical data processing module, for integrating the operation data, fault data and test data of the power grid into sample data, and identifying fault modes in the operation data, the fault data and the test data;
[0013] A test case generation module, used to generate multiple test cases according to the sample data and the failure mode;
[0014] A test case optimization module, used to perform an optimization operation on each of the test cases to optimize the parameters in the test case;
[0015] A test quality prediction module, used for predicting the test quality of the test case based on the sample data if the optimization operation is completed;
[0016] The test case reinforcement module is used to perform reinforcement learning on the test case to optimize the test case when the test quality value meets the preset test requirement.
[0017] A third aspect of the present invention provides an electronic device, the electronic device comprising:
[0018] at least one processor; and
[0019] a memory communicatively connected to the at least one processor; wherein,
[0020] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the method for generating test cases for a power grid as described in the first aspect above.
[0021] A fourth aspect of the present invention provides a computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the method for generating test cases for a power grid as described in the first aspect above.
[0022] A fifth aspect of the present invention provides a computer program product, the computer program product comprising a computer program, and when the computer program is executed by a processor, the method for generating test cases for a power grid as described in the first aspect above is implemented.
[0023] In this embodiment, the operation data, fault data and test data of the power grid are integrated into sample data, and the fault mode is identified in the operation data, fault data and test data; multiple test cases are generated based on the sample data and the fault mode; an optimization operation is performed on each test case to optimize the parameters in the test case; if the optimization operation is completed, the test quality of the test case is predicted based on the sample data; when the test quality value meets the preset test requirements, reinforcement learning is performed on the test case to optimize the test case. In addition to the normal state of the power grid, this embodiment also takes into account the generation of test cases for faults that occur in the power grid, which can improve the coverage of the test, and initially uses the optimization algorithm to optimize the parameters of the test case so that the test case is feasible. Subsequently, reinforcement learning is used to optimize the test case, which can adjust and optimize the test case in real time, adapt to the dynamic changes in the operation state of the power grid, and gradually approach the optimal test case, ensuring that the test case has high adaptability and fault detection capabilities. The degree of automation in the process of constructing test cases is high, which can effectively reduce the operation of manually generating test cases and greatly improve the efficiency of generating test cases.
[0024] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0026] Figure 1 This is a flowchart of a method for generating test cases for a power grid provided in Embodiment 1 of the present invention.
[0027] Figure 2 It is a structural schematic diagram of a device for generating test cases for a power grid provided in Embodiment 2 of the present invention.
[0028] Figure 3 It is a structural schematic diagram of an electronic device provided in Embodiment 3 of the present invention. DETAILED DESCRIPTION
[0029] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0030] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present invention described herein can cover sequential implementations other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0031] Embodiment 1
[0032] See also Figure 1 , shows a flow chart of a method for generating test cases for a power grid provided by a first embodiment of the present invention, the method can be executed by a device for generating test cases for a power grid, the device for generating test cases for a power grid can be implemented in the form of hardware and / or software, and the device for generating test cases for a power grid can be configured in an electronic device. Figure 1 As shown, the method includes:
[0033] Step 101: Integrate operation data, fault data and test data of a power grid into sample data, and identify fault modes in the operation data, fault data and test data.
[0034] In this embodiment, the operation data recorded by the power grid during normal operation, the fault data recorded when a fault occurs, and the test data recorded when the power grid is tested using test cases can be queried in the GIS (Geographic Information System) and other systems of the power grid.
[0035] Preprocess the operation data, fault data and test data, for example, filter abnormal data, fill in missing data, normalize and organize them, etc., and integrate them into structured sample data.
[0036] In addition, for the same system in the power grid, the operating data and the test data are used as reference objects, and the fault data are classified on the basis of the operating data and the test data to obtain the fault mode.
[0037] Step 102: Generate multiple test cases based on sample data and failure modes.
[0038] In this embodiment, a preliminary analysis may be performed on the sample data and the failure mode to generate a plurality of initial test cases that are adapted to the sample data and the failure mode.
[0039] In one approach, test cases may be generated based on rules according to sample data and failure modes.
[0040] In this way, a series of test rules defined for the power grid according to the operation characteristics and fault characteristics of the power grid can be queried, and various test rules are configured in the test case serving as a template.
[0041] The sample data and the failure mode are matched with the test rules in turn. When the match is successful, the sample data and the failure mode are substituted into the corresponding test rules based on the test case of the template to generate a regularized test case.
[0042] In another approach, test cases may be generated based on random sample data and failure modes.
[0043] In this way, the value range of various parameters can be randomly selected within the statistical range of the sample data, and test scenarios at multiple time points can be randomly constructed. These test scenarios are represented in a digital way and configured in the test case as a template.
[0044] Based on the test case of the template, the parameter value range is randomly combined with the test scenario, that is, the parameter value range is substituted into the test scenario to construct the test case.
[0045] It should be pointed out that the rule-based approach and the random approach can be used alone or in combination. When used in combination, the test cases generated based on the rules and the test cases generated based on the randomness are merged to form a preliminary test case set.
[0046] Step 103: Perform an optimization operation on each test case to optimize the parameters in the test case.
[0047] In one embodiment of the present invention, a commercial solver such as Gurobi or a heuristic algorithm such as a particle swarm optimization algorithm may be used to perform an optimization operation on each test case, thereby optimizing the parameters in the test case.
[0048] In one embodiment of the present invention, a genetic algorithm (GA) may be used as an optimization operation. In this embodiment, step 103 may include the following steps:
[0049] Step 1031: For each test case, initialize the test case as an individual in the population.
[0050] In this embodiment, a certain number of test cases can be randomly selected from the test case set and initialized as individuals in the population, where the individual is composed of a chromosome representing a gene set, which is a string or vector of a specific length, and the genes in the individual represent configurable parameters in the test case.
[0051] Step 1032: Calculate the fitness of the individual based on multiple test indicators of the test case.
[0052] In this embodiment, in each round of iteration, the test indicators of the test case when it is tested in the power grid can be evaluated based on the information of the test case itself and the information of the power grid (including sample data), and the test indicators are substituted into the fitness function (Fitness function) for operation, and the fitness of the corresponding individuals is calculated. Individuals with higher fitness represent better solutions, which are more likely to be selected for reproduction and their traits will be expressed in the next generation. As the genetic algorithm proceeds, the quality of the solution will improve, the fitness will increase, and when a solution with a fitness that meets the requirements is found, the genetic algorithm can be terminated.
[0053] For example, for each test case, the breadth of the test case covering the grid operation state, the proportion of faults detected by the test case in the sample data, and the execution time of the test case can be counted respectively.
[0054] The product of the breadth and a preset first weight, the product of the fault ratio and a preset second weight, and the inverse of the product of the execution time and a preset third weight are added together to obtain the fitness of the corresponding individual.
[0055] In this example, the fitness of an individual can be expressed as:
[0056] F(Chromosome)
[0057] =w1·Coverage+w2·Fault Detection Rate
[0058] -w3 Execution Time
[0059] Among them, F (Chromosome) is the fitness of the individual, Coverage is the breadth, Fault Detection Rate is the fault ratio, Execution Time is the execution time, w1 is the first weight, w2 is the second weight, and w3 is the third weight.
[0060] Step 1033: Perform a selection operation on the individuals according to their fitness to select some individuals.
[0061] In this embodiment, a selection operation (Selection) may be performed on individuals in the current population according to fitness, and some individuals may be selected for reproduction and generation of the next generation.
[0062] In general, individuals with high fitness are more likely to be selected and pass their genetic material to the next generation. In addition, there is still a chance that individuals with low fitness values will be selected, but with a lower probability. In this way, their genetic material will not be completely discarded.
[0063] Exemplarily, the fitness of all individuals in the current population can be summed to obtain the total fitness. For each individual, the ratio between the fitness and the total fitness is calculated to obtain the screening probability. The screening probability represents the probability of being selected to enter the next generation. At this time, some individuals are selected to enter the next generation according to the screening probability of each individual.
[0064] Then, the screening probability can be expressed as:
[0065]
[0066] Among them, there are P individuals in the current population, F (Chromosome i ) is the fitness of the ith individual, i∈P, S is the total fitness, P i is the screening probability of the ith individual.
[0067] Step 1034: If the selection operation is completed, a crossover operation is performed on the individual to generate a new individual.
[0068] In order to create a pair of new individuals, a crossover operation is usually performed on the parent individuals selected from the current generation, where part of the chromosomes of the parent individuals are exchanged (crossed over) to create two new chromosomes representing the offspring.
[0069] For example, for two randomly selected individuals, a crossover position may be randomly selected, and the genes located after the crossover position in the two randomly selected individuals may be exchanged to generate a new individual.
[0070] For example, randomly select the parent individual Chromosome A ChromosomeB , among which, Chromosome A Chromosome B The gene sequence can be expressed as:
[0071] Chromosome A =[x A,1 ,x A,2 ,…,x A ,k,x A ,k +1 ,x A ,k+2,…,x A ,n];
[0072] Chromosome B =[x B,1 ,x B,2 ,…,x B,k ,x B,k+1 ,x B,k+2 ,…,x B,n ].
[0073] Among them, x A,i Represents individual Chromosome A The gene at position i, x B,i Represents individual Chromosome B The gene at the ith position.
[0074] If the crossover position is k+1, the parent individuals can generate two offspring individuals Child1 and Child2 after performing the crossover operation, where the gene sequences of Child1 and Child2 can be expressed as:
[0075] Child1=[x A,1 ,x A,2 ,…,x A,k ,x B,k+1 ,x B,k+2 ,…,x B,n ];
[0076] Child2=[x B,1 ,x B,2 ,…,x B,k ,x A,k+1 ,x A,k+2 ,…,x A,n ].
[0077] Step 1035: If the crossover operation is completed, a mutation operation is performed on the individual.
[0078] For newly created individuals, mutation operations can be performed. The purpose of the mutation operation is to periodically randomly update the population, introduce new patterns into the chromosome, and encourage search in unknown areas of the solution space.
[0079] The mutation operation may be manifested as a random change of genes, that is, it is achieved by randomly changing the genes of one or more chromosomes.
[0080] Step 1036: If the mutation operation is completed, determine whether the preset genetic condition is met; if so, execute step 1037; if not, return to execute steps 1032-1036.
[0081] Step 1037: Output multiple individuals with the highest fitness.
[0082] In this embodiment, one or more genetic conditions can be preset, for example, the number of generations reaches a preset threshold, the change in fitness is less than a preset threshold, etc. During each round of iteration, it can be determined whether the genetic conditions are met.
[0083] If any genetic condition is met, the genetic algorithm can be stopped and multiple individuals with the highest fitness are output, that is, the test cases after the optimized parameters are output, thereby forming a preliminary optimized test case set.
[0084] If all the genetic conditions are not met, the genetic algorithm can continue to enter the next round of iteration and re-execute steps 1032 to 1036 until any genetic condition is met.
[0085] In this embodiment, a genetic algorithm is used to perform preliminary optimization on the test cases to avoid falling into a local optimal solution and to improve the diversity and coverage of the test cases.
[0086] Step 104: If the optimization operation is completed, the test quality of the test case is predicted based on the sample data.
[0087] In this embodiment, the sample data can be used to further evaluate the test cases after preliminary optimization, and the test quality when applied to power grid testing is expected.
[0088] In a specific implementation, the power grid can be modeled based on the sample data, that is, the sample data is input into an existing simulation model of the power grid for fine-tuning to obtain a new simulation model.
[0089] When the test cases after preliminary optimization are run in the simulation model, the power operation data in the simulation model, such as power load, voltage, current, frequency, temperature, fault record, etc., are read.
[0090] Use statistical methods (such as average value, peak value, trough value, etc.) to perform feature engineering on the power operation data and extract a variety of power operation features from the power operation data. At this time, the power operation feature can be expressed as X = {x1, x2, ..., x n}, where x i represents the i-th power operation characteristic.
[0091] Various power operation characteristics are normalized using Min-Max (minimum-maximum) algorithms, and are scaled to a specified range (eg, [0, 1]).
[0092] If the normalization process is completed, the power operation characteristics are input into the Long Short Term Memory (LSTM) network trained for the power grid for processing to output the test quality.
[0093] Among them, when training the long short-term memory network, the operation data recorded by the power grid during the formal operation test case can be collected and the test quality can be marked on the operation data. The preprocessed operation data set is divided into a training set and a test set. The mean square error is used as the loss function and the Adam (Adaptive Moment Estimation) algorithm is used as the optimization algorithm. Under the supervision of the test quality, the training set is used to update the parameters in the long short-term memory network. When the update is completed, the long short-term memory network is tested with the test set. When the performance of the long short-term memory network meets the requirements, it is deployed for online operation.
[0094] In this embodiment, the long short-term memory network can more accurately model the operating status of the power grid by learning a large amount of historical data, predict the response of the power grid under different test cases, and improve the accuracy of the test quality of the evaluation test cases.
[0095] Step 105: When the test quality value meets the preset test requirement, reinforcement learning is performed on the test case to optimize the test case.
[0096] If the test quality value of a test case meets the preset test requirements (such as being greater than a certain threshold, etc.), reinforcement learning can be performed on the test case to continue optimizing the test case.
[0097] In one embodiment of the present invention, step 105 may include the following steps:
[0098] Step 1051: define various variables in reinforcement learning.
[0099] In this embodiment, various variables in reinforcement learning can be defined based on the information of the power grid and the information of the test case.
[0100] Among them, the variables in reinforcement learning include the following:
[0101] 1. Status
[0102] In this embodiment, the state in the reinforcement learning may be defined as the operating state of the power grid.
[0103] 2. Action
[0104] In this embodiment, the action in reinforcement learning can be defined as selecting or adjusting the parameters in the test case.
[0105] 3. Rewards
[0106] In this embodiment, the reward in reinforcement learning can be defined as multiple test indicators of the test case. In this case, the reward can be given according to the test performance.
[0107] For example, for each test case, the breadth of the test case covering the grid operation state, the proportion of faults detected by the test case in the sample data, and the execution time of the test case can be counted respectively.
[0108] The product of the breadth and a preset first weight, the product of the fault ratio and a preset second weight, and the inverse of the product of the execution time and a preset third weight are added together to obtain a reward in reinforcement learning.
[0109] In this example, the reward in reinforcement learning can be expressed as:
[0110] R=w1·Coverage+w2·Fault Detection Rate-w3·Execution Time
[0111] Among them, R is the reward in reinforcement learning, Coverage is the breadth, Fault Detection Rate is the fault ratio, Execution Time is the execution time, w1 is the first weight, w2 is the second weight, and w3 is the third weight.
[0112] The fitness when using genetic algorithms to initially optimize test cases is calculated in the same way as the reward when using reinforcement learning to continue optimizing test cases, which can keep the direction of optimizing test cases consistent, effectively improve the optimization depth of test cases, effectively accelerate the optimization of test cases, and improve the quality of test cases.
[0113] Step 1052: Perform reinforcement learning according to the deep Q network to optimize the test case.
[0114] In this embodiment, reinforcement learning can be performed according to DQN (Deep QNetwork) in the local environment of the power grid (especially the isolated environment), so as to continue to optimize the test cases. When the test cases are relatively complete, testing is performed in the backbone network of the power grid to interfere with the backbone network of the power grid and ensure the stability of the power grid.
[0115] The Deep Q-Network is a model-free reinforcement learning algorithm that can predict the expected reward of taking a certain action in a certain state by learning a state-action value function (Q-function).
[0116] Among them, the deep Q network is:
[0117]
[0118] Among them, Q(s,a) represents the Q value when executing action a in the current state s, α is the learning rate, γ is the discount factor, r is the reward, and s' is the new state after executing action a. It represents the maximum Q value when executing all actions a' in the new state s'.
[0119] In this embodiment, the operation data, fault data and test data of the power grid are integrated into sample data, and the fault mode is identified in the operation data, fault data and test data; multiple test cases are generated based on the sample data and the fault mode; an optimization operation is performed on each test case to optimize the parameters in the test case; if the optimization operation is completed, the test quality of the test case is predicted based on the sample data; when the test quality value meets the preset test requirements, reinforcement learning is performed on the test case to optimize the test case. In addition to the normal state of the power grid, this embodiment also takes into account the generation of test cases for faults that occur in the power grid, which can improve the coverage of the test, and initially uses the optimization algorithm to optimize the parameters of the test case so that the test case is feasible. Subsequently, reinforcement learning is used to optimize the test case, which can adjust and optimize the test case in real time, adapt to the dynamic changes in the operation state of the power grid, and gradually approach the optimal test case, ensuring that the test case has high adaptability and fault detection capabilities. The degree of automation in the process of constructing test cases is high, which can effectively reduce the operation of manually generating test cases and greatly improve the efficiency of generating test cases.
[0120] Embodiment 2
[0121] See also Figure 2 , shows a schematic diagram of the structure of a device for generating test cases for a power grid provided by Embodiment 2 of the present invention. Figure 2 As shown, the device comprises:
[0122] The historical data processing module 201 is used to integrate the operation data, fault data and test data of the power grid into sample data, and to identify the fault mode in the operation data, the fault data and the test data;
[0123] A test case generation module 202, used to generate multiple test cases according to the sample data and the failure mode;
[0124] The test case optimization module 203 is used to perform an optimization operation on each of the test cases to optimize the parameters in the test case;
[0125] A test quality prediction module 204, configured to predict the test quality of the test case based on the sample data if the optimization operation is completed;
[0126] The test case reinforcement module 205 is used to perform reinforcement learning on the test case to optimize the test case when the test quality value meets the preset test requirement.
[0127] In one embodiment of the present invention, the test case generation module 202 includes:
[0128] A test rule query module, used to query the test rules defined for the power grid;
[0129] A test rule matching module, used for matching the sample data and the fault mode with the test rule;
[0130] A rule generation module, used for substituting the sample data and the failure mode into the test rule to generate a regularized test case when the match is successful;
[0131] and / or
[0132] A parameter selection module, used to randomly select value ranges for various parameters within the statistical range of the sample data;
[0133] Test scenario construction module, used to randomly construct test scenarios at multiple time points;
[0134] The random generation module is used to randomly combine the value range of the parameter with the test scenario to construct a test case.
[0135] In one embodiment of the present invention, the test case optimization module 203 includes:
[0136] A population initialization module, for initializing each of the test cases into an individual in a population; the genes in the individual represent the parameters in the test case;
[0137] A fitness calculation module, used to calculate the fitness of the individual according to multiple test indicators of the test case;
[0138] A selection operation execution module, used for executing a selection operation on the individuals according to the fitness, so as to select some of the individuals;
[0139] A crossover operation execution module, configured to execute a crossover operation on the individual to generate a new individual if the selection operation is completed;
[0140] A mutation operation execution module, configured to execute a mutation operation on the individual if the crossover operation is completed;
[0141] A genetic condition judgment module is used to judge whether the preset genetic condition is met after the mutation operation is completed; if so, the individual output module is executed; if not, the fitness calculation module is returned to execute;
[0142] The individual output module is used to output the multiple individuals with the highest fitness.
[0143] In one embodiment of the present invention, the fitness calculation module is further used for:
[0144] Counting the breadth of the power grid operation state covered by the test cases;
[0145] Counting the proportion of faults detected by the test case in the sample data;
[0146] Counting the execution time of the test case;
[0147] The fitness of the individual is obtained by adding the product of the breadth and a preset first weight, the product of the fault ratio and a preset second weight, and the inverse of the product of the execution time and a preset third weight.
[0148] In one embodiment of the present invention, the crossover operation execution module is further used for:
[0149] summing the fitness of all the individuals in the population to obtain a total fitness;
[0150] For each of the individuals, the ratio between the fitness and the total fitness is calculated to obtain a screening probability;
[0151] Some of the individuals are selected according to the screening probability of each of the individuals.
[0152] In one embodiment of the present invention, the crossover operation execution module is further used for:
[0153] For the two randomly selected individuals, randomly select a crossover position;
[0154] The genes located after the crossover position in two randomly selected individuals are exchanged to generate a new individual.
[0155] In one embodiment of the present invention, the test quality prediction module 204 includes:
[0156] A simulation model building module, used to model the power grid according to the sample data to obtain a simulation model;
[0157] A power operation data reading module, used to read the power operation data in the simulation model when running the test case in the simulation model;
[0158] A power operation feature extraction module, used to extract a variety of power operation features from the power operation data;
[0159] A normalization processing execution module, used for performing normalization processing on various power operation characteristics;
[0160] A test quality output module is used to input the power operation characteristics into a long short-term memory network trained for the power grid for processing if the normalization processing is completed, so as to output the test quality.
[0161] In one embodiment of the present invention, the test case enhancement module 205 includes:
[0162] A variable definition module is used to define various variables in reinforcement learning; the variables include state, action and reward; the state is the operating state of the power grid; the action is to select or adjust the parameters in the test case; the reward is multiple test indicators of the test case;
[0163] A reinforcement learning execution module, used to execute the reinforcement learning according to the deep Q network to optimize the test case;
[0164] Wherein, the deep Q network is:
[0165]
[0166] Wherein, Q(s,a) represents the Q value when executing the action a in the current state s, α is the learning rate, γ is the discount factor, r is the reward, s' is the new state after executing the action a, Represents the maximum Q value when executing all the actions a' in the new state s'.
[0167] In one embodiment of the present invention, the variable definition module is further used to:
[0168] Counting the breadth of the power grid operation state covered by the test cases;
[0169] Counting the proportion of faults detected by the test case in the sample data;
[0170] Counting the execution time of the test case;
[0171] The product of the breadth and a preset first weight, the product of the fault ratio and a preset second weight, and the inverse of the product of the execution time and a preset third weight are added together to obtain a reward in reinforcement learning.
[0172] The device for generating test cases for a power grid provided in an embodiment of the present invention can execute the method for generating test cases for a power grid provided in any embodiment of the present invention, and has functional modules and beneficial effects corresponding to the method for generating test cases for a power grid.
[0173] Embodiment 3
[0174] See also Figure 3 , shows a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, blade servers, mainframe computers, and other suitable computers. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or claimed herein.
[0175] like Figure 3 As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0176] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0177] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as a method for generating test cases for a power grid.
[0178] In some embodiments, the method for generating test cases for a power grid may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the method for generating test cases for a power grid described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to execute the method for generating test cases for a power grid in any other appropriate manner (e.g., by means of firmware).
[0179] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0180] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0181] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0182] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0183] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0184] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0185] Embodiment 4
[0186] An embodiment of the present invention further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the method for generating test cases for a power grid as provided in any embodiment of the present invention is implemented.
[0187] In the process of implementation, the computer program product can be written in one or more programming languages or a combination thereof to perform the computer program code of the present invention, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (for example, using an Internet service provider to connect through the Internet).
[0188] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0189] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for generating test cases for a power grid, characterized in that: include: Integrating operation data, fault data and test data of the power grid into sample data, and identifying fault modes in the operation data, the fault data and the test data; Generate multiple test cases based on the sample data and the failure mode; Performing an optimization operation on each of the test cases to optimize the parameters in the test cases; If the optimization operation is completed, the test quality of the test case is predicted based on the sample data; When the test quality value meets the preset test requirement, reinforcement learning is performed on the test case to optimize the test case.
2. The method according to claim 1, characterized in that The generating of a plurality of test cases according to the sample data and the failure mode comprises: querying test rules defined for the power grid; Matching the sample data and the failure mode with the test rule; When the match is successful, the sample data and the failure mode are substituted into the test rule to generate a regularized test case; and / or Randomly select value ranges for various parameters within the statistical range of the sample data; Randomly construct test scenarios at multiple time points; The value range of the parameter is randomly combined with the test scenario to construct a test case.
3. The method according to claim 1, characterized in that The performing an optimization operation on each of the test cases to optimize the parameters in the test cases includes: For each of the test cases, the test case is initialized as an individual in a population; the gene in the individual represents the parameter in the test case; Calculating fitness of the individual according to multiple test indicators of the test case; Performing a selection operation on the individuals according to the fitness to select some of the individuals; If the selection operation is completed, a crossover operation is performed on the individual to generate a new individual; If the crossover operation is completed, a mutation operation is performed on the individual; If the mutation operation is completed, determine whether the preset genetic condition is met; if so, output the multiple individuals with the highest fitness; if not, return to execute the test indicator based on the test case to calculate the fitness of the individual.
4. The method according to claim 3, characterized in that The calculating the fitness of the individual according to the multiple test indicators of the test case includes: Counting the breadth of the power grid operation state covered by the test cases; Counting the proportion of faults detected by the test case in the sample data; Counting the execution time of the test case; The fitness of the individual is obtained by adding the product of the breadth and a preset first weight, the product of the fault ratio and a preset second weight, and the inverse of the product of the execution time and a preset third weight.
5. The method according to claim 3, characterized in that: The performing a selection operation on the individuals according to the fitness to select some of the individuals includes: summing the fitness of all the individuals in the population to obtain a total fitness; For each of the individuals, the ratio between the fitness and the total fitness is calculated to obtain a screening probability; selecting some of the individuals according to the screening probability of each of the individuals; The performing a crossover operation on the individuals to generate new individuals comprises: For the two randomly selected individuals, randomly select a crossover position; The genes located after the crossover position in two randomly selected individuals are exchanged to generate a new individual.
6. The method according to any one of claims 1 to 5, characterized in that The test quality predicted for the test case based on the sample data includes: Modeling the power grid according to the sample data to obtain a simulation model; When running the test case in the simulation model, reading the power operation data in the simulation model; extracting a plurality of power operation characteristics from the power operation data; Normalizing the various power operation characteristics; If the normalization process is completed, the power operation characteristics are input into a long short-term memory network trained for the power grid for processing to output the test quality.
7. The method according to any one of claims 1 to 5, characterized in that The performing reinforcement learning on the test case to optimize the test case includes: Define various variables in reinforcement learning; the variables include state, action and reward; the state is the operating state of the power grid; the action is to select or adjust the parameters in the test case; the reward is multiple test indicators of the test case; Performing reinforcement learning as described in terms of a deep Q-network to optimize test cases; Wherein, the deep Q network is: Wherein, Q(s,a) represents the Q value when executing the action a in the current state s, α is the learning rate, γ is the discount factor, r is the reward, s' is the new state after executing the action a, Represents the maximum Q value when executing all the actions a' in the new state s'.
8. The method according to claim 7, characterized in that The variables in the reinforcement learning are defined as follows: Counting the breadth of the power grid operation state covered by the test cases; Counting the proportion of faults detected by the test case in the sample data; Counting the execution time of the test case; The product of the breadth and a preset first weight, the product of the fault ratio and a preset second weight, and the inverse of the product of the execution time and a preset third weight are added together to obtain a reward in reinforcement learning.
9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so as to enable the at least one processor to perform the method for generating a test case for a power grid according to any one of claims 1 to 8.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method for generating a test case for a power grid according to any one of claims 1 to 8 is implemented.
Citation Information
Patent Citations
Reinforcement learning model training method and system based on fitness prediction
CN115423023A
Test case processing method and device, storage medium and electronic equipment
CN117667673A
