Generated on for Gecode by doxygen 1.17.0
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.dev>
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.dev
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
44 class Worker : public Statistics {
45 protected:
49 unsigned long int root_depth;
50 public:
52 Worker(void);
54 void start(void);
56 bool stop(const Options& o);
58 bool stop_seq(Options& o);
60 bool stopped(void) const;
62 void reset(unsigned long int d=0);
64 void stack_depth(unsigned long int d);
66 unsigned long int steal_depth(unsigned long int d) const;
67 };
68
69
70
73 : _stopped(false), root_depth(0) {}
74
75 forceinline void
77 _stopped = false;
78 }
79
80 forceinline bool
82 if (o.stop == nullptr)
83 return false;
84 _stopped |= o.stop->stop(*this,o);
85 return _stopped;
86 }
87
88 forceinline bool
90 // A paused portfolio asset must still observe the round's stop signal.
91 while (!stop(o)) {
92 if (!o.worker_control.engaged() ||
94 return false;
96 }
97 return true;
98 }
99
100 forceinline bool
101 Worker::stopped(void) const {
102 return _stopped;
103 }
104
105 forceinline void
106 Worker::reset(unsigned long int d) {
108 root_depth = d;
109 if (depth < d)
110 depth = d;
111 }
112
113 forceinline void
114 Worker::stack_depth(unsigned long int d) {
115 if (depth < root_depth + d)
116 depth = root_depth + d;
117 }
118
119 forceinline unsigned long int
120 Worker::steal_depth(unsigned long int d) const {
121 return root_depth + d;
122 }
123
124}}
125
126#endif
127
128// STATISTICS: search-other
Search engine options
Definition search.hh:848
WorkerControl worker_control
Definition search.hh:861
Stop * stop
Stop object for stopping search.
Definition search.hh:875
Statistics(void)
Initialize.
unsigned long int depth
Maximum depth of search stack.
Definition search.hh:162
virtual bool stop(const Statistics &s, const Options &o)=0
Stop search, if returns true.
static void wait(WorkerControl &control, unsigned int worker)
Wait for the event belonging to worker worker.
static unsigned int requested(const WorkerControl &control)
Return the current request.
bool engaged(void) const noexcept
Whether this handle is engaged.
bool _stopped
Whether engine has been stopped.
Definition worker.hh:47
void start(void)
Reset stop information.
Definition worker.hh:76
unsigned long int root_depth
Depth of root node (for work stealing).
Definition worker.hh:49
bool stopped(void) const
Check whether engine has been stopped.
Definition worker.hh:101
Worker(void)
Initialize.
Definition worker.hh:72
unsigned long int steal_depth(unsigned long int d) const
Return steal depth.
Definition worker.hh:120
bool stop(const Options &o)
Check whether engine must be stopped.
Definition worker.hh:81
bool stop_seq(Options &o)
Check stop and wait for admission of a sequential worker.
Definition worker.hh:89
void stack_depth(unsigned long int d)
Record stack depth d.
Definition worker.hh:114
void reset(void)
Reset information.
Definition core.hpp:4974
Search engines
Gecode toplevel namespace
#define forceinline
Definition config.hpp:144