#################本文为学习《图论算法及其MATLAB实现》的学习笔记#################
在给定的通信或运输网络中,往往要利用已知的各弧(或边)的可靠性概率,求出指定顶点S到T的一条使得可靠性概率达到最大的路,此路称为由S到T的最大可靠路。实际生活中很多问题都可以转换成此类问题。
算法用途
求两顶点间的最大可靠路
算法思想
程序参数说明
A: 网络的完好概率矩阵
P: 找到的路径
p: 路径 P 对应的概率
f: f=0 表示找到路,否则 f=1
算法程序详解
%最大可靠路算法
function [ P,p,f ] = p_pathf( A )
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%% 输入: A: 网络的完好概率矩阵
%%%%%%%%% 输出: P: 找到的路径
%%%%%%%%% p: 路径 P 对应的概率
%%%%%%%%% f: f=0 表示找到路,否则 f=1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%% 初始化 %%%%%%%
[m, n] = size(A); % 计算 A 的行数和列数
f = 0;
B = zeros(m,n);
%%%%%%%%%% 对原矩阵进行转换 %%%%%%%%%%%
for i = 1:m
for j = 1:n
if A(i,j) > 0 && A(i,j) < 1
B(i,j) = -log(A(i,j));
elseif A(i,j) == 0
B(i,j) = inf;
end
end
end
%%%%%% 利用warshall-Floyd算法求最短路 %%%%%%
[P,d] = f_path(B); % 求出最短路及长度
if d < inf
p = 1;
for i = 1:(length(P)-1)
p = p * A(P(i),P(i+1)); %计算最短路完好概率
end
p;
else % 未找到路
P = 0;
p = 0;
f = 1;
end