Boost logo

Boost Users :

From: Cromwell Enage (sponage_at_[hidden])
Date: 2008-01-25 00:05:55


--- James Jackson wrote:
> Hi,

Hello!

> I am trying to use the BGL to model a simple
> directed graph with internal edge properties.
> Following the example given in the
> documentation[1], I have done the following
> (with question-irrelevant padding removed):
>
> -------------------------------
> #include <boost/graph/adjacency_list.hpp>
> #include <boost/property_map.hpp>
>
> typedef boost::property<boost::edge_weight_t,
> double> EdgeProperties;
> typedef boost::adjacency_list<boost::vecS,
> boost::vecS,
> boost::directedS, boost::no_property,
> EdgeProperties> NetworkGraph;
> typedef std::pair<int, int> Edge;
>
> NetworkGraph g(5);
> boost::add_edge(0, 1, g);
> boost::add_edge(0, 2, g);
> boost::add_edge(1, 3, g);
> boost::add_edge(2, 3, g);
> boost::add_edge(3, 4, g);
>
> boost::property_map<NetworkGraph,
> boost::edge_weight_t>::type weights
> = boost::get(boost::edge_weight_t(), g);
> weights[0] = 1.0;
> weights[1] = 1.0;
> weights[2] = 1.0;
> weights[3] = 1.0;
> weights[4] = 1.0;
> -------------------------------
>
> Which all looks fairly kosher.

Sorry, it isn't.

Edge maps require edge_descriptors for keys. First,
change your Edge type definition to this:

    typedef NetworkGraph::edge_descriptor Edge;

Then, for adding edges, do the following:

    Edge e;
    bool b;

    boost::tie(e, b) = boost::add_edge(0, 1, g);

    if (b)
    {
        weights[e] = 1.0;
    }

    // etc.

                              HTH,
                              Cromwell D. Enage

      ____________________________________________________________________________________
Never miss a thing. Make Yahoo your home page.
http://www.yahoo.com/r/hs


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