VRPTW: The dung beetle optimization algorithm DBO solves the vehicle routing problem with time windows (Vehicle Routing Problem with Time Windows, VRPTW) provides MATLAB code

1. VRPTW

1.1 Model Introduction

Vehicle Routing Problem with Time Windows (VRPTW) is an extended type of Vehicle Routing Problem (VRP). VRPTW generally refers to vehicles with capacity constraints providing delivery or pick-up services within the time specified by customers. It is widely used in the field of logistics and has important practical significance. The general model of VRPTW is as follows: Detailed introduction of VRPTW model

min ⁡ f ( x ) = 1000 ∑ k ∈ K ∑ j ∈ Δ + ( 0 ) x 0 j k + ∑ k ∈ K ∑ ( i , j ) ∈ A c i j x i j k ∑ k ∈ K ∑ j ∈ Δ + ( i ) x i j k = 1 ∀ i ∈ N ( 1 ) ∑ j ∈ Δ + ( 0 ) x 0 j k = 1 ∀ k ∈ K ( 2 ) ∑ i ∈ Δ − ( j ) x i j k − ∑ i ∈ Δ + ( j ) x j i k = 0 ∀ k ∈ K , ∀ j ∈ N ( 3 ) ∑ i ∈ Δ Δ − ( n + 1 ) x i , n + 1 , k = 1 ∀ k ∈ K ( 4 ) w i k + s i + t i j − w j k ≤ ( 1 − x i j k ) M i j , ∀ k ∈ K , ∀ ( i , j ) ∈ A ( 5 ) a i ( ∑ j ∈ Δ + ( i ) x i j k ) ≤ w i k ≤ b i ( ∑ j ∈ Δ + ( i ) x i j k ) ∀ k ∈ K , ∀ i ∈ N ( 6 ) E ≤ w i k ≤ L ∀ k ∈ K , ∀ i ∈ { 0 , n + 1 } ( 7 ) ∑ i ∈ N d i ∑ j ∈ Δ + ( i ) x i j k ≤ C ∀ k ∈ K ( 8 ) x i j k ≥ 0 ∀ k ∈ K , ∀ ( i , j ) ∈ A ( 9 ) x i j k  binary  ∀ k ∈ K , ∀ ( i , j ) ∈ A ( 10 ) \begin{array}{l} \min f(x)=1000 \sum_{k \in K} \sum_{j \in \Delta^{+}(0)} x_{0 j k}+\sum_{k \in K} \sum_{(i, j) \in A} c_{i j} x_{i j k} \\\\ \sum_{k \in K} \sum_{j \in \Delta^{+}(i)} x_{i j k}=1 \quad \forall i \in N \quad \quad \quad (1)\\ \sum_{j \in \Delta^{+}(0)} x_{0 j k}=1 \quad \forall k \in K \quad \quad \quad (2)\\ \sum_{i \in \Delta-(j)} x_{i j k}-\sum_{i \in \Delta^{+}(j)} x_{j i k}=0 \quad \forall k \in K, \forall j \in N \quad \quad \quad (3)\\ \sum_{i \in \Delta \Delta^{-(n+1)}} x_{i, n+1, k}=1 \quad \forall k \in K\quad \quad \quad (4) \\ w_{i k}+s_{i}+t_{i j}-w_{j k} \leq\left(1-x_{i j k}\right) M_{i j}, \forall k \in K, \forall(i, j) \in A \quad \quad \quad (5)\\ a_{i}\left(\sum_{j \in \Delta^{+}(i)} x_{i j k}\right) \leq w_{i k} \leq b_{i}\left(\sum_{j \in \Delta^{+}(i)} x_{i j k}\right) \quad \forall k \in K, \forall i \in N \quad \quad \quad (6)\\ E \leq w_{i k} \leq L \quad \forall k \in K, \forall i \in\{0, n+1\} \quad \quad \quad (7)\\ \sum_{i \in N} d_{i} \sum_{j \in \Delta^{+}(i)} x_{i j k} \leq C \quad \forall k \in K \quad \quad \quad (8) \\ x_{i j k} \geq 0 \quad \forall k \in K, \forall(i, j) \in A\quad \quad \quad (9)\\ x_{i j k} \text { binary } \forall k \in K, \forall(i, j) \in A \quad \quad \quad (10)\\ \end{array} minf(x)=1000kKjΔ+(0)x0jk+kK(i,j)AcijxijkkKjΔ+(i)xijk=1iN(1)jΔ+(0)x0jk=1kK(2)iΔ(j)xijkiΔ+(j)xjik=0kK,jN(3)iΔΔ(n+1)xi,n+1,k=1kK(4)wi+si+tijwjk(1xijk)Mij,kK,(i,j)A(5)ai(jΔ+(i)xijk)wibi(jΔ+(i)xijk)kK,iN(6)EwiLkK,i{ 0,n+1}(7)iNdijΔ+(i)xijkCkK(8)xijk0kK,(i,j)A(9)xijk binary kK,(i,j)A(10)
In the formula, the objective function f ( x ) f(x)f ( x ) is the total cost = 1000 * the number of vehicles used + the total distance traveled by all vehicles,NNN represents the set of customers. Constraint (1) restricts each customer to be assigned to only one route; Constraints (2)-(4) represent the flow limit of vehicle k on the route; Constraints (5)~(7) represent the time window Constraints; Constraint (8) represents load capacity constraints, and constraints (9)-(10) represent decision vector constraints.
References:
[1] He Meiling, Wei Zhixiu, Wu Xiaohui, etc. Solving Vehicle Routing Problems with Soft Time Windows Based on Improved Ant Colony Algorithm [J]. Computer Integrated Manufacturing Systems, 2023, 29(03): 1029-1039. [
2 ] Li Lin, Liu Shixin, Tang Jiafu. Improved Ant Colony Algorithm for Vehicle Routing Problems with Time Window[J]. Control and Strategy, 2010,25(09):1379-1383.

