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 void printElem(std::ostream& out,
127 void printElemDiff(std::ostream& out,
133 #ifdef GECODE_HAS_SET_VARS
138 #ifdef GECODE_HAS_FLOAT_VARS
148 void print(std::ostream& out,
151 #ifdef GECODE_HAS_SET_VARS
155 #ifdef GECODE_HAS_FLOAT_VARS
161 void printDiff(std::ostream& out,
164 #ifdef GECODE_HAS_SET_VARS
168 #ifdef GECODE_HAS_FLOAT_VARS
179 std::map<int,int>& iv, std::map<int,int>& bv,
180 std::map<int,int>& sv, std::map<int,int>& fv);
182 void shrinkArrays(
Space& home,
183 int& optVar,
bool optVarIsInt,
186 #ifdef GECODE_HAS_SET_VARS
190 #ifdef GECODE_HAS_FLOAT_VARS
238 _solutions(
"-n",
"number of solutions (0 = all, -1 = one/best)",-1),
239 _allSolutions(
"-a",
"return all solutions (equal to -n 0)"),
240 _threads(
"-p",
"number of threads (0 = #processing units)",
242 _free(
"-f",
"free search, no need to follow search-specification"),
243 _decay(
"-decay",
"decay factor",0.99),
244 _c_d(
"-c-d",
"recomputation commit distance",
Gecode::Search::Config::
c_d),
245 _a_d(
"-a-d",
"recomputation adaption distance",
Gecode::Search::Config::
a_d),
246 _node(
"-node",
"node cutoff (0 = none, solution mode)"),
247 _fail(
"-fail",
"failure cutoff (0 = none, solution mode)"),
248 _time(
"-time",
"time (in ms) cutoff (0 = none, solution mode)"),
249 _seed(
"-r",
"random seed",0),
250 _restart(
"-restart",
"restart sequence type",
RM_NONE),
251 _r_base(
"-restart-base",
"base for geometric restart sequence",1.5),
252 _r_scale(
"-restart-scale",
"scale factor for restart sequence",250),
253 _nogoods(
"-nogoods",
"whether to use no-goods from restarts",false),
254 _nogoods_limit(
"-nogoods-limit",
"depth limit for no-good extraction",
256 _interrupt(
"-interrupt",
"whether to catch Ctrl-C (true) or not (false)",
259 _stat(
"-s",
"emit statistics"),
260 _output(
"-o",
"file to send output to") {
277 add(_restart);
add(_r_base);
add(_r_scale);
278 add(_nogoods);
add(_nogoods_limit);
283 void parse(
int& argc,
char* argv[]) {
285 if (_allSolutions.
value() && _solutions.
value()==-1) {
293 std::cerr <<
"Gecode FlatZinc interpreter" << std::endl
295 << std::endl << std::endl;
303 unsigned int c_d(
void)
const {
return _c_d.
value(); }
304 unsigned int a_d(
void)
const {
return _a_d.
value(); }
337 const std::string& rel0,
338 const std::string& rel1,
339 const std::vector<std::string>&
n);
342 int a,
int i,
int n, std::ostream& o)
const;
343 #ifdef GECODE_HAS_FLOAT_VARS
364 unsigned int operator ()(
unsigned int n);
409 template<
template<
class>
class Engine>
411 runEngine(std::ostream& out,
const Printer&
p,
414 template<
template<
class>
class Engine,
415 template<
template<
class>
class,
class>
class Meta>
420 branchWithPlugin(AST::Node* ann);
431 std::vector<bool> iv_introduced;
439 std::vector<bool> bv_introduced;
440 #ifdef GECODE_HAS_SET_VARS
446 std::vector<bool> sv_introduced;
448 #ifdef GECODE_HAS_FLOAT_VARS
454 std::vector<bool> fv_introduced;
465 void init(int intVars, int boolVars, int setVars, int floatVars);
468 void newIntVar(IntVarSpec* vs);
470 void aliasBool2Int(int iv, int bv);
472 int aliasBool2Int(int iv);
474 void newBoolVar(BoolVarSpec* vs);
476 void newSetVar(SetVarSpec* vs);
478 void newFloatVar(FloatVarSpec* vs);
481 void postConstraints(std::vector<ConExpr*>& ces);
484 void solve(AST::Array* annotation);
486 void minimize(int var, bool isInt, AST::Array* annotation);
488 void maximize(int var, bool isInt, AST::Array* annotation);
491 void run(std::ostream& out, const Printer& p,
492 const FlatZincOptions& opt, Gecode::Support::Timer& t_total);
495 void
print(std::ostream& out, const Printer& p) const;
499 void
compare(const Space& s, std::ostream& out) const;
502 void
compare(const FlatZincSpace& s, std::ostream& out,
503 const Printer& p) const;
513 void shrinkArrays(Printer& p);
516 Meth method(void) const;
519 int optVar(void) const;
521 bool optVarIsInt(void) const;
532 void createBranchers(AST::Node* ann,
533 int seed, double decay,
535 std::ostream& err = std::cerr);
544 virtual void constrain(const Space& s);
548 virtual bool slave(const CRI& cri);
552 IntArgs arg2intargs(AST::Node* arg, int offset = 0);
555 IntArgs arg2boolargs(AST::Node* arg, int offset = 0);
557 IntSet arg2intset(AST::Node* n);
559 IntSetArgs arg2intsetargs(AST::Node* arg, int offset = 0);
561 IntVarArgs arg2intvarargs(AST::Node* arg, int offset = 0);
563 BoolVarArgs arg2boolvarargs(AST::Node* arg, int offset = 0, int siv=-1);
565 BoolVar arg2BoolVar(AST::Node* n);
567 IntVar arg2IntVar(AST::Node* n);
569 bool isBoolArray(AST::Node* b, int& singleInt);
570 #ifdef GECODE_HAS_SET_VARS
571 SetVar arg2SetVar(AST::Node* n);
574 SetVarArgs arg2setvarargs(AST::Node* arg, int offset = 0, int doffset = 0,
575 const IntSet& od=IntSet::empty);
577 #ifdef GECODE_HAS_FLOAT_VARS
578 FloatValArgs arg2floatargs(AST::Node* arg, int offset = 0);
581 FloatVar arg2FloatVar(AST::Node* n);
583 FloatVarArgs arg2floatvarargs(AST::Node* arg, int offset = 0);
593 const std::string msg;
595 Error(
const std::string& where,
const std::string& what)
596 : msg(where+
": "+what) {}
597 const std::string&
toString(
void)
const {
return msg; }
606 FlatZincSpace*
parse(
const std::string& fileName,
607 Printer&
p, std::ostream& err = std::cerr,
608 FlatZincSpace* fzs=NULL, FznRnd* rnd=NULL);
616 FlatZincSpace*
parse(std::istream& is,
617 Printer&
p, std::ostream& err = std::cerr,
618 FlatZincSpace* fzs=NULL, FznRnd* rnd=NULL);
Restart with linear sequence.
Gecode::Driver::IntOption _solutions
How many solutions.
int floatVarCount
Number of float variables.
void value(int v)
Set default value to v.
Options for running FlatZinc models
Gecode::ScriptMode mode(void) const
Gecode::Support::RandomGenerator random
The actual random number generator.
IntConLevel
Consistency levels for integer propagators.
#define GECODE_FLATZINC_VERSION
unsigned int restart_scale(void) const
Gecode::Driver::UnsignedIntOption _time
Cutoff for time.
Gecode::Driver::BoolOption _allSolutions
Return all solutions.
#define GECODE_HAS_SET_VARS
void value(double v)
Set default value to v.
ScriptMode
Different modes for executing scripts.
Gecode::Driver::UnsignedIntOption _r_scale
Restart scale factor.
Meth _method
Whether to solve as satisfaction or optimization problem.
#define GECODE_FLATZINC_EXPORT
void add(int v, const char *o, const char *h=NULL)
Add option value for value v, string o, and help text h.
unsigned int nogoods_limit(void) const
int boolVarCount
Number of Boolean variables.
int solutions(void) const
Gecode::Driver::StringOption _restart
Restart method option.
const char * output(void) const
Gecode::Driver::BoolOption _free
Use free search.
Restart with Luby sequence.
Gecode::Driver::UnsignedIntOption _nogoods_limit
Depth limit for extracting no-goods.
bool interrupt(void) const
Gecode::Driver::BoolOption _stat
Emit statistics.
unsigned int time(void) const
A thread-safe random number generator.
RestartMode
Different modes for restart-based search.
Gecode::Driver::UnsignedIntOption _a_d
Adaptive recomputation distance.
Gecode::Driver::DoubleOption _decay
Decay option.
void add(Driver::BaseOption &o)
Add new option o.
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.
void value(unsigned int v)
Set default value to v.
double threads(void) const
A mutex for mutual exclausion among several threads.
unsigned int node(void) const
Gecode::Support::Mutex mutex
A mutex for the random number generator.
void value(int v)
Set default value to v.
int p
Number of positive literals for node type.
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Gecode::Driver::StringOption _mode
Script mode to run.
unsigned int c_d(void) const
Print solution and some statistics.
Value description class for branching.
Gecode::Driver::UnsignedIntOption _fail
Cutoff for number of failures.
int _optVar
Index of the variable to optimize.
Output support class for FlatZinc interpreter.
Base class for script options.
FznRnd * _random
Random number generator.
const std::string & toString(void) const
Error(const std::string &where, const std::string &what)
Template for linear congruential generators.
Passing integer variables.
void allSolutions(bool b)
Passing integer arguments.
Passing Boolean variables.
Gecode::Driver::IntOption _seed
Random seed.
virtual void help(void)
Print help text.
bool _optVarIsInt
Whether variable to optimize is integer (or float)
RestartMode restart(void) const
Boolean integer variables.
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
String-valued option (integer value defined by strings)
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::BoolOption _interrupt
Whether to catch SIGINT.
double restart_base(void) const
Print statistics for script.
Gecode::Driver::DoubleOption _r_base
Restart base.
void value(const char *v)
Set default value to v.
Restart with geometric sequence.
Gecode::Driver::BoolOption _nogoods
Whether to use no-goods.
Gecode::Driver::DoubleOption _threads
How many threads to use.
Exception class for FlatZinc errors
AST::Array * _solveAnnotations
Annotations on the solve item.
bool allSolutions(void) const
Gecode::Driver::UnsignedIntOption _c_d
Copy recomputation distance.
void value(bool v)
Set default value to v.
#define GECODE_HAS_FLOAT_VARS
A space that can be initialized with a FlatZinc model.
CompareStatus compare(I &i, J &j)
Check whether range iterator i is a subset of j, or whether they are disjoint.
Gecode::Driver::StringValueOption _output
Output file.
struct Gecode::@518::NNF::@57::@58 b
For binary nodes (and, or, eqv)
Gecode toplevel namespace
int setVarCount
Number of set variables.
int intVarCount
Number of integer variables.
#define GECODE_VTABLE_EXPORT
A node in a FlatZinc abstract syntax tree.
unsigned int fail(void) const
Gecode::Driver::UnsignedIntOption _node
Cutoff for number of nodes.
unsigned int _lns
Percentage of variables to keep in LNS (or 0 for no LNS)
FlatZincOptions(const char *s)
Constructor.
Restart with constant sequence.
struct Gecode::@518::NNF::@57::@59 a
For atomic nodes.
void parse(int &argc, char *argv[])
unsigned int a_d(void) const
virtual void help(void)
Print help text.