A resource-cost-based strategy selection method, system, electronic device, and storage medium
By calculating the memory and CPU rate thresholds to evaluate hardware resource overhead and combining them with a multi-objective optimization algorithm to select a strategy, the problem of resource balancing in software function implementation was solved, thus improving system performance.
Patent Information
- Application Number
- CN202210322851.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-30
- Publication Date
- 2025-09-30
- Estimated Expiration
- 2042-03-30
AI Technical Summary
In the existing technology, during the software function implementation process, it is a challenge to select a strategy solution that reasonably balances function implementation and resource overhead using limited hardware resources.
By calculating the memory occupied and the minimum CPU speed requirements of the strategy scheme, setting the corresponding threshold, and combining the multi-objective optimization algorithm, the optimal strategy scheme is evaluated and selected to balance function implementation and resource overhead.
While satisfying the hardware resources and function realization, the strategy scheme with the best function realization degree or the best resource consumption is selected to improve the performance of the hardware and software system.
Smart Images

Figure CN115016926B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of information security, and in particular to a resource expenditure-based strategy selection method, system, electronic device and storage medium. Background Art
[0002] Software functionality typically involves one or more of the following: computation, search, selection, and security. These problems are primarily addressed using various strategies (i.e., algorithms and programs). Software requires a strategy scheme composed of these strategies to achieve its functionality. Currently, a large number of strategies have been accumulated to address computation, search, selection, and security issues in software. Multiple different strategies are often applicable to software functionality, and each strategy scheme achieves varying degrees of functionality. Furthermore, with the development of network and information technologies, most social activities are now implemented using software. Multiple software programs are typically installed on a single hardware device, and the hardware resources available to each software are limited. Software resource overhead is crucial for both hardware and software systems. Therefore, selecting a strategy scheme that strikes a balance between functionality and resource overhead from among multiple applicable strategies is crucial for improving the performance of both hardware and software systems. Summary of the Invention
[0003] The purpose of the present invention is to solve the above-mentioned problems in the prior art, and to provide a strategy selection method, system, electronic device and storage medium based on resource overhead. The present invention evaluates the hardware resource overhead by calculating the memory occupied by the strategy and the minimum CPU speed requirement and setting corresponding thresholds, and at the same time evaluates the degree of function realization to select an optimal strategy that reasonably balances the degree of function realization and resource overhead.
[0004] In a first aspect, the present invention provides a method for selecting a policy scheme based on resource expenditure, the method comprising the following steps:
[0005] S1, calculates the memory required for each alternative strategy and the minimum CPU speed required to complete the operation within the specified time;
[0006] S2, calculate the functional realization degree of each alternative strategy scheme;
[0007] S3, based on the memory occupied, minimum CPU speed required and functional realization degree of the alternative strategies, an effective strategy is selected from the alternative strategies through a multi-objective optimization algorithm;
[0008] S4, screening the effective strategy solutions according to the set memory, CPU speed and function realization degree thresholds to obtain the optimal strategy solution.
[0009] Preferably, in step S4,
[0010] When there is an effective policy solution that meets the memory, CPU speed and function realization degree threshold requirements, the effective policy solution with the highest function realization degree among the effective policy solutions that meet all the threshold requirements is selected as the preferred policy solution;
[0011] When there is no effective policy solution that meets the memory, CPU speed and function realization threshold requirements, an effective policy solution that meets the function realization threshold requirements is extracted as a reference policy solution. The total cost of memory and CPU speed of each reference policy solution is calculated, and the reference policy solution with the lowest total cost is extracted as the preferred policy solution.
[0012] Preferably, in step S3, the multi-objective optimization algorithm is executed multiple times to screen the alternative strategy solutions, and the alternative strategy solutions selected by the multi-objective optimization algorithm each time are de-duplicated and merged to obtain an effective strategy solution.
[0013] Preferably, the step S1 includes the following sub-steps:
[0014] S11, for a single alternative strategy solution, the program whose logic before and after its existence needs to be run serially is divided into one program body, and the program that can be run in parallel is divided into two program bodies, thereby dividing the single alternative strategy solution into multiple parallel program bodies;
[0015] S12, calculating the minimum CPU speed required for multiple parallel programs to complete execution within a specified time, and obtaining the minimum CPU speed required for the alternative strategy solution to complete execution within the specified time;
[0016] S13, summing up the memory required by the multiple parallel program bodies to obtain the memory required by the alternative strategy solutions.
[0017] Preferably, the memory required to be occupied by the program body is obtained by summing the memory occupied by the program body's input and output data, the memory occupied by the code, and the memory occupied by the program body's execution.
[0018] Preferably, the memory required by the alternative strategy solution is determined by the following formula:
[0019]
[0020] Where M(k) represents the memory required by the kth alternative strategy solution. Indicates the memory occupied by the input and output data of the i-th program body of the k-th alternative strategy solution, The code of the i-th program body representing the k-th alternative strategy solution occupies memory, Indicates the memory occupied by the running of the i-th program body of the k-th alternative strategy;
[0021]
[0022] Where m represents the number of alternative strategy solutions, n(k) represents the number of the kth alternative strategy solution program body, S ki (num ki ) represents the space complexity of the i-th program body of the k-th alternative strategy solution, num ki The data size of the memory occupied by the i-th program body of the k-th alternative strategy solution is represented by γ ki Represents the space complexity proportional coefficient of the i-th program body of the k-th alternative strategy solution.
[0023] Preferably, the minimum CPU speed required for the alternative strategy to complete execution within the specified time is determined by the following formula:
[0024]
[0025] Where m represents the number of alternative strategies, n(k) represents the number of programs of the kth alternative strategy, t represents the time limit for the specified strategy to run, V(k) represents the minimum CPU speed required for the kth alternative strategy to run within the specified time, and O ki (num ki ) represents the time complexity of the i-th program body of the k-th alternative strategy solution, num ki The data size of the number of code runs affected by the i-th program body of the k-th alternative strategy, λ ki Represents the time complexity proportional coefficient of the i-th program body of the k-th alternative strategy solution.
[0026] In a second aspect, the present invention provides a policy scheme selection system based on resource expenditure, the system comprising:
[0027] The acquisition module is used to obtain alternative strategy solutions and obtain the set memory, CPU speed and function realization degree thresholds;
[0028] A processing module is used to divide and process each alternative strategy scheme. Specifically, for a single alternative strategy scheme, the program whose logic before and after its existence needs to be run serially is regarded as a program body, and the program that can be run in parallel is regarded as a program body, thereby dividing the single alternative strategy scheme into multiple parallel program bodies;
[0029] Memory calculation module, used to calculate the memory required by each alternative strategy solution;
[0030] The rate calculation module is used to calculate the minimum CPU rate required for each alternative strategy to complete within the specified time;
[0031] A degree calculation module is used to calculate the degree of functional realization of each alternative strategy solution;
[0032] The selection module is used to select an effective strategy from the alternative strategy schemes through a multi-objective optimization algorithm based on the memory occupied by the alternative strategy schemes, the required minimum CPU speed and the degree of function realization; the effective strategy schemes are screened according to the set memory, CPU speed and function realization degree thresholds to obtain the optimal strategy scheme.
[0033] In a third aspect, the present invention provides an electronic device comprising a memory, a computer program stored thereon, and a processor, wherein the processor implements the above-mentioned resource overhead-based policy selection method when executing the computer program.
[0034] In a fourth aspect, the present invention provides a storage medium storing computer-executable instructions. When the computer-executable instructions are loaded and executed by a processor, the above-mentioned resource-cost-based policy selection method is implemented.
[0035] In summary, the present invention has the following beneficial effects: by calculating the memory occupied by the policy scheme and the minimum CPU speed requirement and setting the corresponding threshold, the hardware resource overhead is evaluated, and at the same time, the functional realization degree of the policy scheme is evaluated. When the policy scheme satisfies both the hardware resource overhead and the functional realization degree, the optimal functional realization degree is preferred; when the policy scheme only satisfies the functional realization degree, the optimal hardware resource overhead is preferred, thereby selecting the preferred policy scheme that reasonably balances the functional realization degree and resource overhead.
[0036] Additional aspects and advantages of the present invention will be set forth in part in the description which follows and, in part, will be obvious from the description which follows, or may be learned by practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the technical solutions and advantages of the embodiments of the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the prior art descriptions. 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 paying any creative work.
[0038] Figure 1 The figure is a flow chart of a method according to a specific embodiment of the present invention.
[0039] Figure 2 This is a flow chart of step 1 of a specific embodiment of the present invention.
[0040] Figure 3 This is a system module block diagram of a specific embodiment of the present invention. DETAILED DESCRIPTION
[0041] In order to make the purpose, technical solutions and advantages disclosed in the embodiments of the present invention clearer, the embodiments of the present invention are further described in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the embodiments of the present invention and are not intended to limit the embodiments of the present invention. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application. Examples of the embodiments are shown in the accompanying drawings, where the same or similar numbers throughout represent the same or similar elements or elements with the same or similar functions.
[0042] It should be noted that the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or server that includes a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units that are not explicitly listed or are inherent to these processes, methods, products or devices.
[0043] The embodiment of the present application provides a method for selecting a strategy scheme based on resource cost, such as Figure 1 As shown, including:
[0044] Step S1 calculates the memory requirements of each candidate strategy and the minimum CPU speed required to execute within the specified time. The latency of a strategy is directly related to user experience. Software functions generally have varying degrees of latency requirements. Meeting latency requirements is particularly important for industrial control software, which carries life-threatening risks.
[0045] In some embodiments of the present invention, Figure 2 As shown, step S1 includes the following sub-steps:
[0046] S11, for a single alternative strategy solution, the program whose logic before and after its existence needs to be run serially is taken as one program body, and the program that can be run in parallel is taken as a program body respectively, and the single alternative strategy solution is divided into multiple parallel program bodies.
[0047] S12, calculating the minimum CPU speed required for multiple parallel program bodies to complete running within the specified time, and obtaining the minimum CPU speed required for the alternative strategy solution to complete running within the specified time.
[0048] In some embodiments of the present invention, the minimum CPU speed required for the alternative strategy to complete execution within the specified time is determined by the following formula:
[0049]
[0050] Where m represents the number of alternative strategies, n(k) represents the number of programs of the kth alternative strategy, t represents the time limit for the specified strategy to run, V(k) represents the minimum CPU speed required for the kth alternative strategy to run within the specified time, and O ki (num ki ) represents the time complexity of the i-th program body of the k-th alternative strategy solution, num ki The data size of the number of code runs affected by the i-th program body of the k-th alternative strategy, λ ki Represents the time complexity proportional coefficient of the i-th program body of the k-th alternative strategy solution.
[0051] S13, summing up the memory required by the multiple parallel program bodies to obtain the memory required by the alternative strategy solutions.
[0052] In some embodiments of the present invention, the memory required by the program body is obtained by summing the memory occupied by the program body's input and output data, the memory occupied by the code, and the memory occupied by the execution. The memory required by the alternative strategy scheme is determined by the following formula:
[0053]
[0054] Where M(k) represents the memory required by the kth alternative strategy solution. The memory occupied by the input and output data of the i-th program body of the k-th alternative strategy is directly related to the amount of input and output data imported into the memory. The memory occupied by the code of the i-th program body representing the k-th alternative strategy depends on the code length of the program. The memory occupied by the execution of the i-th program body of the k-th alternative strategy depends on the intermediate variables that need to be stored during the program execution and is directly related to the space complexity of the program.
[0055]
[0056] Where m represents the number of alternative strategy solutions, n(k) represents the number of the kth alternative strategy solution program body, S ki (num ki ) represents the space complexity of the i-th program body of the k-th alternative strategy solution, num ki The data size of the memory occupied by the i-th program body of the k-th alternative strategy solution is represented by γ ki Represents the space complexity proportional coefficient of the i-th program body of the k-th alternative strategy solution.
[0057] Step S2: Calculate the degree of functional realization of each alternative strategy solution.
[0058] Alternative strategies correspond to software functions involving one or more of the following: calculation, search, selection, classification, judgment, prediction, and security. The degree of their functional realization is primarily reflected in their ability to resolve the relevant problem. If an alternative strategy addresses only a single problem, its functional realization can correspond to its ability to resolve that problem, such as accuracy or security assurance. If an alternative strategy addresses multiple problems, its functional realization can correspond to the sum of the individual strategies' respective solutions. The degree of problem resolution can be calculated using existing algorithms and models for evaluating strategy metrics, such as accuracy assessment algorithms and security assurance capability assessment models.
[0059] In step S3, an effective strategy is selected from the candidate strategies based on their memory usage, minimum CPU speed, and functional implementation. The multi-objective optimization algorithm may adopt the existing NSGA-II algorithm.
[0060] Since the multi-objective optimization algorithm cannot guarantee 100% accuracy and there is a risk of missing a selection, in some embodiments of the present invention, the multi-objective optimization algorithm is executed multiple times in step S3 to screen the alternative strategy solutions, and the alternative strategy solutions selected by the multi-objective optimization algorithm each time are de-duplicated and merged to obtain an effective strategy solution.
[0061] Step S4: Screen the effective strategies according to the set thresholds of memory, CPU speed and function realization degree to obtain the optimal strategy.
[0062] In some embodiments of the present invention, in step S4, when there is an effective policy solution that meets the threshold requirements of memory, CPU speed and function realization degree, the effective policy solution with the highest function realization degree among the effective policy solutions that meet all the threshold requirements is extracted as the preferred policy solution.
[0063] When there is no effective policy solution that meets the memory, CPU speed and function realization threshold requirements, an effective policy solution that meets the function realization threshold requirements is extracted as a reference policy solution. The total cost of the memory and CPU speed of each reference policy solution is calculated, and the reference policy solution with the lowest total cost is extracted as the preferred policy solution. Then, the system hardware capabilities are improved according to the memory and minimum CPU speed of the preferred policy solution.
[0064] The embodiment of the present invention evaluates the hardware resource overhead by calculating the memory occupied by the policy scheme and the minimum CPU speed requirement and setting corresponding thresholds, and at the same time evaluates the functional implementation degree of the policy scheme. When the policy scheme satisfies both the hardware resource overhead and the functional implementation degree, the optimal functional implementation degree is preferred. When the policy scheme only satisfies the functional implementation degree, the optimal hardware resource overhead is preferred, thereby selecting the preferred policy scheme that reasonably balances the functional implementation degree and resource overhead.
[0065] The embodiment of the present application also provides a policy scheme selection system based on resource cost, such as Figure 3 As shown, including:
[0066] An acquisition module is used to obtain all applicable alternative strategy solutions and obtain the set memory, CPU speed and function realization degree thresholds;
[0067] A processing module is used to divide and process each alternative strategy scheme. Specifically, for a single alternative strategy scheme, the program whose logic before and after its existence needs to be run serially is regarded as a program body, and the program that can be run in parallel is regarded as a program body, thereby dividing the single alternative strategy scheme into multiple parallel program bodies;
[0068] The memory calculation module is used to calculate the memory required by each alternative strategy scheme. Specifically, the memory required by multiple parallel program bodies is summed up to obtain the memory required by the alternative strategy scheme.
[0069] The rate calculation module is used to calculate the minimum CPU rate required for each alternative strategy to complete within the specified time; specifically, it calculates the minimum CPU rate required for multiple parallel programs to complete within the specified time, and obtains the minimum CPU rate required for the alternative strategy to complete within the specified time;
[0070] A degree calculation module is used to calculate the degree of functional realization of each alternative strategy solution;
[0071] The selection module is used to select an effective strategy from the alternative strategy schemes through a multi-objective optimization algorithm based on the memory occupied by the alternative strategy schemes, the required minimum CPU speed and the degree of function realization; the effective strategy schemes are screened according to the set memory, CPU speed and function realization degree thresholds to obtain the optimal strategy scheme.
[0072] An embodiment of the present application further provides an electronic device comprising a memory and a processor, wherein the memory and processor may be connected via a bus or other means. The memory may be used to store software programs, computer programs, and modules, such as the programs / modules corresponding to the aforementioned resource cost-based policy selection method; the processor implements the aforementioned resource cost-based policy selection method by executing the computer programs and modules in the memory.
[0073] The processor may be a central processing unit, a digital signal processor, an application-specific integrated circuit, a field programmable gate array, etc., and the memory may be a high-speed random access memory, a non-volatile memory, etc.
[0074] The present application also provides a storage medium storing computer-executable instructions. When loaded and executed by a processor, the computer-executable instructions implement the aforementioned resource-cost-based policy selection method. The storage medium may be a combination of one or more of a magnetic disk, an optical disk, a read-only memory, a random access memory, a flash memory, a hard disk, and the like.
[0075] It should be noted that the order of the embodiments of the present invention described above is for illustrative purposes only and does not represent the superiority or inferiority of the embodiments. The above description is of specific embodiments of this specification, and other embodiments are within the scope of the appended claims. In some cases, the actions or steps described in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the accompanying drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0076] The various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to each other. Each embodiment focuses on the differences from other embodiments.
[0077] Those skilled in the art will appreciate that all or part of the steps in the above embodiments can be implemented by hardware or by programming the relevant hardware. The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention shall be included within the scope of protection of the present invention.
Claims
1. A strategy selection method based on resource expenditure, characterized in that: The method comprises the following steps: S1, calculates the memory required for each alternative strategy and the minimum CPU speed required to complete the operation within the specified time; S2, calculate the functional realization degree of each alternative strategy scheme; S3, based on the memory occupied, minimum CPU speed required and functional realization degree of the alternative strategies, select the effective strategy from the alternative strategies through the multi-objective optimization algorithm; S4, screening the effective strategy solutions according to the set memory, CPU speed and function realization degree thresholds to obtain the optimal strategy solution; The step S1 includes the following sub-steps: S11, for a single alternative strategy solution, the program whose logic needs to be run serially before and after its existence is taken as a program body, and the program that can be run in parallel is taken as a program body, and the single alternative strategy solution is divided into multiple parallel program bodies; S12, calculating the minimum CPU speed required for the multiple parallel program bodies to complete the execution within the specified time, and obtaining the minimum CPU speed required for the alternative strategy solution to complete the execution within the specified time; S13, summing the memory required to be occupied by the multiple parallel program bodies respectively, and obtaining the memory required to be occupied by the alternative strategy solution; The memory required by the alternative strategy is determined by the following formula: Where M(k) represents the memory required by the kth alternative strategy solution. Indicates the memory occupied by the input and output data of the i-th program body of the k-th alternative strategy solution, The code of the i-th program body representing the k-th alternative strategy solution occupies memory, Indicates the memory occupied by the running of the i-th program body of the k-th alternative strategy; Where m represents the number of alternative strategy solutions, n(k) represents the number of the kth alternative strategy solution program body, S ki (num ki ) represents the space complexity of the i-th program body of the k-th alternative strategy solution, num ki The data size of the memory occupied by the i-th program body of the k-th alternative strategy solution is represented by γ ki Represents the space complexity proportional coefficient of the i-th program body of the k-th alternative strategy solution; The minimum CPU speed required for the alternative strategy to complete within the specified time is determined by the following formula: Where m represents the number of alternative strategies, n(k) represents the number of programs of the kth alternative strategy, t represents the time limit for the specified strategy to run, V(k) represents the minimum CPU speed required for the kth alternative strategy to run within the specified time, and O ki (num ki ) represents the time complexity of the i-th program body of the k-th alternative strategy solution, num ki The data size of the number of code runs affected by the i-th program body of the k-th alternative strategy, λ ki Represents the time complexity proportional coefficient of the i-th program body of the k-th alternative strategy solution.
2. The resource cost-based strategy selection method according to claim 1, characterized in that: In step S4, when there is an effective policy solution that meets the threshold requirements of memory, CPU speed and function realization degree, the effective policy solution with the highest function realization degree among the effective policy solutions that meet all threshold requirements is extracted as the preferred policy solution; when there is no effective policy solution that meets the threshold requirements of memory, CPU speed and function realization degree, the effective policy solution that meets the threshold requirements of function realization degree is extracted as the reference policy solution, the total cost of memory and CPU speed of each reference policy solution is calculated, and the reference policy solution with the lowest total cost is extracted as the preferred policy solution.
3. The resource cost-based strategy selection method according to claim 1, characterized in that: In step S3, the multi-objective optimization algorithm is executed multiple times to screen the alternative strategy solutions, and the alternative strategy solutions selected by the multi-objective optimization algorithm each time are de-duplicated and merged to obtain an effective strategy solution.
4. A resource cost-based strategy selection method according to any one of claims 1 to 3, characterized in that: The memory required to be occupied by the program body is obtained by summing the memory occupied by the program body's input and output data, the memory occupied by the code, and the memory occupied by the running process.
5. A strategy selection system based on resource expenditure, characterized in that: The system comprises: The acquisition module is used to obtain alternative strategy solutions and obtain the set memory, CPU speed and function realization degree thresholds; A processing module is used to divide and process each alternative strategy scheme. Specifically, for a single alternative strategy scheme, the program whose logic before and after its existence needs to be run serially is regarded as a program body, and the program that can be run in parallel is regarded as a program body, thereby dividing the single alternative strategy scheme into multiple parallel program bodies; The memory calculation module is used to calculate the memory required for each alternative strategy scheme; the memory required for the alternative strategy scheme is determined by the following formula: Where M(k) represents the memory required by the kth alternative strategy solution. Indicates the memory occupied by the input and output data of the i-th program body of the k-th alternative strategy solution, The code of the i-th program body representing the k-th alternative strategy solution occupies memory, Indicates the memory occupied by the running of the i-th program body of the k-th alternative strategy; Where m represents the number of alternative strategy solutions, n(k) represents the number of the kth alternative strategy solution program body, S ki (num ki ) represents the space complexity of the i-th program body of the k-th alternative strategy solution, num ki The data size of the memory occupied by the i-th program body of the k-th alternative strategy solution is represented by γ ki Represents the space complexity proportional coefficient of the i-th program body of the k-th alternative strategy solution; The rate calculation module is used to calculate the minimum CPU rate required for each alternative strategy to be completed within the specified time; the minimum CPU rate required for the alternative strategy to be completed within the specified time is determined by the following formula: Where m represents the number of alternative strategies, n(k) represents the number of programs of the kth alternative strategy, t represents the time limit for the specified strategy to run, V(k) represents the minimum CPU speed required for the kth alternative strategy to run within the specified time, and O ki (num ki ) represents the time complexity of the i-th program body of the k-th alternative strategy solution, num ki The data size of the number of code runs affected by the i-th program body of the k-th alternative strategy, λ ki The time complexity proportional coefficient of the i-th program body of the k-th alternative strategy solution; A degree calculation module is used to calculate the degree of functional realization of each alternative strategy solution; The selection module is used to select an effective strategy from the alternative strategy schemes through a multi-objective optimization algorithm based on the memory occupied by the alternative strategy schemes, the required minimum CPU speed and the degree of function realization; the effective strategy schemes are screened according to the set memory, CPU speed and function realization degree thresholds to obtain the optimal strategy scheme.
6. An electronic device comprising a memory, a computer program stored therein, and a processor, wherein: When the processor executes the computer program, the resource cost-based policy scheme selection method according to any one of claims 1 to 5 is implemented.
7. A storage medium, characterized in that: The storage medium stores computer-executable instructions, and when the computer-executable instructions are loaded and executed by the processor, the resource cost-based policy scheme selection method according to any one of claims 1 to 5 is implemented.