this repo has no description
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
39namespace Gecode { namespace Search {
40
41 /**
42 * \brief %Search worker statistics
43 */
44 class Worker : public Statistics {
45 protected:
46 /// Whether engine has been stopped
47 bool _stopped;
48 /// Depth of root node (for work stealing)
49 unsigned long int root_depth;
50 public:
51 /// Initialize
52 Worker(void);
53 /// Reset stop information
54 void start(void);
55 /// Check whether engine must be stopped
56 bool stop(const Options& o);
57 /// Check whether engine has been stopped
58 bool stopped(void) const;
59 /// Reset statistics with root depth \a d
60 void reset(unsigned long int d=0);
61 /// Record stack depth \a d
62 void stack_depth(unsigned long int d);
63 /// Return steal depth
64 unsigned long int steal_depth(unsigned long int d) const;
65 };
66
67
68
69 forceinline
70 Worker::Worker(void)
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 == nullptr)
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) {
93 Statistics::reset();
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