Software package compiling method and electronic equipment
By constructing a dependency graph and using the fish swarm algorithm to optimize the compilation order of software packages, the problems of high failure rate and low efficiency in software package compilation in existing technologies are solved, and efficient and stable software package compilation is achieved.
Patent Information
- Application Number
- CN202511462970.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-14
- Publication Date
- 2025-11-11
- Estimated Expiration
- 2045-10-14
AI Technical Summary
Existing software package compilation methods do not consider dependencies, resulting in high compilation failure rates and low efficiency. Furthermore, lower-level packages may be compiled after higher-level packages, leading to dependency issues.
Construct a dependency graph, use the fish swarm algorithm to determine the compilation order of software packages, and move through the dependency graph using the fish swarm algorithm to select the target path for compilation.
It improves the success rate and efficiency of package compilation, avoids repeated compilation, optimizes the compilation order, and reduces the risk of resource contention and getting trapped in local optima.
Smart Images

Figure CN120929088A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of software testing, and more specifically to a software package compilation method and an electronic device. Background Technology
[0002] Multiple software packages may have dependencies on each other; for example, one package may need to be compiled before another can be compiled successfully. However, related software compilation methods typically do not consider the dependencies and compilation order between packages. Instead, they initiate a unified compilation process for all packages, during which the packages are compiled in parallel or out of order. This results in many packages failing to compile, requiring all packages to be compiled repeatedly until successful, leading to long compilation times and low compilation efficiency. Summary of the Invention
[0003] In view of the above problems, this application provides a software package compilation method and an electronic device.
[0004] According to a first aspect of this application, a software package compilation method is provided, comprising: constructing a dependency graph based on a set of software packages to be compiled, the dependency graph including nodes and dependencies between nodes, wherein nodes represent software packages, and dependencies between nodes indicate whether the compilation or installation of a software package corresponding to one node depends on the compilation or installation of a software package corresponding to another node; selecting multiple nodes from the dependency graph as initial positions for multiple fish in a swarm algorithm, wherein the number of multiple fish is a preset value; based on the swarm algorithm, causing the multiple fish to move sequentially to the next node in the dependency graph according to the dependencies between nodes, thereby obtaining the movement paths of each fish, the movement paths representing the sorting result of nodes in the dependency graph; selecting a target path from the movement paths of the multiple fish according to the dependencies between nodes in the movement paths; and compiling the software packages in the software package set according to the target path.
[0005] A second aspect of this application provides an electronic device, comprising: one or more processors; and a memory for storing one or more computer programs, wherein the one or more processors execute the one or more computer programs to implement the steps of the method described above.
[0006] A third aspect of this application also provides a computer-readable storage medium having a computer program or instructions stored thereon, which, when executed by a processor, implement the steps of the above-described method.
[0007] A fourth aspect of this application also provides a computer program product, including a computer program or instructions that, when executed by a processor, implement the steps of the above-described method. Attached Figure Description
[0008] The above-mentioned contents, other objects, features and advantages of this application will become clearer from the following description of embodiments with reference to the accompanying drawings, in which:
[0009] Figure 1 The diagram illustrates an application scenario of a software package compilation method and an electronic device according to embodiments of this application.
[0010] Figure 2 A flowchart of a software package compilation method according to an embodiment of this application is shown;
[0011] Figure 3 A schematic diagram showing the movement path of a school of fish according to an embodiment of this application is provided;
[0012] Figure 4 A schematic diagram of a target path according to an embodiment of this application is shown;
[0013] Figure 5 A flowchart of a software package compilation method according to another embodiment of this application is shown;
[0014] Figure 6 A schematic diagram showing the target radius and movement path corresponding to a single fish according to an embodiment of this application is provided;
[0015] Figure 7 A structural block diagram of a software package compilation apparatus according to an embodiment of this application is shown;
[0016] Figure 8 A block diagram of an electronic device suitable for implementing a software package compilation method according to an embodiment of this application is shown. Detailed Implementation
[0017] The embodiments of this application will now be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of this application. In the following detailed description, numerous specific details are set forth to provide a thorough understanding of the embodiments of this application for ease of explanation. However, it will be apparent that one or more embodiments may be implemented without these specific details. Furthermore, descriptions of well-known structures and technologies are omitted in the following description to avoid unnecessarily obscuring the concepts of this application.
[0018] The terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the scope of this application. The terms “comprising,” “including,” etc., as used herein indicate the presence of features, steps, operations, and / or components, but do not exclude the presence or addition of one or more other features, steps, operations, or components.
[0019] All terms used herein (including technical and scientific terms) have the meanings commonly understood by those skilled in the art, unless otherwise defined. It should be noted that the terms used herein are to be interpreted in a manner consistent with the context of this specification, and not in an idealized or overly rigid way.
[0020] When using expressions such as "at least one of A, B and C", they should generally be interpreted in accordance with the meaning that is commonly understood by those skilled in the art (e.g., "a system having at least one of A, B and C" should include, but is not limited to, a system having A alone, a system having B alone, a system having C alone, a system having A and B, a system having A and C, a system having B and C, and / or a system having A, B and C, etc.).
[0021] The compilation methods for related software packages typically involve sequential compilation (e.g., compiling packages in a fixed order determined by human experience) or limited parallel compilation (compiling some packages simultaneously). This can lead to some packages failing to compile due to unmet dependencies. In cases of package compilation failure, all failed packages need to be compiled again, and this process is repeated multiple times until all package dependencies are satisfied, before resolving other types of errors one by one. This results in some packages needing to be compiled multiple times, leading to long compilation times and low efficiency. Furthermore, lower-level packages that should be compiled first may be compiled after higher-level packages that are compiled later, causing dependency problems to occur even when lower-level packages compile successfully. In addition, the dependencies between packages are usually determined manually based on experience, making it difficult to accurately determine dependencies and increasing the difficulty of package compilation and installation.
[0022] In view of this, embodiments of this application provide a software package compilation method, comprising: constructing a dependency graph based on a set of software packages to be compiled, the dependency graph including nodes and dependencies between nodes, wherein nodes represent software packages, and dependencies between nodes indicate whether the compilation or installation of a software package corresponding to one node depends on the compilation or installation of a software package corresponding to another node; selecting multiple nodes from the dependency graph as initial positions for multiple fish in a swarm algorithm, wherein the number of multiple fish is a preset value; based on the swarm algorithm, causing multiple fish to start from their respective initial positions and move sequentially to the next node in the dependency graph according to the dependencies between nodes, obtaining the movement paths of each fish, the movement paths representing the sorting result of nodes in the dependency graph; selecting a target path from the movement paths of multiple fish according to the dependencies between nodes in the movement paths; and compiling the software packages in the software package set according to the target path.
[0023] Figure 1The diagram illustrates an application scenario of a software package compilation method and an electronic device according to embodiments of this application.
[0024] like Figure 1 As shown, application scenario 100 according to this embodiment may include a first terminal device 101, a second terminal device 102, a third terminal device 103, a network 104, and a server 105. The network 104 serves as a medium for providing a communication link between the first terminal device 101, the second terminal device 102, the third terminal device 103, and the server 105. The network 104 may include various connection types, such as wired or wireless communication links, or fiber optic cables, etc.
[0025] Users can use the first terminal device 101, the second terminal device 102, and the third terminal device 103 to interact with the server 105 via the network 104 to receive or send messages, etc. Various communication client applications can be installed on the first terminal device 101, the second terminal device 102, and the third terminal device 103, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social media platform software, etc. (for example only).
[0026] The first terminal device 101, the second terminal device 102, and the third terminal device 103 can be various electronic devices with displays and support web browsing, including but not limited to smartphones, tablets, laptops, and desktop computers.
[0027] Server 105 can be a server that provides various services, such as a backend management server that supports websites browsed by users using the first terminal device 101, the second terminal device 102, and the third terminal device 103 (this is just an example). The backend management server can analyze and process data such as received user requests, and feed back the processing results (such as web pages, information, or data obtained or generated according to user requests) to the terminal devices.
[0028] For example, a user can initiate a software package compilation command through a first terminal device 101, a second terminal device 102, and a third terminal device 103. In response to the command, the server 105 can construct a dependency graph based on the set of software packages to be compiled. The dependency graph includes nodes and the dependencies between nodes, where nodes represent software packages, and the dependencies between nodes indicate whether the compilation or installation of a software package corresponding to one node depends on the compilation or installation of a software package corresponding to another node. Multiple nodes are selected from the dependency graph as the initial positions of multiple fish in the fish swarm algorithm, where the number of fish is a preset value. Based on the fish swarm algorithm, the multiple fish start from their respective initial positions and move sequentially to the next node in the dependency graph according to the dependencies between nodes, obtaining the movement paths of each fish. The movement paths represent the sorting result of the nodes in the dependency graph. According to the dependencies between nodes in the movement paths, a target path is selected from the movement paths of the multiple fish. The software packages in the software package set are compiled according to the target path.
[0029] It should be noted that the software package compilation method provided in this application embodiment can generally be executed by server 105. Correspondingly, the software package compilation device provided in this application embodiment can generally be located in server 105. The software package compilation method provided in this application embodiment can also be executed by a server or server cluster that is different from server 105 and capable of communicating with the first terminal device 101, the second terminal device 102, the third terminal device 103, and / or server 105. Correspondingly, the software package compilation device provided in this application embodiment can also be located in a server or server cluster that is different from server 105 and capable of communicating with the first terminal device 101, the second terminal device 102, the third terminal device 103, and / or server 105.
[0030] It should be understood that Figure 1 The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, and servers can be included.
[0031] The following will be based on Figure 1 The described scene, through Figures 2-6 The software package compilation method of the embodiments of this application will be described in detail.
[0032] Figure 2 A flowchart of a software package compilation method according to an embodiment of this application is shown.
[0033] like Figure 2 As shown, the software package compilation method in this embodiment includes operations S210 to S250.
[0034] In operation S210, a dependency graph is constructed based on the set of packages to be compiled. The dependency graph includes nodes and the dependencies between nodes. Nodes represent packages, and the dependencies between nodes indicate whether the compilation or installation of the package corresponding to one node depends on the compilation or installation of the package corresponding to another node.
[0035] Optionally, there may be dependencies between multiple packages in the package collection. These dependencies may include the compilation or installation of one package depending on the compilation or installation of the package corresponding to another node. For example, package A can only be compiled successfully after package B is compiled, and / or package A can only be installed successfully after package B is installed.
[0036] Optionally, dependencies between software packages can be represented using a dependency graph. A node in the dependency graph can represent a software package, and the dependencies between nodes correspond to the dependencies between software packages. The dependencies between nodes can be represented by directed edges between nodes. For example, there is a dependency between two nodes connected by a directed edge, and the direction of the directed edge indicates the direction of the dependency. If a directed edge points from node 1 to node 2, it means that the compilation or installation of the software package corresponding to node 1 depends on the compilation or installation of the software package corresponding to node 2.
[0037] In operation S220, multiple nodes are selected from the dependency graph as the initial positions of multiple fish in the fish swarm algorithm, where the number of multiple fish is a preset value.
[0038] In operation S230, based on the fish swarm algorithm, multiple fish start from their respective initial positions and move to the next node in the dependency graph according to the dependencies between nodes, thus obtaining the movement path of each fish. The movement path represents the sorting result of the nodes in the dependency graph.
[0039] For example, the fish swarm algorithm includes a swarm intelligence optimization algorithm that simulates the collective behaviors of fish schools in nature, such as foraging and gathering. In the fish swarm algorithm, one fish represents a possible solution, and the fish swarm represents a set of multiple possible solutions. The action type of each fish can include foraging behavior, swarming behavior, tail-chasing behavior, etc., and in the relevant fish swarm algorithm, a fish usually only performs one of these behaviors at any given time.
[0040] For example, foraging behavior may include fish swimming randomly to explore their surroundings; swarming behavior may include each fish exploring the number of its companions, calculating the center position of these companions, and swimming toward the center position; tailing behavior may include when a fish or a small group of fish finds food (food can represent the most suitable next node), its companions will quickly follow.
[0041] Optionally, the number of fish can be set according to actual needs. Too many fish will increase computational costs, while too few fish will lead to insufficient global search capabilities and a tendency to get trapped in local optima. For example, if there are 1000 nodes in the dependency graph, the number of fish can be set to 30 to 40. It should be noted that the specific values of the number of fish mentioned above are only illustrative examples and can be adjusted according to actual needs. There is no limitation on the specific value of the number of fish.
[0042] Figure 3 A schematic diagram of the movement path of a school of fish according to an embodiment of this application is shown.
[0043] like Figure 3 As shown, the nodes in the dependency graph can include: F1, F2, F3, FN, S1, S2, M1, M2, M3, M4, M5, M6.
[0044] like Figure 3 As shown, nodes F1, F2, F3, and FN can be selected from the dependency graph as the initial positions of the four fish in the fish swarm algorithm. Each fish can start moving from its initial position. Figure 3 The arrows in the diagram indicate the possible directions each fish may move.
[0045] Optionally, the fish's movement direction needs to satisfy the dependencies between nodes. For example, for a fish with node F1 as its initial position, its possible movement directions could include moving from node F1 to node S1, or moving from node F1 to node S2. When determining that the fish meets the preset dependency requirement between nodes F1 and S1, node S1 can be chosen as the next node, and the fish can move from node F1 to node S1. Further, the next node relative to node S1 can be determined, and the fish can continue moving from node S1 to its next next node, and so on, until the fish's movement path is obtained.
[0046] Optionally, the move path can represent the order in which all nodes in the dependency graph are arranged, and the sorting order can represent the compilation order of the packages corresponding to all nodes. For example, the move path includes: moving from node F1 (corresponding to package A) to node S1 (corresponding to package B), moving from node S1 to node M2 (corresponding to package D), and so on. Correspondingly, the compilation order includes: compiling package A first, then compiling package B, and then compiling package D (where package A, package B, and package D are not shown in the graph).
[0047] In operation S240, the target path is selected from the movement paths of multiple fish based on the dependencies between nodes in the movement path.
[0048] When operating the S250, compile the packages in the package set according to the target path.
[0049] Optionally, the movement path of a fish can correspond to the compilation order of a software package. The movement paths of multiple fish may differ in terms of compilation success rate, compilation resource consumption, etc., and the compilation success rate and compilation resource consumption are usually related to dependencies. Therefore, based on the dependencies between nodes in the movement path, a target path is selected from the movement paths of multiple fish. The target path can meet the requirements of compilation success rate, compilation resource consumption, etc.
[0050] Figure 4 A schematic diagram of the target path according to an embodiment of this application is shown.
[0051] like Figure 4 As shown, following the target path, each fish can start from its initial position and move towards the next node in the direction indicated by the arrow.
[0052] Optionally, the software packages corresponding to each node in the target path can be determined, and the software packages corresponding to the nodes can be compiled sequentially according to the sorting result of the nodes in the target path.
[0053] According to embodiments of this application, when the software packages are large (e.g., hundreds or even thousands), simply using a topological order is insufficient to account for various factors such as the cost of retrying failed packages, differences in compilation time, and instantaneous resource contention. These factors are often influenced by dependencies. By constructing a dependency graph, the dependencies between software packages in compilation or installation can be represented intuitively and accurately, avoiding the inefficiency and inaccuracy caused by manually determining dependencies. By combining the dependency graph with the fish swarm algorithm, the process of determining the compilation order of software packages is abstracted as a dynamic optimization process of fish foraging in the dependency graph. By selecting multiple nodes from the dependency graph as the initial positions of multiple fish in the fish swarm algorithm, and obtaining the movement paths of each fish based on the fish swarm algorithm, and using the movement paths to represent the sorting results of nodes in the dependency graph, a better compilation order can be determined, improving the success rate of software package compilation. This allows for the one-time, stable, and efficient compilation of a large number of software packages with complex dependencies. Thus, this solves the technical problems of high compilation failure rate and low compilation efficiency in related methods for software packages with a large number of packages and complex dependencies.
[0054] According to an embodiment of this application, moving sequentially to the next node in a dependency graph based on the dependencies between nodes includes the following operations.
[0055] For each fish in a multi-fish system, the current node of the fish can be used as the center node. Based on the dependency relationship between the center node and the surrounding nodes, a node can be selected as the first candidate node from the surrounding nodes.
[0056] like Figure 3 As shown, for example, if the fish is currently located at node F1, node F1 can be considered the central node, and nodes S1 and S2 can be considered the nodes surrounding the central node. The dependencies between nodes F1 and S1, and between nodes F1 and S2, can be determined separately, and node S1 or node S2 can be selected as the first candidate node based on the dependencies.
[0057] A node in the dependency graph that has been selected as the next node by other fish more times than a preset standard can be designated as a second candidate node.
[0058] Optionally, a node with a selection frequency exceeding a preset threshold can be the node with the highest selection frequency. It's possible to retrieve the next selected node from each of the other fish in the group and determine the node with the highest selection frequency from among them. For example... Figure 3 As shown, the next node selected by each of the other fish can include M1, M2, M3...M6, etc. Among them, node M2 is selected the most times by two fish (the fish with F2 as the initial position and the fish with F3 as the initial position), so node M2 can be regarded as the second candidate node.
[0059] Based on the association between the central node and the first and second candidate nodes, one of the first and second candidate nodes can be selected as the next node for the fish to move to.
[0060] Optionally, the first candidate node can represent the alternative node chosen by each fish itself as the next node, representing the local optimum for each fish. The second candidate node can represent the next node collectively chosen by the other fish in the group, representing the social optimum for the group. The first and second candidate nodes can be evaluated to determine the most suitable node to move to next. For example, the relationship between the center node and the first and second candidate nodes can be evaluated to determine the next node.
[0061] The fish can be moved to the next node. Then, the process returns to the node where the fish is currently located as the center node. Based on the dependencies between the center node and the surrounding nodes, a node is selected as the first candidate node from the surrounding nodes.
[0062] like Figure 3 As shown, for a fish with F1 as its initial position, after determining the next node as S1, the fish is moved to S1. Then, with S1 as the center node, the first candidate node and the second candidate node relative to S1 are determined, and the next node relative to S1 is determined from them.
[0063] According to the embodiments of this application, the options selected by each fish as the next node are determined to obtain the local optimum, and the next node selected by the other fish collectively is determined to obtain the social optimum. The advantages and disadvantages of the local optimum and the social optimum are further compared to determine the next node of each fish. Through the above dual-path comparison, each fish will neither blindly follow the social optimum nor be stuck in a local optimum, thus significantly improving the overall convergence speed.
[0064] According to an embodiment of this application, selecting one of the first candidate node and the second candidate node as the next node to which the fish should move, based on the association between the central node and the first candidate node and the second candidate node, includes the following operations.
[0065] Based on the dependency relationship between the central node and the first and second candidate nodes, as well as the dependency relationship between the first and second candidate nodes and other nodes in the dependency graph, the target path weight from the central node to the first candidate node and the target path weight from the central node to the second candidate node can be calculated.
[0066] Optionally, for the first candidate node, the target path weight from the central node to the first candidate node can be calculated based on the dependency relationship between the central node and the first candidate node, as well as the dependency relationship between the first candidate node and other nodes in the dependency graph.
[0067] Correspondingly, for the second candidate node, the target path weight from the central node to the second candidate node can be calculated based on the dependency relationship between the central node and the second candidate node, as well as the dependency relationship between the second candidate node and other nodes in the dependency graph.
[0068] Based on the target path weights from the central node to the first candidate node and from the central node to the second candidate node, one of the first candidate node and the second candidate node can be selected as the next node the fish should move to.
[0069] Optionally, the weights of the two target paths can be compared. For example, the target path weight with the lower value can be determined, and the candidate node corresponding to the target path weight can be used as the next node.
[0070] According to the embodiments of this application, if the node selected by other fish is directly taken as the next node, although the node selected by other fish may be more in line with the dependency relationship, the congestion of that node will be too high due to multiple fish selecting the same node, which is likely to become a resource bottleneck. If the node selected by each fish is directly taken as the next node, it may fall into local optima, resulting in obtaining only a local optimum value instead of a global optimum value. However, by determining the next node from the first candidate node and the second candidate node, resource consumption and search accuracy can be comprehensively considered, thereby determining a more reasonable next node.
[0071] According to embodiments of this application, the calculation of the target path weight from the central node to the first candidate node and the target path weight from the central node to the second candidate node, based on the dependency relationship between the central node and the first candidate node and the second candidate node, as well as the dependency relationship between the first candidate node and the second candidate node and other nodes in the dependency graph, includes the following operations.
[0072] The initial path weights from the central node to the first candidate node and from the central node to the second candidate node can be determined based on the dependency relationship between the central node and the first and second candidate nodes.
[0073] Optionally, for the first candidate node, the dependency relationship between the central node and the first candidate node can be determined, such as whether the compilation or installation of the first candidate node depends on the compilation or installation of the central node, thereby determining the initial path weight from the central node to the first candidate node.
[0074] Correspondingly, for the second candidate node, it can be determined, for example, whether the compilation or installation of the second candidate node depends on the compilation or installation of the central node, thereby determining the initial path weight from the central node to the second candidate node.
[0075] Optionally, the initial path weight can characterize the compilation cost when two nodes are compiled sequentially. If the compilation or installation of package B does not depend on the compilation or installation of package A, but depends on the compilation or installation of package C, and the determined compilation order is to first compile package A corresponding to the central node and then compile package B corresponding to the next node, the compilation cost of this compilation order is high because the compilation order is difficult to satisfy the dependency relationship of package B, and the corresponding initial path weight is high.
[0076] The node weights of the first and second candidate nodes can be determined based on their respective dependencies with other nodes in the dependency graph.
[0077] Optionally, node weight can represent the importance of a node. For example, if the compilation or installation of multiple other nodes depends on the compilation or installation of the first candidate node, it indicates that the first candidate node is more important and has a higher node weight.
[0078] The target path weight from the center node to the first candidate node can be calculated based on the initial path weight from the center node to the first candidate node and the node weight of the first candidate node.
[0079] The target path weight from the center node to the second candidate node can be calculated based on the initial path weight from the center node to the second candidate node and the node weight of the second candidate node.
[0080] Optionally, the target path weight can be obtained by multiplying the initial path weight and the node weight. The higher the initial path weight, the higher the compilation cost; the higher the node weight, the more important the node. When the compilation cost of a more important node is high (i.e., the target path weight is high), it has a greater impact on whether the package compilation can be executed smoothly (e.g., it will significantly reduce the compilation success rate). Therefore, a candidate node corresponding to a lower target path weight can be selected as the next node.
[0081] According to the embodiments of this application, the target path weight is determined by comprehensively considering the initial path weight between the central node and the candidate node, as well as the node weight of the candidate node itself. The candidate node can be comprehensively evaluated from multiple dimensions such as weight importance and compilation cost to determine whether it is suitable to be the next node, thereby selecting a more reasonable node.
[0082] Optionally, the historical failure rate of the first candidate node and the second candidate node during compilation within a predetermined historical period can also be obtained, and one of the first candidate node and the second candidate node can be selected as the next node to which the fish should move, based on the target path weight and the historical failure rate.
[0083] For example, select a candidate node with a smaller target path weight and a lower historical failure rate as the next node.
[0084] Figure 5 A flowchart of a software package compilation method according to another embodiment of this application is shown. Figure 5 As shown, the software package compilation method in this embodiment includes operations S510 to S5120.
[0085] In operation S510, the total number of fish N, the number of iterations M, and the step size L are set. N, M, and L are all positive integers. For a single fish, one iteration corresponds to one determination of the next node. The step size represents the neighborhood radius that the fish can explore in one move. For example, with a step size of 1, the fish searches for the node adjacent to the current node in each iteration; with a step size of 2, the fish searches for the node separated from the current node by one node in each iteration.
[0086] In operation S520, for the i-th fish in the fish group, when i equals 1, the i-th fish Xi is tailed to obtain the first candidate node. The first candidate node can be determined in the manner described in the above embodiment. For example, for the i-th fish, the node where the fish is currently located can be taken as the center node, and a node can be selected from the surrounding nodes as the first candidate node based on the dependency relationship between the center node and the surrounding nodes.
[0087] In operation S530, the i-th fish Xi is aggregated to obtain the second candidate node. The second candidate node can be determined in the manner described in the above embodiments. For example, for the i-th fish, the node in the dependency graph that has been selected as the next node by other fish more than a preset standard can be used as the second candidate node.
[0088] In operation S540, the target path weight W1 from the central node to the first candidate node can be calculated.
[0089] In operation S550, the target path weight W2 from the central node to the second candidate node is calculated.
[0090] For example, the target path weight W1 from the central node to the first candidate node can be calculated based on the dependency relationship between the central node and the first candidate node, as well as the dependency relationship between the first candidate node and other nodes in the dependency graph.
[0091] For example, the target path weight W2 from the central node to the second candidate node can be calculated based on the dependency relationship between the central node and the second candidate node, as well as the dependency relationship between the second candidate node and other nodes in the dependency graph.
[0092] In operation S560, determine whether the target path weight W1 is less than the target path weight W2.
[0093] In operation S570, if the target path weight W1 is less than the target path weight W2, the first candidate node is taken as the next node of the current node. Assuming the current node is the initial node, i.e., the first node in the sorting, then this operation determines the second node in the sorting.
[0094] In operation S580, if the target path weight W1 is greater than or equal to the target path weight W2, the second candidate node is selected as the next node.
[0095] For example, if the target path weight W1 is less than the target path weight W2, it means that the compilation cost from the central node to the first candidate node may be lower. Therefore, the first candidate node can be selected as the next node.
[0096] Correspondingly, if the target path weight W2 is less than the target path weight W1, it means that the compilation cost from the central node to the second candidate node may be smaller. Therefore, the second candidate node can be selected as the next node.
[0097] For example, for operations S520 to S580, a dual-path comparison mechanism is used to compare the merits of the two paths each time the next node is determined, and the more suitable candidate node is selected as the next node. In this way, each fish will not blindly follow the trend and only select the node determined by the majority of fish as the next node, nor will it become stuck in a local optimum, thus improving the convergence speed of the fish swarm algorithm.
[0098] In operation S590, it is determined whether i has reached the total number of fish N, that is, whether all fish have determined the second node of their respective paths. If i has not reached N, i = i + 1, that is, for the next fish, return to execute operations S520 and S530 until i reaches the total number of fish N.
[0099] In operation S5100, when i reaches the total number of fish N, all fish have determined the second node in their respective paths, thus completing the first iteration. At this point, gen = gen + 1, meaning the current iteration count gen is incremented by 1. For example, after completing the first iteration, the current iteration count gen is incremented by 1, and the second iteration begins.
[0100] In operation S5110, it is determined whether gen is greater than the preset iteration number threshold M. If gen is less than or equal to M, operations S520 and S530 are executed to proceed to the next iteration.
[0101] When operating S5120, the iteration is completed if gen is greater than M.
[0102] For example, the iteration operation can be terminated when a preset iteration number threshold M is reached. Alternatively, the iteration can be completed when the movement paths determined by the N fish no longer change after several iterations (the number of iterations is less than M).
[0103] For example, after the iteration is completed, N fish have obtained their respective movement paths. From the movement paths of the N fish, the movement path with the minimum compilation cost of the entire movement path can be selected as the target path.
[0104] According to the embodiments of this application, by fully applying the fish swarm algorithm to determine the compilation order of software packages, the problems of low efficiency, easy getting trapped in local optima and resource contention of related methods are solved. Finally, a globally optimal compilation sequence can be output, which significantly improves the success rate, throughput and time efficiency of large-scale software package compilation.
[0105] According to embodiments of this application, determining the initial path weight from the central node to the first candidate node and the initial path weight from the central node to the second candidate node based on the dependency relationship between the central node and the first candidate node and the second candidate node includes the following operations.
[0106] For any candidate node between the first and second candidate nodes, if the compilation or installation of the software package corresponding to any candidate node depends on the compilation or installation of the software package corresponding to the central node, then the initial path weight from the central node to any candidate node is set to a first value. If the compilation or installation of the software package corresponding to any candidate node does not depend on the compilation or installation of the software package corresponding to the central node, then the initial path weight from the central node to any candidate node is set to a value higher than the first value.
[0107] Optionally, for any candidate node, if the compilation or installation of the software package corresponding to the candidate node depends on the compilation or installation of the software package corresponding to the central node, it means that the central node can satisfy the dependency required by the candidate node. Therefore, a lower initial path weight can be set for the candidate node, such as setting it to the first value, which is, for example, 0.
[0108] Optionally, if the compilation or installation of the software package corresponding to the candidate node does not depend on the compilation or installation of the software package corresponding to the central node, it means that the central node is difficult to meet the dependency requirements of the candidate node. Therefore, a higher initial path weight can be set for the candidate node.
[0109] According to embodiments of this application, if the compilation or installation of the software package corresponding to any candidate node does not depend on the compilation or installation of the software package corresponding to the central node, setting the initial path weight from the central node to any candidate node to a value higher than a first value includes: if the installation of the software package corresponding to any candidate node does not depend on the installation of the software package corresponding to the central node, setting the initial path weight from the central node to any candidate node to a second value, wherein the second value is higher than the first value; if the compilation of the software package corresponding to any candidate node does not depend on the compilation of the software package corresponding to the central node, setting the initial path weight from the central node to any candidate node to a third value, wherein the third value is higher than the second value.
[0110] Optionally, different types of dependencies may have different importance. For example, if the dependencies of a software package's installation process are not met, it may only affect the operation of that software package; however, if the dependencies of the software package's compilation process are not met, it may cause other software packages that depend on the software package to fail to compile. Therefore, the importance of the dependencies of the compilation process can be set higher than that of the dependencies of the installation process. Correspondingly, different initial path weights can be set according to the type of dependency. For example, if the compilation of the software package corresponding to any candidate node does not depend on the compilation of the software package corresponding to the central node, the initial path weight from the central node to any candidate node can be set to the third value; if the installation of the software package corresponding to any candidate node does not depend on the installation of the software package corresponding to the central node, the initial path weight from the central node to any candidate node can be set to the second value, and the third value is higher than the second value.
[0111] According to embodiments of this application, determining the initial path weight based on the type of dependency can more accurately reflect the importance of the dependency, thereby accurately determining the next node.
[0112] According to an embodiment of this application, determining the node weights of the first candidate node and the second candidate node based on their respective dependencies with other nodes in the dependency graph includes: for any candidate node among the first candidate node and the second candidate node, determining the number of nodes dependent on any candidate node in the dependency graph; and calculating the node weight of any candidate node based on the number of nodes.
[0113] Optionally, for any candidate node, a node that depends on any candidate node may be one that requires the candidate node to be compiled successfully before it can be compiled, and / or one that requires the candidate node to be installed successfully before it can be installed successfully.
[0114] Optionally, calculating the node weight of any candidate node based on the number of nodes may include: calculating the ratio of the number of nodes to the total number of nodes in the dependency graph to obtain the node weight.
[0115] According to the embodiments of this application, by determining the initial path weight and node weight respectively, and determining the target path weight based on the initial path weight and node weight, the next node can be selected. The first candidate node and the second candidate node can be comprehensively evaluated from multiple perspectives such as whether the dependency relationship between nodes can be satisfied and the importance of the node, so that a more reasonable candidate node can be selected as the next node.
[0116] In one embodiment, the corresponding node weights can also be set according to the type of dependency. The type of dependency may include a first type, which may be whether the compilation of a package corresponding to a node depends on the compilation of a package corresponding to another node, and this other node may be called a compilation dependency; it may also include a second type, which may be whether the installation of a package corresponding to a node depends on the installation of a package corresponding to another node, and this other node may be called an installation dependency.
[0117] For example, for any given node, the number of other nodes that the compilation process depends on can be determined in the dependency graph; the first node weight of that node can be calculated based on the number of other nodes. For example, for any given node, the ratio of the number of other nodes that the compilation process depends on to the total number of nodes can be calculated to obtain the first node weight of that node. Alternatively, the number of other nodes that the installation process depends on can be determined in the dependency graph, and the second node weight of that node can be calculated based on the number of other nodes. For example, for any given node, the ratio of the number of other nodes that the installation process depends on to the total number of nodes can be calculated to obtain the first node weight of that node.
[0118] Optionally, the weights of the first and second nodes can be determined based on the importance of different types of dependencies. For example, if the first type of dependency is determined to be more important than the second type of dependency, the weight of the first node can be set to be greater than the weight of the second node. The correspondence between a software package and its compile-time dependencies (i.e., compilation dependencies), its installation-time dependencies (i.e., installation dependencies), the weights of the first and second nodes can be shown in Table 1.
[0119] The first node's weight can be the weight of build dependencies (buildrequire), and the second node's weight can be the weight of installation dependencies (require). buildrequire1, buildrequire2, ..., buildrequire n These represent the packages that depend on during compilation: require1, require2, ..., require. n These represent the software packages that the installation depends on. , … These represent the compilation dependency weights of package a, package b, ..., package n, respectively, and are collectively referred to below as , , … These represent the installation dependency weights of package a, package b, ..., package n, respectively, and are collectively referred to below as .
[0120]
[0121] When the package set contains n packages, the movement path of each fish includes the fish's movement paths through n nodes. For a movement path, the sum of the target path weights between every two nodes can be determined to obtain the compilation cost of the entire movement path.
[0122] The compilation cost of the move path can be represented by the following equation (1).
[0123] (1)
[0124] Where: C(S) is the compilation cost of the move path, For the current package, the total cost of missing compilation dependencies combined with the package weight is calculated. If the package is not in the previous compilation sequence, the compilation cost is increased by 1 and the result is the weight of that package.
[0125] For the current package, the total cost of installing dependencies combined with the weight of missing packages is calculated. If the package is not in the previous compilation sequence, the cost is increased by 0.5 and the weight of that package.
[0126] {δ1,δn} represents the compilation order of compiler dependencies and installation dependencies. If the current package is not in this order, a compilation cost will be incurred.
[0127] In equation (1), if the installation of the software package corresponding to a node does not depend on the installation of the software package corresponding to the previous node, the initial path weight from the previous node to this node is set to 0.5, that is, the second value is 0.5. If the compilation of the software package corresponding to a node does not depend on the compilation of the software package corresponding to the previous node, the initial path weight from the previous node to this node is set to 1, that is, the third value is 1.
[0128] For example, the compilation order can be initialized, or a random compilation order can be generated. Based on this order, starting from the first package, the compilation and installation dependencies of the packages are traversed to see if they exist. If a compilation dependency does not exist, the compilation cost is increased by 1, and if an installation dependency does not exist, the compilation cost is increased by 0.5. Combining the weight of each package, the overall compilation cost of this compilation order is calculated. The optimization goal is to optimize the compilation path with the minimum compilation cost based on the following mathematical model.
[0129] According to the embodiments of this application, setting the initial path weight and node weight according to the type of dependency can more accurately reflect the importance of the dependency and avoid decision bias.
[0130] According to an embodiment of this application, selecting a node as a first candidate node from among the surrounding nodes based on the dependency relationship between the central node and the surrounding nodes includes the following operations.
[0131] In a dependency graph, nodes whose distance from the central node is within a predetermined target radius are defined as surrounding nodes of the central node. The target radius is measured by the number of hops between the nodes.
[0132] Figure 6 A schematic diagram showing the target radius and movement path corresponding to a single fish according to an embodiment of this application is provided.
[0133] like Figure 6 As shown, the center node can be the F1 node. The step size can represent the radius of the neighborhood that the fish can explore in one move. For example, when the step size is 1, the fish only looks for the next node relative to the F1 node. If only the found Xnext node is taken as the next node, the compilation order for this fish is to compile the F1 node first, and then compile the Xnext node.
[0134] The target radius can include the number of hops between nodes. For example, when the number of hops is 1, nodes with a hop count of 1 relative to node F1 can be considered as surrounding nodes. Surrounding nodes include, for example, Xn1, Xn2, Xnext, Xv, etc.
[0135] Alternatively, directly determining the dependencies between the central node and all other nodes in the dependency graph would result in excessive computation. Therefore, nodes whose distance from the central node is within a predetermined target radius can be defined as surrounding nodes of the central node, and only the dependencies between the central node and its surrounding nodes can be determined.
[0136] Based on the dependencies between the central node and the surrounding nodes, the initial path weights from the central node to each surrounding node can be calculated; and nodes can be selected from the surrounding nodes as the first candidate nodes based on the initial path weights.
[0137] Alternatively, the node with the lowest initial path weight among the surrounding nodes can be directly selected as the first candidate node.
[0138] like Figure 3 As shown, for node F1, its surrounding nodes include nodes S1 and S2. The initial path weight from node F1 to node S1 and the initial path weight from node F1 to node S2 can be calculated, and the node with the lowest initial path weight can be determined as the first candidate node.
[0139] Optionally, the node crowding degree of each surrounding node can be determined first. For each surrounding node, the node crowding degree is used to characterize the ratio of the number of times that node is selected as the next node by other fish to the total number of fish. A set of surrounding nodes with a node crowding degree lower than a preset crowding degree threshold (which can be set according to actual needs) can be obtained, and the node with the lowest initial path weight can be selected from the node set as the first candidate node.
[0140] For example, if a large number of fish choose the same node as their next node, a "swarm congestion" problem may occur, causing the node to become too crowded and potentially becoming a resource bottleneck.
[0141] For example, for a school of fish, resources may include the living space required by the school. When a large number of fish point to the same node, the resources around this node will be quickly consumed and occupied. For example, too many fish crowding to the same node will cause the space resources to decrease rapidly, which may obstruct the movement of the school of fish.
[0142] Optionally, a set of nodes with low congestion can be selected first, and then the node with the lowest initial path weight can be selected from the set of nodes as the first candidate node. The first candidate node determined in this way can simultaneously meet the requirements of node congestion and initial path weight.
[0143] According to embodiments of this application, the target radius can also be reduced as the number of nodes the fish passes through in the dependency graph increases.
[0144] For example, a larger target radius results in a stronger global search capability, but may lead to decision jitter, such as unstable and irregular fluctuations in the fish's movement direction and distance, causing a lack of focus in the search process. Conversely, a smaller target radius allows for more accurate local searches, but may introduce local minima, where the fish may become trapped in a seemingly optimal but not globally optimal local region, unable to explore better solutions. By reducing the target radius as the number of nodes the fish traverses in the dependency graph increases, a balance can be struck between search range and search accuracy.
[0145] According to an embodiment of this application, as the number of nodes traversed by the fish in the dependency graph increases, reducing the target radius includes: if the number of nodes traversed by the fish in the dependency graph is less than or equal to a preset number threshold, setting the target radius to a base value; if the number of nodes traversed by the fish in the dependency graph is greater than the preset number threshold, setting the target radius to an updated value, wherein the updated value is greater than the base value.
[0146] Optionally, a larger target radius can be set in the early stages of each fish's movement (e.g., when the number of nodes traversed in the dependency graph is less than or equal to a preset threshold), essentially setting the target radius as the base value. This allows for searching over a larger area, covering a wider search space and enhancing global exploration capabilities. Conversely, the target radius can be reduced in the later stages of each fish's movement (e.g., when the number of nodes traversed in the dependency graph exceeds the preset threshold), essentially setting the target radius as an updated value. This allows for finer searching within a smaller area, improving search accuracy.
[0147] By using the aforementioned nonlinear decreasing target radius method, both search range and search accuracy can be considered, thereby improving the convergence speed and search result accuracy of the fish swarm algorithm.
[0148] According to an embodiment of this application, selecting multiple nodes from the dependency graph as the initial positions of multiple fish in the fish swarm algorithm includes: selecting a set of nodes from the dependency graph that meet the dependency criteria, wherein the dependency criteria include: the compilation or installation of the software package corresponding to the node does not depend on the compilation or installation of the software package corresponding to any other node; and randomly selecting multiple nodes from the node set as the initial positions of multiple fish in the fish swarm algorithm.
[0149] Optionally, for the first software package to be compiled, its compilation and installation processes cannot depend on other software packages. Only in this way can the entire compilation and installation process start to run normally. Therefore, all nodes that meet the above dependency criteria can be determined from the dependency graph to obtain a node set. Then, multiple nodes can be randomly selected from the node set as the initial positions of multiple fish in the fish swarm algorithm.
[0150] For example, nodes that meet the dependency criteria are identified from the dependency graph as F1, F2, F3, F4…FN. Since the preset number of fish is 4, 4 nodes can be randomly selected from the above nodes, such as F1, F2, F3, and FN. According to the embodiments of this application, by selecting a set of nodes that meet the dependency criteria in the dependency graph, any fish can be in a position where compilation can start normally at the initial moment of compilation, thereby ensuring that each compilation sequence can start executing normally.
[0151] According to embodiments of this application, the software package compilation method further includes obtaining the source code corresponding to each software package in the software package set and the configuration file corresponding to the source code; parsing the first field and the second field in the configuration file of each software package to obtain the dependency relationship between the software packages, wherein the first field indicates whether the compilation of the software package depends on the compilation of other software packages, and the second field indicates whether the installation of the software package depends on the installation of other software packages.
[0152] Optionally, the source code and its corresponding configuration file can be obtained from a source code repository maintained by the software developer or community. The configuration file can be parsed to determine the first and second fields.
[0153] Based on the above-described software package compilation method, this application also provides a software package compilation apparatus. The following will be combined with... Figure 7 The device is described in detail.
[0154] Figure 7 A structural block diagram of a software package compilation apparatus according to an embodiment of this application is shown.
[0155] like Figure 7 As shown, the software package compilation device 700 of this embodiment includes a build module 710, a selection module 720, a move module 730, a selection module 740, and a compilation module 750.
[0156] The build module 710 is used to construct a dependency graph based on the set of software packages to be compiled. The dependency graph includes nodes and the dependencies between nodes, where nodes represent software packages, and the dependencies between nodes indicate whether the compilation or installation of the software package corresponding to one node depends on the compilation or installation of the software package corresponding to another node. In one embodiment, the build module 710 can be used to perform the operation S210 described above, which will not be repeated here.
[0157] The selection module 720 is used to select multiple nodes from the dependency graph as the initial positions of multiple fish in the fish swarm algorithm, wherein the number of multiple fish is a preset value. In one embodiment, the selection module 720 can be used to perform the operation S220 described above, which will not be repeated here.
[0158] The movement module 730 is used to, based on the fish swarm algorithm, move multiple fish from their respective initial positions to the next node in the dependency graph according to the dependencies between nodes, thus obtaining the movement paths of each fish. The movement paths represent the sorting result of the nodes in the dependency graph. In one embodiment, the movement module 730 can be used to perform the operation S230 described above, which will not be repeated here.
[0159] The selection module 740 is used to select a target path from the movement paths of multiple fish based on the dependencies between nodes in the movement path. In one embodiment, the selection module 740 can be used to perform the operation S240 described above, which will not be repeated here.
[0160] The compilation module 750 is used to compile the software packages in the software package set according to the target path. In one embodiment, the compilation module 750 can be used to perform the operation S250 described above, which will not be repeated here.
[0161] According to an embodiment of this application, the moving module 730 includes a first selection submodule, a selected submodule, a second selection submodule, and a return submodule.
[0162] The first selection submodule is used to select a node as the first candidate node from the surrounding nodes, based on the dependency relationship between the central node and the nodes around the central node, with the current node of the fish as the center node. The selection submodule is used to select nodes in the dependency relationship graph that have been selected as the next node by other fish more than a preset standard as the second candidate node. The second selection submodule is used to select one of the first candidate node and the second candidate node as the next node to be moved to by the fish, based on the association relationship between the central node and the first and second candidate nodes. The return submodule is used to move the fish to the next node and return to the previous state, using the current node of the fish as the center node and the dependency relationship between the central node and the nodes around the central node as the first candidate node.
[0163] According to an embodiment of this application, the second selection submodule includes a first calculation unit and a selection unit.
[0164] The first calculation unit is used to calculate the target path weight from the central node to the first candidate node and the target path weight from the central node to the second candidate node based on the dependency relationship between the central node and the first candidate node and the second candidate node, as well as the dependency relationship between the first candidate node and the second candidate node and other nodes in the dependency relationship graph. The selection unit is used to select one of the first candidate node and the second candidate node as the next node to which the fish should move, based on the target path weight from the central node to the first candidate node and the target path weight from the central node to the second candidate node.
[0165] According to an embodiment of this application, the first calculation unit includes a first determining subunit, a second determining subunit, a first calculation subunit, and a second calculation subunit.
[0166] The first determining subunit is used to determine the initial path weight from the central node to the first candidate node and the initial path weight from the central node to the second candidate node based on the dependency relationship between the central node and the first candidate node and the second candidate node; the second determining subunit is used to determine the node weights of the first candidate node and the second candidate node respectively based on the dependency relationships between the first candidate node and the second candidate node and other nodes in the dependency graph; the first calculating subunit is used to calculate the target path weight from the central node to the first candidate node based on the initial path weight from the central node to the first candidate node and the node weight of the first candidate node; the second calculating subunit is used to calculate the target path weight from the central node to the second candidate node based on the initial path weight from the central node to the second candidate node and the node weight of the second candidate node.
[0167] According to an embodiment of this application, for the first determining subunit, determining the initial path weight from the central node to the first candidate node and the initial path weight from the central node to the second candidate node based on the dependency relationship between the central node and the first candidate node and the second candidate node includes: if the compilation or installation of the software package corresponding to the first candidate node or the second candidate node does not depend on the compilation or installation of the software package corresponding to the central node, then the initial path weight from the central node to the corresponding first candidate node or second candidate node is set to a first value.
[0168] According to an embodiment of this application, for the first determining subunit, determining the initial path weight from the central node to the first candidate node and the initial path weight from the central node to the second candidate node based on the dependency relationship between the central node and the first candidate node and the second candidate node further includes: if the compilation or installation of the software package corresponding to the first candidate node or the second candidate node depends on the compilation or installation of the software package corresponding to the central node, the initial path weight from the central node to the corresponding first candidate node or second candidate node is set to a second value, wherein the first value is greater than the second value.
[0169] According to an embodiment of this application, for the second determining subunit, determining the node weights of the first candidate node and the second candidate node based on their respective dependencies with other nodes in the dependency graph includes: for any candidate node among the first candidate node and the second candidate node, determining the number of nodes dependent on any candidate node in the dependency graph; and calculating the node weight of any candidate node based on the number of nodes.
[0170] According to an embodiment of this application, the first selection submodule includes a determining unit, a second calculation unit, and a first obtaining unit.
[0171] The determining unit is used to determine the nodes whose distance from the central node is less than a predetermined distance in the dependency graph as the surrounding nodes of the central node; the second calculation unit is used to calculate the initial path weight from the central node to each surrounding node according to the dependency relationship between the central node and the surrounding nodes; the obtaining unit is used to select the surrounding nodes whose initial path weight meets the preset criteria as the first candidate nodes.
[0172] According to embodiments of this application, the first selection submodule further includes a second obtaining unit and a reducing unit.
[0173] The second obtaining unit is used to take the center node as the origin and the nodes within the target radius as the nodes around the center node; the reducing unit is used to reduce the target radius as the number of nodes the fish passes through in the dependency graph increases.
[0174] According to an embodiment of this application, the second obtaining unit includes a first obtaining subunit and a second obtaining subunit.
[0175] The first obtaining subunit is used to set the target radius to a first radius value when the number of executions is less than or equal to a preset number threshold; the second obtaining subunit is used to set the target radius to a second radius value when the number of executions is greater than the preset number threshold, wherein the first radius value is greater than the second radius value.
[0176] According to an embodiment of this application, the selection module 720 includes a first selection subunit and a random selection subunit.
[0177] The first selected subunit is used to select a set of nodes from the dependency graph that meet the dependency criteria, wherein the dependency criteria include: the compilation of the package corresponding to a node does not depend on the compilation of the package corresponding to any other node; the random selection subunit is used for
[0178] Multiple nodes are randomly selected from the node set as the initial positions of multiple fish in the fish swarm algorithm.
[0179] According to embodiments of this application, the software package compilation apparatus further includes an acquisition module and a parsing module.
[0180] The acquisition module is used to obtain the source code and configuration file corresponding to each package in the package set; the parsing module is used to parse the first and second fields in the configuration file of each package to obtain the dependency relationship between the packages. The first field indicates whether the compilation of the package depends on the compilation of other packages, and the second field indicates whether the installation of the package depends on the installation of other packages.
[0181] According to embodiments of this application, any plurality of modules among the construction module 710, selection module 720, movement module 730, selection module 740, and compilation module 750 can be merged into one module, or any one of these modules can be split into multiple modules. Alternatively, at least part of the functionality of one or more of these modules can be combined with at least part of the functionality of other modules and implemented in one module. According to embodiments of this application, at least one of the construction module 710, selection module 720, movement module 730, selection module 740, and compilation module 750 can be at least partially implemented as hardware circuitry, such as a field-programmable gate array (FPGA), a programmable logic array (PLA), a system-on-a-chip, a system-on-a-substrate, a system-on-package, an application-specific integrated circuit (ASIC), or implemented in hardware or firmware by any other reasonable means of integrating or packaging circuitry, or implemented in software, hardware, or firmware, or in any suitable combination of any of these three implementation methods. Alternatively, at least one of the building module 710, the selection module 720, the moving module 730, the selection module 740, and the compilation module 750 may be implemented at least partially as a computer program module that can perform corresponding functions when the computer program module is run.
[0182] Figure 8 A block diagram of an electronic device suitable for implementing a software package compilation method according to an embodiment of this application is shown.
[0183] like Figure 8 As shown, an electronic device 800 according to an embodiment of this application includes a processor 801, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 802 or a program loaded from a storage portion 808 into a random access memory (RAM) 803. The processor 801 may include, for example, a general-purpose microprocessor (e.g., a CPU), an instruction set processor and / or an associated chipset and / or a special-purpose microprocessor (e.g., an application-specific integrated circuit (ASIC)), etc. The processor 801 may also include onboard memory for caching purposes. The processor 801 may include a single processing unit or multiple processing units for performing different actions of the method flow according to an embodiment of this application.
[0184] RAM 803 stores various programs and data required for the operation of electronic device 800. Processor 801, ROM 802, and RAM 803 are interconnected via bus 804. Processor 801 executes various operations of the method flow according to embodiments of this application by executing programs in ROM 802 and / or RAM 803. It should be noted that programs may also be stored in one or more memories other than ROM 802 and RAM 803. Processor 801 may also execute various operations of the method flow according to embodiments of this application by executing programs stored in one or more memories.
[0185] According to embodiments of this application, the electronic device 800 may further include an input / output (I / O) interface 805, which is also connected to a bus 804. The electronic device 800 may also include one or more of the following components connected to the input / output (I / O) interface 805: an input section 806 including a keyboard, mouse, etc.; an output section 807 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 808 including a hard disk, etc.; and a communication section 809 including a network interface card such as a LAN card, modem, etc. The communication section 809 performs communication processing via a network such as the Internet. A drive 810 is also connected to the input / output (I / O) interface 805 as needed. A removable medium 811, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on the drive 810 as needed so that computer programs read from it can be installed into the storage section 808 as needed.
[0186] This application also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiments; or it may exist independently and not assembled into the device / apparatus / system. The computer-readable storage medium carries one or more programs, which, when executed, implement the method according to the embodiments of this application.
[0187] According to embodiments of this application, the computer-readable storage medium can be a non-volatile computer-readable storage medium, such as including but not limited to: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this application, the computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. For example, according to embodiments of this application, the computer-readable storage medium may include ROM 802 and / or RAM 803 and / or one or more memories other than ROM 802 and RAM 803 described above.
[0188] Embodiments of this application also include a computer program product comprising a computer program containing program code for performing the methods shown in the flowchart. When the computer program product is run on a computer system, the program code is used to cause the computer system to implement the methods provided in the embodiments of this application.
[0189] When the computer program is executed by the processor 801, it performs the functions defined in the system / apparatus of this application embodiment. According to the embodiments of this application, the systems, apparatuses, modules, units, etc., described above can be implemented by computer program modules.
[0190] In one embodiment, the computer program may rely on a tangible storage medium such as an optical storage device or a magnetic storage device. In another embodiment, the computer program may also be transmitted and distributed in the form of signals over a network medium, and may be downloaded and installed via the communication section 809, and / or installed from a removable medium 811. The program code contained in the computer program can be transmitted using any suitable network medium, including but not limited to: wireless, wired, etc., or any suitable combination thereof.
[0191] In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 809, and / or installed from the removable medium 811. When the computer program is executed by the processor 801, it performs the functions defined in the system of this application embodiment. According to the embodiments of this application, the systems, devices, apparatuses, modules, units, etc., described above can be implemented by computer program modules.
[0192] According to embodiments of this application, program code for executing the computer programs provided in the embodiments of this application can be written in any combination of one or more programming languages. Specifically, these computational programs can be implemented using high-level procedural and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages include, but are not limited to, languages such as Java, C++, Python, "C", or similar programming languages. The program code can be executed entirely on the user's computing device, partially on the user's device, partially on a remote computing device, or entirely on a remote computing device or server. In cases involving remote computing devices, the remote computing device can be connected to the user's computing device via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device (e.g., via the Internet using an Internet service provider).
[0193] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0194] Those skilled in the art will understand that the features described in the various embodiments of this application can be combined and / or combined in various ways, even if such combinations or combinations are not explicitly described in this application. In particular, the features described in the various embodiments of this application can be combined and / or combined in various ways without departing from the spirit and teachings of this application. All such combinations and / or combinations fall within the scope of this application.
[0195] The embodiments of this application have been described above. However, these embodiments are merely illustrative and not intended to limit the scope of this application. Although various embodiments have been described above, this does not mean that the measures in the various embodiments cannot be used advantageously in combination. Without departing from the scope of this application, those skilled in the art can make various substitutions and modifications, all of which should fall within the scope of this application.
Claims
1. A software package compilation method, characterized in that, The method includes: Based on the set of packages to be compiled, a dependency graph is constructed. The dependency graph includes nodes and the dependencies between nodes, where nodes represent packages and the dependencies between nodes indicate whether the compilation or installation of the package corresponding to one node depends on the compilation or installation of the package corresponding to another node. Multiple nodes are selected from the dependency graph as the initial positions of multiple fish in the fish swarm algorithm, wherein the number of multiple fish is a preset value; Based on the fish swarm algorithm, the multiple fish start from their respective initial positions and move to the next node in the dependency graph according to the dependencies between the nodes, thus obtaining the movement path of each fish. The movement path represents the sorting result of the nodes in the dependency graph. Based on the dependencies between nodes in the movement path, a target path is selected from the movement paths of the multiple fish; Compile the packages in the package set according to the target path.
2. The method according to claim 1, characterized in that, The step of moving sequentially to the next node in the dependency graph according to the dependencies between the nodes includes: for each of the multiple fish, Taking the current node of the fish as the center node, select a node from the surrounding nodes as the first candidate node based on the dependency relationship between the center node and the surrounding nodes. The node in the dependency graph that has been selected as the next node by other fish more than a preset standard is selected as the second candidate node. Based on the association between the central node and the first candidate node and the second candidate node, one of the first candidate node and the second candidate node is selected as the next node that the fish should move to; Move the fish to the next node, then return to the previous step of selecting a node as the first candidate node from the surrounding nodes based on the dependency relationship between the center node and the nodes around the center node, using the current node of the fish as the center node.
3. The method according to claim 2, characterized in that, The step of selecting one of the first candidate node and the second candidate node as the next node for the fish to move to, based on the association relationship between the central node and the first candidate node and the second candidate node, includes: Based on the dependency relationship between the central node and the first and second candidate nodes, as well as the dependency relationship between the first and second candidate nodes and other nodes in the dependency graph, calculate the target path weight from the central node to the first candidate node and the target path weight from the central node to the second candidate node. Based on the target path weights from the central node to the first candidate node and from the central node to the second candidate node, one of the first candidate node and the second candidate node is selected as the next node the fish needs to move to.
4. The method according to claim 3, characterized in that, The step of calculating the target path weight from the central node to the first candidate node and the target path weight from the central node to the second candidate node, based on the dependency relationship between the central node and the first and second candidate nodes, and the dependency relationships between the first and second candidate nodes and other nodes in the dependency graph, includes: Based on the dependency relationship between the central node and the first and second candidate nodes, the initial path weights from the central node to the first candidate node and from the central node to the second candidate node are determined. Based on the dependencies between the first and second candidate nodes and other nodes in the dependency graph, determine the node weights of the first and second candidate nodes respectively. Based on the initial path weight from the central node to the first candidate node and the node weight of the first candidate node, calculate the target path weight from the central node to the first candidate node. The target path weight from the center node to the second candidate node is calculated based on the initial path weight from the center node to the second candidate node and the node weight of the second candidate node.
5. The method according to claim 4, characterized in that, The step of determining the initial path weight from the central node to the first candidate node and the initial path weight from the central node to the second candidate node based on the dependency relationship between the central node and the first candidate node and the second candidate node includes: for any candidate node among the first candidate node and the second candidate node, If the compilation or installation of the software package corresponding to any candidate node depends on the compilation or installation of the software package corresponding to the central node, then the initial path weight from the central node to any candidate node is set to a first value. If the compilation or installation of the software package corresponding to any candidate node does not depend on the compilation or installation of the software package corresponding to the central node, the initial path weight from the central node to any candidate node will be set to a value higher than the first value.
6. The method according to claim 5, characterized in that, The step of setting the initial path weight from the central node to any candidate node to a value higher than the first value if the compilation or installation of the software package corresponding to any candidate node does not depend on the compilation or installation of the software package corresponding to the central node includes: If the installation of the software package corresponding to any candidate node does not depend on the installation of the software package corresponding to the central node, the initial path weight from the central node to any candidate node is set to a second value, wherein the second value is higher than the first value; If the compilation of the software package corresponding to any candidate node does not depend on the compilation of the software package corresponding to the central node, the initial path weight from the central node to any candidate node is set to a third value, wherein the third value is higher than the second value.
7. The method according to claim 4, characterized in that, The step of determining the node weights of the first and second candidate nodes based on their respective dependencies with other nodes in the dependency graph includes: for any one of the first and second candidate nodes, Determine the number of nodes that depend on any of the candidate nodes in the dependency graph; The node weight of any candidate node is calculated based on the number of nodes.
8. The method according to claim 2, characterized in that, The step of selecting a node as a first candidate node from the surrounding nodes based on the dependency relationship between the central node and the surrounding nodes includes: In the dependency graph, nodes whose distance from the central node is within a predetermined target radius are defined as surrounding nodes of the central node, where the target radius is measured by the number of hops between nodes. Based on the dependency relationship between the central node and the surrounding nodes, calculate the initial path weight from the central node to each surrounding node. A node is selected from the surrounding nodes as the first candidate node based on the initial path weight.
9. The method according to claim 8, characterized in that, The method further includes: As the number of nodes the fish passes through in the dependency graph increases, the target radius decreases.
10. The method according to claim 9, characterized in that, The reduction of the target radius as the number of nodes traversed by the fish in the dependency graph increases includes: If the number of nodes the fish traverses in the dependency graph is less than or equal to a preset threshold, the target radius is set to the base value. If the number of nodes the fish traverses in the dependency graph is greater than the preset threshold, the target radius is set as the update value, wherein the update value is greater than the base value.
11. The method according to claim 1, characterized in that, Selecting multiple nodes from the dependency graph as the initial positions of multiple fish in the fish swarm algorithm includes: Select a set of nodes that meet the dependency criteria from the dependency graph, wherein the dependency criteria include: the compilation or installation of the software package corresponding to a node does not depend on the compilation or installation of the software package corresponding to any other node; Multiple nodes are randomly selected from the set of nodes as the initial positions of multiple fish in the fish swarm algorithm.
12. The method according to claim 1, characterized in that, The method further includes: Obtain the source code corresponding to each package in the package set, as well as the configuration file corresponding to the source code; The first and second fields in the configuration files of each package are parsed to obtain the dependencies between the packages, wherein the first field indicates whether the compilation of a package depends on the compilation of other packages, and the second field indicates whether the installation of a package depends on the installation of other packages.
13. An electronic device, comprising: One or more processors; Memory, used to store one or more computer programs. The characteristic feature is that the one or more processors execute the one or more computer programs to implement the steps of the software package compilation method according to any one of claims 1 to 12.
Citation Information
Patent Citations
Method and devicefor constructing Linux system
CN112214221A
Path planning method and system based on water tiger fish algorithm
CN117094456A
Compilation sequence positioning method and system
CN118151939A
Method and system for locating compilation conflict source of software repository based on relational graph and medium
CN120315717A