X-Git-Url: https://ruin.nu/git/?p=germs.git;a=blobdiff_plain;f=src%2Fgenealgorithms.cpp;h=eecdf3fea92bd8048c6c47fd1ef466d5e4698c67;hp=154df354bc346592f53a1373b49bbc1c72a0b79d;hb=6be4116d6211ac4ba4c68dc2ab28f1bc5d77068e;hpb=74e3465418ae60633025efb581e399308ffdf4b1 diff --git a/src/genealgorithms.cpp b/src/genealgorithms.cpp index 154df35..eecdf3f 100644 --- a/src/genealgorithms.cpp +++ b/src/genealgorithms.cpp @@ -22,31 +22,16 @@ #include "geneorder.h" #include +#include #include +#include 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){ @@ -70,3 +55,48 @@ std::vector > robinsonSchensted(const GeneOrder& go){ } return v; } + +int countCycles(const GeneOrder& go){ + int cycles = 0; + set marked; + for (size_t p = 1; p < go.size() - 1; ++p){ + if (marked.find(p) != marked.end()) + continue; + } + return cycles; +} + +std::vector findComponents(const GeneOrder& go){ + return vector(); +} + +//TODO: Think of a better than O(n^2) implementation +std::vector findIntervals(const GeneOrder& go){ + 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; +}