Permalink
Browse files

examples: C++11: Use auto.

  • Loading branch information...
murraycu committed May 3, 2016
1 parent 538a915 commit bfaddb5867a1f3e8596335af10c6a4dd92e87cab
Showing with 286 additions and 389 deletions.
  1. +4 −6 example/accum-compile-times.cpp
  2. +8 −10 example/actor_clustering.cpp
  3. +2 −4 example/adjacency_list.cpp
  4. +7 −7 example/astar-cities.cpp
  5. +8 −8 example/astar_maze.cpp
  6. +4 −7 example/bellman-example.cpp
  7. +1 −1 example/bfs-example2.cpp
  8. +8 −9 example/bfs-name-printer.cpp
  9. +1 −1 example/bfs.cpp
  10. +1 −1 example/bfs_neighbor.cpp
  11. +2 −3 example/biconnected_components.cpp
  12. +7 −7 example/boost_web_graph.cpp
  13. +4 −6 example/boykov_kolmogorov-eg.cpp
  14. +1 −1 example/bron_kerbosch_clique_number.cpp
  15. +4 −4 example/bucket_sorter.cpp
  16. +3 −4 example/canonical_ordering.cpp
  17. +1 −2 example/cc-internet.cpp
  18. +1 −2 example/city_visitor.cpp
  19. +1 −1 example/clustering_coefficient.cpp
  20. +1 −1 example/connected-components.cpp
  21. +1 −1 example/connected_components.cpp
  22. +1 −2 example/copy-example.cpp
  23. +7 −8 example/cuthill_mckee_ordering.cpp
  24. +1 −1 example/cycle_canceling_example.cpp
  25. +8 −8 example/cycle_ratio_example.cpp
  26. +2 −3 example/dag_shortest_paths.cpp
  27. +1 −2 example/dave.cpp
  28. +8 −11 example/dijkstra-example-listS.cpp
  29. +4 −5 example/dijkstra-example.cpp
  30. +3 −4 example/dijkstra-no-color-map-example.cpp
  31. +2 −2 example/directed_graph.cpp
  32. +9 −16 example/edge-connectivity.cpp
  33. +3 −3 example/edge-function.cpp
  34. +2 −2 example/edge_basics.cpp
  35. +1 −1 example/edge_connectivity.cpp
  36. +1 −1 example/edge_iterator_constructor.cpp
  37. +2 −4 example/edge_property.cpp
  38. +3 −5 example/edmonds-karp-eg.cpp
  39. +3 −4 example/family_tree.cpp
  40. +1 −2 example/filtered-copy-example.cpp
  41. +3 −4 example/filtered_graph_edge_range.cpp
  42. +4 −4 example/gerdemann.cpp
  43. +2 −2 example/girth.cpp
  44. +4 −8 example/graph-thingie.cpp
  45. +2 −3 example/graph_as_tree.cpp
  46. +1 −1 example/grid_graph_properties.cpp
  47. +1 −5 example/hawick_circuits.cpp
  48. +1 −1 example/implicit_graph.cpp
  49. +1 −1 example/influence_prestige.cpp
  50. +1 −1 example/interior_property_map.cpp
  51. +1 −2 example/iteration_macros.cpp
  52. +1 −1 example/johnson-eg.cpp
  53. +2 −4 example/kevin-bacon.cpp
  54. +1 −1 example/kevin-bacon2.cpp
  55. +6 −7 example/king_ordering.cpp
  56. +3 −3 example/kruskal-example.cpp
  57. +4 −6 example/kruskal-telephone.cpp
  58. +1 −1 example/kuratowski_subgraph.cpp
  59. +2 −3 example/last-mod-time.cpp
  60. +1 −1 example/leda-graph-eg.cpp
  61. +8 −8 example/loops_dfs.cpp
  62. +1 −1 example/make_biconnected_planar.cpp
  63. +1 −1 example/make_maximal_planar.cpp
  64. +2 −2 example/matching_example.cpp
  65. +3 −6 example/max_flow.cpp
  66. +2 −4 example/mcgregor_subgraphs_example.cpp
  67. +1 −1 example/mean_geodesic.cpp
  68. +2 −4 example/miles_span.cpp
  69. +2 −2 example/min_max_paths.cpp
  70. +1 −2 example/minimum_degree_ordering.cpp
  71. +1 −2 example/modify_graph.cpp
  72. +2 −4 example/neighbor_bfs.cpp
  73. +2 −2 example/ordered_out_edges.cpp
  74. +3 −3 example/ospf-example.cpp
  75. +1 −1 example/planar_face_traversal.cpp
  76. +3 −3 example/prim-example.cpp
  77. +4 −5 example/prim-telephone.cpp
  78. +1 −2 example/property-map-traits-eg.cpp
  79. +2 −4 example/property_iterator.cpp
  80. +4 −6 example/push-relabel-eg.cpp
  81. +3 −5 example/quick-tour.cpp
  82. +3 −4 example/quick_tour.cpp
  83. +3 −4 example/reachable-loop-head.cpp
  84. +2 −3 example/reachable-loop-tail.cpp
  85. +3 −6 example/read_graphviz.cpp
  86. +5 −7 example/read_write_dimacs-eg.cpp
  87. +2 −2 example/remove_edge_if_bidir.cpp
  88. +1 −1 example/remove_edge_if_undir.cpp
  89. +4 −6 example/roget_components.cpp
  90. +1 −2 example/scc.cpp
  91. +4 −4 example/sloan_ordering.cpp
  92. +1 −2 example/strong-components.cpp
  93. +3 −3 example/subgraph_properties.cpp
  94. +1 −1 example/successive_shortest_path_nonnegative_weights_example.cpp
  95. +1 −2 example/tiernan_print_cycles.cpp
  96. +1 −1 example/topo-sort-with-leda.cpp
  97. +1 −1 example/topo-sort-with-sgb.cpp
  98. +1 −1 example/topo-sort1.cpp
  99. +1 −1 example/topo-sort2.cpp
  100. +2 −2 example/topo_sort.cpp
  101. +1 −2 example/transpose-example.cpp
  102. +2 −3 example/two_graphs_common_spanning_trees.cpp
  103. +9 −14 example/undirected_adjacency_list.cpp
  104. +3 −3 example/undirected_graph.cpp
  105. +1 −2 example/vertex-name-property.cpp
  106. +3 −4 example/vertex_basics.cpp
  107. +2 −7 example/vf2_sub_graph_iso_multi_example.cpp
  108. +2 −4 include/boost/graph/bc_clustering.hpp
