Test strategy optimization method based on genetic algorithm and discrete particle swarm optimization
Through the testing strategy optimization method based on genetic algorithm and discrete particle swarm algorithm, the problem of unreasonable design of test strategies in complex systems is solved, the test items and sequences are optimized, the time and cost efficiency are improved, and the calculation amount is reduced.
Patent Information
- Application Number
- CN202411210943.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-30
- Publication Date
- 2024-12-17
AI Technical Summary
Unreasonable design of test strategies for complex systems leads to excessive testing time and high cost, and there are unnecessary testing, reducing the efficiency of fault detection and isolation.
Using the testing strategy optimization method based on genetic algorithm and discrete particle swarm algorithm, the test item and test sequence are optimized by establishing test simulation models, improving test item selection strategies and optimizing test sequences, and combining with or graph heuristic search algorithms to optimize test items and test sequences to reduce the Unnecessary tests.
It significantly reduces testing time and expenses, improves the efficiency of fault detection and isolation, realizes the optimal testing strategy of the system, and reduces the calculation process and calculation amount.
Smart Images

Figure CN119150679A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of system test analysis and design, and in particular to a test strategy optimization method based on genetic algorithm and discrete particle swarm algorithm. Background Art
[0002] As large-scale weapon systems become more and more complex, the testability analysis and test strategy design of electronic equipment are becoming increasingly difficult. Moreover, defects in the test strategy design will lead to higher and higher costs for fault diagnosis and maintenance of the system. A system with good testability can greatly reduce the time required for fault detection and isolation, thereby significantly shortening the maintenance time and reducing the corresponding skill requirements for maintenance personnel, thereby achieving the purpose of improving system reliability and reducing life cycle costs.
[0003] When the system structure and functions are complex, the system failure modes are also diverse, so generally more test points and test items are designed. In this case, if the testability design is not reasonably planned, a lot of test time will be wasted. Under the conditions of the specified fault detection rate and fault isolation rate, only a part of all tests may be required to achieve the testability index parameters required by the system, so it is necessary to optimize the selection of the designed test items.
[0004] For a certain set of tests, if the system has detected and correctly isolated all faults during the step-by-step execution, then the remaining tests do not need to be executed. On the contrary, if the test that can detect and correctly isolate the current fault is executed as the last step, all tests must be executed to detect and isolate the current fault source. Compared with the former, this test sequence significantly reduces the efficiency of system fault detection and isolation, and there are redundant tests. Therefore, in order to minimize the test time and cost when locating the fault, it is necessary to determine the order in which each test item is executed before testing.
[0005] Therefore, there is an urgent need for a test strategy optimization method based on genetic algorithm and discrete particle swarm algorithm to optimize the test strategy of complex systems in order to achieve the above purpose. Summary of the invention
[0006] The purpose of the present invention is to provide a test strategy optimization method based on genetic algorithm and discrete particle swarm algorithm, which overcomes the problems of long test time and high test cost caused by unreasonable test item design.
[0007] To achieve the above object, the present invention provides a test strategy optimization method based on genetic algorithm and discrete particle swarm algorithm, comprising the following steps:
[0008] S1. Establish a test simulation model for the system and establish a fault-test correlation matrix;
[0009] S2, based on genetic algorithm, improve the test item selection strategy;
[0010] S3. Based on discrete particle swarm algorithm, complete the test sequence optimization.
[0011] Preferably, step S1 specifically includes the following steps:
[0012] S11. Clarify the basic structure of the object under test and conduct test simulation modeling on the object under test according to the independence principle and physical division principle;
[0013] S12. Based on the test simulation model, the system reachability matrix is calculated by using the Warshall algorithm through the system adjacency matrix, and then the complete fault correlation matrix is calculated;
[0014] S13. Combine the complete failure correlation matrix and the functional failure correlation matrix to obtain the system failure-test correlation matrix.
[0015] Preferably, step S2 specifically includes the following steps:
[0016] S21, initialize the population, determine the size of the solution set, the crossover probability of two individuals in the solution set, the probability of a certain individual mutation, and the termination evolution condition of the population;
[0017] S22, using real number coding to directly encode the individual according to the test sequence number, and using the test sequence number to form the sequence number of the individual gene, while ensuring that the chromosome gene sequence is not repeated in the process of randomly generating the individual gene;
[0018] S23. Design a fitness function to evaluate the excellence of individuals;
[0019] S24, using a combination of roulette wheel selection method and best-reserved selection method, and using bubble sort to select good solutions;
[0020] S25, crossover mode selects single-point crossover, and selects two excellent solutions and two inferior solutions for crossover operation in each generation of evolution;
[0021] S26. A combination of basic position mutation and uniform mutation is used. If the mutated gene is repeated with the original individual gene, it will be randomly mutated again until every gene of the individual is different. An optimal individual protection mechanism is added to prevent the optimal individual from participating in the mutation.
[0022] Preferably, step S3 specifically includes the following steps:
[0023] S31, using discrete particle swarm algorithm to optimize and select the test set that needs to be expanded each time;
[0024] S32. Expand the optimized results using the AND-OR graph heuristic search algorithm.
[0025] Preferably, step S31 specifically includes the following steps:
[0026] S311, first determine the dimension of the search space, that is, the number of tests included in the test set obtained after optimization, and set the number of particles in the community;
[0027] S312. In the discrete particle swarm algorithm, the speed update formula of each particle is
[0028]
[0029] Among them, w is the coefficient of the particle itself maintaining its original speed, c1 is the weight coefficient of the particle's own historical optimal position, c2 is the weight coefficient of the particle following the optimal position of the entire group, ξ and η are random numbers in the interval [0,1];
[0030] The particle update formula is:
[0031]
[0032] S313. Design test evaluation function:
[0033]
[0034] Among them, P(t i ) is the test t i The average probability of all possible failures of the system that can be detected, N(t i ) is t i The number of faults that can be detected, S(t i ) is t i The minimum measurable magnitude of a system fault among all system faults detected;
[0035] S314, the evaluation function of the test set is:
[0036]
[0037] Where, T s represents the test set randomly selected by the algorithm, T represents all the test items in the system, and N is T s The number of test items included in FD and η Fl Respectively represent the test set T s The fault detection rate and isolation rate of the system after the test, c i Indicates test ti The cost, h(t i ) indicates test t i The evaluation function value of .
[0038] Preferably, step S32 specifically includes the following steps:
[0039] S321, generating a Huffman code of the system initial state according to the system state set and the prior probability vector of each state in the mathematical model of the system test sequence optimization problem;
[0040] S322, calculating the Huffman coding length of each state of the system, and expanding the initial node of the system according to the fault-test correlation matrix;
[0041] S323, in the initial fault state set S = (s1, s2, ...s 12 ) to test t j After that, the fault set is divided into two parts, S jp By not being able to be tested j The detected system fault consists of jf By being able to be j The detected fault composition calculates the evaluation function value of the corresponding test based on the probability of the state set and the heuristic function value of the state set.
[0042] Therefore, the present invention adopts the above-mentioned test strategy optimization method based on genetic algorithm and discrete particle swarm algorithm, obtains the optimal set of test items through genetic algorithm, and combines the advantages of the two algorithms, the AND-OR graph heuristic search algorithm and the discrete particle swarm algorithm, to complete the system test sequence optimization, which greatly reduces the calculation process and amount of calculation compared with the traditional algorithm.
[0043] The technical solution of the present invention is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] Figure 1 It is an overall flow chart of an embodiment of a test strategy optimization method based on a genetic algorithm and a discrete particle swarm algorithm of the present invention;
[0045] Figure 2 It is a genetic algorithm test item optimization flow chart of an embodiment of a test strategy optimization method based on a genetic algorithm and a discrete particle swarm algorithm of the present invention;
[0046] Figure 3 It is an AND-OR graph heuristic search algorithm and a discrete particle swarm algorithm test sequence optimization flow chart of an embodiment of a test strategy optimization method based on a genetic algorithm and a discrete particle swarm algorithm of the present invention;
[0047] Figure 4The invention discloses a system optimal test strategy decision tree of a test strategy optimization method embodiment based on a genetic algorithm and a discrete particle swarm algorithm. DETAILED DESCRIPTION
[0048] The technical solution of the present invention is further described below through the accompanying drawings and embodiments.
[0049] Unless otherwise defined, technical or scientific terms used in the present invention shall have the common meanings understood by one having ordinary skills in the field to which the present invention belongs.
[0050] As shown in the figure, a test strategy optimization method based on genetic algorithm and discrete particle swarm algorithm includes the following steps:
[0051] S1. Establish a test simulation model of the system and establish a fault-test correlation matrix, which specifically includes the following steps:
[0052] S11. Clarify the basic structure of the object under test and conduct test simulation modeling on the object under test according to the independence principle and physical division principle;
[0053] S12. Based on the test simulation model, the system reachability matrix is calculated by using the Warshall algorithm through the system adjacency matrix, and then the complete fault correlation matrix is calculated;
[0054] S13. Combine the complete failure correlation matrix and the functional failure correlation matrix to obtain the system failure-test correlation matrix.
[0055] S2. Improve the test item selection strategy based on genetic algorithm, such as Figure 2 As shown, step S2 specifically includes the following steps:
[0056] S21. First, the population is initialized to determine the size of the solution set, the crossover probability of two individuals in the solution set, the mutation probability of an individual (except the optimal individual), and the termination evolution condition of the population;
[0057] S22, using real number coding to directly encode the individual according to the test sequence number, and using the test sequence number to form the sequence number of the individual gene, while ensuring that the chromosome gene sequence is not repeated in the process of randomly generating the individual gene;
[0058] S23. In order to find the best individual in the population, a fitness function needs to be designed to evaluate the quality of the individual. The function should be a non-negative monotonous continuous function as much as possible, so that individuals who are more adaptable to the new environment or individuals close to the optimal solution to the problem can be selected. Therefore, the fitness function is designed as:
[0059]
[0060] Where ci Indicates test t i The test cost, h i is the test t i The evaluation function value represents the quality of the test, and its calculation formula is:
[0061]
[0062] In the formula, d(t i ) is the test t i The number of possible faults that can be detected in the system, k(t i ) indicates test t i The minimum measurable fault among all system faults that can be detected. The measurability of a fault can be expressed by the number of test items that can detect the fault.
[0063] S(T s ) is the selection coefficient, and the calculation formula is:
[0064]
[0065] Among them, D and I represent a test set T of the system respectively. s The system fault detection rate and fault isolation rate that can be detected, D' and I' are the fault detection rate and fault isolation rate required by the system respectively.
[0066] S24, using a combination of roulette wheel selection method and best-reserved selection method, and using bubble sort to select good solutions;
[0067] S25, crossover mode selects single-point crossover, and selects two excellent solutions and two inferior solutions for crossover operation in each generation of evolution;
[0068] S26. A combination of basic position mutation and uniform mutation is used. If the mutated gene is repeated with the original individual gene, it will be randomly mutated again until every gene of the individual is different. An optimal individual protection mechanism is added to prevent the optimal individual from participating in the mutation.
[0069] S3, based on discrete particle swarm algorithm, complete the test sequence optimization, such as Figure 3 As shown, step S3 specifically includes the following steps:
[0070] S31, using discrete particle swarm algorithm to optimize and select the test set that needs to be expanded each time, including the following steps:
[0071] S311, first determine the dimension of the search space, that is, the number of tests included in the test set obtained after optimization, and set the number of particles in the community;
[0072] S312. In the discrete particle swarm algorithm, the speed update formula of each particle is
[0073]
[0074] Among them, w is the coefficient of the particle itself maintaining its original speed, c1 is the weight coefficient of the particle's own historical optimal position, c2 is the weight coefficient of the particle following the optimal position of the entire group, ξ and η are random numbers in the interval [0,1];
[0075] The particle update formula is:
[0076]
[0077] S313. Since the principle of the DPSO algorithm in optimizing the selection of test items is to use relatively less test cost to first detect and isolate the fault source with a relatively high probability in the system, the designed test evaluation function is:
[0078]
[0079] Among them, P(t i ) is the test t i The average probability of all possible failures of the system that can be detected, N(t i ) is t i The number of faults that can be detected, S(t i ) is t i The minimum measurable magnitude of a system fault among all system faults detected;
[0080] S314, the evaluation function of the test set is:
[0081]
[0082] Where, T s represents the test set randomly selected by the algorithm, T represents all the test items in the system, and N is T s The number of test items included in FD and η Fl Respectively represent the test set T s The fault detection rate and isolation rate of the system after the test, c i Indicates test t i The cost, h(t i ) indicates test t i The larger the evaluation function value of a test set, the greater the possibility of selecting this test set.
[0083] Define a particle of the discrete particle swarm algorithm as a binary vector x i =(x i1 , xi2 , …, x iN ), x i represents the position of the ith particle, x ij (i=1, 2, ..., M; j=1, 2, ..., N) indicates whether the jth test of the i-th particle is selected. If selected, its value is 1, otherwise it is 0. M represents the number of particles in the particle group, and N represents the number of tests.
[0084] S32, using the AND-OR graph heuristic search algorithm to expand the optimized result, specifically including the following steps:
[0085] The system parameters used are combined into a four-tuple (S, p, T, c), where S = {s0, s1, s2..., s m} represents a finite set of system states, s0 represents the system fault-free state, s i (1≤i≤m) represents different fault states of the system; p=[p(s0), p(s1), …, p(s m )] r is the prior probability vector of the system in each state, p(s0) represents the probability of the system being fault-free, under the assumption of a single fault mode, T={t1,t2,…,t n} is a set of n available tests; c = [c1, c2, ..., c n ] r The vector represents the test cost, which includes time cost, labor cost and other economic costs. j (1≤j≤n), there is a binary vector d ij It means that if d ij =1, indicating t j Fault conditions can be detected j , obviously 0j =0, j=1≤j≤n.
[0086] S321, generating a Huffman code of the system initial state according to the system state set and the prior probability vector of each state in the mathematical model of the system test sequence optimization problem;
[0087] S322, calculating the Huffman coding length of each state of the system, and expanding the initial node of the system according to the fault-test correlation matrix;
[0088] S323, in the initial fault state set S = (s1, s2, ...s 12 ) to test t j After that, the fault set is divided into two parts, S jp By not being able to be tested jThe detected system fault consists of jf By being able to be j The detected fault composition calculates the evaluation function value of the corresponding test based on the probability of the state set and the heuristic function value of the state set.
[0089] For any state set x of an "or node", the formula for the cost estimate is:
[0090]
[0091] Among them, c j is the test t j The price, h * (x,t j ) represents the application subnode t j The cost of isolating x is that t j is a child node of x, so h * (x,t j ) is the "with node" (x, t j )’s cost value;
[0092] h * (x i , t j )=p(x jp )·h * (x jp )+p(x jf )·h * (x jf ) (9)
[0093] Among them, x jp and x jf They have been tested j The passed failure subset and failed failure subset after x jp ∪x jf =x, (j=1, 2, ...n).
[0094] The estimated value of any state set node x is:
[0095]
[0096] In the formula, p(x jp ) and p(x if ) are calculated by equation (11) and equation (12) respectively:
[0097]
[0098] h * (x jp ) and h * (x if ) are nodes xjp and x if The heuristic function of the estimated value is:
[0099]
[0100] In the formula, w * (x) is the system fault state S i The Huffman code length of w'(x) is w * The integer part of (x).
[0101] This embodiment takes a complex system as an example to optimize the test strategy, and the specific steps are as follows:
[0102] Based on step S1, on the basis of clarifying the functional structure of the complex system, a test simulation model of the system is established, and a fault-test correlation matrix is established. The fault-test correlation matrix is shown in Table 1:
[0103] Table 1 Fault-test correlation matrix
[0104]
[0105] Based on step S2, the algorithm operation results for different numbers of test items of the system are statistically shown in Table 2:
[0106] Table 2 Statistics of algorithm operation results for different numbers of test items
[0107]
[0108] When there are 11 test items in the algorithm optimization result, the minimum number of test items is achieved while meeting the system testability index. When 9 and 10 test items are set respectively, although the fault detection rate reaches 100%, fuzzy groups appear in the system faults, and it is impossible to accurately locate and isolate all faults, that is, the fault isolation rate does not reach 100%. When the optimization result is set to include 11 test items, the gene sequence number of the optimal individual selected by the algorithm is {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, and the fitness function value is 0.424242.
[0109] Based on step S3, the system test sequence optimization is completed by combining the advantages of the AND-OR graph heuristic search algorithm and the discrete particle swarm algorithm. The obtained system optimal test strategy decision tree is as follows: Figure 4 shown.
[0110] Therefore, the present invention adopts the above-mentioned test strategy optimization method based on genetic algorithm and discrete particle swarm algorithm, obtains the optimal test item set through genetic algorithm, and completes the system test sequence optimization by combining the advantages of the two algorithms, namely, AND-OR graph heuristic search algorithm and discrete particle swarm algorithm. Compared with traditional algorithms, the calculation process and amount of calculation are greatly reduced.
[0111] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that they can still modify or replace the technical solution of the present invention with equivalents, and these modifications or equivalent replacements cannot cause the modified technical solution to deviate from the spirit and scope of the technical solution of the present invention.
Claims
1. A test strategy optimization method based on genetic algorithm and discrete particle swarm algorithm, characterized in that: The following steps are involved: S1. Establish a test simulation model for the system and establish a fault-test correlation matrix; S2, based on genetic algorithm, improve the test item selection strategy; S3. Based on discrete particle swarm algorithm, complete the test sequence optimization.
2. The test strategy optimization method based on genetic algorithm and discrete particle swarm algorithm according to claim 1, characterized in that: Step S1 specifically includes the following steps: S11. Clarify the basic structure of the object under test and conduct test simulation modeling on the object under test according to the independence principle and physical division principle; S12. Based on the test simulation model, the system reachability matrix is calculated by using the Warshall algorithm through the system adjacency matrix, and then the complete fault correlation matrix is calculated; S13. Combine the complete failure correlation matrix and the functional failure correlation matrix to obtain the system failure-test correlation matrix.
3. The test strategy optimization method based on genetic algorithm and discrete particle swarm algorithm according to claim 1, characterized in that: Step S2 specifically includes the following steps: S21, initialize the population, determine the size of the solution set, the crossover probability of two individuals in the solution set, the probability of a certain individual mutation, and the termination evolution condition of the population; S22, using real number coding to directly encode the individual according to the test sequence number, and using the test sequence number to form the sequence number of the individual gene, while ensuring that the chromosome gene sequence is not repeated in the process of randomly generating the individual gene; S23. Design a fitness function to evaluate the excellence of individuals; S24, using a combination of roulette wheel selection method and best-reserved selection method, and using bubble sort to select good solutions; S25, crossover mode selects single-point crossover, and selects two excellent solutions and two inferior solutions for crossover operation in each generation of evolution; S26. A combination of basic position mutation and uniform mutation is used. If the mutated gene is repeated with the original individual gene, it will be randomly mutated again until every gene of the individual is different. An optimal individual protection mechanism is added to prevent the optimal individual from participating in the mutation.
4. The test strategy optimization method based on genetic algorithm and discrete particle swarm algorithm according to claim 1, characterized in that: Step S3 specifically includes the following steps: S31, using discrete particle swarm algorithm to optimize and select the test set that needs to be expanded each time; S32. Expand the optimized results using the AND-OR graph heuristic search algorithm.
5. The test strategy optimization method based on genetic algorithm and discrete particle swarm algorithm according to claim 4 is characterized in that: Step S31 specifically includes the following steps: S311, first determine the dimension of the search space, that is, the number of tests included in the test set obtained after optimization, and set the number of particles in the community; S312. In the discrete particle swarm algorithm, the speed update formula of each particle is Among them, w is the coefficient of the particle itself maintaining its original speed, c1 is the weight coefficient of the particle's own historical optimal position, c2 is the weight coefficient of the particle following the optimal position of the entire group, ξ and η are random numbers in the interval [0,1]; The particle update formula is: S313. Design test evaluation function: Among them, P(t i ) is the test t i The average probability of all possible failures of the system that can be detected, N(t i ) is t i The number of faults that can be detected, S(t i ) is t i The minimum measurable magnitude of a system fault among all system faults detected; S314, the evaluation function of the test set is: Where, T s represents the test set randomly selected by the algorithm, T represents all the test items in the system, and N is T s The number of test items included in FD and η Fl Respectively represent the test set T s The fault detection rate and isolation rate of the system after the test, c i Indicates test t i The cost, h(t i ) indicates test t i The evaluation function value of .
6. The test strategy optimization method based on genetic algorithm and discrete particle swarm algorithm according to claim 4 is characterized in that: Step S32 specifically includes the following steps: S321, generating a Huffman code of the system initial state according to the system state set and the prior probability vector of each state in the mathematical model of the system test sequence optimization problem; S322, calculating the Huffman coding length of each state of the system, and expanding the initial node of the system according to the fault-test correlation matrix; S323, in the initial fault state set S=(s1, s2, ...s 12 ) to test t j After that, the fault set is divided into two parts, S jp By not being able to be tested j The detected system fault consists of jf By being able to be j The detected fault composition calculates the evaluation function value of the corresponding test based on the probability of the state set and the heuristic function value of the state set.
