mirror of
https://github.com/boostorg/graph.git
synced 2026-01-19 04:12:11 +00:00
@@ -214,12 +214,12 @@ example, the following code will result in undefined (bad) behavior:
|
||||
|
||||
<b>// Attempt to remove all the vertices. Wrong!</b>
|
||||
graph_traits<Graph>::vertex_iterator vi, vi_end;
|
||||
for (tie(vi, vi_end) = vertices(G); vi != vi_end; ++vi)
|
||||
for (boost::tie(vi, vi_end) = vertices(G); vi != vi_end; ++vi)
|
||||
remove_vertex(*vi, G);
|
||||
|
||||
<b>// Remove all the vertices. This is still wrong!</b>
|
||||
graph_traits<Graph>::vertex_iterator vi, vi_end, next;
|
||||
tie(vi, vi_end) = vertices(G);
|
||||
boost::tie(vi, vi_end) = vertices(G);
|
||||
for (next = vi; vi != vi_end; vi = next) {
|
||||
++next;
|
||||
remove_vertex(*vi, G);
|
||||
@@ -247,12 +247,12 @@ actual vertex that was removed. The following code demonstrates this.
|
||||
|
||||
<b>// Attempt to remove all the vertices. Wrong!</b>
|
||||
graph_traits<Graph>::vertex_iterator vi, vi_end;
|
||||
for (tie(vi, vi_end) = vertices(G); vi != vi_end; ++vi)
|
||||
for (boost::tie(vi, vi_end) = vertices(G); vi != vi_end; ++vi)
|
||||
remove_vertex(*vi, G);
|
||||
|
||||
<b>// Remove all the vertices. This is OK.</b>
|
||||
graph_traits<Graph>::vertex_iterator vi, vi_end, next;
|
||||
tie(vi, vi_end) = vertices(G);
|
||||
boost::tie(vi, vi_end) = vertices(G);
|
||||
for (next = vi; vi != vi_end; vi = next) {
|
||||
++next;
|
||||
remove_vertex(*vi, G);
|
||||
@@ -281,7 +281,7 @@ vertex descriptors have become invalid, the result is incorrect.
|
||||
remove_vertex(s, G); <b>// Bad idea! Invalidates vertex descriptors in parent vector.</b>
|
||||
|
||||
<b>// The following will produce incorrect results</b>
|
||||
for(tie(vi, vend) = vertices(G); vi != vend; ++vi)
|
||||
for(boost::tie(vi, vend) = vertices(G); vi != vend; ++vi)
|
||||
std::cout << p[*vi] << " is the parent of " << *vi << std::endl;
|
||||
</pre>
|
||||
|
||||
|
||||
@@ -338,8 +338,8 @@ main()
|
||||
std::cout << "c flow values:" << std::endl;
|
||||
graph_traits < Graph >::vertex_iterator u_iter, u_end;
|
||||
graph_traits < Graph >::out_edge_iterator ei, e_end;
|
||||
for (tie(u_iter, u_end) = vertices(g); u_iter != u_end; ++u_iter)
|
||||
for (tie(ei, e_end) = out_edges(*u_iter, g); ei != e_end; ++ei)
|
||||
for (boost::tie(u_iter, u_end) = vertices(g); u_iter != u_end; ++u_iter)
|
||||
for (boost::tie(ei, e_end) = out_edges(*u_iter, g); ei != e_end; ++ei)
|
||||
if (capacity[*ei] > 0)
|
||||
std::cout << "f " << *u_iter << " " << target(*ei, g) << " "
|
||||
<< (capacity[*ei] - residual_capacity[*ei]) << std::endl;
|
||||
|
||||
@@ -134,7 +134,7 @@ namespace boost {
|
||||
mark(V, numeric_limits_max(max_color));
|
||||
|
||||
typename GraphTraits::vertex_iterator v, vend;
|
||||
for (tie(v, vend) = vertices(G); v != vend; ++v)
|
||||
for (boost::tie(v, vend) = vertices(G); v != vend; ++v)
|
||||
color[*v] = V - 1; // which means "not colored"
|
||||
|
||||
for (size_type i = 0; i < V; i++) {
|
||||
@@ -142,7 +142,7 @@ namespace boost {
|
||||
|
||||
// mark all the colors of the adjacent vertices
|
||||
typename GraphTraits::adjacency_iterator ai, aend;
|
||||
for (tie(ai, aend) = adjacent_vertices(current, G); ai != aend; ++ai)
|
||||
for (boost::tie(ai, aend) = adjacent_vertices(current, G); ai != aend; ++ai)
|
||||
mark[color[*ai]] = i;
|
||||
|
||||
// find the smallest color unused by the adjacent vertices
|
||||
|
||||
@@ -115,7 +115,7 @@ library. OO was hip in the 80s and 90s, but its time we moved beyond!
|
||||
// initialize the vertex_index property values
|
||||
graph_traits<graph_t>::vertex_iterator vi, vend;
|
||||
graph_traits<graph_t>::vertices_size_type cnt = 0;
|
||||
for(tie(vi,vend) = vertices(G); vi != vend; ++vi)
|
||||
for(boost::tie(vi,vend) = vertices(G); vi != vend; ++vi)
|
||||
put(index, *vi, cnt++);
|
||||
</pre>
|
||||
</li>
|
||||
|
||||
@@ -233,7 +233,7 @@ it depends on.
|
||||
if (in_degree (*i, g) > 0) {
|
||||
Graph::in_edge_iterator j, j_end;
|
||||
int maxdist = 0;
|
||||
for (tie(j, j_end) = in_edges(*i, g); j != j_end; ++j)
|
||||
for (boost::tie(j, j_end) = in_edges(*i, g); j != j_end; ++j)
|
||||
maxdist = std::max(time[source(*j, g)], maxdist);
|
||||
time[*i]=maxdist+1;
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ namespace boost {
|
||||
const size_type num = num_vertices(G);
|
||||
|
||||
typename GraphTraits::vertex_iterator v, vend;
|
||||
for (tie(v, vend) = vertices(G); v != vend; ++v) {
|
||||
for (boost::tie(v, vend) = vertices(G); v != vend; ++v) {
|
||||
put(marker, *v, num);
|
||||
put(degree, *v, out_degree(*v, G));
|
||||
degree_buckets.push(*v);
|
||||
@@ -152,7 +152,7 @@ namespace boost {
|
||||
put(marker, node, 0); //node has been ordered.
|
||||
|
||||
typename GraphTraits::adjacency_iterator v, vend;
|
||||
for (tie(v,vend) = adjacent_vertices(node, G); v != vend; ++v)
|
||||
for (boost::tie(v,vend) = adjacent_vertices(node, G); v != vend; ++v)
|
||||
|
||||
if ( get(marker, *v) > current_order ) { //*v is unordered vertex
|
||||
put(marker, *v, current_order); //mark the columns adjacent to node
|
||||
|
||||
@@ -408,7 +408,7 @@ href="../example/undirected_adjacency_list.cpp"><TT>example/undirected_adjacency
|
||||
boost::graph_traits<UndirectedGraph>::out_edge_iterator e, e_end;
|
||||
boost::graph_traits<UndirectedGraph>::vertex_descriptor
|
||||
s = vertex(0, undigraph);
|
||||
for (tie(e, e_end) = out_edges(s, undigraph); e != e_end; ++e)
|
||||
for (boost::tie(e, e_end) = out_edges(s, undigraph); e != e_end; ++e)
|
||||
std::cout << "(" << source(*e, undigraph)
|
||||
<< "," << target(*e, undigraph) << ")" << endl;
|
||||
</PRE>
|
||||
@@ -447,8 +447,8 @@ of <i>(v,u)</i> since they are the same edge.
|
||||
add_edge(digraph, v, u, Weight(2.4));
|
||||
boost::graph_traits<DirectedGraph>::edge_descriptor e1, e2;
|
||||
bool found;
|
||||
tie(e1, found) = edge(u, v, digraph);
|
||||
tie(e2, found) = edge(v, u, digraph);
|
||||
boost::tie(e1, found) = edge(u, v, digraph);
|
||||
boost::tie(e2, found) = edge(v, u, digraph);
|
||||
std::cout << "in a directed graph is ";
|
||||
std::cout << "(u,v) == (v,u) ? " << (e1 == e2) << std::endl;
|
||||
|
||||
@@ -464,8 +464,8 @@ of <i>(v,u)</i> since they are the same edge.
|
||||
add_edge(undigraph, u, v, Weight(3.1));
|
||||
boost::graph_traits<UndirectedGraph>::edge_descriptor e1, e2;
|
||||
bool found;
|
||||
tie(e1, found) = edge(u, v, undigraph);
|
||||
tie(e2, found) = edge(v, u, undigraph);
|
||||
boost::tie(e1, found) = edge(u, v, undigraph);
|
||||
boost::tie(e2, found) = edge(v, u, undigraph);
|
||||
std::cout << "in an undirected graph is ";
|
||||
std::cout << "(u,v) == (v,u) ? " << (e1 == e2) << std::endl;
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ is the target. This function is equivalent to the expression
|
||||
edge_descriptor e;
|
||||
vertex_descriptor u, v;
|
||||
...
|
||||
tie(u, v) = incident(e, g);
|
||||
boost::tie(u, v) = incident(e, g);
|
||||
</pre>
|
||||
|
||||
|
||||
|
||||
@@ -156,7 +156,7 @@ descriptor from the map's <TT>pos</TT> iterator.
|
||||
tokenizer<>::iterator i = line_toks.begin();
|
||||
std::string actors_name = *i++;
|
||||
|
||||
tie(pos, inserted) = actors.insert(std::make_pair(actors_name, Vertex()));
|
||||
boost::tie(pos, inserted) = actors.insert(std::make_pair(actors_name, Vertex()));
|
||||
if (inserted) {
|
||||
u = add_vertex(g);
|
||||
actor_name[u] = actors_name;
|
||||
@@ -174,7 +174,7 @@ actor into the graph.
|
||||
<PRE>
|
||||
std::string movie_name = *i++;
|
||||
|
||||
tie(pos, inserted) = actors.insert(std::make_pair(*i, Vertex()));
|
||||
boost::tie(pos, inserted) = actors.insert(std::make_pair(*i, Vertex()));
|
||||
if (inserted) {
|
||||
v = add_vertex(g);
|
||||
actor_name[v] = *i;
|
||||
@@ -190,7 +190,7 @@ the name of the connecting movie.
|
||||
<P>
|
||||
<PRE>
|
||||
graph_traits<Graph>::edge_descriptor e;
|
||||
tie(e, inserted) = add_edge(u, v, g);
|
||||
boost::tie(e, inserted) = add_edge(u, v, g);
|
||||
if (inserted)
|
||||
connecting_movie[e] = movie_name;
|
||||
</PRE>
|
||||
|
||||
@@ -56,7 +56,7 @@ target, then this function returns the source vertex.
|
||||
edge_descriptor e;
|
||||
...
|
||||
vertex_descriptor u, v;
|
||||
tie(u, v) = incident(e, g);
|
||||
boost::tie(u, v) = incident(e, g);
|
||||
assert(v == opposite(e, u, g));
|
||||
assert(u == opposite(e, v, g));
|
||||
</pre>
|
||||
|
||||
@@ -196,8 +196,8 @@ main()
|
||||
std::cout << "c flow values:" << std::endl;
|
||||
graph_traits<Graph>::vertex_iterator u_iter, u_end;
|
||||
graph_traits<Graph>::out_edge_iterator ei, e_end;
|
||||
for (tie(u_iter, u_end) = vertices(g); u_iter != u_end; ++u_iter)
|
||||
for (tie(ei, e_end) = out_edges(*u_iter, g); ei != e_end; ++ei)
|
||||
for (boost::tie(u_iter, u_end) = vertices(g); u_iter != u_end; ++u_iter)
|
||||
for (boost::tie(ei, e_end) = out_edges(*u_iter, g); ei != e_end; ++ei)
|
||||
if (capacity[*ei] > 0)
|
||||
std::cout << "f " << *u_iter << " " << target(*ei, g) << " "
|
||||
<< (capacity[*ei] - residual_capacity[*ei]) << std::endl;
|
||||
|
||||
@@ -187,7 +187,7 @@ but in this case the iterators are <i>edge iterators</i>. Dereferencing an edge
|
||||
iterator gives an edge object. The <tt>source()</tt> and <tt>target()</tt>
|
||||
functions return the two vertices that are connected by the edge. Instead of
|
||||
explicitly creating a <tt>std::pair</tt> for the iterators, this time we will
|
||||
use the <a href="../../tuple/doc/tuple_users_guide.html#tiers"><tt>tie()</tt></a> helper function.
|
||||
use the <a href="../../tuple/doc/tuple_users_guide.html#tiers"><tt>boost::tie()</tt></a> helper function.
|
||||
This handy function can be used to assign the parts of a <tt>std::pair</tt> into
|
||||
two separate variables, in this case <tt>ei</tt> and <tt>ei_end</tt>. This is
|
||||
usually more convenient than creating a <tt>std::pair</tt> and is our method of
|
||||
@@ -200,7 +200,7 @@ choice for the BGL.
|
||||
// ...
|
||||
std::cout << "edges(g) = ";
|
||||
graph_traits<Graph>::edge_iterator ei, ei_end;
|
||||
for (tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
|
||||
for (boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
|
||||
std::cout << "(" << index[source(*ei, g)]
|
||||
<< "," << index[target(*ei, g)] << ") ";
|
||||
std::cout << std::endl;
|
||||
@@ -303,7 +303,7 @@ out-edge of vertex <tt>v</tt>.
|
||||
std::cout << "out-edges: ";
|
||||
typename GraphTraits::out_edge_iterator out_i, out_end;
|
||||
typename GraphTraits::edge_descriptor e;
|
||||
for (tie(out_i, out_end) = out_edges(v, g);
|
||||
for (boost::tie(out_i, out_end) = out_edges(v, g);
|
||||
out_i != out_end; ++out_i) {
|
||||
e = *out_i;
|
||||
Vertex src = source(e, g), targ = target(e, g);
|
||||
@@ -337,7 +337,7 @@ specified instead of <tt>directedS</tt>.
|
||||
std::cout << "in-edges: ";
|
||||
typedef typename graph_traits<Graph> GraphTraits;
|
||||
typename GraphTraits::in_edge_iterator in_i, in_end;
|
||||
for (tie(in_i, in_end) = in_edges(v,g);
|
||||
for (boost::tie(in_i, in_end) = in_edges(v,g);
|
||||
in_i != in_end; ++in_i) {
|
||||
e = *in_i;
|
||||
Vertex src = source(e, g), targ = target(e, g);
|
||||
@@ -373,7 +373,7 @@ descriptor for an adjacent vertex.
|
||||
std::cout << "adjacent vertices: ";
|
||||
typename graph_traits<Graph>::adjacency_iterator ai;
|
||||
typename graph_traits<Graph>::adjacency_iterator ai_end;
|
||||
for (tie(ai, ai_end) = adjacent_vertices(v, g);
|
||||
for (boost::tie(ai, ai_end) = adjacent_vertices(v, g);
|
||||
ai != ai_end; ++ai)
|
||||
std::cout << index[*ai] << " ";
|
||||
std::cout << std::endl;
|
||||
|
||||
@@ -143,7 +143,7 @@ namespace boost {
|
||||
rcm_queue<Vertex, Degree> Q(degree);
|
||||
|
||||
typename boost::graph_traits<Graph>::vertex_iterator ui, ui_end;
|
||||
for (tie(ui, ui_end) = vertices(G); ui != ui_end; ++ui)
|
||||
for (boost::tie(ui, ui_end) = vertices(G); ui != ui_end; ++ui)
|
||||
put(color, *ui, white(c));
|
||||
breadth_first_search(G, u, Q, bfs_visitor<>(), color);
|
||||
|
||||
@@ -214,7 +214,7 @@ from BGL can be reused.
|
||||
CMVisitor cm_visitor(inverse_permutation);
|
||||
|
||||
typename boost::graph_traits<Graph>::vertex_iterator ui, ui_end;
|
||||
for (tie(ui, ui_end) = vertices(G); ui != ui_end; ++ui)
|
||||
for (boost::tie(ui, ui_end) = vertices(G); ui != ui_end; ++ui)
|
||||
put(color, *ui, white(c));
|
||||
breadth_first_search(G, s, Q, cm_visitor, color);
|
||||
}
|
||||
|
||||
@@ -116,11 +116,11 @@ int main(int,char*[])
|
||||
Graph g(used_by, used_by + nedges, N);
|
||||
|
||||
graph_traits<Graph>::vertex_iterator v, v_end;
|
||||
for (tie(v,v_end) = vertices(g); v != v_end; ++v)
|
||||
for (boost::tie(v,v_end) = vertices(g); v != v_end; ++v)
|
||||
put(vertex_color_t(), g, *v, name[*v]);
|
||||
|
||||
graph_traits<Graph>::edge_iterator e, e_end;
|
||||
for (tie(e,e_end) = edges(g); e != e_end; ++e)
|
||||
for (boost::tie(e,e_end) = edges(g); e != e_end; ++e)
|
||||
put(edge_weight_t(), g, *e, 3);
|
||||
|
||||
dynamic_properties dp;
|
||||
|
||||
Reference in New Issue
Block a user