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),
239 _allSolutions(
"-a",
"return all solutions (equal to -solutions 0)"),
240 _threads(
"-p",
"number of threads (0 = #processing units)",
241 Gecode::Search::Config::
threads),
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;
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);