Boost logo

Boost :

From: Jeremy Siek (jsiek_at_[hidden])
Date: 2002-11-02 18:33:11


Hi Andrew,

You don't need the associative_property_map for what you are doing. Just
use a std::map instead. Like this:

typedef property<vertex_data_t, std::map<std::string, std::string> >
  VertexProperty;

The associative_property_map is for creating external property maps, and
you're trying to use at as the value_type of an internal property map.

Regards,
Jeremy

On Sat, 2 Nov 2002, Andrew Brown wrote:
ajbrow> I'm writing a graph program that needs to store arbitrary
ajbrow> attribute:value pairs on each edge and vertex. Reading through
ajbrow> the BGL documentation, it seemed as though this should be easy.
ajbrow> I tried the following:
ajbrow>
ajbrow> namespace boost {
ajbrow> enum vertex_data_t { vertex_data = 100 };
ajbrow> BOOST_INSTALL_PROPERTY(vertex, data);
ajbrow> enum edge_data_t { edge_data = 101};
ajbrow> BOOST_INSTALL_PROPERTY(edge, data);
ajbrow>
ajbrow> typedef associative_property_map< std::map< std::string,
ajbrow> std::string> > apm
ajbrow>
ajbrow> typedef property< vertex_data_t, apm > vertexProperty;
ajbrow> typedef property< edge_data_t, apm > edgeProperty;
ajbrow>
ajbrow> typedef adjacency_list< // use and adjacency list representation
ajbrow> listS, // Store out edges of each
ajbrow> node in a std::list
ajbrow> setS, // Store nodes (vertices)
ajbrow> in a std::set
ajbrow> directedS, // the graph is directed
ajbrow> vertexProperty,
ajbrow> edgeProperty
ajbrow> > FCMGraph;
ajbrow>
ajbrow> typedef graph_traits<FCMGraph>::vertex_descriptor vertex;
ajbrow> typedef graph_traits<FCMGraph>::edge_descriptor edge;
ajbrow> }
ajbrow>
ajbrow> int main(void)
ajbrow> {
ajbrow> boost::FCMGraph graph;
ajbrow>
ajbrow> boost::vertex v1 = boost::add_vertex(graph);
ajbrow> boost::vertex v2 = boost::add_vertex(graph);
ajbrow>
ajbrow> boost::edge e;
ajbrow> bool inserted(false);
ajbrow>
ajbrow> boost::tie(e, inserted) = boost::add_edge(v1,v2, graph);
ajbrow>
ajbrow> vertexProperty
ajbrow>
ajbrow> boost::apm& v1Map = boost::get(boost::vertex_data, graph)[v1];
ajbrow> boost::apm& v2Map = boost::get(boost::vertex_data, graph)[v2];
ajbrow> boost::apm& e1Map = boost::get(boost::edge_data, graph)[e];
ajbrow>
ajbrow> v1Map[std::string("name")]=std::string("v1");
ajbrow> v2Map[std::string("name")]=std::string("v2");
ajbrow> e1Map[std::string("name")]=std::string("e");
ajbrow>
ajbrow> ...
ajbrow> }
ajbrow>
ajbrow> This compiles fine, but crashes when run. The problem is that the
ajbrow> container in associate_property_map<> never gets allocated.
ajbrow>
ajbrow> I tried a quick fix of writing my own associative_property_map that
ajbrow> makes sure to initiailize the container in all constructors. This
ajbrow> worked for vertex properties, but did not work for edge properties. As
ajbrow> far as I can tell, it doesn't work with edge properties because they are
ajbrow> stored internally as an auto_ptr.
ajbrow>
ajbrow> So my questions are :
ajbrow>
ajbrow> 1) What is a good way to store an arbitray list of properties with
ajbrow> vertices and edges. The program does not know until run-time what the
ajbrow> attributes it needs to store will be, so I need some sort of expandable,
ajbrow> associative container.
ajbrow>
ajbrow> 2) If the above code should theoretically work, how can I fix it? I'm
ajbrow> willing to work with BGL developers to solve this, but be forewarned-
ajbrow> this is my first attempt at using BGL.
ajbrow>
ajbrow>
ajbrow> Thanks,
ajbrow>
ajbrow> Andrew Brown
ajbrow>
ajbrow>
ajbrow>
ajbrow>
ajbrow>
ajbrow> _______________________________________________
ajbrow> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
ajbrow>

----------------------------------------------------------------------
 Jeremy Siek http://php.indiana.edu/~jsiek/
 Ph.D. Student, Indiana Univ. B'ton email: jsiek_at_[hidden]
 C++ Booster (http://www.boost.org) office phone: (812) 855-3608
----------------------------------------------------------------------


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk