dijkstra_shortest_paths with undirectedS example
Hello,
I am new to BGL, I was trying to test dijkstra_shortest_paths() with
undirectedS, the result is not what I wanted, anyone giving help?
Thanks, source code like dijkstra-example.cpp in the graph/example.
int
main(int, char *[])
{
typedef adjacency_list < listS, vecS, undirectedS,
no_property, property < edge_weight_t, double > > graph_t;
typedef graph_traits < graph_t >::vertex_descriptor
vertex_descriptor;
typedef graph_traits < graph_t >::edge_descriptor edge_descriptor;
typedef std::pair
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi,
The result is : distances and parents: distance(0) = 0, parent(0) = 0 distance(1) = 2, parent(1) = 0 distance(0) = 1, parent(2) = 0
According to your code, the last line should be distance(2) = 1, parent(2) = 0 Thr results are all correct. Why did you expect them to be different? You have an undirected Graph, and you can directly reach node 1 and 2 from node 0:
min paths tree 0 -> 1 2 1 -> 2 ->
I think the correct one should be: distances and parents: distance(0) = 0, parent(0) = 0 distance(1) = 2, parent(1) = 2
Why that? Node 1 is directly connected with node 0 and the path via node 2 is not shorter.
distance(2) = 1, parent(2) = 0 min paths tree 0 -> 1 1 -> 2
Here again: see above.
2 ->
Michael - -- Dipl.-Ing. Michael Kettner, Wissenschaftlicher Mitarbeiter Institut für Verkehrswesen, Eisenbahnbau und -betrieb, Universitaet Hannover Appelstr. 9A # Tel: ++49/(0)511/762-4273 D-30167 Hannover # Fax: ++49/(0)511/762-3001 http://www.ive.uni-hannover.de # kettner@ive.uni-hannover.de -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE+pU5pkCdGnb0kVFMRAsOiAKCB5OfzNHHux/kj9M92h4TnFLSL3gCfdegJ QpU7QJwOU88UONIDHLgaumI= =qxUV -----END PGP SIGNATURE-----
Thanks, Michael, I knew that I misunderstand the problem, the
results from the code is correct.
O.K., let me explain my problem, and I would appreciate for any hints
and help.
Suppose that I have a number of points(node), I know their distance
(weight), and I know the starting point, how could I get the shortest
path passing all the these points or some of these points? Any
algorithm I can use in BGL?
Thanks!
--- In Boost-Users@yahoogroups.com, Michael Kettner
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Hi,
The result is : distances and parents: distance(0) = 0, parent(0) = 0 distance(1) = 2, parent(1) = 0 distance(0) = 1, parent(2) = 0
According to your code, the last line should be distance(2) = 1, parent(2) = 0 Thr results are all correct. Why did you expect them to be different? You have an undirected Graph, and you can directly reach node 1 and 2 from node 0:
min paths tree 0 -> 1 2 1 -> 2 ->
I think the correct one should be: distances and parents: distance(0) = 0, parent(0) = 0 distance(1) = 2, parent(1) = 2
Why that? Node 1 is directly connected with node 0 and the path via node 2 is not shorter.
distance(2) = 1, parent(2) = 0 min paths tree 0 -> 1 1 -> 2
Here again: see above.
2 ->
Michael
- -- Dipl.-Ing. Michael Kettner, Wissenschaftlicher Mitarbeiter Institut für Verkehrswesen, Eisenbahnbau und -betrieb, Universitaet Hannover Appelstr. 9A # Tel: ++49/(0)511/762-4273 D-30167 Hannover # Fax: ++49/(0)511/762-3001 http://www.ive.uni-hannover.de # kettner@i... -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org
iD8DBQE+pU5pkCdGnb0kVFMRAsOiAKCB5OfzNHHux/kj9M92h4TnFLSL3gCfdegJ QpU7QJwOU88UONIDHLgaumI= =qxUV -----END PGP SIGNATURE-----
"jfw1000"
Thanks, Michael, I knew that I misunderstand the problem, the results from the code is correct.
O.K., let me explain my problem, and I would appreciate for any hints and help.
Suppose that I have a number of points(node), I know their distance (weight), and I know the starting point, how could I get the shortest path passing all the these points or some of these points? Any algorithm I can use in BGL?
Hah! Classic travelling salesman problem! NP complete! Well, if you have a big graph any algorithm which actually finds the shortest path is going to be SLOW. However, there are some interesting heuristic algorithms out there which do pretty well. Just google for "travelling salesman" and have fun exploring. -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (3)
-
David Abrahams
-
jfw1000
-
Michael Kettner