munkres.cpp
Go to the documentation of this file.
00001 /*
00002  *  munkres.cpp
00003  *  Hungaraian Assignment Algorithm
00004  *
00005  *  Authored by Ryan Rigdon on [May15].
00006  *  Copyright 2008 M. Ryan Rigdon
00007  *      mr.rigdon@gmail.com
00008  *
00009  */
00010 
00011 //This file is part of The Kuhn-Munkres Assignment Algorithm.
00012 //
00013 //The Kuhn-Munkres Assignment Algorithm is free software: you can redistribute it and/or modify
00014 //it under the terms of the GNU General Public License as published by
00015 //the Free Software Foundation, either version 3 of the License, or
00016 //(at your option) any later version.
00017 //
00018 //The Kuhn-Munkres Assignment Algorithm is distributed in the hope that it will be useful,
00019 //but WITHOUT ANY WARRANTY; without even the implied warranty of
00020 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021 //GNU General Public License for more details.
00022 //
00023 //You should have received a copy of the GNU General Public License
00024 //along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
00025 
00026 #include "munkres/munkres.h"
00027 #include "limits.h"
00028 
00029 munkres::munkres(void)
00030 {
00031         //default to not showing steps
00032         diag_on = false;
00033 }
00034 
00035 munkres::~munkres(void)
00036 {
00037 }
00038 
00039 //Load wieght_array from a vector of vectors of integers
00040 void munkres::load_weights(std::vector<std::vector<int> > x)
00041 {
00042         //get the row and column sizes of the vector passed in
00043         int a = x.size(), b = x[0].size();
00044 
00045         //default vectors for populating the matrices
00046         //these are needed because you need a default object when calling vector::resize()
00047         std::vector<int> ivector;
00048         cell default_cell;
00049         std::vector<cell> default_vector;
00050 
00051         //We need at least as many columns as there are rows
00052 
00053         //If we currently have more rows than columns
00054         if (a > b)
00055         {
00056                 //set matrix sizes
00057                 num_rows = b;
00058                 num_columns = a;
00059                 ivector.resize(num_columns, -1);
00060                 weight_array.resize(num_rows, ivector);
00061                 default_vector.resize(num_columns, default_cell);
00062                 cell_array.resize(num_rows, default_vector);
00063 
00064                 //populate weight_array and cell_array with the weights from x
00065                 for (int i = 0; i < num_rows; i++)
00066                 {
00067                         for (int j = 0; j < num_columns; j++)
00068                         {
00069                                 weight_array[i][j] = x[j][i];
00070                                 cell_array[i][j].weight = x[j][i];
00071                         }
00072                 }
00073         }
00074 
00075         //if the dimensions are correct 
00076         else
00077         {
00078                 //set matrix sizes
00079                 num_rows = a;
00080                 num_columns = b;
00081                 ivector.resize(num_columns, -1);
00082                 weight_array.resize(num_rows, ivector);
00083                 default_vector.resize(num_columns, default_cell);
00084                 cell_array.resize(num_rows, default_vector);
00085 
00086                 //populate weight_array and cell_array with the weights from x
00087                 for (int i = 0; i < num_rows; i++)
00088                 {
00089                         for (int j = 0; j < num_columns; j++)
00090                         {
00091                                 weight_array[i][j] = x[i][j];
00092                                 cell_array[i][j].weight = x[i][j];
00093                         }
00094                 }
00095         }
00096 
00097         //resize our covered and starred vectors
00098         row_starred.resize(num_rows, false);
00099         row_cov.resize(num_rows, false);
00100         column_starred.resize(num_columns, false);
00101         column_cov.resize(num_columns, false);
00102 
00103         if (diag_on)
00104         {
00105                 diagnostic(1);
00106         }
00107 
00108 }
00109 
00110 //function to copy weight values from cell_array to weight_array        
00111 int munkres::assign(ordered_pair *matching)
00112 {
00113 
00114         //total cost of the matching
00115         int total_cost = 0;
00116 
00117         //did we find a matching?
00118         bool matching_found = false;
00119 
00120         //For Checking
00121         if (diag_on)
00122         {
00123                 diagnostic(1);
00124         }
00125 
00126         //try to find a matching
00127         matching_found = find_a_matching();
00128 
00129         //For Checking
00130         if (diag_on)
00131         {
00132                 diagnostic(1);
00133         }
00134 
00135         //total up the weights from matched vertices
00136         for (int i = 0; i < num_rows; i++)
00137         {
00138                 for (int j = 0; j < num_columns; j++)
00139                 {
00140                         if (cell_array[i][j].starred)
00141                         {
00142                                 matching[i].col = j;
00143                                 matching[i].row = i;
00144                                 total_cost += weight_array[i][j];
00145                         }
00146                 }
00147         }
00148         return total_cost;
00149 }
00150 
00151 //functions to check if there is a star or prime in the 
00152 //current row or column
00153 int munkres::find_star_row(int r)
00154 {
00155 
00156         //check row
00157         for (int i = 0; i < num_columns; i++)
00158         {
00159                 //If a starred value is found in current row return true
00160                 if (cell_array[r][i].starred == true)
00161                 {
00162                         row_starred[r] = true;
00163                         column_starred[i] = true;
00164                         return i;
00165                 }
00166         }
00167         //If no stars are found return -1
00168         return -1;
00169 }
00170 
00171 int munkres::find_star_column(int c)
00172 {
00173         //check column
00174         for (int i = 0; i < num_rows; i++)
00175         {
00176                 //If a starred value is found in current column return true
00177                 if (cell_array[i][c].starred == true)
00178                 {
00179                         column_starred[c] = true;
00180                         row_starred[i] = true;
00181                         return i;
00182                 }
00183         }
00184         //If no stars are found return -1
00185         return -1;
00186 }
00187 
00188 int munkres::find_prime_row(int r)
00189 {
00190 
00191         //check row
00192         for (int i = 0; i < num_columns; i++)
00193         {
00194                 //If a primed value is found in current row return 
00195                 //its psoition
00196                 if (cell_array[r][i].primed == true)
00197                 {
00198                         return i;
00199                 }
00200         }
00201         //If no primes are found return -1
00202         return -1;
00203 }
00204 
00205 int munkres::find_prime_column(int c)
00206 {
00207         //check column
00208         for (int i = 0; i < num_rows; i++)
00209         {
00210                 //If a primed value is found in current column return 
00211                 //its position
00212                 if (cell_array[i][c].primed == true)
00213                 {
00214                         return i;
00215                 }
00216         }
00217         //If no primes are found return -1
00218         return -1;
00219 }
00220 
00221 //The function that will call each of step of Munkres' algorithm in turn
00222 //We're using this since multiple functions use the algorithm
00223 bool munkres::find_a_matching(void)
00224 {
00225         step1();
00226         step2();
00227         return step3();
00228 }
00229 
00230 //Function defintions for the steps of Munkres' algorithm
00231 //found at http://csclab.murraystate.edu/bob.pilgrim/445/munkres.html
00232 
00233 //We skip step 0 as the matrix is already formed
00234 //Here we subtract the smallest element in each row from the other values in that row
00235 void munkres::step1(void)
00236 {
00237         //variable to keep track of the smallest value in each row
00238         int smallest = 0;
00239         //iterate through rows
00240         for (int i = 0; i < num_rows; i++)
00241         {
00242                 //set smallest = first element in the current row
00243                 while (smallest == 0)
00244                 {
00245                         smallest = cell_array[i][0].weight;
00246                         //if the first element is 0 then increase the row
00247                         if (smallest == 0)
00248                         {
00249                                 if (i < num_rows - 1)
00250                                         i++;
00251                                 else
00252                                         break;
00253                         }
00254                 }
00255                 //iterate through each value in current row and find the smallest value
00256                 for (int j = 1; j < num_columns; j++)
00257                 {
00258                         //if the current value is a zero, then set smallest to zero
00259                         //and stop searching for a smaller value
00260                         if (cell_array[i][j].weight == 0)
00261                         {
00262                                 smallest = 0;
00263                                 //break out of the for loop
00264                                 j = num_columns;
00265                         }
00266 
00267                         //if the current value is smaller than smallest, then
00268                         //set smallest == to current value
00269                         else if (cell_array[i][j].weight < smallest)
00270                         {
00271                                 smallest = cell_array[i][j].weight;
00272                         }
00273                 }
00274 
00275                 //if the smallest == 0 then we don't need to subtract anything
00276                 //otherwise we need to subtract smallest from everything in the current row
00277                 if (smallest != 0)
00278                 {
00279                         //iterate through the values of current row and subtract
00280                         //smallest from evrything
00281                         for (int j = 0; j < num_columns; j++)
00282                         {
00283                                 cell_array[i][j].weight -= smallest;
00284                         }
00285                 }
00286 
00287                 //reset smallest for next iteration
00288                 smallest = 0;
00289         }
00290 
00291         if (diag_on)
00292         {
00293                 std::cerr << "Step 1" << std::endl;
00294                 diagnostic(2);
00295         }
00296 }
00297 
00298 //Star zeroes that don't have stars (upon thars :P) in the
00299 //same row or column
00300 void munkres::step2(void)
00301 {
00302         //iterate through rows
00303         for (int i = 0; i < num_rows; i++)
00304         {
00305                 //iterate through columns
00306                 for (int j = 0; j < num_columns; j++)
00307                 {
00308                         //if the current index is equal to 0
00309                         if (cell_array[i][j].weight == 0)
00310                         {
00311                                 //check for stars in current row
00312                                 if (!row_starred[i])
00313                                 {
00314                                         //if not try to find one
00315                                         find_star_row(i);
00316                                 }
00317 
00318                                 //check for stars in current column
00319                                 if (!column_starred[j])
00320                                 {
00321                                         //if not try to find one
00322                                         find_star_column(j);
00323                                 }
00324 
00325                                 //if no stars in column or row then star current index
00326                                 if (!row_starred[i] && !column_starred[j])
00327                                 {
00328                                         //star index
00329                                         cell_array[i][j].starred = true;
00330                                         //mark row as having a star
00331                                         row_starred[i] = true;
00332                                         //mark column as having a star
00333                                         column_starred[j] = true;
00334                                 }
00335                         }
00336                 }
00337         }
00338 
00339         if (diag_on)
00340         {
00341                 std::cerr << "Step 2" << std::endl;
00342                 diagnostic(3);
00343         }
00344 }
00345 
00346 //cover all columns with starred zeros
00347 //if (num_rows) columns are covered then return true
00348 //to signify that we're done
00349 bool munkres::step3(void)
00350 {
00351         //an iterator for our while loop
00352         int iter = 0;
00353 
00354         //loop through columns
00355         for (int i = 0; i < num_columns; i++)
00356         {
00357                 //if the column is starred
00358                 if (column_starred[i])
00359                 {
00360                         //cover it
00361                         column_cov[i] = true;
00362                 }
00363         }
00364         //while every column so far is covered
00365         for (int i = 0; i < num_columns; i++)
00366         {
00367                 if (column_cov[i])
00368                 {
00369                         iter++;
00370                 }
00371         }
00372 
00373         if (diag_on)
00374         {
00375                 std::cerr << "Step 3" << std::endl;
00376                 diagnostic(6);
00377         }
00378 
00379         //if all the rows were covered
00380         if (iter == num_rows)
00381         {
00382                 //exit algorithm
00383                 return true;
00384         }
00385 
00386         //else goto step 4
00387         else
00388                 return step4();
00389 }
00390 
00391 // Find a noncovered zero and prime it.  If there is no starred zero in the row containing this primed zero, Go to Step 5.
00392 // Otherwise, cover this row and uncover the column containing the starred zero. Continue in this manner until there are no
00393 // uncovered zeros left. Save the smallest uncovered value and Go to Step 6.
00394 
00395 // probably wrong algorithm
00401 bool munkres::step4(void)
00402 {
00403         while (true)
00404         {
00405                 // find an uncovered zero
00406                 int row = -1;
00407                 int col = -1;
00408                 for (int i = 0; i < num_rows; i++)
00409                 {
00410                         for (int j = 0; j < num_columns; j++)
00411                         {
00412                                 if (cell_array[i][j].weight == 0 && row_cov[i] == false && column_cov[j] == false)
00413                                 {
00414                                         row = i;
00415                                         col = j;
00416                                         break;
00417                                 }
00418                         }
00419                         if (row != -1)
00420                                 break;
00421                 }
00422 
00423                 // there is no further uncovered zero
00424                 if (row == -1)
00425                 {
00426                         if (diag_on)
00427                         {
00428                                 std::cerr << "Step 4" << std::endl;
00429                                 diagnostic(6);
00430                         }
00431                         return step6();
00432                 }
00433                 // prime the uncovered zero
00434                 else
00435                 {
00436                         cell_array[row][col].primed = true;
00437 
00438                         // If there is no starred zero in the row containing this primed zero, Go to Step 5
00439                         if (row_starred[row] == false)
00440                         {
00441                                 if (diag_on)
00442                                 {
00443                                         std::cerr << "Step 4: " << row << ",  " << col << std::endl;
00444                                         diagnostic(6);
00445                                 }
00446                                 return step5(row, col);
00447                         }
00448                         // Otherwise, cover this row and uncover the column containing the starred zero.
00449                         else
00450                         {
00451                                 row_cov[row] = true;
00452                                 int starredZeroCol = 0;
00453                                 for (starredZeroCol = 0; starredZeroCol < num_rows; starredZeroCol++)
00454                                         if (cell_array[row][starredZeroCol].starred == true)
00455                                                 break;
00456                                 column_cov[starredZeroCol] = false;
00457                         }
00458                 }
00459         }
00460 
00461         return false;
00462 
00463         // old algorithm
00465         //int smallest = 0;
00466 
00468         //for (int i = 0; i < num_rows; i++)
00469         //{
00470         //      //if the current row isn't covered
00471         //      if (!row_cov[i])
00472         //      {
00473 
00474         //              //set smallest = first element in the current row
00475         //              while (smallest == 0){
00476         //                      smallest = cell_array[i][0].weight;
00477         //                      //if the first element is 0 then increase the row
00478         //                      if (smallest == 0)
00479         //                      {
00480         //                              if (i < num_rows-1)
00481         //                                      i++;
00482         //                              else
00483         //                                      break;
00484         //                      }
00485         //              }
00486 
00487         //              //iterate through columns
00488         //              for (int j = 0; j < num_columns; j++)
00489         //              {
00490         //                      //if the column and row aren't covered, the current index is zero,
00491         //                      //and there isn't a star in the current row,
00492         //                      //then prime the current index and go to step 5
00493         //                      if (!column_cov[j] && !row_cov[i] && cell_array[i][j].weight == 0 && !row_starred[i])
00494         //                      {
00495         //                              //prime current index
00496         //                              cell_array[i][j].primed = true;
00497 
00498         //                              //if a primed zero with no star in the row exists
00499         //                              //goto step 5
00500         //                              if (diag_on)
00501         //                              {
00502         //                              std::cerr << "Step 4: " << i << ",  " << j <<std::endl;
00503         //                              diagnostic(6);
00504         //                              }
00505         //                              return step5(i, j);
00506 
00507 
00508         //                      }
00509 
00510         //                      //if the column and row aren't covered, the current index is zero,
00511         //                      //and there is a star in the current row,
00512         //                      //then prime the current index, cover the current row,
00513         //                      //and uncover the column with the starred zero
00514         //                      //also reset indeces to 0 to look for zeros that may have been uncovered
00515         //                      else if (!column_cov[j] && !row_cov[i] && cell_array[i][j].weight == 0)
00516         //                      {
00517         //                              //prime current index
00518         //                              cell_array[i][j].primed = true;
00519         //                              //cover current row
00520         //                              row_cov[i] = true;
00521         //                              //uncover column with starred zero
00522         //                              column_cov[find_star_row(i)] = false;
00523         //                              i = 0;
00524         //                              j = 0;
00525         //                      }
00526 
00527         //                      //if the column isn't covered, the current index isn't zero,
00528         //                      //and the current index is smaller than smallest so far,
00529         //                      //then set smallest == current index
00530         //                      else if (!column_cov[j] && cell_array[i][j].weight != 0 && cell_array[i][j].weight < smallest)
00531         //                      {
00532         //                              //set smallest == current index
00533         //                              smallest = cell_array[i][j].weight;
00534         //                      }
00535         //              }
00536         //      }
00537         //}
00538 
00539         //if (diag_on)
00540         //{
00541         //      std::cerr << "Step 4" << std::endl;
00542         //      diagnostic(6);
00543         //}
00544 
00545         //if we don't go to step 5 then go to step 6
00546         //return step6(smallest);
00547 }
00548 
00549 //start at the primed zero found in step 4
00550 //star this zero, erase its prime, and check for a starred zero in current column
00551 //if there is one, erase its star and go to the primed zero in its row
00552 //continue until we arrive at a primed zero with no starred zero in its column
00553 //uncover every row and column in the matrix and return to step 3
00554 
00555 //This step checks to see if there is a matching in the current matrix without altering
00556 //any values
00557 bool munkres::step5(int r, int c)
00558 {
00559         //to determine if we're done creating the sequence
00560         //of starred and primed zeros
00561         bool done = false;
00562 
00563         //are we looking for a star or prime
00564         bool looking_for_star = true;
00565 
00566         //for stupid special case in which we would look for a star in 
00567         //the current column after starring the current index
00568         //this returns the current index without looking further down
00569         //the column, resulting in an error
00570         int a;
00571 
00572         //create our sequence
00573         while (!done)
00574         {
00575                 switch (looking_for_star)
00576                 {
00577 
00578                 //if we're looking for a star
00579                 case true:
00580 
00581                         //special case protection
00582                         a = r;
00583 
00584                         //if there isn't a starred zero in the current column
00585                         if (!column_starred[c])
00586                         {
00587                                 //unprime current index
00588                                 cell_array[r][c].primed = false;
00589                                 //star current index
00590                                 cell_array[r][c].starred = true;
00591                                 //mark current row starred
00592                                 row_starred[r] = true;
00593                                 //set done to true
00594                                 done = true;
00595                         }
00596                         else
00597                         {
00598                                 //set the next row to search to the location of the
00599                                 //starred zero in current column
00600                                 r = find_star_column(c);
00601                                 //unprime current index
00602                                 cell_array[a][c].primed = false;
00603                                 //star current index
00604                                 cell_array[a][c].starred = true;
00605                                 //mark current row starred
00606                                 row_starred[a] = true;
00607                                 //set case to look for prime next
00608                                 looking_for_star = false;
00609                         }
00610 
00611                         //we can't do this earlier due to needing to check for stars in the column
00612                         //mark the column as starred
00613                         column_starred[c] = true;
00614                         break;
00615 
00616                         //if we're looking for a prime
00617                 case false:
00618 
00619                         //prime current index
00620                         cell_array[r][c].primed = false;
00621                         //unstar current index
00622                         cell_array[r][c].starred = false;
00623 
00624                         //unmark current row as starred
00625                         row_starred[r] = false;
00626 
00627                         //set the next column to search to the location of the
00628                         //primed zero in current row
00629                         c = find_prime_row(r);
00630 
00631                         //set case to look for star next
00632                         looking_for_star = true;
00633                         break;
00634                 }
00635         }
00636 
00637         //erase all primes and uncover all rows
00638         for (int i = 0; i < num_rows; i++)
00639         {
00640                 for (int j = 0; j < num_columns; j++)
00641                 {
00642                         cell_array[i][j].primed = false;
00643                 }
00644                 row_cov[i] = false;
00645         }
00646 
00647         //uncover all columns
00648         for (int i = 0; i < num_columns; i++)
00649                 column_cov[i] = false;
00650 
00651         if (diag_on)
00652         {
00653                 std::cerr << "Step 5" << std::endl;
00654                 diagnostic(6);
00655         }
00656         //go back to step 3
00657         return step3();
00658 }
00659 
00660 // Add the value found in Step 4 to every element of each covered row, and subtract it from every element of each uncovered column.  Return to Step 4 without altering any stars, primes, or covered lines.
00661 
00662 // maybe wrong algorithm:
00666 //
00669 bool munkres::step6()
00670 {
00671         // find minimum uncovered value
00672         int minVal = INT_MAX;
00673         for (int i = 0; i < num_rows; i++)
00674                 for (int j = 0; j < num_columns; j++)
00675                         if (row_cov[i] == false && column_cov[j] == false)
00676                                 if (minVal > cell_array[i][j].weight)
00677                                         minVal = cell_array[i][j].weight;
00678 
00679         //iterate through rows
00680         for (int i = 0; i < num_rows; i++)
00681         {
00682                 //iterate through columns
00683                 for (int j = 0; j < num_columns; j++)
00684                 {
00685                         // Substract the value found in Step 4 from every element of each uncovered column
00686                         if (column_cov[j] == false)
00687                         {
00688                                 //substract sub from its weight
00689                                 cell_array[i][j].weight -= minVal;
00690                         }
00691 
00692                         // Add the value found in Step 4 to every element of each covered row
00693                         else if (row_cov[i] == true)
00694                                 cell_array[i][j].weight += minVal;
00695                 }
00696         }
00697 
00698         if (diag_on)
00699         {
00700                 std::cerr << "Step 6" << std::endl;
00701                 diagnostic(6);
00702         }
00703         //go back to step 4
00704         return step4();
00705 }
00706 
00707 //Diagnostics only
00708 //Does not affect any results
00709 void munkres::diagnostic(int a) const
00710 {
00711         switch (a)
00712         {
00713         //Show base weights in weight_array
00714         case 1:
00715                 std::cerr << std::endl << "Base Weights" << std::endl;
00716                 for (int i = 0; i < num_rows; i++)
00717                 {
00718                         for (int j = 0; j < num_columns; j++)
00719                         {
00720                                 std::cerr << weight_array[i][j] << " | ";
00721                         }
00722                         std::cerr << std::endl;
00723                 }
00724                 std::cerr << std::endl;
00725                 break;
00726 
00727                 //show current weight values of cell_array
00728         case 2:
00729                 std::cerr << std::endl << "Current Weights" << std::endl;
00730                 for (int i = 0; i < num_rows; i++)
00731                 {
00732                         for (int j = 0; j < num_columns; j++)
00733                         {
00734                                 std::cerr << cell_array[i][j].weight << " | ";
00735                         }
00736                         std::cerr << std::endl;
00737                 }
00738                 std::cerr << std::endl;
00739                 break;
00740 
00741                 //Show current star placement
00742         case 3:
00743                 std::cerr << std::endl << "Starred values" << std::endl;
00744                 for (int i = 0; i < num_rows; i++)
00745                 {
00746                         for (int j = 0; j < num_columns; j++)
00747                         {
00748                                 if (cell_array[i][j].starred == true)
00749                                 {
00750                                         std::cerr << cell_array[i][j].weight << "* |  ";
00751                                 }
00752                                 else
00753                                 {
00754                                         std::cerr << cell_array[i][j].weight << "  |  ";
00755                                 }
00756                         }
00757                         std::cerr << std::endl;
00758                 }
00759                 std::cerr << std::endl;
00760                 break;
00761 
00762                 //Show current star placement, covered rows, and covered columns
00763         case 4:
00764                 std::cerr << std::endl << "Starred values and Lines" << std::endl;
00765                 for (int i = 0; i < num_rows; i++)
00766                 {
00767                         for (int j = 0; j < num_columns; j++)
00768                         {
00769                                 if (cell_array[i][j].starred == true)
00770                                 {
00771                                         std::cerr << cell_array[i][j].weight << "* |  ";
00772                                 }
00773                                 else
00774                                 {
00775                                         std::cerr << cell_array[i][j].weight << "  |  ";
00776                                 }
00777                         }
00778 
00779                         if (row_cov[i])
00780                         {
00781                                 std::cerr << "  X";
00782                         }
00783                         std::cerr << std::endl;
00784                 }
00785 
00786                 for (int i = 0; i < num_columns; i++)
00787                 {
00788                         if (column_cov[i])
00789                         {
00790 
00791                                 std::cerr << "X  |  ";
00792                         }
00793                         else
00794                         {
00795                                 std::cerr << "   |  ";
00796                         }
00797                 }
00798                 std::cerr << std::endl;
00799                 break;
00800 
00801                 //Show current prime placement, covered lines and covered columns
00802         case 5:
00803                 std::cerr << std::endl << "Primed values and Lines" << std::endl;
00804                 for (int i = 0; i < num_rows; i++)
00805                 {
00806                         for (int j = 0; j < num_columns; j++)
00807                         {
00808                                 if (cell_array[i][j].primed == true)
00809                                 {
00810                                         std::cerr << cell_array[i][j].weight << "' |  ";
00811                                 }
00812                                 else
00813                                 {
00814                                         std::cerr << cell_array[i][j].weight << "  |  ";
00815                                 }
00816                         }
00817 
00818                         if (row_cov[i])
00819                         {
00820                                 std::cerr << "  X";
00821                         }
00822                         std::cerr << std::endl;
00823                 }
00824 
00825                 for (int i = 0; i < num_columns; i++)
00826                 {
00827                         if (column_cov[i])
00828                         {
00829 
00830                                 std::cerr << "X  |  ";
00831                         }
00832                         else
00833                         {
00834                                 std::cerr << "   |  ";
00835                         }
00836                 }
00837                 std::cerr << std::endl;
00838                 break;
00839 
00840                 //Show current star and prime placement, covered rows, and covered columns
00841         case 6:
00842                 std::cerr << std::endl << "Starred values and Lines" << std::endl;
00843                 for (int i = 0; i < num_rows; i++)
00844                 {
00845                         for (int j = 0; j < num_columns; j++)
00846                         {
00847                                 if (cell_array[i][j].starred == true)
00848                                 {
00849                                         std::cerr << cell_array[i][j].weight << "* |  ";
00850                                 }
00851                                 else if (cell_array[i][j].primed == true)
00852                                 {
00853                                         std::cerr << cell_array[i][j].weight << "' |  ";
00854                                 }
00855                                 else
00856                                 {
00857                                         std::cerr << cell_array[i][j].weight << "  |  ";
00858                                 }
00859                         }
00860 
00861                         if (row_cov[i])
00862                         {
00863                                 std::cerr << "  X";
00864                         }
00865 
00866                         else
00867                         {
00868                                 std::cerr << "   ";
00869                         }
00870                         if (row_starred[i])
00871                         {
00872                                 std::cerr << "  *";
00873                         }
00874                         std::cerr << std::endl;
00875                 }
00876 
00877                 for (int i = 0; i < num_columns; i++)
00878                 {
00879                         if (column_cov[i])
00880                         {
00881 
00882                                 std::cerr << "X  |  ";
00883                         }
00884                         else
00885                         {
00886                                 std::cerr << "   |  ";
00887                         }
00888                 }
00889                 std::cerr << std::endl;
00890 
00891                 for (int i = 0; i < num_columns; i++)
00892                 {
00893                         if (column_starred[i])
00894                         {
00895 
00896                                 std::cerr << "*  |  ";
00897                         }
00898                         else
00899                         {
00900                                 std::cerr << "   |  ";
00901                         }
00902                 }
00903                 std::cerr << std::endl;
00904                 break;
00905 
00906         default:
00907                 break;
00908         }
00909 }


cob_people_detection
Author(s): Richard Bormann , Thomas Zwölfer
autogenerated on Fri Aug 28 2015 10:24:13