Generated on Thu Jul 6 07:06:48 2006 for Gecode by doxygen 1.4.7

bab.icc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Christian Schulte <schulte@gecode.org>
00004  *
00005  *  Contributing authors:
00006  *     Guido Tack <tack@gecode.org>
00007  *
00008  *  Copyright:
00009  *     Christian Schulte, 2004
00010  *     Guido Tack, 2004
00011  *
00012  *  Last modified:
00013  *     $Date: 2006-06-05 12:14:42 +0200 (Mon, 05 Jun 2006) $ by $Author: schulte $
00014  *     $Revision: 3264 $
00015  *
00016  *  This file is part of Gecode, the generic constraint
00017  *  development environment:
00018  *     http://www.gecode.org
00019  *
00020  *  See the file "LICENSE" for information on usage and
00021  *  redistribution of this file, and for a
00022  *     DISCLAIMER OF ALL WARRANTIES.
00023  *
00024  */
00025 
00026 namespace Gecode { 
00027 
00028   /*
00029    * BAB search engine
00030    *
00031    */
00032 
00033   namespace Search {
00034 
00035     forceinline
00036     BabEngine::BabEngine(unsigned int c_d0, unsigned int a_d,
00037                          Stop* st, size_t sz)
00038       : EngineCtrl(st,sz), ds(a_d), cur(NULL), mark(0), best(NULL), 
00039         c_d(c_d0), d(0) {}
00040     
00041     
00042     forceinline void
00043     BabEngine::init(Space* s) {
00044       cur = s;
00045     }
00046     
00047     forceinline size_t
00048     BabEngine::stacksize(void) const {
00049       return ds.size();
00050     }
00051 
00052     forceinline
00053     BabEngine::~BabEngine(void) {
00054       ds.reset();
00055       delete best;
00056       delete cur;
00057     }
00058   }
00059 
00060   /*
00061    * Control for bab search engine
00062    *
00063    */
00064   
00065   template <class T>
00066   forceinline
00067   BAB<T>::BAB(T* s, unsigned int c_d, unsigned int a_d, Search::Stop* st)
00068     : Search::BAB(s,c_d,a_d,st,sizeof(T)) {}
00069 
00070   template <class T>
00071   forceinline T*
00072   BAB<T>::next(void) {
00073     Space *s1, *s2;
00074     while (!e.explore(s1,s2))
00075       static_cast<T*>(s1)->constrain(static_cast<T*>(s2));
00076     return static_cast<T*>(s1);
00077   }
00078 
00079 
00080 
00081 
00082   /*
00083    * BAB convenience
00084    *
00085    */
00086 
00087   template <class T>
00088   T*
00089   bab(T* s, unsigned int c_d, unsigned int a_d, Search::Stop* st) {
00090     BAB<T> b(s,c_d,a_d,st);
00091     T* l = NULL;
00092     while (T* n = b.next()) {
00093       delete l; l = n;
00094     }
00095     return l;
00096   }
00097 
00098 }
00099 
00100 // STATISTICS: search-any