4 #include "utilities.hpp"
5 #include "sparsematrix.hpp"
6 #include "listvector.hpp"
11 typedef list<PCell>::iterator MatData;
13 /***********************************************************************/
15 SparseMatrix::SparseMatrix() : numNodes(0), minsIndex(0), smallDist(1e6){};
17 /***********************************************************************/
19 int SparseMatrix::getNNodes(){
23 /***********************************************************************/
25 float SparseMatrix::getSmallDist(){
29 /***********************************************************************/
31 void SparseMatrix::rmCell(MatData data){
33 if(data->vectorMap != NULL ){
34 *(data->vectorMap) = NULL;
35 data->vectorMap = NULL;
40 // seems like i should be updating smallDist here, but the only time we remove cells is when
41 // clustering and the clustering algorithm updates smallDist
44 cout << "Standard Error: " << e.what() << " has occurred in the SparseMatrix class Function rmCell. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
48 cout << "An unknown error has occurred in the SparseMatrix class function rmCell. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
53 /***********************************************************************/
55 void SparseMatrix::addCell(PCell value){
57 matrix.push_back(value);
59 if(value.dist < smallDist){
60 smallDist = value.dist;
64 cout << "Standard Error: " << e.what() << " has occurred in the SparseMatrix class Function addCell. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
68 cout << "An unknown error has occurred in the SparseMatrix class function addCell. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
73 /***********************************************************************/
75 void SparseMatrix::clear(){
84 cout << "Standard Error: " << e.what() << " has occurred in the SparseMatrix class Function clear. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
88 cout << "An unknown error has occurred in the SparseMatrix class function clear. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
93 /***********************************************************************/
95 MatData SparseMatrix::begin(){
96 return matrix.begin();
99 /***********************************************************************/
101 MatData SparseMatrix::end(){
105 /***********************************************************************/
107 void SparseMatrix::print(){
111 cout << endl << "Index\tRow\tColumn\tDistance" << endl;
113 for(MatData currentCell=matrix.begin();currentCell!=matrix.end();currentCell++){
114 cout << index << '\t' << currentCell->row << '\t' << currentCell->column << '\t' << currentCell->dist << endl;
118 catch(exception& e) {
119 cout << "Standard Error: " << e.what() << " has occurred in the SparseMatrix class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
123 cout << "An unknown error has occurred in the SparseMatrix class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
128 /***********************************************************************/
130 void SparseMatrix::print(ListVector* list){
134 cout << endl << "Index\tRow\tColumn\tDistance" << endl;
136 for(MatData currentCell=matrix.begin();currentCell!=matrix.end();currentCell++){
137 cout << index << '\t' << list->get(currentCell->row) << '\t' << list->get(currentCell->column) << '\t' << currentCell->dist << endl;
141 catch(exception& e) {
142 cout << "Standard Error: " << e.what() << " has occurred in the SparseMatrix class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
146 cout << "An unknown error has occurred in the SparseMatrix class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
151 /***********************************************************************/
153 PCell* SparseMatrix::getSmallestCell(){
155 // this is where I check to see if the next small distance has the correct distance
156 // if it doesn't then I remove the offending Cell -> should also be able to check for
157 // invalid iterator / pointer -- right???
159 while(!mins.empty() && mins.back() == NULL){
163 // if the mins vector is empty go here...
167 smallDist = begin()->dist; //set the first candidate small distance
169 for(MatData currentCell=begin();currentCell!=end();currentCell++){
171 float dist = currentCell->dist;
173 if(dist < smallDist){ //found a new smallest distance
176 mins.push_back(&*currentCell); //this is the address of the data in the list being pointed to by the MatData iterator
178 else if(dist == smallDist){ //if a subsequent distance is the same as mins distance add the new iterator to the mins vector
179 mins.push_back(&*currentCell); //this is the address of the data in the list being pointed to by the MatData iterator
183 random_shuffle(mins.begin(), mins.end()); //randomize the order of the iterators in the mins vector
185 for(int i=0;i<mins.size();i++){
186 mins[i]->vectorMap = &mins[i]; //assign vectorMap to the address for the container
191 smallCell = mins.back(); //make the smallestCell the last element of the vector
193 mins.pop_back(); //remove the last element from the vector
197 catch(exception& e) {
198 cout << "Standard Error: " << e.what() << " has occurred in the SparseMatrix class Function getSmallestCell. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
202 cout << "An unknown error has occurred in the SparseMatrix class function getSmallestCell. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
207 /***********************************************************************/