Hmm, maybe if I add some extra information someone will be better able to answer... The basic premise is that I want the dijkstra algorithm to iterate through the Bar weights making its comparisons as it would were it only a POD (ie, as if it were using Foo instead). I've been reading the mailing list, online documentation and examples all day while trying different things, but I can't get it working. :| I also tried this (weightMap is a local variable in main()): dijkstra_shortest_paths(mygraph, *vi, weight_map( make_iterator_property_map(weightMap.begin(), get(edge_index, mygraph) ) ) .distance_map( make_iterator_property_map(distances.begin(), vertex_ind) ) .predecessor_map( make_iterator_property_map(predecessors.begin(), vertex_ind)) .visitor(vis) ); This compiles (with warnings).. and runs without issue... but what I want is to point it towards the Bar member in my EdgeProperty struct. Is it just a syntax issue? What is it I should alter? Thanks again, Geoff Geoff Hilton wrote:
Hi, I'm new to the boost and the BGL, and as the subject suggests, I'm trying to get my property bundle-using adjacency list to use a vector for its WeightMap.
First off, the property bundles in question:
template
struct EdgeProperty { EdgeProperty(long double foo = 0):Foo(foo), Bar(NumberOfBar){} long double Foo; vector<long long> Bar; }; template
struct VertexProperty { VertexProperty():Baz(NumberOfBar){} vector > Baz; }; The visitor: struct MyVisitor : public default_dijkstra_visitor { template void discover_vertex(Vertex u, const Graph& g) { cout << "discovered " << u << '\n'; } template
void tree_edge(Edge e, const Graph& g) { cout << "tree edge " << e << '\n'; } template
void examine_edge(Edge e, const Graph& g) { cout << "examining edge " << e << '\n'; } template void finish_vertex(Vertex u, const Graph& g) { cout << "finishing vertex " << u << endl; } }; The graph typedef: typedef adjacency_list< vecS, vecS, bidirectionalS, property >, property > > graph_t; Adding edges and vertices to the graph works without issue, as does assigning values to the properties, and navigating it, I was also able to get my test visitor to work.. using this code:
int _tmain(int argc, _TCHAR* argv[]) { graph_t mygraph; //build graph //... //set up property accessors typedef EdgeProperty<1> EdgeProp; property_map
::type edge_foo_t = get(&EdgeProp::foo, mygraph); property_map ::type edge_bar_t = get(&EdgeProp::Bar, mygraph); property_map ::type vertex_ind = get(vertex_index, mygraph); //dijkstra stuff size_t numberOfVertices = num_vertices(mygraph); std::vector<long double> distances(numberOfVertices, (numeric_limits<long double>::max)()); vector predecessors(numberOfVertices); MyVisitor vis; dijkstra_shortest_paths(mygraph, *vi, weight_map(edge_foo_t) .weight_map2(edge_bar_t) .distance_map( make_iterator_property_map(distances.begin(), vertex_ind) ) .predecessor_map( make_iterator_property_map(predecessors.begin(), vertex_ind) ) .visitor(vis) ); return 0; }
However when I switch edge_bar_t and edge_foo_t within the weight_map/weight_map2 parentheses, I get this error (Visual Studio 2005) 'bool std::less<_Ty>::operator ()(const _Ty &,const _Ty &) const' : cannot convert parameter 1 from 'std::vector<_Ty>' to 'const D &'
Of course that's normal because it's a vector. I figure I'm supposed to use make_iterator_property_map and somehow point it to &EdgeProp::Bar::begin() (or &EdgeProp::Bar::rbegin()) with a property_map<...> as I did with the others...but what I've tried so far hasn't worked.
Any ideas?
Thanks very much and best wishes, Geoff