views:

25

answers:

1

I am using Dijkstra algorithm in a program.suppose i have a graph with vertices and edges.if we imaging all the edges starting from source vertex "a" are as below a-->b
a-->c and
a-->d
and all the edges ending to vertex "f" are : b-->f m-->f e-->f w-->f

what i need is i know from beginning that i want the edge a-->b as my starting edge (assume "a" as start point )so do not need to search for the other neighbors of "a" i.e. a-->c and a-->d also i only want paths which end to m-->f (assume "f" as the destination)i.e. i do not want the path containing b-->f ,m-->f,e-->f,w-->f so is it a good idea to trim my initial graph as such it doesn't contain these edges and then apply dijkstra on that. actually finding these edges needs some searches. I wonder if it is worth(considering time or cpu usage) dong searches and trimming my graph or there is a better way.

+1  A: 

Why not just search for a path from b to m then and add the edges you want after that? If you really need it, you may add a special case to exclude edges containing a and f from ever being added to the stack -- you'd have to check if that makes it faster overall, my bet is that it will on small graphs but not on really huge ones (it only changes speed by a constant factor anyways).

Radomir Dopieralski