Generated on Wed Nov 1 15:04:43 2006 for Gecode by doxygen 1.4.5

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: 2006-03-31 10:27:07 +0200 (Fri, 31 Mar 2006) $ by $Author: schulte $
00010  *     $Revision: 3142 $
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                       Search::Stop* st) :
00032     Gecode::DFS<T>(s,c_d,a_d,st), root(s->clone()), best(NULL) {}
00033 
00034   template <class T>
00035   forceinline
00036   Restart<T>::~Restart(void) {
00037     delete best;
00038     delete root;
00039   }
00040 
00041   template <class T>
00042   forceinline T*
00043   Restart<T>::next(void) {
00044     if (best != NULL) {
00045       static_cast<T*>(root)->constrain(static_cast<T*>(best));
00046       this->e.clone++;
00047       this->e.reset(root->clone(true,this->e.propagate));
00048     }
00049     Space* b = this->e.explore();
00050     delete best;
00051     best = (b != NULL) ? b->clone() : NULL;
00052     return static_cast<T*>(b);
00053   }
00054 
00055 
00056 
00057 
00058   /*
00059    * Restart convenience
00060    *
00061    */
00062 
00063   template <class T>
00064   T*
00065   restart(T* s, unsigned int c_d, unsigned int a_d, Search::Stop* st) {
00066     Restart<T> b(s,c_d,a_d,st);
00067     T* l = NULL;
00068     while (T* n = b.next()) {
00069       delete l; l = n;
00070     }
00071     return l;
00072   }
00073 
00074 }
00075 
00076 // STATISTICS: search-any