Boost logo

Boost Users :

From: Geoff Hilton (geoff.hilton_at_[hidden])
Date: 2008-08-12 18:32:58


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<size_t NumberOfBar>
struct EdgeProperty
{
        EdgeProperty(long double foo = 0):Foo(foo),
Bar(NumberOfBar){}
        long double Foo;
        vector<long long> Bar;
};

template<size_t NumberOfBar>
struct VertexProperty
{
        VertexProperty():Baz(NumberOfBar){}
        vector<pair<long long, long long> > Baz;
};
The visitor:
struct MyVisitor
: public default_dijkstra_visitor
{
        template <typename Vertex, typename Graph>
        void discover_vertex(Vertex u, const Graph& g)
        {
                cout << "discovered " << u << '\n';
        }

        template <typename Edge, typename Graph>
        void tree_edge(Edge e, const Graph& g)
        {
                cout << "tree edge " << e << '\n';
        }

        template <typename Edge, typename Graph>
        void examine_edge(Edge e, const Graph& g)
        {
                cout << "examining edge " << e << '\n';
        }
        template <typename Vertex, typename Graph>
        void finish_vertex(Vertex u, const Graph& g)
        {
                cout << "finishing vertex " << u << endl;
        }
};
The graph typedef:
typedef adjacency_list< vecS, vecS, bidirectionalS,
property<vertex_index_t, unsigned long long, VertexProperty<1> >,
property<edge_index_t, unsigned long long, EdgeProperty<1> > > 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<graph_t, long double EdgeProp::*>::type edge_foo_t =
get(&EdgeProp::foo, mygraph);
        property_map<graph_t, vector<long long> EdgeProp::*>::type edge_bar_t =
get(&EdgeProp::Bar, mygraph);
        property_map<graph_t, vertex_index_t>::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<vertex_descriptor> 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


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