question on routing problem

1 view (last 30 days)
jana
jana on 4 Sep 2013
I am working on shortest path problem (dijiktra). My current code keeps track of one path from source to destination. I want to keep track of other paths if certain condition is satisfied. Any suggestions on how to keep track of other paths?
  4 Comments
jana
jana on 4 Sep 2013
I am not sure how to include this into the code. I am fairly new to matlab.
jana
jana on 4 Sep 2013
should I create a cell array for the distance matrix?

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 4 Sep 2013
visited(1:n) = 0;
distance(1:n) = inf; % it stores the shortest distance between each node and the source node;
parent(1:n) = 0;
distance(s) = 0;
tracked_paths = {};
tracking_idx = 0;
for i = 1:(n-1),
temp = [];
for h = 1:n,
if visited(h) == 0 % in the tree;
temp=[temp distance(h)];
else
temp=[temp inf];
end
end;
[t, u] = min(temp); % it starts from node with the shortest distance to the source;
visited(u) = 1; % mark it as visited;
for v = 1:n, % for each neighbors of node u;
if ( ( netCostMatrix(u, v) + distance(u)) < distance(v) )
distance(v) = distance(u) + netCostMatrix(u, v); % update the shortest distance when a shorter path is found;
parent(v) = u; % update its parent;
else if netCostMatrix(u, v) + distance(u)) == distance(v)
# I want to keep track of this path and its distance.
tracking_idx = tracking_idx + 1;
tracking_paths{tracking_idx} = {distance(u), distance(v), parent};
end;
end;
end;

Categories

Find more on Graph and Network Algorithms 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!