Skip to content

Commit 72fbdf9

Browse files
author
Christian Schulte
committed
All scripts must call a constructor with options
git-svn-id: file:///Users/tack/GecodeGitMigration/gecode-svn-mirror/gecode/trunk@14447 e85b7adc-8362-4630-8c63-7469d557c915
1 parent e318944 commit 72fbdf9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+99
-69
lines changed

examples/all-interval.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class AllInterval : public Script {
7272
public:
7373
/// Actual model
7474
AllInterval(const SizeOptions& opt) :
75+
Script(opt),
7576
x(*this, opt.size(), 0, opt.size()-1),
7677
d(*this, opt.size()-1, 1, opt.size()-1) {
7778
const int n = x.size();

examples/alpha.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ class Alpha : public Script {
6464
BRANCH_SIZE ///< Choose variable with smallest size
6565
};
6666
/// Actual model
67-
Alpha(const Options& opt) : le(*this,n,1,n) {
67+
Alpha(const Options& opt)
68+
: Script(opt), le(*this,n,1,n) {
6869
IntVar
6970
a(le[ 0]), b(le[ 1]), c(le[ 2]), e(le[ 4]), f(le[ 5]),
7071
g(le[ 6]), h(le[ 7]), i(le[ 8]), j(le[ 9]), k(le[10]),

examples/archimedean-spiral.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,14 @@ using namespace Gecode;
6868
*
6969
* \ingroup Example
7070
*/
71-
class ArchimedeanSpiral : public Script {
71+
class ArchimedeanSpiral : public FloatMaximizeScript {
7272
protected:
7373
/// The numbers
7474
FloatVarArray f;
75-
/// Minimum distance between two solutions
76-
FloatNum step;
7775
public:
7876
/// Actual model
79-
ArchimedeanSpiral(const Options&)
80-
: f(*this,4,-20,20), step(0.1) {
77+
ArchimedeanSpiral(const Options& opt)
78+
: FloatMaximizeScript(opt), f(*this,4,-20,20) {
8179
// Post equation
8280
FloatVar theta = f[0];
8381
FloatVar r = f[3];
@@ -95,17 +93,16 @@ class ArchimedeanSpiral : public Script {
9593
}
9694
/// Constructor for cloning \a p
9795
ArchimedeanSpiral(bool share, ArchimedeanSpiral& p)
98-
: Script(share,p), step(p.step) {
96+
: FloatMaximizeScript(share,p) {
9997
f.update(*this,share,p.f);
10098
}
10199
/// Copy during cloning
102100
virtual Space* copy(bool share) {
103101
return new ArchimedeanSpiral(share,*this);
104102
}
105-
/// Add constraint to current model to get next solution (not too close)
106-
virtual void constrain(const Space& _b) {
107-
const ArchimedeanSpiral& b = static_cast<const ArchimedeanSpiral&>(_b);
108-
rel(*this, f[0] >= (b.f[0].max()+step));
103+
/// Cost function
104+
virtual FloatVar cost(void) const {
105+
return f[0];
109106
}
110107
/// Print solution coordinates
111108
virtual void print(std::ostream& os) const {
@@ -120,9 +117,10 @@ class ArchimedeanSpiral : public Script {
120117
*/
121118
int main(int argc, char* argv[]) {
122119
Options opt("ArchimedeanSpiral");
123-
opt.parse(argc,argv);
124120
opt.solutions(0);
125-
Script::run<ArchimedeanSpiral,BAB,Options>(opt);
121+
opt.step(0.1);
122+
opt.parse(argc,argv);
123+
FloatMaximizeScript::run<ArchimedeanSpiral,BAB,Options>(opt);
126124
return 0;
127125
}
128126

examples/bacp.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ class BACP : public IntMinimizeScript {
120120
};
121121

122122
/// Actual model
123-
BACP(const SizeOptions& opt) : curr(curriculum[opt.size()]) {
123+
BACP(const SizeOptions& opt)
124+
: IntMinimizeScript(opt), curr(curriculum[opt.size()]) {
124125
std::map<std::string, int> courseMap; // Map names to course numbers
125126
int maxCredit = 0;
126127
int numberOfCourses = 0;

examples/bibd.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class BIBD : public Script {
109109

110110
/// Actual model
111111
BIBD(const BIBDOptions& o)
112-
: opt(o), _p(*this,opt.v*opt.b,0,1) {
112+
: Script(opt), opt(o), _p(*this,opt.v*opt.b,0,1) {
113113
Matrix<BoolVarArray> p(_p,opt.b,opt.v);
114114

115115
// r ones per row

examples/bin-packing.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,8 @@ class BinPacking : public IntMinimizeScript {
413413
};
414414
/// Actual model
415415
BinPacking(const InstanceOptions& opt)
416-
: spec(opt.instance()),
416+
: IntMinimizeScript(opt),
417+
spec(opt.instance()),
417418
load(*this, spec.upper(), 0, spec.capacity()),
418419
bin(*this, spec.items(), 0, spec.upper()-1),
419420
bins(*this, spec.lower(), spec.upper()) {

examples/black-hole.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ class BlackHole : public Script {
129129
};
130130
/// Actual model
131131
BlackHole(const SizeOptions& opt)
132-
: x(*this, 52, 0,51), y(*this, 52, 0,51)
133-
{
132+
: Script(opt), x(*this, 52, 0,51), y(*this, 52, 0,51) {
134133
// Black ace at bottom
135134
rel(*this, x[0], IRT_EQ, 0);
136135

examples/car-sequencing.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ class CarSequencing : public Script {
245245
public:
246246
/// Initial model
247247
CarSequencing(const CarOptions& opt)
248-
: problem(opt.size()),
248+
: Script(opt),
249+
problem(opt.size()),
249250
ncars(problems[problem][0]),
250251
noptions(problems[problem][1]),
251252
nclasses(problems[problem][2]),

examples/cartesian-heart.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ class CartesianHeart : public Script {
7272
FloatNum step;
7373
public:
7474
/// Actual model
75-
CartesianHeart(const Options&)
76-
: f(*this,2,-20,20), step(0.01) {
75+
CartesianHeart(const Options& opt)
76+
: Script(opt), f(*this,2,-20,20), step(0.01) {
7777
int q = 2;
7878
FloatNum p = 0.5;
7979
// Post equation

examples/colored-matrix.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,8 @@ class ColoredMatrix : public IntMinimizeScript {
361361

362362
/// Actual model
363363
ColoredMatrix(const ColoredMatrixOptions& opt0)
364-
: opt(opt0), height(opt.height()), width(opt.width()), colors(opt.colors()),
364+
: IntMinimizeScript(opt0),
365+
opt(opt0), height(opt.height()), width(opt.width()), colors(opt.colors()),
365366
x(*this, height*width, 1, colors),
366367
max_color(*this, 1, colors)
367368
{

0 commit comments

Comments
 (0)