|
Boost Users : |
From: Stefan Walkner (swalkner_at_[hidden])
Date: 2008-05-21 17:51:46
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);
}
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net