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,
186 #ifdef GECODE_HAS_SET_VARS
190 #ifdef GECODE_HAS_FLOAT_VARS
236 _solutions(
"-n",
"number of solutions (0 = all)",1),
237 _allSolutions(
"-a",
"return all solutions (equal to -solutions 0)"),
238 _threads(
"-p",
"number of threads (0 = #processing units)",
239 Gecode::Search::Config::
threads),
240 _free(
"--free",
"no need to follow search-specification"),
241 _decay(
"-decay",
"decay factor",1.0),
242 _c_d(
"-c-d",
"recomputation commit distance",Gecode::Search::Config::
c_d),
243 _a_d(
"-a-d",
"recomputation adaption distance",Gecode::Search::Config::
a_d),
244 _node(
"-node",
"node cutoff (0 = none, solution mode)"),
245 _fail(
"-fail",
"failure cutoff (0 = none, solution mode)"),
246 _time(
"-time",
"time (in ms) cutoff (0 = none, solution mode)"),
247 _seed(
"-r",
"random seed",0),
249 _r_base(
"-restart-base",
"base for geometric restart sequence",1.5),
250 _r_scale(
"-restart-scale",
"scale factor for restart sequence",250),
251 _interrupt(
"-interrupt",
"whether to catch Ctrl-C (true) or not (false)",
254 _stat(
"-s",
"emit statistics"),
255 _output(
"-o",
"file to send output to") {
277 void parse(
int& argc,
char* argv[]) {
287 std::cerr <<
"Gecode FlatZinc interpreter" << std::endl
289 << std::endl << std::endl;
352 template<
template<
class>
class Engine>
354 runEngine(std::ostream& out,
const Printer&
p,
357 template<
template<
class>
class Engine,
358 template<
template<
class>
class,
class>
class Meta>
360 runMeta(std::ostream& out, const
Printer&
p,
363 branchWithPlugin(AST::Node* ann);
370 std::vector<bool> iv_introduced;
378 std::vector<bool> bv_introduced;
379 #ifdef GECODE_HAS_SET_VARS
385 std::vector<bool> sv_introduced;
387 #ifdef GECODE_HAS_FLOAT_VARS
393 std::vector<bool> fv_introduced;
404 void init(int intVars, int boolVars, int setVars, int floatVars);
407 void newIntVar(IntVarSpec* vs);
409 void aliasBool2Int(int iv, int bv);
411 int aliasBool2Int(int iv);
413 void newBoolVar(BoolVarSpec* vs);
415 void newSetVar(SetVarSpec* vs);
417 void newFloatVar(FloatVarSpec* vs);
420 void postConstraint(const ConExpr& ce, AST::Node* annotation);
423 void solve(AST::Array* annotation);
425 void minimize(int var, AST::Array* annotation);
427 void maximize(int var, AST::Array* annotation);
430 void run(std::ostream& out, const Printer& p,
431 const FlatZincOptions& opt, Gecode::Support::Timer& t_total);
434 void
print(std::ostream& out, const Printer& p) const;
438 void
compare(const Space& s, std::ostream& out) const;
441 void
compare(const FlatZincSpace& s, std::ostream& out,
442 const Printer& p) const;
452 void shrinkArrays(Printer& p);
455 Meth method(void) const;
458 int optVar(void) const;
469 void createBranchers(AST::Node* ann,
470 int seed, double decay,
472 std::ostream& err = std::cerr);
478 virtual void constrain(const Space& s);
486 IntArgs arg2intargs(AST::Node* arg, int offset = 0);
488 IntArgs arg2boolargs(AST::Node* arg, int offset = 0);
490 IntSet arg2intset(AST::Node* n);
492 IntSetArgs arg2intsetargs(AST::Node* arg, int offset = 0);
494 IntVarArgs arg2intvarargs(AST::Node* arg, int offset = 0);
496 BoolVarArgs arg2boolvarargs(AST::Node* arg, int offset = 0, int siv=-1);
498 BoolVar arg2BoolVar(AST::Node* n);
500 IntVar arg2IntVar(AST::Node* n);
502 bool isBoolArray(AST::Node* b, int& singleInt);
503 #ifdef GECODE_HAS_SET_VARS
505 SetVar arg2SetVar(AST::Node* n);
507 SetVarArgs arg2setvarargs(AST::Node* arg, int offset = 0, int doffset = 0,
508 const IntSet& od=IntSet::empty);
510 #ifdef GECODE_HAS_FLOAT_VARS
512 FloatValArgs arg2floatargs(AST::Node* arg, int offset = 0);
514 FloatVar arg2FloatVar(AST::Node* n);
516 FloatVarArgs arg2floatvarargs(AST::Node* arg, int offset = 0);
526 const std::string msg;
528 Error(
const std::string& where,
const std::string& what)
529 : msg(where+
": "+what) {}
530 const std::string&
toString(
void)
const {
return msg; }
539 FlatZincSpace*
parse(
const std::string& fileName,
540 Printer&
p, std::ostream& err = std::cerr,
541 FlatZincSpace* fzs=NULL);
549 FlatZincSpace*
parse(std::istream& is,
550 Printer&
p, std::ostream& err = std::cerr,
551 FlatZincSpace* fzs=NULL);