How to find shortest path using dijkstra algorithm?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Here, i have attached the code for shortest path using dijkstra algorithm and output image. In this, i give 21 nodes as input. In this code, i have following TWO doubts. 1.But in this output image, only first 10 nodes are shown other nodes are not shown. How solve this problem? 2. In this code, if i give start and finish node less than 10, it will work. If i give start and finish node greater than 10, it will not work. How to solve it?
nodes = [ 1 131 130; 2 281 135; 3 389 220; 4 132 290; 5 231 293; 6 392 395; 7 227 503; 8 137 504; 9 390 574; 10 145 672; 11 292 674; 12 131 1; 13 291 1; 14 1 135; 15 525 183; 16 1 292; 17 525 397; 18 1 504; 19 525 607; 20 1 672; 21 147 799];
segments = [(1:17); floor(1:0.5:9); ceil(2:0.5:10)]';
figure; plot(nodes(:,2), nodes(:,3),'k.');
hold on;
for s = 1:17
if (s <= 10) text(nodes(s,2),nodes(s,3),[' ' num2str(s)]); end
plot(nodes(segments(s,2:3)',2),nodes(segments(s,2:3)',3),'k');
end
[d, p] = dijkstra(nodes, segments, 3, 9)
for n = 2:length(p)
plot(nodes(p(n-1:n),2),nodes(p(n-1:n),3),'r-.','linewidth',2);
end
hold off;
0 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Dijkstra algorithm dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!