Generated on Sat Feb 7 2015 02:01:29 for Gecode by doxygen 1.8.9.1
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.org>
5  *
6  * Copyright:
7  * Christian Schulte, 2006
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 namespace Gecode { namespace Search {
39 
40  /*
41  * Base class
42  *
43  */
45  Stop::Stop(void) {}
47  Stop::~Stop(void) {}
48  forceinline void*
49  Stop::operator new(size_t s) {
50  return heap.ralloc(s);
51  }
52  forceinline void
53  Stop::operator delete(void* p) {
54  heap.rfree(p);
55  }
56 
57 
58 
59 
60  /*
61  * Stopping for node limit
62  *
63  */
64 
66  NodeStop::NodeStop(unsigned long int l0) : l(l0) {}
67 
68  forceinline unsigned long int
69  NodeStop::limit(void) const {
70  return l;
71  }
72 
73  forceinline void
74  NodeStop::limit(unsigned long int l0) {
75  l=l0;
76  }
77 
78 
79  /*
80  * Stopping for failure limit
81  *
82  */
83 
85  FailStop::FailStop(unsigned long int l0) : l(l0) {}
86 
87  forceinline unsigned long int
88  FailStop::limit(void) const {
89  return l;
90  }
91 
92  forceinline void
93  FailStop::limit(unsigned long int l0) {
94  l=l0;
95  }
96 
97 
98  /*
99  * Stopping for time limit
100  *
101  */
102 
104  TimeStop::TimeStop(unsigned long int l0)
105  : l(l0) {
106  t.start();
107  }
108 
109  forceinline unsigned long int
110  TimeStop::limit(void) const {
111  return l;
112  }
113 
114  forceinline void
115  TimeStop::limit(unsigned long int l0) {
116  l=l0;
117  }
118 
119  forceinline void
121  t.start();
122  }
123 
124 
125  /*
126  * Stopping for meta search engines
127  *
128  */
129 
132  : e_stop(new FailStop(0)), m_stop(s), e_stopped(false) {}
133 
134  forceinline void
135  MetaStop::limit(const Search::Statistics& s, unsigned long int l) {
136  m_stat += s;
137  e_stopped = false;
138  e_stop->limit(l);
139  }
140 
141  forceinline void
143  m_stat += s;
144  }
145 
147  MetaStop::enginestop(void) const {
148  return e_stop;
149  }
150 
151  forceinline bool
152  MetaStop::enginestopped(void) const {
153  return e_stopped;
154  }
155 
158  return m_stat;
159  }
160 
163  delete e_stop;
164  delete m_stop;
165  }
166 
167 }}
168 
169 // STATISTICS: search-other
unsigned long int limit(void) const
Return current limit.
Definition: stop.hpp:69
NNF * l
Left subtree.
Definition: bool-expr.cpp:244
Search engine statistics
Definition: search.hh:136
~MetaStop(void)
Delete object.
Definition: stop.hpp:162
void rfree(void *p)
Free memory block starting at p.
Definition: heap.hpp:355
unsigned long int l
Current limit in milliseconds.
Definition: search.hh:331
void limit(const Search::Statistics &s, unsigned long int l)
Set current limit for the engine to l fails.
Definition: stop.hpp:135
void * ralloc(size_t s)
Allocate s bytes from heap.
Definition: heap.hpp:341
Support::Timer t
Time when execution should stop.
Definition: search.hh:329
NodeStop(unsigned long int l)
Stop if node limit l is exceeded.
Definition: stop.hpp:66
Heap heap
The single global heap.
Definition: heap.cpp:49
void start(void)
Start timer.
Definition: timer.hpp:70
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
FailStop(unsigned long int l)
Stop if failure limit l is exceeded.
Definition: stop.hpp:85
unsigned long int limit(void) const
Return current limit.
Definition: stop.hpp:88
MetaStop(Stop *s)
Stop the meta engine if indicated by the stop object s.
Definition: stop.hpp:131
void reset(void)
Reset time to zero.
Definition: stop.hpp:120
Stop(void)
Default constructor.
Definition: stop.hpp:45
Stop * enginestop(void) const
Return the stop object to control the engine.
Definition: stop.hpp:147
unsigned long int l
Node limit.
Definition: search.hh:287
void update(const Search::Statistics &s)
Update statistics.
Definition: stop.hpp:142
#define forceinline
Definition: config.hpp:132
unsigned long int l
Failure limit.
Definition: search.hh:310
virtual ~Stop(void)
Destructor.
Definition: stop.hpp:47
Statistics metastatistics(void) const
Return statistics for the meta engine.
Definition: stop.hpp:157
TimeStop(unsigned long int l)
Stop if search exceeds l milliseconds (from creation of this object)
Definition: stop.hpp:104
Gecode toplevel namespace
unsigned long int limit(void) const
Return current limit in milliseconds.
Definition: stop.hpp:110
Base-class for Stop-object.
Definition: search.hh:262
Stop-object based on number of failures
Definition: search.hh:307
bool enginestopped(void) const
Return whether the engine has been stopped.
Definition: stop.hpp:152