Search code examples
c++boost-graph

Setting edge properties before creating the graph


I'm generating a boost::graph, with some 300k edges. I create the set of edges in a loop, in which I also calculate some properties of the edges. Since I need all edges to create the graph, I don't have access to the edge_descriptors yet. Is there a way to do this without doing another pass over the entire set again? When I create my edges, I use std::pair<int, int>, is this compatible with the descriptors?


Solution

  • If you know the number of vertices(then you can initialize a graph and then you can add edges later).I have no idea how'd you make the graph if you do not know the number of vertices beforehand.

    if you have vertices(i.e. if you make vertex_descriptors as soon as you get a value - for vertex) then you can add edges to the graph using the function boost::add_edge(u,v,the_graph), in the same loop let's say you have the graph and vertex_descriptors like this:

    //Note: this code is just a guideline, i hope you'd be able to take up from here
    typedef typename boost::adjacency_list<boost::listS, boost::vecS,
                                boost::directedS,Vertex_t*> Graph_t;
    
    typedef typename boost::graph_traits<Graph_t>::vertex_descriptor Vd_t;
    

    then

    Graph_t the_graph(Num_vertices);
    Vd_t u,v;
    //assign u,v
    boost::add_edge(u,v,the_graph)