1.2 Introduction to VRPTW dataset

The detailed information of the data set selected in this paper is shown in the following table, which includes 1 distribution center (serial number 0 indicates the distribution center), 25 customers (serial number 1-25), and the load limit of each vehicle is 200. ( Can be replaced with other datasets )
insert image description here

2. Dung Beetle Optimization Algorithm DBO

The Dung beetle optimizer (DBO) was proposed by Jiankai Xue and Bo Shen in 2022. This algorithm is mainly inspired by the behaviors of rolling balls, dancing, foraging, stealing and breeding of dung beetles.
insert image description here

2.1 Dung beetle rolling ball

(1) When the dung beetle is moving forward without obstacles, the dung beetle will use the sun to navigate during the process of rolling the dung ball. The red arrow in the figure below indicates the rolling direction. This paper assumes that the intensity of the light source will affect the position of the dung beetle
insert image description here
. The position update during the dung ball process is as follows:

x i ( t + 1 ) = x i ( t ) + α × k × x i ( t − 1 ) + b × Δ x , Δ x = ∣ x i ( t ) − X w ∣ \begin{aligned} x_{i}(t+1) &=x_{i}(t)+\alpha \times k \times x_{i}(t-1)+b \times \Delta x, \\ \Delta x &=\left|x_{i}(t)-X^{w}\right| \end{aligned} xi(t+1)Δ x=xi(t)+a×k×xi(t1)+b×Δx , _=xi(t)Xw
Among them, ttt represents the current iteration number,xi ( t ) x_{i}(t)xi( t ) means theiiThe position information of the dung beetle in the t iteration of the i time, k ∈ ( 0 , 0.2 ] k ∈ (0,0.2]k(0,0.2 ] is the disturbance coefficient,bbb is( 0 , 1 ) (0,1)(0,1 ) , a random number betweenα \alphaα takes -1 or 1,X w X^{w}Xw represents the global worst position,Δ x \Delta xΔx is used to simulate the intensity change of light.
Among them,α \alphaThe value of α adopts Algorithm 1:
insert image description here

(2) When a dung beetle encounters an obstacle and cannot move forward, it needs to readjust itself by dancing to obtain a new route. In this paper, the tangent function is used to imitate the dancing behavior to obtain a new rolling direction. The rolling direction is only considered as [ 0 , π ] [0,π][0,π ] between.
insert image description here
Once the dung beetle has successfully determined a new direction, it should continue rolling the ball backwards. The position of the dung beetle is updated as follows:
xi ( t + 1 ) = xi ( t ) + tan ⁡ ( θ ) ∣ xi ( t ) − xi ( t − 1 ) ∣ x_{i}(t+1)=x_{i }(t)+\tan (\theta)\left|x_{i}(t)-x_{i}(t-1)\right|xi(t+1)=xi(t)+tan ( θ )xi(t)xi(t1 )
Among them,θ \thetaθ is the deflection angle, and its value is[ 0 , π ] [0,π][0,π ] , using Algorithm 2:
insert image description here

2.2 Dung beetle reproduction

insert image description here

