Boost logo

Boost Users :

Subject: Re: [Boost-users] [BGL] dynamic_properties for graph attributes
From: Paul Hilbert (vock_at_[hidden])
Date: 2009-06-06 10:17:32


Andrew Sutton wrote:

>> The adjacency_list class constructor takes a property type for graph
>> attributes. However I could not figure out how to create the appropriate
>> dynamic_property map for graph attributes and - not surprisingly -
>> this subtle detail is left out in the "documentation".
>
>
>
>> Maybe someone can enlighten my path (and those of all people
>> I found asking the same question without getting any responses).
>>
>
> Why is documentation in quotes? I haven't seen this question posted
> before. Maybe you can reference a previous instance.

For example here:
http://www.nabble.com/-BGL--Graph-properties-and-dynamic-properties-
tt3340645.html

Googling intensively for things like "dynamic_property graph properties"
guides you to more hits...

Regarding the "documentation":
Replacing the doc by
<html><body>Browse the sources.</body></html> would have saved me a lot
of time I suppose. I cannot find anything that allows me to search for
definitions like e.g. the one for graph_properties. And everywhere in the
documentation I stumble across terms like property (think * = wildcard)
they are inside sentences like "see xyz for an example of how to create
custom edge/vertex properties" or "A Property Tag is a type used to name or
identify properties that are attached to the vertices and edges of a graph."
Which makes me think the writers mainly forgot to think about graph
attributes and guides me to the following question:

Looking at graphml.hpp I find the following piece of code:
// Output keys
for (dynamic_properties::const_iterator i = dp.begin(); i != dp.end(); ++i)
{
   std::string key_id = "key" + lexical_cast<std::string>(key_count++);
   if (i->second->key() == typeid(Graph))
      vertex_key_ids[i->first] = key_id;
   else if (i->second->key() == typeid(vertex_descriptor))
      vertex_key_ids[i->first] = key_id;
   else if (i->second->key() == typeid(edge_descriptor))
      edge_key_ids[i->first] = key_id;
    else
      continue;
    ...
} ...

for (dynamic_properties::const_iterator i = dp.begin(); i != dp.end(); ++i){
   if (i->second->key() == typeid(Graph))
   {
      out << " <data key=\"" << graph_key_ids[i->first] << "\">"
            << i->second->get_string(g) << "</data>\n";
   }
}

So the first snippet inserts all graph attributes into vertex_key_ids and the
second one outputs graph_key_ids. Can there be anything output? Looks like
totally untested code to me, but correct me on that.

> I believe you can construct property maps over the GraphProperty parameter
> using:
>
> get_property(g) // Where g is your graph object.

I (and g++) can't find a get_property which takes one argument.
The semantically closest I could find is
get_property(adjacency_list& g, GraphPropertyTag);
However this:

typedef boost::property<boost::matching_count_t,int> GProp;
typedef boost::adjacency_list<
 boost::vecS, boost::vecS, boost::undirectedS,
 NumberedNodeProperties, NumberedEdgeProperties, GProp > Graph;
Graph g(connections.begin(), connections.end(), m_NumberedNodes.size());
boost::graph_property<Graph, boost::matching_count_t>::type& graphAttr
= boost::get_property(g, g.m_property);

gives me a
"invalid initialization of reference of type 'int&' from expression of type
 'boost::detail::error_property_not_found'"

I really don't get how to do it right but have to during the next days...
I definitely appreciate your help and am sorry for any offence my rambling
may have produced (I'm just totally depressed trying to implement some-
thing supposedly trivial for 3 days now and not being able to find ANY
example for this in the docs).


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