worker.hh
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef __GECODE_SEARCH_WORKER_HH__
00039 #define __GECODE_SEARCH_WORKER_HH__
00040
00041 #include <gecode/search.hh>
00042
00043 namespace Gecode { namespace Search {
00044
00048 class Worker : public Statistics {
00049 protected:
00051 bool _stopped;
00053 size_t mem_space;
00055 size_t mem_cur;
00057 size_t mem_total;
00059 unsigned long int root_depth;
00060 public:
00062 Worker(size_t sz);
00064 void start(void);
00066 bool stop(const Options& o, size_t sz);
00068 bool stopped(void) const;
00070 void push(const Space* s, const Choice* c);
00072 void constrained(const Space* s1, const Space* s2);
00074 void adapt(const Space* s);
00076 void pop(const Space* s, const Choice* c);
00078 void lao(const Space* s);
00080 void current(const Space* s);
00082 void reset(const Space* s, unsigned long int d=0);
00084 void reset(void);
00086 void stack_depth(unsigned long int d);
00088 unsigned long int steal_depth(unsigned long int d) const;
00089 };
00090
00091
00092
00093 forceinline
00094 Worker::Worker(size_t sz)
00095 : _stopped(false), mem_space(sz), mem_cur(0), mem_total(0),
00096 root_depth(0) {
00097 memory = 0;
00098 }
00099
00100 forceinline void
00101 Worker::start(void) {
00102 _stopped = false;
00103 }
00104
00105 forceinline bool
00106 Worker::stop(const Options& o, size_t sz) {
00107 if (o.stop == NULL)
00108 return false;
00109 memory += sz;
00110 _stopped |= o.stop->stop(*this,o);
00111 memory -= sz;
00112 return _stopped;
00113 }
00114
00115 forceinline bool
00116 Worker::stopped(void) const {
00117 return _stopped;
00118 }
00119
00120 forceinline void
00121 Worker::push(const Space* s, const Choice* c) {
00122 if (s != NULL)
00123 mem_total += mem_space + s->allocated();
00124 mem_total += c->size();
00125 if (mem_total > memory)
00126 memory = mem_total;
00127 }
00128
00129 forceinline void
00130 Worker::adapt(const Space* s) {
00131 mem_total += mem_space + s->allocated();
00132 if (mem_total > memory)
00133 memory = mem_total;
00134 }
00135
00136 forceinline void
00137 Worker::constrained(const Space* s1, const Space* s2) {
00138 mem_total -= s1->allocated();
00139 mem_total += s2->allocated();
00140 if (mem_total > memory)
00141 memory = mem_total;
00142 }
00143
00144 forceinline void
00145 Worker::lao(const Space* s) {
00146 mem_total -= mem_space + s->allocated();
00147 }
00148
00149 forceinline void
00150 Worker::pop(const Space* s, const Choice* c) {
00151 if (s != NULL)
00152 mem_total -= mem_space + s->allocated();
00153 mem_total -= c->size();
00154 }
00155
00156 forceinline void
00157 Worker::current(const Space* s) {
00158 if (s == NULL) {
00159 mem_total -= mem_cur;
00160 mem_cur = 0;
00161 } else {
00162 mem_cur = mem_space + s->allocated();
00163 mem_total += mem_cur;
00164 if (mem_total > memory)
00165 memory = mem_total;
00166 }
00167 }
00168
00169 forceinline void
00170 Worker::reset(const Space* s, unsigned long int d) {
00171 mem_cur = mem_space + s->allocated();
00172 mem_total = mem_cur;
00173 if (mem_total > memory)
00174 memory = mem_total;
00175 root_depth = d;
00176 if (depth < d)
00177 depth = d;
00178 }
00179
00180 forceinline void
00181 Worker::reset(void) {
00182 mem_cur = 0;
00183 mem_total = 0;
00184 root_depth = 0;
00185 }
00186
00187 forceinline void
00188 Worker::stack_depth(unsigned long int d) {
00189 if (depth < root_depth + d)
00190 depth = root_depth + d;
00191 }
00192
00193 forceinline unsigned long int
00194 Worker::steal_depth(unsigned long int d) const {
00195 return root_depth + d;
00196 }
00197
00198 }}
00199
00200 #endif
00201
00202