vector<vector<int>> permute(vector<int> & nums) { sort(nums.begin(), nums.end()); vector<vector<int>> vecResult(1, nums); while (next_permutation(nums.begin(), nums.end())) { vecResult.push_back(nums); } return vecResult; }
void CMultiSeg::GraphCutSolve() { clusterPatchInterval.push_back(0); for(int i = 0;i < clusterPatchNumLocal.size();i++) { int interval = 0; for(int j = 0;j <= i;j++) { interval += clusterPatchNumLocal[j]; } clusterPatchInterval.push_back(interval); } for(int i = 0;i < vecvecObjectPoolClustering.size();i++) { for(int j = 0;j < clusterPatchInterval.size();j++) { if(vecvecObjectPoolClustering[i][0] < clusterPatchInterval[j]) { vecObjectClusteringIndex.push_back(j - 1); break; } } } int num_sites, num_labels; num_sites = vecPatchPoint.size(); num_labels = vecvecObjectPoolClustering.size(); GCoptimizationGeneralGraph *gc = new GCoptimizationGeneralGraph(num_sites, num_labels); for(int i = 0;i < num_labels;i++) { for(int j = 0;j < num_labels;j++) { gc->setSmoothCost(i,j,1); } } //smooth for(int i = 0;i < vecpairPatchConnection.size();i++) { gc->setNeighbors(vecpairPatchConnection[i].first,vecpairPatchConnection[i].second,vecSmoothValue[i]); } //data for(int i = 0;i < num_sites;i++) { for(int j = 0;j < num_labels;j++) { int siteCluster; for(int k = 0;k < clusterPatchInterval.size();k++) { if(i < clusterPatchInterval[k]) { siteCluster = k - 1; break; } } if(siteCluster == vecObjectClusteringIndex[j]) { double dataValue = GetMultiDataValue(i,j); if(dataValue < 0) dataValue = 0; gc->setDataCost(i,j,dataValue); } else { gc->setDataCost(i,j,LARGE_NUM); } } } gc->swap(2); vector<int> vecResult(num_sites,-1); for ( int i = 0; i < num_sites; i++ ) vecResult[i] = gc->whatLabel(i); vecvecMultiResult.resize(num_labels); for(int i = 0;i < vecResult.size();i++) { vecvecMultiResult[vecResult[i]].push_back(i); } vector<vector<int>> vecvecMultiResultClean; for(int i =0;i < vecvecMultiResult.size();i++) { if(vecvecMultiResult[i].size() > 0) { vecvecMultiResultClean.push_back(vecvecMultiResult[i]); } } vecvecMultiResult = vecvecMultiResultClean; ofstream outFile("Output\\MultiResult.txt"); for(int i=0;i<vecvecMultiResult.size();i++) { for(int j=0;j<vecvecMultiResult[i].size();j++) { outFile << vecvecMultiResult[i][j] << " "; } outFile << " " << endl; } outFile.close(); }