advance_sp_itor_track was triggering an infinite loop
authorDiane Trout <diane@caltech.edu>
Tue, 28 Feb 2006 08:15:51 +0000 (08:15 +0000)
committerDiane Trout <diane@caltech.edu>
Tue, 28 Feb 2006 08:15:51 +0000 (08:15 +0000)
I somehow missed moving the logic that detected when we'd finished advancing
all the species iterators, which was causing an infinite loop.
I also changed int to vector<>::size_type to get rid of some warnings.

alg/nway_other.cxx

index 62f78581d1ca092fd1205718f92e35e6c5145743..51e9622240ca44ab0cb467292cd2233b7d915f93 100644 (file)
@@ -43,7 +43,8 @@ make_all_seq_win_matches(const vector<vector<FLPs> >& all_comparisons,
   list<int> new_nodes; 
   bool some_matches=true;
   all_matches.clear();
-  for(int sp_i=1; (sp_i < all_comparisons.size()) && (some_matches); sp_i++ )
+  for(vector<FLPs>::size_type sp_i=1; 
+      (sp_i < all_comparisons.size()) && (some_matches); sp_i++ )
   {
     new_nodes.clear();
     // --thres
@@ -75,7 +76,7 @@ void reset_species_iterators(vector<list<int> >& all_matches,
   sp_itor_begin.clear();
   sp_itor_end.clear();
   // set each species list of matches to beginning
-  for (int sp_i = 0; sp_i < all_matches.size(); sp_i++)
+  for (list<int>::size_type sp_i = 0; sp_i < all_matches.size(); sp_i++)
   {
     sp_itor_begin.push_back(all_matches[sp_i].begin());
     sp_itor_end.push_back(all_matches[sp_i].end());
@@ -94,7 +95,7 @@ void set_path_to_cur_sp_itor_track(
   path.clear();
   path.push_back(base_window_index);
 
-  for (int sp_i = 0; sp_i < sp_itor_begin.size(); sp_i++)
+  for (vector<int>::size_type sp_i = 0; sp_i < sp_itor_begin.size(); sp_i++)
   {
     path.push_back(*(sp_itor_begin[sp_i]));
   }
@@ -128,14 +129,18 @@ bool advance_sp_itor_track(vector<list<int>::iterator>& sp_itor_begin,
     else
       not_advanced = false;
   }
+  if (sp_depth == -1) // jumped up to first species, all paths searched
+    return false;
+  else
+    return true;
 }
 
 void
 Nway_Paths::radiate_path_search(vector<vector<FLPs> > all_comparisons)
 {
   vector<int> path;
-  int win_i, sp_i, window_num;
-  bool still_paths, not_advanced;
+  int win_i, window_num;
+  bool still_paths;
   vector<list<int> > all_matches;
   vector<list<int>::iterator> sp_itor_begin(all_comparisons.size());
   vector<list<int>::iterator> sp_itor_end(all_comparisons.size());
@@ -179,10 +184,10 @@ bool is_transitive_path(const vector<int>& path,
   int cur_node;
   list<int> trans_check_nodes;
 
-  for (int sp_depth=1; sp_depth != path.size()-1; ++sp_depth)
+  for (vector<int>::size_type sp_depth=1; sp_depth != path.size()-1; ++sp_depth)
   {
     cur_node = path[sp_depth];
-    for(int i = sp_depth+1; i != path.size()-1; i++)
+    for(vector<int>::size_type i = sp_depth+1; i != path.size()-1; i++)
     {
       // --thres
       //trans_check_nodes = all_comparisons[sp_depth][i].matches(cur_node);
@@ -206,12 +211,14 @@ Nway_Paths::trans_path_search(vector<vector<FLPs> > all_comparisons)
 {
   assert (species_num == all_comparisons.size());
   vector<int> path;
-  int win_i, sp_i, sp_depth, window_num;
-  bool still_paths, not_advanced;
+  int win_i, window_num;
+  bool still_paths;
+  list<int> trans_check_nodes;
   vector<list<int> > all_matches;
   vector<list<int>::iterator> sp_itor_begin(all_comparisons.size()); 
   vector<list<int>::iterator> sp_itor_end(all_comparisons.size()); 
 
+
   cout << "trans: softhres = " << soft_thres;
   cout << ", window = " << win_size << ", ";
 
@@ -235,10 +242,10 @@ Nway_Paths::trans_path_search(vector<vector<FLPs> > all_comparisons)
         // advanced.
         set_path_to_cur_sp_itor_track(path, win_i, sp_itor_begin);
 
+
         // if the path is transitive, save the path
         if (is_transitive_path(path, all_comparisons, soft_thres))
           pathz.push_back(path);
-
         // now advance the right iterator
         still_paths = advance_sp_itor_track(sp_itor_begin, 
                                             sp_itor_end,