]> ruin.nu Git - germs.git/commitdiff
we need a list of smart pointers
authorMichael Andreen <harv@ruin.nu>
Sun, 24 Jun 2007 11:38:15 +0000 (11:38 +0000)
committerMichael Andreen <harv@ruin.nu>
Sun, 24 Jun 2007 11:38:15 +0000 (11:38 +0000)
src/genesorter.cpp
src/genesorter.h
src/reverseaction.h
src/test/genesortertest.cpp

index 5f8699c62d0991f504520713d18a517fc555a01f..1e199843a1a5ecedcbf692fc6da5117dafa4ce8e 100644 (file)
 #include "sortaction.h"
 #include "reverseaction.h"
 
+#include "genealgorithms.h"
+
 using namespace std;
 
-GeneSorter::ActionList GeneSorter::sort(const GeneOrder& go1){
+GeneSorter::ActionList GeneSorter::sort(const GeneOrder& go){
        return ActionList();
 }
 
-GeneSorter::ActionList GeneSorter::safeActions(const GeneOrder& go1){
-       return ActionList();
+GeneSorter::ActionList GeneSorter::safeActions(const GeneOrder& go){
+       if (countCycles(go) == go.size() - 1)
+               return ActionList();
+       ActionList al;
+       al.push_back(ActionPointer(new ReverseAction(2,3)));
+       return al;
 }
index 384261196060dfaa19522a7deadc68e28784e6d1..402464bcc4b8555d3d0c6541dc2ab21aa4fc18f3 100644 (file)
@@ -22,6 +22,7 @@
 #define __GENESORTER_H__
 
 #include <vector>
+#include <tr1/memory>
 
 class SortAction;
 class GeneOrder;
@@ -33,7 +34,8 @@ class GeneOrder;
  */
 class GeneSorter{
        public:
-               typedef std::vector<SortAction> ActionList;
+               typedef std::tr1::shared_ptr<SortAction> ActionPointer;
+               typedef std::vector<ActionPointer> ActionList;
 
                /**
                 * Takes a GeneOrder, finds the actions to transform it into a sorted
index a7db6d460530082828fa26d59aa80cbe134d670d..0d8ac91999e02d3f5bf2b3d1058854e3dcb76fb9 100644 (file)
@@ -36,7 +36,7 @@ class ReverseAction : public SortAction{
                ReverseAction(size_t i, size_t j):_i(i),_j(j){}
 
                /**
-                * Sort SortActions by score
+                * Applies the sort action on the gene order
                 */
                virtual GeneOrder& operator()(GeneOrder& go) const{
                        go.reverse(_i,_j);
index a2c4faeaf93b0987d5fc7f406b83c19e6fb85b76..b06191827c58376cd50e31346094dea7e05d7280 100644 (file)
@@ -62,11 +62,18 @@ protected:
                GeneOrder go2(_validPerm2.begin(),_validPerm2.end());
                al = so.sort(go2);
                CPPUNIT_ASSERT_EQUAL(1ul,al.size());
-               CPPUNIT_ASSERT(al[0] == ReverseAction(2,3));
+               CPPUNIT_ASSERT((*al[0]) == ReverseAction(2,3));
+
+               (*al[0])(go2);
+               CPPUNIT_ASSERT(equal(go.begin(),go.end(),go2.begin()));
 
                GeneOrder go3(_validPerm3.begin(),_validPerm3.end());
                al = so.sort(go3);
                CPPUNIT_ASSERT_EQUAL(5ul,al.size());
+               for (size_t i = 0; i < al.size(); ++i)
+                       (*al[i])(go3);
+               int perm[] = {0,1,2,3,4,5,6,7,8,9};
+               CPPUNIT_ASSERT(equal(go3.begin(),go3.end(),perm));
        }
        void testSafeActions (){
                GeneSorter so;
@@ -77,7 +84,8 @@ protected:
                GeneOrder go2(_validPerm2.begin(),_validPerm2.end());
                al = so.safeActions(go2);
                CPPUNIT_ASSERT_EQUAL(1ul,al.size());
-               CPPUNIT_ASSERT(al[0] == ReverseAction(2,3));
+               CPPUNIT_ASSERT((*al[0]) == ReverseAction(2,3));
+               CPPUNIT_ASSERT(!((*al[0]) == ReverseAction(2,5)));
        }
 
 };