Disclosure of Invention
The invention aims to provide a rapid and convenient VRP combination optimization scheme.
The technical scheme adopted by the invention is as follows:
the invention provides a method based on an improved A*The logistic distribution vehicle dispatching method of the algorithm comprises an improved type A*Algorithm and logistics distribution algorithm.
The terms used in the present invention are explained as follows:
(1) path: a sequence of consecutive numbers called nodes from start to end;
(2) path weight: path length from one node to another;
(3) the following drawings: is a set of nodes and edges, usually denoted by G ═ V, E, where V is the set of all nodes and E is the set of all edges;
(4) undirected graph: is a graph with no direction of edges, and no order relationship between two vertexes, and the examples (V1, V2) and (V2, V1) represent the same edges;
(5) adjacency matrix: for an undirected graph, the adjacency matrix must be symmetrical, the diagonal of the adjacency matrix is 0, and the matrix represents the adjacent relation between each node in the graph;
(6) shortest path: there are multiple paths from the initial vertex to the end vertex in the undirected graph, and the shortest path is taken as the shortest path.
Improved A of the invention*The algorithm is used for rapidly searching the optimal path between two points and comprises the following steps: gridding the delivery area, preferably evaluating the distance appropriately, and searching for the shortest distance three parts in a recursive method.
The logistics distribution algorithm is used for generating vehicle information sent from a distribution center to each customer node, wherein the vehicle information comprises a vehicle number, passing customer nodes, a vehicle route, a load capacity and a total route distance, and the logistics distribution algorithm comprises the following steps: calculating the distance and the route from each client node to the logistics center, and generating a distribution scheme by using an improved weighted graph algorithm.
In the present invention, the positions of the logistics center and the customer sites are known, and the maximum cargo capacity of the cargo truck is Q, and the cargo truck uses at most m cargo trucks from the logistics center to distribute the cargo to n customersmaxMaximum distance of travel LmaxThe trucks start from the logistics distribution center, return to the logistics center after completing the transportation task, and have the following constraint conditions:
(1) the using time of truck transportation is minimum;
(2) the shortest transportation distance;
(3) completing the delivery using a minimum of vehicles;
(4) the total amount of the customer goods in each distribution line is less than or equal to the maximum loading capacity of the truck;
(5) each customer site is completed by one delivery of one truck and cannot be repeated.
Improved A of the invention*The algorithm is realized by the following steps:
(1) gridding a distribution area: on the premise of knowing the accurate geographic position of a client node, dividing a map into square grids (Grid) according to a certain proportion, and describing the Grid state by a two-dimensional array; the trellis pass-then trellis state is labeled □, represented as 0 in the array; if the grid is not passed then the grid status flag is
1 in the array; the path is a set of grids passing from a starting grid S to an end grid E, wherein the passing grids are called nodes, the nodes have a passable state and a non-passable state, and the passable state has two modes of moving along the XY axis direction of the grids and moving along the diagonal direction of the grids;
(2) preferably, the appropriate evaluation distance: node n (x)
n,y
n) Is from a starting point S (x)
S,y
S) And end point E (x)
E,y
E) The node reached after n steps evaluates the distance f (n) g (n) h (n), where g (n) is the distance from the starting point S to the path passed by the node n, the grid side length is d, i is a certain grid passed by the starting point a to the node nIf the grid is moved in the XY-axis direction of the grid, the distance d (i) ═ d passed by the grid, and if the grid is moved in the diagonal direction of the grid, the distance passed by the grid
h (n) is a heuristic function from the node n to the end point E, the value of which is the minimum value of the Manhattan distance and the Euclidean distance between two points, and Min () represents a function for returning the minimum value, then
If the terrain is known, and for the convenience of calculation, the manhattan distance can be directly selected, namely h (n) ═ x
n-x
E|+|y
n-y
EL, |; comparing the Euclidean distances when the Manhattan distances are the same;
(3) the shortest distance is searched for by a recursive method: with A*(S, E) describing a better path from the starting point S to the end point E and returning a weight of the path, wherein the weight of the path is represented by L1, an open set stores all grids which are considered to find the shortest path, a closed set stores grids which are not considered any more, and a set PminStoring the grids with the minimum f (n) values in the open sets, storing all the sets in a stack form, and constructing a linked list K, A according to a last-in first-out principle*The algorithm of (S, E) is described as follows:
STEP 1: emptying an open set and a closed set, and putting S into the open set;
STEP 2: continuing when the open is not empty, otherwise returning to the error and exiting;
STEP 3: finding out the node n with the minimum evaluation distance in open, and putting n into PminPerforming the following steps;
STEP 4: if n is equal to E, the end point is found, the step9 is switched to, otherwise, the operation is continued;
STEP5: removing n from the open set and adding the n into the closed set;
STEP 6: checking all grids G which can be passed around n, and skipping grids which cannot be passed;
STEP 7: adding all G not in the open set into the open set;
STEP 8: returning to STEP 2;
STEP 9: from E, pop P out in sequenceminAnd adding the linked list K into the nodes in the set until the starting point S is returned, reversely placing the linked list K to obtain a path from the starting point S to the end point E, and obtaining the weight L1 f (E) of the path.
The logistics distribution algorithm of the invention comprises the following steps:
(1) calculating the distance and route from each client node to the logistics center, wherein the address of the distribution center A is (x)A,yA) Address (x) of client node ViVi,yVi) (i ═ 1,2, …, n) by modification a*The algorithm calculates the path weight from the distribution center to each node Vi and puts the path weight into a one-dimensional array Lse Vi]=A*(a, Vi) (i ═ 1, …, n), and saves its path;
(2) generation of delivery plans by means of a modified weighted graph algorithm, known as delivery center A (x)A,yA) The client nodes and paths are described by a weighted undirected graph, G ═ V, E ═ V1, …, Vn }, E { (Vi, Vj) } (Vi ∈ V, Vj ∈ V), using a two-dimensional array L [ Vi ∈ V }][Vj]Storing the weight values between vertexes Vi to Vj, L [ Vi][Vj]=A*(Vi,Vj);D[k]The travel distance to store each vehicle includes the distance to return to the distribution center, where (k ═ 1,2, …, M), M is the vehicle maximum; q [ k ]]Storing the load weight of each vehicle in driving, wherein (k is 1,2, …, M); the maximum travel distance of each vehicle is Lmax(ii) a The maximum load of each vehicle is Qmax(ii) a Set VTIs a set of unassigned vertices; set S [ k ]]Is a set of vertices assigned to the kth vehicle; a is a process variable and represents the current starting point to search the vertex of the next jump; the algorithm is described as follows:
STEP 1: initialization variable k is 1, VT=V;
STEP 2: initializing S [ k ] ═ phi, Q [ k ] ═ 0, D [ k ] ═ 0, and a ═ A;
STEP3:VTturning to STEP10 when empty, otherwise, continuing;
STEP 4: from the set VTMiddle through modified type A*The algorithm finds the vertex V [ i ] with the minimum distance from a];
STEP5: judgment (Q [ k ]]+Q[V[i]]<=Qmax)AND(D[k]+L[a][V[i]]+Lse(V[i])<=Lmax) If true, go to STEP6, otherwise go to STEP 9;
STEP6:D[k]=D[k]+L[a,V[i]],Q[k]=Q[k]+Q[V[i]],a=V[i];
STEP 7: let the vertex V [ i ]]Put into the set S [ k ]]In (3), delete the set VTV [ i ] of (1)];
STEP 8: returning to STEP 3;
STEP 9: d [ k ] + ls [ a ], k ═ k +1, return to STEP 2;
STEP 10: d [ k ] + ls [ a ], and ends.
The returned client nodes which are stored in the set S [ k ] and need to be visited by the vehicle k are the client nodes, the visiting sequence is the sequence of the elements in the set S [ k ], and all the logistics distribution vehicles only need to visit the client nodes in the set according to the corresponding vehicle.
Compared with the prior art, the invention has the following advantages:
improved A of the invention*The algorithm combines the advantages of a conventional algorithm Dijsktra and a heuristic algorithm, different heuristic functions are used for adapting to different terrains for solving the shortest path, a weighted graph is designed in the logistics distribution algorithm for describing the road path condition, and the distribution scheme is planned by an improved recursive weighted graph search algorithm to obtain the optimal solution of the VRP.
Detailed Description
Gridding a distribution area:
as shown in fig. 1, on the premise that the precise geographic location of a client is known, a map is divided into square grids (Grid) according to a certain proportion and simplified into a two-dimensional array, each Grid is an element of the array, and the Grid mark □ represents a passable path and is marked as □
Indicating an impassable path (e.g., wall, gutter, etc.). A path is referred to as a set of points that pass through the grid from a starting point a to an end point B, where the points that pass through are referred to as "nodes," which may be any location of any shape.
Preferably, the appropriate evaluation distance:
as shown in fig. 2, a is a starting point, B is an end point, the edges of the grid are 10, g (n) is added to 10 when moving along the XY axis of the grid, g (n) is added to 14 when moving along the diagonal of the grid (where integers are taken for convenience of calculation), and the value of h (n) is the minimum value of the manhattan distance from the node to the point B and the euclidean distance, or one of them, where the manhattan distance h ═ x is selected for convenience of calculation1-x2|+|y1-y2|, LABThe final path weight from A to B is stored in the buffer.
The shortest distance is searched for by a recursive method:
as shown in fig. 2, the following steps describe the process of searching for a path:
step 1: emptying open and closed sets;
step 2: putting A into an open set, finding a square which can pass around A, calculating the value of F-G + H, finding the square which is 54 marked with 1, and adding A into a closed set;
step 3: putting 1 into an open set, finding a square grid which can pass around the 1, calculating the value of F-G + H, finding the square grid which is 74 and marked by 2, and adding 1 into a closed set;
step 4: putting 2 into an open set, finding a square grid which can pass around 2, calculating the value of F-G + H, finding the square grid which is 74 and marked by 3, and adding 2 into a closed set;
step5, putting 3 into the open set, finding the square grids which can pass around the 3, calculating the value of F & ltG + H & gt, finding the square grid which is F & lt74 & gt and marked by 4, and adding 3 into the closed set;
step 6: putting 4 into an open set, finding a square which can pass around 4, calculating the value of F-G + H, finding the square which can pass around F-68 and marking the square with 5, and adding 4 into a closed set;
step 7: putting 5 into an open set, finding a square which can pass around the 5, calculating the value of F-G + H, finding the square B of F-68, and adding the 5 into a closed set;
step 8: putting B into an open set, calculating the value of F ═ G + H, F ═ 68, and adding B into a closed set;
step 9: ending circulation, returning path to A, and sequentially B-fifth-fourth-third-fifth-A, so that the shortest path from A to B is LAB=68。
The logistics distribution algorithm is realized as follows:
as shown in fig. 3, the vertex a is the logistics center, the vertices V1 to V6 are the customer nodes, and the logistics distribution needs to traverse all the vertices in the graph from the vertex a, satisfy the logistics distribution constraint, and obtain the optimal path solution.
The distance weights between vertices, represented as a adjacency matrix, can be obtained from FIG. 3, as shown in FIG. 4.
Regarding the undirected weight graph G (V, E) as a road from a distribution center to each customer point, wherein the distribution center A, nodes V1 to V6 are vertexes of each customer, and the weight E on each side represents the distance of the path; q
max=4.9,L
max200, initialize
k 1, set V
TAdding V1, V2, V3, V4, V5 and V6 into a set V
TSet of
Assign a to distribution center A, the vehicle load Q [1]]0, distance D [1]]=0;
Step 1: from the set VT{ V1, V2, V3, V4, V5, V6}, searching a vertex V2 with the minimum distance to a, and judging a condition Q [1]]+2.3<=QmaxAnd D [1]]+15+15<=LmaxIf the condition is satisfied, then V2 is selected from the set VTDelete middle, put set S [1]]In this case, S [1]]={V2},Q[1]=2.3,D[1]15, then V2 is assigned to a;
step 2: from the set VT{ V1, V3, V4, V5, and V6} searching the vertex V6 with the minimum distance to a, and judging the condition Q [1]]+2.3<=QmaxAnd D [1]]+22+30<=LmaxIf the condition is satisfied, then V6 is selected from the set VTDelete middle, put set S [1]]In this case, S [1]]={V2,V6},Q[1]=4.6,D[1]67, V6 is assigned to a;
step 3: from the set VT{ V1, V3, V4, V5} searching the vertex V4 with the minimum distance to a, and judging the condition Q [1]]+1.5<=QmaxAnd D [1]]+25+39<=LmaxIf the first condition is not satisfied, the first vehicle is distributed completely, Q1]=4.6,D[1]67, k 2, assign a to a and reset Q2]=0,D[2]=0;
Step 4: from the set VT{ V1, V3, V4, V5} searching the vertex V3 with the minimum distance to a, and judging the condition Q [2]]+1.8<=QmaxAnd D [2]]+35+35<=LmaxIf the condition is satisfied, then V3 is selected from the set VTDelete middle, put set S [2]]In this case, S2]={V3},Q[2]=1.8,D[2]35, V3 is assigned to a;
step5: from the set VT{ V1, V4, V5} searching the vertex V5 with the minimum distance from a, and judging the condition Q [2]]+1.3<=QmaxAnd D [2]]+40+37<=LmaxIf the condition is satisfied, then V5 is selected from the set VTDelete middle, put set S [2]]In this case, S2]={V3,V5},Q[2]=3.1,D[2]V5 is assigned to a at 75;
step 6: from the set VT{ V1, V4} searching the vertex V4 with the minimum distance to a, and judging the condition Q [2]]+1.5<=QmaxAnd D [2]]+55+39<=LmaxIf the condition is satisfied, then V4 is selected from the set VTDelete middle, put set S [2]]In this case, S2]={V3,V5,V4},Q[2]=4.6,D[2]130, V4 is assigned to a;
step 7: from the set VT{ V1} searching the vertex V1 with the minimum distance from a, and judging the condition Q [2]]+2.3<=QmaxAnd D [2]]+74+44<=LmaxIf all the conditions of the condition are not met, the second vehicle is distributed completely,Q[2]=4.6,D[2]169, k 3, assign a to a and reset Q3]=0,D[3]=0;
Step 8: from the set VT{ V1} searching the vertex V1 with the minimum distance from a, and judging the condition Q [3]]+2.3<=QmaxAnd D [3]]+44+44<=LmaxIf the condition is satisfied, then V1 is selected from the set VTDelete middle, put set S [3]]{ r }, in this case S [3]]={V1},Q[3]=2.3,D[3]44, V1 is assigned to a;
step 9: set VTIs empty, Q3]=2.3,D[3]When the cycle is finished, 88;
according to the logistics distribution algorithm, 3 vehicles are needed to complete distribution tasks; because S [1] = { V2, V6}, the first vehicle delivers vertices V2 and V6 in that order; the second vehicle sequentially delivers three vertexes V3, V5 and V4 because S [2] { V3, V5 and V4 }; s [3] = { V1}, so the third vehicle delivers V1; since Q [1] is 4.6 and D [1] is 67, the first vehicle weighs 4.6T and the travel distance is 67 km; the second vehicle weighs 4.6T and the driving distance is 169 kilometers because Q [2] is 4.6 and D [2] is 169; since Q [3] is 2.3 and D [3] is 88, the third vehicle weighs 2.3T and the travel distance is 88 km.