[CVRP] Based on matlab genetic algorithm to solve the problem of vehicle path planning with capacity (optimization goal: transportation cost) [including Matlab source code 2776]

⛄1. Introduction to VRP

1 Basic Principles of VRP
Vehicle Routing Problem (VRP) is one of the important research problems in operations research. VRP focuses on the route planning of a supplier and K sales points, which can be briefly described as: for a series of delivery points and receiving points, organize and call certain vehicles, arrange appropriate driving routes, and make the vehicles orderly Through them, we strive to achieve certain goals (such as vehicle The total mileage of empty driving is the shortest, the total transportation cost is the lowest, the vehicles arrive at a certain time, and the number of vehicles used is the smallest, etc.).
The illustration of VRP is as follows:
insert image description here
2 Problem Attributes and Common Problems
The characteristics of vehicle routing problems are relatively complex, and generally include four aspects of attributes:
(1) Address characteristics include: number of parking lots, type of demand, and operation requirements.
(2) Vehicle characteristics include: vehicle quantity, load capacity constraints, transportable variety constraints, operating route constraints, and working time constraints.
(3) Other characteristics of the problem.
(4) The objective function may be to minimize the total cost, or minimize the maximum operating cost, or maximize on-time operation.

3 Common problems fall into the following categories:
(1) Traveling salesman problem (2) Vehicle Routing Problem with Capacity Constraints
(CVRP).
insert image description here
insert image description here
insert image description here
The model continues to improve.
insert image description here
insert image description here
insert image description here
(3) Vehicle route problem with time window
Due to the continuous development of the VRP problem, considering that the demand point has requirements on the arrival time of the vehicle, adding time window restrictions to the vehicle journey problem becomes a vehicle route with time window problem (VRP with Time Windows, VRPTW). The Vehicle Routing Problem with Time Window (VRPTW) is to add the customer's visited time window constraints on the VRP. In the VRPTW problem, in addition to the travel cost, the cost function also includes the waiting time caused by arriving early for a certain customer and the service time required by the customer. In VRPTW, in addition to meeting the constraints of the VRP problem, the vehicle must also meet the time window constraints of the demand point, and the time window constraints of the demand point can be divided into two types, one is the hard time window (Hard Time Window) , the hard time window requires that vehicles must arrive within the time window, early arrivals must wait, and late arrivals are rejected; the other is the Soft Time Window (Soft Time Window), which does not necessarily have to arrive within the time window, but must be Arrival outside the window must be punished, and the biggest difference between the soft time window and the hard time window is to replace waiting and rejection with punishment.
insert image description here
insert image description here
Model 2 (refer to 2017 A generalized formulation for vehicle routing problems):
This model is a 2-dimensional decision variable
insert image description here
insert image description here
insert image description here
(4) collection and distribution problem
(5) multi-depot vehicle routing problem
reference (2005 lim, genetic algorithm for multi-depot vehicle routing problems_ Zou Tong, 1996 renaud)
insert image description here
Since the vehicle is homogeneous, the modeling here does not include the dimension of the vehicle in the variables.
insert image description here
insert image description here
(6) Priority constraint vehicle routing problem
(7) Compatibility Constrained Vehicle Routing Problem
(8) Stochastic Demand Vehicle Routing Problem

4 Solutions
(1) Mathematical analysis method
(2) Human-computer interaction method (
3) Grouping first and then routing method
(4) First routing and then grouping method
(5) Saving or insertion method
(6) Improvement or exchange method
(7 ) Mathematical programming approximation
(8) Heuristic algorithm

5 Comparison between VRP and VRPTW
insert image description here

⛄ 2. Introduction to Genetic Algorithms

1 Introduction
insert image description here
insert image description here
2 Genetic Algorithm Theory
2.1 Biological Basis of Genetic Algorithm
insert image description here
insert image description here
2.2 Theoretical Basis of Genetic Algorithm
insert image description here
insert image description here
insert image description here
insert image description here
2.3 Basic Concept of Genetic Algorithm 2.4
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
Standard Genetic Algorithm
insert image description here
insert image description here
2.5 Characteristics of Genetic Algorithm
insert image description here
insert image description here
2.6 Improvement Direction of Genetic Algorithm
insert image description here
3 Genetic Algorithm Process
insert image description here
insert image description here
insert image description here
4 Description of Key Parameters
insert image description here

⛄3. Part of the source code

% Genetic algorithm VRP problem Matlab implementation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%
clear;clc;close all;
load location.mat % load the data array in the database, you can call
cost=zeros() through data later;
Sup_Parent=[3 6 7 17 18 5 8 16 19 15 26 25 4 27 29 2 9 14 20 28 30 31 13 22 21 24 11 12 23 10 32 1]; G=100;% population
size
Parent=rand(G,32);% random parent 30-100 evenly distributed
for i=1:G % [Actually, each row of the parent G×30 matrix is ​​filled with 1 30 random numbers, and each row is 1 30]
[mn]=sort(Parent(i,: )); %After sorting row i of parent in ascending order, the result is stored in m, and the original subscripts of elements in m are stored in parent to n %initialized data
Parent(i,:)=n; %Store out-of-order subscripts in rows To parent
end
Pc=0.99;% cross ratio
Pm=0.0001;% variation ratio
species=[Sup_Parent;Parent];% population
children=[];% offspring
% fitness_value(4070,1)=0;% fitness value
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

g=input('number of iterations');
for generation=1:g
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Parent=species;% children become parents
children=[];% children
% selection Cross parent
[nm]=size(Parent);
% select=rand(1,n)<Pc;
% select=find(select==1);
% cross
for i=1:n
for j=i:n
if i~=j & rand<Pc
jiaocha
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%
for i=1:n
if rand<Pm
parent=Parent(i,:);% mutant individual
X=floor(rand 32)+1;
Y=floor(rand
32)+1;
Z=parent(X); % Exchange the X and Y elements of the current individual Parent(i,:)
parent(X)=parent(Y);
parent(Y)=Z; %mutation
children=[ children;parent];% mutant individuals added to the population
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%
Calculate the offspring fitness value
[mn]=size(children);
fitness_value_c=zeros(m,1);% offspring fitness value
for i=1:m
L1 =1;
for L2=1:n
if sum(data(children(i,L1:L2),3))>100 %adaptation function; row children(i,L1:L2) of data, element in column 3 and >25
fitness_c
L1=L2;
end
if L2==n
L2=L2+1;
fitness_c
end
end
end

⛄4. Running results

insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here

⛄5. Matlab version and references

1 matlab version
2014a

2 References
[1] Huang Gewen, Cai Yanguang, Qi Yuanhang, Chen Houren, Wang Shihao. Adaptive Genetic Gray Wolf Optimization Algorithm for Vehicle Routing Problems with Capacity Constraints [J]. Electronic Journal. 2019,47(12)

3 Remarks
Introduction This part is taken from the Internet and is for reference only. If there is any infringement, please contact to delete

Guess you like

Origin blog.csdn.net/TIQCmatlab/article/details/131503707