Skip to content

Commit

Permalink
examples: C++11: Some use of range-based for loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
murraycu committed May 10, 2017
1 parent bfaddb5 commit 6b7f7b4
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 39 deletions.
19 changes: 8 additions & 11 deletions example/cuthill_mckee_ordering.cpp
Expand Up @@ -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;

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
15 changes: 7 additions & 8 deletions example/edge-connectivity.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
10 changes: 4 additions & 6 deletions example/king_ordering.cpp
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions example/kruskal-telephone.cpp
Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions example/matching_example.cpp
Expand Up @@ -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;

Expand Down
6 changes: 2 additions & 4 deletions example/topo-sort1.cpp
Expand Up @@ -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;
}
6 changes: 2 additions & 4 deletions example/topo-sort2.cpp
Expand Up @@ -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.