Generated on Tue Dec 16 13:34:01 2008 for ell-3.0.0 by doxygen 1.5.1

src/ell/NeighborGenerator.cc

Go to the documentation of this file.
00001 #include "ell/NeighborGenerator.hh"
00002 #include "ell/State.hh"
00003 #include <biu/assertbiu.hh>
00004 
00005 namespace ell {
00006 
00007     NG_Random::NeighborList::NeighborList(const State* _origin) 
00008         :origin(_origin)
00009     {}
00010     
00011     NG_Random::NeighborList::~NeighborList() {}
00012     
00013     State*
00014     NG_Random::NeighborList::first(State::NeighborList::ItState** itstate) const
00015     {
00016         State* newstate = NULL;
00017         do newstate = origin->getRandomNeighbor(newstate);
00018         while (newstate == NULL);
00019         return newstate;
00020     }
00021     
00022     State*
00023     NG_Random::NeighborList::next(  State::NeighborList::ItState* itstate, 
00024                                     State* elem) const
00025     {
00026         assertbiu(elem != NULL, "Elem is not allowed to be NULL");
00027 
00028         delete elem;
00029         State* nextstate = NULL;
00030         do nextstate = origin->getRandomNeighbor(nextstate);
00031         while (nextstate == NULL);
00032         return nextstate;
00033         
00034         // TODO: reuse elem for better performance, but segfaults
00035 //      State* nextstate = NULL;
00036 //      do nextstate = origin->getRandomNeighbor(elem);
00037 //      while (nextstate == NULL);
00038 //      elem = nextstate;
00039 //      return elem;
00040     }
00041     
00042     State::NeighborListPtr 
00043     NG_Random::getNeighborList(const State* const s) const
00044     {
00045         return State::NeighborListPtr(new NG_Random::NeighborList(s));
00046     }
00047     
00048     State::NeighborListPtr 
00049     NG_SuccessiveRandom::getNeighborList(const State* const s) const
00050     {
00051         return s->getRandomNeighborList();
00052     }
00053 
00054     State::NeighborListPtr 
00055     NG_Successive::getNeighborList(const State* const s) const
00056     {
00057         return s->getNeighborList();
00058     }
00059     
00060 } // namespace ell