Please quote the relevant portions of the message to which you are replying.
costantinos@gmail.com wrote:
Quote:
Mark thanks for the reply.
you are right on some point but the problem is that over there are
passed only the values that have to do with the path that was already
selected.
>
mostly the problem is at
>
>
>
//if it is <= we get a different route.
for (jj = 1; jj < graph_size; jj ++)
{
>
if (distance[jj] <= shortest_d && not_checked[jj])
{
V = jj;
shortest_d = distance[V];
}
}
>
I don't think so. The code above is to pick out the closest vertex not
yet "finalized", which then becomes the source for the next relaxation
pass. (And as an aside this is a pretty slow implementation since you
take O(n) time to find that vertex. The conventional approach is to use
a priority queue instead.)
In any event, look back at my earlier reply. What you call the "edge
relaxation" step is where you determine if there is a better route to a
particular vertex. What you don't check for is the case of a tie-- two
routes that are equally good. You need separate logic for the '>' case
and the '=' case, but in the '=' case you need to save all equally good
routes. As I said before, the way to do this is not to have a single
predecessor value but a collection (list, vector, whatever) of values.
Mark