ADD_DEFINITIONS(-Wall -O2)
INCLUDE_DIRECTORIES(.)
-ADD_EXECUTABLE(../bin/genesort main.cpp GeneOrder.cpp)
+ADD_EXECUTABLE(../bin/genesort main.cpp geneorder.cpp)
TARGET_LINK_LIBRARIES(../bin/genesort doublefann)
+++ /dev/null
-/***************************************************************************
- * 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 "GeneOrder.h"
-
-using namespace std;
-
-/**
- * \file GeneOrder.cpp
- * Implements the GeneOrder class
- *
- * \author Michael Andreen
- */
-
-
-
-GeneOrder::GeneOrder(const GeneOrder& go){
- _geneorder = go._geneorder;
-}
-
-
-GeneOrder::~GeneOrder(){
-}
-
-const GeneOrder& GeneOrder::operator=(const GeneOrder& go){
- _geneorder = go._geneorder;
- return *this;
-}
-
-/**
- * Check so i is in the valid range, then return the gene.
- */
-const Gene& GeneOrder::operator[](size_type i) const{
- if (i < 0 || i >= _geneorder.size())
- throw out_of_range("Index is not in valid range");
- return _geneorder[i];
-}
-
-int GeneOrder::size() const{
- return _geneorder.size();
-}
-
-const GeneOrder::GeneList& GeneOrder::list() const{
- return _geneorder;
-}
+++ /dev/null
-/***************************************************************************
- * 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 *
- ***************************************************************************/
-
-#ifndef __GENEORDER_H__
-#define __GENEORDER_H__
-
-#include <vector>
-#include <stdexcept>
-#include <cstdlib>
-
-#include "misc.h"
-
-/**
- * Stores a gene order permutation and ensures that all genes are present and not duplicated.
- * \author Michael Andreen
-*/
-class GeneOrder{
- public:
-
- typedef std::vector<Gene> GeneList;
- typedef GeneList::size_type size_type;
-
- /**
- * Creates a copy of the given gene order
- */
- GeneOrder(const GeneOrder& go);
-
- /**
- * Creates a gene order from a given list.
- *
- * \throws invalid_argument if the list is not a valid permutation.
- */
- template<class T>
- GeneOrder(T begin, T end);
-
- /**
- * Destroyes the gene order.
- */
- ~GeneOrder();
-
- /**
- * Copies the given gene order.
- */
- const GeneOrder& operator=(const GeneOrder& go);
-
- /**
- * Returns the gene at the given index.
- *
- * \throws out_of_range if i is smaller than 0 or too big.
- */
- const Gene& operator[](size_type i) const;
-
- /**
- * Returns the size of the permutation.
- */
- int size() const;
-
- /**
- * Returns the vector containing the gene order permutation.
- */
- const GeneList& list() const;
-
- /**
- * Reverses an interval and returns the new permutation
- */
- GeneOrder reverse(size_type i, size_type j) const;
-
- /**
- * Moves the gene on position i to position j, returning a new permutation
- */
- GeneOrder transpos(size_type i, size_type j) const;
-
- private:
- GeneList _geneorder;
-};
-
-
-/**
- * Put all the genes in the list, check that all genes are included, pad with 0 and n+1 if needed.
- * TODO: This is far from done atm
- */
-template<typename T>
-GeneOrder::GeneOrder(T begin, T end): _geneorder(begin,end){
-
- /*TODO: Pad code, just not sure if I need it all the time.
- if (_geneorder[0] != 0)
- _geneorder.insert(_geneorder.begin(),0);
- if(_geneorder[_geneorder.size()-1] != _geneorder.size() - 1)
- _geneorder.push_back(_geneorder.size());
- */
-
- GeneList genes(_geneorder.size());
- for (GeneList::iterator gene = _geneorder.begin(); gene != _geneorder.end(); ++gene){
- ++genes[std::abs(*gene)];
- }
- for (GeneList::iterator gene = genes.begin(); gene != genes.end(); ++gene){
- if (*gene != 1)
- throw std::invalid_argument("Not all genes are present only 1 time");
- }
-}
-
-#endif
-
+++ /dev/null
-/***************************************************************************
- * 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 *
- ***************************************************************************/
-
-#ifndef __GENESORTER_H__
-#define __GENESORTER_H__
-
-#include "GeneOrder.h"
-#include "SortAction.h"
-
-#include <vector>
-
-
-/**
- * Abstract baseclass for different gene sorters.
- * \author Michael Andreen
- */
-class GeneSorter{
- public:
- typedef std::vector<SortAction> ActionList;
-
- /**
- * Takes a GeneOrder, finds the actions to transform it into a sorted
- * permutation and returns the list with required actions.
- */
- virtual ActionList sort(const GeneOrder& go1) = 0;
-
- /**
- * Find the safe actions for this GeneOrder.
- */
- virtual ActionList safeActions(const GeneOrder& go1) = 0;
-
- virtual ~GeneSorter(){};
-};
-
-#endif
-
+++ /dev/null
-/***************************************************************************
- * 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 *
- ***************************************************************************/
-
-#ifndef __MODELIDENTIFIER_H__
-#define __MODELIDENTIFIER_H__
-
-#include "GeneOrder.h"
-
-#include <map>
-
-
-/**
- * Identifies the model this gene order belongs to
- * \author Michael Andreen
- */
-class ModelIdentifier{
- public:
- enum Model{Whirl,X,FatX,Zipper,Cloud};
-
- /**
- * Identifies the model for a given gene order.
- * \returns a map with the model as key and the score between 0 and 1
- */
- std::map<Model,double> identify(const GeneOrder& go);
-
- virtual ~ModelIdentifier(){};
-};
-
-#endif
-
+++ /dev/null
-/***************************************************************************
- * 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 *
- ***************************************************************************/
-
-#ifndef __SORTACTION_H__
-#define __SORTACTION_H__
-
-/**
- * Abstraction of a sort action, keeping track of score
- *
- * \author Michael Andreen
- */
-class SortAction{
- public:
-
- virtual ~SortAction(){};
-
- /**
- * Sort SortActions by score
- */
- virtual operator<(const SortAction& sa) const;
-};
-
-#endif
-
--- /dev/null
+/***************************************************************************
+ * 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 "geneorder.h"
+
+using namespace std;
+
+/**
+ * \file GeneOrder.cpp
+ * Implements the GeneOrder class
+ *
+ * \author Michael Andreen
+ */
+
+
+
+GeneOrder::GeneOrder(const GeneOrder& go){
+ _geneorder = go._geneorder;
+}
+
+
+GeneOrder::~GeneOrder(){
+}
+
+const GeneOrder& GeneOrder::operator=(const GeneOrder& go){
+ _geneorder = go._geneorder;
+ return *this;
+}
+
+/**
+ * Check so i is in the valid range, then return the gene.
+ */
+const Gene& GeneOrder::operator[](size_type i) const{
+ if (i < 0 || i >= _geneorder.size())
+ throw out_of_range("Index is not in valid range");
+ return _geneorder[i];
+}
+
+int GeneOrder::size() const{
+ return _geneorder.size();
+}
+
+const GeneOrder::GeneList& GeneOrder::list() const{
+ return _geneorder;
+}
--- /dev/null
+/***************************************************************************
+ * 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 *
+ ***************************************************************************/
+
+#ifndef __GENEORDER_H__
+#define __GENEORDER_H__
+
+#include <vector>
+#include <stdexcept>
+#include <cstdlib>
+
+#include "misc.h"
+
+/**
+ * Stores a gene order permutation and ensures that all genes are present and not duplicated.
+ * \author Michael Andreen
+*/
+class GeneOrder{
+ public:
+
+ typedef std::vector<Gene> GeneList;
+ typedef GeneList::size_type size_type;
+
+ /**
+ * Creates a copy of the given gene order
+ */
+ GeneOrder(const GeneOrder& go);
+
+ /**
+ * Creates a gene order from a given list.
+ *
+ * \throws invalid_argument if the list is not a valid permutation.
+ */
+ template<class T>
+ GeneOrder(T begin, T end);
+
+ /**
+ * Destroyes the gene order.
+ */
+ ~GeneOrder();
+
+ /**
+ * Copies the given gene order.
+ */
+ const GeneOrder& operator=(const GeneOrder& go);
+
+ /**
+ * Returns the gene at the given index.
+ *
+ * \throws out_of_range if i is smaller than 0 or too big.
+ */
+ const Gene& operator[](size_type i) const;
+
+ /**
+ * Returns the size of the permutation.
+ */
+ int size() const;
+
+ /**
+ * Returns the vector containing the gene order permutation.
+ */
+ const GeneList& list() const;
+
+ /**
+ * Reverses an interval and returns the new permutation
+ */
+ GeneOrder reverse(size_type i, size_type j) const;
+
+ /**
+ * Moves the gene on position i to position j, returning a new permutation
+ */
+ GeneOrder transpos(size_type i, size_type j) const;
+
+ private:
+ GeneList _geneorder;
+};
+
+
+/**
+ * Put all the genes in the list, check that all genes are included, pad with 0 and n+1 if needed.
+ * TODO: This is far from done atm
+ */
+template<typename T>
+GeneOrder::GeneOrder(T begin, T end): _geneorder(begin,end){
+
+ /*TODO: Pad code, just not sure if I need it all the time.
+ if (_geneorder[0] != 0)
+ _geneorder.insert(_geneorder.begin(),0);
+ if(_geneorder[_geneorder.size()-1] != _geneorder.size() - 1)
+ _geneorder.push_back(_geneorder.size());
+ */
+
+ GeneList genes(_geneorder.size());
+ for (GeneList::iterator gene = _geneorder.begin(); gene != _geneorder.end(); ++gene){
+ ++genes[std::abs(*gene)];
+ }
+ for (GeneList::iterator gene = genes.begin(); gene != genes.end(); ++gene){
+ if (*gene != 1)
+ throw std::invalid_argument("Not all genes are present only 1 time");
+ }
+}
+
+#endif
+
--- /dev/null
+/***************************************************************************
+ * 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 *
+ ***************************************************************************/
+
+#ifndef __GENESORTER_H__
+#define __GENESORTER_H__
+
+#include "geneorder.h"
+#include "sortaction.h"
+
+#include <vector>
+
+
+/**
+ * Abstract baseclass for different gene sorters.
+ * \author Michael Andreen
+ */
+class GeneSorter{
+ public:
+ typedef std::vector<SortAction> ActionList;
+
+ /**
+ * Takes a GeneOrder, finds the actions to transform it into a sorted
+ * permutation and returns the list with required actions.
+ */
+ virtual ActionList sort(const GeneOrder& go1) = 0;
+
+ /**
+ * Find the safe actions for this GeneOrder.
+ */
+ virtual ActionList safeActions(const GeneOrder& go1) = 0;
+
+ virtual ~GeneSorter(){};
+};
+
+#endif
+
--- /dev/null
+/***************************************************************************
+ * 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 *
+ ***************************************************************************/
+
+#ifndef __MODELIDENTIFIER_H__
+#define __MODELIDENTIFIER_H__
+
+#include "geneorder.h"
+
+#include <map>
+
+
+/**
+ * Identifies the model this gene order belongs to
+ * \author Michael Andreen
+ */
+class ModelIdentifier{
+ public:
+ enum Model{Whirl,X,FatX,Zipper,Cloud};
+
+ /**
+ * Identifies the model for a given gene order.
+ * \returns a map with the model as key and the score between 0 and 1
+ */
+ std::map<Model,double> identify(const GeneOrder& go);
+
+ virtual ~ModelIdentifier(){};
+};
+
+#endif
+
--- /dev/null
+/***************************************************************************
+ * 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 *
+ ***************************************************************************/
+
+#ifndef __SORTACTION_H__
+#define __SORTACTION_H__
+
+/**
+ * Abstraction of a sort action, keeping track of score
+ *
+ * \author Michael Andreen
+ */
+class SortAction{
+ public:
+
+ virtual ~SortAction(){};
+
+ /**
+ * Sort SortActions by score
+ */
+ virtual operator<(const SortAction& sa) const;
+};
+
+#endif
+