From 8827131c37c21740b5ac8acf6da9ff598de3f166 Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Sun, 24 Jun 2007 13:42:06 +0000 Subject: [PATCH] minor things --- src/genesorter.cpp | 15 +++++++++++++-- src/test/genesortertest.cpp | 7 +++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/genesorter.cpp b/src/genesorter.cpp index 40e62e5..8643702 100644 --- a/src/genesorter.cpp +++ b/src/genesorter.cpp @@ -26,16 +26,27 @@ #include "genealgorithms.h" +#include 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; } diff --git a/src/test/genesortertest.cpp b/src/test/genesortertest.cpp index 479db46..6a58ce2 100644 --- a/src/test/genesortertest.cpp +++ b/src/test/genesortertest.cpp @@ -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)); } }; -- 2.39.2