Boost logo

Boost :

From: Andrew Brown (ajbrown_at_[hidden])
Date: 2002-11-02 03:16:36


I'm writing a graph program that needs to store arbitrary
attribute:value pairs on each edge and vertex. Reading through the BGL
documentation, it seemed as though this should be easy. I tried the
following:

namespace boost {
    enum vertex_data_t { vertex_data = 100 };
    BOOST_INSTALL_PROPERTY(vertex, data);
    enum edge_data_t { edge_data = 101};
    BOOST_INSTALL_PROPERTY(edge, data);

    typedef associative_property_map< std::map< std::string,
std::string> > apm

    typedef property< vertex_data_t, apm > vertexProperty;
    typedef property< edge_data_t, apm > edgeProperty;

    typedef adjacency_list< // use and adjacency list representation
        listS, // Store out edges of each
node in a std::list
        setS, // Store nodes (vertices)
in a std::set
        directedS, // the graph is directed
        vertexProperty,
        edgeProperty
> FCMGraph;

    typedef graph_traits<FCMGraph>::vertex_descriptor vertex;
    typedef graph_traits<FCMGraph>::edge_descriptor edge;
}

int main(void)
{
    boost::FCMGraph graph;

    boost::vertex v1 = boost::add_vertex(graph);
    boost::vertex v2 = boost::add_vertex(graph);

    boost::edge e;
    bool inserted(false);

    boost::tie(e, inserted) = boost::add_edge(v1,v2, graph);

    vertexProperty

    boost::apm& v1Map = boost::get(boost::vertex_data, graph)[v1];
    boost::apm& v2Map = boost::get(boost::vertex_data, graph)[v2];
    boost::apm& e1Map = boost::get(boost::edge_data, graph)[e];
   
    v1Map[std::string("name")]=std::string("v1");
    v2Map[std::string("name")]=std::string("v2");
    e1Map[std::string("name")]=std::string("e");

    ...
}

This compiles fine, but crashes when run. The problem is that the
container in associate_property_map<> never gets allocated.

I tried a quick fix of writing my own associative_property_map that
makes sure to initiailize the container in all constructors. This
worked for vertex properties, but did not work for edge properties. As
far as I can tell, it doesn't work with edge properties because they are
stored internally as an auto_ptr.

So my questions are :

1) What is a good way to store an arbitray list of properties with
vertices and edges. The program does not know until run-time what the
attributes it needs to store will be, so I need some sort of expandable,
associative container.

2) If the above code should theoretically work, how can I fix it? I'm
willing to work with BGL developers to solve this, but be forewarned-
this is my first attempt at using BGL.

Thanks,

Andrew Brown


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