restart.icc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 namespace Gecode {
00023
00024
00025
00026
00027
00028
00029 template <class T>
00030 Restart<T>::Restart(T* s, unsigned int c_d, unsigned int a_d) :
00031 DFS<T>(s,c_d,a_d), root(s->clone()), best(NULL) {}
00032
00033 template <class T>
00034 forceinline
00035 Restart<T>::~Restart(void) {
00036 delete best;
00037 delete root;
00038 }
00039
00040 template <class T>
00041 forceinline T*
00042 Restart<T>::next(void) {
00043 if (best != NULL) {
00044 static_cast<T*>(root)->constrain(static_cast<T*>(best));
00045 this->e->clone++;
00046 this->e->reset(root->clone(true,this->e->propagate));
00047 }
00048 Space* b = this->e->explore();
00049 delete best;
00050 best = (b != NULL) ? b->clone() : NULL;
00051 return static_cast<T*>(b);
00052 }
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 template <class T>
00063 T*
00064 restart(T* s, unsigned int c_d, unsigned int a_d) {
00065 Restart<T> b(s,c_d,a_d);
00066 T* l = NULL;
00067 while (T* n = b.next()) {
00068 delete l; l = n;
00069 }
00070 return l;
00071 }
00072
00073 }
00074
00075