Skip to content

Commit d65c557

Browse files
author
Christian Schulte
committed
FloatOptimize supports step value
git-svn-id: file:///Users/tack/GecodeGitMigration/gecode-svn-mirror/gecode/trunk@14445 e85b7adc-8362-4630-8c63-7469d557c915
1 parent 5336f1d commit d65c557

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

gecode/minimodel.hh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,9 +2220,12 @@ namespace Gecode {
22202220
/// Baseclass for float-based cost-based optimization
22212221
template<FloatRelType frt>
22222222
class FloatOptimizeSpace : public Space {
2223+
protected:
2224+
/// Step to increment for next better solution
2225+
FloatNum step;
22232226
public:
2224-
/// Default constructor
2225-
FloatOptimizeSpace(void);
2227+
/// Constructor with step \a s
2228+
FloatOptimizeSpace(FloatNum s=0.0);
22262229
/// Constructor for cloning
22272230
FloatOptimizeSpace(bool share, FloatOptimizeSpace& s);
22282231
/// Member function constraining according to cost

gecode/minimodel/optimize.hpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,14 @@ namespace Gecode { namespace MiniModel {
6060

6161
template<FloatRelType frt>
6262
forceinline
63-
FloatOptimizeSpace<frt>::FloatOptimizeSpace(void) {}
63+
FloatOptimizeSpace<frt>::FloatOptimizeSpace(FloatNum s)
64+
: step(s) {}
6465

6566
template<FloatRelType frt>
6667
forceinline
6768
FloatOptimizeSpace<frt>::FloatOptimizeSpace(bool share,
6869
FloatOptimizeSpace& s)
69-
: Space(share,s) {}
70+
: Space(share,s), step(s.step) {}
7071

7172
template<FloatRelType frt>
7273
void
@@ -75,7 +76,18 @@ namespace Gecode { namespace MiniModel {
7576
dynamic_cast<const FloatOptimizeSpace<frt>*>(&_best);
7677
if (best == NULL)
7778
throw DynamicCastFailed("FloatOptimizeSpace::constrain");
78-
rel(*this, cost(), frt, best->cost().val());
79+
switch (frt) {
80+
case FRT_LE:
81+
// Minimize cost variable
82+
rel(*this, cost(), FRT_LE, best->cost().val()-step);
83+
break;
84+
case FRT_GR:
85+
// Maximize cost variable
86+
rel(*this, cost(), FRT_GR, best->cost().val()+step);
87+
break;
88+
default:
89+
GECODE_NEVER;
90+
}
7991
}
8092

8193
#endif

0 commit comments

Comments
 (0)