2 #include "sparsematrix.hpp"
3 #include "listvector.hpp"
5 typedef list<PCell>::iterator MatData;
7 /***********************************************************************/
9 SparseMatrix::SparseMatrix() : numNodes(0), minsIndex(0), smallDist(1e6){}
11 /***********************************************************************/
13 int SparseMatrix::getNNodes(){
17 /***********************************************************************/
19 float SparseMatrix::getSmallDist(){
23 /***********************************************************************/
25 void SparseMatrix::rmCell(MatData data){
27 if(data->vectorMap != NULL ){
28 *(data->vectorMap) = NULL;
29 data->vectorMap = NULL;
34 // seems like i should be updating smallDist here, but the only time we remove cells is when
35 // clustering and the clustering algorithm updates smallDist
38 cout << "Standard Error: " << e.what() << " has occurred in the SparseMatrix class Function rmCell. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
42 cout << "An unknown error has occurred in the SparseMatrix class function rmCell. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
47 /***********************************************************************/
49 void SparseMatrix::addCell(PCell value){
51 matrix.push_back(value);
53 if(value.dist < smallDist){
54 smallDist = value.dist;
58 cout << "Standard Error: " << e.what() << " has occurred in the SparseMatrix class Function addCell. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
62 cout << "An unknown error has occurred in the SparseMatrix class function addCell. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
67 /***********************************************************************/
69 void SparseMatrix::clear(){
78 cout << "Standard Error: " << e.what() << " has occurred in the SparseMatrix class Function clear. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
82 cout << "An unknown error has occurred in the SparseMatrix class function clear. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
87 /***********************************************************************/
89 MatData SparseMatrix::begin(){
90 return matrix.begin();
93 /***********************************************************************/
95 MatData SparseMatrix::end(){
99 /***********************************************************************/
101 void SparseMatrix::print(){
105 cout << endl << "Index\tRow\tColumn\tDistance" << endl;
107 for(MatData currentCell=matrix.begin();currentCell!=matrix.end();currentCell++){
108 cout << index << '\t' << currentCell->row << '\t' << currentCell->column << '\t' << currentCell->dist << endl;
112 catch(exception& e) {
113 cout << "Standard Error: " << e.what() << " has occurred in the SparseMatrix class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
117 cout << "An unknown error has occurred in the SparseMatrix class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
122 /***********************************************************************/
124 void SparseMatrix::print(ListVector* list){
128 cout << endl << "Index\tRow\tColumn\tDistance" << endl;
130 for(MatData currentCell=matrix.begin();currentCell!=matrix.end();currentCell++){
131 cout << index << '\t' << list->get(currentCell->row) << '\t' << list->get(currentCell->column) << '\t' << currentCell->dist << endl;
135 catch(exception& e) {
136 cout << "Standard Error: " << e.what() << " has occurred in the SparseMatrix class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
140 cout << "An unknown error has occurred in the SparseMatrix class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
145 /***********************************************************************/
147 PCell* SparseMatrix::getSmallestCell(){
149 // this is where I check to see if the next small distance has the correct distance
150 // if it doesn't then I remove the offending Cell -> should also be able to check for
151 // invalid iterator / pointer -- right???
153 while(!mins.empty() && mins.back() == NULL){
157 // if the mins vector is empty go here...
161 smallDist = begin()->dist; //set the first candidate small distance
163 for(MatData currentCell=begin();currentCell!=end();currentCell++){
165 float dist = currentCell->dist;
167 if(dist < smallDist){ //found a new smallest distance
170 mins.push_back(&*currentCell); //this is the address of the data in the list being pointed to by the MatData iterator
172 else if(dist == smallDist){ //if a subsequent distance is the same as mins distance add the new iterator to the mins vector
173 mins.push_back(&*currentCell); //this is the address of the data in the list being pointed to by the MatData iterator
177 random_shuffle(mins.begin(), mins.end()); //randomize the order of the iterators in the mins vector
179 for(int i=0;i<mins.size();i++){
180 mins[i]->vectorMap = &mins[i]; //assign vectorMap to the address for the container
185 smallCell = mins.back(); //make the smallestCell the last element of the vector
187 mins.pop_back(); //remove the last element from the vector
191 catch(exception& e) {
192 cout << "Standard Error: " << e.what() << " has occurred in the SparseMatrix class Function getSmallestCell. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
196 cout << "An unknown error has occurred in the SparseMatrix class function getSmallestCell. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
201 /***********************************************************************/