]> ruin.nu Git - germs.git/blob - src/geneorder.h
constructor for GeneOrder done
[germs.git] / src / geneorder.h
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 #ifndef __GENEORDER_H__
22 #define __GENEORDER_H__
23
24 #include <vector>
25 #include <stdexcept>
26
27 #include "misc.h"
28
29 /**
30  * Stores a gene order permutation and ensures that all genes are present and not duplicated.
31  * \author Michael Andreen
32 */
33 class GeneOrder{
34         public:
35
36                 typedef std::vector<long> GeneList;
37                 typedef GeneList::size_type size_type;
38
39                 /**
40                  * Creates a copy of the given gene order
41                  */
42                 GeneOrder(const GeneOrder& go);
43
44                 /**
45                  * Creates a gene order from a given list.
46                  *
47                  * \throws invalid_argument if the list is not a valid permutation.
48                  */
49                 template<class T>
50                 GeneOrder(T begin, T end);
51
52                 /**
53                  * Destroyes the gene order.
54                  */
55                 ~GeneOrder();
56
57                 /**
58                  * Copies the given gene order.
59                  */
60                 const GeneOrder& operator=(const GeneOrder& go);
61
62                 /**
63                  * Returns the gene at the given index.
64                  *
65                  * \throws out_of_range if i is smaller than 0 or too big.
66                  */
67                 const Gene& operator[](size_type i) const;
68
69                 /**
70                  * Returns the size of the permutation.
71                  */
72                 int size() const;
73
74                 /**
75                  * Returns the vector containing the gene order permutation.
76                  */
77                 const GeneList& list() const;
78
79
80         private:
81                 GeneList _geneorder;
82                 /**
83                  * pads the permutation with 0 in front and n+1 at the end if needed
84                  */
85                 void pad();
86
87                 /**
88                  * Verifies that the permutation starts with 0, ends with n+1 and that all genes i, 0 < i < n+1
89                  * are present, without duplication.
90                  */
91                 void verify();
92 };
93
94
95 /**
96  * Put all the genes in the list, check that all genes are included, pad with 0 and n+1 if needed.
97  * TODO: This is far from done atm
98  */
99 template<typename T>
100 GeneOrder::GeneOrder(T begin, T end): _geneorder(begin,end){
101         pad();
102         verify();
103 }
104
105 #endif
106