필터 지우기
필터 지우기

how to find shortest path between 2 nodes

조회 수: 2 (최근 30일)
FIR
FIR 2014년 1월 21일
답변: Walter Roberson 2014년 1월 22일
I have a image in
here i want to find the shorted path between 2 nodes ,say node 1 and node 4,there are twopaths
1-5-4 and 1-5-3-4
can anyone tell how to find these two paths and find the shortest among them
i tried
[dist,path,pred] = graphshortestpath(UG,1,3,'directed',false);
it gives only one path i.e shortest path,i need all paths from node 1 to 4
  댓글 수: 2
Walter Roberson
Walter Roberson 2014년 1월 21일
I am confused. Your title indicates you want to find the shortest path, but your body seems to indicate that you want to find all the possible paths and then figure out which one is shortest and return that, with the effect of finding the shortest path. Algorithms for finding the shortest path do not require finding all paths first.
FIR
FIR 2014년 1월 22일
ok walter i go on with shortest path,as you indicated in previous mail,to use UDP or tcp for data transfer,now i want to transfer data between node 1 and 4,kindly tell what function or how to proceed for data transfer

댓글을 달려면 로그인하십시오.

답변 (2개)

Amit
Amit 2014년 1월 21일
편집: Amit 2014년 1월 21일

Walter Roberson
Walter Roberson 2014년 1월 22일
Follow the procedure I indicated in that other thread, as many times as necessary, each time getting one step closer to the destination.
There are two different ways you can proceed:
  1. At the source node, you work out the complete path to the destination node. When you transmit the data, prefix it with the remaining path. The node you hand over to will be responsible for contacting the next hop and transmitting the data to it with its own address stripped from the path list. Or:
  2. At the source node, figure out a node that is "closer" to the destination. There might be enough information to predict a likely complete path, but there might not be, and even if there is enough information, it could be that a node in the predicted path will become unavailable while the data is being relayed. Transmit the data to the predicted next step along the way, prefixed by an indication of the final destination, but not all of the predicted steps in the route. At the receiving node, again predict the best route and forward the packet onwards, hopefully getting closer and closer to the destination each time.
The first option, predicting the complete path and having each node required to follow it, runs the risk that a node will become unavailable, leaving it undefined how the packet should continue. The second option, continually predicting the path along the way, runs the risk that based on the path information as known to the receiving node, the packet will be sent to a node that has already handled it in the trip (possibly right back to the node that just send it here), potentially resulting in an infinite loop for the packet.
Both of these are classic routing problems in networking, and there is no solution that guarantees delivery or shortest delivery. There have been a number of routing protocols invented to work with these problems, with trade-offs necessarily taken. You need to investigate routing protocols and decide which one you are going to use.

카테고리

Help CenterFile Exchange에서 Construction에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by