Generated on Tue Jan 19 2021 06:15:49 for Gecode by doxygen 1.8.13
worker.hh
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Christian Schulte <schulte@gecode.org>
5  *
6  * Copyright:
7  * Christian Schulte, 2004
8  *
9  * This file is part of Gecode, the generic constraint
10  * development environment:
11  * http://www.gecode.org
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining
14  * a copy of this software and associated documentation files (the
15  * "Software"), to deal in the Software without restriction, including
16  * without limitation the rights to use, copy, modify, merge, publish,
17  * distribute, sublicense, and/or sell copies of the Software, and to
18  * permit persons to whom the Software is furnished to do so, subject to
19  * the following conditions:
20  *
21  * The above copyright notice and this permission notice shall be
22  * included in all copies or substantial portions of the Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31  *
32  */
33 
34 #ifndef __GECODE_SEARCH_WORKER_HH__
35 #define __GECODE_SEARCH_WORKER_HH__
36 
37 #include <gecode/search.hh>
38 
39 namespace Gecode { namespace Search {
40 
44  class Worker : public Statistics {
45  protected:
47  bool _stopped;
49  unsigned long int root_depth;
50  public:
52  Worker(void);
54  void start(void);
56  bool stop(const Options& o);
58  bool stopped(void) const;
60  void reset(unsigned long int d=0);
62  void stack_depth(unsigned long int d);
64  unsigned long int steal_depth(unsigned long int d) const;
65  };
66 
67 
68 
71  : _stopped(false), root_depth(0) {}
72 
73  forceinline void
74  Worker::start(void) {
75  _stopped = false;
76  }
77 
78  forceinline bool
79  Worker::stop(const Options& o) {
80  if (o.stop == NULL)
81  return false;
82  _stopped |= o.stop->stop(*this,o);
83  return _stopped;
84  }
85 
86  forceinline bool
87  Worker::stopped(void) const {
88  return _stopped;
89  }
90 
91  forceinline void
92  Worker::reset(unsigned long int d) {
94  root_depth = d;
95  if (depth < d)
96  depth = d;
97  }
98 
99  forceinline void
100  Worker::stack_depth(unsigned long int d) {
101  if (depth < root_depth + d)
102  depth = root_depth + d;
103  }
104 
105  forceinline unsigned long int
106  Worker::steal_depth(unsigned long int d) const {
107  return root_depth + d;
108  }
109 
110 }}
111 
112 #endif
113 
114 // STATISTICS: search-other
Worker(void)
Initialize.
Definition: worker.hh:70
Search engine statistics
Definition: search.hh:147
Search engine options
Definition: search.hh:746
unsigned long int steal_depth(unsigned long int d) const
Return steal depth.
Definition: worker.hh:106
unsigned long int depth
Maximum depth of search stack.
Definition: search.hh:154
#define forceinline
Definition: config.hpp:185
bool stopped(void) const
Check whether engine has been stopped.
Definition: worker.hh:87
Gecode::IntSet d(v, 7)
void start(void)
Reset stop information.
Definition: worker.hh:74
Search worker statistics
Definition: worker.hh:44
unsigned long int root_depth
Depth of root node (for work stealing)
Definition: worker.hh:49
bool _stopped
Whether engine has been stopped.
Definition: worker.hh:47
void stack_depth(unsigned long int d)
Record stack depth d.
Definition: worker.hh:100
Stop * stop
Stop object for stopping search.
Definition: search.hh:765
Gecode toplevel namespace
virtual bool stop(const Statistics &s, const Options &o)=0
Stop search, if returns true.
bool stop(const Options &o)
Check whether engine must be stopped.
Definition: worker.hh:79
void reset(void)
Reset.
Definition: statistics.hpp:39