Using Dijkstra algorithm.

2 次查看(过去 30 天)
sn at
sn at 2017-4-4
编辑: sn at 2017-4-4
I found this function
function [dist,path] = CSDG_Dijkstra_SP(nodes,segments,start_id,finish_id,L,PlotFlags);
which allows me to calculate the the shortest distance and path between points on a map. The inputs I need are "nodes", "segments", "start_id", and "finish_id". I already have the following:
xyNode=randi([1,100],N,2);
ID=[1:N]'
nodes=[ID,xyNode(:,1),xyNode(:,2)];
and start_id is the number of the node among N nodes that I have in my map. finish_id is for another node(different from this N nodes. It is the sink node) which is placed in certain position (center of the map). For this I wrote:
for n=1:N
start_id=n;
finish_id=(100*sqrt(N)/2),(100*sqrt(N)/2);
[dist,path]=CSDG_Dijkstra_SPT(nodes,segments,start_id,finish_id)
output(:,:,n)=[dist,path];
end
As it is defined in this function, the input "segments" should be an Mx3 matrix with the format [ID N1 N2] where ID is an integer, and N1, N2 correspond to node IDs from NODES list such that there is an [undirected] edge/segment between node N1 and node N2.
I've been told that two nodes are able to communicate if the distance between them is less than 100*sqrt(5).
How can I get the segments input with this information?
I'll be very grateful for any help.

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Networks 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by