From 3db2f8d8f21614408dfd072cc45e618c7905461f Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Mon, 18 Jun 2007 14:54:07 +0000 Subject: [PATCH] longest increasing and decreasing subsequences --- src/genealgorithms.cpp | 21 ++------------------- src/test/genealgorithmstest.cpp | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/genealgorithms.cpp b/src/genealgorithms.cpp index 154df35..b2d7fa6 100644 --- a/src/genealgorithms.cpp +++ b/src/genealgorithms.cpp @@ -26,27 +26,10 @@ using namespace std; std::pair longestSequences(const GeneOrder& go){ + vector > v = robinsonSchensted(go); + return pair(v[0].size(),v.size()); } - -/* -robSche2 :: [Int] -> [[Int]] -> [[Int]] -robSche2 [] ys = ys -robSche2 (x:xs) ys = robSche2 xs $ robSche4 x ys - -robSche3 :: Int -> [Int] -> (Maybe Int,[Int]) -robSche3 x ys = let yless = [y | y <- ys, y < x] in - let ymore = [y | y <- ys, y > x] in - case ymore of - [] -> (Nothing, yless++[x]) - (y:ys) -> (Just y, yless++(x:ys)) - -robSche4 :: Int -> [[Int]] -> [[Int]] -robSche4 x [] = [[x]] -robSche4 x (y:ys) = case robSche3 x y of - (Nothing, y) -> y:ys - (Just x, y) -> y:robSche4 x ys -*/ std::vector > robinsonSchensted(const GeneOrder& go){ vector > v; for (GeneOrder::iterator i = go.begin(); i != go.end(); ++i){ diff --git a/src/test/genealgorithmstest.cpp b/src/test/genealgorithmstest.cpp index f7bd2fc..55ebb58 100644 --- a/src/test/genealgorithmstest.cpp +++ b/src/test/genealgorithmstest.cpp @@ -21,6 +21,7 @@ class TESTNAME : public CPPUNIT_NS::TestFixture { CPPUNIT_TEST_SUITE( TESTNAME ); CPPUNIT_TEST( testRobinsonSchensted ); + CPPUNIT_TEST( testLongestSequences ); CPPUNIT_TEST_SUITE_END(); protected: @@ -65,6 +66,20 @@ protected: CPPUNIT_ASSERT(equal(v[1].begin(),v[1].end(),second)); } + void testLongestSequences (){ + GeneOrder go(_validPerm.begin(),_validPerm.end()); + pair p = longestSequences(go); + CPPUNIT_ASSERT_EQUAL(5,p.first); + CPPUNIT_ASSERT_EQUAL(1,p.second); + + GeneOrder go2(_validPerm2.begin(),_validPerm2.end()); + p = longestSequences(go2); + int first[] = {0,1,3,5,6,7,9}; + int second[] = {2,4,8}; + CPPUNIT_ASSERT_EQUAL(7,p.first); + CPPUNIT_ASSERT_EQUAL(2,p.second); + } + }; CPPUNIT_TEST_SUITE_REGISTRATION( TESTNAME ); -- 2.39.2