File tree Expand file tree Collapse file tree 2 files changed +20
-5
lines changed
Expand file tree Collapse file tree 2 files changed +20
-5
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments