Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does boost::out_edges( v, g ) in Boost.Graph do?

I am not able to comprehend the documentation for this function, I have seen several times the following

tie (ei,ei_end) = out_edges(*(vi+a),g);

**g**<-graph
**vi**<-beginning vertex of graph
**a**<- a node
**ei and ei_end** <- edge iterators

What does the function return,and what does it do,when could I use?

Can I find all edges from a node for example?

like image 721
LoveMeow Avatar asked Nov 11 '14 20:11

LoveMeow


People also ask

Which data structure is used in Boost Graph Library?

Data Structures The adjacency_matrix class stores edges in a |V| x |V| matrix (where |V| is the number of vertices). The elements of this matrix represent edges in the graph. Adjacency matrix representations are especially suitable for very dense graphs, i.e., those where the number of edges approaches |V|2.


1 Answers

Provides iterators to iterate over the out-going edges of node u from graph g, e.g.:

  typename graph_traits < Graph >::out_edge_iterator ei, ei_end;
  for (boost::tie(ei, ei_end) = out_edges(u, g); ei != ei_end; ++ei) {
    auto source = boost::source ( *ei, g );
    auto target = boost::target ( *ei, g );
    std::cout << "There is an edge from " << source <<  " to " << target << std::endl;
  }

where Graph is your type definition of the graph an g is an instance of that. However, out_edges is only applicable for graphs with directed edges. The opposite of out_edges is in_edges that provides you iterators to compute in-coming edges of a node.

In an undirected graph both out_edges and in_edges will return all the edges connecting to the node in question.

However, more information can be easily found on http://www.boost.org/doc/libs/1_55_0/libs/graph/doc/graph_concepts.html or just in the Boost.Graph examples/tests.

like image 122
sfrehse Avatar answered Jan 04 '23 12:01

sfrehse