Algorithm introduction
B station up video introduction
Easy-to-use software: Algorithm animation diagram (Android has a cracked version and Apple needs to buy it)
Use matlab built-in function code to achieve
clear;clc
load Ddata.mat
%内置函数实现
G = digraph(D(:,1),D(:,2),D(:,3));%输入邻接矩阵
plot(G, 'EdgeLabel', G.Edges.Weight, 'linewidth', 2) %作带权重的有向图并将边的宽度设为2以显示的更加清晰
[P,d] = shortestpath(G, 1, 8); %注意:该函数matlab2015b之后才有
% 在图中高亮我们的最短路径
myplot = plot(G, 'EdgeLabel', G.Edges.Weight, 'linewidth', 2); %首先将图赋给一个变量
highlight(myplot, P, 'EdgeColor', 'r') %对这个变量即我们刚刚绘制的图形进行高亮处理(给边加上r红色)
%%扩展
% 求出任意两点的最短路径矩阵
A = distances(G); %注意:该函数matlab2015b之后才有
%A(1,8) % 1 -> 8的最短路径
%自定义函数实现
[P,d] = Dijkstra(D,start,end);
result
Attached, reproduce the algorithm with your own code
I'll make it up later, I can't finish learning, woo woo woo