Boost logo

Boost Users :

Subject: [Boost-users] [BGL] add_edge also adds a vertex
From: Olivier Tournaire (olitour_at_[hidden])
Date: 2010-02-07 03:16:32


Hi all,

I am facing a problem with BGL. Here is a minimal piece of code which
reproduces the problem

using namespace boost;
typedef adjacency_list_traits < vecS, vecS, directedS > Traits;
typedef adjacency_list < vecS, vecS, directedS,
property < vertex_index_t, long,
property < vertex_color_t, boost::default_color_type,
property < vertex_distance_t, long,
property < vertex_potential_t, long, // stores the unary energy associated
to each vertex
property < vertex_predecessor_t, Traits::edge_descriptor > > > > >,
property < edge_capacity_t, long, // stores the binary energy associated to
each edge
property < edge_residual_capacity_t, long,
property < edge_reverse_t, Traits::edge_descriptor > > > > Graph;

int main(int argc, char** argv)
{
    Graph g;

    //property_map<Graph, edge_capacity_t>::type capacity =
get(edge_capacity, g);
    //property_map<Graph, edge_reverse_t>::type rev = get(edge_reverse, g);

    add_vertex(g);
    add_vertex(g);

    std::pair< graph_traits<Graph>::edge_descriptor, bool > p =
add_edge(*vertices(g).first, *vertices(g).second, g);
    std::pair< graph_traits<Graph>::edge_descriptor, bool > p_reverse =
add_edge(*vertices(g).second, *vertices(g).first, g);

    std::cout << "num_vertices = " << num_vertices(g) << std::endl; //
output: 3!!!!
    std::cout << "num_edges = " << num_edges(g) << std::endl; // output: 2
    long flow = kolmogorov_max_flow(g , *vertices(g).first,
*vertices(g).second); // crashes ...

    return 0;
}

So, I add 2 vertices in my graph, insert 2 edges between these vertices, and
I finally have 3 vertices in my graph. What am I doing wrong?
I am on a 32 bit Ubuntu box, with g++ 4.3.4 and boost 1.40

Best regards,

Olivier

-----------------------------------------------------
Olivier Tournaire
MATIS - Institut Géographique National
73, Ave de Paris
94165 St Mandé cedex, France

tel: (+33) 1 43 98 84 29
fax: (+33) 1 43 98 85 81



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