Hi Olivier,
please post an example, which compiles. For example with all
necessary #include directives.
Olivier Tournaire writes:
std::pair< graph_traits<Graph>::edge_descriptor, bool > p = add_edge
(*vertices(g).first, *vertices(g).second, g);
The function vertices returns an iterator range. In my understanding an
iterator range is a pair of iterators [first, second) so that second
can be reached from first with increment operations, _but_ is not part
of the iterator range itself. It could be an iterator like one returned
by the end-function of a stl-vector. It shall not be dereferenced!
Therefore If I alter your code to read the following, everything is ok.
#include <iostream>
#include
#include
#include
#include
#include
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::type capacity = get(edge_capacity,
//g);
//property_map::type rev = get(edge_reverse, g);
add_vertex(g);
add_vertex(g);
graph_traits<Graph>::vertex_iterator v_first, v_second;
v_first = vertices(g).first;
v_second = v_first;
++v_second;
std::pair< graph_traits<Graph>::edge_descriptor, bool > p = add_edge
(*v_first, *v_second, g);
std::pair< graph_traits<Graph>::edge_descriptor, bool > p_reverse =
add_edge(*v_second, *v_first, g);
std::cout << "num_vertices = " << num_vertices(g) << std::endl; // output:
//3!!!!
std::cout << "num_edges = " << num_edges(g) << std::endl; // output: 2
return 0;
}
Yours sincerely,
Eric