Generated on Thu Apr 11 13:59:18 2019 for Gecode by doxygen 1.6.3

pbs.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  *
00006  *  Copyright:
00007  *     Christian Schulte, 2015
00008  *
00009  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 #ifndef __GECODE_SEARCH_PAR_PBS_HH__
00035 #define __GECODE_SEARCH_PAR_PBS_HH__
00036 
00037 #include <gecode/search.hh>
00038 
00039 namespace Gecode { namespace Search { namespace Par {
00040 
00042   class GECODE_SEARCH_EXPORT PortfolioStop : public Stop {
00043   private:
00045     Stop* so;
00047     volatile bool* tostop;
00048   public:
00050     PortfolioStop(Stop* so);
00052     void share(volatile bool* ts);
00054     virtual bool stop(const Statistics& s, const Options& o);
00056     void stop(bool s);
00058     bool stop(void) const;
00059   };
00060 
00061   // Forward declaration
00062   template<class Collect>
00063   class PBS;
00064 
00066   template<class Collect>
00067   class GECODE_SEARCH_EXPORT Slave : public Support::Runnable {
00068   protected:
00070     PBS<Collect>* master;
00072     Engine* slave;
00074     Stop* stop;
00075   public:
00077     Slave(PBS<Collect>* m, Engine* s, Stop* so);
00079     Statistics statistics(void) const;
00081     bool stopped(void) const;
00083     void constrain(const Space& b);
00085     virtual void run(void);
00087     virtual ~Slave(void);
00088   };
00089 
00091   class CollectAll {
00092   protected:
00094     Support::DynamicQueue<Space*,Heap> solutions;
00095   public:
00097     static const bool best = false;
00099     CollectAll(void);
00101     bool add(Space* s, Slave<CollectAll>* r);
00103     bool constrain(const Space& b);
00105     bool empty(void) const;
00107     Space* get(Slave<CollectAll>*& r);
00109     ~CollectAll(void);
00110   };
00111 
00113   class CollectBest {
00114   protected:
00116     Space* b;
00118     Slave<CollectBest>* reporter;
00119   public:
00121     static const bool best = true;
00123     CollectBest(void);
00125     bool add(Space* s, Slave<CollectBest>* r);
00127     bool constrain(const Space& b);
00129     bool empty(void) const;
00131     Space* get(Slave<CollectBest>*& r);
00133     ~CollectBest(void);
00134   };
00135 
00137   template<class Collect>
00138   class GECODE_SEARCH_EXPORT PBS : public Engine {
00139     friend class Slave<Collect>;
00140   protected:
00142     Statistics stat;
00144     Slave<Collect>** slaves;
00146     unsigned int n_slaves;
00148     unsigned int n_active;
00150     bool slave_stop;
00152     volatile bool tostop;
00154     Collect solutions;
00156     Support::Mutex m;
00158     unsigned int n_busy;
00160     Support::Event idle;
00162     bool report(Slave<Collect>* slave, Space* s);
00171   public:
00173     PBS(Engine** s, Stop** so, unsigned int n, const Statistics& stat);
00175     virtual Space* next(void);
00177     virtual Statistics statistics(void) const;
00179     virtual bool stopped(void) const;
00181     virtual void constrain(const Space& b);
00183     virtual ~PBS(void);
00184   };
00185 
00186 }}}
00187 
00188 #include <gecode/search/par/pbs.hpp>
00189 
00190 #endif
00191 
00192 // STATISTICS: search-par