X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=src%2Fgenesorter.cpp;h=8126d6aaa5781336ab03ba3a822f4d72f4c8820d;hb=e81855989d0f0e124e0ec770b417bcb099959391;hp=5f8699c62d0991f504520713d18a517fc555a01f;hpb=d0abe1592fcbb10f4ac303e7b66c384624d4d439;p=germs.git diff --git a/src/genesorter.cpp b/src/genesorter.cpp index 5f8699c..8126d6a 100644 --- a/src/genesorter.cpp +++ b/src/genesorter.cpp @@ -24,12 +24,29 @@ #include "sortaction.h" #include "reverseaction.h" +#include "genealgorithms.h" + +#include using namespace std; -GeneSorter::ActionList GeneSorter::sort(const GeneOrder& go1){ - return ActionList(); +GeneSorter::ActionList GeneSorter::sort(const GeneOrder& go){ + ActionList al; + GeneOrder temp(go); + while(inversionDistance(go) > 0){ + ActionList safe = safeActions(go); + if (safe.size() > 0){ + safe[0](temp); + al.push_back(safe[0]); + }else + return ActionList(); //TODO: Need to handle hurdles. + } + return al; } -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(SortAction(new ReverseAction(2,3))); + return al; }