A method for solving a capacitated vehicle routing problem based on time series encoding and attention mechanism
By introducing a hierarchical structure embedding module that incorporates temporal coding and attention mechanisms, the problem of unmodeled intra-trip temporal dependencies and inter-trip coupling relationships in existing methods is solved, thereby improving the stability and efficiency of solving the capacity-constrained vehicle routing problem.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- NORTHWEST UNIV
- Filing Date
- 2026-03-02
- Publication Date
- 2026-06-05
AI Technical Summary
Existing perturbation-based improvement methods based on reinforcement learning fail to effectively model intra-trip temporal dependencies and inter-trip coupling relationships in capacity-constrained vehicle routing problems, resulting in unstable operator selection, low search efficiency, and a tendency to get stuck in local stagnation.
A hierarchical solution embedding module based on temporal coding and attention mechanism is adopted. The sequential dependency of nodes within the trip is modeled by a bidirectional temporal coding module, and the interaction between trips is characterized by a multi-layer attention mechanism to generate a global solution embedding vector to guide the selection of local optimization operators.
It improves the effectiveness of path perturbation decision-making and the stability and generalization ability of the overall solution process, reduces search oscillations caused by ineffective adjustments, and enhances the model's adaptability to instances of different sizes.
Smart Images

Figure CN122155053A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of vehicle routing technology, specifically relating to a method for solving capacity-constrained vehicle routing problems based on temporal coding and attention mechanisms. Background Technology
[0002] Combinatorial optimization problems (COPs) are widely found in fields such as logistics, transportation, and bioinformatics. The vehicle routing problem (VRP), a typical example, aims to optimize delivery routes to minimize costs under complex constraints such as capacity and time windows, and has significant application value. However, because VRP is a strongly NP-hard problem, traditional exact algorithms struggle to handle large-scale instances, while classic heuristic methods, although highly efficient, rely on manually designed rules and have limited generalization ability. In recent years, neural combinatorial optimization (NCO) methods have emerged, attempting to combine deep learning with combinatorial optimization. Among them, the perturbative neural combinatorial optimization (PNCO) framework integrates deep reinforcement learning and local search mechanisms. Based on an initial feasible solution, it iteratively improves the solution quality by intelligently selecting local perturbation operators (such as 2-opt, relocate, and swap). A typical approach is the Learn to Improve (L2I) framework, whose core components include an environment state construction module, a run embedding network, a policy network, and an operator selector. The policy network is trained using a policy gradient method to dynamically decide on perturbation operations. In existing PNCO methods, run representation is usually generated by directly summing the feature vectors of each node within the run, or by using a shallow encoder (such as a single-layer fully connected network) to generate run-level feature vectors. Subsequently, all run vectors are aggregated through averaging or concatenation, and then input into the policy network along with the global environment state vector to select the next perturbation operator.
[0003] In solving the Capacitated Vehicle Routing Problem (CVRP), local optimization operators typically improve the current solution through two types of perturbation operations: adjusting the access order of nodes within a single path and performing node migration, swapping, or insertion across paths. The effectiveness of these operations is highly dependent on the temporal structure within the path and the load and service coupling relationships between multiple trips.
[0004] However, existing reinforcement learning-based perturbation-based improvement methods generally employ simplified run-length representations—such as directly summing the feature vectors of each node within the run-length, or using shallow encoders to generate run-length embeddings. These methods suffer from two key drawbacks: (1) Ignoring the sequence directionality and temporal dependency within the process makes it impossible to accurately characterize the impact of node rearrangement on path cost and capacity feasibility. (2) The lack of effective modeling of complex interactions between multiple routes makes it difficult to reflect the global impact of cross-path operations on the overall solution structure.
[0005] Because the travel representation fails to fully capture the aforementioned structural information, the policy network lacks reliable criteria for the consequences of operations when selecting perturbation operators, which can easily lead to infeasible solutions or low-quality candidate solutions being generated by the selected operators. This not only reduces search efficiency but may also cause oscillations in the optimization process, slow convergence, or even prolonged local stagnation, thus limiting the stability and generalization ability of the algorithm in real-world CVRP instances. Summary of the Invention
[0006] The purpose of this invention is to address the problem in the Capacity-Constrained Vehicle Routing Problem (CVRP) where existing reinforcement learning-based perturbation improvement methods are insufficiently aware of intra-trip temporal changes and inter-trip coupling relationships during path node order adjustment and cross-path perturbation, leading to unstable operator selection and low search efficiency. This invention provides a solution method for the CVRP based on temporal encoding and attention mechanisms. This method explicitly models the bidirectional temporal dependencies of node access order within the trip during the solution representation stage and introduces an attention mechanism at the trip level to characterize the interactive effects between different vehicle trips. This effectively enhances the perception of intra-trip node order changes, providing a more discriminative state representation for subsequent local optimization operator selection, improving the effectiveness of path perturbation decisions and the stability and generalization ability of the overall solution process.
[0007] To achieve the above objectives, the present invention provides the following technical solution: A method for solving the capacity-constrained vehicle routing problem based on temporal coding and attention mechanisms includes the following steps: Step 1: Problem Generation and Initial Solution Construction: Based on the preset combinatorial optimization problem type and scale parameters, obtain an instance of the Capacity-Constrained Vehicle Routing Problem (CVRP) to be solved, and construct an initial feasible solution that satisfies all basic constraints. The CVRP includes a distribution center and multiple customer nodes. Each path corresponds to a vehicle's journey from the distribution center, visiting several customer nodes in service order, and returning to the distribution center. The total customer demand covered by this journey does not exceed the vehicle's capacity limit. The CVRP instance includes a set of nodes, attribute data associated with each node, and problem constraints, where each node corresponds to an actual service pair. The image or demand point, the attribute data includes node coordinates and demand quantity; under the above problem setting, the optimization objective is to minimize the total travel cost of all vehicle paths, the total travel cost is calculated by accumulating the distance between adjacent nodes in the path or the predefined travel cost; the initial solution consists of several paths, each path represents the service order of a vehicle, and consists of several nodes arranged in the service order; based on the structure of the initial solution, a hierarchical feature representation is constructed, including a hierarchical feature structure of node-level features, travel-level features and solution-level features, wherein the node-level features include node spatial location, demand quantity, distance between nodes, historical state information and location-related encoding information; Step 2: Based on the hierarchical solution structure embedding module, sequence modeling is performed on the node sequence within each trip to characterize the impact of the node access order on path cost and constraint satisfaction during vehicle service execution, and node-level context features containing node sequence dependencies are extracted; the node-level context features within the same trip are aggregated to obtain the corresponding trip-level feature representation, which is used to characterize the overall state of a single vehicle's service trip; attention modeling is performed on the trip-level feature sets of multiple trips in the current solution to characterize the correlation between different vehicle trips in terms of resource consumption, service distribution, and constraint coupling, and the enhanced trip set features are obtained; the trip set features are aggregated at the solution level to generate a fixed-dimensional solution embedding vector, which is used to characterize the overall structural features of the current vehicle path scheduling scheme; The hierarchical de-embedding module is constructed based on the de-embedding module of the perturbation-type neural optimization framework, including a bidirectional temporal coding module for modeling the node access order within a single vehicle trip, and a multi-layer attention modeling module for modeling the interaction relationship between multiple vehicle trips. Step 3: Construction and splicing of environmental state features Before making a strategy decision, an environmental state feature vector is constructed based on the current optimization process state of the solution. The environmental state feature vector is used to reflect the current search stage, historical improvement trends, and constraint satisfaction. Subsequently, the global solution embedding vector obtained in step 2 is concatenated and fused with the environmental state feature vector to form the joint input feature of the strategy decision network, which is used to guide the selection of subsequent local optimization operators and the solution update process. Step 4: The policy decision module receives the concatenated joint feature vector and trains it using reinforcement learning or supervised learning, outputting the selection result of the local optimization operator. The solution update module perturbs the current solution according to the selected local optimization operator, generates candidate solutions, and evaluates the feasibility and objective function value of the candidate solutions. By evaluating their quality and combining them with the policy gradient method, the reward signal is calculated and used to update the parameters of the policy network and the hierarchical solution structure embedding module. Then, the candidate solution is used as the new current solution, and the process returns to step 2 for the next iteration. When the preset termination condition is met, the iterative optimization process stops, and the optimized path scheduling scheme corresponding to the current problem instance is output.
[0008] Furthermore, step 2 includes the following process: Step 2.1 Input representation: Represent the current solution as a four-dimensional tensor, whose hierarchical structure is represented as: (solution sample dimension, number of paths in the solution dimension, sequence dimension of nodes in a single path dimension, original feature dimension of nodes or paths), wherein the tensor is used to uniformly represent the path scheduling status of multiple vehicles and multiple nodes. Step 2.2, Intra-trip temporal coding: For each trip, the node embedding vector sequence arranged in service order is input into the bidirectional temporal coding module. The forward and backward dependencies between nodes are modeled by forward and backward LSTM respectively to obtain the context-enhanced representation of each node. Node sequence of the journey By performing forward and backward encoding using a bidirectional sequence modeling structure, the context-enhanced representation of a node can be represented as follows: in For the first The embedding vector of each node. and These represent the encoding results of the node in the forward and backward sequences, respectively; Subsequently, the context representations of all nodes within the same trip are aggregated to generate the trip-level feature vector corresponding to that trip; Step 2.3, Inter-trip attention modeling: Combine the trip-level feature vectors of all trips in the solution into a feature representation of the trip set, and input it into a three-layer stacked multi-head attention modeling module. Each layer contains 16 attention heads. The global interaction relationship between adaptive modeling paths is calculated in parallel by multiple heads, and residual connections and layer normalization operations are introduced between layers to stabilize the training process and enhance the model's ability to perceive key trips. The features of the itinerary set are weighted and calculated using an attention mechanism: in, Indicates the first The characteristics of a single trip are represented as follows: These are the corresponding weighting coefficients; Step 2.4: Generate global solution embedding: After completing the attention modeling of the set of runs, the run-level output features are aggregated at the solution level to obtain the solution embedding vector used to represent the overall structure of the current solution. Through a projection network consisting of multiple fully connected layers, where each layer contains activation functions and random deactivation mechanisms, the solution embedding vector is mapped to a feature space that matches the input dimension of the policy decision network, generating a fixed-dimensional global solution embedding vector.
[0009] Furthermore, the aggregation method described in step 2.2 adopts average aggregation, maximum aggregation, or weighted aggregation based on attention weight allocation.
[0010] Furthermore, the solution-level aggregation method described in step 2.4 is global pooling, introducing a global identifier vector, or a weighted aggregation method based on run weights.
[0011] Furthermore, the optimization results described in step 4 include: (1) The final feasible solution corresponding to the current problem instance, wherein the final feasible solution consists of multiple processes, and each process consists of several nodes arranged in service order; (2) The objective function value corresponding to the final feasible solution is used to quantitatively characterize the overall optimization quality of the solution.
[0012] Compared with the prior art, the present invention has the following beneficial effects: This invention explicitly models the sequence dependencies of nodes within a path during the destructuring embedding process, enabling the path representation to sensitively reflect changes in node order. This allows for early assessment of cost fluctuation risks caused by local perturbation operations such as node rearrangement, insertion, or swapping within the path, reducing search oscillations and iterative degradation caused by ineffective node adjustments, and improving the policy network's ability to discriminate and respond to local structural adjustments. Simultaneously, an attention mechanism is introduced to perform global correlation modeling on multi-path sets, allowing the model to comprehensively evaluate the load distribution and structural coupling relationships of each path before operations such as cross-path node swapping or path merging, adaptively capturing non-linear relationships. The interaction between the same path reduces the probability of capacity constraint violation or abnormal cost increase caused by cross-path disturbances, effectively avoids the problem of low-quality candidate solution generation caused by relying solely on local path information, and improves the stability and convergence efficiency of the overall search process. In addition, a hierarchical feature representation architecture combining node level, path level and solution level is adopted, which enables the solution representation to simultaneously characterize the internal structural changes of a single path and the overall distribution characteristics between multiple paths, thereby enhancing the model's adaptability to scenarios such as changes in the number of vehicles, expansion of node scale and fluctuations in demand distribution. It can maintain relatively stable operator selection effect and optimization performance on CVRP instances of different sizes.
[0013] The hierarchical solution structure embedding module proposed in this invention maintains compatibility with existing policy decision-making processes in its interface design, allowing for seamless integration without modifying the original policy network structure. This avoids large-scale reconstruction of existing reinforcement learning frameworks, reducing system transformation complexity and engineering implementation costs. Furthermore, the embedding network supports flexible configuration in terms of layer number, feature dimensions, and regularization methods, effectively balancing efficiency and performance based on actual computing resource conditions. It is suitable for vehicle route scheduling system deployment scenarios under different computing power conditions. In addition, thanks to the feature modeling mechanism based on weight allocation introduced during the embedding process, the model can reflect the structural importance of each journey in the current solution and its relative impact on the overall cost. This provides quantifiable auxiliary information for analyzing the effect of path structure adjustment, tracing the basis for operator selection, and locating performance bottlenecks, improving the interpretability and analyzability of the optimization process. Attached Figure Description
[0014] Figure 1 This is a schematic diagram of the overall process of the combined optimization method based on temporal coding and attention mechanism of the present invention; Figure 2 A schematic diagram of the hierarchical structure and abstract relationships of the solution; Figure 3 This diagram illustrates the relationship between the embedded vector, the policy decision network, and the solution update. Detailed Implementation
[0015] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the present invention will be described in detail below with reference to the accompanying drawings and specific embodiments.
[0016] like Figure 1 As shown in the figure, the capacity-constrained vehicle routing problem solution based on temporal coding and attention mechanism described in this embodiment includes the following steps: Step 1, Problem Generation and Initial Solution Construction: Based on the preset combinatorial optimization problem type and scale parameters, obtain the instance of the capacity-constrained vehicle routing problem (CVRP) to be solved, and construct an initial feasible solution that satisfies all basic constraints; The CVRP includes a distribution center and multiple customer nodes. Each path corresponds to a journey where a vehicle departs from the distribution center, visits several customer nodes in service order, and returns to the distribution center. The total demand of customers covered by this journey does not exceed the vehicle's capacity limit. Under the above problem setting, the optimization objective is to minimize the total journey cost of all vehicle paths. The total journey cost is calculated by accumulating the distance between adjacent nodes in the path or the predefined travel cost. This problem instance includes a set of nodes, node attributes (such as coordinates and requirements), and problem constraints. Subsequently, an initial feasible solution satisfying all basic constraints is constructed. This initial solution consists of several paths (trips), each path representing the service sequence of a vehicle, composed of several nodes arranged in the service sequence. Based on the structure of the initial solution, a hierarchical feature representation is constructed, which includes at least node-level features, trip-level features, and solution-level features. Figure 2 As shown, node-level features describe the attribute information of a single node. These features may include, but are not limited to, node spatial location, demand, distance between nodes, and historical state information. Furthermore, location-related encoding information can be introduced to characterize the relative order of nodes in the journey, thereby enhancing the model's ability to perceive the journey structure. For scalar or low-dimensional node features, a linear mapping method is preferably used to map them to a unified feature space dimension to form node-level embedding vectors. Journey-level features describe the overall characteristics of a single journey, while solution-level features describe the global state of the current solution.
[0017] Taking CVRP20 as an example, the problem instance includes one distribution center node and 20 customer nodes. Each customer node has corresponding spatial coordinates and demand information, and the vehicle capacity is a preset constant. Before starting the solution, an initial feasible solution can be constructed based on the problem instance. This initial solution can be generated through conventional path construction strategies, such as inserting customers sequentially according to their numbers and dividing them into multiple delivery routes while satisfying vehicle capacity constraints, or using existing construction methods such as the nearest neighbor heuristic.
[0018] In this embodiment, an exemplary initial solution is represented as: Itinerary 1: [0 → 3 → 7 → 12 → 5 → 0] Itinerary 2: [0 → 1 → 9 → 14 → 6 → 0] Itinerary 3: [0 → 2 → 4 → 10 → 16 → 8 → 0] Itinerary 4: [0 → 11 → 13 → 15 → 18 → 17 → 19 → 20 → 0] Where 0 represents the distribution center node, and the remaining numbers represent the customer node number.
[0019] Step 2: Based on the hierarchical solution structure embedding module, sequence modeling is performed on the node sequence within each trip to characterize the impact of the node access order on path cost and constraint satisfaction during vehicle service execution, extracting node-level context features containing node order dependencies; the node-level context features within the same trip are aggregated to obtain the corresponding trip-level feature representation, used to characterize the overall state of a single vehicle's service trip; attention modeling is performed on the trip-level feature sets of multiple trips in the current solution to characterize the correlation between different vehicle trips in terms of resource consumption, service distribution, and constraint coupling, obtaining enhanced trip set features; the trip set features are then aggregated at the solution level to generate a fixed-dimensional solution embedding vector, used to characterize the overall structural features of the current vehicle path scheduling scheme. This invention is based on a perturbation-based neural optimization framework, which mainly includes the following functional modules: a problem instance and current solution state representation module, a solution embedding module, a policy decision network, and a local operator execution and environment feedback module. Among these, the solution embedding module and the policy decision network together constitute the core neural network component for intelligent selection of local optimization operators.
[0020] In traditional implementations, the solution embedding module typically uses simple aggregation (e.g., direct summation) or shallow encoding of node features within a run (i.e., path) to generate run-level or solution-level vector representations. While such methods can reflect the global state of the solution to some extent, they lack the ability to explicitly model the node access order within the path, and the structural coupling relationships between different paths are expressed only through simple superposition, resulting in low sensitivity of the embedding results to changes in node order and load interactions between paths.
[0021] In the practical solution of the Capacity-Constrained Vehicle Routing Problem (CVRP), local optimization operators typically include operations such as intra-path node rearrangement (e.g., two-opt), cross-path node exchange (e.g., exchange), and node insertion. These operations alter the service order of nodes within the path and their cross-path distribution structure, directly impacting the cumulative load and trip cost. If the solution representation fails to explicitly model node order dependencies and load distribution across different paths, the policy network struggles to distinguish between high-risk perturbations and potentially effective perturbations during operator selection, easily generating candidate solutions that violate capacity constraints or degrade costs, leading to a decrease in the number of effective improvements and reduced search efficiency.
[0022] To address the aforementioned issues, this invention makes key improvements to the de-embedding module, proposing a hierarchical de-embedding structure module. This hierarchical de-embedding structure network module is constructed based on the de-embedding module of a perturbation-based neural optimization framework, and includes a bidirectional temporal coding module and a multi-layer attention modeling module, used to model the sequence dependencies of nodes within a process and the global interaction relationships between processes, respectively.
[0023] The attention modeling module for the set of trips can be implemented by stacking attention sub-layers of different numbers to accommodate problem instances of varying scales and complexities. The number of parallel substructures and feature dimensions in the attention mechanism can also be adjusted according to actual needs.
[0024] like Figure 3 The diagram illustrates the core functional modules of this invention and their interrelationships, specifically including the information interaction and collaboration process between the attention-based solution structure embedding module, the policy decision module, and the solution update module. First, a bidirectional temporal encoder is used to model the sequential dependencies of nodes within each run to generate a run-level representation. Then, an attention mechanism is used to aggregate all run-level representations and fuse global context information, ultimately outputting a unified-dimensional solution embedding vector. The specific processing is as follows: (2.1) Input representation: The current solution is represented as a four-dimensional tensor, whose hierarchical structure is represented as: (solution sample dimension, number of paths in the solution dimension, sequence dimension of nodes in a single path dimension, original feature dimension of nodes or paths). This representation can completely preserve the structural information of the solution at the "path-node" level.
[0025] (2.2) Intra-trip temporal coding: For each trip, the node embedding vector sequence arranged in service order is input into the bidirectional temporal coding module. The forward and backward dependencies between nodes are modeled by forward and backward LSTM respectively to obtain the context-enhanced representation of each node. Node sequence By performing forward and backward encoding on a bidirectional sequence modeling structure, its node-level context representation can be expressed as: in, and These represent the encoding results of the node in the forward and backward sequences, respectively.
[0026] In this way, node features, while maintaining their original attribute information, are given the ability to perceive changes in the order of nodes within the journey.
[0027] Subsequently, the context representations of all nodes within the same trip are aggregated to generate the trip-level feature vector corresponding to that trip. The aggregation method can be any of the following: average aggregation, maximum aggregation, or weighted aggregation based on attention weight allocation.
[0028] By using run-level aggregation, variable-length node sequences are compressed into fixed-dimensional run representations, thereby achieving feature abstraction from the node level to the run level.
[0029] Taking trip 1 as an example, its node feature sequence [0, 3, 7, 12, 5, 0] is input sequentially into a bidirectional sequence modeling network to model the forward and backward dependencies between nodes, obtaining a context-enhanced feature representation for each node. This processing enables the model to perceive, for example, the impact of changes in the order between nodes 7 and 12 on the trip cost. The context features of each node in trip 1 are then aggregated to obtain the corresponding trip-level feature vectors; the remaining trips are processed in the same way to obtain their corresponding trip-level feature vectors, thus forming a trip set representation containing four trip-level feature vectors.
[0030] (2.3) Inter-trip attention modeling: The trip-level feature vectors of all trips in the solution are combined into a feature representation of the trip set, and then input into a three-layer stacked multi-head attention modeling module. Each layer contains 16 attention heads. The global interaction relationship between adaptive modeling paths is calculated in parallel by multiple heads. Residual connections and layer normalization operations are introduced between layers to stabilize the training process and enhance the model's ability to perceive key trips. The features of the trip set are weighted using an attention mechanism. The attention weights reflect the relative importance of each trip in the current solution. The calculation process can be illustrated as follows: in, Indicates the first The characteristics of a single trip are represented as follows: These are the corresponding weighting coefficients.
[0031] This attention modeling process can highlight critical steps that have a significant impact on the overall solution quality.
[0032] For example, by using the four run-level feature vectors mentioned above as input, a multi-head attention modeling structure with multiple layers stacked can be introduced to model the relationships between different runs. The attention mechanism can adaptively adjust the weights of each run based on its impact on the overall solution quality, thereby highlighting the runs that are more critical to optimizing the overall solution.
[0033] (2.4) Generating Global Solution Embeddings: After completing the attention modeling of the run set, the run-level output features are aggregated at the solution level to obtain a solution embedding vector that represents the overall structure of the current solution. Through a projection network consisting of multiple fully connected layers, where each layer contains activation functions and random deactivation mechanisms, the solution embedding vector is mapped to a feature space that matches the input dimension of the policy decision network, generating a fixed-dimensional global solution embedding vector. This vector comprehensively characterizes the overall structural features of the current solution.
[0034] The aggregation method can be global pooling, introducing a global identifier vector, or weighted aggregation based on run weights.
[0035] Step 3: Construction and splicing of environmental state features Before policy decision-making, an environmental state feature vector is constructed based on the current solution's optimization process state. This vector describes information such as historical improvements during the search process, the current solution's quality change trend, and the search stage. Subsequently, the global solution embedding vector obtained in step 2 is concatenated and fused with the environmental state feature vector to form the joint input features of the policy decision-making network. This joint input feature guides the selection of subsequent local optimization operators and the solution update process.
[0036] Step 4: The policy decision module receives the concatenated joint feature vector and trains it using reinforcement learning or supervised learning, outputting the selection result of the local optimization operator. The solution update module perturbs the current solution according to the selected local optimization operator, generates candidate solutions, and evaluates the feasibility and objective function value of the candidate solutions. The module calculates a reward signal by evaluating the quality of the candidate solutions and combining it with the policy gradient method, which is used to update the parameters of the policy network and the hierarchical solution structure embedding module. When evaluating the quality of candidate solutions, if the candidate solution violates the capacity constraint, a negative reward value is given; if the candidate solution satisfies the constraint and the objective function value decreases, a positive reward value is given according to the magnitude of the decrease; if the objective function does not improve, a zero reward or penalty value is given. This reward mechanism guides the policy network to gradually learn the preferred perturbation direction. Then, the candidate solution is used as the new current solution, and the process returns to step 2 for the next iteration. When the preset termination condition is met, the iterative optimization process stops, and the current optimization result is output.
[0037] The optimization results include: (1) The final feasible solution corresponding to the current problem instance, which consists of multiple routes, each of which consists of several nodes arranged in service order; (2) The objective function value corresponding to the final feasible solution is used to quantitatively characterize the overall optimization quality of the solution.
[0038] The final output is the optimal or near-optimal delivery route for a given instance of a capacity-constrained vehicle routing problem, along with its corresponding total travel cost.
[0039] Compared with existing perturbation-based optimization methods based on simple aggregation embedding, this invention achieves the following technical effects at the model mechanism level by constructing a hierarchical destructive embedding architecture: First, a bidirectional temporal coding module models the forward and backward dependencies of the node sequence within the path, ensuring that the node embedding vector simultaneously contains contextual information about its predecessor and successor nodes in the path. This mechanism allows the impact of node rearrangement operations (such as two-opt and insert) on the cumulative travel cost and load distribution to be reflected in the changes in embedding features in advance. Since the input vector of the policy network is more sensitive to changes in node order, the operator selection probability distribution shifts with the potential cost change trend, thereby reducing the selection probability of high-risk insertion positions or high-cost rearrangement operations.
[0040] Secondly, a multi-layered multi-head attention mechanism is used to interactively model the set of paths, allowing the representation of each path to incorporate the load and cost context information of other paths during computation. This mechanism can explicitly reflect the differences in capacity margin between paths and the risk of capacity conflicts that may arise from cross-path node migration. Before performing cross-path swapping or migration operations, the embedding vector already contains cross-path load balancing information, thus enabling the policy network to favor operations with higher capacity feasibility and a more significant overall cost reduction trend during the decision-making stage.
[0041] Therefore, the hierarchical resolution structure embedding architecture designed in this invention improves the risk perception capability of strategy decision-making through an explicit structure modeling mechanism, optimizes the search trajectory structure from the decision distribution level, and thus improves the stability and efficiency of the solution process for capacity-constrained vehicle routing problems at the engineering implementation level.
[0042] Analysis of Experimental Results and Explanation of Method Validity To verify the effectiveness of the proposed solution to the capacity-constrained vehicle routing problem based on temporal coding and attention mechanism, the capacity-constrained vehicle routing problem (CVRP) was selected as the test object. Comparative experiments were conducted between the proposed method and several existing representative methods at different problem scales. Table 1 shows the average path cost results of the solutions obtained by each method at three scales: CVRP20, CVRP50, and CVRP100. The result of the proposed method is the average value after running it 10 times under the same experimental settings.
[0043] Table 1. Comparison of average path costs for different methods on the CVRP20, CVRP50, and CVRP100 test sets. As can be seen from Table 1: 1) Performance under small-scale problems (CVRP20) On the CVRP20 problem, the method of this invention achieves an average path cost of 5.84, which is significantly better than various constructive methods such as Google OR-Tools, AM greedy, AM sampling, and POMO, and also better than existing L2I methods (average path cost 6.12). These results demonstrate that the hierarchical solution structure embedding method adopted in this invention can more effectively characterize the temporal dependencies and global associations between nodes and routes in the solution, thereby providing a more discriminative state representation for the selection of local optimization operators and improving overall optimization performance.
[0044] 2) Performance under medium-sized problems (CVRP50) On the CVRP50 problem, the method of this invention achieves an average path cost of 9.76, which is superior to the existing L2I method (10.35) and other comparative methods. This result demonstrates that even with increased problem size and a significant increase in the number of nodes and trips, the solution structure embedding network proposed in this invention can still effectively model the hierarchical structure of the solution and maintain good optimization performance, exhibiting its robustness and stability in medium-sized combinatorial optimization problems. 3) Performance under larger-scale problems (CVRP100) On the CVRP100 problem, the average path cost of the method in this invention is 15.54, which is close to the result of the existing L2I method (15.57) and shows a slight improvement. This result indicates that in larger-scale problems, the method in this invention can achieve optimization results that are no worse than existing methods by maintaining the scalability of the original L2I framework and through more refined solution structure modeling.
[0045] On the CVRP100 problem instance, the average path cost of the method in this invention is 15.54, slightly better than the existing L2I method (15.57), with essentially equivalent results and a slight improvement. This result demonstrates that in large-scale problem scenarios, the method in this invention, while maintaining the good scalability of the L2I framework, can effectively maintain or even slightly improve optimization performance by introducing a more refined hierarchical resolution structure modeling mechanism. This verifies the applicability and effectiveness of the proposed hierarchical resolution structure embedding module in large-scale instances.
[0046] Experimental results from problems of varying sizes demonstrate that the method of this invention exhibits significant advantages in small- and medium-sized problems, while maintaining performance levels comparable to existing learning improvement methods in larger-scale problems. These results validate that by introducing a hierarchical resolution structure embedding mechanism to jointly model the intra-trip node sequence relationships and inter-trip correlations, this invention effectively enhances the selection ability of local optimization operators during the policy decision-making stage, thereby improving the overall solution quality.
Claims
1. A method for solving the capacity-constrained vehicle routing problem based on temporal coding and attention mechanisms, characterized in that, Includes the following steps: Step 1, Problem Generation and Initial Solution Construction: Based on the preset combinatorial optimization problem type and scale parameters, obtain the instance of the capacity-constrained vehicle routing problem (CVRP) to be solved, and construct an initial feasible solution that satisfies all basic constraints; The CVRP includes a distribution center and multiple customer nodes. Each path corresponds to a journey in which a vehicle departs from the distribution center, visits several customer nodes in service order, and returns to the distribution center. The total demand of customers covered by this journey does not exceed the vehicle's capacity limit. The capacity-constrained vehicle routing problem (CVRP) instance includes a set of nodes, attribute data associated with each node, and problem constraints, wherein the nodes correspond to actual service objects or demand points, and the attribute data includes node coordinates and demand quantity. Under the above problem setting, the optimization objective is to minimize the total travel cost of all vehicle paths, which is calculated by summing the distances between adjacent nodes in the path or the predefined travel costs. The initial solution consists of several paths, each path representing the service sequence of a vehicle, and is composed of several nodes arranged in the service sequence. Based on the structure of the initial solution, a hierarchical feature representation is constructed, including a hierarchical feature structure of node-level features, trip-level features, and solution-level features. The node-level features include node spatial location, demand, distance between nodes, historical state information, and location-related encoding information. Step 2: Based on the hierarchical solution structure embedding module, sequence modeling is performed on the node sequence within each trip to characterize the impact of the node access order on path cost and constraint satisfaction during vehicle service execution, and node-level context features containing node sequence dependencies are extracted; the node-level context features within the same trip are aggregated to obtain the corresponding trip-level feature representation, which is used to characterize the overall state of a single vehicle's service trip; attention modeling is performed on the trip-level feature sets of multiple trips in the current solution to characterize the correlation between different vehicle trips in terms of resource consumption, service distribution, and constraint coupling, and the enhanced trip set features are obtained; the trip set features are aggregated at the solution level to generate a fixed-dimensional solution embedding vector, which is used to characterize the overall structural features of the current vehicle path scheduling scheme; The hierarchical de-embedding module is constructed based on the de-embedding module of the perturbation-type neural optimization framework, including a bidirectional temporal coding module for modeling the node access order within a single vehicle trip, and a multi-layer attention modeling module for modeling the interaction relationship between multiple vehicle trips. Step 3: Construction and splicing of environmental state features Before making a strategy decision, an environmental state feature vector is constructed based on the current optimization process state of the solution. The environmental state feature vector is used to reflect the current search stage, historical improvement trends, and constraint satisfaction. Subsequently, the global solution embedding vector obtained in step 2 is concatenated and fused with the environmental state feature vector to form the joint input feature of the strategy decision network, which is used to guide the selection of subsequent local optimization operators and the solution update process. Step 4: The policy decision module receives the concatenated joint feature vector and trains it using reinforcement learning or supervised learning, outputting the selection result of the local optimization operator. The solution update module perturbs the current solution according to the selected local optimization operator, generates candidate solutions, and evaluates the feasibility and objective function value of the candidate solutions. By evaluating their quality and combining them with the policy gradient method, the reward signal is calculated and used to update the parameters of the policy network and the hierarchical solution structure embedding module. Then, the candidate solution is used as the new current solution, and the process returns to step 2 for the next iteration. When the preset termination condition is met, the iterative optimization process stops, and the optimized path scheduling scheme corresponding to the current problem instance is output.
2. The method for solving the capacity-constrained vehicle routing problem based on temporal coding and attention mechanisms according to claim 1, characterized in that, Step 2 includes the following process: Step 2.1 Input representation: Represent the current solution as a four-dimensional tensor, whose hierarchical structure is represented as: (solution sample dimension, number of paths in the solution dimension, sequence dimension of nodes in a single path dimension, original feature dimension of nodes or paths), wherein the tensor is used to uniformly represent the path scheduling status of multiple vehicles and multiple nodes. Step 2.2, Intra-trip temporal coding: For each trip, the node embedding vector sequence arranged in service order is input into the bidirectional temporal coding module. The forward and backward dependencies between nodes are modeled by forward and backward LSTM respectively to obtain the context-enhanced representation of each node. Node sequence of the journey By performing forward and backward encoding using a bidirectional sequence modeling structure, the context-enhanced representation of a node can be represented as follows: in For the first The embedding vector of each node. and These represent the encoding results of the node in the forward and backward sequences, respectively; Subsequently, the context representations of all nodes within the same trip are aggregated to generate the trip-level feature vector corresponding to that trip; Step 2.3, Inter-trip attention modeling: Combine the trip-level feature vectors of all trips in the solution into a feature representation of the trip set, and input it into a three-layer stacked multi-head attention modeling module. Each layer contains 16 attention heads. The global interaction relationship between adaptive modeling paths is calculated in parallel by multiple heads, and residual connections and layer normalization operations are introduced between layers to stabilize the training process and enhance the model's ability to perceive key trips. The features of the itinerary set are weighted and calculated using an attention mechanism: in, Indicates the first The characteristics of a single trip are represented as follows: These are the corresponding weighting coefficients; Step 2.4: Generate global solution embedding: After completing the attention modeling of the set of runs, the run-level output features are aggregated at the solution level to obtain the solution embedding vector used to represent the overall structure of the current solution. Through a projection network consisting of multiple fully connected layers, where each layer contains activation functions and random deactivation mechanisms, the solution embedding vector is mapped to a feature space that matches the input dimension of the policy decision network, generating a fixed-dimensional global solution embedding vector.
3. The method for solving the capacity-constrained vehicle routing problem based on temporal coding and attention mechanisms according to claim 2, characterized in that, The aggregation method described in step 2.2 is average aggregation, maximum aggregation, or weighted aggregation based on attention weight allocation.
4. The method for solving the capacity-constrained vehicle routing problem based on temporal coding and attention mechanisms according to claim 2, characterized in that, The solution-level aggregation method described in step 2.4 is global pooling, introducing a global identifier vector, or a weighted aggregation method based on run weights.
5. The method for solving the capacity-constrained vehicle routing problem based on temporal coding and attention mechanisms according to claim 1, characterized in that, The optimization results described in step 4 include: (1) The final feasible solution corresponding to the current problem instance, wherein the final feasible solution consists of multiple processes, and each process consists of several nodes arranged in service order; (2) The objective function value corresponding to the final feasible solution is used to quantitatively characterize the overall optimization quality of the solution.