A twin optimization method based on similar historical samples to solve the traveling salesman problem
Through a twin optimization method based on similar historical samples, using autoencoder and mapping matrix technology, the problem of insufficient search capabilities in solving the problem of larger-scale travel merchants is solved, and a more efficient solution process and better calculation results are achieved.
Patent Information
- Application Number
- CN202211242263.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-11
- Publication Date
- 2025-05-13
- Estimated Expiration
- 2042-10-11
AI Technical Summary
When traditional evolutionary algorithms solve the problem of larger travel merchants, their search capabilities are weak, resulting in longer calculation time and lower quality of calculation results.
Using a twin optimization method based on similar historical samples, the eigenvectors of the historical TSP and the target TSP are extracted through the autoencoder, the cosine distance is calculated, the twin TSP is constructed, and its solution is mapped to the search space of the target TSP through the mapping matrix.
It effectively reduces the time cost of solving the target TSP, improves the efficiency of matching the historical TSP with the target TSP, enhances the local search capability, and improves the quality of the calculation results.
Smart Images

Figure CN116245262B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of combinatorial optimization, and in particular to a twin optimization method based on similar historical samples for solving the traveling salesman problem. Background Art
[0002] The Traveling Salesman Problem (TSP) is a benchmark problem in the field of combinatorial optimization. Practical combinatorial optimization problems such as logistics distribution problems, automobile path planning problems, drone path planning problems, robot path planning problems, CNC machine tool path planning problems, and engraving machine path planning problems are all variants of TSP. The method for solving TSP can usually also solve the above practical combinatorial optimization problems. Therefore, designing an efficient method for solving TSP is of great significance to the development of the field of combinatorial optimization and solving practical combinatorial optimization problems.
[0003] TSP is an NP-Complete problem, and its time complexity increases exponentially with the increase of the problem size. At present, evolutionary algorithms (EAs) are usually used to solve large-scale TSP. Evolutionary algorithms have high flexibility and can obtain high-quality calculation results within an acceptable time. However, when solving problems, traditional EAs often assume that the prior knowledge of the problem is zero. Therefore, when solving large-scale TSP, EAs have weak search capabilities, resulting in long calculation time and low quality of calculation results. Problems in the real world do not exist in isolation. The tasks currently encountered may be similar to those completed at some point in history. For example, the path planning of a traffic intersection this Sunday and the path planning of the intersection last Sunday. Summary of the invention
[0004] The purpose of the present invention is to provide a twin optimization method based on similar historical samples for solving the traveling salesman problem, comprising the following steps:
[0005] 1) Build a historical TSP database, including historical TSP data and solutions.
[0006] 2) Construct an autoencoder, input all historical TSP data in the historical TSP database into the autoencoder in sequence, obtain the feature vector corresponding to each historical TSP, and store the feature vectors corresponding to all historical TSPs into the Mivlus vector database.
[0007] 3) Divide the feature vectors of all historical TSPs stored in the Mivlus vector database into several clusters, recorded as historical TSP clusters, and record the feature vector of the cluster center of each historical TSP cluster.
[0008] 4) Obtain the data of the target TSP, input the data of the target TSP into the autoencoder, and obtain the feature vector of the target TSP.
[0009] 5) Calculate the cosine distance between the feature vector of the target TSP and the feature vector of the cluster center of each historical TSP cluster, and determine the cluster whose cosine distance is less than the preset value, which is recorded as the coarsely selected twin TSP cluster.
[0010] 6) Calculate the cosine distance between the feature vectors of all historical TSPs of the roughly selected twin TSP cluster and the feature vector of the target TSP, and determine the minimum cosine distance.
[0011] 7) Construct the twin TSP of the target TSP based on the minimum cosine distance and determine the data and solution of the twin TSP.
[0012] 8) Learn the mapping matrix between the twin TSP and the target TSP.
[0013] 9) Map the solution of the twin TSP to the search space of the target TSP through the mapping matrix to obtain the initial solution G of the evolutionary algorithm EAs t .
[0014] 10) Iterate the initial solution of the evolutionary algorithm EAs, and output the solution to the target TSP after reaching the set number of iterations.
[0015] Furthermore, the TSP data includes city coordinate points.
[0016] Furthermore, the autoencoder consists of an input layer, a hidden layer and an output layer.
[0017] Further, the step of obtaining the TSP feature vector by the autoencoder includes:
[0018] 1) Draw the city coordinate points of TSP as pixel points on the image.
[0019] 2) Extract the binary matrix of the image and input it into the autoencoder.
[0020] 3) Calculate the eigenvector of the binary matrix as the eigenvector of TSP.
[0021] Furthermore, the method of dividing the feature vectors of all historical TSPs stored in the Mivlus vector database into several clusters includes a k-means clustering algorithm.
[0022] Furthermore, the calculation formula of the cosine distance dist(A, B) is as follows:
[0023]
[0024] In the formula, A and B represent two different TSPs. A and h B represent the eigenvectors of A and B respectively, ||h A ||2 represents h A The Euclidean norm of ||h B ||2 represents h B The Euclidean norm of .
[0025] Furthermore, the construction of the twin TSP of the target TSP includes the following steps:
[0026] 1) Determine whether the minimum cosine distance is less than the set value. If the minimum cosine distance is less than the set value, proceed to step 2); if the minimum cosine distance is greater than or equal to the set value, proceed to step 3).
[0027] 2) The TSP corresponding to the eigenvector with the smallest cosine distance to the target TSP is taken as the twin TSP of the target TSP, and the data and solution of the twin TSP are obtained from the historical TSP database.
[0028] 3) Constructing a twin TSP for the target TSP through a fast resampling method based on graph filters, including the following steps:
[0029] 3.1) Assume that the city coordinate set P of the target TSP is as follows:
[0030] P = {p i =(x i ,y i )|i=1,…N} (2)
[0031] In the formula, p i is the coordinate point of city i, x i and i Respectively represent the horizontal and vertical coordinates of the coordinate point of city i. N is the total number of cities in the city coordinate set P of the target TSP.
[0032] 3.2) Normalize the target TSP data.
[0033] 3.3) Use K nearest neighbor algorithm to obtain city p i The neighbor set δ i , the neighbor set δ i As shown below:
[0034] δ i ={δ i,1 ,δ i,2 …δ i,m} (3)
[0035] In the formula, δ i,m For the city i The mth neighbor city of .
[0036] 3.4) Calculate the weight matrix W. For any city P in the target TSP city coordinate set P i and City P j , City P i and City P j The weight W between i,j The calculation formula is as follows:
[0037]
[0038] Where σ is a predefined parameter. i,j represents the weight between city i and city j, W i,i =1, ‖‖2 represents the Euclidean norm.
[0039] 3.5) Calculate the diagonal matrix D of the density around each city in the city coordinate set P representing the target TSP, and the diagonal elements D i,i The calculation formula is as follows:
[0040]
[0041] 3.6) Calculate the transfer matrix A. The calculation formula of the transfer matrix A is as follows:
[0042] A=D -1 W (6).
[0043] 3.7) Construct an identity matrix I of the same dimension as the transfer matrix A.
[0044] 3.8) Construct a first-order filter F, which is as follows:
[0045] F=IA (7).
[0046] 3.9) Calculate the characteristic response res of the city coordinate set P of the target TSP, and the characteristic response res is as follows:
[0047] res=F×P∈R N×2 (8).
[0048] 3.10) Calculate the resampling probability r of each city i in the city coordinate set P of the target TSP in turn i , the resampling probability r i The calculation formula is as follows:
[0049]
[0050] 3.11) Calculate the number of cities s in the twin TSP. The calculation formula for the number of cities s in the twin TSP is as follows:
[0051] s=α×N (10)
[0052] Where, parameter α∈[0,1].
[0053] 3.12) The resampling probability r of each city i i Sort from high to low, and select the first s cities in the sort to form the twin TSP.
[0054] 3.13) Use evolutionary algorithms EAs to solve the twin TSP to obtain solutions, and store the data and solutions of the twin TSP in the historical TSP database.
[0055] Further, the learning of the mapping matrix between the twin TSP and the target TSP includes the following steps:
[0056] 1) Set T s represents twin TSP, containing n s Cities, T t represents the target TSP, containing n t cities.
[0057] 2) Calculate T in sequence s City P i With T t City P j The Euclidean distance e ij , and determine T s All cities in T t Middle City P j The minimum Euclidean distance
[0058] 3) The construction dimension is n s ×n t The zero matrix D of .
[0059] 4) Calculate T in sequence s City P i With T t City P j The weight d ij , and stored in the matrix D, weight d ij The calculation formula is as follows:
[0060]
[0061] 5) The construction dimension is n s ×n t The elements in the matrix M are random numbers drawn from the interval [0,1).
[0062] 6) Solve the minimum value f of the optimization problem and obtain the corresponding mapping matrix M.
[0063] The calculation formula for the minimum value f of the optimization problem is as follows:
[0064]
[0065] In the formula, ||T S ×MT t || F represents the mapping error, |||| F represents the Frobenius norm. λ|D⊙M||1 represents T t The city and T s The distance constraint between the cities in , where λ = b, ||||1 represents the l1 norm, and ⊙ represents the Hadamard product operator.
[0066] The corresponding mapping matrix M is expressed as follows:
[0067]
[0068] In the formula, the elements in M represent T s A city in T t The weight value corresponding to a city in .
[0069] Further, mapping the solution of the twin TSP to the search space of the target TSP through the mapping matrix includes the following steps:
[0070] 1) Obtain the solution G of the twin TSP from the historical TSP database.
[0071] 2) Use the mapping matrix M and solution G to calculate the solution G that maps solution G to the target TSP search space t , solution G t The calculation formula is as follows:
[0072] G×M=G t (14).
[0073] Furthermore, the method for iteratively calculating the initial solution of the evolutionary algorithm EAs includes 2-opt and 2-swap local search operators.
[0074] It is worth noting that the use of the mapping matrix to map the solution of the twin TSP to the search space of the target TSP should satisfy mapping rule one and mapping rule two.
[0075] Rule 1: If a city P in the target TSP bThere are multiple cities corresponding to the twin TSP. These cities are regarded as a set. The absolute value of the city correspondence in the mapping matrix M multiplied by the proportion is used as the selection probability. A city is randomly selected from the set to replace the city P in G using the roulette wheel selection method. b Assume that the target TSP city P i Urban P with twin TSP j , P k and P l Correspondingly, select city P j The probability p(j) is calculated by the following formula.
[0076]
[0077] in, and The cities P of the target TSP are i Urban P with twin TSP j , P k and P l The correspondence degree.
[0078] Rule 2: If multiple cities in the target TSP are related to cities P in the twin TSP a Correspondingly, these cities are regarded as a set to replace the city P in G a location.
[0079] The technical effect of the present invention is undoubted, and the advantages of the present invention are:
[0080] 1) Extract the feature vectors of the historical TSP and the target TSP through the autoencoder. Calculate the cosine similarity between the feature vectors of the historical TSP and the target TSP and store them in the Milvus vector database. Put the time cost of learning and training a large number of historical TSPs by the autoencoder before solving the target TSP, which effectively reduces the time cost of solving the target TSP.
[0081] 2) The feature vectors in the Milvus vector database are clustered into multiple clusters using the k-means clustering algorithm. First, the distance between the target TSP feature vector and the center of each cluster is compared, and then the clusters closest to the target TSP feature vector are selected. Next, all feature vectors in these corresponding clusters are obtained, and the distance between each feature vector and the target task feature vector is calculated in turn, and the TSP corresponding to the feature vector with the closest distance is used as the twin TSP. This method improves the efficiency of matching the historical TSP with the target TSP.
[0082] 3) When there is no historical TSP similar to the target TSP in the historical TSP database, a fast resampling method based on graph filters is used to construct a twin TSP similar to the target TSP.
[0083] 4) A mapping strategy based on sparse mapping matrix is proposed, which can map the solution of historical TSP into the target TSP and effectively suppress negative transfer.
[0084] 5) 2-opt and 2-swap local search operators are used as the search strategy of EAs to effectively improve the local search capability. BRIEF DESCRIPTION OF THE DRAWINGS
[0085] Figure 1 This is the overall flow chart of a twin optimization method based on similar historical samples to solve the traveling salesman problem;
[0086] Figure 2 This is the structural diagram of the traditional autoencoder;
[0087] Figure 3 This is a schematic diagram of mapping rule 2. DETAILED DESCRIPTION
[0088] The present invention is further described below in conjunction with the embodiments, but it should not be understood that the above subject matter of the present invention is limited to the following embodiments. Without departing from the above technical ideas of the present invention, various substitutions and changes are made according to the common technical knowledge and customary means in the art, which should all be included in the protection scope of the present invention.
[0089] Embodiment 1:
[0090] See also Figures 1 to 3 , a twin optimization method based on similar historical samples for solving the traveling salesman problem, comprising the following steps:
[0091] 1) Build a historical TSP database, including historical TSP data and solutions.
[0092] 2) Construct an autoencoder, input all historical TSP data in the historical TSP database into the autoencoder in sequence, obtain the feature vector corresponding to each historical TSP, and store the feature vectors corresponding to all historical TSPs into the Mivlus vector database.
[0093] 3) Divide the feature vectors of all historical TSPs stored in the Mivlus vector database into several clusters, recorded as historical TSP clusters, and record the feature vector of the cluster center of each historical TSP cluster.
[0094] 4) Obtain the data of the target TSP, input the data of the target TSP into the autoencoder, and obtain the feature vector of the target TSP.
[0095] 5) Calculate the cosine distance between the feature vector of the target TSP and the feature vector of the cluster center of each historical TSP cluster, and determine the cluster whose cosine distance is less than the preset value, which is recorded as the coarsely selected twin TSP cluster.
[0096] 6) Calculate the cosine distance between the feature vectors of all historical TSPs of the roughly selected twin TSP cluster and the feature vector of the target TSP, and determine the minimum cosine distance.
[0097] 7) Construct the twin TSP of the target TSP based on the minimum cosine distance and determine the data and solution of the twin TSP.
[0098] 8) Learn the mapping matrix between the twin TSP and the target TSP.
[0099] 9) Map the solution of the twin TSP to the search space of the target TSP through the mapping matrix to obtain the initial solution G of the evolutionary algorithm EAs t .
[0100] 10) Iterate the initial solution of the evolutionary algorithm EAs, and output the solution to the target TSP after reaching the set number of iterations.
[0101] The data of the TSP includes city coordinate points.
[0102] The autoencoder consists of an input layer, a hidden layer and an output layer, including two parts: an encoder and a decoder.
[0103] The step of obtaining the TSP feature vector by the autoencoder comprises:
[0104] 1) Draw the city coordinate points of TSP as pixel points on the image.
[0105] 2) Extract the binary matrix of the image and input it into the autoencoder.
[0106] 3) Calculate the eigenvector of the binary matrix as the eigenvector of TSP.
[0107] The method for dividing the feature vectors of all historical TSPs stored in the Mivlus vector database into several clusters includes a k-means clustering algorithm.
[0108] The calculation formula of the cosine distance dist(A, B) is as follows:
[0109]
[0110] In the formula, A and B represent two different TSPs. A and h B represent the eigenvectors of A and B respectively, ||h A ||2 represents h A The Euclidean norm of ||h B ||2 represents h B The Euclidean norm of .
[0111] The construction of the twin TSP of the target TSP includes the following steps:
[0112] 1) Determine whether the minimum cosine distance is less than the set value. If the minimum cosine distance is less than the set value, proceed to step 2); if the minimum cosine distance is greater than or equal to the set value, proceed to step 3).
[0113] 2) The TSP corresponding to the eigenvector with the smallest cosine distance to the target TSP is taken as the twin TSP of the target TSP, and the data and solution of the twin TSP are obtained from the historical TSP database.
[0114] 3) Constructing a twin TSP for the target TSP through a fast resampling method based on graph filters, including the following steps:
[0115] 3.1) Assume that the city coordinate set P of the target TSP is as follows:
[0116] P = {p i =(x i ,y i )|i=1,…N} (2)
[0117] In the formula, p i is the coordinate point of city i, x i and i Respectively represent the horizontal and vertical coordinates of the coordinate point of city i. N is the total number of cities in the city coordinate set P of the target TSP.
[0118] 3.2) Normalize the target TSP data.
[0119] 3.3) Use K nearest neighbor algorithm to obtain city p i The neighbor set δ i , the neighbor set δ i As shown below:
[0120] δ i ={δ i,1 ,δ i,2 …δ i,m} (3)
[0121] In the formula, δ i,m For the city i The mth neighbor city of .
[0122] 3.4) Calculate the weight matrix W. For any city P in the target TSP city coordinate set P i and City P j , City P i and City P j The weight W between i,j The calculation formula is as follows:
[0123]
[0124] Where σ is a predefined parameter, σ = 0.1. i,j represents the weight between city i and city j, W i,i =1, ‖‖2 represents the Euclidean norm.
[0125] 3.5) Calculate the diagonal matrix D of the density around each city in the city coordinate set P representing the target TSP, and the diagonal elements D i,i The calculation formula is as follows:
[0126]
[0127] 3.6) Calculate the transfer matrix A. The calculation formula of the transfer matrix A is as follows:
[0128] A=D -1 W (6).
[0129] 3.7) Construct an identity matrix I of the same dimension as the transfer matrix A.
[0130] 3.8) Construct a first-order filter F, which is as follows:
[0131] F=IA (7).
[0132] 3.9) Calculate the characteristic response res of the city coordinate set P of the target TSP, and the characteristic response res is as follows:
[0133] res=F×P∈R N×2 (8).
[0134] 3.10) Calculate the resampling probability r of each city i in the city coordinate set P of the target TSP in turn i , the resampling probability r i The calculation formula is as follows:
[0135]
[0136] 3.11) Calculate the number of cities s in the twin TSP. The calculation formula for the number of cities s in the twin TSP is as follows:
[0137] s=α×N (10)
[0138] Where, parameter α∈[0,1].
[0139] 3.12) The resampling probability r of each city i i Sort from high to low, and select the first s cities in the sort to form the twin TSP.
[0140] 3.13) Use evolutionary algorithms EAs to solve the twin TSP to obtain solutions, and store the data and solutions of the twin TSP in the historical TSP database.
[0141] The learning of the mapping matrix between the twin TSP and the target TSP includes the following steps:
[0142] 1) Set T s represents twin TSP, containing n s Cities, T t represents the target TSP, containing n t cities.
[0143] 2) Calculate T in sequence s City P i With T t City P j The Euclidean distance e ij , and determine T s All cities in T t Middle City P j The minimum Euclidean distance
[0144] 3) The construction dimension is n s ×n t The zero matrix D of .
[0145] 4) Calculate T in sequence s City P i With T t City P j The weight d ij , and stored in the matrix D, weight d ij The calculation formula is as follows:
[0146]
[0147] 5) The construction dimension is n s ×n t The elements in the matrix M are random numbers drawn from the interval [0,1).
[0148] 6) Solve the minimum value f of the optimization problem and obtain the corresponding mapping matrix M.
[0149] The calculation formula for the minimum value f of the optimization problem is as follows:
[0150]
[0151] In the formula, ||T S ×MT t || F represents the mapping error, ||||F represents the Frobenius norm. λ|D⊙M||1 represents T t The city and T s The distance constraint between cities in , where λ = 0.3, ||||1 represents the l1 norm, and ⊙ represents the Hadamard product operator.
[0152] The corresponding mapping matrix M is expressed as follows:
[0153]
[0154] In the formula, the elements in M represent T s A city in T t The weight value corresponding to a city in .
[0155] The mapping of the solution of the twin TSP to the search space of the target TSP through the mapping matrix includes the following steps:
[0156] 1) Obtain the solution G of the twin TSP from the historical TSP database.
[0157] 2) Use the mapping matrix M and solution G to calculate the solution G that maps solution G to the target TSP search space t , solution G t The calculation formula is as follows:
[0158] G×M=G t (14).
[0159] The method for iteratively calculating the initial solution of the evolutionary algorithm EAs includes 2-opt and 2-swap local search operators.
[0160] The use of the mapping matrix to map the solution of the twin TSP to the search space of the target TSP should satisfy mapping rule one and mapping rule two.
[0161] Rule 1: If a city P in the target TSP b There are multiple cities corresponding to the twin TSP. These cities are regarded as a set. The absolute value of the city correspondence in the mapping matrix M multiplied by the proportion is used as the selection probability. A city is randomly selected from the set to replace the city P in G using the roulette wheel selection method. b Assume that the city P of the target TSP i Urban P with twin TSP j , P k and P l Correspondingly, select city P j The probability p(j) is calculated by the following formula.
[0162]
[0163] in, and The cities P of the target TSP are i Urban P with twin TSP j , P k and P l The correspondence degree.
[0164] Rule 2: If multiple cities in the target TSP are related to cities P in the twin TSP a Correspondingly, these cities are regarded as a set to replace the city P in G a location.
[0165] Embodiment 2:
[0166] See also Figures 1 to 3 , a twin optimization method based on similar historical samples for solving the traveling salesman problem, comprising the following steps:
[0167] 1) Build a historical TSP database, including historical TSP data and solutions.
[0168] 2) Construct an autoencoder, input all historical TSP data in the historical TSP database into the autoencoder in sequence, obtain the feature vector corresponding to each historical TSP, and store the feature vectors corresponding to all historical TSPs into the Mivlus vector database.
[0169] 3) Divide the feature vectors of all historical TSPs stored in the Mivlus vector database into several clusters, recorded as historical TSP clusters, and record the feature vector of the cluster center of each historical TSP cluster.
[0170] 4) Obtain the data of the target TSP, input the data of the target TSP into the autoencoder, and obtain the feature vector of the target TSP.
[0171] 5) Calculate the cosine distance between the feature vector of the target TSP and the feature vector of the cluster center of each historical TSP cluster, and determine the cluster whose cosine distance is less than the preset value, which is recorded as the coarsely selected twin TSP cluster.
[0172] 6) Calculate the cosine distance between the feature vectors of all historical TSPs of the roughly selected twin TSP cluster and the feature vector of the target TSP, and determine the minimum cosine distance.
[0173] 7) Construct the twin TSP of the target TSP based on the minimum cosine distance and determine the data and solution of the twin TSP.
[0174] 8) Learn the mapping matrix between the twin TSP and the target TSP.
[0175] 9) Map the solution of the twin TSP to the search space of the target TSP through the mapping matrix to obtain the initial solution G of the evolutionary algorithm EAs t .
[0176] 10) Iterate the initial solution of the evolutionary algorithm EAs, and output the solution to the target TSP after reaching the set number of iterations.
[0177] Embodiment 3:
[0178] A twin optimization method based on similar historical samples for solving the traveling salesman problem, the main steps of which are shown in Example 2, wherein the TSP data includes city coordinate points.
[0179] Embodiment 4:
[0180] A twin optimization method based on similar historical samples for solving the traveling salesman problem, the main steps of which are shown in Example 2. The autoencoder consists of an input layer, a hidden layer and an output layer, including an encoder and a decoder.
[0181] Embodiment 5:
[0182] A twin optimization method based on similar historical samples for solving the traveling salesman problem, the main steps of which are shown in Example 2, wherein the step of obtaining a TSP feature vector through an autoencoder comprises:
[0183] 1) Draw the city coordinate points of TSP as pixel points on the image.
[0184] 2) Extract the binary matrix of the image and input it into the autoencoder.
[0185] 3) Calculate the eigenvector of the binary matrix as the eigenvector of TSP.
[0186] Embodiment 6:
[0187] A twin optimization method based on similar historical samples for solving the traveling salesman problem, the main steps of which are shown in Example 2, wherein the method for dividing the feature vectors of all historical TSPs stored in the Mivlus vector database into several clusters includes a k-means clustering algorithm.
[0188] Embodiment 7:
[0189] A twin optimization method based on similar historical samples for solving the traveling salesman problem, the main steps are shown in Example 2, and the calculation formula of the cosine distance dist(A, B) is as follows:
[0190]
[0191] In the formula, A and B represent two different TSPs. A and hB represent the eigenvectors of A and B respectively, ||h A ||2 represents h A The Euclidean norm of ||h B ||2 represents h B The Euclidean norm of .
[0192] Embodiment 8:
[0193] A twin optimization method based on similar historical samples for solving the traveling salesman problem, the main steps of which are shown in Example 2, wherein the twin TSP of the target TSP is constructed including the following steps:
[0194] 1) Determine whether the minimum cosine distance is less than the set value. If the minimum cosine distance is less than the set value, proceed to step 2); if the minimum cosine distance is greater than or equal to the set value, proceed to step 3).
[0195] 2) The TSP corresponding to the eigenvector with the smallest cosine distance to the target TSP is taken as the twin TSP of the target TSP, and the data and solution of the twin TSP are obtained from the historical TSP database.
[0196] 3) Constructing a twin TSP for the target TSP through a fast resampling method based on graph filters, including the following steps:
[0197] 3.1) Assume that the city coordinate set P of the target TSP is as follows:
[0198] P = {p i =(x i ,y i )|i=1,…N} (2)
[0199] In the formula, p i is the coordinate point of city i, x i and i Respectively represent the horizontal and vertical coordinates of the coordinate point of city i. N is the total number of cities in the city coordinate set P of the target TSP.
[0200] 3.2) Normalize the target TSP data.
[0201] 3.3) Use K nearest neighbor algorithm to obtain city p i The neighbor set δ i , the neighbor set δ i As shown below:
[0202] δ i ={δ i,1 ,δ i,2 …δ i,m} (3)
[0203] In the formula, δ i,mFor the city i The mth neighbor city of .
[0204] 3.4) Calculate the weight matrix W. For any city P in the target TSP city coordinate set P i and City P j , City P i and City P j The weight W between i,j The calculation formula is as follows:
[0205]
[0206] Where σ is a predefined parameter, σ = 0.1. i,j represents the weight between city i and city j, W i,i =1, ‖‖2 represents the Euclidean norm.
[0207] 3.5) Calculate the diagonal matrix D of the density around each city in the city coordinate set P representing the target TSP, and the diagonal elements D i,i The calculation formula is as follows:
[0208]
[0209] 3.6) Calculate the transfer matrix A. The calculation formula of the transfer matrix A is as follows:
[0210] A=D -1 W (6).
[0211] 3.7) Construct an identity matrix I of the same dimension as the transfer matrix A.
[0212] 3.8) Construct a first-order filter F, which is as follows:
[0213] F=IA (7).
[0214] 3.9) Calculate the characteristic response res of the city coordinate set P of the target TSP, and the characteristic response res is as follows:
[0215] res=F×P∈R N×2 (8).
[0216] 3.10) Calculate the resampling probability r of each city i in the city coordinate set P of the target TSP in turn i , the resampling probability r i The calculation formula is as follows:
[0217]
[0218] 3.11) Calculate the number of cities s in the twin TSP. The calculation formula for the number of cities s in the twin TSP is as follows:
[0219] s=α×N (10)
[0220] Where, parameter α∈[0,1].
[0221] 3.12) The resampling probability r of each city i i Sort from high to low, and select the first s cities in the sort to form the twin TSP.
[0222] 3.13) Use evolutionary algorithms EAs to solve the twin TSP to obtain solutions, and store the data and solutions of the twin TSP in the historical TSP database.
[0223] Embodiment 9:
[0224] A twin optimization method based on similar historical samples for solving the traveling salesman problem, the main steps of which are shown in Example 2, wherein the mapping matrix of learning the twin TSP and the target TSP includes the following steps:
[0225] 1) Set T s represents twin TSP, containing n s Cities, T t represents the target TSP, containing n t cities.
[0226] 2) Calculate T in sequence s City P i With T t City P j The Euclidean distance e ij , and determine T s All cities in T t Middle City P j The minimum Euclidean distance
[0227] 3) The construction dimension is n s ×n t The zero matrix D of .
[0228] 4) Calculate T in sequence s City P i With T t City P j The weight d ij , and stored in the matrix D, weight d ij The calculation formula is as follows:
[0229]
[0230] 5) The construction dimension is ns ×n t The elements in the matrix M are random numbers drawn from the interval [0,1).
[0231] 6) Solve the minimum value f of the optimization problem and obtain the corresponding mapping matrix M.
[0232] The calculation formula for the minimum value f of the optimization problem is as follows:
[0233]
[0234] In the formula, ||T S ×MT t || F represents the mapping error, |||| F represents the Frobenius norm. λ|D⊙M||1 represents T t The city and T s The distance constraint between cities in , where λ = 0.3, ||||1 represents the l1 norm, and ⊙ represents the Hadamard product operator.
[0235] The corresponding mapping matrix M is expressed as follows:
[0236]
[0237] In the formula, the elements in M represent T s A city in T t The weight value corresponding to a city in .
[0238] Embodiment 10:
[0239] A twin optimization method for solving the traveling salesman problem based on similar historical samples, the main steps of which are shown in Example 2, wherein the mapping of the twin TSP solution to the search space of the target TSP through the mapping matrix includes the following steps:
[0240] 1) Obtain the solution G of the twin TSP from the historical TSP database.
[0241] 2) Use the mapping matrix M and solution G to calculate the solution G that maps solution G to the target TSP search space t , solution G t The calculation formula is as follows:
[0242] G×M=G t (14).
[0243] Embodiment 11:
[0244] A twin optimization method based on similar historical samples for solving the traveling salesman problem, the main steps of which are shown in Example 2, wherein the method for iteratively calculating the initial solution of the evolutionary algorithm EAs includes 2-opt and 2-swap local search operators.
[0245] The use of the mapping matrix to map the solution of the twin TSP to the search space of the target TSP should satisfy mapping rule one and mapping rule two.
[0246] Rule 1: If a city P in the target TSP b There are multiple cities corresponding to the twin TSP. These cities are regarded as a set. The absolute value of the city correspondence in the mapping matrix M multiplied by the proportion is used as the selection probability. A city is randomly selected from the set to replace the city P in G using the roulette wheel selection method. b Assume that the target TSP city P i Urban P with twin TSP j , P k and P l Correspondingly, select city P j The probability p(j) is calculated by the following formula.
[0247]
[0248] in, and The cities P of the target TSP are i Urban P with twin TSP j , P k and P l The correspondence degree.
[0249] Rule 2: If multiple cities in the target TSP are related to cities P in the twin TSP a Correspondingly, these cities are regarded as a set to replace the city P in G a location.
[0250] Embodiment 12:
[0251] See also Figures 1 to 3 ,The purpose of the present invention is to provide a twin optimization method based on ,similar historical samples for solving the traveling salesman problem, which can ,be used to efficiently solve large-scale TSP.
[0252] The present invention provides a twin optimization method based on similar historical samples for solving the traveling salesman problem, comprising the following steps:
[0253] S1 builds a historical TSP database, which contains the data and solutions of the solved TSP.
[0254] S2 inputs the data of all TSPs in the historical TSP database into the autoencoder in sequence, obtains the feature vector of each historical TSP, and stores the feature vectors of all historical TSPs into the Mivlus vector database.
[0255] S3 inputs the data of the target TSP into the autoencoder to obtain the feature vector of the target TSP.
[0256] S4 uses the k-means clustering algorithm to divide the feature vectors stored in the Mivlus vector database into multiple clusters and records the cluster center of each cluster.
[0257] S5 calculates the cosine distance between the feature vector of the target TSP and the feature vector of each cluster center, and determines several classes with smaller cosine distances.
[0258] S6 calculates the cosine distance between the eigenvectors of several classes with smaller cosine distances and the eigenvector of the target TSP, and determines the minimum cosine distance. If the minimum cosine distance meets the set value, the TSP corresponding to the eigenvector with the smallest cosine distance to the target TSP is used as the twin TSP of the target TSP. If the minimum cosine distance does not meet the set value, it means that there is no TSP similar to the target TSP in the historical TSP database, and a fast resampling method based on a graph filter is needed to construct a twin TSP for the target TSP, and EAs are used to calculate the solution of the twin TSP.
[0259] S7 obtains data and solutions of twin TSP.
[0260] S8 learns the mapping matrix between the twin TSP and the target TSP.
[0261] S9 uses the mapping matrix to map the solution of the twin TSP into the search space of the target TSP as the initial solution of EAs.
[0262] S10 uses 2-opt and 2-swap local search operators to iteratively calculate the initial solution and outputs the solution to the target TSP after reaching the set number of iterations.
[0263] The data of the TSP are city coordinates.
[0264] The autoencoder described in S2 consists of an input layer, a hidden layer and an output layer, including two parts: an encoder and a decoder.
[0265] The specific steps of S2 and S3 using the autoencoder to extract the TSP feature vector include:
[0266] (1) The city points of TSP are regarded as pixels and drawn on an image of fixed size.
[0267] (2) Extract the binary matrix of the image and input it into the autoencoder.
[0268] The calculation formula of cosine distance is as follows.
[0269]
[0270] Where A and B represent a TSP respectively. A and h B represent the eigenvectors of A and B respectively, ||h A ||2 represents h A The Euclidean norm of ||h B ||2 represents h B The Euclidean norm of .
[0271] Assume that the target TSP city set can be expressed as P = {p i =(x i ,y i )|i=1,…N}, then the specific steps of the fast resampling method based on graph filter described in S6 include:
[0272] Normalize the data of the target TSP.
[0273] Use K-nearest neighbor (KNN) algorithm to obtain the p i The neighbor set of i ={δ i,1 ,δ i,2 …δ i,k}.
[0274] Calculate the weighted matrix W. For any city P in P i and P j , P i and P j The weight W between i,j Calculated by the following formula.
[0275]
[0276] Where, σ is a predefined parameter, σ=0.1. i,j represents the distance measure between cities i and j, W i,i =1.
[0277] Calculate the diagonal matrix D that can represent the density around each city in P. The diagonal elements are calculated using the following formula.
[0278]
[0279] Calculate the transfer matrix A = D -1 W.
[0280] Construct an identity matrix I of the same dimension as A.
[0281] Construct a first-order filter F = IA
[0282] Calculate the characteristic response of P res = F × P ∈ R N×2
[0283] Calculate the resampling probability of city points in P one by one Where ‖‖2 represents the l2 norm.
[0284] (10) Calculate the number of cities in the twin TSP s = α × N, where α ∈ [0, 1].
[0285] (11) According to the r of each city point i Select s city points from high to low to form a twin TSP.
[0286] (12) Use EAs to solve the twin TSP and obtain the solution, and store the data and solution of the twin TSP in the historical TSP database.
[0287] Assume T s represents twin TSP, containing n s Cities, T t represents the target TSP, containing n t cities, then the step of learning the mapping matrix of the twin TSP and the target TSP described in S8 includes.
[0288] Calculate T in sequence s City P i With T t City P j The Euclidean distance e ij . Determine T s All cities in T t Middle City P j The minimum Euclidean distance
[0289] The construction dimension is n s ×n t The zero matrix D of .
[0290] Calculate T in sequence s City P i With T t City P j The weight d ij , and stored in matrix D. ij The calculation formula is as follows.
[0291]
[0292] (4) The construction dimension is n s ×n t Each element in M is a random number drawn from a uniform distribution in the interval [0,1).
[0293] (5) Solving optimization problems The minimum value of is obtained to obtain the mapping matrix M.
[0294] ||T S ×MT t || F represents the mapping error, where |||| F represents the Frobenius norm. λ||D⊙M||1 represents T t The city and T s The distance constraint between cities in , where λ = 0.3, ||||1 represents the l1 norm, and ⊙ represents the Hadamard product operator. The specific expression of the learned mapping matrix M is as follows.
[0295]
[0296] Among them, the elements in M represent T s A city in T t The greater the correspondence, the stronger the correspondence between cities. For example, Represents T s City P i With T t City P j The correspondence degree.
[0297] The step of using a mapping matrix to map the solution of the twin TSP to the search space of the target TSP described in S9 includes:
[0298] Get the solution G of the twin TSP from the historical TSP database.
[0299] Use the mapping matrix M and G to calculate the solution G that maps G to the target TSP search space t The calculation formula is as follows.
[0300] G×M=G t
[0301] S9 described using a mapping matrix to map the solution of the twin TSP to the search space of the target TSP should satisfy mapping rule one and mapping rule two.
[0302] Rule 1: If a city P in the target TSP bThere are multiple cities corresponding to the twin TSP. These cities are regarded as a set. The absolute value of the city correspondence in the mapping matrix M multiplied by the proportion is used as the selection probability. A city is randomly selected from the set to replace the city P in G using the roulette wheel selection method. b Assume that the city P of the target TSP i Urban P with twin TSP j , P k and P l Correspondingly, select city P j The probability p(j) is calculated by the following formula.
[0303]
[0304] in, and The cities P of the target TSP are i Urban P with twin TSP j , P k and P l The correspondence degree.
[0305] Rule 2: If multiple cities in the target TSP are related to cities P in the twin TSP a Correspondingly, these cities are regarded as a set to replace the city P in G a location.
[0306] The advantages of the present invention are: first, the feature vectors of the historical TSP and the target TSP are extracted by the autoencoder. The cosine similarity between the feature vector of the historical TSP and the feature vector of the target TSP is calculated and stored in the Milvus vector database. The time cost of the autoencoder for learning and training a large number of historical TSPs is placed before solving the target TSP, which effectively reduces the time cost of solving the target TSP. Second, the feature vectors in the Milvus vector database are clustered into multiple clusters through the k-means clustering algorithm. First, the distance between the target TSP feature vector and the center of each cluster is compared, and then the clusters closest to the target TSP feature vector are selected. Next, all the feature vectors in these corresponding clusters are obtained, and the distance between each feature vector and the target task feature vector is calculated in turn, and the TSP corresponding to the feature vector with the closest distance is used as the twin TSP. This method improves the efficiency of matching the historical TSP with the target TSP. Third, when there is no historical TSP similar to the target TSP in the historical TSP database, a fast resampling method based on a graph filter is used to construct a twin TSP similar to the target TSP. Fourthly, a mapping strategy based on sparse mapping matrix is proposed, which can map the solution of historical TSP to the target TSP, effectively suppressing negative migration. Fifthly, 2-opt and 2-swap local search operators are used as the search strategy of EAs, which effectively improves the local search capability.
Claims
1. A twin optimization method based on similar historical samples for solving the traveling salesman problem, characterized in that: The following steps are involved: 1) Build a historical TSP database, including historical TSP data and solutions; 2) Construct an autoencoder, input all historical TSP data in the historical TSP database into the autoencoder in sequence, obtain the feature vector corresponding to each historical TSP, and store the feature vectors corresponding to all historical TSPs in the Mivlus vector database; 3) Divide the feature vectors of all historical TSPs stored in the Mivlus vector database into several clusters, recorded as historical TSP clusters, and record the feature vector of the cluster center of each historical TSP cluster; 4) Obtain the data of the target TSP, input the data of the target TSP into the autoencoder, and obtain the feature vector of the target TSP; 5) Calculate the cosine distance between the feature vector of the target TSP and the feature vector of the cluster center of each historical TSP cluster, and determine the cluster whose cosine distance is less than the preset value, which is recorded as the coarsely selected twin TSP cluster; 6) Calculate the cosine distance between the feature vectors of all historical TSPs of the roughly selected twin TSP cluster and the feature vector of the target TSP, and determine the minimum cosine distance; 7) Construct the twin TSP of the target TSP based on the minimum cosine distance and determine the data and solution of the twin TSP; 8) Learn the mapping matrix between the twin TSP and the target TSP; 9) Map the solution of the twin TSP to the search space of the target TSP through the mapping matrix to obtain the initial solution G of the evolutionary algorithm EAs t ; 10) Iterate the initial solution of the evolutionary algorithm EAs, and output the solution to the target TSP after reaching the set number of iterations.
2. A twin optimization method based on similar historical samples for solving the traveling salesman problem according to claim 1, characterized in that: The data of the TSP includes city coordinate points.
3. A twin optimization method based on similar historical samples for solving the traveling salesman problem according to claim 1, characterized in that: The autoencoder includes an input layer, a hidden layer and an output layer.
4. A twin optimization method based on similar historical samples for solving the traveling salesman problem according to claim 1, characterized in that: The step of obtaining the TSP feature vector by the autoencoder comprises: 1) Draw the city coordinate points of TSP as pixel points on the image; 2) Extract the binary matrix of the image and input it into the autoencoder; 3) Calculate the eigenvector of the binary matrix as the eigenvector of TSP.
5. The twin optimization method based on similar historical samples for solving the traveling salesman problem according to claim 1 is characterized in that: The method for dividing the feature vectors of all historical TSPs stored in the Mivlus vector database into several clusters includes a k-means clustering algorithm.
6. A twin optimization method based on similar historical samples for solving the traveling salesman problem according to claim 1, characterized in that: The calculation formula of the cosine distance dist(A, B) is as follows: In the formula, A and B represent two different TSPs respectively; h A and h B represent the eigenvectors of A and B respectively, ||h A ||2 represents h A The Euclidean norm of ||h B ||2 represents h B The Euclidean norm of .
7. A twin optimization method based on similar historical samples for solving the traveling salesman problem according to claim 1, characterized in that: The construction of the twin TSP of the target TSP includes the following steps: 1) Determine whether the minimum cosine distance is less than the set value. If the minimum cosine distance is less than the set value, go to step 2); if the minimum cosine distance is greater than or equal to the set value, jump to step 3); 2) The TSP corresponding to the feature vector with the smallest cosine distance to the target TSP is used as the twin TSP of the target TSP, and the data and solution of the twin TSP are obtained from the historical TSP database; 3) Constructing a twin TSP for the target TSP through a fast resampling method based on graph filters, including the following steps: 3.1) Assume that the city coordinate set P of the target TSP is as follows: P={p i (x i ,y i )∣i=1,…N} (2) In the formula, p i is the coordinate point of city i, x i and i Respectively represent the horizontal and vertical coordinates of the coordinate point of city i; N is the total number of cities in the city coordinate set P of the target TSP; 3.2) Normalize the data of the target TSP; 3.3) Use K nearest neighbor algorithm to obtain city p i The neighbor set δ i , the neighbor set δ i As shown below: d i ={δ i,1 ,d i,2 …d i,m } (3) In the formula, δ i,m For the city i The mth neighbor city of 3.4) Calculate the weighted matrix W; for any city P in the target TSP city coordinate set P i and City P j , City P i and City P j The weight W between i,j The calculation formula is as follows: Where σ is a predefined parameter; W i,j represents the weight between city i and city j, W i,i =1, ‖‖2 represents the Euclidean norm; 3.5) Calculate the diagonal matrix D of the density around each city in the city coordinate set P representing the target TSP, and the diagonal elements D i,i The calculation formula is as follows: 3.6) Calculate the transfer matrix A. The calculation formula of the transfer matrix A is as follows: A=D -1 W (6); 3.7) Construct an identity matrix I with the same dimension as the transfer matrix A; 3.8) Construct a first-order filter F, which is as follows: F = IA (7); 3.9) Calculate the characteristic response res of the city coordinate set P of the target TSP, and the characteristic response res is as follows: res=F×P∈R N×2 (8); 3.10) Calculate the resampling probability r of each city i in the city coordinate set P of the target TSP in turn i , the resampling probability r i The calculation formula is as follows: 3.11) Calculate the number of cities s in the twin TSP. The calculation formula for the number of cities s in the twin TSP is as follows: s=α×N (10) Where, parameter α∈[0,1]; 3.12) The resampling probability r of each city i i Sort from high to low, and select the first s cities in the sort to form the twin TSP; 3.13) Use evolutionary algorithms EAs to solve the twin TSP to obtain solutions, and store the data and solutions of the twin TSP in the historical TSP database.
8. A twin optimization method based on similar historical samples for solving the traveling salesman problem according to claim 1, characterized in that: The learning of the mapping matrix between the twin TSP and the target TSP includes the following steps: 1) Set T s represents twin TSP, containing n s Cities, T t represents the target TSP, containing n t cities; 2) Calculate T in sequence s City P i With T t City P j The Euclidean distance e ij , and determine T s All cities in T t Middle City P j The minimum Euclidean distance 3) The construction dimension is n s ×n t The zero matrix D of 4) Calculate T in sequence s City P i With T t City P j The weight d ij , and stored in the matrix D, weight d ij The calculation formula is as follows: 5) The construction dimension is n s ×n t The matrix M is a random number drawn from the interval [0,1). 6) Solve the minimum value f of the optimization problem and obtain the corresponding mapping matrix M; The calculation formula for the minimum value f of the optimization problem is as follows: In the formula, ||T S ×MT t || F represents the mapping error, |||| F represents the Frobenius norm; λ||D⊙M||1 represents T t The city and T s The distance constraint between cities in , where λ = b, || ||1 represents the l1 norm, and ⊙ represents the Hadamard product operator; The corresponding mapping matrix M is expressed as follows: In the formula, the elements in M represent T s A city in T t The weight value corresponding to a city in .
9. A twin optimization method based on similar historical samples for solving the traveling salesman problem according to claim 1, characterized in that: The mapping of the solution of the twin TSP to the search space of the target TSP through the mapping matrix includes the following steps: 1) Obtain the solution G of the twin TSP from the historical TSP database; 2) Use the mapping matrix M and solution G to calculate the solution G that maps solution G to the target TSP search space t , solution G t The calculation formula is as follows: G×M=G t (14)。 10. A twin optimization method based on similar historical samples for solving the traveling salesman problem according to claim 1, characterized in that: The method for iteratively calculating the initial solution of the evolutionary algorithm EAs includes 2-opt and 2-swap local search operators.
Citation Information
Patent Citations
Ant colony algorithm traveling salesman problem solving method based on improved harmony search optimization
CN111832831A
Video text cross-modal retrieval method and device, storage medium and equipment
CN113806482A