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