Skip to content

Commit 7e78761

Browse files
author
Christian Schulte
committed
Updated
git-svn-id: file:///Users/tack/GecodeGitMigration/gecode-svn-mirror/gecode/trunk@14448 e85b7adc-8362-4630-8c63-7469d557c915
1 parent 72fbdf9 commit 7e78761

File tree

4 files changed

+48
-22
lines changed

4 files changed

+48
-22
lines changed

changelog.in

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,33 @@ Date: 2015-01-20
7272
[DESCRIPTION]
7373
Yada! Yada!
7474

75+
[ENTRY]
76+
Module: driver
77+
What: change
78+
Rank: major
79+
[DESCRIPTION]
80+
All scripts now must call the constructor of their base class
81+
with an option argument. Note that you will have to change your
82+
models!
83+
84+
[ENTRY]
85+
Module: driver
86+
What: new
87+
Rank: minor
88+
Thanks: Mark Manser
89+
[DESCRIPTION]
90+
An option -step now can pass an improvement step to scripts of
91+
type FloatMinimizeScript and FloatMaximizeScript.
92+
93+
[ENTRY]
94+
Module: minimodel
95+
What: new
96+
Rank: minor
97+
Thanks: Mark Manser
98+
[DESCRIPTION]
99+
The classes FloatMinimizeSpace and FloatMaximizeSpace can be
100+
created with an improvement step for optimization.
101+
75102
[ENTRY]
76103
Module: flatzinc
77104
What: bug

examples/cartesian-heart.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class CartesianHeart : public Script {
7373
public:
7474
/// Actual model
7575
CartesianHeart(const Options& opt)
76-
: Script(opt), f(*this,2,-20,20), step(0.01) {
76+
: Script(opt), f(*this,2,-20,20), step(opt.step()) {
7777
int q = 2;
7878
FloatNum p = 0.5;
7979
// Post equation
@@ -111,8 +111,9 @@ class CartesianHeart : public Script {
111111
*/
112112
int main(int argc, char* argv[]) {
113113
Options opt("CartesianHeart");
114-
opt.parse(argc,argv);
115114
opt.solutions(0);
115+
opt.step(0.01);
116+
opt.parse(argc,argv);
116117
Script::run<CartesianHeart,BAB,Options>(opt);
117118
return 0;
118119
}

examples/descartes-folium.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ using namespace Gecode;
6969
*
7070
* \ingroup Example
7171
*/
72-
class DescartesFolium : public Script {
72+
class DescartesFolium : public FloatMaximizeScript {
7373
protected:
7474
/// The numbers
7575
FloatVarArray f;
@@ -78,7 +78,7 @@ class DescartesFolium : public Script {
7878
public:
7979
/// Actual model
8080
DescartesFolium(const Options& opt)
81-
: Script(opt), f(*this,3,-20,20), step(0.1) {
81+
: FloatMaximizeScript(opt), f(*this,3,-20,20) {
8282
// Post equation
8383
FloatVar p = f[0];
8484
FloatVar x = f[1];
@@ -92,17 +92,16 @@ class DescartesFolium : public Script {
9292
}
9393
/// Constructor for cloning \a p
9494
DescartesFolium(bool share, DescartesFolium& p)
95-
: Script(share,p), step(p.step) {
95+
: FloatMaximizeScript(share,p) {
9696
f.update(*this,share,p.f);
9797
}
9898
/// Copy during cloning
9999
virtual Space* copy(bool share) {
100100
return new DescartesFolium(share,*this);
101101
}
102-
/// Add constraint to current model to get next solution (not too close)
103-
virtual void constrain(const Space& _b) {
104-
const DescartesFolium& b = static_cast<const DescartesFolium&>(_b);
105-
rel(*this, f[0] >= (b.f[0].max()+step));
102+
/// Cost function
103+
virtual FloatVar cost(void) const {
104+
return f[0];
106105
}
107106
/// Print solution coordinates
108107
virtual void print(std::ostream& os) const {
@@ -117,9 +116,10 @@ class DescartesFolium : public Script {
117116
*/
118117
int main(int argc, char* argv[]) {
119118
Options opt("DescartesFolium");
120-
opt.parse(argc,argv);
121119
opt.solutions(0);
122-
Script::run<DescartesFolium,BAB,Options>(opt);
120+
opt.step(0.1);
121+
opt.parse(argc,argv);
122+
FloatMaximizeScript::run<DescartesFolium,BAB,Options>(opt);
123123
return 0;
124124
}
125125

examples/golden-spiral.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,14 @@ using namespace Gecode;
7878
*
7979
* \ingroup Example
8080
*/
81-
class GoldenSpiral : public Script {
81+
class GoldenSpiral : public FloatMaximizeScript {
8282
protected:
8383
/// The numbers
8484
FloatVarArray f;
85-
/// Minimum distance between two solutions
86-
FloatNum step;
8785
public:
8886
/// Actual model
8987
GoldenSpiral(const Options& opt)
90-
: Script(opt), f(*this,4,-20,20), step(0.1) {
88+
: FloatMaximizeScript(opt), f(*this,4,-20,20) {
9189
// Post equation
9290
FloatVar theta = f[0];
9391
FloatVar r = f[3];
@@ -103,17 +101,16 @@ class GoldenSpiral : public Script {
103101
}
104102
/// Constructor for cloning \a p
105103
GoldenSpiral(bool share, GoldenSpiral& p)
106-
: Script(share,p), step(p.step) {
104+
: FloatMaximizeScript(share,p) {
107105
f.update(*this,share,p.f);
108106
}
109107
/// Copy during cloning
110108
virtual Space* copy(bool share) {
111109
return new GoldenSpiral(share,*this);
112110
}
113-
/// Add constraint to current model to get next solution (not too close)
114-
virtual void constrain(const Space& _b) {
115-
const GoldenSpiral& b = static_cast<const GoldenSpiral&>(_b);
116-
rel(*this, f[0] >= (b.f[0].max()+step));
111+
/// Cost function
112+
virtual FloatVar cost(void) const {
113+
return f[0];
117114
}
118115
/// Print solution coordinates
119116
virtual void print(std::ostream& os) const {
@@ -128,9 +125,10 @@ class GoldenSpiral : public Script {
128125
*/
129126
int main(int argc, char* argv[]) {
130127
Options opt("GoldenSpiral");
131-
opt.parse(argc,argv);
132128
opt.solutions(0);
133-
Script::run<GoldenSpiral,BAB,Options>(opt);
129+
opt.step(0.1);
130+
opt.parse(argc,argv);
131+
FloatMaximizeScript::run<GoldenSpiral,BAB,Options>(opt);
134132
return 0;
135133
}
136134

0 commit comments

Comments
 (0)