Boost logo

Boost Users :

From: James Jackson (james.jackson_at_[hidden])
Date: 2008-01-25 04:56:42


Hi,

Thanks for the reply - I'm just trying to work out how this fits with
the example given in interior_property_map.cpp (which compiles and
runs file), where essentially this is done:

enum vertex_first_name_t { vertex_first_name };
namespace boost {
   BOOST_INSTALL_PROPERTY(vertex, first_name);
}

typedef adjacency_list<vecS, vecS, directedS,
       property<vertex_first_name_t, std::string> > MyGraphType;

MyGraphType G(5);

// then for 11 edges:
add_edge(start, end, G);

property_map<MyGraphType, vertex_first_name_t>::type name
       = get(vertex_first_name, G);

boost::put(name, 0, "Jeremy");
boost::put(name, 1, "Rich");
boost::put(name, 2, "Andrew");
boost::put(name, 3, "Jeff");
name[4] = "Kinis";

Of course, the difference here is that in the example names are being
assigned to Vertices, not Edges - is this why there is a difference in
the value assignment method?

Regards,
James.

On 25 Jan 2008, at 05:05, Cromwell Enage wrote:

> --- 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 mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


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