src/biu/PullMoveSet.hh
Go to the documentation of this file.00001 #ifndef PULLMOVESET_HH_
00002 #define PULLMOVESET_HH_
00003
00004 #include "LatticeMoveSet.hh"
00005 #include "LatticeProtein.hh"
00006 #include <vector>
00007
00008 namespace biu
00009 {
00010
00016 class PullMoveSet : public LatticeMoveSet
00017 {
00018 public:
00025 class PullMoveDecoder
00026 {
00027 protected:
00029 const biu::LatticeModel* const lattice;
00030
00032 IPointVec neighDirections;
00033
00035 std::vector< std::vector< IPointVec > > stdPulls;
00036
00038 std::vector< IPointVec > endPulls;
00039
00041 size_t directionNumber;
00042
00044 size_t stdPullNumber;
00046 size_t endPullNumber;
00047
00048 public:
00052 PullMoveDecoder(const LatticeModel* const lattice);
00053
00058 void lookupMove(const size_t& proteinLength,
00059 size_t& moveIndex, bool& pullFront,
00060 bool& stdPull, size_t& movePosition) const;
00066 IPointVec lookupStdMove(const IntPoint& rootpoint,
00067 const IntPoint& fixpoint,
00068 const size_t& moveIndex) const;
00069
00073 IPointVec lookupEndMove(const IntPoint& rootpoint,
00074 const size_t& moveIndex) const;
00075
00080 size_t getMoveNumber(const size_t proteinLength) const;
00081
00082 const LatticeModel* const getLattice(void) const;
00083 };
00084
00085 private:
00092 class RelativeInt
00093 {
00094 private:
00100 class Operators {
00101 public:
00102 virtual ~Operators() {}
00103
00109 virtual const int add(const int& a, const int& b) const = 0;
00110
00116 virtual const int sub(const int& a, const int& b) const = 0;
00117
00123 virtual const bool largerEq(const int& a, const int& b) const = 0;
00124
00130 virtual const bool smallerEq(const int& a, const int& b) const = 0;
00131 };
00132
00139 class StdOps : public Operators {
00140 public:
00141 virtual const int add(const int& a, const int& b) const
00142 { return a + b; }
00143 virtual const int sub(const int& a, const int& b) const
00144 { return a - b; }
00145 virtual const bool largerEq(const int& a, const int& b) const
00146 { return a >= b; }
00147 virtual const bool smallerEq(const int& a, const int& b) const
00148 { return a <= b; }
00149 };
00150
00157 class InvOps : public Operators {
00158 virtual const int add(const int& a, const int& b) const
00159 { return a - b; }
00160 virtual const int sub(const int& a, const int& b) const
00161 { return a + b; }
00162 virtual const bool largerEq(const int& a, const int& b) const
00163 { return a <= b; }
00164 virtual const bool smallerEq(const int& a, const int& b) const
00165 { return a >= b; }
00166 };
00167
00169 Operators* ops;
00171 int value;
00172
00173 public:
00177 RelativeInt(int _value, bool direction) : value(_value) {
00178 if (direction)
00179 ops=new PullMoveSet::RelativeInt::StdOps();
00180 else
00181 ops=new PullMoveSet::RelativeInt::InvOps();
00182 }
00183
00184 ~RelativeInt() { delete ops; }
00185
00186 const bool
00187 operator >= (const int& y) const { return ops->largerEq(value,y); }
00188
00189 const bool
00190 operator <= (const int& y) const { return ops->smallerEq(value,y); }
00191
00192 const int
00193 operator+ (const int& y) const { return ops->add(value,y); }
00194
00195 const int
00196 operator- (const int& y) const { return ops->sub(value,y); }
00197
00198 void
00199 operator --(int) { value = ops->sub(value,1); }
00200
00201 void
00202 operator ++(int) { value = ops->add(value,1); }
00203
00204 const int
00205 getValue() const { return value; };
00206 };
00207
00208 protected:
00209 struct UndoRecord
00210 {
00212 LatticeProtein* lastChangedObject;
00214 bool hasChanged;
00216 bool pullFront;
00218 size_t position;
00220 size_t lastPullPosition;
00222 IntPoint lostPos0;
00224 IntPoint lostPos1;
00225 } undoRec;
00226
00228 PullMoveSet::PullMoveDecoder* decoder;
00229
00231 const bool decoderIsShared;
00232
00233 public:
00234
00239 PullMoveSet(const LatticeModel* lattice);
00240
00249 PullMoveSet(PullMoveDecoder* decoder, const bool decoderIsShared);
00250
00251 PullMoveSet(const PullMoveSet& moveSet);
00252 PullMoveSet& operator=(const PullMoveSet& moveSet2);
00253
00254 PullMoveSet* clone();
00255
00256 virtual ~PullMoveSet();
00257
00270 virtual LatticeProtein* applyMove(const LatticeProtein* const todo,
00271 const size_t moveIndex);
00272
00282 virtual LatticeProtein* applyMoveInPlace(LatticeProtein* const todo,
00283 const size_t moveIndex);
00284
00288 size_t getMoveNumber ( const LatticeProtein* const lp) const;
00289
00294 virtual LatticeProtein* undoLastMove(LatticeProtein* toUndo);
00295
00298 virtual const PullMoveDecoder* const getDecoder(void) const;
00299 };
00300
00301 }
00302
00303 #endif