How can i do that list for dijkstra algorithm?
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello, I have to optmizate a route using dijkstra algorithm. I'll import data from an excel archive like the following image (but with more data):

ID is a location and Value the distance between locations. From 1 to 2 the distance is 3, from 5 to 6 the distance is 4 and from 4 to 7 the distance its 1
I have to transform this data into a matrix to use in the dijkstra algorithm like this:
W = [3 3 4 5 4 1 2 1 1 3 1 4 2 1 2 1 3];
A = [3 1 1 1 1 2 3 4 5 6 7 8 2 3 4 6 7];
B = [6 2 3 4 5 6 7 7 8 9 9 9 3 4 5 7 8];
Example for the image:
W: [3 4 3 4 3 2 2 3 4 1 3 2] - Distances (Using Values data)
A: [1 2 4 5 7 8 1 2 3 4 5 6] - Original Location (Using ID in from left to right to the first 6 values and then up to down to the following 6 values)
B: [2 3 5 6 8 9 4 5 6 7 8 9] - Destinated Location (Using ID in from left to right to the first 6 values and then up to down to the following 6 values)
So, using the first column we have: Distance 3, from 1 to 2. Second column: Distance 4, from 2 to 3...
How can I automate that?
0 commentaires
Réponses (1)
Ameer Hamza
le 31 Oct 2020
Modifié(e) : Ameer Hamza
le 31 Oct 2020
You can use MATLAB's graph() object to do such a thing
W = [3 4 3 4 3 2 2 3 4 1 3 2];
A = [1 2 4 5 7 8 1 2 3 4 5 6];
B = [2 3 5 6 8 9 4 5 6 7 8 9];
G = graph(A, B, W);
Plot the graph()
plot(G)
Find the shortest path
shortestpath(G, 1, 9) % shortest path between 1 and 9
2 commentaires
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!