Generated on for Gecode by doxygen 1.15.0
stop.cpp
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
38#include <gecode/search.hh>
39
40namespace Gecode { namespace Search {
41
42 /*
43 * Creation functions for stop objects
44 *
45 */
46 Stop*
47 Stop::node(unsigned long long int l) {
48 return new NodeStop(l);
49 }
50 Stop*
51 Stop::fail(unsigned long long int l) {
52 return new FailStop(l);
53 }
54 Stop*
55 Stop::time(double l) {
56 return new TimeStop(l);
57 }
58 Stop*
59 Stop::restart(unsigned long long int l) {
60 return new RestartStop(l);
61 }
62
63
64 /*
65 * Stopping for node limit
66 *
67 */
68 bool
69 NodeStop::stop(const Statistics& s, const Options&) {
70 return s.node > l.load(std::memory_order_acquire);
71 }
72
73
74 /*
75 * Stopping for failure limit
76 *
77 */
78 bool
79 FailStop::stop(const Statistics& s, const Options&) {
80 return s.fail > l.load(std::memory_order_acquire);
81 }
82
83
84 /*
85 * Stopping for time limit
86 *
87 */
88 bool
90 const clock::rep now = clock::now().time_since_epoch().count();
91 const clock::duration elapsed(now - t0.load(std::memory_order_acquire));
92 return std::chrono::duration<double, std::milli>(elapsed).count() >
93 l.load(std::memory_order_acquire);
94 }
95
96 /*
97 * Stopping for restart limit
98 *
99 */
100 bool
102 return s.restart > l.load(std::memory_order_acquire);
103 }
104
105}}
106
107// 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
virtual bool stop(const Statistics &s, const Options &o)
Return true if failure limit is exceeded.
Definition stop.cpp:79
Stop-object based on number of nodes
Definition search.hh:836
std::atomic< unsigned long long int > l
Node limit.
Definition search.hh:839
virtual bool stop(const Statistics &s, const Options &o)
Return true if node limit is exceeded.
Definition stop.cpp:69
Search engine options
Definition search.hh:751
Stop-object based on number of restarts
Definition search.hh:915
std::atomic< unsigned long long int > l
Restart limit.
Definition search.hh:918
virtual bool stop(const Statistics &s, const Options &o)
Return true if failure limit is exceeded.
Definition stop.cpp:101
Search engine statistics
Definition search.hh:151
unsigned long int restart
Number of restarts.
Definition search.hh:160
unsigned long long int fail
Number of failed nodes in search tree.
Definition search.hh:154
unsigned long long int node
Number of nodes expanded.
Definition search.hh:156
Base-class for Stop-object.
Definition search.hh:804
static Stop * time(double l)
Stop if time limit l (in milliseconds) has been exceeded.
Definition stop.cpp:55
static Stop * node(unsigned long long int l)
Stop if node limit l has been exceeded.
Definition stop.cpp:47
static Stop * fail(unsigned long long int l)
Stop if failure limit l has been exceeded.
Definition stop.cpp:51
static Stop * restart(unsigned long long int l)
Stop if restart limit l has been exceeded.
Definition stop.cpp:59
Stop-object based on time
Definition search.hh:886
virtual bool stop(const Statistics &s, const Options &o)
Return true if time limit is exceeded.
Definition stop.cpp:89
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
Search engines
Gecode toplevel namespace