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
239 _solutions(
"-n",
"number of solutions (0 = all, -1 = one/best)",-1),
240 _allSolutions(
"-a",
"return all solutions (equal to -n 0)"),
241 _threads(
"-p",
"number of threads (0 = #processing units)",
243 _free(
"-f",
"free search, no need to follow search-specification"),
244 _decay(
"-decay",
"decay factor",0.99),
245 _c_d(
"-c-d",
"recomputation commit distance",
Gecode::Search::Config::
c_d),
246 _a_d(
"-a-d",
"recomputation adaption distance",
Gecode::Search::Config::
a_d),
247 _node(
"-node",
"node cutoff (0 = none, solution mode)"),
248 _fail(
"-fail",
"failure cutoff (0 = none, solution mode)"),
249 _time(
"-time",
"time (in ms) cutoff (0 = none, solution mode)"),
250 _seed(
"-r",
"random seed",0),
251 _restart(
"-restart",
"restart sequence type",
RM_NONE),
252 _r_base(
"-restart-base",
"base for geometric restart sequence",1.5),
253 _r_scale(
"-restart-scale",
"scale factor for restart sequence",250),
254 _nogoods(
"-nogoods",
"whether to use no-goods from restarts",false),
255 _nogoods_limit(
"-nogoods-limit",
"depth limit for no-good extraction",
257 _interrupt(
"-interrupt",
"whether to catch Ctrl-C (true) or not (false)",
259 _step(
"-step",
"step distance for float optimization",0.0),
261 _stat(
"-s",
"emit statistics"),
262 _output(
"-o",
"file to send output to") {
273 add(_solutions); add(_threads); add(_c_d); add(_a_d);
277 add(_node); add(_fail); add(_time); add(_interrupt);
280 add(_restart); add(_r_base); add(_r_scale);
281 add(_nogoods); add(_nogoods_limit);
282 add(_mode); add(_stat);
286 void parse(
int& argc,
char* argv[]) {
288 if (_allSolutions.
value() && _solutions.
value()==-1) {
296 std::cerr <<
"Gecode FlatZinc interpreter" << std::endl
298 << std::endl << std::endl;
306 unsigned int c_d(
void)
const {
return _c_d.
value(); }
307 unsigned int a_d(
void)
const {
return _a_d.
value(); }
341 const std::string& rel0,
342 const std::string& rel1,
343 const std::vector<std::string>&
n);
346 int a,
int i,
int n, std::ostream& o)
const;
347 #ifdef GECODE_HAS_FLOAT_VARS 368 unsigned int operator ()(
unsigned int n);
413 template<
template<
class>
class Engine>
415 runEngine(std::ostream& out,
const Printer&
p,
418 template<
template<
class>
class Engine,
419 template<
template<
class>
class,
class>
class Meta>
424 branchWithPlugin(AST::Node* ann);
435 std::vector<bool> iv_introduced;
443 std::vector<bool> bv_introduced;
444 #ifdef GECODE_HAS_SET_VARS 450 std::vector<bool> sv_introduced;
452 #ifdef GECODE_HAS_FLOAT_VARS 458 std::vector<bool> fv_introduced;
471 void init(int intVars, int boolVars, int setVars, int floatVars);
474 void newIntVar(IntVarSpec* vs);
476 void aliasBool2Int(int iv, int bv);
478 int aliasBool2Int(int iv);
480 void newBoolVar(BoolVarSpec* vs);
482 void newSetVar(SetVarSpec* vs);
484 void newFloatVar(FloatVarSpec* vs);
487 void postConstraints(std::vector<ConExpr*>& ces);
490 void solve(AST::Array* annotation);
492 void minimize(int var, bool isInt, AST::Array* annotation);
494 void maximize(int var, bool isInt, AST::Array* annotation);
497 void run(std::ostream& out, const Printer& p,
498 const FlatZincOptions& opt, Gecode::Support::Timer& t_total);
501 void
print(std::ostream& out, const Printer& p) const;
505 void
compare(const Space& s, std::ostream& out) const;
508 void
compare(const FlatZincSpace& s, std::ostream& out,
509 const Printer& p) const;
519 void shrinkArrays(Printer& p);
522 Meth method(void) const;
525 int optVar(void) const;
527 bool optVarIsInt(void) const;
538 void createBranchers(AST::Node* ann,
539 int seed, double decay,
541 std::ostream& err = std::cerr);
550 virtual void constrain(const Space& s);
554 virtual bool slave(const CRI& cri);
558 IntArgs arg2intargs(AST::Node* arg, int offset = 0);
561 IntArgs arg2boolargs(AST::Node* arg, int offset = 0);
563 IntSet arg2intset(AST::Node* n);
565 IntSetArgs arg2intsetargs(AST::Node* arg, int offset = 0);
567 IntVarArgs arg2intvarargs(AST::Node* arg, int offset = 0);
569 BoolVarArgs arg2boolvarargs(AST::Node* arg, int offset = 0, int siv=-1);
571 BoolVar arg2BoolVar(AST::Node* n);
573 IntVar arg2IntVar(AST::Node* n);
575 bool isBoolArray(AST::Node* b, int& singleInt);
576 #ifdef GECODE_HAS_SET_VARS 577 SetVar arg2SetVar(AST::Node* n);
580 SetVarArgs arg2setvarargs(AST::Node* arg, int offset = 0, int doffset = 0,
581 const IntSet& od=IntSet::empty);
583 #ifdef GECODE_HAS_FLOAT_VARS 584 FloatValArgs arg2floatargs(AST::Node* arg, int offset = 0);
587 FloatVar arg2FloatVar(AST::Node* n);
589 FloatVarArgs arg2floatvarargs(AST::Node* arg, int offset = 0);
599 const std::string msg;
601 Error(
const std::string& where,
const std::string& what)
602 : msg(where+
": "+what) {}
603 const std::string&
toString(
void)
const {
return msg; }
613 Printer&
p, std::ostream& err = std::cerr,
623 Printer& p, std::ostream& err = std::cerr,
int solutions(void) const
Restart with linear sequence.
const std::string & toString(void) const
Gecode::Driver::IntOption _solutions
How many solutions.
int floatVarCount
Number of float variables.
void value(int v)
Set default value to v.
const Gecode::FloatNum step
Options for running FlatZinc models
RestartMode restart(void) const
Gecode::Support::RandomGenerator random
The actual random number generator.
IntConLevel
Consistency levels for integer propagators.
#define GECODE_FLATZINC_VERSION
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
Gecode::ScriptMode mode(void) const
void add(int v, const char *o, const char *h=NULL)
Add option value for value v, string o, and help text h.
int boolVarCount
Number of Boolean variables.
Gecode::Driver::StringOption _restart
Restart method option.
Gecode::Driver::BoolOption _free
Use free search.
Restart with Luby sequence.
Gecode::Driver::UnsignedIntOption _nogoods_limit
Depth limit for extracting no-goods.
bool allSolutions(void) const
Gecode::Driver::BoolOption _stat
Emit statistics.
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.
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.
A mutex for mutual exclausion among several threads.
Gecode::Support::Mutex mutex
A mutex for the random number generator.
void value(int v)
Set default value to v.
unsigned int nogoods_limit(void) const
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.
Print solution and some statistics.
Value description class for branching.
double threads(void) const
Gecode::Driver::UnsignedIntOption _fail
Cutoff for number of failures.
int _optVar
Index of the variable to optimize.
Output support class for FlatZinc interpreter.
const unsigned int a_d
Create a clone during recomputation if distance is greater than a_d (adaptive distance) ...
Base class for script options.
FznRnd * _random
Random number generator.
Gecode::Driver::DoubleOption _step
Step option.
Error(const std::string &where, const std::string &what)
const char * output(void) const
struct Gecode::@519::NNF::@60::@62 a
For atomic nodes.
Template for linear congruential generators.
unsigned int node(void) const
Passing integer variables.
const double threads
Number of threads to use.
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)
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.
struct Gecode::@519::NNF::@60::@61 b
For binary nodes (and, or, eqv)
Print statistics for script.
Gecode::Driver::DoubleOption _r_base
Restart base.
void value(const char *v)
Set default value to v.
unsigned int fail(void) const
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.
unsigned int c_d(void) const
Gecode::Driver::UnsignedIntOption _c_d
Copy recomputation distance.
void value(bool v)
Set default value to v.
double restart_base(void) const
const unsigned int c_d
Create a clone after every c_d commits (commit distance)
unsigned int time(void) const
#define GECODE_HAS_FLOAT_VARS
bool interrupt(void) const
A space that can be initialized with a FlatZinc model.
unsigned int restart_scale(void) const
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.
Gecode toplevel namespace
int setVarCount
Number of set variables.
int intVarCount
Number of integer variables.
unsigned int a_d(void) const
#define GECODE_VTABLE_EXPORT
A node in a FlatZinc abstract syntax tree.
const unsigned int nogoods_limit
Depth limit for no-good generation during search.
Gecode::Driver::UnsignedIntOption _node
Cutoff for number of nodes.
unsigned int _lns
Percentage of variables to keep in LNS (or 0 for no LNS)
double FloatNum
Floating point number base type.
FlatZincOptions(const char *s)
Constructor.
Restart with constant sequence.
void parse(int &argc, char *argv[])
virtual void help(void)
Print help text.