@@ -159,10 +159,230 @@ namespace Gecode { namespace Search {
159159
160160#include < gecode/search/statistics.hpp>
161161
162+ namespace Gecode { namespace Search {
163+
164+ /* *
165+ * \brief Base class for cutoff generators for restart-based meta engine
166+ */
167+ class GECODE_SEARCH_EXPORT Cutoff {
168+ public:
169+ // / \name Constructors and member functions
170+ // @{
171+ // / Default constructor
172+ Cutoff (void );
173+ // / Return the current cutoff value
174+ virtual unsigned long int operator ()(void ) const = 0;
175+ // / Increment and return the next cutoff value
176+ virtual unsigned long int operator ++(void ) = 0 ;
177+ // / Destructor
178+ virtual ~Cutoff (void );
179+ // @}
180+ // / Memory management
181+ // @{
182+ // / Allocate memory from heap
183+ static void * operator new (size_t s);
184+ // / Free memory allocated from heap
185+ static void operator delete (void * p);
186+ // @}
187+ // / \name Predefined cutoff generators
188+ // @{
189+ // / Create generator for constant sequence with constant \a s
190+ static Cutoff*
191+ constant (unsigned long int scale=1U );
192+ // / Create generator for linear sequence scaled by \a scale
193+ static Cutoff*
194+ linear (unsigned long int scale=1U );
195+ /* * Create generator for geometric sequence scaled by
196+ * \a scale using base \a base
197+ */
198+ static Cutoff*
199+ geometric (unsigned long int scale=1U , double base=1.5 );
200+ // / Create generator for luby sequence with scale-factor \a scale
201+ static Cutoff*
202+ luby (unsigned long int scale=1U );
203+ /* * Create generator for random sequence with seed \a seed that
204+ * generates values between \a min and \a max with \a n steps
205+ * between the extreme values (use 0 for \a n to get step size 1).
206+ */
207+ static Cutoff*
208+ rnd (unsigned int seed,
209+ unsigned long int min, unsigned long int max,
210+ unsigned long int n);
211+ // / Append cutoff values from \a c2 after \a n values from \a c1
212+ static Cutoff*
213+ append (Cutoff* c1, unsigned long int n, Cutoff* c2);
214+ // / Merge cutoff values from \a c1 with values from \a c2
215+ static Cutoff*
216+ merge (Cutoff* c1, Cutoff* c2);
217+ // / Create generator that repeats \a n times each cutoff value from \a c
218+ static Cutoff*
219+ repeat (Cutoff* c, unsigned long int n);
220+ // @}
221+ };
222+
223+ // / Cutoff generator for constant sequence
224+ class GECODE_SEARCH_EXPORT CutoffConstant : public Cutoff {
225+ protected:
226+ // / Constant
227+ unsigned long int c;
228+ public:
229+ // / Constructor
230+ CutoffConstant (unsigned long int c);
231+ // / Return the current cutoff value
232+ virtual unsigned long int operator ()(void ) const ;
233+ // / Increment and return the next cutoff value
234+ virtual unsigned long int operator ++(void );
235+ };
236+
237+ // / Cutoff generator for linear sequence
238+ class GECODE_SEARCH_EXPORT CutoffLinear : public Cutoff {
239+ protected:
240+ // / Scale factor
241+ unsigned long int scale;
242+ // / Next number in sequence
243+ unsigned long int n;
244+ public:
245+ // / Constructor
246+ CutoffLinear (unsigned long int scale);
247+ // / Return the current cutoff value
248+ virtual unsigned long int operator ()(void ) const ;
249+ // / Increment and return the next cutoff value
250+ virtual unsigned long int operator ++(void );
251+ };
252+
253+ // / Cutoff generator for the Luby sequence
254+ class GECODE_SEARCH_EXPORT CutoffLuby : public Cutoff {
255+ protected:
256+ // / Iteration number
257+ unsigned long int i;
258+ // / Scale factor
259+ unsigned long int scale;
260+ // / Number of pre-computed luby values
261+ static const unsigned long int n_start = 63U ;
262+ // / Precomputed luby-values
263+ static unsigned long int start[n_start];
264+ // / Compute binary logarithm of \a i
265+ static unsigned long int log (unsigned long int i);
266+ // / Compute Luby number for step \a i
267+ static unsigned long int luby (unsigned long int i);
268+ public:
269+ // / Constructor
270+ CutoffLuby (unsigned long int scale);
271+ // / Return the current cutoff value
272+ virtual unsigned long int operator ()(void ) const ;
273+ // / Increment and return the next cutoff value
274+ virtual unsigned long int operator ++(void );
275+ };
276+
277+ // / Cutoff generator for the geometric sequence
278+ class GECODE_SEARCH_EXPORT CutoffGeometric : public Cutoff {
279+ protected:
280+ // / Current cutoff value
281+ double n;
282+ // / Scale factor
283+ double scale;
284+ // / Base
285+ double base;
286+ public:
287+ // / Constructor
288+ CutoffGeometric (unsigned long int scale, double base);
289+ // / Return the current cutoff value
290+ virtual unsigned long int operator ()(void ) const ;
291+ // / Increment and return the next cutoff value
292+ virtual unsigned long int operator ++(void );
293+ };
294+
295+ // / Cutoff generator for the random sequence
296+ class GECODE_SEARCH_EXPORT CutoffRandom : public Cutoff {
297+ protected:
298+ // / Random number generator
299+ Support::RandomGenerator rnd;
300+ // / Minimum cutoff value
301+ unsigned long int min;
302+ // / Random values
303+ unsigned long int n;
304+ // / Step size
305+ unsigned long int step;
306+ // / Current value
307+ unsigned long int cur;
308+ public:
309+ // / Constructor
310+ CutoffRandom (unsigned int seed,
311+ unsigned long int min, unsigned long int max,
312+ unsigned long int n);
313+ // / Return the current cutoff value
314+ virtual unsigned long int operator ()(void ) const ;
315+ // / Increment and return the next cutoff value
316+ virtual unsigned long int operator ++(void );
317+ };
318+
319+ // / Cutoff generator appending two cutoff generators
320+ class GECODE_SEARCH_EXPORT CutoffAppend : public Cutoff {
321+ protected:
322+ // / First cutoff generators
323+ Cutoff* c1;
324+ // / Second cutoff generators
325+ Cutoff* c2;
326+ // / How many number to take from the first
327+ unsigned long int n;
328+ public:
329+ // / Constructor
330+ CutoffAppend (Cutoff* c1, unsigned long int n, Cutoff* c2);
331+ // / Return the current cutoff value
332+ virtual unsigned long int operator ()(void ) const ;
333+ // / Increment and return the next cutoff value
334+ virtual unsigned long int operator ++(void );
335+ // / Destructor
336+ virtual ~CutoffAppend (void );
337+ };
338+
339+ // / Cutoff generator merging two cutoff generators
340+ class GECODE_SEARCH_EXPORT CutoffMerge : public Cutoff {
341+ protected:
342+ // / First cutoff generator
343+ Cutoff* c1;
344+ // / Second cutoff generator
345+ Cutoff* c2;
346+ public:
347+ // / Constructor
348+ CutoffMerge (Cutoff* c1, Cutoff* c2);
349+ // / Return the current cutoff value
350+ virtual unsigned long int operator ()(void ) const ;
351+ // / Increment and return the next cutoff value
352+ virtual unsigned long int operator ++(void );
353+ // / Destructor
354+ virtual ~CutoffMerge (void );
355+ };
356+
357+ // / Cutoff generator that repeats a cutoff from another cutoff generator
358+ class GECODE_SEARCH_EXPORT CutoffRepeat : public Cutoff {
359+ protected:
360+ // / Actual cutoff generator
361+ Cutoff* c;
362+ // Current cutoff
363+ unsigned int cutoff;
364+ // Iteration
365+ unsigned long int i;
366+ // Number of repetitions
367+ unsigned long int n;
368+ public:
369+ // / Constructor
370+ CutoffRepeat (Cutoff* c, unsigned long int n);
371+ // / Return the current cutoff value
372+ virtual unsigned long int operator ()(void ) const ;
373+ // / Increment and return the next cutoff value
374+ virtual unsigned long int operator ++(void );
375+ // / Destructor
376+ virtual ~CutoffRepeat (void );
377+ };
378+
379+ }}
380+
381+ #include < gecode/search/cutoff.hpp>
382+
162383namespace Gecode { namespace Search {
163384
164385 class Stop ;
165- class Cutoff ;
166386
167387 /* *
168388 * \brief %Search engine options
@@ -261,16 +481,31 @@ namespace Gecode { namespace Search {
261481 */
262482 class GECODE_SEARCH_EXPORT Stop {
263483 public:
484+ // / \name Constructors and member functions
485+ // @{
264486 // / Default constructor
265487 Stop (void );
266488 // / Stop search, if returns true
267489 virtual bool stop (const Statistics& s, const Options& o) = 0;
268490 // / Destructor
269491 virtual ~Stop (void );
492+ // @}
493+ // / \name Memory management
494+ // @{
270495 // / Allocate memory from heap
271496 static void * operator new (size_t s);
272497 // / Free memory allocated from heap
273498 static void operator delete (void * p);
499+ // @}
500+ // / \name Predefined stop objects
501+ // @{
502+ // / Stop if node limit \a l has been exceeded
503+ static Stop* node (unsigned long int l);
504+ // / Stop if failure limit \a l has been exceeded
505+ static Stop* fail (unsigned long int l);
506+ // / Stop if time limit \a l (in milliseconds) has been exceeded
507+ static Stop* time (unsigned long int l);
508+ // @}
274509 };
275510
276511 /* *
@@ -381,62 +616,6 @@ namespace Gecode { namespace Search {
381616
382617#include < gecode/search/stop.hpp>
383618
384- namespace Gecode { namespace Search {
385-
386- /* *
387- * \brief Base class for cutoff generators for restart-based meta engine
388- */
389- class GECODE_SEARCH_EXPORT Cutoff {
390- public:
391- // / Default constructor
392- Cutoff (void );
393- // / Return the current cutoff value
394- virtual unsigned long int operator ()(void ) const = 0;
395- // / Increment and return the next cutoff value
396- virtual unsigned long int operator ++(void ) = 0 ;
397- // / Destructor
398- virtual ~Cutoff (void );
399- // / Create generator for constant sequence with constant \a s
400- static Cutoff*
401- constant (unsigned long int scale=1U );
402- // / Create generator for linear sequence scaled by \a scale
403- static Cutoff*
404- linear (unsigned long int scale=1U );
405- /* * Create generator for geometric sequence scaled by
406- * \a scale using base \a base
407- */
408- static Cutoff*
409- geometric (unsigned long int scale=1U , double base=1.5 );
410- // / Create generator for luby sequence with scale-factor \a scale
411- static Cutoff*
412- luby (unsigned long int scale=1U );
413- /* * Create generator for random sequence with seed \a seed that
414- * generates values between \a min and \a max with \a n steps
415- * between the extreme values (use 0 for \a n to get step size 1).
416- */
417- static Cutoff*
418- rnd (unsigned int seed,
419- unsigned long int min, unsigned long int max,
420- unsigned long int n);
421- // / Append cutoff values from \a c2 after \a n values from \a c1
422- static Cutoff*
423- append (Cutoff* c1, unsigned long int n, Cutoff* c2);
424- // / Merge cutoff values from \a c1 with values from \a c2
425- static Cutoff*
426- merge (Cutoff* c1, Cutoff* c2);
427- // / Create generator that repeats \a n times each cutoff value from \a c
428- static Cutoff*
429- repeat (Cutoff* c, unsigned long int n);
430- // / Allocate memory from heap
431- static void * operator new (size_t s);
432- // / Free memory allocated from heap
433- static void operator delete (void * p);
434- };
435-
436- }}
437-
438- #include < gecode/search/cutoff.hpp>
439-
440619namespace Gecode { namespace Search {
441620
442621 /* *
0 commit comments