Skip to content

Commit ce3cee2

Browse files
author
Christian Schulte
committed
More cleanups
git-svn-id: file:///Users/tack/GecodeGitMigration/gecode-svn-mirror/gecode/trunk@14435 e85b7adc-8362-4630-8c63-7469d557c915
1 parent aa0bbe4 commit ce3cee2

File tree

9 files changed

+156
-226
lines changed

9 files changed

+156
-226
lines changed

Makefile.dep

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -438,31 +438,6 @@ gecode/search/parallel/bab$(OBJSUFFIX) gecode/search/parallel/bab$(SBJSUFFIX): \
438438
./gecode/support/sort.hpp ./gecode/support/static-stack.hpp ./gecode/support/thread.hpp \
439439
./gecode/support/thread/none.hpp ./gecode/support/thread/pthreads.hpp ./gecode/support/thread/thread.hpp \
440440
./gecode/support/thread/windows.hpp ./gecode/support/timer.hpp
441-
gecode/search/rbs$(OBJSUFFIX) gecode/search/rbs$(SBJSUFFIX): \
442-
./gecode/kernel.hh ./gecode/kernel/activity.hpp ./gecode/kernel/advisor.hpp \
443-
./gecode/kernel/afc.hpp ./gecode/kernel/allocators.hpp ./gecode/kernel/archive.hpp \
444-
./gecode/kernel/array.hpp ./gecode/kernel/branch-tiebreak.hpp ./gecode/kernel/branch-traits.hpp \
445-
./gecode/kernel/branch-val.hpp ./gecode/kernel/branch-var.hpp ./gecode/kernel/brancher-merit.hpp \
446-
./gecode/kernel/brancher-val-commit.hpp ./gecode/kernel/brancher-val-sel-commit.hpp ./gecode/kernel/brancher-val-sel.hpp \
447-
./gecode/kernel/brancher-view-sel.hpp ./gecode/kernel/brancher-view-val.hpp ./gecode/kernel/brancher-view.hpp \
448-
./gecode/kernel/core.hpp ./gecode/kernel/exception.hpp ./gecode/kernel/global-afc.hpp \
449-
./gecode/kernel/macros.hpp ./gecode/kernel/memory-config.hpp ./gecode/kernel/memory-manager.hpp \
450-
./gecode/kernel/modevent.hpp ./gecode/kernel/propagator.hpp ./gecode/kernel/range-list.hpp \
451-
./gecode/kernel/region.hpp ./gecode/kernel/rnd.hpp ./gecode/kernel/shared-array.hpp \
452-
./gecode/kernel/var-imp.hpp ./gecode/kernel/var-type.hpp ./gecode/kernel/var.hpp \
453-
./gecode/kernel/view.hpp ./gecode/search.hh ./gecode/search/bab.hpp \
454-
./gecode/search/cutoff.hpp ./gecode/search/dfs.hpp ./gecode/search/engine-base.hpp \
455-
./gecode/search/exception.hpp ./gecode/search/meta/rbs.hh ./gecode/search/options.hpp \
456-
./gecode/search/rbs.hpp ./gecode/search/statistics.hpp ./gecode/search/stop.hpp \
457-
./gecode/search/support.hh ./gecode/support.hh ./gecode/support/auto-link.hpp \
458-
./gecode/support/bitset-base.hpp ./gecode/support/bitset-offset.hpp ./gecode/support/bitset.hpp \
459-
./gecode/support/block-allocator.hpp ./gecode/support/cast.hpp ./gecode/support/config.hpp \
460-
./gecode/support/dynamic-array.hpp ./gecode/support/dynamic-queue.hpp ./gecode/support/dynamic-stack.hpp \
461-
./gecode/support/exception.hpp ./gecode/support/heap.hpp ./gecode/support/hw-rnd.hpp \
462-
./gecode/support/int-type.hpp ./gecode/support/macros.hpp ./gecode/support/marked-pointer.hpp \
463-
./gecode/support/random.hpp ./gecode/support/sort.hpp ./gecode/support/static-stack.hpp \
464-
./gecode/support/thread.hpp ./gecode/support/thread/none.hpp ./gecode/support/thread/pthreads.hpp \
465-
./gecode/support/thread/thread.hpp ./gecode/support/thread/windows.hpp ./gecode/support/timer.hpp
466441
gecode/search/meta/rbs$(OBJSUFFIX) gecode/search/meta/rbs$(SBJSUFFIX): \
467442
./gecode/kernel.hh ./gecode/kernel/activity.hpp ./gecode/kernel/advisor.hpp \
468443
./gecode/kernel/afc.hpp ./gecode/kernel/allocators.hpp ./gecode/kernel/archive.hpp \

