1 #include "utilities.hpp"
2 #include "sparsematrix.hpp"
3 #include "listvector.hpp"
7 typedef list<PCell>::iterator MatData;
9 /***********************************************************************/
11 SparseMatrix::SparseMatrix() : numNodes(0), minsIndex(0), smallDist(1e6){};
13 /***********************************************************************/
15 int SparseMatrix::getNNodes(){
19 /***********************************************************************/
21 float SparseMatrix::getSmallDist(){
25 /***********************************************************************/
27 void SparseMatrix::rmCell(MatData data){
29 if(data->vectorMap != NULL ){
30 *(data->vectorMap) = NULL;
31 data->vectorMap = NULL;
36 // seems like i should be updating smallDist here, but the only time we remove cells is when
37 // clustering and the clustering algorithm updates smallDist
40 cout << "Standard Error: " << e.what() << " has occurred in the SparseMatrix class Function rmCell. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
44 cout << "An unknown error has occurred in the SparseMatrix class function rmCell. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
49 /***********************************************************************/
51 void SparseMatrix::addCell(PCell value){
53 matrix.push_back(value);
55 if(value.dist < smallDist){
56 smallDist = value.dist;
60 cout << "Standard Error: " << e.what() << " has occurred in the SparseMatrix class Function addCell. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
64 cout << "An unknown error has occurred in the SparseMatrix class function addCell. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
69 /***********************************************************************/
71 void SparseMatrix::clear(){
80 cout << "Standard Error: " << e.what() << " has occurred in the SparseMatrix class Function clear. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
84 cout << "An unknown error has occurred in the SparseMatrix class function clear. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
89 /***********************************************************************/
91 MatData SparseMatrix::begin(){
92 return matrix.begin();
95 /***********************************************************************/
97 MatData SparseMatrix::end(){
101 /***********************************************************************/
103 void SparseMatrix::print(){
107 cout << endl << "Index\tRow\tColumn\tDistance" << endl;
109 for(MatData currentCell=matrix.begin();currentCell!=matrix.end();currentCell++){
110 cout << index << '\t' << currentCell->row << '\t' << currentCell->column << '\t' << currentCell->dist << endl;
114 catch(exception& e) {
115 cout << "Standard Error: " << e.what() << " has occurred in the SparseMatrix class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
119 cout << "An unknown error has occurred in the SparseMatrix class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
124 /***********************************************************************/
126 void SparseMatrix::print(ListVector* list){
130 cout << endl << "Index\tRow\tColumn\tDistance" << endl;
132 for(MatData currentCell=matrix.begin();currentCell!=matrix.end();currentCell++){
133 cout << index << '\t' << list->get(currentCell->row) << '\t' << list->get(currentCell->column) << '\t' << currentCell->dist << endl;
137 catch(exception& e) {
138 cout << "Standard Error: " << e.what() << " has occurred in the SparseMatrix class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
142 cout << "An unknown error has occurred in the SparseMatrix class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
147 /***********************************************************************/
149 PCell* SparseMatrix::getSmallestCell(){
151 // this is where I check to see if the next small distance has the correct distance
152 // if it doesn't then I remove the offending Cell -> should also be able to check for
153 // invalid iterator / pointer -- right???
155 while(!mins.empty() && mins.back() == NULL){
159 // if the mins vector is empty go here...
163 smallDist = begin()->dist; //set the first candidate small distance
165 for(MatData currentCell=begin();currentCell!=end();currentCell++){
167 float dist = currentCell->dist;
169 if(dist < smallDist){ //found a new smallest distance
172 mins.push_back(&*currentCell); //this is the address of the data in the list being pointed to by the MatData iterator
174 else if(dist == smallDist){ //if a subsequent distance is the same as mins distance add the new iterator to the mins vector
175 mins.push_back(&*currentCell); //this is the address of the data in the list being pointed to by the MatData iterator
179 random_shuffle(mins.begin(), mins.end()); //randomize the order of the iterators in the mins vector
181 for(int i=0;i<mins.size();i++){
182 mins[i]->vectorMap = &mins[i]; //assign vectorMap to the address for the container
187 smallCell = mins.back(); //make the smallestCell the last element of the vector
189 mins.pop_back(); //remove the last element from the vector
193 catch(exception& e) {
194 cout << "Standard Error: " << e.what() << " has occurred in the SparseMatrix class Function getSmallestCell. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
198 cout << "An unknown error has occurred in the SparseMatrix class function getSmallestCell. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
203 /***********************************************************************/