Resource allocation method and device based on improved genetic algorithm, equipment and medium
By improving the chromosome coding and optimization operations of the genetic algorithm, the resource allocation problem of task flow in complex tree topology structures is solved, and efficient resource allocation and task scheduling is achieved.
Patent Information
- Application Number
- CN202510354337.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-25
- Publication Date
- 2025-07-11
AI Technical Summary
It is difficult for the prior art to effectively apply genetic algorithms to allocate resources to multioperator tasks with multiple task flows with complex tree topology.
Improved genetic algorithms are adopted to generate initial populations through chromosome encoding, improved fitness algorithm, selection operations, improved cross-operation and improved mutation operations, and optimize resource allocation methods during the iteration process to ensure that the topological sorting of operator tasks is not destroyed.
Quickly find the optimal resource allocation method in high complexity situations, improve resource allocation efficiency, save time, and use scattered resources in the nodes to achieve the simultaneous operation of multiple operator tasks.
Smart Images

Figure HDA0005326871050000011 
Figure HDA0005326871050000012 
Figure HDA0005326871050000021
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a resource allocation method, device, equipment and medium based on an improved genetic algorithm. Background Art
[0002] Currently, most of the resource allocation methods based on genetic algorithms are aimed at the resource allocation of multiple operator tasks in a single task flow, and it is difficult to apply them to multiple operator tasks of multiple task flows. In related technologies, research on resource allocation of multiple operator tasks of multiple task flows using genetic algorithms has also been carried out, but these research results are only applicable to the resource allocation of operator tasks in a series-structured task flow, and there is no relatively effective means for the resource allocation of multiple operator tasks of multiple task flows with a complex tree topology structure. Summary of the Invention
[0003] In a first aspect, an embodiment of the present application provides a resource allocation method based on an improved genetic algorithm, characterized in that the method includes:
[0004] S1: Obtain a resource allocation task, where the resource allocation task requires allocating n operator tasks to m nodes;
[0005] S2: Perform chromosome encoding, where one chromosome includes a pair of operator sequences and node sequences, and one kind of chromosome maps one resource allocation method;
[0006] S3: Generate an initial population, initialize the iteration number to 1, and use the initial population as the current population;
[0007] S4: Calculate the fitness of each chromosome of the current population based on an improved fitness algorithm;
[0008] S5: Perform a selection operation, an improved crossover operation, and an improved mutation operation on the current population based on the fitness to obtain a next-generation population;
[0009] S6: Determine whether the current iteration number is less than the maximum iteration number. If so, increment the iteration number by 1, use the next-generation population as the current population, and transfer to S4; otherwise, transfer to S7;
[0010] S7: Select the optimal resource allocation method from the current population, and allocate the n operator tasks to the m nodes according to the optimal resource allocation method.
[0011] In a second aspect, an embodiment of the present application provides a resource allocation device based on an improved genetic algorithm, characterized in that the device includes:
[0012] A task acquisition module, configured to acquire a resource allocation task, where the resource allocation task requires allocating n operator tasks to m nodes;
[0013] An encoding module, configured to perform chromosome encoding, where one chromosome includes a pair of operator sequences and node sequences, and one such chromosome maps to one resource allocation method;
[0014] An initial population generation module, configured to generate an initial population, initialize the iteration count to 1, and use the initial population as the current population;
[0015] A fitness calculation module, configured to calculate the fitness of each chromosome in the current population based on an improved fitness algorithm;
[0016] A new population generation module, configured to perform a selection operation, an improved crossover operation, and an improved mutation operation on the current population based on the fitness to obtain the next generation population;
[0017] A judgment module, configured to judge whether the current iteration count is less than the maximum iteration count. If so, increment the iteration count by 1, use the next generation population as the current population, and transfer to S4; otherwise, transfer to S7;
[0018] A resource allocation execution module, configured to select the optimal resource allocation method from the current population and allocate the n operator tasks to the m nodes according to the optimal resource allocation method.
[0019] In a third aspect, an embodiment of the present application provides an electronic device, including: a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, it is capable of executing the method in the first aspect.
[0020] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it is capable of executing the method in the first aspect.
[0021] The beneficial effects of the present invention at least include:
[0022] 1. The present invention realizes resource allocation for operator tasks in multiple task flows with complex topological structures by using an improved genetic algorithm, and can quickly find the optimal resource allocation method in the case of high complexity, improving the efficiency of resource allocation;
[0023] 2. The present invention combines the predicted earliest start time, running resources, and running duration of operator tasks to determine the credible earliest start time and completion time one by one, can run multiple operator tasks on the same node at the same time, and can utilize the scattered resources in the node, saving time and improving the efficiency of resource allocation.
[0024] 3. Through two steps of first performing cross-operation based on the task flow on the operator sequence and then performing cross-operation based on the operator task, the present invention realizes in-depth cross-operation of operator tasks of multiple task flows with complex structures without destroying the topological sorting of operator tasks. On this basis, high-quality new populations and optimal chromosomes can be obtained, and then the optimal resource allocation method can be obtained. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following will briefly introduce the drawings required in the embodiments. Obviously, the drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0026] Figure 1 is a schematic flowchart of the resource allocation method based on the improved genetic algorithm of the present invention;
[0027] Figure 2 is a schematic diagram of the topological structure of multiple task flows of the present invention;
[0028] Figure 3 is a schematic flowchart of determining the predicted earliest start time, credible earliest start time, and completion time of each operator task one by one according to the present invention;
[0029] Figure 4 is a schematic diagram of the cross-operation process of the operator sequence of the present invention;
[0030] Figure 5 is a schematic diagram of the mutation operation process of the operator sequence of the present invention;
[0031] Figure 6 is a schematic diagram of the structure of the resource allocation device based on the improved genetic algorithm of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0032] The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the drawings in the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, rather than all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art belong to the scope of protection of the present invention.
[0033] Figure 1 is a schematic flowchart of a resource allocation method based on the improved genetic algorithm provided by the present invention. As Figure 1 shown, the method includes:
[0034] S1: Obtain a resource allocation task, where the resource allocation task requires allocating n operator tasks to m nodes;
[0035] S2: Perform chromosome encoding. The chromosome includes an operator sequence and a node sequence, and one such chromosome maps to one resource allocation method;
[0036] S3: Generate an initial population, initialize the iteration count to 1, and use the initial population as the current population;
[0037] S4: Calculate the fitness of each chromosome in the current population based on an improved fitness algorithm;
[0038] S5: Perform a selection operation, an improved crossover operation, and an improved mutation operation on the current population based on the fitness to obtain the next generation population;
[0039] S6: Determine whether the current iteration count is less than the maximum iteration count. If so, increment the iteration count by 1, use the next generation population as the current population, and transfer to S4; otherwise, transfer to S7;
[0040] S7: Select the optimal resource allocation method from the current population and allocate the n operator tasks to the m nodes according to the optimal resource allocation method.
[0041] Based on an optional implementation manner, the resource allocation method in the present invention is applicable to allocating multiple operator tasks in multiple different task flows to multiple nodes. In particular, the task flow of the present invention can be a task flow with a tree topological structure, that is, at least some operator tasks have the same preceding or succeeding operator tasks. The nodes in the present invention are machine nodes that can run operator tasks, such as servers or processors.
[0042] Based on an embodiment of the present invention, S1: Obtain a resource allocation task, where the resource allocation task requires allocating n operator tasks to m nodes, including: obtaining the resource allocation task through a control center, and the resource allocation task requires allocating n operator tasks belonging to s different task flows to m nodes.
[0043] Specifically, the control center can obtain the resource allocation task through a human-computer interaction method. Optionally, the control center can provide a human-computer interaction interface externally. The control center can also obtain the resource allocation task through other means. For example, if the user pre-inserts a resource allocation task set in the control center, the control center can obtain the resource allocation task from the pre-inserted resource allocation task set. Optionally, the control center can automatically obtain the resource allocation task for execution according to the pre-setting.
[0044] The n operator tasks can be operator tasks belonging to s different task flows, each task flow contains multiple operator tasks, and some or all of the s task flows can be task flows with a tree topology structure.
[0045] Based on an embodiment of the present invention, S2: Perform chromosome encoding, where one chromosome includes a pair of operator sequences and node sequences, and one chromosome maps a resource allocation method, including:
[0046] Randomly allocate the order between multiple task flows to obtain a task flow sequence; under the constraint of the topology structure, randomly allocate the order for each operator task within each task flow to obtain respective sub-operator sequences corresponding to each task flow; based on the task flow sequence and each sub-operator sequence, obtain an operator sequence representing the sorting of all operator tasks; randomly allocate nodes to each operator task in each task flow to obtain a node sequence.
[0047] Specifically, a chromosome includes two sequences, one is an operator sequence (Operator Series, OS) representing the running order of each operator task, and the other is a node sequence (Machine Series, MS) representing the nodes running each operator task. One chromosome maps a resource allocation method, that is, using the operator sequence OS and the node sequence MS can uniquely determine a resource allocation method.
[0048] Suppose there are s task flows J1, J2, …, J s , each task flow contains multiple operator tasks, and there are m nodes M1, M2, …, M m distributed on the system, and each node has corresponding various hardware resources. Encode the operator sequence OS, and the specific process includes:
[0049] First, determine the order between task flows. Specifically, randomly allocate the order between s task flows J1, J2, …, J s to obtain a task flow sequence JS. Use the number i of task flow J i to represent the i-th task flow, and use the numbers 1, 2, …, s of task flows J1, J2, …, J s to sort and represent the order between task flows to obtain a task flow sequence JS. Figure 2 is a schematic diagram of the topology structure of multiple task flows of the present invention. For example, there are 2 task flows J1, J2, and the topology structure is as Figure 2 shown. Randomly allocate the order between 2 task flows to obtain a task flow sequence JS: [1, 2, 1, 1, 2, 2, 2, 1, 1, 2, 1, 2, 2, 2, 1, 2].
[0050] Next, respectively determine the order between all operator tasks in each task flow. Specifically, while following task flow Ji On the premise of the topological structure, for task flow J i Randomly assign the order of operator tasks within it to obtain the sub-operator sequence OSS of the task flow i , where i ∈ [1, s]. In the sub-operator sequence OSS i , the operator task is represented by the serial number order j of the operator task within task flow J i , where j ∈ [1, num(J i ), and num(J i ) represents the total number of operator tasks within task flow J i . For example, under the condition of ensuring the topological order, randomly generate the sub-operator sequence OSS1 of task flow J1: [1, 2, 3, 6, 4, 5, 7], and randomly generate the sub-operator sequence of task flow J2 as OSS2: [1, 2, 5, 6, 3, 4, 7, 8, 9].
[0051] Then, determine the operator sequence representing the sorting of all operator tasks. Specifically, determine the order between task flows according to the task flow sequence JS, and then determine the sorting of operator tasks in each task flow according to the sub-operator sequence to obtain the operator sequence OS. In the operator sequence OS, the serial number i of task flow J i and the serial number order j of the operator task within task flow J i jointly represent operator task O ij , where i ∈ [1, s], j ∈ [1, num(J i ). For example, according to the task flow sequence JS and sub-operator sequences OSS1 and OSS2 in the above example, obtain the operator sequence OS composed of 16 operator tasks of 2 task flows: [11, 21, 12, 13, 22, 25, 26, 16, 14, 23, 15, 24, 27, 28, 17, 29], and the operator task sorting corresponding to the operator sequence OS is:
[0052] [O 11 , O 21 , O 12 , O 13 , O 22 , O 25 , O 26 , O 16 , O 14 , O 23 , O 15 , O 24 , O 27, O 28 , O 17 , O 29 . The operator sequence OS determines the execution order among all operators, and the maximum duration of executing n task flows can be calculated according to the operator sequence OS.
[0053] Encode the node sequence MS, and the process includes:
[0054] Randomly assign nodes to each operator task in the task flows J1, J2, …, J s and represent them with node numbers to obtain the node sequence MS. For example, assume there are 3 nodes M1, M2, and M3, which are represented by node numbers 1, 2, and 3 respectively. For each operator task [O 11 , O 12 , O 13 , O 14 , O 15 , O 16 , O 17 , O 21 , O 22 , O 23 , O 24 , O 25 , O 26 , O 27 , O 28 , O 29 in the task flows J1 and J2, randomly assign the corresponding nodes to obtain the node sequence MS: [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1].
[0055] So far, the encoding of the n operator tasks and m nodes in s task flows is completed, and the operator sequence OS and the node sequence MS are obtained. The total length of the operator sequence OS is the same as the total length of the node sequence MS, both of which are the total number n of all operators in all task flows.
[0056] Based on an embodiment of the present invention, S3: Generate an initial population, initialize the number of iterations to 1, and use the initial population as the current population, including:
[0057] On the premise of following the topological dependency relationship of the operator tasks, randomly generate W chromosomes, including W operator sequences that are not completely the same and W node sequences that are not completely the same, and initialize the number of iterations Gen to 1. W can be set according to actual needs, for example, it is 400. Then, set the initial population as the current population for subsequent processing.
[0058] Based on an embodiment of the present invention, S4: Calculate the fitness of each chromosome in the current population based on the improved fitness algorithm, including:
[0059] S41: According to the order of the operator sequence, determine the predicted earliest start time, the credible earliest start time, and the completion time of each operator task one by one.
[0060] Figure 3This is a schematic flowchart for determining the predicted earliest start time, credible earliest start time, and completion time of each operator task in the present invention. As Figure 3 shown, it is calculated according to the following steps:
[0061] Step a: Obtain the corresponding operator task in the order of the operator sequence.
[0062] According to the order in the operator sequence OS, obtain the operator task O corresponding to ij in the operator sequence, where i ∈ [1, s], j ∈ [0, num(J ij )], for example, obtain the first operator task in the operator sequence. The first operator task in the operator sequence refers to the operator task indicated by the first element in the operator sequence. For example, assume the first element is 10, then it indicates the operator task O i . 10 .
[0063] Step b: Calculate the predicted earliest start time of the operator task.
[0064] The predicted earliest start time of the current operator task is calculated according to the following formula:
[0065] T s (O ij ) = max{T f (O xy ) | O xy ∈ bef(Q ij )} (1)
[0066] Where, T s (O ij ) represents the predicted earliest start time of the operator task O ij , O xy ∈ bef(O ij ) represents all the prior operator tasks O ij of the operator task O xy based on the topological structure, T f (O xy ) represents the completion time of the prior operator task O xy , i, x ∈ [1, s], j, y ∈ [0, num(J i )].
[0067] It should be noted that the completion time of the operator task is calculated according to formula (2), and this part of the content will be introduced later. The predicted earliest start time of the operator task depends on the maximum value of the completion times of all the prior operator tasks based on the topological structure on the same task flow. In particular, the first operator task is the starting operator of the task flow, and there are usually no prior operator tasks based on the topological structure, so its predicted earliest start time is generally 0.
[0068] Step c: Obtain the running resources, running duration required for the current operator task, and the real-time node resource map of the node where it is located.
[0069] Specifically, the running resources and running duration required for the current operator task can be obtained from the operator task database. Before resource allocation is performed, the running resources and running duration required for all operator tasks are predicted in advance and stored in the operator task database. The running resources of the operator task include but are not limited to resources such as CPU, GPU, and memory. For example, in the operator task database, the running duration of operator task O ij is T c (O ij ), and the running resources are V c (O ij ), where the running resources include CPU resources, GPU resources, and memory resources.
[0070] Based on an embodiment of the present invention, the running resources and running duration required for all operator tasks can be predicted by training a prediction model. Specifically, a prediction model can be trained based on iTransformer, and the prediction model is used to predict the required running resources and running duration based on the historical running data of the operator task.
[0071] According to the operator sequence OS and the node sequence MS, the node M where the current operator task is located can be determined k , where k ∈ [1, m]; furthermore, the real-time node resource map F k corresponding to node M k can be obtained.
[0072] Each node has a corresponding real-time node resource map. Before operator tasks are allocated to the node, the real-time node resource map records the resource information of the node, including the CPU, GPU, and memory sizes in the node. When starting to allocate operator tasks to the node, as the operator tasks increase, the real-time node resource map also changes dynamically, and the real-time node resource map records the real-time resource occupancy of the node.
[0073] Step d: On the real-time node resource map, starting from the predicted earliest start time, search for an available interval that simultaneously satisfies the running resources and running duration, and use the start time of the available interval as the credible earliest start time.
[0074] On the real-time node resource map F k , starting from the predicted earliest start time T ij (O s ) of operator task O ij , search for an available interval that simultaneously satisfies the running duration T c (O ij) and the running resource V c (O ij )'s available interval [t a , t b , and use the start time t a of the available interval as the trusted earliest start time T ij of the operator task O sc (O ij ). In this way, during the execution stage of the operator task, the corresponding operator task O ij can be inserted into the node M sc (O ij ) at the trusted earliest start time T k .
[0075] In the embodiments of the present invention, by combining the predicted earliest start time, running resource, and running duration of the operator task to determine the trusted earliest start time, multiple operator tasks can be run on the same node simultaneously, saving time and improving the efficiency of resource allocation.
[0076] Step e: Based on the trusted earliest start time and running duration of the operator task, calculate the completion time of the operator task and update the node resource graph.
[0077] The completion time of the operator task depends on the trusted earliest start time of the operator task and the running duration of the operator task. The completion time of the operator task is calculated according to the following formula:
[0078] T f (O ij ) = T sc (O ij ) + T c (O ij ) (2)
[0079] Wherein, T f (O ij ) represents the completion time of the operator task O ij , i ∈ [1, s], j ∈ [0, num(J i )]. In the node resource graph F k of the node M k , mark the resources of the operator task O ij from the trusted earliest start time T sc (O ij ) to the completion time T f (O ij ) as occupied.
[0080] Step f: Obtain the next operator task and execute steps b - e on the next operator task.
[0081] Obtain the next operator task in the order of the operator sequence, and execute steps b to g to obtain the predicted earliest start time, credible earliest start time, and completion time of the next operator task.
[0082] Step g: Loop and execute step f until the calculation of all operator tasks in the operator sequence is completed.
[0083] Execute steps b to g for each operator task in order to obtain the corresponding predicted earliest start time, credible earliest start time, and completion time until all operator tasks are completed. Thus, the predicted earliest start time, credible earliest start time, and completion time of all operator tasks are obtained.
[0084] In the embodiments of the present invention, since the real-time node resource graph of the corresponding node is updated in each loop, the allocation of the next operator task can be determined based on the latest node resource situation, realizing the maximization of the utilization of node resources.
[0085] S42: Obtain the fitness of the chromosome based on the credible earliest start time and completion time of all operator tasks.
[0086] Specifically, obtain the minimum value among the credible earliest start times of all operator tasks in the operator sequence to obtain the start time of resource allocation; obtain the maximum value among the completion times of all operator tasks in the operator sequence to obtain the completion time of resource allocation; obtain the difference between the completion time of resource allocation and the start time of resource allocation to obtain the duration of resource allocation, and use the duration of resource allocation as the fitness of the chromosome. Among them, the fitness calculation formula is as follows:
[0087] T d =max{T f (O ij )}-min{T sc (O ij )} (3)
[0088] Among them, T d represents the fitness of the chromosome, i ∈ [1, s], j ∈ [0, num(J i )].
[0089] Obtain the fitness of each chromosome in the current population according to the methods of steps S41 - S42. The fitness of the chromosome represents the quality of the resource allocation method corresponding to the chromosome. The larger the fitness, the longer the time it takes to execute and complete all operator tasks, and the worse the corresponding resource allocation method; the smaller the fitness, the shorter the time it takes to execute and complete all operator tasks, and the better the corresponding resource allocation method.
[0090] Based on an embodiment of the present invention, S5: Perform selection operation, improved crossover operation, and improved mutation operation on the current population based on the fitness to obtain the next-generation population, including:
[0091] The improved crossover operation includes the crossover operation of the operator sequence and the crossover operation of the node sequence. Among them, the crossover operation of the operator sequence includes two crossover operations: the crossover operation based on the task flow and the crossover operation based on the operator task.
[0092] Specifically, in each iteration operation, perform a selection operation on the current population to obtain the parental chromosomes. A part of the chromosomes with the highest fitness can be selected from the current population as the parental chromosomes.
[0093] The improved crossover operation on the parental chromosomes includes the crossover operation of the operator sequence and the hybridization operation of the node sequence. The crossover operation of the operator sequence is divided into two steps, including the crossover based on the task flow and the crossover based on the operator task.
[0094] Suppose randomly select the first chromosome and the second chromosome from the parental chromosomes for the improved crossover operation. The first chromosome includes the first operator sequence OS1 and the first node sequence MS1, and the second chromosome includes the second operator sequence OS2 and the second node sequence MS2.
[0095] (1) Crossover operation of the operator sequence
[0096] It should be noted that the crossover operation of the operator sequence should not destroy the topological relationship between the operator tasks. First, perform the crossover based on the task flow, including:
[0097] Randomly select the first operator sequence OS1 and the second operator sequence OS2 from the parental chromosomes obtained through the selection operation; randomly select a task flow Ji as the target task flow, retain all the operator tasks in the first operator sequence OS1 that belong to the target task flow Ji, and delete other operator tasks; take out all the operator tasks in the second operator sequence OS2 that do not belong to the target task flow Ji one by one in order, and fill them into the vacant positions in the first operator sequence OS1 in turn to obtain the first intermediate operator sequence OSM1; retain all the operator tasks in the second operator sequence OS2 that belong to the task flow Ji, and delete other operator tasks; take out all the operator tasks in the first operator sequence OS1 that do not belong to the target task flow Ji one by one in order, and fill them into the vacant positions in the second operator sequence OS2 in turn to obtain the second intermediate operator sequence OSM2.
[0098] Figure 4 This is a schematic diagram of the process of the crossover operation of the operator sequence of the present invention. As Figure 4 shown, assume OS1 and OS2 are:
[0099] OS1: [11, 21, 12, 13, 22, 25, 26, 16, 14, 23, 15, 24, 27, 28, 17, 29]
[0100] OS2: [11, 21, 13, 12, 22, 26, 25, 16, 15, 24, 14, 28, 23, 27, 17, 29]
[0101] Assume that the task flow J2 is selected as the target task flow for cross - operation based on the task flow. For OS1, all operator tasks belonging to the task flow J2 in OS1 are retained, and other operator tasks are deleted. Then, operator tasks except those of the task flow J2 are sequentially taken from OS2 to fill the vacant positions one by one, and the obtained OSM1 is:
[0102] OSM1: [11, 21, 13, 12, 22, 25, 26, 16, 15, 23, 14, 24, 27, 28, 17, 29]
[0103] Process OS2 in the same way, and the obtained OSM2 is:
[0104] OSM2: [11, 21, 12, 13, 22, 26, 25, 16, 14, 24, 15, 28, 23, 27, 17, 29]
[0105] Next, perform cross - operation based on operator tasks, including:
[0106] Randomly select a truncation position to truncate the first intermediate operator sequence OSM1 and the second intermediate operator sequence OSM2 into front and back parts respectively; retain the front part of the first intermediate operator sequence OSM1 and delete the back part. Then, select operator tasks that do not belong to the front part of the first intermediate operator sequence OSM1 from the second intermediate operator sequence OSM2 in sequence and fill them into the vacant positions of the first intermediate operator sequence OSM1 one by one to obtain the first cross - operator sequence OSC1; retain the front part of the second intermediate operator sequence OSM2 and delete the back part. Then, select operator tasks that do not belong to the front part of the second intermediate operator sequence OSM2 from the first intermediate operator sequence OSM1 in sequence and fill them into the vacant positions of the second intermediate operator sequence OSM2 one by one to obtain the second cross - operator sequence OSC2.
[0107] Continue to refer to Appendix Figure 4 , for OSM1 and OSM2 in the above example, perform cross - operation based on operator tasks. Assume that the truncation is selected at the sixth operator task. For OSM1, truncate OSM1 into front and back parts after the sixth operator task, retain the front part of OSM1 and delete the back part. Then, select operator tasks from OSM2 in sequence and fill them into the vacant positions of OSM1 one by one to obtain OSC1 as:
[0108] OSC1: [11, 21, 13, 12, 22, 25, 26, 16, 14, 24, 15, 28, 23, 27, 17, 29]
[0109] Process OSM2 in the same way, and OSC2 is obtained as follows:
[0110] OSC2: [11, 21, 12, 13, 22, 26, 25, 16, 15, 23, 14, 24, 27, 28, 17, 29]
[0111] In the embodiments of the present invention, through two steps of first performing cross-operation based on the task flow on the operator sequence and then performing cross-operation based on the operator task, the deep cross-operation of the operator tasks of multiple task flows with complex structures is realized without destroying the topological sorting of the operator tasks. On this basis, a high-quality and reliable new population can be obtained, and then the optimal chromosome can be obtained.
[0112] (2) Cross-operation of node sequences
[0113] The cross-operation of node sequences can use single-point crossover method, two-point crossover method, multi-point crossover method or other crossover methods, and the present invention does not limit this. Perform cross-operation of node sequences on the first node sequence MS1 and the second node sequence MS2 to obtain the first cross-node sequence MSC1 and the second cross-node sequence MSC2.
[0114] Through the improved cross-operation on the parental chromosome, cross-chromosomes are obtained. For example, the first cross-operator sequence OSC1 and the first cross-node sequence MSC1, as well as the second cross-operator sequence OSC2 and the second cross-node sequence MSC2.
[0115] Next, based on an embodiment of the present invention, the improved mutation operation is introduced. The improved mutation operation includes mutation operation of operator sequence and mutation operation of node sequence.
[0116] (3) Mutation operation of operator sequence
[0117] The mutation operation of operator sequence should not destroy the topological structure of operator tasks in each task flow. The steps include:
[0118] Randomly select a third operator sequence from the crossover chromosomes obtained through the improved crossover operation; randomly select an operator task from the third operator sequence as the target operator task; starting from the target operator task, search for a boundary operator task along one direction of the operator sequence, where the boundary operator task satisfies that there is no subsequent or previous operator task of the target operator task in the interval from the target operator task to the boundary operator task; move the target operator task to any position in the interval to obtain a mutant operator sequence.
[0119] For example, select the first crossover operator sequence OSC1 as the third operator sequence. Figure 5 It is a schematic diagram of the mutation operation process of the operator sequence of the present invention.
[0120] As Figure 5 shown, randomly select an operator task O 15 from the first crossover operator sequence OSC1 as the target operator task. In the first crossover operator sequence OSC1, starting from this target operator task O 15 , search along the forward direction to obtain the boundary operator task as O 22 , that is, there is no previous operator task O 15 of the target operator task O 22 and no subsequent operator task O 15 in the interval from the operator task O 11 to the operator task O 12 . Among them, the previous operator task of an operator task refers to all operator tasks in front of this operator task in the topological structure, and the subsequent operator task of an operator task refers to all operator tasks behind this operator task in the topological structure. Move this target operator task O 17 to any position in the above interval, for example, after O 15 , to obtain the first mutant operator sequence: 25 QST1: [11,21,13,12,22,25,15,26,16,14,24,28,23,27,17,29]
[0121] QST1: [11,21,13,12,22,25,15,26,16,14,24,28,23,27,17,29]
[0122] The present invention provides a method for improving the mutation operation. By searching for the boundary operator task to find an interval that meets the mutation requirements, the mutation of the operator sequence composed of operator tasks of multiple complex task flows is realized.
[0123] (4) Mutation operation of the node sequence
[0124] The mutation operation of the node sequence can adopt the single-point mutation method or the multi-point mutation method, and the present invention does not limit this. For example, select the first crossover node sequence MSC1 for single-point mutation operation to obtain the first mutant node sequence MST1.
[0125] Based on an embodiment of the present invention, the chromosomes obtained by performing an improved crossover operation on the parental chromosomes in the current population and through an improved mutation operation can be used as the offspring chromosomes. For example, the first mutation operator sequence OST1 and the first mutation node sequence MST1 are used as the offspring chromosomes and added to the next-generation population.
[0126] Based on an embodiment of the present invention, when forming the next-generation population, a part of the chromosomes with the highest fitness can be jointly selected from all the parental chromosomes and all the offspring chromosomes in the current population as the next-generation population.
[0127] S6: Determine whether the current iteration number is less than the maximum iteration number. If so, increment the iteration number by one, use the next-generation population as the current population, and transfer to S4; otherwise, transfer to S7.
[0128] The maximum iteration number is preset. For example, it can be 400 times. If the current iteration number has not reached the maximum iteration number, steps S4 - S6 are looped to continuously perform population iteration; if the current iteration number has reached the maximum iteration number, the population iteration ends and step S7 is entered to determine the optimal resource allocation method.
[0129] S7: Select the optimal resource allocation method from the current population and allocate the n operator tasks to the m nodes according to the optimal resource allocation method.
[0130] Specifically, select the chromosome with the minimum fitness from the current population in the last iteration as the optimal chromosome, and use the resource allocation method mapped by the optimal chromosome as the optimal resource allocation method. The control center allocates the n operator tasks to the m nodes according to the optimal resource allocation method.
[0131] In an embodiment of the present invention, a resource allocation device based on an improved genetic algorithm is provided. Please refer to Figure 6 the structural schematic diagram of the resource allocation device of the improved genetic algorithm shown. The resource allocation device 600 includes:
[0132] A task acquisition module 610, configured to acquire a resource allocation task, where the resource allocation task requires allocating n operator tasks to m nodes;
[0133] An encoding module 620, configured to perform chromosome encoding, where one chromosome includes a pair of operator sequences and node sequences, and one chromosome maps one resource allocation method;
[0134] An initial population generation module 630, configured to generate an initial population, initialize the iteration number to 1, and use the initial population as the current population;
[0135] A fitness calculation module 640, configured to calculate the fitness of each chromosome of the current population based on an improved fitness algorithm;
[0136] A new population generation module 650, configured to perform a selection operation, an improved crossover operation, and an improved mutation operation on the current population based on the fitness to obtain a next-generation population;
[0137] A judgment module 660, configured to judge whether the current iteration number is less than the maximum iteration number. If so, increment the iteration number by one, use the next-generation population as the current population, and transfer to S4; otherwise, transfer to S7;
[0138] A resource allocation execution module 670, configured to select an optimal resource allocation method from the current population and allocate the n operator tasks to the m nodes according to the optimal resource allocation method.
[0139] An embodiment of the present invention further provides an electronic device, including: a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the program, the steps of the method described in any one of the foregoing method embodiments are implemented. Further, the electronic device further includes: at least one input device; at least one output device. The foregoing memory, processor, input device, and output device are connected through a bus. Among them, the input device may specifically be a camera, a touch panel, a physical button, or a mouse, etc. The output device may specifically be a display screen. The memory may be a high-speed random access memory (RAM, Random Access Memory) or a non-volatile memory, such as a disk memory. The memory is used to store a set of executable program codes, and the processor is coupled to the memory.
[0140] An embodiment of the present invention further provides a computer-readable storage medium. The computer-readable storage medium may be disposed in the electronic device in the foregoing embodiments, and the computer-readable storage medium may be the electronic device in the foregoing embodiments. A computer program is stored on the computer-readable storage medium, and when the program is executed by a processor, the steps of the method described in any one of the foregoing method embodiments are implemented. Further, the computer-readable storage medium may also be various media such as a USB flash drive, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk, or an optical disc that can store program codes.
[0141] It should be noted that in this text, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed, or further includes elements inherent in such a process, method, article or device. Without further limitation, an element defined by the statement "including one..." does not exclude the existence of additional identical elements in the process, method, article or device including that element.
[0142] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present invention shall be included within the protection scope of the present invention.
Claims
1. A resource allocation method based on an improved genetic algorithm, characterized in that, The method includes: S1: Obtain a resource allocation task, where the resource allocation task requires allocating n operator tasks to m nodes; S2: Perform chromosome encoding, where one chromosome includes a pair of operator sequences and node sequences, and one type of chromosome maps to one resource allocation method; S3: Generate an initial population, initialize the iteration count to 1, and use the initial population as the current population; S4: Calculate the fitness of each chromosome in the current population based on an improved fitness algorithm; S5: Perform a selection operation, an improved crossover operation, and an improved mutation operation on the current population based on the fitness to obtain the next-generation population; S6: Determine whether the current iteration count is less than the maximum iteration count. If so, increment the iteration count by 1, use the next-generation population as the current population, and transfer to S4; otherwise, transfer to S7; S7: Select the optimal resource allocation method from the current population and allocate the n operator tasks to the m nodes according to the optimal resource allocation method.
2. The method according to claim 1, wherein The S4: Calculating the fitness of each chromosome in the current population based on an improved fitness algorithm includes: S41: Sequentially determine the predicted earliest start time, credible earliest start time, and completion time of each operator task according to the order of the operator sequence; S42: Obtain the fitness of the chromosome based on the credible earliest start time and completion time of all operator tasks.
3. The method according to claim 2, wherein The formula for the predicted earliest start time is as follows: T s (O ij ) = max{T f (O xy ) | O xy ∈ bef(O ij )} Among them, T s (O ij ) represents the earliest predicted start time of operator task O ij . O xy ∈bef(O ij ) represents all the prior operator tasks O ij of operator task O xy based on the topological structure. T f (O xy ) represents the completion time of the prior operator task O xy . i, x ∈ [1, s], j, y ∈ [0, num(J i )], and num(J i ) represents the number of operator tasks included in task flow J i .
4. The method according to claim 3, wherein The steps for determining the credible earliest start time include: Obtain the running resources, running duration required by the operator task, and the real-time node resource map of the node where it is located; On the real-time node resource map, starting from the predicted earliest start time, search for an available interval that simultaneously satisfies the running resources and running duration, and use the start time of the available interval as the credible earliest start time.
5. The method according to claim 1, wherein The improved crossover operation includes a crossover operation of the operator sequence and a crossover operation of the node sequence. Among them, the crossover operation of the operator sequence includes two crossover operations: a crossover operation based on the task flow and a crossover operation based on the operator task.
6. The method according to claim 5, wherein The crossover operation based on the task flow includes: Randomly select a first operator sequence and a second operator sequence from the parent chromosomes obtained through the selection operation; Randomly select a task flow as the target task flow, retain all operator tasks belonging to the target task flow in the first operator sequence, and delete other operator tasks; sequentially take out all operator tasks not belonging to the target task flow in the second operator sequence and fill them into the vacant positions in the first operator sequence in turn to obtain a first intermediate operator sequence; Retain all operator tasks belonging to the task flow in the second operator sequence, and delete other operator tasks; sequentially take out all operator tasks not belonging to the target task flow in the first operator sequence and fill them into the vacant positions in the second operator sequence in turn to obtain a second intermediate operator sequence.
7. The method according to claim 6, wherein The crossover operation based on the operator task includes: Randomly select a truncation position, and truncate the first intermediate operator sequence and the second intermediate operator sequence into front and back parts respectively; Reserve the front part of the first intermediate operator sequence, delete the rear part, and sequentially select operator tasks from the second intermediate operator sequence that do not belong to the front part of the first intermediate operator sequence, and fill them into the vacant positions of the first intermediate operator sequence in order to obtain the first crossover operator sequence; Reserve the front part of the second intermediate operator sequence, delete the rear part, and sequentially select operator tasks from the first intermediate operator sequence that do not belong to the front part of the second intermediate operator sequence, and fill them into the vacant positions of the second intermediate operator sequence in order to obtain the second crossover operator sequence.
8. A resource allocation device based on an improved genetic algorithm, characterized in that, The device includes: A task acquisition module, configured to acquire a resource allocation task, where the resource allocation task requires allocating n operator tasks to m nodes; An encoding module, configured to perform chromosome encoding, where one chromosome includes a pair of operator sequences and node sequences, and one such chromosome maps one resource allocation method; An initial population generation module, configured to generate an initial population, initialize the iteration count to 1, and use the initial population as the current population; A fitness calculation module, configured to calculate the fitness of each chromosome of the current population based on an improved fitness algorithm; A new population generation module, configured to perform a selection operation, an improved crossover operation, and an improved mutation operation on the current population based on the fitness to obtain the next generation population; A judgment module, configured to judge whether the current iteration count is less than the maximum iteration count. If so, increment the iteration count by 1, use the next generation population as the current population, and transfer to S4; otherwise, transfer to S7; A resource allocation execution module, configured to select the optimal resource allocation method from the current population and allocate the n operator tasks to the m nodes according to the optimal resource allocation method.
9. An electronic device, characterized in that, The electronic device includes: A memory, a processor, and a computer program stored on the memory and executable on the processor. When the computer program is executed by the processor, the steps of the method according to any one of claims 1-7 are implemented.
10. A computer-readable storage medium, characterized in that A computer program is stored on the computer-readable storage medium. When the computer program is executed by the processor, the steps of the method according to any one of claims 1-7 are implemented.