]> ruin.nu Git - germs.git/blobdiff - src/genealgorithms.cpp
robinson schensted algorithm implemented
[germs.git] / src / genealgorithms.cpp
diff --git a/src/genealgorithms.cpp b/src/genealgorithms.cpp
new file mode 100644 (file)
index 0000000..154df35
--- /dev/null
@@ -0,0 +1,72 @@
+/***************************************************************************
+ *   Copyright (C) 2006 by Michael Andreen                                 *
+ *   andreen@student.chalmers.se                                           *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA          *
+ ***************************************************************************/
+
+#include "genealgorithms.h"
+#include "geneorder.h"
+
+#include <algorithm>
+#include <cstdlib>
+using namespace std;
+
+std::pair<int,int> longestSequences(const GeneOrder& go){
+}
+
+
+/*
+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<std::vector<int> > robinsonSchensted(const GeneOrder& go){
+       vector<vector<int> > v;
+       for (GeneOrder::iterator i = go.begin(); i != go.end(); ++i){
+               int n = abs(*i);
+               bool added = false;
+               for (vector<vector<int> >::iterator vs = v.begin();
+                               vs != v.end(); ++vs){
+                       vector<int>::iterator bigger = upper_bound(vs->begin(),vs->end(),n);
+                       if ( bigger == vs->end()){
+                               vs->push_back(n);
+                               added = true;
+                               break;
+                       }else{
+                               swap(n,*bigger);
+                       }
+               }
+               if (!added){
+                       v.push_back(vector<int>());
+                       v.back().push_back(n);
+               }
+       }
+       return v;
+}