Generated on Wed Mar 13 11:48:33 2013 for Gecode by doxygen 1.6.3

search.hh

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *     Guido Tack <tack@gecode.org>
00006  *
00007  *  Copyright:
00008  *     Christian Schulte, 2002
00009  *     Guido Tack, 2004
00010  *
00011  *  Last modified:
00012  *     $Date: 2013-03-08 11:11:37 +0100 (Fri, 08 Mar 2013) $ by $Author: schulte $
00013  *     $Revision: 13482 $
00014  *
00015  *  This file is part of Gecode, the generic constraint
00016  *  development environment:
00017  *     http://www.gecode.org
00018  *
00019  *  Permission is hereby granted, free of charge, to any person obtaining
00020  *  a copy of this software and associated documentation files (the
00021  *  "Software"), to deal in the Software without restriction, including
00022  *  without limitation the rights to use, copy, modify, merge, publish,
00023  *  distribute, sublicense, and/or sell copies of the Software, and to
00024  *  permit persons to whom the Software is furnished to do so, subject to
00025  *  the following conditions:
00026  *
00027  *  The above copyright notice and this permission notice shall be
00028  *  included in all copies or substantial portions of the Software.
00029  *
00030  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00031  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00032  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00033  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00034  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00035  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00036  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00037  *
00038  */
00039 
00040 #ifndef __GECODE_SEARCH_HH__
00041 #define __GECODE_SEARCH_HH__
00042 
00043 #include <gecode/kernel.hh>
00044 
00045 /*
00046  * Configure linking
00047  *
00048  */
00049 #if !defined(GECODE_STATIC_LIBS) && \
00050     (defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER))
00051 
00052 #ifdef GECODE_BUILD_SEARCH
00053 #define GECODE_SEARCH_EXPORT __declspec( dllexport )
00054 #else
00055 #define GECODE_SEARCH_EXPORT __declspec( dllimport )
00056 #endif
00057 
00058 #else
00059 
00060 #ifdef GECODE_GCC_HAS_CLASS_VISIBILITY
00061 #define GECODE_SEARCH_EXPORT __attribute__ ((visibility("default")))
00062 #else
00063 #define GECODE_SEARCH_EXPORT
00064 #endif
00065 
00066 #endif
00067 
00068 // Configure auto-linking
00069 #ifndef GECODE_BUILD_SEARCH
00070 #define GECODE_LIBRARY_NAME "Search"
00071 #include <gecode/support/auto-link.hpp>
00072 #endif
00073 
00074 
00075 namespace Gecode { namespace Search {
00076 
00078   namespace Sequential {}
00079   
00081   namespace Parallel {}
00082 
00084   namespace Meta {}
00085 
00091   namespace Config {
00093     const bool clone = true;
00095     const double threads = 1.0;
00097     const unsigned int c_d = 8;
00099     const unsigned int a_d = 2;
00100     
00102     const unsigned int steal_limit = 3;
00104     const unsigned int initial_delay = 5;
00105   }
00106 
00107 }}
00108 
00109 namespace Gecode { namespace Search {
00110 
00116 
00117   class GECODE_VTABLE_EXPORT UninitializedCutoff : public Exception {
00118   public:
00120     UninitializedCutoff(const char* l);
00121   };
00123 }}
00124 
00125 #include <gecode/search/exception.hpp>
00126 
00127 namespace Gecode { namespace Search {
00128 
00133   class Statistics : public StatusStatistics {
00134   public:
00136     unsigned long int fail;
00138     unsigned long int node;
00140     unsigned long int depth;
00142     size_t memory;
00144     unsigned long int restart;
00146     Statistics(void);
00148     void reset(void);
00150     Statistics operator +(const Statistics& s);
00152     Statistics& operator +=(const Statistics& s);
00153   };
00154 
00155 }}
00156 
00157 #include <gecode/search/statistics.hpp>
00158 
00159 namespace Gecode { namespace Search {
00160 
00161     class Stop;
00162     class Cutoff;
00163 
00201     class Options {
00202     public:
00204       bool clone;
00206       double threads;
00208       unsigned int c_d;
00210       unsigned int a_d;
00212       Stop* stop;
00214       Cutoff* cutoff;
00216       GECODE_SEARCH_EXPORT static const Options def;
00218       Options(void);
00220       GECODE_SEARCH_EXPORT Options
00221       expand(void) const;
00222     };
00223 
00224 }}
00225 
00226 #include <gecode/search/options.hpp>
00227 
00228 namespace Gecode {
00229 
00230   template<template<class> class E, class T>
00231   class RBS;
00232 
00233 }
00234 
00235 namespace Gecode { namespace Search { namespace Meta {
00236 
00237   class RBS;
00238 
00239 }}}
00240 
00241 namespace Gecode { namespace Search {
00242 
00257   class GECODE_SEARCH_EXPORT Stop {
00258   public:
00260     Stop(void);
00262     virtual bool stop(const Statistics& s, const Options& o) = 0;
00264     virtual ~Stop(void);
00266     static void* operator new(size_t s);
00268     static void  operator delete(void* p);
00269   };
00270   
00276   class GECODE_SEARCH_EXPORT MemoryStop : public Stop {
00277   protected:
00279     size_t l;
00280   public:
00282     MemoryStop(size_t l);
00284     size_t limit(void) const;
00286     void limit(size_t l);
00288     virtual bool stop(const Statistics& s, const Options& o);
00289   };
00290   
00299   class GECODE_SEARCH_EXPORT NodeStop : public Stop {
00300   protected:
00302     unsigned long int l;
00303   public:
00305     NodeStop(unsigned long int l);
00307     unsigned long int limit(void) const;
00309     void limit(unsigned long int l);
00311     virtual bool stop(const Statistics& s, const Options& o);
00312   };
00313 
00322   class GECODE_SEARCH_EXPORT FailStop : public Stop {
00323   protected:
00325     unsigned long int l;
00326   public:
00328     FailStop(unsigned long int l);
00330     unsigned long int limit(void) const;
00332     void limit(unsigned long int l);
00334     virtual bool stop(const Statistics& s, const Options& o);
00335   };
00336   
00341   class GECODE_SEARCH_EXPORT TimeStop : public Stop {
00342   protected:
00344     Support::Timer t;
00346     unsigned long int l;
00347   public:
00349     TimeStop(unsigned long int l);
00351     unsigned long int limit(void) const;
00353     void limit(unsigned long int l);
00355     void reset(void);
00357     virtual bool stop(const Statistics& s, const Options& o);
00358   };
00359 
00364   class GECODE_SEARCH_EXPORT MetaStop : public Stop {
00365     template<template<class>class,class> friend class ::Gecode::RBS;
00366     friend class ::Gecode::Search::Meta::RBS;
00367   private:
00369     FailStop* e_stop;
00371     Stop* m_stop;
00373     bool e_stopped;
00375     Statistics m_stat;
00376   public:
00378     MetaStop(Stop* s);
00380     virtual bool stop(const Statistics& s, const Options& o);
00382     void limit(const Search::Statistics& s, unsigned long int l);
00384     Stop* enginestop(void) const;
00386     bool enginestopped(void) const;
00388     Statistics metastatistics(void) const;
00390     ~MetaStop(void);
00391   };
00392 
00393 }}
00394 
00395 #include <gecode/search/stop.hpp>
00396 
00397 namespace Gecode { namespace Search {
00398 
00402   class GECODE_SEARCH_EXPORT Cutoff {
00403   public:
00405     Cutoff(void);
00407     virtual unsigned long int operator ()(void) = 0;
00409     virtual ~Cutoff(void);
00411     static Cutoff*
00412     constant(unsigned long int scale=1U);
00414     static Cutoff*
00415     linear(unsigned long int scale=1U);
00419     static Cutoff*
00420     geometric(unsigned long int scale=1U, double base=1.5);
00422     static Cutoff*
00423     luby(unsigned long int scale=1U);
00428     static Cutoff*
00429     rnd(unsigned int seed, 
00430         unsigned long int min, unsigned long int max, 
00431         unsigned long int n);
00433     static Cutoff*
00434     append(Cutoff* c1, unsigned long int n, Cutoff* c2);
00436     static void* operator new(size_t s);
00438     static void  operator delete(void* p);
00439   };
00440     
00441 }}
00442 
00443 #include <gecode/search/cutoff.hpp>
00444 
00445 namespace Gecode { namespace Search {
00446 
00450   class Engine {
00451   public:
00453     virtual Space* next(void) = 0;
00455     virtual Statistics statistics(void) const = 0;
00457     virtual bool stopped(void) const = 0;
00459     virtual void reset(Space* s) = 0;
00461     virtual ~Engine(void) {}
00462   };
00463 
00464 }}
00465 
00466 namespace Gecode {
00467 
00471   class EngineBase {
00472     template<template<class>class,class> friend class ::Gecode::RBS;
00473   protected:
00475     Search::Engine* e;
00477     ~EngineBase(void);
00479     EngineBase(Search::Engine* e = NULL);
00480   };
00481 
00482 }
00483 
00484 #include <gecode/search/engine-base.hpp>
00485 
00486 namespace Gecode {
00487 
00488 
00496   template<class T>
00497   class DFS : public EngineBase {
00498   public:
00500     DFS(T* s, const Search::Options& o=Search::Options::def);
00502     T* next(void);
00504     Search::Statistics statistics(void) const;
00506     bool stopped(void) const;
00507   };
00508 
00510   template<class T>
00511   T* dfs(T* s, const Search::Options& o=Search::Options::def);
00512 
00513 }
00514 
00515 #include <gecode/search/dfs.hpp>
00516 
00517 namespace Gecode {
00518 
00530   template<class T>
00531   class BAB : public EngineBase {
00532   public:
00534     BAB(T* s, const Search::Options& o=Search::Options::def);
00536     T* next(void);
00538     Search::Statistics statistics(void) const;
00540     bool stopped(void) const;
00541   };
00542 
00555   template<class T>
00556   T* bab(T* s, const Search::Options& o=Search::Options::def);
00557 
00558 }
00559 
00560 #include <gecode/search/bab.hpp>
00561 
00562 namespace Gecode {
00563 
00582   template<template<class> class E, class T>
00583   class RBS : public EngineBase {
00584   public:
00586     RBS(T* s, const Search::Options& o);
00588     T* next(void);
00590     Search::Statistics statistics(void) const;
00592     bool stopped(void) const;
00593   };
00594 
00613   template<template<class> class E, class T>
00614   T* rbs(T* s, const Search::Options& o);
00615 
00616 }
00617 
00618 #include <gecode/search/rbs.hpp>
00619 
00620 #endif
00621 
00622 // STATISTICS: search-other