]> ruin.nu Git - germs.git/commitdiff
findIntervals implemented and passing test
authorMichael Andreen <harv@ruin.nu>
Tue, 19 Jun 2007 09:18:53 +0000 (09:18 +0000)
committerMichael Andreen <harv@ruin.nu>
Tue, 19 Jun 2007 09:18:53 +0000 (09:18 +0000)
src/genealgorithms.cpp
src/test/genealgorithmstest.cpp

index 7dc832f252c208900b92c234879c8f09b5a93c24..eecdf3fea92bd8048c6c47fd1ef466d5e4698c67 100644 (file)
@@ -24,6 +24,7 @@
 #include <algorithm>
 #include <set>
 #include <cstdlib>
+#include <iostream>
 using namespace std;
 
 std::pair<int,int> longestSequences(const GeneOrder& go){
@@ -69,6 +70,33 @@ std::vector<Component> findComponents(const GeneOrder& go){
        return vector<Component>();
 }
 
+//TODO: Think of a better than O(n^2) implementation
 std::vector<Interval> findIntervals(const GeneOrder& go){
-       return vector<Interval>();
+       vector<Interval> intervals;
+       for (size_t i = 0; i < go.size() - 1; ++i){
+               size_t f = 0;
+               size_t s = 0;
+               bool found = false;
+               size_t n = 0;
+               for (GeneOrder::iterator g = go.begin(); g != go.end(); ++g, ++n){
+                       if (static_cast<size_t>(abs(*g)) == i){
+                               f = n;
+                               if (*g >= 0)
+                                       ++f;
+                               if (found)
+                                       break;
+                               found = true;
+                       }
+                       if(static_cast<size_t>(abs(*g)) == i+1){
+                               s = n;
+                               if (*g < 0)
+                                       ++s;
+                               if (found)
+                                       break;
+                               found = true;
+                       }
+               }
+               intervals.push_back(Interval(f,s));
+       }
+       return intervals;
 }
index 50a5c736c1903ac2bd6d8a7941cccfec715353d4..2b9ae79bfc89dbac994081a753ddc04feb6d0b37 100644 (file)
@@ -89,7 +89,7 @@ protected:
                CPPUNIT_ASSERT(go12 == v[2]);
                
                GeneOrder go2(_validPerm2.begin(),_validPerm2.end());
-               v = findIntervals(go);
+               v = findIntervals(go2);
                CPPUNIT_ASSERT_EQUAL(9ul,v.size());
                Interval go20(1,3);
                Interval go22(1,4);