Boost logo

Boost Users :

From: Alejandro Marcos Aragón (aaragon2_at_[hidden])
Date: 2007-02-12 14:21:07


Hi everyone,

I posted this message but I haven't received any response so I decided
to post it again. I am trying to store all the vertices with their
respective distances
from a source within the Dijkstra shortest path algorithm. For that I
plan to use a std::vector<std::queue > >. I was able to have the visitor
working but I don't know how to access to those values that are computed
automatically by the algorithm (d_v, d_u, for example). The code I wrote
is as follows:

template <class Tag>
struct vis : public default_dijkstra_visitor
{
    vis() { }

    template <class Edge, class Graph>
    void edge_relaxed(Edge e, Graph& g){
        cout<<"VISITOR!!!"<<endl;
        cout<<"Edge -> "<<e<<endl;
    }

private:

    std::vector<std::queue<Vertex> > storage;

};

template <class Tag>
vis<Tag> target_visit(Tag) {
    return vis<Tag>();
}

void Dijkstra()
{
     // maps needed by the algorithm
    IndexMap indexmap = get(vertex_index, *gPtr);
    WeightMap weightmap = get(edge_weight, *gPtr);

    // define containers for the predecessor vertices and
    // for distances
    std::vector<Vertex> pred(num_vertices(*gPtr));
    std::vector<double> dist(num_vertices(*gPtr));

    // vertex to compute Dijkstra's algorithm on
    Vertex source = vertex(get_source(), *gPtr);

    // Dijkstra's algorithm
    dijkstra_shortest_paths(*gPtr, source,
predecessor_map(&pred[0]).distance_map(&dist[0]).visitor(target_visit(on_examine_edge())));

...

Any help will be appreciated.

a^2


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