Generated on Sat Feb 7 2015 02:01:29 for Gecode by doxygen 1.8.9.1
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  * Last modified:
10  * $Date: 2013-10-30 15:42:34 +0100 (Wed, 30 Oct 2013) $ by $Author: schulte $
11  * $Revision: 14037 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 #ifndef __GECODE_SEARCH_WORKER_HH__
39 #define __GECODE_SEARCH_WORKER_HH__
40 
41 #include <gecode/search.hh>
42 
43 namespace Gecode { namespace Search {
44 
48  class Worker : public Statistics {
49  protected:
51  bool _stopped;
53  unsigned long int root_depth;
54  public:
56  Worker(void);
58  void start(void);
60  bool stop(const Options& o);
62  bool stopped(void) const;
64  void reset(unsigned long int d=0);
66  void stack_depth(unsigned long int d);
68  unsigned long int steal_depth(unsigned long int d) const;
69  };
70 
71 
72 
75  : _stopped(false), root_depth(0) {}
76 
77  forceinline void
78  Worker::start(void) {
79  _stopped = false;
80  }
81 
82  forceinline bool
83  Worker::stop(const Options& o) {
84  if (o.stop == NULL)
85  return false;
86  _stopped |= o.stop->stop(*this,o);
87  return _stopped;
88  }
89 
90  forceinline bool
91  Worker::stopped(void) const {
92  return _stopped;
93  }
94 
95  forceinline void
96  Worker::reset(unsigned long int d) {
98  root_depth = d;
99  if (depth < d)
100  depth = d;
101  }
102 
103  forceinline void
104  Worker::stack_depth(unsigned long int d) {
105  if (depth < root_depth + d)
106  depth = root_depth + d;
107  }
108 
109  forceinline unsigned long int
110  Worker::steal_depth(unsigned long int d) const {
111  return root_depth + d;
112  }
113 
114 }}
115 
116 #endif
117 
118 // STATISTICS: search-other
Worker(void)
Initialize.
Definition: worker.hh:74
Search engine statistics
Definition: search.hh:136
Search engine options
Definition: search.hh:204
unsigned long int depth
Maximum depth of search stack.
Definition: search.hh:143
bool stopped(void) const
Check whether engine has been stopped.
Definition: worker.hh:91
Gecode::IntSet d(v, 7)
void start(void)
Reset stop information.
Definition: worker.hh:78
Search worker statistics
Definition: worker.hh:48
unsigned long int root_depth
Depth of root node (for work stealing)
Definition: worker.hh:53
#define forceinline
Definition: config.hpp:132
bool _stopped
Whether engine has been stopped.
Definition: worker.hh:51
void stack_depth(unsigned long int d)
Record stack depth d.
Definition: worker.hh:104
Stop * stop
Stop object for stopping search.
Definition: search.hh:217
Gecode toplevel namespace
virtual bool stop(const Statistics &s, const Options &o)=0
Stop search, if returns true.
unsigned long int steal_depth(unsigned long int d) const
Return steal depth.
Definition: worker.hh:110
bool stop(const Options &o)
Check whether engine must be stopped.
Definition: worker.hh:83
void reset(void)
Reset.
Definition: statistics.hpp:43