]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/libs/graph/example/weighted_matching_example.cpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / boost / libs / graph / example / weighted_matching_example.cpp
index 026394cf98786e199928a754d9c9fb427df26504..50fe5d50cefbfac91b56570a844eb6a4302c4266 100644 (file)
 
 using namespace boost;
 
-typedef property<edge_weight_t, float, property<edge_index_t, int> > EdgeProperty;
-typedef adjacency_list<vecS, vecS, undirectedS, no_property, EdgeProperty> my_graph;
+typedef property< edge_weight_t, float, property< edge_index_t, int > >
+    EdgeProperty;
+typedef adjacency_list< vecS, vecS, undirectedS, no_property, EdgeProperty >
+    my_graph;
 
-int main(int argc, const char * argv[])
+int main(int argc, const char* argv[])
 {
-    graph_traits<my_graph>::vertex_iterator vi, vi_end;
+    graph_traits< my_graph >::vertex_iterator vi, vi_end;
     const int n_vertices = 18;
     my_graph g(n_vertices);
-    
-    // vertices can be refered by integers because my_graph use vector to store them
-    
+
+    // vertices can be refered by integers because my_graph use vector to store
+    // them
+
     add_edge(1, 2, EdgeProperty(5), g);
     add_edge(0, 4, EdgeProperty(1), g);
     add_edge(1, 5, EdgeProperty(4), g);
@@ -45,14 +48,13 @@ int main(int argc, const char * argv[])
     add_edge(14, 15, EdgeProperty(6), g);
     add_edge(12, 13, EdgeProperty(2), g);
     add_edge(16, 17, EdgeProperty(5), g);
-    
-    
+
     // print the ascii graph into terminal (better to use fixed-width font)
     // this graph has a maximum cardinality matching of size 8
     // but maximum weighted matching is of size 7
-    
-    std::vector<std::string> ascii_graph_weighted;
-    
+
+    std::vector< std::string > ascii_graph_weighted;
+
     ascii_graph_weighted.push_back("                     5                 ");
     ascii_graph_weighted.push_back("           A       B---C       D       ");
     ascii_graph_weighted.push_back("           1\\  7  /4   1\\  5  /4     ");
@@ -62,51 +64,58 @@ int main(int argc, const char * argv[])
     ascii_graph_weighted.push_back("           4/    3\\    7/  4  \\6     ");
     ascii_graph_weighted.push_back("       M---N       O---P       Q---R   ");
     ascii_graph_weighted.push_back("         2           6           5     ");
-    
-    
+
     // our maximum weighted matching and result
-    
+
     std::cout << "In the following graph:" << std::endl << std::endl;
-    
-    for(std::vector<std::string>::iterator itr = ascii_graph_weighted.begin(); itr != ascii_graph_weighted.end(); ++itr)
+
+    for (std::vector< std::string >::iterator itr
+         = ascii_graph_weighted.begin();
+         itr != ascii_graph_weighted.end(); ++itr)
         std::cout << *itr << std::endl;
-    
+
     std::cout << std::endl;
-    
-    std::vector<graph_traits<my_graph>::vertex_descriptor> mate1(n_vertices), mate2(n_vertices);
+
+    std::vector< graph_traits< my_graph >::vertex_descriptor > mate1(
+        n_vertices),
+        mate2(n_vertices);
     maximum_weighted_matching(g, &mate1[0]);
-    
+
     std::cout << "Found a weighted matching:" << std::endl;
-    std::cout << "Matching size is " << matching_size(g, &mate1[0]) << ", total weight is " << matching_weight_sum(g, &mate1[0]) << std::endl;
+    std::cout << "Matching size is " << matching_size(g, &mate1[0])
+              << ", total weight is " << matching_weight_sum(g, &mate1[0])
+              << std::endl;
     std::cout << std::endl;
-    
+
     std::cout << "The matching is:" << std::endl;
-    for (boost::tie(vi,vi_end) = vertices(g); vi != vi_end; ++vi)
-        if (mate1[*vi] != graph_traits<my_graph>::null_vertex() && *vi < mate1[*vi])
+    for (boost::tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi)
+        if (mate1[*vi] != graph_traits< my_graph >::null_vertex()
+            && *vi < mate1[*vi])
             std::cout << "{" << *vi << ", " << mate1[*vi] << "}" << std::endl;
     std::cout << std::endl;
-    
-    
-    // now we check the correctness by compare the weight sum to a brute-force matching result
-    // note that two matchings may be different because of multiple optimal solutions
-    
+
+    // now we check the correctness by compare the weight sum to a brute-force
+    // matching result note that two matchings may be different because of
+    // multiple optimal solutions
+
     brute_force_maximum_weighted_matching(g, &mate2[0]);
-    
-    std::cout << "Found a weighted matching by brute-force searching:" << std::endl;
-    std::cout << "Matching size is " << matching_size(g, &mate2[0]) << ", total weight is " << matching_weight_sum(g, &mate2[0]) << std::endl;
+
+    std::cout << "Found a weighted matching by brute-force searching:"
+              << std::endl;
+    std::cout << "Matching size is " << matching_size(g, &mate2[0])
+              << ", total weight is " << matching_weight_sum(g, &mate2[0])
+              << std::endl;
     std::cout << std::endl;
-    
+
     std::cout << "The brute-force matching is:" << std::endl;
-    for (boost::tie(vi,vi_end) = vertices(g); vi != vi_end; ++vi)
-        if (mate2[*vi] != graph_traits<my_graph>::null_vertex() && *vi < mate2[*vi])
+    for (boost::tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi)
+        if (mate2[*vi] != graph_traits< my_graph >::null_vertex()
+            && *vi < mate2[*vi])
             std::cout << "{" << *vi << ", " << mate2[*vi] << "}" << std::endl;
     std::cout << std::endl;
-    
-    assert(matching_weight_sum(g, &mate1[0]) == matching_weight_sum(g, &mate2[0]));
-    
-    
-    return 0;
-}
-
 
+    assert(
+        matching_weight_sum(g, &mate1[0]) == matching_weight_sum(g, &mate2[0]));
 
+    return 0;
+}