@@ -69,12 +69,10 @@ main()
file_dep_graph2 g(input_begin, input_end, n_vertices);
#endif
typedef property_map < file_dep_graph2, vertex_name_t >::type name_map_t;
typedef property_map < file_dep_graph2, vertex_compile_cost_t >::type
compile_cost_map_t;
name_map_t name_map = get(vertex_name, g);
compile_cost_map_t compile_cost_map = get(vertex_compile_cost, g);
auto name_map = get(vertex_name, g);
auto compile_cost_map = get(vertex_compile_cost, g);
auto distance_map = get(vertex_distance, g);
auto color_map = get(vertex_color, g);
std::ifstream name_in("makefile-target-names.dat");
std::ifstream compile_cost_in("target-compile-costs.dat");
@@ -50,21 +50,21 @@ void load_actor_graph(std::istream& in, ActorGraph& g)
// Map from the actor numbers on this line to the actor vertices
typedef tokenizer<char_separator<char> > Tok;
Tok tok(line, char_separator<char>(" "));
for (Tok::iterator id = tok.begin(); id != tok.end(); ++id) {
int actor_id = lexical_cast<int>(*id);
std::map<int, Vertex>::iterator v = actors.find(actor_id);
for (const auto& id : tok) {
auto actor_id = lexical_cast<int>(id);
auto v = actors.find(actor_id);
if (v == actors.end()) {
Vertex new_vertex = add_vertex(Actor(actor_id), g);
auto new_vertex = add_vertex(Actor(actor_id), g);
actors[actor_id] = new_vertex;
actors_in_movie.push_back(new_vertex);
} else {
actors_in_movie.push_back(v->second);
}
}
for (std::vector<Vertex>::iterator i = actors_in_movie.begin();
for (auto i = actors_in_movie.begin();
i != actors_in_movie.end(); ++i) {
for (std::vector<Vertex>::iterator j = i + 1;
for (auto j = i + 1;
j != actors_in_movie.end(); ++j) {
if (!edge(*i, *j, g).second) add_edge(*i, *j, g);
}
@@ -78,14 +78,12 @@ write_pajek_graph(std::ostream& out, const Graph& g,
VertexIndexMap vertex_index, VertexNameMap vertex_name)
{
out << "*Vertices " << num_vertices(g) << '\n';
typedef typename graph_traits<Graph>::vertex_iterator vertex_iterator;
for (vertex_iterator v = vertices(g).first; v != vertices(g).second; ++v) {
for (auto v = vertices(g).first; v != vertices(g).second; ++v) {
out << get(vertex_index, *v)+1 << " \"" << get(vertex_name, *v) << "\"\n";
}
out << "*Edges\n";
typedef typename graph_traits<Graph>::edge_iterator edge_iterator;
for (edge_iterator e = edges(g).first; e != edges(g).second; ++e) {
for (auto e = edges(g).first; e != edges(g).second; ++e) {
out << get(vertex_index, source(*e, g))+1 << ' '
<< get(vertex_index, target(*e, g))+1 << " 1.0\n"; // HACK!
}
@@ -59,10 +59,8 @@ int main(int , char* [])
const int V = 5;
Graph g(V);
property_map<Graph, std::size_t VertexProperties::*>::type
id = get(&VertexProperties::index, g);
property_map<Graph, std::string EdgeProperties::*>::type
name = get(&EdgeProperties::name, g);
auto id = get(&VertexProperties::index, g);
auto name = get(&EdgeProperties::name, g);
boost::graph_traits<Graph>::vertex_iterator vi, viend;
int vnum = 0;
@@ -81,8 +81,8 @@ class distance_heuristic : public astar_heuristic<Graph, CostType>
: m_location(l), m_goal(goal) {}
CostType operator()(Vertex u)
{
CostType dx = m_location[m_goal].x - m_location[u].x;
CostType dy = m_location[m_goal].y - m_location[u].y;
auto dx = m_location[m_goal].x - m_location[u].x;
auto dy = m_location[m_goal].y - m_location[u].y;
return ::sqrt(dx * dx + dy * dy);
}
private:
@@ -160,7 +160,7 @@ int main(int argc, char **argv)
// create graph
mygraph_t g(N);
WeightMap weightmap = get(edge_weight, g);
auto weightmap = get(edge_weight, g);
for(std::size_t j = 0; j < num_edges; ++j) {
edge_descriptor e; bool inserted;
boost::tie(e, inserted) = add_edge(edge_array[j].first,
@@ -171,8 +171,8 @@ int main(int argc, char **argv)
// pick random start/goal
boost::mt19937 gen(time(0));
vertex start = random_vertex(g, gen);
vertex goal = random_vertex(g, gen);
auto start = random_vertex(g, gen);
auto goal = random_vertex(g, gen);
cout << "Start vertex: " << name[start] << endl;
@@ -202,14 +202,14 @@ int main(int argc, char **argv)
} catch(found_goal fg) { // found a path to the goal
list<vertex> shortest_path;
for(vertex v = goal;; v = p[v]) {
for(auto v = goal;; v = p[v]) {
shortest_path.push_front(v);
if(p[v] == v)
break;
}
cout << "Shortest path from " << name[start] << " to "
<< name[goal] << ": ";
list<vertex>::iterator spi = shortest_path.begin();
auto spi = shortest_path.begin();
cout << name[start];
for(++spi; spi != shortest_path.end(); ++spi)
cout << " -> " << name[*spi];
@@ -178,8 +178,8 @@ bool maze::solve() {
dist_map distance;
boost::associative_property_map<dist_map> dist_pmap(distance);
vertex_descriptor s = source();
vertex_descriptor g = goal();
auto s = source();
auto g = goal();
euclidean_heuristic heuristic(g);
astar_goal_visitor visitor(g);
@@ -192,7 +192,7 @@ bool maze::solve() {
} catch(found_goal fg) {
// Walk backwards from the goal through the predecessor chain adding
// vertices to the solution path.
for (vertex_descriptor u = g; u != s; u = predecessor[u])
for (auto u = g; u != s; u = predecessor[u])
m_solution.insert(u);
m_solution.insert(s);
m_solution_length = distance[g];
@@ -256,9 +256,9 @@ std::size_t random_int(std::size_t a, std::size_t b) {
// Generate a maze with a random assignment of barriers.
maze random_maze(std::size_t x, std::size_t y) {
maze m(x, y);
vertices_size_type n = num_vertices(m.m_grid);
vertex_descriptor s = m.source();
vertex_descriptor g = m.goal();
auto n = num_vertices(m.m_grid);
auto s = m.source();
auto g = m.goal();
// One quarter of the cells in the maze should be barriers.
int barriers = n/4;
while (barriers > 0) {
@@ -267,7 +267,7 @@ maze random_maze(std::size_t x, std::size_t y) {
// Walls range up to one quarter the dimension length in this direction.
vertices_size_type wall = random_int(1, m.length(direction)/4);
// Create the wall while decrementing the total barrier count.
vertex_descriptor u = vertex(random_int(0, n-1), m.m_grid);
auto u = vertex(random_int(0, n-1), m.m_grid);
while (wall) {
// Start and goal spaces should never be barriers.
if (u != s && u != g) {
@@ -277,7 +277,7 @@ maze random_maze(std::size_t x, std::size_t y) {
barriers--;
}
}
vertex_descriptor v = m.m_grid.next(u, direction);
auto v = m.m_grid.next(u, direction);
// Stop creating this wall if we reached the maze's edge.
if (u == v)
break;
@@ -27,8 +27,7 @@ struct edge_writer
void operator() (std::ostream & out, const Edge & e) const
{
out << "[label=\"" << get(edge_weight, m_g, e) << "\"";
typename graph_traits < Graph >::vertex_descriptor
u = source(e, m_g), v = target(e, m_g);
auto u = source(e, m_g), v = target(e, m_g);
if (m_parent[v] == u)
out << ", color=\"black\"";
else
@@ -71,8 +70,7 @@ main()
Graph g(edge_array, edge_array + n_edges, N);
#endif
graph_traits < Graph >::edge_iterator ei, ei_end;
property_map<Graph, int EdgeProperties::*>::type
weight_pmap = get(&EdgeProperties::weight, g);
auto weight_pmap = get(&EdgeProperties::weight, g);
int i = 0;
for (boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei, ++i)
weight_pmap[*ei] = weight[i];
@@ -109,9 +107,8 @@ main()
{
for (boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei) {
graph_traits < Graph >::edge_descriptor e = *ei;
graph_traits < Graph >::vertex_descriptor
u = source(e, g), v = target(e, g);
auto e = *ei;
auto u = source(e, g), v = target(e, g);
// VC++ doesn't like the 3-argument get function, so here
// we workaround by using 2-nested get()'s.
dot_file << name[u] << " -> " << name[v]
@@ -69,7 +69,7 @@ main()
Size time = 0;
typedef property_map<graph_t, std::size_t VertexProps::*>::type dtime_map_t;
dtime_map_t dtime_map = get(&VertexProps::discover_time, g);
auto dtime_map = get(&VertexProps::discover_time, g);
bfs_time_visitor < dtime_map_t > vis(dtime_map, time);
breadth_first_search(g, vertex(s, g), color_map(get(&VertexProps::color, g)).
visitor(vis));
@@ -17,16 +17,15 @@ void
build_router_network(Graph & g, VertexNameMap name_map,
TransDelayMap delay_map)
{
typename graph_traits < Graph >::vertex_descriptor a, b, c, d, e;
a = add_vertex(g);
auto a = add_vertex(g);
name_map[a] = 'a';
b = add_vertex(g);
auto b = add_vertex(g);
name_map[b] = 'b';
c = add_vertex(g);
auto c = add_vertex(g);
name_map[c] = 'c';
d = add_vertex(g);
auto d = add_vertex(g);
name_map[d] = 'd';
e = add_vertex(g);
auto e = add_vertex(g);
name_map[e] = 'e';
typename graph_traits<Graph>::edge_descriptor ed;
@@ -79,13 +78,13 @@ main()
typedef adjacency_list < listS, vecS, directedS, VP, EP> graph_t;
graph_t g;
property_map<graph_t, char VP::*>::type name_map = get(&VP::name, g);
property_map<graph_t, double EP::*>::type delay_map = get(&EP::weight, g);
auto name_map = get(&VP::name, g);
auto delay_map = get(&EP::weight, g);
build_router_network(g, name_map, delay_map);
typedef property_map<graph_t, char VP::*>::type VertexNameMap;
graph_traits<graph_t>::vertex_descriptor a = *vertices(g).first;
auto a = *vertices(g).first;
bfs_name_printer<VertexNameMap> vis(name_map);
std::cout << "BFS vertex discover order: ";
breadth_first_search(g, a, visitor(vis));
@@ -129,7 +129,7 @@ int main(int , char* [])
std::fill_n(d, 5, 0);
// The source vertex
Vertex s = *(boost::vertices(G).first);
auto s = *(boost::vertices(G).first);
p[s] = s;
boost::breadth_first_search
(G, s,
@@ -123,7 +123,7 @@ int main(int , char* [])
std::fill_n(d, 5, 0);
// The source vertex
Vertex s = *(boost::vertices(G).first);
auto s = *(boost::vertices(G).first);
p[s] = s;
boost::neighbor_breadth_first_search
(G, s,
@@ -44,10 +44,9 @@ main()
add_edge(6, 7, g);
add_edge(7, 8, g);
property_map < graph_t, edge_component_t >::type
component = get(edge_component, g);
auto component = get(edge_component, g);
std::size_t num_comps = biconnected_components(g, component);
auto num_comps = biconnected_components(g, component);
std::cerr << "Found " << num_comps << " biconnected components.\n";
std::vector<vertex_t> art_points;
@@ -30,9 +30,8 @@ class calc_distance_visitor : public boost::bfs_visitor<>
void tree_edge(typename boost::graph_traits<Graph>::edge_descriptor e,
Graph& g)
{
typename boost::graph_traits<Graph>::vertex_descriptor u, v;
u = boost::source(e, g);
v = boost::target(e, g);
auto u = boost::source(e, g);
auto v = boost::target(e, g);
distance[v] = distance[u] + 1;
}
private:
@@ -97,9 +96,8 @@ main()
NameVertexMap name2vertex;
Graph g;
typedef property_map<Graph, vertex_name_t>::type NameMap;
NameMap node_name = get(vertex_name, g);
property_map<Graph, edge_name_t>::type link_name = get(edge_name, g);
auto node_name = get(vertex_name, g);
auto link_name = get(edge_name, g);
//===========================================================================
// Read the data file and construct the graph.
@@ -114,7 +112,7 @@ main()
bool inserted;
Vertex u, v;
std::list<std::string>::iterator i = line_toks.begin();
auto i = line_toks.begin();
boost::tie(pos, inserted) = name2vertex.insert(std::make_pair(*i, Vertex()));
if (inserted) {
@@ -203,6 +201,8 @@ main()
// the tree nodes in the order that we want to print out:
// a directory-structure like format.
std::vector<size_type> dfs_distances(num_vertices(g), 0);
using NameMap = property_map<Graph, vertex_name_t>::type;
print_tree_visitor<NameMap, size_type*>
tree_printer(node_name, &dfs_distances[0]);
for (boost::tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi)
@@ -83,17 +83,15 @@ int main()
property < edge_reverse_t, Traits::edge_descriptor > > > > Graph;
Graph g;
property_map < Graph, edge_capacity_t >::type
capacity = get(edge_capacity, g);
property_map < Graph, edge_residual_capacity_t >::type
residual_capacity = get(edge_residual_capacity, g);
property_map < Graph, edge_reverse_t >::type rev = get(edge_reverse, g);
auto capacity = get(edge_capacity, g);
auto residual_capacity = get(edge_residual_capacity, g);
auto rev = get(edge_reverse, g);
Traits::vertex_descriptor s, t;
read_dimacs_max_flow(g, capacity, rev, s, t);
std::vector<default_color_type> color(num_vertices(g));
std::vector<long> distance(num_vertices(g));
long flow = boykov_kolmogorov_max_flow(g ,s, t);
auto flow = boykov_kolmogorov_max_flow(g ,s, t);
std::cout << "c The total flow:" << std::endl;
std::cout << "s " << flow << std::endl << std::endl;
@@ -28,7 +28,7 @@ main(int argc, char *argv[])
read_graph(g, cin);
// Use the Bron-Kerbosch algorithm to find all cliques, and
size_t c = bron_kerbosch_clique_number(g);
auto c = bron_kerbosch_clique_number(g);
cout << "clique number: " << c << endl;
return 0;
@@ -51,7 +51,7 @@ int main() {
if ( ! my_bucket_sorter[j].empty() ) {
cout << " has number ";
do {
int v = my_bucket_sorter[j].top();
auto v = my_bucket_sorter[j].top();
my_bucket_sorter[j].pop();
cout << v << " ";
} while ( ! my_bucket_sorter[j].empty() );
@@ -74,7 +74,7 @@ int main() {
if ( ! my_bucket_sorter[j].empty() ) {
cout << " has number ";
do {
int v = my_bucket_sorter[j].top();
auto v = my_bucket_sorter[j].top();
my_bucket_sorter[j].pop();
cout << v << " ";
} while ( ! my_bucket_sorter[j].empty() );
@@ -88,7 +88,7 @@ int main() {
for (iii=0; iii<N; iii++) {
std::size_t current = rand() % N;
if ( ! my_bucket_sorter[current].empty() ) {
int v = my_bucket_sorter[current].top();
auto v = my_bucket_sorter[current].top();
my_bucket_sorter[current].pop();
bucket[v] = rand() % N;
my_bucket_sorter.push(v);
@@ -98,7 +98,7 @@ int main() {
for (iii=0; iii<N; iii++) {
std::size_t current = rand() % N;
if ( ! my_bucket_sorter[current].empty() ) {
int v = my_bucket_sorter[current].top();
auto v = my_bucket_sorter[current].top();
bucket[v] = rand() % N;
my_bucket_sorter.update(v);
}
Oops, something went wrong.

0 comments on commit bfaddb5

Please sign in to comment.