]> ruin.nu Git - germs.git/blob - src/genealgorithms.cpp
154df354bc346592f53a1373b49bbc1c72a0b79d
[germs.git] / src / genealgorithms.cpp
1 /***************************************************************************
2  *   Copyright (C) 2006 by Michael Andreen                                 *
3  *   andreen@student.chalmers.se                                           *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA          *
19  ***************************************************************************/
20
21 #include "genealgorithms.h"
22 #include "geneorder.h"
23
24 #include <algorithm>
25 #include <cstdlib>
26 using namespace std;
27
28 std::pair<int,int> longestSequences(const GeneOrder& go){
29 }
30
31
32 /*
33 robSche2 :: [Int] -> [[Int]] -> [[Int]]
34 robSche2 [] ys = ys
35 robSche2 (x:xs) ys = robSche2 xs $ robSche4 x ys
36
37 robSche3 :: Int -> [Int] -> (Maybe Int,[Int])
38 robSche3 x ys = let yless = [y | y <- ys, y < x] in
39         let ymore = [y | y <- ys, y > x] in
40                 case ymore of
41                         [] -> (Nothing, yless++[x])
42                         (y:ys) -> (Just y, yless++(x:ys))
43
44 robSche4 :: Int -> [[Int]] -> [[Int]]
45 robSche4 x [] = [[x]]
46 robSche4 x (y:ys) = case robSche3 x y of
47         (Nothing, y) -> y:ys
48         (Just x, y) -> y:robSche4 x ys
49 */
50 std::vector<std::vector<int> > robinsonSchensted(const GeneOrder& go){
51         vector<vector<int> > v;
52         for (GeneOrder::iterator i = go.begin(); i != go.end(); ++i){
53                 int n = abs(*i);
54                 bool added = false;
55                 for (vector<vector<int> >::iterator vs = v.begin();
56                                 vs != v.end(); ++vs){
57                         vector<int>::iterator bigger = upper_bound(vs->begin(),vs->end(),n);
58                         if ( bigger == vs->end()){
59                                 vs->push_back(n);
60                                 added = true;
61                                 break;
62                         }else{
63                                 swap(n,*bigger);
64                         }
65                 }
66                 if (!added){
67                         v.push_back(vector<int>());
68                         v.back().push_back(n);
69                 }
70         }
71         return v;
72 }