From: Michael Andreen Date: Tue, 19 Jun 2007 09:18:53 +0000 (+0000) Subject: findIntervals implemented and passing test X-Git-Tag: v0.1~66 X-Git-Url: https://ruin.nu/git/?p=germs.git;a=commitdiff_plain;h=6be4116d6211ac4ba4c68dc2ab28f1bc5d77068e;hp=e7953f0050007cd1999d64d985d0a063b9ddc99b findIntervals implemented and passing test --- diff --git a/src/genealgorithms.cpp b/src/genealgorithms.cpp index 7dc832f..eecdf3f 100644 --- a/src/genealgorithms.cpp +++ b/src/genealgorithms.cpp @@ -24,6 +24,7 @@ #include #include #include +#include using namespace std; std::pair longestSequences(const GeneOrder& go){ @@ -69,6 +70,33 @@ std::vector findComponents(const GeneOrder& go){ return vector(); } +//TODO: Think of a better than O(n^2) implementation std::vector findIntervals(const GeneOrder& go){ - return vector(); + vector 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(abs(*g)) == i){ + f = n; + if (*g >= 0) + ++f; + if (found) + break; + found = true; + } + if(static_cast(abs(*g)) == i+1){ + s = n; + if (*g < 0) + ++s; + if (found) + break; + found = true; + } + } + intervals.push_back(Interval(f,s)); + } + return intervals; } diff --git a/src/test/genealgorithmstest.cpp b/src/test/genealgorithmstest.cpp index 50a5c73..2b9ae79 100644 --- a/src/test/genealgorithmstest.cpp +++ b/src/test/genealgorithmstest.cpp @@ -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);