mirror of
https://github.com/boostorg/graph.git
synced 2025-05-09 23:14:00 +00:00
examples: C++11: Some use of range-based for loops
This commit is contained in:
parent
4792e04be7
commit
6ebdc2c8fd
@ -57,8 +57,8 @@ int main(int, char*[])
|
||||
Pair(6, 7) }; // g-h
|
||||
|
||||
Graph G(10);
|
||||
for (int i = 0; i < 14; ++i)
|
||||
add_edge(edges[i].first, edges[i].second, G);
|
||||
for (auto const& edge : edges)
|
||||
add_edge(edge.first, edge.second, G);
|
||||
|
||||
graph_traits< Graph >::vertex_iterator ui, ui_end;
|
||||
|
||||
@ -79,8 +79,8 @@ int main(int, char*[])
|
||||
get(vertex_degree, G));
|
||||
cout << "Reverse Cuthill-McKee ordering starting at: " << s << endl;
|
||||
cout << " ";
|
||||
for (auto i = inv_perm.begin(); i != inv_perm.end(); ++i)
|
||||
cout << index_map[*i] << " ";
|
||||
for (auto const& vertex : inv_perm)
|
||||
cout << index_map[vertex] << " ";
|
||||
cout << endl;
|
||||
|
||||
for (size_type c = 0; c != inv_perm.size(); ++c)
|
||||
@ -98,8 +98,8 @@ int main(int, char*[])
|
||||
get(vertex_degree, G));
|
||||
cout << "Reverse Cuthill-McKee ordering starting at: " << s << endl;
|
||||
cout << " ";
|
||||
for (auto i = inv_perm.begin(); i != inv_perm.end(); ++i)
|
||||
cout << index_map[*i] << " ";
|
||||
for (auto const& vertex : inv_perm)
|
||||
cout << index_map[vertex] << " ";
|
||||
cout << endl;
|
||||
|
||||
for (size_type c = 0; c != inv_perm.size(); ++c)
|
||||
@ -118,8 +118,8 @@ int main(int, char*[])
|
||||
|
||||
cout << "Reverse Cuthill-McKee ordering:" << endl;
|
||||
cout << " ";
|
||||
for (auto i = inv_perm.begin(); i != inv_perm.end(); ++i)
|
||||
cout << index_map[*i] << " ";
|
||||
for (auto const& vertex : inv_perm)
|
||||
cout << index_map[vertex] << " ";
|
||||
cout << endl;
|
||||
|
||||
for (size_type c = 0; c != inv_perm.size(); ++c)
|
||||
|
@ -136,13 +136,13 @@ typename graph_traits< VertexListGraph >::degree_size_type edge_connectivity(
|
||||
}
|
||||
|
||||
std::vector< bool > in_S_star(num_vertices(g), false);
|
||||
for (auto si = S_star.begin(); si != S_star.end(); ++si)
|
||||
in_S_star[*si] = true;
|
||||
for (auto const& vertex : S_star.begin())
|
||||
in_S_star[vertex] = true;
|
||||
degree_size_type c = 0;
|
||||
for (auto si = S_star.begin(); si != S_star.end(); ++si)
|
||||
for (auto const& vertex : S_star.begin())
|
||||
{
|
||||
typename graph_traits< VertexListGraph >::out_edge_iterator ei, ei_end;
|
||||
for (boost::tie(ei, ei_end) = out_edges(*si, g); ei != ei_end; ++ei)
|
||||
for (boost::tie(ei, ei_end) = out_edges(vertex, g); ei != ei_end; ++ei)
|
||||
if (!in_S_star[target(*ei, g)])
|
||||
{
|
||||
*disconnecting_set++ = *ei;
|
||||
@ -170,9 +170,9 @@ int main()
|
||||
auto attr_map = get(vertex_attribute, g);
|
||||
|
||||
std::cout << "The disconnecting set is {";
|
||||
for (auto i = disconnecting_set.begin(); i != disconnecting_set.end(); ++i)
|
||||
std::cout << "(" << attr_map[source(*i, g)]["label"] << ","
|
||||
<< attr_map[target(*i, g)]["label"] << ") ";
|
||||
for (auto const& edge : disconnecting_set)
|
||||
std::cout << "(" << attr_map[source(edge, g)]["label"] << ","
|
||||
<< attr_map[target(edge, g)]["label"] << ") ";
|
||||
std::cout << "}." << std::endl;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@ -98,8 +98,8 @@ int main(int, char*[])
|
||||
get(vertex_degree, G), get(vertex_index, G));
|
||||
cout << "King ordering starting at: " << s << endl;
|
||||
cout << " ";
|
||||
for (auto i = inv_perm.begin(); i != inv_perm.end(); ++i)
|
||||
cout << index_map[*i] << " ";
|
||||
for (auto const& vertex : inv_perm)
|
||||
cout << index_map[vertex] << " ";
|
||||
cout << endl;
|
||||
|
||||
for (size_type c = 0; c != inv_perm.size(); ++c)
|
||||
@ -118,8 +118,8 @@ int main(int, char*[])
|
||||
|
||||
cout << "King ordering:" << endl;
|
||||
cout << " ";
|
||||
for (auto i = inv_perm.begin(); i != inv_perm.end(); ++i)
|
||||
cout << index_map[*i] << " ";
|
||||
for (auto const& vertex : inv_perm)
|
||||
cout << index_map[vertex] << " ";
|
||||
cout << endl;
|
||||
|
||||
for (size_type c = 0; c != inv_perm.size(); ++c)
|
||||
|
@ -46,14 +46,14 @@ int main()
|
||||
|
||||
auto weight = get(edge_weight, g);
|
||||
int total_weight = 0;
|
||||
for (size_type e = 0; e < mst.size(); ++e)
|
||||
total_weight += get(weight, mst[e]);
|
||||
for (auto const& edge : mst)
|
||||
total_weight += get(weight, edge);
|
||||
std::cout << "total weight: " << total_weight << std::endl;
|
||||
|
||||
typedef graph_traits< Graph >::vertex_descriptor Vertex;
|
||||
for (size_type i = 0; i < mst.size(); ++i)
|
||||
for (auto const& edge : mst)
|
||||
{
|
||||
auto u = source(mst[i], g), v = target(mst[i], g);
|
||||
auto u = source(edge, g), v = target(edge, g);
|
||||
edge_attr_map[edge(u, v, g_dot).first]["color"] = "black";
|
||||
}
|
||||
std::ofstream out("figs/telephone-mst-kruskal.dot");
|
||||
|
@ -74,8 +74,8 @@ int main()
|
||||
|
||||
std::cout << "In the following graph:" << std::endl << std::endl;
|
||||
|
||||
for (auto itr = ascii_graph.begin(); itr != ascii_graph.end(); ++itr)
|
||||
std::cout << *itr << std::endl;
|
||||
for (auto const& str : ascii_graph)
|
||||
std::cout << str << std::endl;
|
||||
|
||||
std::cout << std::endl
|
||||
<< "Found a matching of size " << matching_size(g, &mate[0])
|
||||
|
@ -28,9 +28,8 @@ int main()
|
||||
topological_sort(g, std::front_inserter(topo_order),
|
||||
vertex_index_map(identity_property_map()));
|
||||
|
||||
int n = 1;
|
||||
for (auto i = topo_order.begin(); i != topo_order.end(); ++i, ++n)
|
||||
std::cout << tasks[*i] << std::endl;
|
||||
for (auto const& vertex : topo_order)
|
||||
std::cout << tasks[vertex] << std::endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@ -35,9 +35,8 @@ int main()
|
||||
topological_sort(g, std::front_inserter(topo_order),
|
||||
vertex_index_map(identity_property_map()));
|
||||
|
||||
int n = 1;
|
||||
for (auto i = topo_order.begin(); i != topo_order.end(); ++i, ++n)
|
||||
std::cout << tasks[*i] << std::endl;
|
||||
for (auto const& vertex : topo_order)
|
||||
std::cout << tasks[vertex] << std::endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user