Performance problems with digraph structure
Ältere Kommentare anzeigen
Hello, I need to add and remove nodes to a directional graph structure in real-time. Unfortunately i've encountered massive performance problems using the digraph structure from Matlab - especially when adding or removing nodes/edges. Are there any alternatives or more adequate ways to archive my goles. I'm thankful for any help!
nClosest = 16;
numFrames = 30;
idx = knnsearch(featureTree, features, 'K', nClosest).';
data = frameData(idx,:);
%%420 frames per second
nodes = table(data, 'VariableNames', {'Data'});
%%350 frames per second
% Node 1 is START, node 2 is END
if counter < numFrames
lastIdx = counter*nClosest+2;
graph = addnode(graph, nodes);
else
lastIdx = numFrames*nClosest+2;
graph = addnode(graph, nodes);
graph = rmnode(graph, 3:nClosest+2); % never remove START or END
end
myNodes = graph.Nodes;
%%180 frames per second
if lastIdx == numFrames*nClosest+2
firstRowIdx = lastIdx-nClosest+1 : lastIdx;
secondRowIdx = lastIdx-nClosest*2+1 : lastIdx-nClosest;
firstRow = myNodes(firstRowIdx,:).Data;
secondRow = myNodes(secondRowIdx,:).Data;
[t,knnW] = knnsearch(firstRow, secondRow);
edge = secondRowIdx(t);
startNodeIdx = 1;
endNodeIdx = 2;
w = zeros(1,nClosest*3);
w(nClosest*2+1:end) = knnW;
from = 3:nClosest*3+2; %last row
from(nClosest+1:nClosest*2) = ones(1,nClosest)*startNodeIdx; % start
from(nClosest*2+1:end) = firstRowIdx; % first row
to = ones(1,nClosest*3)*endNodeIdx; %end
to(nClosest+1:nClosest*2) = firstRowIdx; % first row
to(nClosest*2+1:end) = edge; % second row
graph = addedge(graph, from, to, w);
end
%%108 frames per second
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Graph and Network Algorithms finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!