Go to the documentation of this file.
42 #ifndef __GECODE_FLATZINC_HH__
43 #define __GECODE_FLATZINC_HH__
49 #ifdef GECODE_HAS_SET_VARS
52 #ifdef GECODE_HAS_FLOAT_VARS
62 #if !defined(GECODE_STATIC_LIBS) && \
63 (defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER))
65 #ifdef GECODE_BUILD_FLATZINC
66 #define GECODE_FLATZINC_EXPORT __declspec( dllexport )
68 #define GECODE_FLATZINC_EXPORT __declspec( dllimport )
73 #ifdef GECODE_GCC_HAS_CLASS_VISIBILITY
75 #define GECODE_FLATZINC_EXPORT __attribute__ ((visibility("default")))
79 #define GECODE_FLATZINC_EXPORT
85 #ifndef GECODE_BUILD_FLATZINC
86 #define GECODE_LIBRARY_NAME "FlatZinc"
105 namespace Gecode {
namespace FlatZinc {
114 std::vector<std::string> iv_names;
116 std::vector<std::string> bv_names;
117 #ifdef GECODE_HAS_FLOAT_VARS
118 std::vector<std::string> fv_names;
121 #ifdef GECODE_HAS_SET_VARS
122 std::vector<std::string> sv_names;
126 void printElem(std::ostream& out,
139 void printElemDiff(std::ostream& out,
160 void print(std::ostream& out,
173 void printDiff(std::ostream& out,
190 void addIntVarName(
const std::string&
n);
192 void addBoolVarName(
const std::string&
n);
194 #ifdef GECODE_HAS_FLOAT_VARS
195 void addFloatVarName(
const std::string&
n);
198 #ifdef GECODE_HAS_SET_VARS
199 void addSetVarName(
const std::string&
n);
204 std::map<int,int>& iv, std::map<int,int>& bv,
205 std::map<int,int>& sv, std::map<int,int>& fv);
207 void shrinkArrays(
Space& home,
208 int& optVar,
bool optVarIsInt,
264 _solutions(
"-n",
"number of solutions (0 = all, -1 = one/best)",-1),
266 _threads(
"-p",
"number of threads (0 = #processing units)",
268 _free(
"-f",
"free search, no need to follow search-specification"),
269 _decay(
"-decay",
"decay factor",0.99),
270 _c_d(
"-c-d",
"recomputation commit distance",
Gecode::Search::Config::
c_d),
271 _a_d(
"-a-d",
"recomputation adaption distance",
Gecode::Search::Config::
a_d),
272 _node(
"-node",
"node cutoff (0 = none, solution mode)"),
273 _fail(
"-fail",
"failure cutoff (0 = none, solution mode)"),
274 _time(
"-time",
"time (in ms) cutoff (0 = none, solution mode)"),
275 _seed(
"-r",
"random seed",0),
277 _r_base(
"-restart-base",
"base for geometric restart sequence",1.5),
278 _r_scale(
"-restart-scale",
"scale factor for restart sequence",250),
279 _nogoods(
"-nogoods",
"whether to use no-goods from restarts",false),
280 _nogoods_limit(
"-nogoods-limit",
"depth limit for no-good extraction",
282 _interrupt(
"-interrupt",
"whether to catch Ctrl-C (true) or not (false)",
284 _step(
"-step",
"step distance for float optimization",0.0),
286 _stat(
"-s",
"emit statistics"),
287 _output(
"-o",
"file to send output to") {
311 void parse(
int& argc,
char* argv[]) {
321 std::cerr <<
"Gecode FlatZinc interpreter" << std::endl
323 << std::endl << std::endl;
366 const std::string& rel0,
367 const std::string& rel1,
368 const std::vector<std::string>&
n);
371 unsigned int a,
int i,
int n, std::ostream& o)
const;
372 #ifdef GECODE_HAS_FLOAT_VARS
376 std::ostream& o)
const;
394 unsigned int operator ()(
unsigned int n);
442 template<
template<
class>
class Engine>
444 runEngine(std::ostream& out,
const Printer&
p,
447 template<
template<
class>
class Engine,
448 template<
class,
template<
class>
class>
class Meta>
450 runMeta(std::ostream& out, const
Printer&
p,
453 branchWithPlugin(AST::Node* ann);
464 std::vector<bool> iv_introduced;
472 std::vector<bool> bv_introduced;
473 #ifdef GECODE_HAS_SET_VARS
479 std::vector<bool> sv_introduced;
481 #ifdef GECODE_HAS_FLOAT_VARS
487 std::vector<bool> fv_introduced;
500 void init(int intVars, int boolVars, int setVars, int floatVars);
503 void newIntVar(IntVarSpec* vs);
505 void aliasBool2Int(int iv, int bv);
507 int aliasBool2Int(int iv);
509 void newBoolVar(BoolVarSpec* vs);
511 void newSetVar(SetVarSpec* vs);
513 void newFloatVar(FloatVarSpec* vs);
516 void postConstraints(std::vector<ConExpr*>& ces);
519 void solve(AST::Array* annotation);
521 void minimize(int var, bool isInt, AST::Array* annotation);
523 void maximize(int var, bool isInt, AST::Array* annotation);
526 void run(std::ostream& out, const Printer& p,
527 const FlatZincOptions& opt, Gecode::Support::Timer& t_total);
530 void
print(std::ostream& out, const Printer& p) const;
534 void
compare(const Space& s, std::ostream& out) const;
537 void
compare(const FlatZincSpace& s, std::ostream& out,
538 const Printer& p) const;
548 void shrinkArrays(Printer& p);
551 Meth method(void) const;
554 int optVar(void) const;
556 bool optVarIsInt(void) const;
567 void createBranchers(Printer& p, AST::Node* ann,
568 int seed, double decay,
570 std::ostream& err = std::cerr);
579 virtual void constrain(const Space& s);
583 virtual bool slave(const MetaInfo& mi);
587 IntArgs arg2intargs(AST::Node* arg, int offset = 0);
590 IntArgs arg2boolargs(AST::Node* arg, int offset = 0);
592 IntSet arg2intset(AST::Node* n);
594 IntSetArgs arg2intsetargs(AST::Node* arg, int offset = 0);
596 IntVarArgs arg2intvarargs(AST::Node* arg, int offset = 0);
598 BoolVarArgs arg2boolvarargs(AST::Node* arg, int offset = 0, int siv=-1);
600 BoolVar arg2BoolVar(AST::Node* n);
602 IntVar arg2IntVar(AST::Node* n);
604 bool isBoolArray(AST::Node* b, int& singleInt);
605 #ifdef GECODE_HAS_SET_VARS
606 SetVar arg2SetVar(AST::Node* n);
609 SetVarArgs arg2setvarargs(AST::Node* arg, int offset = 0, int doffset = 0,
610 const IntSet& od=IntSet::empty);
612 #ifdef GECODE_HAS_FLOAT_VARS
613 FloatValArgs arg2floatargs(AST::Node* arg, int offset = 0);
616 FloatVar arg2FloatVar(AST::Node* n);
618 FloatVarArgs arg2floatvarargs(AST::Node* arg, int offset = 0);
628 const std::string msg;
630 Error(
const std::string& where,
const std::string& what)
631 : msg(where+
": "+what) {}
632 const std::string&
toString(
void)
const {
return msg; }
641 FlatZincSpace*
parse(
const std::string& fileName,
642 Printer&
p, std::ostream& err = std::cerr,
643 FlatZincSpace* fzs=NULL, FznRnd* rnd=NULL);
651 FlatZincSpace*
parse(std::istream& is,
652 Printer&
p, std::ostream& err = std::cerr,
653 FlatZincSpace* fzs=NULL, FznRnd* rnd=NULL);
A node in a FlatZinc abstract syntax tree.
FlatZincOptions(const char *s)
Constructor.
const Gecode::FloatNum step
bool free(void) const
Script mode to run.
#define GECODE_VTABLE_EXPORT
double restart_base(void) const
Script mode to run.
int solutions(void) const
Script mode to run.
unsigned int nogoods_limit(void) const
Script mode to run.
void value(const char *v)
Set default value to v.
Output support class for FlatZinc interpreter.
A space that can be initialized with a FlatZinc model.
int boolVarCount
Number of Boolean variables.
Passing integer variables.
Gecode::Driver::BoolOption _stat
Emit statistics.
Meth _method
Whether to solve as satisfaction or optimization problem.
void add(Driver::BaseOption &o)
Add new option o.
String-valued option (integer value defined by strings)
Gecode::IntArgs i(4, 1, 2, 3, 4)
void value(int v)
Set default value to v.
IntPropLevel
Propagation levels for integer propagators.
Gecode::Driver::UnsignedIntOption _r_scale
Restart scale factor.
@ RM_LUBY
Restart with Luby sequence.
Gecode::Driver::IntOption _solutions
How many solutions.
@ RM_LINEAR
Restart with linear sequence.
double threads(void) const
Script mode to run.
#define GECODE_HAS_FLOAT_VARS
bool allSolutions(void) const
Script mode to run.
Gecode::Driver::UnsignedIntOption _time
Cutoff for time.
Options for running FlatZinc models
void value(unsigned int v)
Set default value to v.
Gecode::Driver::StringValueOption _output
Output file.
Gecode toplevel namespace
Gecode::Driver::BoolOption _allSolutions
Return all solutions.
Gecode::Driver::UnsignedIntOption _a_d
Adaptive recomputation distance.
RestartMode restart(void) const
Script mode to run.
int _optVar
Index of the variable to optimize.
Gecode::Driver::BoolOption _nogoods
Whether to use no-goods.
@ RM_GEOMETRIC
Restart with geometric sequence.
void print(std::basic_ostream< Char, Traits > &s, bool assigned, IL &lb, IU &ub, unsigned int cardMin, unsigned int cardMax)
Print set view.
Gecode::Driver::DoubleOption _decay
Decay option.
@ SM_STAT
Print statistics for script.
#define GECODE_HAS_SET_VARS
@ SM_SOLUTION
Print solution and some statistics.
Base-class for branchers.
unsigned int node(void) const
Script mode to run.
void value(int v)
Set default value to v.
Passing Boolean variables.
struct Gecode::@579::NNF::@61::@63 a
For atomic nodes.
struct Gecode::@579::NNF::@61::@62 b
For binary nodes (and, or, eqv)
A thread-safe random number generator.
double FloatNum
Floating point number base type.
Boolean integer variables.
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
void add(int v, const char *o, const char *h=NULL)
Add option value for value v, string o, and help text h.
FznRnd * _random
Random number generator.
RestartMode
Different modes for restart-based search.
const std::string & intVarName(int i) const
const std::string & floatVarName(int i) const
Value description class for branching.
@ RM_CONSTANT
Restart with constant sequence.
Template for linear congruential generators.
@ SM_GIST
Run script in Gist.
bool _optVarIsInt
Whether variable to optimize is integer (or float)
void value(double v)
Set default value to v.
unsigned int fail(void) const
Script mode to run.
Gecode::Driver::UnsignedIntOption _node
Cutoff for number of nodes.
void value(bool v)
Set default value to v.
Base class for script options.
Gecode::Driver::DoubleOption _threads
How many threads to use.
virtual void help(void)
Print help text.
Exception class for FlatZinc errors
void allSolutions(bool b)
Script mode to run.
virtual void help(void)
Script mode to run.
AST::Array * _solveAnnotations
Annotations on the solve item.
Gecode::Driver::UnsignedIntOption _fail
Cutoff for number of failures.
Gecode::Driver::StringOption _mode
Script mode to run.
Gecode::Driver::UnsignedIntOption _nogoods_limit
Depth limit for extracting no-goods.
Gecode::Driver::BoolOption _interrupt
Whether to catch SIGINT.
Gecode::Driver::DoubleOption _r_base
Restart base.
Gecode::Support::RandomGenerator random
The actual random number generator.
const std::string & setVarName(int i) const
#define GECODE_FLATZINC_EXPORT
#define GECODE_FLATZINC_VERSION
int setVarCount
Number of set variables.
int intVarCount
Number of integer variables.
int seed(void) const
Script mode to run.
unsigned int c_d(void) const
Script mode to run.
double decay(void) const
Script mode to run.
const std::string & toString(void) const
ScriptMode
Different modes for executing scripts.
void parse(int &argc, char *argv[])
Script mode to run.
const std::string & boolVarName(int i) const
Gecode::Support::Mutex mutex
A mutex for the random number generator.
Gecode::ScriptMode mode(void) const
Script mode to run.
A mutex for mutual exclausion among several threads.
Gecode::Driver::UnsignedIntOption _c_d
Copy recomputation distance.
int n
Number of negative literals for node type.
bool nogoods(void) const
Script mode to run.
double step(void) const
Script mode to run.
bool interrupt(void) const
Script mode to run.
Gecode::Driver::IntOption _seed
Random seed.
IntSharedArray _lnsInitialSolution
Initial solution to start the LNS (or NULL for no LNS)
Gecode::Driver::StringOption _restart
Restart method option.
unsigned int restart_scale(void) const
Script mode to run.
Error(const std::string &where, const std::string &what)
Passing integer arguments.
CompareStatus compare(I &i, J &j)
Check whether range iterator i is a subset of j, or whether they are disjoint.
Gecode::Driver::BoolOption _free
Use free search.
unsigned int time(void) const
Script mode to run.
int p
Number of positive literals for node type.
unsigned int _lns
Percentage of variables to keep in LNS (or 0 for no LNS)
GECODE_FLATZINC_EXPORT FlatZincSpace * parse(const std::string &fileName, Printer &p, std::ostream &err=std::cerr, FlatZincSpace *fzs=NULL, FznRnd *rnd=NULL)
Parse FlatZinc file fileName into fzs and return it.
Gecode::Driver::DoubleOption _step
Step option.
const char * output(void) const
Script mode to run.
unsigned int a_d(void) const
Script mode to run.
int floatVarCount
Number of float variables.