Skip to content

Commit 42eecca

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

File tree

8 files changed

+5254
-4997
lines changed

8 files changed

+5254
-4997
lines changed

Makefile.dep

Lines changed: 5087 additions & 4931 deletions
Large diffs are not rendered by default.

Makefile.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ endif
244244
#
245245

246246
SEARCHSRC0 = \
247-
stop options cutoff \
247+
stop options cutoff engine \
248248
parallel/engine \
249249
dfs parallel/dfs \
250250
bab parallel/bab \
@@ -256,7 +256,7 @@ SEARCHHDR0 = \
256256
parallel/path.hh parallel/engine.hh \
257257
parallel/dfs.hh parallel/bab.hh \
258258
meta/rbs.hh meta/nogoods.hh \
259-
dfs.hpp bab.hpp rbs.hpp engine-base.hpp
259+
dfs.hpp bab.hpp rbs.hpp engine.hpp engine-base.hpp
260260

261261
SEARCHSRC = $(SEARCHSRC0:%=gecode/search/%.cpp)
262262
SEARCHHDR = gecode/search.hh $(SEARCHHDR0:%=gecode/search/%)

gecode/search.hh

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -598,48 +598,56 @@ namespace Gecode { namespace Search {
598598
/**
599599
* \brief %Search engine implementation interface
600600
*/
601-
class Engine {
601+
class GECODE_SEARCH_EXPORT Engine {
602602
public:
603603
/// Return next solution (NULL, if none exists or search has been stopped)
604604
virtual Space* next(void) = 0;
605605
/// Return statistics
606606
virtual Statistics statistics(void) const = 0;
607607
/// Check whether engine has been stopped
608608
virtual bool stopped(void) const = 0;
609-
/// Reset engine to restart at space \a s
610-
virtual void reset(Space* s) = 0;
611-
/// Return no-goods
612-
virtual NoGoods& nogoods(void) = 0;
609+
/// Reset engine to restart at space \a s (does nothing)
610+
virtual void reset(Space* s);
611+
/// Return no-goods (the no-goods are empty)
612+
virtual NoGoods& nogoods(void);
613613
/// Destructor
614-
virtual ~Engine(void) {}
614+
virtual ~Engine(void);
615+
/// \name Memory management
616+
//@{
617+
/// Allocate memory from heap
618+
static void* operator new(size_t s);
619+
/// Free memory allocated from heap
620+
static void operator delete(void* p);
621+
//@}
615622
};
616623

617624
}}
618625

626+
#include <gecode/search/engine.hpp>
627+
619628
namespace Gecode {
620629

621630
template<template<class> class E, class T>
622631
class RBS;
623632

624633
}
625634

626-
namespace Gecode {
635+
namespace Gecode { namespace Search {
627636

628-
/**
629-
* \brief Base-class for search engines
630-
*/
637+
/// Base-class for search engines
631638
class EngineBase {
632639
template<template<class>class,class> friend class ::Gecode::RBS;
633640
protected:
634641
/// The actual search engine
635642
Search::Engine* e;
636-
/// Destructor
637-
~EngineBase(void);
638643
/// Constructor
639644
EngineBase(Search::Engine* e = NULL);
645+
public:
646+
/// Destructor
647+
~EngineBase(void);
640648
};
641649

642-
}
650+
}}
643651

644652
#include <gecode/search/engine-base.hpp>
645653

@@ -654,7 +662,7 @@ namespace Gecode {
654662
* \ingroup TaskModelSearch
655663
*/
656664
template<class T>
657-
class DFS : public EngineBase {
665+
class DFS : public Search::EngineBase {
658666
public:
659667
/// Initialize search engine for space \a s with options \a o
660668
DFS(T* s, const Search::Options& o=Search::Options::def);
@@ -690,7 +698,7 @@ namespace Gecode {
690698
* \ingroup TaskModelSearch
691699
*/
692700
template<class T>
693-
class BAB : public EngineBase {
701+
class BAB : public Search::EngineBase {
694702
public:
695703
/// Initialize engine for space \a s and options \a o
696704
BAB(T* s, const Search::Options& o=Search::Options::def);
@@ -744,7 +752,7 @@ namespace Gecode {
744752
* \ingroup TaskModelSearch
745753
*/
746754
template<template<class> class E, class T>
747-
class RBS : public EngineBase {
755+
class RBS : public Search::EngineBase {
748756
public:
749757
/// Initialize engine for space \a s and options \a o
750758
RBS(T* s, const Search::Options& o);

gecode/search/engine-base.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
*
4040
*/
4141

42-
namespace Gecode {
42+
namespace Gecode { namespace Search {
4343

4444
forceinline
4545
EngineBase::EngineBase(Search::Engine* e0)
@@ -49,6 +49,6 @@ namespace Gecode {
4949
delete e;
5050
}
5151

52-
}
52+
}}
5353

5454
// STATISTICS: search-other

gecode/search/engine.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2+
/*
3+
* Main authors:
4+
* Christian Schulte <[email protected]>
5+
*
6+
* Copyright:
7+
* Christian Schulte, 2015
8+
*
9+
* Last modified:
10+
* $Date$ by $Author$
11+
* $Revision$
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+
#include <gecode/search.hh>
39+
40+
namespace Gecode { namespace Search {
41+
42+
void
43+
Engine::reset(Space* s) {
44+
(void) s;
45+
}
46+
NoGoods&
47+
Engine::nogoods(void) {
48+
return NoGoods::eng;
49+
}
50+
51+
}}
52+
53+
// STATISTICS: search-other

gecode/search/engine.hpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2+
/*
3+
* Main authors:
4+
* Christian Schulte <[email protected]>
5+
*
6+
* Copyright:
7+
* Christian Schulte, 2015
8+
*
9+
* Last modified:
10+
* $Date$ by $Author$
11+
* $Revision$
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+
forceinline
41+
Engine::~Engine(void) {}
42+
forceinline void*
43+
Engine::operator new(size_t s) {
44+
return heap.ralloc(s);
45+
}
46+
forceinline void
47+
Engine::operator delete(void* p) {
48+
heap.rfree(p);
49+
}
50+
51+
}}
52+
53+
// STATISTICS: search-other

gecode/search/meta/rbs.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,6 @@ namespace Gecode { namespace Search { namespace Meta {
140140
return e->stopped();
141141
}
142142

143-
void
144-
RBS::reset(Space*) {
145-
}
146-
147-
NoGoods&
148-
RBS::nogoods(void) {
149-
return NoGoods::eng;
150-
}
151-
152143
RBS::~RBS(void) {
153144
// Deleting e also deletes stop
154145
delete e;

gecode/search/meta/rbs.hh

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,39 @@ namespace Gecode { namespace Search { namespace Meta {
7676
~RestartStop(void);
7777
};
7878

79+
/// Engine for restart-based search
80+
class GECODE_SEARCH_EXPORT RBS : public Engine {
81+
protected:
82+
/// The actual engine
83+
Engine* e;
84+
/// The master space to restart from
85+
Space* master;
86+
/// The last solution space (possibly NULL)
87+
Space* last;
88+
/// The cutoff object
89+
Cutoff* co;
90+
/// The stop control object
91+
RestartStop* stop;
92+
/// How many solutions since the last restart
93+
unsigned long int sslr;
94+
/// Whether the slave can be shared with the master
95+
bool shared;
96+
/// Whether search for the next solution will be complete
97+
bool complete;
98+
/// Whether a restart must be performed when next is called
99+
bool restart;
100+
public:
101+
/// Constructor
102+
RBS(Space* s, RestartStop* stop0, Engine* e0, const Options& o);
103+
/// Return next solution (NULL, if none exists or search has been stopped)
104+
virtual Space* next(void);
105+
/// Return statistics
106+
virtual Search::Statistics statistics(void) const;
107+
/// Check whether engine has been stopped
108+
virtual bool stopped(void) const;
109+
/// Destructor
110+
virtual ~RBS(void);
111+
};
79112

80113
/*
81114
* Stopping for meta search engines
@@ -120,43 +153,6 @@ namespace Gecode { namespace Search { namespace Meta {
120153
}
121154

122155

123-
/// Engine for restart-based search
124-
class GECODE_SEARCH_EXPORT RBS : public Engine {
125-
protected:
126-
/// The actual engine
127-
Engine* e;
128-
/// The master space to restart from
129-
Space* master;
130-
/// The last solution space (possibly NULL)
131-
Space* last;
132-
/// The cutoff object
133-
Cutoff* co;
134-
/// The stop control object
135-
RestartStop* stop;
136-
/// How many solutions since the last restart
137-
unsigned long int sslr;
138-
/// Whether the slave can be shared with the master
139-
bool shared;
140-
/// Whether search for the next solution will be complete
141-
bool complete;
142-
/// Whether a restart must be performed when next is called
143-
bool restart;
144-
public:
145-
/// Constructor
146-
RBS(Space* s, RestartStop* stop0, Engine* e0, const Options& o);
147-
/// Return next solution (NULL, if none exists or search has been stopped)
148-
virtual Space* next(void);
149-
/// Return statistics
150-
virtual Search::Statistics statistics(void) const;
151-
/// Check whether engine has been stopped
152-
virtual bool stopped(void) const;
153-
/// Reset engine to restart at space \a s
154-
virtual void reset(Space* s);
155-
/// Return no-goods
156-
virtual NoGoods& nogoods(void);
157-
/// Destructor
158-
virtual ~RBS(void);
159-
};
160156

161157
forceinline
162158
RBS::RBS(Space* s, RestartStop* stop0,

0 commit comments

Comments
 (0)