how to find Shortest path from source to destination in wireless sensor networks using matlab?
조회 수: 4 (최근 30일)
이전 댓글 표시
Among all the paths available from source to destination, I need to find the shortest path between source and destination....For example,in an area of 500*500 i have deployed 10 nodes randomly.considering 1st node as source and 10th node as destination now,I need matlab code for finding the optimized route from node1 to node10..can anyone please help??
댓글 수: 3
Walter Roberson
2022년 9월 10일
I described the process https://www.mathworks.com/matlabcentral/answers/155009-how-to-find-shortest-path-from-source-to-destination-in-wireless-sensor-networks-using-matlab#answer_311668
x = randi(500, 1, 10);
y = randi(500, 1, 10);
xy = [x; y].'
D = squareform(pdist(xy))
G = graph(D)
p = shortestpath(G, 1, 10)
Shortest path is just to go directly from the beginning to the end.
This will always be the case unless:
- you have range limitations; or
- you have blocked paths; or
- you have non-euclidean paths: due to reflections and different materials, direct paths might lead to traversing paths with slower signal transmission rates, and indirect paths might hypothetically travel routes that have higher signal transmission rates
%range limit
D(D > 250) = 0;
G1 = graph(D)
p = shortestpath(G1, 1, 10)
채택된 답변
Walter Roberson
2018년 3월 24일
First construct a connection matrix with distances between nodes. Then use graph() or digraph() to build a graph object. You can then use shortestpath() to find the route between nodes.
Note that if you use euclidian distances and your graph is fully connected, then the shortest path is always direct from source to destination. Shortest path algorithms are for the case of noneucludian costs or the case where the graph is not fully connected.
An example of a noneucludian cost would be if there is a partly transparent obstacle such as a tree in some path that causes the energy requirements for that path to rise faster than the square of the distance. A full blockage such as concrete would prevent a path from being used. Reflections off of metal can have odd effects and can even provide better than euclidian energy costs if the reflection acts to focus a spreading signal.
Pure Euclidean costs also assume that there is an indefinitely large energy budget to transmit with, or that there is an indefinitely sensitive receiver with no noise. If these are not true then the graph will not be fully connected and a shortest path algorithm helps.
댓글 수: 0
추가 답변 (2개)
Junaid Qadir
2018년 3월 24일
You can use the Euclidean distance formula to find the nearest neighbor node.
댓글 수: 1
Walter Roberson
2018년 3월 24일
This is not sufficient to find shortest path on a network that forwards packets to nodes.
참고 항목
카테고리
Help Center 및 File Exchange에서 Dijkstra algorithm에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!