Generated on for Gecode by doxygen 1.17.0
stop.hpp
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 * Contributing authors:
7 * Mikael Zayenz Lagerkvist <lagerkvist@gecode.dev>
8 *
9 * Copyright:
10 * Christian Schulte, 2006
11 * Mikael Zayenz Lagerkvist, 2026
12 *
13 * This file is part of Gecode, the generic constraint
14 * development environment:
15 * http://www.gecode.dev
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
38namespace Gecode { namespace Search {
39
40 /*
41 * Base class
42 *
43 */
44 forceinline
45 Stop::Stop(void) {}
46 forceinline
47 Stop::~Stop(void) {}
48
49
50 /*
51 * Stopping for node limit
52 *
53 */
54
55 forceinline
56 NodeStop::NodeStop(unsigned long long int l0) : l(l0) {}
57 forceinline
58 NodeStop::NodeStop(const NodeStop& s) : Stop(s), l(s.limit()) {}
59 forceinline NodeStop&
61 Stop::operator =(s);
62 limit(s.limit());
63 return *this;
64 }
65
66 forceinline unsigned long long int
67 NodeStop::limit(void) const {
68 return l.load(std::memory_order_acquire);
69 }
70
71 forceinline void
72 NodeStop::limit(unsigned long long int l0) {
73 l.store(l0, std::memory_order_release);
74 }
75
76
77 /*
78 * Stopping for failure limit
79 *
80 */
81
82 forceinline
83 FailStop::FailStop(unsigned long long int l0) : l(l0) {}
84 forceinline
85 FailStop::FailStop(const FailStop& s) : Stop(s), l(s.limit()) {}
86 forceinline FailStop&
88 Stop::operator =(s);
89 limit(s.limit());
90 return *this;
91 }
92
93 forceinline unsigned long long int
94 FailStop::limit(void) const {
95 return l.load(std::memory_order_acquire);
96 }
97
98 forceinline void
99 FailStop::limit(unsigned long long int l0) {
100 l.store(l0, std::memory_order_release);
101 }
102
103
104 /*
105 * Stopping for time limit
106 *
107 */
108
109 forceinline
111 : t0(clock::now().time_since_epoch().count()), l(l0) {}
112 forceinline
114 : Stop(s),
115 t0(s.t0.load(std::memory_order_acquire)),
116 l(s.l.load(std::memory_order_acquire)) {}
117 forceinline TimeStop&
119 const clock_rep t00 = s.t0.load(std::memory_order_acquire);
120 const double l0 = s.l.load(std::memory_order_acquire);
121 Stop::operator =(s);
122 t0.store(t00, std::memory_order_release);
123 l.store(l0, std::memory_order_release);
124 return *this;
125 }
126
127 forceinline double
128 TimeStop::limit(void) const {
129 return l.load(std::memory_order_acquire);
130 }
131
132 forceinline void
133 TimeStop::limit(double l0) {
134 l.store(l0, std::memory_order_release);
135 }
136
137 forceinline void
139 t0.store(clock::now().time_since_epoch().count(),
140 std::memory_order_release);
141 }
142
143 /*
144 * Stopping for restart limit
145 *
146 */
147
148 forceinline
149 RestartStop::RestartStop(unsigned long long int l0) : l(l0) {}
150 forceinline
152 forceinline RestartStop&
154 Stop::operator =(s);
155 limit(s.limit());
156 return *this;
157 }
158
159 forceinline unsigned long long int
160 RestartStop::limit(void) const {
161 return l.load(std::memory_order_acquire);
162 }
163
164 forceinline void
165 RestartStop::limit(unsigned long long int l0) {
166 l.store(l0, std::memory_order_release);
167 }
168
169}}
170
171// STATISTICS: search-other
Stop-object based on number of failures
Definition search.hh:863
std::atomic< unsigned long long int > l
Failure limit.
Definition search.hh:866
FailStop & operator=(const FailStop &s)
Assignment operator.
Definition stop.hpp:87
FailStop(unsigned long long int l)
Stop if failure limit l is exceeded.
Definition stop.hpp:83
unsigned long long int limit(void) const
Return current limit.
Definition stop.hpp:94
Stop-object based on number of nodes
Definition search.hh:836
NodeStop(unsigned long long int l)
Stop if node limit l is exceeded.
Definition stop.hpp:56
unsigned long long int limit(void) const
Return current limit.
Definition stop.hpp:67
std::atomic< unsigned long long int > l
Node limit.
Definition search.hh:839
NodeStop & operator=(const NodeStop &s)
Assignment operator.
Definition stop.hpp:60
Stop-object based on number of restarts
Definition search.hh:915
RestartStop & operator=(const RestartStop &s)
Assignment operator.
Definition stop.hpp:153
std::atomic< unsigned long long int > l
Restart limit.
Definition search.hh:918
RestartStop(unsigned long long int l)
Stop if restart limit l is exceeded.
Definition stop.hpp:149
unsigned long long int limit(void) const
Return current limit.
Definition stop.hpp:160
Stop(void)
Default constructor.
Definition stop.hpp:45
virtual ~Stop(void)
Destructor.
Definition stop.hpp:47
Stop-object based on time
Definition search.hh:886
clock::time_point::rep clock_rep
Definition search.hh:889
std::chrono::steady_clock clock
Definition search.hh:888
TimeStop(double l)
Stop if search exceeds l milliseconds (from creation of this object).
Definition stop.hpp:110
double limit(void) const
Return current limit in milliseconds.
Definition stop.hpp:128
std::atomic< double > l
Current limit in milliseconds.
Definition search.hh:893
std::atomic< clock_rep > t0
Clock representation at the start of timing.
Definition search.hh:891
TimeStop & operator=(const TimeStop &s)
Assignment operator.
Definition stop.hpp:118
void reset(void)
Reset time to zero.
Definition stop.hpp:138
Search engines
Gecode toplevel namespace
void count(Home home, const IntVarArgs &x, int n, IntRelType irt, int m, IntPropLevel ipl=IPL_DEF)
Post propagator for .