/** * @brief Hungarian::stepFive * Construct a series of alternating primed and starred zeros as follows. * Let Z0 represent the uncovered primed zero found in Step 4. Let Z1 denote * the starred zero in the column of Z0 (if any). Let Z2 denote the primed * zero in the row of Z1 (there will always be one). Continue until the * series terminates at a primed zero that has no starred zero in its column. * Unstar each starred zero of the series, star each primed zero of the series, * erase all primes and uncover every line in the matrix. * Return to Step 3. * @return */ int Hungarian::stepFive() { bool done = false; int row = -1; int col = -1; int pathLength = 0; while(!done) { // First construct the alternating path... row = findStarInCol(this->mPath.at(pathLength).second); if(row != ROWNOTFOUND) { ++pathLength; this->mPath.at(pathLength).first = row; this->mPath.at(pathLength).second = this->mPath.at(pathLength-1).second; } else { done = true; } if(!done) { col = this->findPrimedZeroInRow(this->mPath.at(pathLength).first); ++pathLength; this->mPath.at(pathLength).first = this->mPath.at(pathLength-1).first; this->mPath.at(pathLength).second = col; } } // Then modify it. this->augmentPath(pathLength); this->clearCovers(); this->clearPrimes(); return 3; }
void HungarianMatrix<T>::csaz() { // step 5; constact a series of alternating zeros; bool done = false; int r = -1, c = -1, path_count = 1; vector<vector<int>>path(height, vector<int>(width)); for (size_t i = 0; i < height; ++i) { // path[i].resize(width); memset(&path[i].begin(), 0, sizeof(path[i])); } path[path_count - 1][0] = path_row0; path[path_count - 1][1] = path_col0; while (!done) { findStarInCol(path[path_count - 1][1], r); if (r > -1) { path_count++; path[path_count - 1][0] = r; path[path_count - 1][1] = path[path_count - 2][1]; } else { done = true; } if (!done) { findPrimeInRow(path[path_count - 1][0], c); path_count++; path[path_count - 1][0] = path[path_count - 2][0]; path[path_count - 1][1] = c; } } augmentPath(path_count, path); clearCovers(); erasePrimes(); for (size_t i = 0; i < height; ++i) path[i].clear(); path.clear(); czc(); }