X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=src%2Freverseaction.h;h=e0857803518b2d4aa5acaa72f0c7cfe89f41bf4f;hb=dcd966c5fca7dca53ca1f605f70f13f019d29771;hp=a7db6d460530082828fa26d59aa80cbe134d670d;hpb=d0abe1592fcbb10f4ac303e7b66c384624d4d439;p=germs.git diff --git a/src/reverseaction.h b/src/reverseaction.h index a7db6d4..e085780 100644 --- a/src/reverseaction.h +++ b/src/reverseaction.h @@ -22,34 +22,64 @@ #define __REVERSEACTION_H__ #include "sortaction.h" +#include "genealgorithms.h" +#include "geneorder.h" + +#include +#include + /** * Reverses an interval * * \author Michael Andreen */ -class ReverseAction : public SortAction{ +class ReverseAction : public SortActionImpl{ public: /** * Creates a new reverse action for the interval [i,j] */ - ReverseAction(size_t i, size_t j):_i(i),_j(j){} + ReverseAction(size_t i, size_t j): _i(i),_j(j){ + } + + ReverseAction(Interval i){ + _i = std::min(i.first,i.second); + _j = std::max(i.first,i.second)-1; + } /** - * Sort SortActions by score + * Applies the sort action on the gene order */ virtual GeneOrder& operator()(GeneOrder& go) const{ go.reverse(_i,_j); return go; } - virtual bool operator==(const SortAction& sa) const{ + virtual bool operator==(const SortActionImpl& sa) const{ if (const ReverseAction* psa = dynamic_cast(&sa)){ if (_i == psa->_i && _j == psa->_j) return true; } return false; } + + /** + * Gives a string representation of the action, for output + */ + virtual std::string toString() const{ + std::ostringstream os; + os << "[" << _i << "," << _j << "]"; + return os.str(); + } + + size_t i() const{ + return _i; + } + size_t j() const{ + return _j; + } + + private: size_t _i; size_t _j;