Generated on Sat May 25 2013 18:00:40 for Gecode by doxygen 1.8.3.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-03-07 22:14:40 +0100 (Thu, 07 Mar 2013) $ by $Author: schulte $
11  * $Revision: 13467 $
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  * Stopping for memory limit
61  *
62  */
63 
65  MemoryStop::MemoryStop(size_t l0) : l(l0) {}
66 
67  forceinline size_t
68  MemoryStop::limit(void) const {
69  return l;
70  }
71 
72  forceinline void
73  MemoryStop::limit(size_t l0) {
74  l=l0;
75  }
76 
77 
78  /*
79  * Stopping for node limit
80  *
81  */
82 
84  NodeStop::NodeStop(unsigned long int l0) : l(l0) {}
85 
86  forceinline unsigned long int
87  NodeStop::limit(void) const {
88  return l;
89  }
90 
91  forceinline void
92  NodeStop::limit(unsigned long int l0) {
93  l=l0;
94  }
95 
96 
97  /*
98  * Stopping for failure limit
99  *
100  */
101 
103  FailStop::FailStop(unsigned long int l0) : l(l0) {}
104 
105  forceinline unsigned long int
106  FailStop::limit(void) const {
107  return l;
108  }
109 
110  forceinline void
111  FailStop::limit(unsigned long int l0) {
112  l=l0;
113  }
114 
115 
116  /*
117  * Stopping for time limit
118  *
119  */
120 
122  TimeStop::TimeStop(unsigned long int l0)
123  : l(l0) {
124  t.start();
125  }
126 
127  forceinline unsigned long int
128  TimeStop::limit(void) const {
129  return l;
130  }
131 
132  forceinline void
133  TimeStop::limit(unsigned long int l0) {
134  l=l0;
135  }
136 
137  forceinline void
139  t.start();
140  }
141 
142 
143  /*
144  * Stopping for meta search engines
145  *
146  */
147 
150  : e_stop(new FailStop(0)), m_stop(s), e_stopped(false) {}
151 
152  forceinline void
153  MetaStop::limit(const Search::Statistics& s, unsigned long int l) {
154  m_stat += s;
155  e_stopped = false;
156  e_stop->limit(l);
157  }
158 
160  MetaStop::enginestop(void) const {
161  return e_stop;
162  }
163 
164  forceinline bool
165  MetaStop::enginestopped(void) const {
166  return e_stopped;
167  }
168 
171  return m_stat;
172  }
173 
176  delete e_stop;
177  delete m_stop;
178  }
179 
180 }}
181 
182 // STATISTICS: search-other