fordyn.m
来自「Mathematical Methods by Moor n Stiling.」· M 代码 · 共 31 行
M
31 行
function [pathlist,cost] = fordyn(G,W)
%
% Do forward dynamic programing
%
% function [pathlist,cost] = fordyn(G,W)
%
% G = list of next vertices
% W = list of costs to next vertices
%
% pathlist = list of paths through graphs
% cost = cost of the paths
% Copyright 1999 by Todd K. Moon
[m,n] = size(G); % n = number of vertices
n = n+1;
costs(n) = 0;
for j=n-1:-1:1
c = W{j}+costs(G{j});
[minc,idx] = min(c);
costs(j) = minc;
savevertex(j) = G{j}(idx);
end
cost = costs(1);
pathlist(1) = 1;
for j=2:n
pathlist(j) = savevertex(pathlist(j-1));
if(pathlist(j) == n)
break;
end
end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?