Skip to content

Commit e318944

Browse files
author
Christian Schulte
committed
All scripts now have a constructor taking options as argumenrs and supporting a floating point step value
git-svn-id: file:///Users/tack/GecodeGitMigration/gecode-svn-mirror/gecode/trunk@14446 e85b7adc-8362-4630-8c63-7469d557c915
1 parent d65c557 commit e318944

File tree

4 files changed

+127
-58
lines changed

4 files changed

+127
-58
lines changed

gecode/driver.hh

Lines changed: 91 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ namespace Gecode {
334334
Driver::StringOption _branching; ///< Branching options
335335
Driver::DoubleOption _decay; ///< Decay option
336336
Driver::UnsignedIntOption _seed; ///< Seed option
337+
Driver::DoubleOption _step; ///< Step option
337338
//@}
338339

339340
/// \name Search options
@@ -412,6 +413,11 @@ namespace Gecode {
412413
void seed(unsigned int s);
413414
/// Return seed value
414415
unsigned int seed(void) const;
416+
417+
/// Set default step value
418+
void step(double s);
419+
/// Return step value
420+
double step(void) const;
415421
//@}
416422

417423
/// \name Search options
@@ -614,51 +620,80 @@ namespace Gecode {
614620

615621
#include <gecode/driver/options.hpp>
616622

617-
namespace Gecode {
623+
namespace Gecode { namespace Driver {
618624

619-
namespace Driver {
620-
/**
621-
* \brief Parametric base-class for scripts
625+
/**
626+
* \brief Parametric base-class for scripts
627+
*
628+
* All scripts must inherit from this class
629+
* - adds printing and comparison for Gist to scripts
630+
* - run allows to execute scripts
631+
*/
632+
template<class BaseSpace>
633+
class ScriptBase : public BaseSpace {
634+
public:
635+
/// Constructor
636+
ScriptBase(const Options& opt);
637+
/// Constructor used for cloning
638+
ScriptBase(bool share, ScriptBase& e);
639+
/// Print a solution to \a os
640+
virtual void print(std::ostream& os) const;
641+
/// Compare with \a s
642+
virtual void compare(const Space& home, std::ostream& os) const;
643+
/// Choose output stream according to \a name
644+
static std::ostream& select_ostream(const char* name, std::ofstream& ofs);
645+
/** Run script with search engine \a Engine and options \a opt
646+
*
647+
* In the solution and stat modes, search can be aborted by sending
648+
* SIGINT to the process (i.e., pressing Ctrl-C on the command
649+
* line).
622650
*
623-
* All scripts must inherit from this class
624-
* - adds printing and comparison for Gist to scripts
625-
* - run allows to execute scripts
651+
* In case \a s is different from NULL, the search engine uses
652+
* \a s as root of the search tree.
626653
*/
627-
template<class BaseSpace>
628-
class ScriptBase : public BaseSpace {
629-
public:
630-
/// Default constructor
631-
ScriptBase(void) {}
632-
/// Constructor used for cloning
633-
ScriptBase(bool share, ScriptBase& e)
634-
: BaseSpace(share,e) {}
635-
/// Print a solution to \a os
636-
virtual void print(std::ostream& os) const { (void) os; }
637-
/// Compare with \a s
638-
virtual void compare(const Space&, std::ostream& os) const {
639-
(void) os;
640-
}
641-
/// Choose output stream according to \a name
642-
static std::ostream& select_ostream(const char* name, std::ofstream& ofs);
643-
/** Run script with search engine \a Engine and options \a opt
644-
*
645-
* In the solution and stat modes, search can be aborted by sending
646-
* SIGINT to the process (i.e., pressing Ctrl-C on the command
647-
* line).
648-
*
649-
* In case \a s is different from NULL, the search engine uses
650-
* \a s as root of the search tree.
651-
*/
652-
template<class Script, template<class> class Engine, class Options>
653-
static void run(const Options& opt, Script* s=NULL);
654-
private:
655-
template<class Script, template<class> class Engine, class Options,
656-
template<template<class> class,class> class Meta>
657-
static void runMeta(const Options& opt, Script* s);
658-
/// Catch wrong definitions of copy constructor
659-
explicit ScriptBase(ScriptBase& e);
660-
};
661-
}
654+
template<class Script, template<class> class Engine, class Options>
655+
static void run(const Options& opt, Script* s=NULL);
656+
private:
657+
template<class Script, template<class> class Engine, class Options,
658+
template<template<class> class,class> class Meta>
659+
static void runMeta(const Options& opt, Script* s);
660+
/// Catch wrong definitions of copy constructor
661+
explicit ScriptBase(ScriptBase& e);
662+
};
663+
664+
#ifdef GECODE_HAS_FLOAT_VARS
665+
666+
/// Class to extract the step option value
667+
template<class BaseSpace>
668+
class ExtractStepOption : public BaseSpace {
669+
public:
670+
/// Constructor that extracts the step value
671+
ExtractStepOption(const Options& opt)
672+
: BaseSpace(opt.step()) {}
673+
/// Constructor used for cloning
674+
ExtractStepOption(bool share, BaseSpace& e)
675+
: BaseSpace(share,e) {}
676+
};
677+
678+
#endif
679+
680+
/// Class to ignore the step option value
681+
template<class BaseSpace>
682+
class IgnoreStepOption : public BaseSpace {
683+
public:
684+
/// Constructor
685+
IgnoreStepOption(const Options& opt) {}
686+
/// Constructor used for cloning
687+
IgnoreStepOption(bool share, BaseSpace& e)
688+
: BaseSpace(share,e) {}
689+
};
690+
691+
692+
}}
693+
694+
#include <gecode/driver/script.hpp>
695+
696+
namespace Gecode {
662697

663698
/**
664699
* \defgroup TaskDriverScript Script classes
@@ -669,47 +704,52 @@ namespace Gecode {
669704
* \brief Base-class for scripts
670705
* \ingroup TaskDriverScript
671706
*/
672-
typedef Driver::ScriptBase<Space> Script;
707+
typedef Driver::ScriptBase<Driver::IgnoreStepOption<Space> >
708+
Script;
673709
/**
674710
* \brief Base-class for scripts for finding solution of lowest integer cost
675711
* \ingroup TaskDriverScript
676712
*/
677-
typedef Driver::ScriptBase<MinimizeSpace> MinimizeScript;
713+
typedef Driver::ScriptBase<Driver::IgnoreStepOption<MinimizeSpace> >
714+
MinimizeScript;
678715
/**
679716
* \brief Base-class for scripts for finding solution of highest integer cost
680717
* \ingroup TaskDriverScript
681718
*/
682-
typedef Driver::ScriptBase<MaximizeSpace> MaximizeScript;
719+
typedef Driver::ScriptBase<Driver::IgnoreStepOption<MaximizeSpace> >
720+
MaximizeScript;
683721
/**
684722
* \brief Base-class for scripts for finding solution of lowest integer cost
685723
* \ingroup TaskDriverScript
686724
*/
687-
typedef Driver::ScriptBase<IntMinimizeSpace> IntMinimizeScript;
725+
typedef Driver::ScriptBase<Driver::IgnoreStepOption<IntMinimizeSpace> >
726+
IntMinimizeScript;
688727
/**
689728
* \brief Base-class for scripts for finding solution of highest integer cost
690729
* \ingroup TaskDriverScript
691730
*/
692-
typedef Driver::ScriptBase<IntMaximizeSpace> IntMaximizeScript;
731+
typedef Driver::ScriptBase<Driver::IgnoreStepOption<IntMaximizeSpace> >
732+
IntMaximizeScript;
693733

694734
#ifdef GECODE_HAS_FLOAT_VARS
695735

696736
/**
697737
* \brief Base-class for scripts for finding solution of lowest float cost
698738
* \ingroup TaskDriverScript
699739
*/
700-
typedef Driver::ScriptBase<FloatMinimizeSpace> FloatMinimizeScript;
740+
typedef Driver::ScriptBase<Driver::ExtractStepOption<FloatMinimizeSpace> >
741+
FloatMinimizeScript;
701742
/**
702743
* \brief Base-class for scripts for finding solution of highest float cost
703744
* \ingroup TaskDriverScript
704745
*/
705-
typedef Driver::ScriptBase<FloatMaximizeSpace> FloatMaximizeScript;
746+
typedef Driver::ScriptBase<Driver::ExtractStepOption<FloatMaximizeSpace> >
747+
FloatMaximizeScript;
706748

707749
#endif
708750

709751
}
710752

711-
#include <gecode/driver/script.hpp>
712-
713753
#endif
714754

715755
// STATISTICS: driver-any

gecode/driver/options.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ namespace Gecode {
366366
_branching("-branching","branching variants"),
367367
_decay("-decay","decay factor",1.0),
368368
_seed("-seed","random number generator seed",1U),
369+
_step("-step","step distance for float optimization",0.0),
369370

370371
_search("-search","search engine variants"),
371372
_solutions("-solutions","number of solutions (0 = all)",1),
@@ -412,7 +413,7 @@ namespace Gecode {
412413
_restart.add(RM_GEOMETRIC,"geometric");
413414

414415
add(_model); add(_symmetry); add(_propagation); add(_icl);
415-
add(_branching); add(_decay); add(_seed);
416+
add(_branching); add(_decay); add(_seed); add(_step);
416417
add(_search); add(_solutions); add(_threads); add(_c_d); add(_a_d);
417418
add(_node); add(_fail); add(_time); add(_interrupt);
418419
add(_restart); add(_r_base); add(_r_scale);

gecode/driver/options.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,15 @@ namespace Gecode {
230230
return _seed.value();
231231
}
232232

233+
inline void
234+
Options::step(double s) {
235+
_step.value(s);
236+
}
237+
inline double
238+
Options::step(void) const {
239+
return _step.value();
240+
}
241+
233242

234243
/*
235244
* Search options

gecode/driver/script.hpp

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,27 @@ namespace Gecode { namespace Driver {
206206
#endif
207207

208208

209-
template<class Space>
209+
template<class BaseSpace>
210+
forceinline
211+
ScriptBase<BaseSpace>::ScriptBase(const Options& opt)
212+
: BaseSpace(opt) {}
213+
214+
template<class BaseSpace>
215+
forceinline
216+
ScriptBase<BaseSpace>::ScriptBase(bool share, ScriptBase& e)
217+
: BaseSpace(share,e) {}
218+
219+
template<class BaseSpace>
220+
void
221+
ScriptBase<BaseSpace>::print(std::ostream&) const {}
222+
223+
template<class BaseSpace>
224+
void
225+
ScriptBase<BaseSpace>::compare(const Space&, std::ostream&) const {}
226+
227+
template<class BaseSpace>
210228
std::ostream&
211-
ScriptBase<Space>::select_ostream(const char* name, std::ofstream& ofs) {
229+
ScriptBase<BaseSpace>::select_ostream(const char* name, std::ofstream& ofs) {
212230
if (strcmp(name, "stdout") == 0) {
213231
return std::cout;
214232
} else if (strcmp(name, "stdlog") == 0) {
@@ -221,6 +239,7 @@ namespace Gecode { namespace Driver {
221239
}
222240
}
223241

242+
224243
/**
225244
* \brief Wrapper class to add engine template argument
226245
*/
@@ -230,22 +249,22 @@ namespace Gecode { namespace Driver {
230249
EngineToMeta(T* s, const Search::Options& o) : E<T>(s,o) {}
231250
};
232251

233-
template<class Space>
252+
template<class BaseSpace>
234253
template<class Script, template<class> class Engine, class Options>
235254
void
236-
ScriptBase<Space>::run(const Options& o, Script* s) {
255+
ScriptBase<BaseSpace>::run(const Options& o, Script* s) {
237256
if (o.restart()==RM_NONE) {
238257
runMeta<Script,Engine,Options,EngineToMeta>(o,s);
239258
} else {
240259
runMeta<Script,Engine,Options,RBS>(o,s);
241260
}
242261
}
243262

244-
template<class Space>
263+
template<class BaseSpace>
245264
template<class Script, template<class> class Engine, class Options,
246265
template<template<class> class,class> class Meta>
247266
void
248-
ScriptBase<Space>::runMeta(const Options& o, Script* s) {
267+
ScriptBase<BaseSpace>::runMeta(const Options& o, Script* s) {
249268
using namespace std;
250269

251270
ofstream sol_file, log_file;

0 commit comments

Comments
 (0)