worker.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, 2004 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_WORKER_HH__ 00035 #define __GECODE_SEARCH_WORKER_HH__ 00036 00037 #include <gecode/search.hh> 00038 00039 namespace Gecode { namespace Search { 00040 00044 class Worker : public Statistics { 00045 protected: 00047 bool _stopped; 00049 unsigned long int root_depth; 00050 public: 00052 Worker(void); 00054 void start(void); 00056 bool stop(const Options& o); 00058 bool stopped(void) const; 00060 void reset(unsigned long int d=0); 00062 void stack_depth(unsigned long int d); 00064 unsigned long int steal_depth(unsigned long int d) const; 00065 }; 00066 00067 00068 00069 forceinline 00070 Worker::Worker(void) 00071 : _stopped(false), root_depth(0) {} 00072 00073 forceinline void 00074 Worker::start(void) { 00075 _stopped = false; 00076 } 00077 00078 forceinline bool 00079 Worker::stop(const Options& o) { 00080 if (o.stop == NULL) 00081 return false; 00082 _stopped |= o.stop->stop(*this,o); 00083 return _stopped; 00084 } 00085 00086 forceinline bool 00087 Worker::stopped(void) const { 00088 return _stopped; 00089 } 00090 00091 forceinline void 00092 Worker::reset(unsigned long int d) { 00093 Statistics::reset(); 00094 root_depth = d; 00095 if (depth < d) 00096 depth = d; 00097 } 00098 00099 forceinline void 00100 Worker::stack_depth(unsigned long int d) { 00101 if (depth < root_depth + d) 00102 depth = root_depth + d; 00103 } 00104 00105 forceinline unsigned long int 00106 Worker::steal_depth(unsigned long int d) const { 00107 return root_depth + d; 00108 } 00109 00110 }} 00111 00112 #endif 00113 00114 // STATISTICS: search-other