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,
148 void print(std::ostream& out,
161 void printDiff(std::ostream& out,
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,
238 _solutions(
"-n",
"number of solutions (0 = all)",1),
239 _allSolutions(
"-a",
"return all solutions (equal to -solutions 0)"),
240 _threads(
"-p",
"number of threads (0 = #processing units)",
242 _free(
"--free",
"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),
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") {
283 void parse(
int& argc,
char* argv[]) {
293 std::cerr <<
"Gecode FlatZinc interpreter" << std::endl
295 << std::endl << std::endl;
311 return static_cast<Gecode::ScriptMode>(
_mode.
value());
336 const std::string& rel0,
337 const std::string& rel1,
338 const std::vector<std::string>&
n);
341 int a,
int i,
int n, std::ostream& o)
const;
342 #ifdef GECODE_HAS_FLOAT_VARS 385 template<
template<
class>
class Engine>
387 runEngine(std::ostream& out,
const Printer&
p,
390 template<
template<
class>
class Engine,
391 template<
template<
class>
class,
class>
class Meta>
393 runMeta(std::ostream& out, const
Printer&
p,
396 branchWithPlugin(AST::Node* ann);
403 std::vector<bool> iv_introduced;
411 std::vector<bool> bv_introduced;
412 #ifdef GECODE_HAS_SET_VARS 418 std::vector<bool> sv_introduced;
420 #ifdef GECODE_HAS_FLOAT_VARS 426 std::vector<bool> fv_introduced;
437 void init(int intVars, int boolVars, int setVars, int floatVars);
440 void newIntVar(IntVarSpec* vs);
442 void aliasBool2Int(int iv, int bv);
444 int aliasBool2Int(int iv);
446 void newBoolVar(BoolVarSpec* vs);
448 void newSetVar(SetVarSpec* vs);
450 void newFloatVar(FloatVarSpec* vs);
453 void postConstraint(const ConExpr& ce, AST::Node* annotation);
456 void solve(AST::Array* annotation);
458 void minimize(int var, bool isInt, AST::Array* annotation);
460 void maximize(int var, bool isInt, AST::Array* annotation);
463 void run(std::ostream& out, const Printer& p,
464 const FlatZincOptions& opt, Gecode::Support::Timer& t_total);
467 void
print(std::ostream& out, const Printer& p) const;
471 void
compare(const Space& s, std::ostream& out) const;
474 void
compare(const FlatZincSpace& s, std::ostream& out,
475 const Printer& p) const;
485 void shrinkArrays(Printer& p);
488 Meth method(void) const;
491 int optVar(void) const;
493 bool optVarIsInt(void) const;
504 void createBranchers(AST::Node* ann,
505 int seed, double decay,
507 std::ostream& err = std::cerr);
516 virtual void constrain(const Space& s);
522 IntArgs arg2intargs(AST::Node* arg, int offset = 0);
525 IntArgs arg2boolargs(AST::Node* arg, int offset = 0);
527 IntSet arg2intset(AST::Node* n);
529 IntSetArgs arg2intsetargs(AST::Node* arg, int offset = 0);
531 IntVarArgs arg2intvarargs(AST::Node* arg, int offset = 0);
533 BoolVarArgs arg2boolvarargs(AST::Node* arg, int offset = 0, int siv=-1);
535 BoolVar arg2BoolVar(AST::Node* n);
537 IntVar arg2IntVar(AST::Node* n);
539 bool isBoolArray(AST::Node* b, int& singleInt);
540 #ifdef GECODE_HAS_SET_VARS 541 SetVar arg2SetVar(AST::Node* n);
544 SetVarArgs arg2setvarargs(AST::Node* arg, int offset = 0, int doffset = 0,
545 const IntSet& od=IntSet::empty);
547 #ifdef GECODE_HAS_FLOAT_VARS 548 FloatValArgs arg2floatargs(AST::Node* arg, int offset = 0);
551 FloatVar arg2FloatVar(AST::Node* n);
553 FloatVarArgs arg2floatvarargs(AST::Node* arg, int offset = 0);
563 const std::string msg;
565 Error(
const std::string& where,
const std::string& what)
566 : msg(where+
": "+what) {}
567 const std::string&
toString(
void)
const {
return msg; }
576 FlatZincSpace*
parse(
const std::string& fileName,
577 Printer&
p, std::ostream& err = std::cerr,
578 FlatZincSpace* fzs=NULL);
586 FlatZincSpace*
parse(std::istream& is,
587 Printer&
p, std::ostream& err = std::cerr,
588 FlatZincSpace* fzs=NULL);
Restart with linear sequence.
const std::string & toString(void) const
int floatVarCount
Number of float variables.
void value(int v)
Set default value to v.
Options for running FlatZinc models
Gecode::Driver::UnsignedIntOption _solutions
How many solutions.
RestartMode restart(void) const
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.
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.
#define GECODE_FLATZINC_EXPORT
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.
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.
void value(unsigned int v)
Set default value to v.
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.
Base class for script options.
Error(const std::string &where, const std::string &what)
GECODE_FLATZINC_EXPORT FlatZincSpace * parse(const std::string &fileName, Printer &p, std::ostream &err=std::cerr, FlatZincSpace *fzs=NULL)
Parse FlatZinc file fileName into fzs and return it.
const char * output(void) const
unsigned int node(void) const
Passing integer variables.
Passing integer arguments.
Passing Boolean variables.
Gecode::Driver::IntOption _seed
Random seed.
virtual void help(void)
Print help text.
struct Gecode::@511::NNF::@54::@56 a
For atomic nodes.
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.
unsigned int solutions(void) const
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
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
A node in a FlatZinc abstract syntax tree.
Gecode::Driver::UnsignedIntOption _node
Cutoff for number of nodes.
FlatZincOptions(const char *s)
Constructor.
Restart with constant sequence.
void parse(int &argc, char *argv[])
virtual void help(void)
Print help text.