]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix a bug in graph_coloring when there is only one partition.
authorBruno Turcksin <bruno.turcksin@gmail.com>
Thu, 7 Nov 2013 22:42:51 +0000 (22:42 +0000)
committerBruno Turcksin <bruno.turcksin@gmail.com>
Thu, 7 Nov 2013 22:42:51 +0000 (22:42 +0000)
git-svn-id: https://svn.dealii.org/trunk@31579 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/include/deal.II/base/graph_coloring.h

index 3deb60d5959bfc5ac78a7155e518807168c8004a..31576e38f711ff619eb32b9c3aad4d671a52e06d 100644 (file)
@@ -110,7 +110,7 @@ namespace GraphColoring
               for (unsigned int i=0; i<n_conflict_indices; ++i)
                 {
                   const std::vector<Iterator> &conflicting_elements
-                  = indices_to_iterators[conflict_indices[i]];
+                    = indices_to_iterators[conflict_indices[i]];
                   for (unsigned int j=0; j<conflicting_elements.size(); ++j)
                     {
                       // check that the iterator conflicting with the current one is not
@@ -347,51 +347,54 @@ namespace GraphColoring
             }
         }
 
-      // Do the same thing that we did for the even partitions to the odd
-      // partitions
-      unsigned int max_odd_n_colors(0);
-      for (unsigned int i=1; i<partition_size; i+=2)
+      // If there is more than one partition, do the same thing that we did for the even partitions 
+      // to the odd partitions
+      if (partition_size>1)
         {
-          if (max_odd_n_colors<colors_counter[i].size())
+          unsigned int max_odd_n_colors(0);
+          for (unsigned int i=1; i<partition_size; i+=2)
             {
-              max_odd_n_colors = colors_counter[i].size();
-              i_color = i;
+              if (max_odd_n_colors<colors_counter[i].size())
+                {
+                  max_odd_n_colors = colors_counter[i].size();
+                  i_color = i;
+                }
             }
-        }
-      coloring.resize(max_even_n_colors+max_odd_n_colors);
-      for (unsigned int j=0; j<colors_counter[i_color].size(); ++j)
-        coloring[max_even_n_colors+j] = partition_coloring[i_color][j];
+          coloring.resize(max_even_n_colors+max_odd_n_colors);
+          for (unsigned int j=0; j<colors_counter[i_color].size(); ++j)
+            coloring[max_even_n_colors+j] = partition_coloring[i_color][j];
 
-      for (unsigned int i=1; i<partition_size; i+=2)
-        {
-          if (i!=i_color)
+          for (unsigned int i=1; i<partition_size; i+=2)
             {
-              boost::unordered_set<unsigned int> used_k;
-              for (unsigned int j=0; j<colors_counter[i].size(); ++j)
+              if (i!=i_color)
                 {
-                  // Find the color in the current partition with the largest number of
-                  // iterators.
-                  std::vector<unsigned int>::iterator it;
-                  it = std::max_element(colors_counter[i].begin(),colors_counter[i].end());
-                  unsigned int min_iterators(-1);
-                  unsigned int pos(0);
-                  // Find the color of coloring with the least number of colors among
-                  // the colors that have not been used yet.
-                  for (unsigned int k=0; k<max_odd_n_colors; ++k)
-                    if (used_k.count(k)==0)
-                      if (colors_counter[i_color][k]<min_iterators)
-                        {
-                          min_iterators = colors_counter[i_color][k];
-                          pos = k;
-                        }
-                  colors_counter[i_color][pos] += *it;
-                  // Concatenate the current color with the existing coloring.
-                  coloring[max_even_n_colors+pos].insert(coloring[max_even_n_colors+pos].end(),
-                                                         partition_coloring[i][it-colors_counter[i].begin()].begin(),
-                                                         partition_coloring[i][it-colors_counter[i].begin()].end());
-                  used_k.insert(pos);
-                  // Put the number of iterators to the current color to zero.
-                  *it = 0;
+                  boost::unordered_set<unsigned int> used_k;
+                  for (unsigned int j=0; j<colors_counter[i].size(); ++j)
+                    {
+                      // Find the color in the current partition with the largest number of
+                      // iterators.
+                      std::vector<unsigned int>::iterator it;
+                      it = std::max_element(colors_counter[i].begin(),colors_counter[i].end());
+                      unsigned int min_iterators(-1);
+                      unsigned int pos(0);
+                      // Find the color of coloring with the least number of colors among
+                      // the colors that have not been used yet.
+                      for (unsigned int k=0; k<max_odd_n_colors; ++k)
+                        if (used_k.count(k)==0)
+                          if (colors_counter[i_color][k]<min_iterators)
+                            {
+                              min_iterators = colors_counter[i_color][k];
+                              pos = k;
+                            }
+                      colors_counter[i_color][pos] += *it;
+                      // Concatenate the current color with the existing coloring.
+                      coloring[max_even_n_colors+pos].insert(coloring[max_even_n_colors+pos].end(),
+                                                             partition_coloring[i][it-colors_counter[i].begin()].begin(),
+                                                             partition_coloring[i][it-colors_counter[i].begin()].end());
+                      used_k.insert(pos);
+                      // Put the number of iterators to the current color to zero.
+                      *it = 0;
+                    }
                 }
             }
         }

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.