Table of contents
1. Algorithm simulation effect
2. Algorithms involve an overview of theoretical knowledge
4. Complete algorithm code file
1. Algorithm simulation effect
The matlab2022a simulation results are as follows:
2. Algorithms involve an overview of theoretical knowledge
Definition of negative ring: Negative ring refers to the ring whose weight sum is negative. A negative cycle will cause the shortest path calculation of the graph to fall into an infinite loop, so there is no shortest path in a graph with a negative cycle.
Calculation method of negative ring:
There are two calculation methods for negative ring, both of which are based on Bellman-Ford algorithm or SPFA algorithm.
The first algorithm is: count the number of enqueues of each point. If a point enqueues more than or equal to n times, it means that there is a negative ring. The second algorithm is:
count the number of points that the shortest path to a certain point passes through. Number, if it passes through n points, it means that there is a negative cycle.
(In general, we use the second algorithm)
Because when the negative loop exists, SPFA will fall into an infinite loop, and n is the worst case of a non-infinite loop. So the above two algorithms are correct.
The programming implementation of the negative ring algorithm
first assigns the distance of all points to 0
and then enqueues all points.
12 nodes are randomly constructed at 100m*100m , and the nodes are connected by directed lines within 30m , and the simulation is independently performed for 1000 cycles. Among them, N_j can be set as 500~1000 random numbers.
Solving by using the N algorithm, the specific N algorithm process has been introduced in the article, mainly for the simulation of 2 and 3 parts in 111.pdf , that is, single user, multi-user with priority, and multi-user without distinction, among which for multi-user , the source node and destination node can be set according to: s_1=1,d_1=12;s_2=2,d_2=10;s_3=3,d_3=9;s_4=5,d_5=11.
3. MATLAB core program
........................................................
USER = [2,3,5];
for jks = 1:length(USER);
Traffic_VolumeS = [20];
SR = [10:10:60];
Es3 = [];
for jjj = 1:length(SR)
Traffic_Volume = Traffic_VolumeS;
Loop = 9;
Es = zeros(MTKL,Loop);
rng(5*jjj);
for i = 1:MTKL
i
%随机12个节点
X = SCALE*rand(1,Note);
Y = SCALE*rand(1,Note);
%30以内有相线相连接
xk_ij = zeros(Note,Note);
w_ij = zeros(Note,Note);
b_ij = zeros(Note,Note);
for j1 = 1:Note
for j2 = 1:Note
dist = sqrt((X(j1)-X(j2))^2 + (Y(j1)-Y(j2))^2);
if dist <= Dis_R & j1~=j2
%Select a feasible route with f = fij,这里构造一个连接矩阵,将相互连接的用1表示
xk_ij(j1,j2) = 1;
%随机分配cost
b_ij(j1,j2) = 50*randn-30;
end
end
end
EZ = 0;
for js2 = 1:USER(jks)
%初始值
fij = (1+rand/5)*Traffic_Volume + 2*randn(Note,Note);
fijmax0 = max(max(fij));
%选择一个路径
[f,flag] = func_sel_route(xk_ij,X,Y,fij,b_ij,Dis_R);
%开始迭代
E_1 = zeros(1,Loop);
for j = 1:Loop
if flag == 1
%补图
Nj = 500 + 500*rand;
Ys = func_complementary_graph(xk_ij,f);
[R,C] = size(Ys);
a = randperm(10);
SR_(jjj) = SR(jjj);%模拟in的Rate
Ri_in = 1e6*SR_(jjj);%转换为M,
Ri_out = 1e6*SR(jjj);%转换为M,
if j == 1
E_1(1,j) = Traffic_Volume;%初始值
else
Ej_proc = Nj/2*ECMP_max + ECMP_min;
Ei_out = frp(Ri_out) * (MOEC_min+(MOEC_max-MOEC_min)*rand);
Ej_in = frp(Ri_in) * (MIEC_min+(MIEC_max-MIEC_min)*rand);
E_1(1,j) = Ei_out + Ej_in + Ej_proc;
end
for k1 = 1:R
for k2 = 1:C
E(k1,k2) =E_1(1,j)*(1+randn/5);
end
end
%再将M除掉
E=E/1e6;
fijmax_ = zeros(R,C);
for k1 = 1:R
for k2 = 1:C
if Ys(k1,k2) == 1
fijmax_(k1,k2) = fijmax0 - fij(k1,k2);
fij(k2,k1) = fijmax_(k1,k2);
E_(k1,k2) = E(k1,k2);
E(k2,k1) = -E_(k1,k2);
end
end
end
E_=-E;
E = 7*E/sqrt(SR(jjj));
%negative cost cycle
[flags2] = func_negative_cost_cycle(Ys,xk_ij,X,Y,fij,Dis_R,E,E_,f);
if flags2 == 1%算法结束
break;
end
f_=f.*E;
for k1 = 1:R
for k2 = 1:C
tmps = fijmax0 - fij;
[xc,yc] = find(tmps==0);
tmps(xc,yc)=fijmax0;
delta = min([min(min(tmps)),min(min(fij))]);
if E_(k1,k2) > 0
fij(k2,k1) = fij(k2,k1)+delta;
else
fij(k2,k1) = fij(k2,k1)-delta;
end
end
end
E_1(1,j) = sum(sum(f_.*fij));
else
E_1(1,j) = 0;
end
end
EZ = EZ + E_1(end);
end
Es(i,:) = EZ;
end
%对1000迭代进行平均
Es2 = [];
for i = 1:Loop
tmps = Es(:,i);
index= find(tmps==0);
tmps(index)=[];
Es2 = [Es2,mean(tmps)];
end
Es3 = [Es3,Es2(end)];
end
if jks == 1
Eas = Es3;
save R1.mat Eas SR
end
if jks == 2
Ebs = Es3;
save R2.mat Ebs SR
end
if jks == 3
Ecs = Es3;
save R3.mat Ecs SR
end
end
12_028_m
4. Complete algorithm code file
V