Makefile.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,7 @@ SEARCHSRC0 = \
248248
parallel/engine \
249249
dfs parallel/dfs \
250250
bab parallel/bab \
251-
rbs meta/rbs \
252-
meta/nogoods sequential/path parallel/path
251+
meta/rbs meta/nogoods sequential/path parallel/path
253252
SEARCHHDR0 = \
254253
statistics.hpp stop.hpp options.hpp cutoff.hpp \
255254
support.hh worker.hh exception.hpp \

gecode/search.hh

Lines changed: 40 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ namespace Gecode { namespace Search {
163163

164164
/**
165165
* \brief Base class for cutoff generators for restart-based meta engine
166+
* \ingroup TaskModelSearch
166167
*/
167168
class GECODE_SEARCH_EXPORT Cutoff {
168169
public:
@@ -220,7 +221,10 @@ namespace Gecode { namespace Search {
220221
//@}
221222
};
222223

223-
/// Cutoff generator for constant sequence
224+
/**
225+
* \brief Cutoff generator for constant sequence
226+
* \ingroup TaskModelSearch
227+
*/
224228
class GECODE_SEARCH_EXPORT CutoffConstant : public Cutoff {
225229
protected:
226230
/// Constant
@@ -234,7 +238,10 @@ namespace Gecode { namespace Search {
234238
virtual unsigned long int operator ++(void);
235239
};
236240

237-
/// Cutoff generator for linear sequence
241+
/**
242+
* \brief Cutoff generator for linear sequence
243+
* \ingroup TaskModelSearch
244+
*/
238245
class GECODE_SEARCH_EXPORT CutoffLinear : public Cutoff {
239246
protected:
240247
/// Scale factor
@@ -250,7 +257,10 @@ namespace Gecode { namespace Search {
250257
virtual unsigned long int operator ++(void);
251258
};
252259

253-
/// Cutoff generator for the Luby sequence
260+
/**
261+
* \brief Cutoff generator for the Luby sequence
262+
* \ingroup TaskModelSearch
263+
*/
254264
class GECODE_SEARCH_EXPORT CutoffLuby : public Cutoff {
255265
protected:
256266
/// Iteration number
@@ -274,7 +284,10 @@ namespace Gecode { namespace Search {
274284
virtual unsigned long int operator ++(void);
275285
};
276286

277-
/// Cutoff generator for the geometric sequence
287+
/**
288+
* \brief Cutoff generator for the geometric sequence
289+
* \ingroup TaskModelSearch
290+
*/
278291
class GECODE_SEARCH_EXPORT CutoffGeometric : public Cutoff {
279292
protected:
280293
/// Current cutoff value
@@ -292,7 +305,10 @@ namespace Gecode { namespace Search {
292305
virtual unsigned long int operator ++(void);
293306
};
294307

295-
/// Cutoff generator for the random sequence
308+
/**
309+
* \brief Cutoff generator for the random sequence
310+
* \ingroup TaskModelSearch
311+
*/
296312
class GECODE_SEARCH_EXPORT CutoffRandom : public Cutoff {
297313
protected:
298314
/// Random number generator
@@ -316,7 +332,10 @@ namespace Gecode { namespace Search {
316332
virtual unsigned long int operator ++(void);
317333
};
318334

319-
/// Cutoff generator appending two cutoff generators
335+
/**
336+
* \brief Cutoff generator appending two cutoff generators
337+
* \ingroup TaskModelSearch
338+
*/
320339
class GECODE_SEARCH_EXPORT CutoffAppend : public Cutoff {
321340
protected:
322341
/// First cutoff generators
@@ -336,7 +355,10 @@ namespace Gecode { namespace Search {
336355
virtual ~CutoffAppend(void);
337356
};
338357

339-
/// Cutoff generator merging two cutoff generators
358+
/**
359+
* \brief Cutoff generator merging two cutoff generators
360+
* \ingroup TaskModelSearch
361+
*/
340362
class GECODE_SEARCH_EXPORT CutoffMerge : public Cutoff {
341363
protected:
342364
/// First cutoff generator
@@ -354,7 +376,10 @@ namespace Gecode { namespace Search {
354376
virtual ~CutoffMerge(void);
355377
};
356378

357-
/// Cutoff generator that repeats a cutoff from another cutoff generator
379+
/**
380+
* \brief Cutoff generator that repeats a cutoff from another cutoff generator
381+
* \ingroup TaskModelSearch
382+
*/
358383
class GECODE_SEARCH_EXPORT CutoffRepeat : public Cutoff {
359384
protected:
360385
/// Actual cutoff generator
@@ -450,19 +475,6 @@ namespace Gecode { namespace Search {
450475

451476
#include <gecode/search/options.hpp>
452477

453-
namespace Gecode {
454-
455-
template<template<class> class E, class T>
456-
class RBS;
457-
458-
}
459-
460-
namespace Gecode { namespace Search { namespace Meta {
461-
462-
class RBS;
463-
464-
}}}
465-
466478
namespace Gecode { namespace Search {
467479

468480
/**
@@ -577,41 +589,6 @@ namespace Gecode { namespace Search {
577589
virtual bool stop(const Statistics& s, const Options& o);
578590
};
579591

580-
/**
581-
* \brief %Stop-object for meta engine
582-
* \ingroup TaskModelSearchStop
583-
*/
584-
class GECODE_SEARCH_EXPORT MetaStop : public Stop {
585-
template<template<class>class,class> friend class ::Gecode::RBS;
586-
friend class ::Gecode::Search::Meta::RBS;
587-
private:
588-
/// The failure stop object for the engine
589-
FailStop* e_stop;
590-
/// The stop object for the meta engine
591-
Stop* m_stop;
592-
/// Whether the engine was stopped
593-
bool e_stopped;
594-
/// Accumulated statistics for the meta engine
595-
Statistics m_stat;
596-
public:
597-
/// Stop the meta engine if indicated by the stop object \a s
598-
MetaStop(Stop* s);
599-
/// Return true if meta engine must be stopped
600-
virtual bool stop(const Statistics& s, const Options& o);
601-
/// Set current limit for the engine to \a l fails
602-
void limit(const Search::Statistics& s, unsigned long int l);
603-
/// Update statistics
604-
void update(const Search::Statistics& s);
605-
/// Return the stop object to control the engine
606-
Stop* enginestop(void) const;
607-
/// Return whether the engine has been stopped
608-
bool enginestopped(void) const;
609-
/// Return statistics for the meta engine
610-
Statistics metastatistics(void) const;
611-
/// Delete object
612-
~MetaStop(void);
613-
};
614-
615592
}}
616593

617594
#include <gecode/search/stop.hpp>
@@ -639,6 +616,13 @@ namespace Gecode { namespace Search {
639616

640617
}}
641618

619+
namespace Gecode {
620+
621+
template<template<class> class E, class T>
622+
class RBS;
623+
624+
}
625+
642626
namespace Gecode {
643627

644628
/**

gecode/search/meta/rbs.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,28 @@
4040

4141
namespace Gecode { namespace Search { namespace Meta {
4242

43+
/*
44+
* Stopping for meta search engines
45+
*
46+
*/
47+
48+
bool
49+
RestartStop::stop(const Statistics& s, const Options& o) {
50+
// Stop if the fail stop object for the engine says so
51+
if (e_stop->stop(s,o)) {
52+
e_stopped = true;
53+
m_stat.restart++;
54+
return true;
55+
}
56+
// Stop if the stop object for the meta engine says so
57+
if ((m_stop != NULL) && m_stop->stop(m_stat+s,o)) {
58+
e_stopped = false;
59+
return true;
60+
}
61+
return false;
62+
}
63+
64+
4365
Space*
4466
RBS::next(void) {
4567
if (restart) {

gecode/search/meta/rbs.hh

Lines changed: 87 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,93 @@
3535
*
3636
*/
3737

38-
3938
#ifndef __GECODE_SEARCH_META_RBS_HH__
4039
#define __GECODE_SEARCH_META_RBS_HH__
4140

4241
#include <gecode/search.hh>
4342

4443
namespace Gecode { namespace Search { namespace Meta {
4544

45+
class RBS;
46+
47+
/// %Stop-object for restart engine
48+
class GECODE_SEARCH_EXPORT RestartStop : public Stop {
49+
template<template<class>class,class> friend class ::Gecode::RBS;
50+
friend class ::Gecode::Search::Meta::RBS;
51+
private:
52+
/// The failure stop object for the engine
53+
FailStop* e_stop;
54+
/// The stop object for the meta engine
55+
Stop* m_stop;
56+
/// Whether the engine was stopped
57+
bool e_stopped;
58+
/// Accumulated statistics for the meta engine
59+
Statistics m_stat;
60+
public:
61+
/// Stop the meta engine if indicated by the stop object \a s
62+
RestartStop(Stop* s);
63+
/// Return true if meta engine must be stopped
64+
virtual bool stop(const Statistics& s, const Options& o);
65+
/// Set current limit for the engine to \a l fails
66+
void limit(const Search::Statistics& s, unsigned long int l);
67+
/// Update statistics
68+
void update(const Search::Statistics& s);
69+
/// Return the stop object to control the engine
70+
Stop* enginestop(void) const;
71+
/// Return whether the engine has been stopped
72+
bool enginestopped(void) const;
73+
/// Return statistics for the meta engine
74+
Statistics metastatistics(void) const;
75+
/// Delete object
76+
~RestartStop(void);
77+
};
78+
79+
80+
/*
81+
* Stopping for meta search engines
82+
*
83+
*/
84+
85+
forceinline
86+
RestartStop::RestartStop(Stop* s)
87+
: e_stop(new FailStop(0)), m_stop(s), e_stopped(false) {}
88+
89+
forceinline void
90+
RestartStop::limit(const Search::Statistics& s, unsigned long int l) {
91+
m_stat += s;
92+
e_stopped = false;
93+
e_stop->limit(l);
94+
}
95+
96+
forceinline void
97+
RestartStop::update(const Search::Statistics& s) {
98+
m_stat += s;
99+
}
100+
101+
forceinline Stop*
102+
RestartStop::enginestop(void) const {
103+
return e_stop;
104+
}
105+
106+
forceinline bool
107+
RestartStop::enginestopped(void) const {
108+
return e_stopped;
109+
}
110+
111+
forceinline Statistics
112+
RestartStop::metastatistics(void) const {
113+
return m_stat;
114+
}
115+
116+
forceinline
117+
RestartStop::~RestartStop(void) {
118+
delete e_stop;
119+
delete m_stop;
120+
}
121+
122+
46123
/// Engine for restart-based search
47-
class RBS : public Engine {
124+
class GECODE_SEARCH_EXPORT RBS : public Engine {
48125
protected:
49126
/// The actual engine
50127
Engine* e;
@@ -55,19 +132,18 @@ namespace Gecode { namespace Search { namespace Meta {
55132
/// The cutoff object
56133
Cutoff* co;
57134
/// The stop control object
58-
MetaStop* stop;
135+
RestartStop* stop;
136+
/// How many solutions since the last restart
137+
unsigned long int sslr;
59138
/// Whether the slave can be shared with the master
60139
bool shared;
61140
/// Whether search for the next solution will be complete
62141
bool complete;
63142
/// Whether a restart must be performed when next is called
64143
bool restart;
65-
/// How many solutions since the last restart
66-
unsigned long int sslr;
67144
public:
68145
/// Constructor
69-
RBS(Space* s, Cutoff* co0, MetaStop* stop0,
70-
Engine* e0, const Options& o);
146+
RBS(Space* s, RestartStop* stop0, Engine* e0, const Options& o);
71147
/// Return next solution (NULL, if none exists or search has been stopped)
72148
virtual Space* next(void);
73149
/// Return statistics
@@ -83,10 +159,11 @@ namespace Gecode { namespace Search { namespace Meta {
83159
};
84160

85161
forceinline
86-
RBS::RBS(Space* s, Cutoff* co0, MetaStop* stop0,
162+
RBS::RBS(Space* s, RestartStop* stop0,
87163
Engine* e0, const Options& opt)
88-
: e(e0), master(s), last(NULL), co(co0), stop(stop0),
89-
shared(opt.threads == 1), complete(true), restart(false), sslr(0) {
164+
: e(e0), master(s), last(NULL), co(opt.cutoff), stop(stop0),
165+
sslr(0),
166+
shared(opt.threads == 1), complete(true), restart(false) {
90167
stop->limit(Statistics(),(*co)());
91168
}
92169

0 commit comments

Comments
 (0)