遷移コスト行列のノードから他のすべてのノード(ここにある関数のフォルダ内のDPA関数http://uk.mathworks.com/matlabcentral/fileexchange/39034-finding-optimal-path-on-a-terrain)への最適なパスを見つけるスクリプトがあります。最適なパス関数の高速化
私が抱えている問題は、この機能が私の必要とするものですが、16641 x 16641のマトリックス(129 * 129 x 129 * 129)で実行する必要があるということです。私は現在それを実行していますが、予想どおりの年齢を取っています(現在はまだ2時間で稼働しています)。私は最後に機能全体を掲示するつもりですが、誰かが機能に次のような変更を加えるとかなり速く動くかどうかを明らかにすることができるのだろうかと思っていました。私は、この過剰な時間を実行するプロセスが、
for fromNode = 1 : m
for toNode = 1 : m
aij = P(toNode, fromNode);
dj = aij + prevStageCostMat(fromNode);
if dj < stageCostMat(toNode)
stageCostMat(toNode) = dj;
predMat(toNode, stage) = fromNode;
end
end % end toNode
end % end fromNode
ここでm = 16641であると信じています。関数は、正しい結果を出すかどうかにかかわらず、すべてのノードを伝播しなければなりません(関数が何をしているのかを正しく理解していますか?)、あるいは計算を高速化する方法はありますか?
主な機能のページには、誰もが私に私は非常に感謝(とあなたが任意のより多くの明確化が必要な場合、私は理解して私に知らせてくださいと思います任意の洞察力を与えることができればここで
% Keep in mind that DPA propagates through all the nodes. Basically DPA
% tries to find optimal path from one nodes to all nodes
は、フル機能であると言います私がこれを混乱させて説明したならば)、ありがとう!
function [stageCostMat, predMat, converged] = dpa(P, startNode, endNode, maxIteration)
% This is the function that will perform the DPA.
%
% Assume we have n number of nodes. P matrix is the transition cost matrix
% with dimension of n x n(square matrix). P(toNode, fromNode) shows
% transition cost from fromNode to toNode.
%
% stageCostMat shows the cost at each node for current iteration.
% stageCostMat(c) = current stage cost matrix at node c.
%
% predMat shows parent/predecessor node of each node for every stage.
% predMat(c, s): parent of node c during stage s.
%
% [email protected]
% 17.11.2012
% -------------------------------------------------------------------------
% Is the algortihm converged?
converged = 0;
% Cost matrix is a square matrix, m = n
[m, n] = size(P);
% Assume we will probably converge after n stages
stageCostMat = ones(1, m) * inf;
% Initial cost, no initial cost
stageCostMat(startNode) = 0;
% Predecessor matrix to trace back the optimum path, we will record parent of
% each node on each iteration
predMat = zeros(m, maxIteration);
% Stage-by-stage, we move from start node to terminal node
for stage = 2 : maxIteration
% Find connection from any nodes to any nodes, keep the smaller cost
prevStageCostMat = stageCostMat;
stageCostMat = ones(1, m) * inf;
for fromNode = 1 : m
for toNode = 1 : m
aij = P(toNode, fromNode);
dj = aij + prevStageCostMat(fromNode);
if dj < stageCostMat(toNode)
stageCostMat(toNode) = dj;
predMat(toNode, stage) = fromNode;
end
end % end toNode
end % end fromNode
% Termination
% if (stageCostMat == prevStageCostMat)
% converged = 1;
% break;
% end
if (predMat(endNode, stage) == endNode) || (predMat(endNode, stage-1) > 0) && (predMat(endNode, stage) == predMat(endNode, stage-1))
converged = 1;
break;
end
end
predMat = predMat(:, 1:stage);
おそらくこれをスピードアップするにはいくつかのことがありますが、これは主にあなたのマトリックスに依存しています。ループは可能なすべての接続(1:mから1:m)をチェックしますが、これはおそらく減らすことができます。行列Pはどのくらい疎ですか? – Finn
さて、Pのすべての値は対角にあるセルと対角線の上にあるセルとその直下のセルを除いて「Inf」です –
素晴らしい!その場合、内側のforループでthorugh(m-1):(m + 1)からループするだけで、すべての「Inf」計算が何とか生成されないので、計算を1%未満に減らします。それをあなた自身に適応させることができますか? (P、startNode、endNode、maxIteration) – Finn