- Main Page
- Classes
- Files

- File List

# OptFrame/Util/NSSeqkRouteAdapter.hpp

    00001 #ifndef OPTFRAME_NSSEQkROUTEADAPTER_HPP_
    00002 #define OPTFRAME_NSSEQkROUTEADAPTER_HPP_
    00003
    00004 // Framework includes
    00005 #include "../Move.hpp"
    00006 #include "../NSSeq.hpp"
    00007
    00008 using namespace std;
    00009
    00010 template<class T, class M>
    00011 class MovekRoute: public Move<vector<vector<T> > , M>
    00012 {
    00013         typedef vector<T> Route;
    00014         typedef vector<vector<T> > MultiRoute;
    00015
    00016 protected:
    00017         int k; // route number
    00018         Move<Route, M>& m;
    00019
    00020 public:
    00021
    00022         MovekRoute(int _k, Move<Route, M>& _m) :
    00023                 k(_k), m(_m)
    00024         {
    00025         }
    00026
    00027         virtual ~MovekRoute()
    00028         {
    00029                 delete &m;
    00030         }
    00031
    00032         bool canBeApplied(const MultiRoute& rep)
    00033         {
    00034                 return m.canBeApplied(rep[k]);
    00035         }
    00036
    00037         Move<MultiRoute, M>& apply(MultiRoute& rep)
    00038         {
    00039                 return *new MovekRoute<T, M> (k, m.apply(rep[k]));
    00040         }
    00041
    00042         Move<MultiRoute, M>& apply(M& mem, MultiRoute& rep)
    00043         {
    00044                 return *new MovekRoute<T, M> (k, m.apply(mem, rep[k]));
    00045         }
    00046
    00047         virtual bool operator==(const Move<MultiRoute, M>& _m) const
    00048         {
    00049                 const MovekRoute<T, M>& m1 = (const MovekRoute<T, M>&) _m;
    00050                 if (k == m1.k)
    00051                         return m == m1.m;
    00052                 else
    00053                         return false;
    00054         }
    00055
    00056         void print()
    00057         {
    00058                 cout << "MovekRoute: k=" << k << "; move = ";
    00059                 m.print();
    00060         }
    00061 };
    00062
    00063 template<class T, class M = OPTFRAME_DEFAULT_MEMORY, class MOVE = MovekRoute<T, M> >
    00064 class IteratorNSSeqkRoute: public NSIterator<vector<vector<T> > , M>
    00065 {
    00066         typedef vector<T> Route;
    00067         typedef vector<vector<T> > MultiRoute;
    00068
    00069 private:
    00070         int k;
    00071         NSIterator<Route, M>& iterator;
    00072
    00073 public:
    00074
    00075         IteratorNSSeqkRoute(int _k, NSIterator<Route, M>& it) :
    00076                 k(_k), iterator(it)
    00077         {
    00078         }
    00079
    00080         virtual ~IteratorNSSeqkRoute()
    00081         {
    00082                 delete &iterator;
    00083         }
    00084
    00085         void first()
    00086         {
    00087                 iterator.first();
    00088         }
    00089
    00090         void next()
    00091         {
    00092                 iterator.next();
    00093         }
    00094
    00095         bool isDone()
    00096         {
    00097                 return iterator.isDone();
    00098         }
    00099
    00100         Move<MultiRoute, M>& current()
    00101         {
    00102                 return *new MOVE(k, iterator.current());
    00103         }
    00104 };
    00105
    00106 template<class T, class M = OPTFRAME_DEFAULT_MEMORY, class MOVE = MovekRoute<T, M> >
    00107 class NSSeqkRouteAdapter: public NSSeq<vector<vector<T> > , M>
    00108 {
    00109         typedef vector<T> Route;
    00110         typedef vector<vector<T> > MultiRoute;
    00111
    00112 private:
    00113         int k;
    00114         NSSeq<Route, M>& ns;
    00115
    00116 public:
    00117
    00118         NSSeqkRouteAdapter(int _k, NSSeq<Route, M>& _ns) :
    00119                 k(_k), ns(_ns)
    00120         {
    00121         }
    00122
    00123         virtual ~NSSeqkRouteAdapter()
    00124         {
    00125         }
    00126
    00127         Move<MultiRoute, M>& move(const MultiRoute& r)
    00128         {
    00129                 return *new MOVE(k, ns.move(r[k]));
    00130         }
    00131
    00132         virtual NSIterator<MultiRoute, M>& getIterator(const MultiRoute& r)
    00133         {
    00134                 NSIterator<Route, M>& iterator = ns.getIterator(r[k]);
    00135                 return *new IteratorNSSeqkRoute<T, M, MOVE> (k, iterator);
    00136         }
    00137
    00138         virtual void print()
    00139         {
    00140                 cout << "NSSeqkRouteAdapter {" << endl;
    00141                 ns.print();
    00142                 cout << "}" << endl;
    00143         }
    00144 };
    00145
    00146 #endif /*OPTFRAME_NSSEQkROUTEADAPTER_HPP_*/

All Classes Functions