%========================================================
% Shortest path matrix algorithm, Floyd algorithm
% targeted: Program budget, can find out the shortest possible between the short (minimum cost, etc.)
%========================================================
function D=zuiduanjulijuzhen (quanzhijuzhen)
N=length (Quanzhijuzhen);
D=quanzhijuzhen;
M=1;
While M<=n
For I=1:n
For J=1:n
If D (i,j) >d (i,m) +d (M,J)
D (i,j) =d (i,m) +d (M,J);
End
End
End
m=m+1;
End
D
%========================================================
% Evaluation: Matrix Shortest Path algorithm, you can find all point to point minimum distance, but with its shortcomings,
% is not given a specific path, the program D is the shortest distance matrix
%========================================================
Example: the shortest distance between each point in the request.
Solution: (1) Write Weights matrix
Quanzhijuzhen =[0 2 8 1 inf inf INF
2 0 6 INF 1 inf INF
8 6 0 7 5 1 2 INF
1 INF 7 0 INF INF 9 inf
INF 1 5 INF 0 3 INF 8
INF INF 1 INF 3 0 4 6
INF INF 2 9 INF 4 0 3
INF inf INF 8 6 3 0]
(2) Bring in the procedure
>> D=zuiduanjulijuzhen (Quanzhijuzhen)
Description: Line 1th represents the distance between point 1 and other points, and the I=2-8 line represents the distance between the I point and other points.
Copyright Notice: Bo Main article can be reproduced non-commercial, but please be sure to indicate the source, because the level is limited, inevitably error, in this disclaimer.
Graph theory Shortest circuit 01--shortest circuit matrix (FLOYD) algorithm