Esempio n. 1
0
int SparseDistanceMatrix::addCellSorted(ull row, PDistCell cell){
	try {
		numNodes+=2;
		if(cell.dist < smallDist){ smallDist = cell.dist; }
        
        seqVec[row].push_back(cell);
        PDistCell temp(row, cell.dist);
        seqVec[cell.index].push_back(temp);
        
        sortSeqVec(row);
        sortSeqVec(cell.index);
        
        int location = -1; //find location of new cell when sorted
        for (int i = 0; i < seqVec[row].size(); i++) {  if (seqVec[row][i].index == cell.index) { location = i; break; } }
        
        return location;
	}
	catch(exception& e) {
		m->errorOut(e, "SparseDistanceMatrix", "addCellSorted");
		exit(1);
	}
}
Esempio n. 2
0
ull SparseDistanceMatrix::getSmallestCell(ull& row){
	try {
        if (!sorted) { sortSeqVec(); sorted = true; }
        
        //print();
        
        vector<PDistCellMin> mins;
        smallDist = MOTHURMAX;
       
        for (int i = 0; i < seqVec.size(); i++) {
            for (int j = 0; j < seqVec[i].size(); j++) {
                
                if (m->getControl_pressed()) { return smallDist; }
                
                //already checked everyone else in row
                if (i < seqVec[i][j].index) {  
			    
                    float dist = seqVec[i][j].dist;
                  
                    if(dist < smallDist){  //found a new smallest distance
                        mins.clear();
                        smallDist = dist;
                        PDistCellMin temp(i, seqVec[i][j].index);
                        mins.push_back(temp);
                        //cout << "adding " << i << '\t' << seqVec[i][j].index << " to mins\n";
                    }
                    else if(util.isEqual(dist, smallDist)){  //if a subsequent distance is the same as mins distance add the new iterator to the mins vector
                        PDistCellMin temp(i, seqVec[i][j].index);
                        mins.push_back(temp);
                        //cout << "adding " << i << '\t' << seqVec[i][j].index << " to mins\n";
                    }
                }else { j+=seqVec[i].size(); } //stop looking 
			}
		}
        
		util.mothurRandomShuffle(mins);  //randomize the order of the iterators in the mins vector
        
        row = mins[0].row;
        ull col = mins[0].col;
        
        //cout << "num mins = " << mins.size() << endl;

		return col;
	}
	catch(exception& e) {
		m->errorOut(e, "SparseDistanceMatrix", "getSmallestCell");
		exit(1);
	}
}
Esempio n. 3
0
ull SparseDistanceMatrix::getSmallestCell(ull& row){
	try {
        if (!sorted) { sortSeqVec(); sorted = true; }
        
        vector<PDistCellMin> mins;
        smallDist = 1e6;
       
        for (int i = 0; i < seqVec.size(); i++) {
            for (int j = 0; j < seqVec[i].size(); j++) {
                
                if (m->control_pressed) { return smallDist; }
                
                //already checked everyone else in row
                if (i < seqVec[i][j].index) {  
			    
                    float dist = seqVec[i][j].dist;
                  
                    if(dist < smallDist){  //found a new smallest distance
                        mins.clear();
                        smallDist = dist;
                        PDistCellMin temp(i, seqVec[i][j].index);
                        mins.push_back(temp);  
                    }
                    else if(dist == smallDist){  //if a subsequent distance is the same as mins distance add the new iterator to the mins vector
                        PDistCellMin temp(i, seqVec[i][j].index);
                        mins.push_back(temp); 
                    }
                }else { j+=seqVec[i].size(); } //stop looking 
			}
		}
        
		random_shuffle(mins.begin(), mins.end());  //randomize the order of the iterators in the mins vector
        
        row = mins[0].row;
        ull col = mins[0].col;

		return col;
	}
	catch(exception& e) {
		m->errorOut(e, "SparseDistanceMatrix", "getSmallestCell");
		exit(1);
	}
}