minimiztion the distance travel

1 view (last 30 days)
hi everyone
i have to write a code such that the time reaching the two points is minimum where different different routes are available to reach the point
for example :
A=[ 0 2 100 2 10 100 100;
2 0 3 100 100 100 100;
100 3 0 100 100 5 2;
100 100 100 0 4 3 100;
10 100 100 2 0 2 1;
100 100 5 3 2 0 4;
100 100 2 100 1 4 0];
the above matrix denotes the time to reach from one point to other (for example: from point(1) to point(5) time will 10 sec) but when the time is 100 (point(1) and point(3)) that way has to b skipped and we have to find another route (ex: to reach point 1 fro 3 the new route can be (3-->2-->1)or(3-->6-->4-->1)) the another route must have minimum time travel.
can we use optimization technique??
  1 Comment
Walter Roberson
Walter Roberson on 1 Sep 2019
If you need to calculate the shortest path from each point to each other point then you will need to call one of the above multiple times.

Sign in to comment.

Accepted Answer

Bruno Luong
Bruno Luong on 1 Sep 2019
Edited: Bruno Luong on 1 Sep 2019
Checkout function distances
Warning : Your adjacent matrix is not symmetric !
>> A
A =
0 2 100 2 10 100 100
2 0 3 100 100 100 100
100 3 0 100 100 5 2
100 100 100 0 4 3 100
10 100 100 2 0 2 1
100 100 5 3 2 0 4
100 100 2 100 1 4 0
>> A==A'
ans =
7×7 logical array
1 1 1 0 1 1 1
1 1 1 1 1 1 1
1 1 1 1 1 1 1
0 1 1 1 0 1 1
1 1 1 0 1 1 1
1 1 1 1 1 1 1
1 1 1 1 1 1 1
Apply on symmetrized A
G = graph((A+A')/2);
distances(G)
Result:
ans =
0 2 5 11 8 10 7
2 0 3 9 6 8 5
5 3 0 6 3 5 2
11 9 6 0 3 3 4
8 6 3 3 0 2 1
10 8 5 3 2 0 3
7 5 2 4 1 3 0

More Answers (0)

Categories

Find more on Problem-Based Optimization Setup in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!