Permalink
Browse files

examples: C++11: Some use of range-based for loop.

  • Loading branch information...
murraycu committed May 3, 2016
1 parent bfaddb5 commit 6b7f7b4266242770401eb6740584877982a64212
@@ -56,8 +56,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 (const auto& edge : edges)
add_edge(edge.first, edge.second, G);
graph_traits<Graph>::vertex_iterator ui, ui_end;
@@ -78,9 +78,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 (const auto& vertex : inv_perm)
cout << index_map[vertex] << " ";
cout << endl;
for (size_type c = 0; c != inv_perm.size(); ++c)
@@ -96,9 +95,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 (const auto& vertex : inv_perm)
cout << index_map[vertex] << " ";
cout << endl;
for (size_type c = 0; c != inv_perm.size(); ++c)
@@ -115,9 +113,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 (const auto& vertex : inv_perm)
cout << index_map[vertex] << " ";
cout << endl;
for (size_type c = 0; c != inv_perm.size(); ++c)
@@ -126,12 +126,12 @@ namespace boost
}
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 (const auto& 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 (const auto& 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;
++c;
@@ -159,11 +159,10 @@ 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)
for (const auto& edge : disconnecting_set)
std::
cout << "(" << attr_map[source(*i, g)]["label"] << "," <<
attr_map[target(*i, g)]["label"] << ") ";
cout << "(" << attr_map[source(edge, g)]["label"] << "," <<
attr_map[target(edge, g)]["label"] << ") ";
std::cout << "}." << std::endl;
return EXIT_SUCCESS;
}
@@ -96,9 +96,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 (const auto& vertex : inv_perm)
cout << index_map[vertex] << " ";
cout << endl;
for (size_type c = 0; c != inv_perm.size(); ++c)
@@ -115,9 +114,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 (const auto& vertex : inv_perm)
cout << index_map[vertex] << " ";
cout << endl;
for (size_type c = 0; c != inv_perm.size(); ++c)
@@ -36,13 +36,13 @@ 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 (const auto& 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) {
auto u = source(mst[i], g), v = target(mst[i], g);
for (const auto& edge : mst) {
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");
@@ -76,8 +76,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 (const auto& str : ascii_graph)
std::cout << str << std::endl;
std::cout << std::endl << "Found a matching of size " << matching_size(g, &mate[0]) << std::endl;
@@ -41,10 +41,8 @@ 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 (const auto& vertex : topo_order)
std::cout << tasks[vertex] << std::endl;
return EXIT_SUCCESS;
}
@@ -41,10 +41,8 @@ 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 (const auto& vertex : topo_order)
std::cout << tasks[vertex] << std::endl;
return EXIT_SUCCESS;
}

0 comments on commit 6b7f7b4

Please sign in to comment.