1 /***************************************************************************
2 * Copyright (C) 2006 by Michael Andreen *
3 * andreen@student.chalmers.se *
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. *
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. *
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 ***************************************************************************/
21 #include <geneorder.h>
30 * Implements the GeneOrder class
32 * \author Michael Andreen
37 GeneOrder::GeneOrder(const GeneOrder& go){
38 _geneorder = go._geneorder;
41 void GeneOrder::pad(){
42 if (_geneorder[0] != 0)
43 _geneorder.insert(_geneorder.begin(),0);
44 if(_geneorder.back() != static_cast<Gene>(_geneorder.size() - 1))
45 _geneorder.push_back(_geneorder.size());
49 Gene operator()(Gene x) const{
54 void GeneOrder::verify(){
55 if(_geneorder[0] != 0)
56 throw std::invalid_argument("Permutation doesn't start with 0");
57 if ( _geneorder.back() != static_cast<Gene>(_geneorder.size() - 1))
58 throw std::invalid_argument("Permutation doesn't end with n+1");
59 GeneList genes(_geneorder);
60 transform(genes.begin(),genes.end(),genes.begin(),test());
61 sort(genes.begin(),genes.end());
62 if (unique(genes.begin(),genes.end()) != genes.end())
63 throw std::invalid_argument("Not all genes are present exactly 1 time");
67 GeneOrder::~GeneOrder(){
70 const GeneOrder& GeneOrder::operator=(const GeneOrder& go){
71 _geneorder = go._geneorder;
76 * Check so i is in the valid range, then return the gene.
78 const Gene& GeneOrder::operator[](size_type i) const{
79 if (i < 0 || i >= _geneorder.size())
80 throw out_of_range("Index is not in valid range");
84 int GeneOrder::size() const{
85 return _geneorder.size();
88 const GeneOrder::GeneList& GeneOrder::list() const{