Graph theory Shortest circuit 01--shortest circuit matrix (FLOYD) algorithm

Source: Internet
Author: User

%========================================================

% 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.