Skip to content

Commit 6f86995

Browse files
committed
Add step option to FlatZinc driver
git-svn-id: file:///Users/tack/GecodeGitMigration/gecode-svn-mirror/gecode/trunk@14463 e85b7adc-8362-4630-8c63-7469d557c915
1 parent c529375 commit 6f86995

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

changelog.in

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

75+
[ENTRY]
76+
Module: flatzinc
77+
What: new
78+
Rank: minor
79+
[DESCRIPTION]
80+
An option -step now can pass an improvement step for
81+
optimization of float problems.
82+
7583
[ENTRY]
7684
Module: driver
7785
What: change

gecode/flatzinc.hh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ namespace Gecode { namespace FlatZinc {
223223
Gecode::Driver::BoolOption _nogoods; ///< Whether to use no-goods
224224
Gecode::Driver::UnsignedIntOption _nogoods_limit; ///< Depth limit for extracting no-goods
225225
Gecode::Driver::BoolOption _interrupt; ///< Whether to catch SIGINT
226+
Gecode::Driver::DoubleOption _step; ///< Step option
226227
//@}
227228

228229
/// \name Execution options
@@ -255,6 +256,7 @@ namespace Gecode { namespace FlatZinc {
255256
Search::Config::nogoods_limit),
256257
_interrupt("-interrupt","whether to catch Ctrl-C (true) or not (false)",
257258
true),
259+
_step("-step","step distance for float optimization",0.0),
258260
_mode("-mode","how to execute script",Gecode::SM_SOLUTION),
259261
_stat("-s","emit statistics"),
260262
_output("-o","file to send output to") {
@@ -274,6 +276,7 @@ namespace Gecode { namespace FlatZinc {
274276
add(_decay);
275277
add(_node); add(_fail); add(_time); add(_interrupt);
276278
add(_seed);
279+
add(_step);
277280
add(_restart); add(_r_base); add(_r_scale);
278281
add(_nogoods); add(_nogoods_limit);
279282
add(_mode); add(_stat);
@@ -306,6 +309,7 @@ namespace Gecode { namespace FlatZinc {
306309
unsigned int fail(void) const { return _fail.value(); }
307310
unsigned int time(void) const { return _time.value(); }
308311
int seed(void) const { return _seed.value(); }
312+
double step(void) const { return _step.value(); }
309313
const char* output(void) const { return _output.value(); }
310314
Gecode::ScriptMode mode(void) const {
311315
return static_cast<Gecode::ScriptMode>(_mode.value());
@@ -452,6 +456,8 @@ namespace Gecode { namespace FlatZinc {
452456
Gecode::FloatVarArray fv_aux;
453457
/// Indicates whether a float variable is introduced by mzn2fzn
454458
std::vector<bool> fv_introduced;
459+
/// Step by which a next solution has to have lower cost
460+
Gecode::FloatNum step;
455461
#endif
456462
/// Whether the introduced variables still need to be copied
457463
bool needAuxVars;

gecode/flatzinc/flatzinc.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,9 @@ namespace Gecode { namespace FlatZinc {
623623
FlatZincSpace::FlatZincSpace(bool share, FlatZincSpace& f)
624624
: Space(share, f), _random(f._random),
625625
_solveAnnotations(NULL), iv_boolalias(NULL),
626+
#ifdef GECODE_HAS_FLOAT_VARS
627+
step(f.step),
628+
#endif
626629
needAuxVars(f.needAuxVars) {
627630
_optVar = f._optVar;
628631
_optVarIsInt = f._optVarIsInt;
@@ -1475,6 +1478,9 @@ namespace Gecode { namespace FlatZinc {
14751478
true);
14761479
o.c_d = opt.c_d();
14771480
o.a_d = opt.a_d();
1481+
#ifdef GECODE_HAS_FLOAT_VARS
1482+
step = opt.step();
1483+
#endif
14781484
o.threads = opt.threads();
14791485
o.nogoods_limit = opt.nogoods() ? opt.nogoods_limit() : 0;
14801486
o.cutoff = Driver::createCutoff(opt);
@@ -1603,10 +1609,10 @@ namespace Gecode { namespace FlatZinc {
16031609
#ifdef GECODE_HAS_FLOAT_VARS
16041610
if (_method == MIN)
16051611
rel(*this, fv[_optVar], FRT_LE,
1606-
static_cast<const FlatZincSpace*>(&s)->fv[_optVar].val());
1612+
static_cast<const FlatZincSpace*>(&s)->fv[_optVar].val()-step);
16071613
else if (_method == MAX)
16081614
rel(*this, fv[_optVar], FRT_GR,
1609-
static_cast<const FlatZincSpace*>(&s)->fv[_optVar].val());
1615+
static_cast<const FlatZincSpace*>(&s)->fv[_optVar].val()+step);
16101616
#endif
16111617
}
16121618
}

0 commit comments

Comments
 (0)