In nature, female dung beetles roll dung balls to a safe place suitable for laying eggs and hide them to provide a safe environment for their offspring. Inspired by this, a boundary selection strategy is proposed to simulate the spawning area of ​​female dung beetles:
L b ∗ = max ⁡ ( X ∗ × ( 1 − R ) , L b ) U b ∗ = min ⁡ ( X ∗ × ( 1 + R ) , U b ) \begin{array}{l} L b^{*}=\max \left(X^{*} \times(1-R), L b\right) \ \ U b^{*}=\min \left(X^{*} \times(1+R), U b\right) \end{array}Lb=max(X×(1R),Lb)Ub=min(X×(1+R),Ub)
Among them, X ∗ X^{*}X represents the current optimal position,L b ∗ L b^{*}Lb sumU b ∗ U b^{*}Ub represent the lower limit and upper limit of the spawning area respectively,R = 1 − t / T max R=1−t/T_{max}R=1t/Tmax T m a x T_{max} TmaxIndicates the maximum number of iterations, L b LbL bU b UbU b denote the lower and upper bounds of the optimization problem, respectively.
Once the female dung beetle has determined the spawning area, she will choose to lay eggs in the brood ball in this area. Each female dung beetle only produces one egg in each iteration. It can be seen that the boundary range of the spawning area is dynamically changed, mainly determined by the R value. Therefore, the position of the brood ball is also dynamic during the iteration process, which is defined as follows:
B i ( t + 1 ) = X ∗ + b 1 × ( B i ( t ) − L b ∗ ) + b 2 × ( B i ( t ) − U b ∗ ) B_{i}(t+1)=X^{*}+b_{1} \times\left(B_{i}(t)-L b^{*}\right) +b_{2} \times\left(B_{i}(t)-U b^{*}\right)Bi(t+1)=X+b1×(Bi(t)Lb)+b2×(Bi(t)Ub )
Among them,B i ( t ) B_{i}(t)Bi( t ) represents the position information of the i-th brood ball in the t-th iteration,b 1 b_{1}b1and b 2 b_{2}b2Both are random vectors of 1×D, and D represents the dimension of the optimization problem.
The selection of the spawning area is shown in Algorithm 3:
insert image description here

2.3 Dung beetle foraging

insert image description here
The eggs laid by female dung beetles will gradually grow up, and some mature young dung beetles will come out from the ground to find food. The optimal foraging area of ​​young dung beetles is modeled as follows:
L bb = max ⁡ ( X b × ( 1 − R ) , L b ) U bb = min ⁡ ( X b × ( 1 + R ) , U b ) \begin{array}{l} L b^{b}=\max \left(X^{b} \times(1-R), L b\right) \\ U b^{b}=\min \left(X^{b} \times(1+R), U b\right) \end{array}Lbb=max(Xb×(1R),Lb)Ubb=min(Xb×(1+R),Ub)
where, X b X^{b}Xb represents the global optimal position,L bb L b^{b}Lbb sumU bb U b^{b}Ubb represent the lower limit and upper limit of the optimal foraging area, respectively.
insert image description here

小蜣螂的位置更新如下:
x i ( t + 1 ) = x i ( t ) + C 1 × ( x i ( t ) − L b b ) + C 2 × ( x i ( t ) − U b b ) x_{i}(t+1)=x_{i}(t)+C_{1} \times\left(x_{i}(t)-L b^{b}\right)+C_{2} \times\left(x_{i}(t)-U b^{b}\right) xi(t+1)=xi(t)+C1×(xi(t)Lbb)+C2×(xi(t)Ubb )
Among them,xi ( t ) x_{i}(t)xi( t ) indicates the position of the i-th dung beetle in the t-th iteration,C 1 C_{1}C1is a random number subject to normal distribution, C 2 C_{2}C2A random vector of (0,1).

2.4 Dung beetle stealing

insert image description here

On the other hand, some dung beetles steal dung balls from other dung beetles, and the location of the thieves dung beetles is updated as follows:

x i ( t + 1 ) = X b + S × g × ( ∣ x i ( t ) − X ∗ ∣ + ∣ x i ( t ) − X b ∣ ) x_{i}(t+1)=X^{b}+S \times g \times\left(\left|x_{i}(t)-X^{*}\right|+\left|x_{i}(t)-X^{b}\right|\right) xi(t+1)=Xb+S×g×(xi(t)X+ xi(t)Xb )
, wherexi ( t ) x_{i}(t)xi( t ) represents the position of the i-th thieves dung beetle in the t-th iteration, g is a 1×D random vector that obeys a normal distribution, and S is a constant.

2.5. Algorithm description

The distribution of the proportions of rolling beetle, breeding beetle, foraging beetle and stealing beetle is as follows: The
insert image description here
DBO algorithm is described as follows:
insert image description here
Reference: Xue, J., Shen, B. Dung beetle optimizer: a new meta-heuristic algorithm for global optimization . J Supercomput (2022). https://doi.org/10.1007/s11227-022-04959-6

