[BGL] and dijkstra_shortest_paths...
Hello, sorry, I guess this is a noob question but after struggling along with property definitions etc. I cannot find the problem with my code: I simply can not figure out, why my dijkstra_shortest_paths invocation is not correct... I searched around the net but nothing helped me... Thanks in advance for any suggestions! --------------------------------------------------- #include "boost/config.hpp" #include <iostream> #include <fstream> #include "boost/graph/graph_traits.hpp" #include "boost/graph/adjacency_list.hpp" #include "boost/graph/dijkstra_shortest_paths.hpp" using namespace std; using namespace boost; typedef enum { ePositive, eNegative } EdgeDirection_t; struct EdgeProperties { uint8_t level; uint16_t length; uint8_t angle; EdgeDirection_t direction; }; struct VertexProperties { uint32_t index; uint32_t id; uint8_t level; }; // define type for graph types typedef adjacency_list <vecS , listS, directedS, VertexProperties, EdgeProperties> Graph; int main(int argc, char** argv) { Graph graph; property_map<Graph, uint32_t VertexProperties::*>::type vIndex = get(&VertexProperties::index, graph); property_map<Graph, uint32_t VertexProperties::*>::type vId = get(&VertexProperties::id, graph); property_map<Graph, uint8_t VertexProperties::*>::type vLevel = get(&VertexProperties::level, graph); typedef graph_traits<Graph>::vertex_descriptor Vertex; Vertex v1, v2; v1 = add_vertex(graph); vIndex[v1] = 0; vId[v1] = 1; vLevel[v1] = 1; v2 = add_vertex(graph); vIndex[v2] = 1; vId[v2] = 2; vLevel[v2] = 1; EdgeProperties e1; e1.level = 10; e1.length = 2000; e1.angle = 90; e1.direction = ePositive; add_edge(v1, v2, e1, graph); typedef graph_traits<Graph>::vertex_descriptor VertexDescriptor; std::vector<VertexDescriptor> p(num_vertices(graph)); std::vector<int> d(num_vertices(graph)); // BOTH lines to not work ;( // and I have no clue why... //dijkstra_shortest_paths(graph, v1, predecessor_map(&p[0]).distance_map(&d[0])); dijkstra_shortest_paths(graph, v1, vertex_index_map(vIndex). predecessor_map(&p[0]). weight_map(get(&EdgeProperties::length, graph)). distance_map(&d[0]) ); exit(EXIT_SUCCESS); }
Hello again, Finally I was able to locate (not explain) the "problem": typedef adjacency_list <vecS , listS, directedS, VertexProperties, EdgeProperties> Graph; listS for the VertexList is obviously not working... So I changed it to vecS - but an explanation would be nice... Because even the tutorial says it is okay to use listS or am I wrong? http://www.boost.org/doc/libs/1_35_0/libs/graph/doc/using_adjacency_list.htm... thx anyway :D
On May 23, 2008, at 7:18 AM, Stefan Walkner wrote:
Finally I was able to locate (not explain) the "problem": typedef adjacency_list <vecS , listS, directedS, VertexProperties, EdgeProperties> Graph; listS for the VertexList is obviously not working... So I changed it to vecS - but an explanation would be nice... Because even the tutorial says it is okay to use listS or am I wrong? http://www.boost.org/doc/libs/1_35_0/libs/graph/doc/using_adjacency_list.htm... :choosing-graph-type
Using listS can be a bit tricky... it means that you either have to add a vertex_index_t property to all of the vertices in your graph, which provides a mapping from vertices to a index in the range [0, num_vertices(g)), or you have to create a separate property map that does the same thing. - Doug
participants (2)
-
Doug Gregor
-
Stefan Walkner