+/***********************************************************************/
+//This function clusters based on the method of the derived class
+//At the moment only average and complete linkage are covered, because
+//single linkage uses a different approach.
+void Cluster::update(){
+ try {
+ getRowColCells();
+
+ vector<int> found(nColCells, 0);
+ int search;
+ bool changed;
+
+ // The vector has to be traversed in reverse order to preserve the index
+ // for faster removal in removeCell()
+ for (int i=nRowCells-1;i>=0;i--) {
+ if (!((rowCells[i]->row == smallRow) && (rowCells[i]->column == smallCol))) {
+ if (rowCells[i]->row == smallRow) {
+ search = rowCells[i]->column;
+ } else {
+ search = rowCells[i]->row;
+ }
+
+ for (int j=0;j<nColCells;j++) {
+ if (!((colCells[j]->row == smallRow) && (colCells[j]->column == smallCol))) {
+ if (colCells[j]->row == search || colCells[j]->column == search) {
+ found[j] = 1;
+ changed = updateDistance(colCells[j], rowCells[i]);
+ // If the cell's distance changed and it had the same distance as
+ // the smallest distance, invalidate the mins vector in SparseMatrix
+ if (changed) {
+ if (colCells[j]->vectorMap != NULL) {
+ *(colCells[j]->vectorMap) = NULL;
+ colCells[j]->vectorMap = NULL;
+ }
+ }
+ break;
+ }
+ }
+ }
+ removeCell(rowCells[i], i , -1);
+ }
+ }
+ clusterBins();
+ clusterNames();
+
+ // Special handling for singlelinkage case, not sure whether this
+ // could be avoided
+ for (int i=nColCells-1;i>=0;i--) {
+ if (found[i] == 0) {
+ removeCell(colCells[i], -1, i);
+ }
+ }
+ }
+ catch(exception& e) {
+ errorOut(e, "Cluster", "update");
+ exit(1);
+ }
+}
+
+