3. The dung beetle optimization algorithm DBO solves VRPTW

close all
clear 
clc
完整代码添加博主微信:djpcNLP123

SearchAgents_no=50; % 种群大小
Function_name='F1'; 
Max_iteration=100; % 最大迭代次数
[lb,ub,dim,fobj]=Get_Functions_details(Function_name);
[fMin,bestX,curve]=DBO(SearchAgents_no,Max_iteration,lb,ub,dim,fobj);  %算法求解

%% 显示最终结果
Pos=ShowResult(bestX);
%% 画图
figure
plot(curve,'Color','g','linewidth',1.5)%semilogy
xlabel('迭代次数');
ylabel('路径成本');
grid on
box on
legend('DBO')
%% 保存数据
save curve curve
save bestX bestX

Partial results:
insert image description here
insert image description here
insert image description here

Delivery route 1: 0->21->6->0 Number of customers served: 2 Path length: 51.56878 Load capacity: 14
Start time of service customer 21: 18.02776, end time: 28.02776
Start time of service customer 6: 50.38844 , End time: 60.38844
Arrival time at distribution center: 71.56878

Delivery route 2: 0->12->22->1->0 Number of customers served: 3 Path length: 94.93124 Load capacity: 47
Start time of service customer 12: 15.00000, end time: 25.00000 Start time
of service customer 22 Time: 50.49510, end time: 60.49510
service customer 1 start time: 99.69969, end time: 109.69969
arrival time at distribution center: 124.93124

Delivery route 3: 0->5->16->17->0 Number of customers served: 3 Path length: 73.39002 Load capacity: 47
Start time of service customer 5: 20.61553, end time: 30.61553
Start time of service customer 16 Time: 41.79587, End Time: 51.79587
Service Customer 17 Start Time: 62.97621, End Time: 72.97621
Arrival Time at Distribution Center: 103.39002

Delivery route 4: 0->2->3->4->0 Number of customers served: 3 Path length: 102.40930 Loading capacity: 39
Start time of service customer 2: 18.00000, end time: 28.00000 Start time
of service customer 3 Time: 62.40930, end time: 72.40930
service customer 4 start time: 97.40930, end time: 107.40930
arrival time at distribution center: 132.40930

Delivery route 5: 0->7->8->0 Number of customers served: 2 Path length: 59.66857 Load capacity: 14
Start time of service customer 7: 21.21320, end time: 31.21320
Start time of service customer 8: 43.41976 , End time: 53.41976
Arrival time at distribution center: 79.66857

Delivery route 6: 0->9->10->0 Number of customers served: 2 Path length: 82.51072 Load capacity: 32
Start time of service customer 9: 32.01562, end time: 42.01562
Start time of service customer 10: 67.01562 ,End time: 77.01562
Arrive at distribution center: 102.51072

Delivery route 7: 0->11->13->0 Number of customers served: 2 Path length: 85.95242 Load capacity: 35
Start time of service customer 11: 33.54102, end time: 43.54102
Start time of service customer 13: 84.77208 ,End time: 94.77208
Time to arrive at distribution center: 105.95242

Delivery route 8: 0->14->15->0 Number of customers served: 2 Path length: 78.24082 Load capacity: 28
Start time of service customer 14: 32.01562, end time: 42.01562
Start time of service customer 15: 57.82701 , End time: 67.82701
Arrival time at distribution center: 98.24082

Delivery route 9: 0->18->0 Number of customers served: 1 Path length: 31.62278 Loading capacity: 12
Start time of service customer 18: 15.81139, end time: 25.81139
Arrival time at distribution center: 41.62278

Delivery route 10: 0->19->20->0 Number of customers served: 2 Path length: 94.05221 Load capacity: 26
Start time of service customer 19: 32.01562, end time: 42.01562
Start time of service customer 20: 72.42943 , End time: 82.42943
Arrival time at distribution center: 114.05221

Delivery route 11: 0->23->24->25->0 Number of customers served: 3 Path length: 116.21931 Load capacity: 38
Start time of service customer 23: 36.05551, end time: 46.05551 Start time
of service customer 24 Time: 77.67829, end time: 87.67829
service customer 25 start time: 102.67829, end time: 112.67829
arrival time at distribution center: 146.21931

Total length of delivery route: 870.56615

4. Complete MATLAB code

Add the complete code to the blogger’s WeChat account below the blog

Guess you like

Origin blog.csdn.net/weixin_46204734/article/details/130440988