Generated on Wed Jan 4 17:49:13 2006 for Gecode by doxygen 1.4.6

restart.icc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Christian Schulte <schulte@gecode.org>
00004  *
00005  *  Copyright:
00006  *     Christian Schulte, 2004
00007  *
00008  *  Last modified:
00009  *     $Date: 2005-07-28 22:52:19 +0200 (Thu, 28 Jul 2005) $ by $Author: schulte $
00010  *     $Revision: 2072 $
00011  *
00012  *  This file is part of Gecode, the generic constraint
00013  *  development environment:
00014  *     http://www.gecode.org
00015  *
00016  *  See the file "LICENSE" for information on usage and
00017  *  redistribution of this file, and for a
00018  *     DISCLAIMER OF ALL WARRANTIES.
00019  *
00020  */
00021 
00022 namespace Gecode {
00023 
00024   /*
00025    * Control for restart best solution search engine
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    * Restart convenience
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 // STATISTICS: search-any