Path problem solving method and device, equipment and storage medium
By building preset solutions and updating paths, the problem of low quality of path optimization solutions in the existing technology is solved, and a higher quality target solution is achieved.
Patent Information
- Application Number
- CN202411672458.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-21
- Publication Date
- 2025-04-25
AI Technical Summary
In the prior art, when generating path optimization solutions, the final complete solution is of low quality because each access node cannot change the incomplete solution generated by the previous steps.
By building a preset solution, filter out the current node from the unreached nodes and update the preset solution to cover the current node until all nodes are accessed.
This method can correct errors in preset solutions, gradually approach the shortest path, and improve the quality of the final target solution.
Smart Images

Figure CN119886478A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a path problem solving method, device, equipment and storage medium. Background Art
[0002] Given multiple locations (nodes) to be visited, the order of visiting each location (node) needs to be planned in advance before visiting so that the total path length formed is the shortest. This is a path optimization problem. The prior art first uses some nodes to generate an incomplete solution (that is, an incomplete path), and then connects the remaining nodes to the end of the incomplete solution generated in the previous step, and repeats the above steps until a complete solution is generated. Since the incomplete solution generated in the previous step cannot be changed each time a node is connected, the incomplete solution generated in the previous step is solidified, so that even if there is an error in the incomplete solution of the previous step, it cannot be corrected by connecting a new node, resulting in a low quality of the final complete solution.
[0003] In summary, the solutions generated by existing techniques are of low quality.
[0004] Therefore, the prior art still needs to be improved and enhanced. Summary of the invention
[0005] In order to solve the above technical problems, the present invention provides a path problem solving method, device, equipment and storage medium, which solves the problem of low quality of solutions generated by the prior art.
[0006] To achieve the above object, the present invention adopts the following technical solutions:
[0007] In a first aspect, the present invention provides a method for solving a path problem, which comprises:
[0008] Select nodes from all nodes to build a preset solution;
[0009] Determine the previous node included in the preset solution, and based on the previous node, filter out the current node from unvisited nodes, wherein the unvisited node is a node other than the node selected by the preset solution among all nodes, and the previous node is the last node selected when constructing the preset solution;
[0010] The preset path included in the preset solution is changed to cover the current node, so as to update the preset solution, and a target solution is obtained according to the updated preset solution.
[0011] In one implementation, selecting a node from all nodes to construct a preset solution includes:
[0012] An initial node is randomly selected from all nodes, and the initial node is used as the previous node of the first step. According to the distance between the previous node of the first step and all nodes, nodes are continuously selected from all nodes, and the selected node is used as the previous node of the second step. The previous node of the second step is connected to the previous node of the first step, and according to the distance between the previous node of the second step and all nodes, nodes are continuously selected from all nodes, and the selected node is used as the previous node of the next step, until a preset solution is constructed.
[0013] In one implementation, the step of selecting a current node from unvisited nodes based on the previous node includes:
[0014] Determine the distance between the previous node and the unvisited node;
[0015] The current node is selected from the unvisited nodes according to the distance.
[0016] In one implementation, the changing the preset path included in the preset solution to cover the current node includes:
[0017] Constructing a real vector corresponding to the preset path according to the characteristics of the nodes located at both ends of the preset path;
[0018] Constructing a pseudo vector corresponding to the current node according to the characteristics of the current node;
[0019] According to the real vector and the pseudo vector, a preferred path is selected from the preset paths included in the preset solution, and the current node is used as an inflection point of the preferred path so that the preferred path covers the current node.
[0020] In one implementation, the selecting a preferred path from preset paths included in the preset solution according to the real vector and the pseudo vector includes:
[0021] Performing a union operation on the real vector and the pseudo vector to obtain a vector set;
[0022] The vector set and the pseudo vector are used as inputs of a decoder to obtain an updated vector set corresponding to each preset path output by the decoder, wherein the decoder includes a plurality of attention layers, the vector set input to the previous attention layer is used as input to the next attention layer, and the output of the previous attention layer is used as input to the next attention layer;
[0023] According to the updated vector set corresponding to each of the preset paths, a preferred path is selected from the preset paths included in the preset solution.
[0024] In one implementation, the selecting a preferred path from the preset paths included in the preset solution according to the updated vector set corresponding to each preset path includes:
[0025] Applying linear projection and softmax to the updated vector set corresponding to each of the preset paths to obtain a prediction probability corresponding to each of the preset paths, wherein the prediction probability is used to characterize the prediction probability when the preset path covers the current node and the path formed by all nodes is the shortest;
[0026] According to the predicted probability corresponding to each of the preset paths, a preferred path is selected from the preset paths included in the preset solution.
[0027] In a second aspect, an embodiment of the present invention further provides a path problem solving device, which includes a probability prediction model for predicting the prediction probability corresponding to each preset path of the preset solution, the prediction probability is used to filter out a preferred path from the preset paths included in the preset solution, the preferred path is used to cover the current node to update the preset solution, and the preset solution after the update is used to determine the target solution;
[0028] The probability prediction model is composed of an encoder, a decoder, a linear projection and a normalization function connected in sequence. The decoder includes several attention layers. The vector set input to the previous attention layer serves as the input of the next attention layer, and the output of the previous attention layer serves as the input of the next attention layer.
[0029] In one implementation, the probability prediction model is obtained by training a neural network model, and the loss function of the neural network model is constructed by:
[0030] Obtain a complete sample solution, and remove some nodes included in the sample solution to obtain an incomplete sample solution and unvisited sample nodes;
[0031] Inputting the sample incomplete solution and the unvisited sample node into a neural network model to obtain a predicted sample probability corresponding to covering the unvisited sample node with a label path, wherein the label path is a path where the unvisited sample node is located in the sample solution;
[0032] A loss function is constructed based on the predicted sample probability.
[0033] In a third aspect, an embodiment of the present invention further provides a terminal device, wherein the terminal device includes a memory, a processor, and a path problem solving program stored in the memory and executable on the processor, and when the processor executes the path problem solving program, the steps of the above-mentioned path problem solving method are implemented.
[0034] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, on which a path problem solving program is stored. When the path problem solving program is executed by a processor, the steps of the path problem solving method described above are implemented.
[0035] Beneficial effect: The present invention first constructs a preset solution, then filters out the current node from the unvisited nodes, and updates the preset solution with the current node, that is, changes the preset path contained in the preset solution so that the preset path after the change can cover the current node, thereby updating the preset solution, repeating the above operation, and continuing to connect other unvisited nodes to the updated preset solution to continue updating the preset solution until all unvisited nodes are connected to the solution, thereby forming a target solution. From the above analysis, it can be seen that each time the present invention connects a node to the preset solution, the path of the preset solution is changed, so that errors that may exist in the preset solution can be corrected, so that the total path corresponding to the target solution is constantly close to the shortest path, and finally the quality of the obtained target solution is high, thereby meeting actual needs. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Figure 1 It is the overall flow chart of the present invention;
[0037] Figure 2 A schematic diagram of node insertion for the traveling salesman problem in an embodiment of the present invention;
[0038] Figure 3 Schematic diagram of the traveling salesman problem in an embodiment of the present invention;
[0039] Figure 4 A schematic diagram of a vehicle routing problem with capacity constraints in an embodiment of the present invention;
[0040] Figure 5 is a structural diagram of a probability prediction model in an embodiment of the present invention;
[0041] Figure 6 is a flow chart of model training for the traveling salesman problem in an embodiment of the present invention;
[0042] Figure 7 is a flow chart of model training for solving the capacity-constrained vehicle routing problem in an embodiment of the present invention;
[0043] Figure 8 A flowchart of generating a target solution in an embodiment of the present invention;
[0044] Fig. 9 A schematic diagram of inserting nodes for a capacity-constrained vehicle routing problem in an embodiment of the present invention;
[0045] Fig.10 This is a block diagram of the internal structure principle of the terminal device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0046] The following is a clear and complete description of the technical solution of the present invention in combination with the embodiments and the accompanying drawings. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0047] Given multiple locations (nodes) to be visited, the order of visiting each location (node) needs to be planned in advance before visiting so that the total path length formed is the shortest. This is a path optimization problem. The prior art first uses some nodes to generate an incomplete solution (that is, an incomplete path), and then connects the remaining nodes to the end of the incomplete solution generated in the previous step, and repeats the above steps until a complete solution is generated. Since the incomplete solution generated in the previous step cannot be changed each time a node is connected, the incomplete solution generated in the previous step is solidified, so that even if there is an error in the incomplete solution of the previous step, it cannot be corrected by connecting a new node, resulting in a low quality of the final complete solution.
[0048] In order to solve the above technical problems, the present invention provides a path problem solving method, device, equipment and storage medium, which solves the problem of low quality of solutions generated by the prior art. In specific implementation, firstly, a node is selected from all nodes to construct a preset solution; then the previous node included in the preset solution is determined, and based on the previous node, the current node is filtered out from the unvisited nodes (where the unvisited node is a node among all nodes that is not selected by the preset solution, and the previous node is the last node selected when constructing the preset solution); finally, the preset path included in the preset solution is changed to cover the current node, so as to update the preset solution, and the target solution is obtained based on the updated preset solution.
[0049] For example, Figure 2 As shown, Figure 2The left side of the graph in Node 1-Node 2-Node 4-Node 5-Node 6-Node 1 is the preset solution. Since Node 3 and Node 7 have not been connected to the preset solution, Node 3 and Node 7 are unvisited nodes. Node 6 is the last node selected when building the preset solution, so Node 6 is the previous node. Since the Manhattan distance between Node 3 and Node 6 is less than the Manhattan distance between Node 7 and Node 6, Node 3 is used as the current node.
[0050] Figure 2 The preset solution presented in the left figure includes five preset paths: 1-2, 2-4, 4-5, 5-6, and 6-1. According to the location information of node 3 (the current node) and the location information of each preset path, a path is selected from the five preset paths, and the path is turned to node 3 (that is, node 3 is inserted into the path) to update the preset solution. If 2-4 is the path selected from the five preset paths, then the updated preset solution is Figure 2 The right figure in . Using the same method, insert node 7 into a preset path in the updated preset solution to obtain the target solution.
[0051] The path problem solving method of this embodiment can be applied to a terminal device, which can be a terminal product with data processing function, such as a computer. Figure 1 As shown in , the path problem solving method specifically includes the following steps:
[0052] S100, select nodes from all nodes to build a preset solution;
[0053] S200, determining a previous node included in the preset solution, and based on the previous node, filtering out the current node from unvisited nodes, wherein the unvisited nodes are nodes other than those selected by the preset solution among all nodes, and the previous node is the last node selected when constructing the preset solution;
[0054] S300, changing the preset path included in the preset solution to cover the current node, so as to update the preset solution, and obtaining a target solution according to the updated preset solution.
[0055] Steps S100, S200, and S300 of the present invention can be applied to solving the target solution of the traveling salesman problem:
[0056] like Figure 3As shown in the figure, given the coordinates of all cities that a traveling salesman needs to visit, it is required to find a path starting from a certain starting city, visiting each city only once, and finally returning to the starting city, so that the total distance traversed is the shortest. The above cities are nodes, and the path with the shortest total distance is the target solution. The traveling salesman problem includes the wiring, drilling optimization, and lithography path planning tasks of printed circuit boards.
[0057] Steps S100, S200, and S300 of the present invention can also be applied to solving the Capacitated Vehicle Routing Problem (CVRP):
[0058] like Figure 4 As shown in the figure, the task is to deliver goods from a central warehouse to multiple customers. The vehicle has a certain load capacity, and each customer (node) has specific cargo requirements. The goal is to plan the vehicle's delivery route so that the total driving distance of the vehicle is the shortest while meeting the needs of all customers, while ensuring that the vehicle's load during the delivery process does not exceed its maximum capacity (that is, if the vehicle's cargo is delivered or cannot meet the needs of any remaining customer during the delivery process, it needs to return to the warehouse to replenish the cargo). CVRP is widely used in various logistics and distribution systems, such as express delivery services, cargo transportation, waste collection and other fields. By optimizing the vehicle's path planning, transportation costs can be significantly reduced, resource utilization can be improved, and overall operational efficiency can be enhanced.
[0059] Embodiment 1: This embodiment provides a path problem solving device, such as Figure 5 As shown, the device includes a probability prediction model, which in turn includes an encoder, a decoder, a linear projection (i.e. Figure 5 The linear mapping in () and the normalization function (softmax), the data output by the normalization function is the predicted probability.
[0060] like Figure 5 As shown, the decoder includes L decoding layers, each decoding layer includes two attention layers, the output end of the encoder is connected to the input end of the first attention layer of the first decoding layer, the input end of the first attention layer of the first decoding layer is connected to the input end of the second attention layer of the first decoding layer, the output end of the first attention layer of the first decoding layer is connected to the input end of the second attention layer of the first decoding layer, the output end of the second attention layer of the first decoding layer is connected to the input end of the first attention layer of the second decoding layer, the input end of the first attention layer of the second decoding layer is connected to the input end of the second attention layer of the second decoding layer, the output end of the first attention layer of the second decoding layer is connected to the input end of the second attention layer of the second decoding layer, and so on to the Lth decoding layer.
[0061] The probability prediction model of this embodiment is obtained by training a neural network model, which includes an encoder, a decoder, a linear projection and a softmax. Training the neural network model is to adjust the parameters of the encoder, the decoder and the linear projection. The neural network model after training is a probability prediction model.
[0062] In this embodiment, the loss function used when training the neural network model is The method comprises the following specific steps: obtaining a complete sample solution, and removing some nodes included in the sample solution to obtain an incomplete sample solution and unvisited sample nodes; inputting the incomplete sample solution and the unvisited sample nodes into a neural network model to obtain a predicted sample probability corresponding to covering the unvisited sample nodes with a label path. The label path is the path where the unvisited sample nodes are located in the complete sample solution; based on the predicted sample probability Constructing the loss function in, is the sample path from the first sample path (sample path is also edge) to the lth sample path contained in the sample incomplete solution. S is a whole instance, including all nodes, θ is the parameter set of the neural network model, e * is the label path corresponding to the current sample node, Before the complete sample solution is disassembled or removed, all nodes are visited sample nodes, and the removed sample nodes are unvisited sample nodes. When the unvisited sample node is input into the neural network model, the node becomes the current sample node, and the sample path of the unvisited sample node in the complete sample solution is the label path; when the sample incomplete solution and the current sample node are input into the neural network model with parameter θ, the model predicts that the current sample node is inserted into the label path e * The probability of
[0063] Tag Path * The mark as Figure 6 As shown in Figure 2, after excluding the unvisited sample nodes π4 and π5, the two visited sample nodes adjacent to the current sample node π2 in the complete sample solution are π1 and π3. Therefore, the label path is e * =e1=(π1,π3).
[0064] For example, suppose that for a TSP instance with 10 nodes, its complete solution is (0,1,2,3,4,5,6,7,8,9,10), that is, a complete sample solution. First, delete the continuous solution fragment of length η=4: (4,5,6,7), that is, sample nodes 4,5,6,7 become unvisited sample nodes, and the remaining (0,1,2,3,8,9,10) are sample incomplete solutions. In the subsequent training process, the neural network model uses the complete sample solution as a label and learns to insert each unvisited sample node into the sample incomplete solution one by one until the original complete sample solution is re-formed. Specifically, in the first step of the training process, an unvisited sample node 5 is randomly selected, and the selected unvisited sample node 5 becomes the current sample node. It is predicted that the unvisited sample node 5 will be inserted into the label path (that is, e * ) (i.e. ), the label path is all the sample paths in the incomplete solution (0,1,2,3,8,9,10) (i.e. ). At this time, according to the complete sample solution, the inserted target edge (i.e., label path) of the unvisited sample node 5 is the sample path connecting node 3 and node 8. Assume that the probability predicted by the model at this time is Then the value of the loss function can be calculated as According to the value of the loss function, the existing optimizer (such as Adam) can calculate the gradient and then use the gradient descent algorithm to update the model parameters. In the second step of the training process, the incomplete sample solution is expanded to (0, 1, 2, 3, 5, 8, 9, 10), and the set of unvisited sample nodes is reduced to (4, 5, 7). Then, the unvisited sample node closest to the last inserted sample node, that is, node 4, is selected as the current sample node. According to the information of the loss function and the complete solution, the model continues to be trained to correctly insert the current sample node into the current incomplete solution. And so on, until all unvisited sample nodes are visited.
[0065] In this example, the parameters of the neural network model are updated through the loss function to complete the training of the neural network model. The trained neural network model is a probability prediction model. For the two problems of TSP and CVRP, training is performed on 1 million TSP and CVRP instances of 100 nodes respectively. For the neural network model, the embedding vector dimension d is set to 64, and the number of layers in the decoder is set to 6, that is, there are 6 decoding layers, each decoding layer includes two attention layers, so there are a total of 12 attention layers. In each attention layer, the head number of MHA is set to 16, and the dimension d of the feedforward layer is ffThe batch size is set to 1024. The optimizer is Adam and the initial learning rate is 1e-4. The learning rate decay value of the TSP model and the CVRP model is set to decay 0.97 per epoch. With a batch size of 1024, 100 epochs were trained for TSP and 60 epochs were trained for CVRP. A single NVIDIA GeForce RTX 3090 GPU with 24GB of video memory was used to train and test the neural network models.
[0066] The process of training the neural network model for the CVRP problem is as follows: Figure 7 As shown:
[0067] We start with solution fragments of different lengths (i.e., sample incomplete solutions) to reduce the training difficulty and make efficient use of label paths.
[0068] For example, given a problem instance with n customer nodes and 1 warehouse node and its complete sample solution, first delete the continuous solution fragments of length η∈[1,n-1] in the order of the solution, and the customer nodes in the deleted continuous solution fragments become unvisited customer nodes. Then, the model learns the label path that inserts the unvisited customer nodes into the solution fragments one by one under the supervision of the complete sample solution.
[0069] Embodiment 2 is based on embodiment 1. In this embodiment, step S100 includes the following specific steps: randomly selecting an initial node from all nodes, taking the initial node as the previous node of the first step, and continuing to select nodes from all nodes based on the distance between the previous node of the first step and all nodes, and the selected node is used as the previous node of the second step, connecting the previous node of the second step to the previous node of the first step, and continuing to select nodes from all nodes based on the distance between the previous node of the second step and all nodes, and the selected node is used as the previous node of the next step, until a preset solution is constructed.
[0070] Step S200 includes the following specific steps: determining the distance between the previous node and the unvisited nodes; and selecting the current node from the unvisited nodes based on the distance.
[0071] like Figure 8 As shown in the figure, the closed path surrounded by the nodes and arrows in each box is a preset solution. Inserting the current node selected from the unvisited nodes on the arrow of the previous preset solution becomes the next preset solution. Repeat the above operation until the number of unvisited nodes is reduced to zero. At this time, the target solution (that is, Figure 8 , the complete solution in ).
[0072] For the TSP problem, such as Figure 8As shown, the first step, step 1: randomly select an unvisited node from 6 nodes as the initial node, and the initial node becomes a visited node. Then select the node with the minimum Manhattan distance to the visited node from the remaining 5 nodes as the previous node, and form a closed path with the initial node and the previous node to obtain the preset solution of the first step, step 1. Then select the node with the minimum Manhattan distance to the previous node from the remaining 4 nodes as the current node, and then input the preset solution and the current node into the probability prediction model, that is, input the coordinate information of the path contained in the preset solution and the coordinate information of the current node into the probability prediction model, and the probability prediction model outputs the probability that the current node should be inserted on each path;
[0073] Step 2: Insert the current node into the path or edge corresponding to the maximum probability, and you will get the preset solution for step 2. Then use the same method as step 1 to determine the previous node, the current node, and the probability of the current node being inserted into each path.
[0074] The third step, step 3, generates another preset solution based on the second step, step 2. The fourth step, step 4, also generates a new preset solution based on the third step, step 3. The fifth step, step 5, generates the final complete target solution based on the fourth step, step 4.
[0075] For the CVRP problem, not only the coordinate information of the path included in the preset solution and the coordinate information of the current node are input into the probability prediction model, but also the demand information of the current node (such as the weight of the cargo required by the current node) and the remaining capacity of the vehicle are input into the probability prediction model. The other steps of generating a solution to the CVRP problem are the same as the other steps of generating a solution to the TSP problem. In addition, for the CVRP problem, when the remaining cargo of the vehicle cannot meet the demand of any unvisited customer node, the vehicle needs to return to the warehouse and reload the cargo before setting off again.
[0076] That is, generate a solution to solve CVRP such as Fig. 9 As shown:
[0077] Initially, all customer nodes are unvisited. In the first step, the warehouse node and its nearest unvisited nodes are initialized as an incomplete solution. The node selected in the last step is called the previous node, and the node selected in the current step is called the current node. In each step except the first step, only unvisited customer nodes can be selected as the current node. In each subsequent step, the model predicts: (1) the probability of inserting the current node into each edge in the incomplete solution and (2) the probability of inserting it between two duplicate copies of the warehouse node to start a new route. The model selects the edge with the maximum probability to insert the current node. Fig. 9 It provides an intermediate construction process of a solution. Among them, (0,π1,π2,0,π8,0) is the incomplete solution of the current step, π8 is the previous node, and π7 is the current node. The model needs to predict that the node π7 is inserted into an edge of the current incomplete solution, or inserted into the edge between two duplicate copies of the warehouse node to start a new sub-route. The incomplete solution at step t is represented as (0,π1,π2,…,0,π j ,π j+1 ,…,0,…,π t-1 ,0), where is the index of the visited client nodes. For example, an incomplete solution (that is, every preset solution) can be (0,1,2,0,4,5,6,0,7,8,0). The set of unvisited client nodes is
[0078] Embodiment 3, based on Embodiment 2 or Embodiment 1, step S300 in this embodiment includes the following specific steps S301, S302, S303, S304, S305, S306:
[0079] S301, constructing a real vector corresponding to the preset path according to the characteristics of the nodes located at both ends of the preset path
[0080] Let the incomplete solution at the current step be of length l, represented by (π1,π2,…,π l ). The features of the nodes at both ends of the preset path are input into the encoder in the probability prediction model, and the encoder outputs the true vector That is Figure 5 The edge embedding vector in :
[0081]
[0082] [·,·] represents horizontal concatenation of vectors. For the i-th node π iis the real vector corresponding to the preset path of the head node, where is the vector corresponding to the feature of the first node π1 (which is a visited node) in the preset solution, is the previous node π in the preset solution l The vector corresponding to the feature of (this node is a visited node), is the i+1th node π in the preset solution i+1 The vector corresponding to the feature of (this node is a visited node), is the i-th node π in the preset solution i (This node is a visited node) The vector corresponding to the feature. For the CVRP problem, the remaining capacity of the vehicle in the subpath where each edge is located needs to be horizontally spliced into the edge embedding vector.
[0083] Node π1 - ... - Node π i -Node π i+1 -...-Node π l -node π1, forming a closed access path, that is, visiting node π1-...-node π in sequence i -Node π i+1 -...-Node π l Finally, return to node π1.
[0084] Let i'∈{π1,…,π i ,π i+1 ,…,π l}, h i' =s i' W (0) +b (0) ,s i' is the node feature, including the node coordinate feature or the node requirement feature (for the TSP problem, the feature of each node is the coordinate, d x =2; for the CVRP problem, the characteristics of each node are the coordinates and the demand, d x =3), and are all learnable parameters in the encoder, that is, the function of the encoder is to generate h i' , d represents the embedding vector dimension.
[0085] S302: construct a pseudo vector corresponding to the current node according to the characteristics of the current node.
[0086] The current node is the unvisited node that will be connected to the preset solution. Let u j Represents the current node, the current node u j The characteristics are Then the pseudo vector It can be calculated by the following formula:
[0087]
[0088] S303, performing a union operation on the real vector and the pseudo vector to obtain a vector set X (0) .
[0089]
[0090] S304, the vector set X (0) and the pseudo vector As the input of the decoder, the updated vector set X output by the decoder is obtained (L) Each of the preset paths i" corresponds to the updated vector The decoder includes several attention layers, the vector set input to the previous attention layer serves as the input of the next attention layer, and the output of the previous attention layer serves as the input of the next attention layer.
[0091] X (0) and Y (0) Is the input of the first decoding layer, X (0) and Y (0) After inputting to the first decoding layer, The output of the decoding layer is
[0092]
[0093] and All are The input of the decoding layer, AttnLayer is the algorithm of each attention layer, which is the existing technology.
[0094] The total number of attention layers is L, and the input of the Lth decoding layer of the decoder is X (L-1) and Y (L-1) , the output is X (L) :
[0095] Y (L) =AttnLayer(Y (L-1) ,X (L-1) )
[0096] X (L) =AttnLayer(X (L-1) ,Y (L) )
[0097] The attention layer in this embodiment includes a multi-head attention (MHA) sublayer and a node feed-forward (FF) sublayer. Each sublayer is followed by a skip connection and normalization (Norm). and Represented as the input of the attention layer, is the output of the attention layer, which is calculated as follows:
[0098]
[0099] Here, X is often referred to as the query matrix (Q), and Y is both the key (K) and value (C) matrix.
[0100] To describe the multi-head attention (MHA) sublayer, we first describe the single-head attention function as follows:
[0101]
[0102] in, is a learnable parameter. The multi-head attention sublayer applies the single-head attention function h times in parallel, and each single-head attention parameter uses independent parameters:
[0103] MHA(A,B)=Concat(head1,…,head h )W O
[0104] head i =Attn i (A,B)
[0105] For each Attn i (A,B), d k =d v =d / h, is a learnable parameter.
[0106] S305, updating the vector corresponding to each preset path i″ Apply linear projection and softamx to obtain the prediction probability corresponding to each preset path i″, which is used to characterize the prediction probability p when the preset path covers the current node and the path formed by all nodes is the shortest. i″ :
[0107]
[0108] For all When i” is the preset path in the preset solution, a i” =x i” Otherwise a i”=-∞. x i” Calculated by the following formula:
[0109]
[0110] in is a learnable parameter and e is the base of the natural logarithm.
[0111] S306, based on the predicted probability corresponding to each of the preset paths, select a preferred path from the preset paths included in the preset solution, and use the current node as the turning point of the preferred path so that the preferred path covers the current node.
[0112] That is, if the current node u j Insert the preset path corresponding to the maximum probability, which is the preferred path. That is, turn the preferred path to the current node, and keep the current node unchanged, which is equivalent to inserting the current node into the preferred path. After the current node is inserted into the preferred path, it is equivalent to updating the preset solution (incomplete solution). The unvisited nodes are inserted into the incomplete solution one by one until all nodes are visited, at which time the final target solution is obtained.
[0113] Based on the above embodiments, the present invention further provides a terminal device, whose principle block diagram can be shown as follows: Fig.10 As shown. The terminal device includes a processor, a memory, a network interface, and a display screen connected via a system bus. Among them, the processor of the terminal device is used to provide computing and control capabilities. The memory of the terminal device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the terminal device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, a path problem solving method is implemented. The display screen of the terminal device can be a liquid crystal display screen or an electronic ink display screen.
[0114] Those skilled in the art will understand that Fig.10 The principle block diagram shown in the figure is only a block diagram of a partial structure related to the scheme of the present invention, and does not constitute a limitation on the terminal device to which the scheme of the present invention is applied. The specific terminal device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0115] In one embodiment, a terminal device is provided. The terminal device includes a memory, a processor, and a path problem solving program stored in the memory and executable on the processor. When the processor executes the path problem solving program, the following operation instructions are implemented:
[0116] Select nodes from all nodes to build a preset solution;
[0117] Determine the previous node included in the preset solution, and based on the previous node, filter out the current node from unvisited nodes, wherein the unvisited node is a node other than the node selected by the preset solution among all nodes, and the previous node is the last node selected when constructing the preset solution;
[0118] The preset path included in the preset solution is changed to cover the current node, so as to update the preset solution, and a target solution is obtained according to the updated preset solution.
[0119] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided by the present invention can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0120] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for solving a path problem, characterized in that: include: Select nodes from all nodes to build a preset solution; Determine the previous node included in the preset solution, and based on the previous node, filter out the current node from unvisited nodes, wherein the unvisited node is a node other than the node selected by the preset solution among all nodes, and the previous node is the last node selected when constructing the preset solution; The preset path included in the preset solution is changed to cover the current node, so as to update the preset solution, and a target solution is obtained according to the updated preset solution.
2. The path problem solving method according to claim 1, characterized in that: The step of selecting nodes from all nodes to construct a preset solution includes: An initial node is randomly selected from all nodes, and the initial node is used as the previous node of the first step. According to the distance between the previous node of the first step and all nodes, nodes are continuously selected from all nodes, and the selected node is used as the previous node of the second step. The previous node of the second step is connected to the previous node of the first step, and according to the distance between the previous node of the second step and all nodes, nodes are continuously selected from all nodes, and the selected node is used as the previous node of the next step, until a preset solution is constructed.
3. The path problem solving method according to claim 1, characterized in that: The step of selecting the current node from unvisited nodes based on the previous node includes: Determine the distance between the previous node and the unvisited node; The current node is selected from the unvisited nodes according to the distance.
4. The path problem solving method according to claim 1, characterized in that: The changing the preset path included in the preset solution to cover the current node includes: Constructing a real vector corresponding to the preset path according to the characteristics of the nodes located at both ends of the preset path; Constructing a pseudo vector corresponding to the current node according to the characteristics of the current node; According to the real vector and the pseudo vector, a preferred path is selected from the preset paths included in the preset solution, and the current node is used as an inflection point of the preferred path so that the preferred path covers the current node.
5. The path problem solving method according to claim 4, characterized in that: The step of selecting a preferred path from preset paths included in the preset solution according to the real vector and the pseudo vector includes: Performing a union operation on the real vector and the pseudo vector to obtain a vector set; The vector set and the pseudo vector are used as inputs of a decoder to obtain an updated real vector corresponding to each preset path output by the decoder, wherein the decoder includes a plurality of attention layers, the vector set input to the previous attention layer is used as input to the next attention layer, and the output of the previous attention layer is used as input to the next attention layer; According to the updated real vector corresponding to each of the preset paths, a preferred path is selected from the preset paths included in the preset solution.
6. The path problem solving method according to claim 5, characterized in that: The step of selecting a preferred path from the preset paths included in the preset solution according to the updated real vector corresponding to each preset path includes: Applying linear projection and softmax to the updated real vector corresponding to each of the preset paths to obtain a prediction probability corresponding to each of the preset paths, wherein the prediction probability is used to characterize the prediction probability when the path formed by all nodes is the shortest when the current node is covered by the preset path; According to the predicted probability corresponding to each of the preset paths, a preferred path is selected from the preset paths included in the preset solution.
7. A path problem solving device, characterized in that: A probability prediction model is included, which is used to predict the prediction probability corresponding to each preset path of the preset solution, the prediction probability is used to screen out a preferred path from the preset paths included in the preset solution, the preferred path is used to cover the current node to update the preset solution, and the preset solution after the update is used to determine the target solution; The probability prediction model is composed of an encoder, a decoder, a linear projection and a normalization function connected in sequence. The decoder includes several attention layers. The vector set input to the previous attention layer serves as the input of the next attention layer, and the output of the previous attention layer serves as the input of the next attention layer.
8. The path problem solving device according to claim 7, characterized in that: The probability prediction model is obtained by training a neural network model, and the loss function of the neural network model is constructed in a manner including: Obtain a complete sample solution, and remove some nodes included in the sample solution to obtain an incomplete sample solution and unvisited sample nodes; Inputting the sample incomplete solution and the unvisited sample node into a neural network model to obtain a predicted sample probability corresponding to covering the unvisited sample node with a label path, wherein the label path is a path where the unvisited sample node is located in the sample solution; A loss function is constructed based on the predicted sample probability.
9. A terminal device, characterized in that: The terminal device includes a memory, a processor, and a path problem solving program stored in the memory and executable on the processor. When the processor executes the path problem solving program, the steps of the path problem solving method according to any one of claims 1 to 6 are implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a path problem solving program, and when the path problem solving program is executed by the processor, the steps of the path problem solving method according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Method and device for generating solution of vehicle path problem
CN117073703A
Travel salesman cutting path planning method and device based on reinforcement learning
CN117787522A
Modeling a border gateway protocol network
US20170346727A1
Probabilistic resource allocation system with self-adaptive capability
US5586219A