]> ruin.nu Git - germs.git/commitdiff
minor things
authorMichael Andreen <harv@ruin.nu>
Sun, 24 Jun 2007 13:42:06 +0000 (13:42 +0000)
committerMichael Andreen <harv@ruin.nu>
Sun, 24 Jun 2007 13:42:06 +0000 (13:42 +0000)
src/genesorter.cpp
src/test/genesortertest.cpp

index 40e62e5b8bab62ae58e55fdc85f0c2f7a486380e..8643702250f82ac6b90bbfd08f6b65aaf0e85ee2 100644 (file)
 
 #include "genealgorithms.h"
 
+#include <queue>
 using namespace std;
 
 GeneSorter::ActionList GeneSorter::sort(const GeneOrder& go){
-       return ActionList();
+       ActionList al;
+       GeneOrder temp(go);
+       while(countCycles(temp) != temp.size() - 1){
+               ActionList safe = safeActions(go);
+               if (safe.size() > 0){
+                       safe[0](temp);
+                       al.push_back(safe[0]);
+               }else
+                       return ActionList(); //TODO: Need to handle other cases here.
+       }
+       return al;
 }
 
 GeneSorter::ActionList GeneSorter::safeActions(const GeneOrder& go){
        if (countCycles(go) == go.size() - 1)
                return ActionList();
        ActionList al;
-       al.push_back(SortAction(new ReverseAction(2,3)));
+       //al.push_back(SortAction(new ReverseAction(2,3)));
        return al;
 }
index 479db468e25d97d048d5c7cb9acdc54bdd54cb3c..6a58ce2b8fb6e8fa0ecace92a3542d2823545c83 100644 (file)
@@ -86,6 +86,13 @@ protected:
                CPPUNIT_ASSERT_EQUAL(1ul,al.size());
                CPPUNIT_ASSERT(al[0] == ReverseAction(2,3));
                CPPUNIT_ASSERT(!(al[0] == ReverseAction(2,5)));
+
+               GeneOrder go3(_validPerm3.begin(),_validPerm3.end());
+               al = so.safeActions(go3);
+               CPPUNIT_ASSERT(al.size() > 0);
+               size_t cycles = countCycles(go3);
+               al[0](go3);
+               CPPUNIT_ASSERT(cycles < countCycles(go3));
        }
 
 };