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 std::vector<std::string> iv_names;
116 std::vector<std::string> bv_names;
117 #ifdef GECODE_HAS_FLOAT_VARS 118 std::vector<std::string> fv_names;
121 #ifdef GECODE_HAS_SET_VARS 122 std::vector<std::string> sv_names;
126 void printElem(std::ostream& out,
139 void printElemDiff(std::ostream& out,
160 void print(std::ostream& out,
173 void printDiff(std::ostream& out,
190 void addIntVarName(
const std::string&
n);
192 void addBoolVarName(
const std::string&
n);
194 #ifdef GECODE_HAS_FLOAT_VARS 195 void addFloatVarName(
const std::string&
n);
198 #ifdef GECODE_HAS_SET_VARS 199 void addSetVarName(
const std::string&
n);
204 std::map<int,int>& iv, std::map<int,int>& bv,
205 std::map<int,int>& sv, std::map<int,int>& fv);
207 void shrinkArrays(
Space& home,
208 int& optVar,
bool optVarIsInt,
264 _solutions(
"-n",
"number of solutions (0 = all, -1 = one/best)",-1),
266 _threads(
"-p",
"number of threads (0 = #processing units)",
268 _free(
"-f",
"free search, no need to follow search-specification"),
269 _decay(
"-decay",
"decay factor",0.99),
270 _c_d(
"-c-d",
"recomputation commit distance",
Gecode::Search::Config::
c_d),
271 _a_d(
"-a-d",
"recomputation adaption distance",
Gecode::Search::Config::
a_d),
272 _node(
"-node",
"node cutoff (0 = none, solution mode)"),
273 _fail(
"-fail",
"failure cutoff (0 = none, solution mode)"),
274 _time(
"-time",
"time (in ms) cutoff (0 = none, solution mode)"),
275 _seed(
"-r",
"random seed",0),
277 _r_base(
"-restart-base",
"base for geometric restart sequence",1.5),
278 _r_scale(
"-restart-scale",
"scale factor for restart sequence",250),
279 _nogoods(
"-nogoods",
"whether to use no-goods from restarts",false),
280 _nogoods_limit(
"-nogoods-limit",
"depth limit for no-good extraction",
282 _interrupt(
"-interrupt",
"whether to catch Ctrl-C (true) or not (false)",
284 _step(
"-step",
"step distance for float optimization",0.0),
286 _stat(
"-s",
"emit statistics"),
287 _output(
"-o",
"file to send output to") {
311 void parse(
int& argc,
char* argv[]) {
321 std::cerr <<
"Gecode FlatZinc interpreter" << std::endl
323 << std::endl << std::endl;
366 const std::string& rel0,
367 const std::string& rel1,
368 const std::vector<std::string>&
n);
371 unsigned int a,
int i,
int n, std::ostream& o)
const;
372 #ifdef GECODE_HAS_FLOAT_VARS 376 std::ostream& o)
const;
394 unsigned int operator ()(
unsigned int n);
442 template<
template<
class>
class Engine>
444 runEngine(std::ostream& out,
const Printer&
p,
447 template<
template<
class>
class Engine,
448 template<
class,
template<
class>
class>
class Meta>
453 branchWithPlugin(AST::Node* ann);
464 std::vector<bool> iv_introduced;
472 std::vector<bool> bv_introduced;
473 #ifdef GECODE_HAS_SET_VARS 479 std::vector<bool> sv_introduced;
481 #ifdef GECODE_HAS_FLOAT_VARS 487 std::vector<bool> fv_introduced;
500 void init(int intVars, int boolVars, int setVars, int floatVars);
503 void newIntVar(IntVarSpec* vs);
505 void aliasBool2Int(int iv, int bv);
507 int aliasBool2Int(int iv);
509 void newBoolVar(BoolVarSpec* vs);
511 void newSetVar(SetVarSpec* vs);
513 void newFloatVar(FloatVarSpec* vs);
516 void postConstraints(std::vector<ConExpr*>& ces);
519 void solve(AST::Array* annotation);
521 void minimize(int var, bool isInt, AST::Array* annotation);
523 void maximize(int var, bool isInt, AST::Array* annotation);
526 void run(std::ostream& out, const Printer& p,
527 const FlatZincOptions& opt, Gecode::Support::Timer& t_total);
530 void
print(std::ostream& out, const Printer& p) const;
534 void
compare(const Space& s, std::ostream& out) const;
537 void
compare(const FlatZincSpace& s, std::ostream& out,
538 const Printer& p) const;
548 void shrinkArrays(Printer& p);
551 Meth method(void) const;
554 int optVar(void) const;
556 bool optVarIsInt(void) const;
567 void createBranchers(Printer& p, AST::Node* ann,
568 int seed, double decay,
570 std::ostream& err = std::cerr);
579 virtual void constrain(const Space& s);
583 virtual bool slave(const MetaInfo& mi);
587 IntArgs arg2intargs(AST::Node* arg, int offset = 0);
590 IntArgs arg2boolargs(AST::Node* arg, int offset = 0);
592 IntSet arg2intset(AST::Node* n);
594 IntSetArgs arg2intsetargs(AST::Node* arg, int offset = 0);
596 IntVarArgs arg2intvarargs(AST::Node* arg, int offset = 0);
598 BoolVarArgs arg2boolvarargs(AST::Node* arg, int offset = 0, int siv=-1);
600 BoolVar arg2BoolVar(AST::Node* n);
602 IntVar arg2IntVar(AST::Node* n);
604 bool isBoolArray(AST::Node* b, int& singleInt);
605 #ifdef GECODE_HAS_SET_VARS 606 SetVar arg2SetVar(AST::Node* n);
609 SetVarArgs arg2setvarargs(AST::Node* arg, int offset = 0, int doffset = 0,
610 const IntSet& od=IntSet::empty);
612 #ifdef GECODE_HAS_FLOAT_VARS 613 FloatValArgs arg2floatargs(AST::Node* arg, int offset = 0);
616 FloatVar arg2FloatVar(AST::Node* n);
618 FloatVarArgs arg2floatvarargs(AST::Node* arg, int offset = 0);
628 const std::string msg;
630 Error(
const std::string& where,
const std::string& what)
631 : msg(where+
": "+what) {}
632 const std::string&
toString(
void)
const {
return msg; }
641 FlatZincSpace*
parse(
const std::string& fileName,
642 Printer&
p, std::ostream& err = std::cerr,
643 FlatZincSpace* fzs=NULL, FznRnd* rnd=NULL);
651 FlatZincSpace*
parse(std::istream& is,
652 Printer&
p, std::ostream& err = std::cerr,
653 FlatZincSpace* fzs=NULL, FznRnd* rnd=NULL);
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.
#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.
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.
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
struct Gecode::@579::NNF::@61::@63 a
For atomic nodes.
int p
Number of positive literals for node type.
Gecode::IntArgs i(4, 1, 2, 3, 4)
Base-class for branchers.
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.
FznRnd * _random
Random number generator.
Gecode::Driver::DoubleOption _step
Step option.
const std::string & floatVarName(int i) const
Error(const std::string &where, const std::string &what)
struct Gecode::@579::NNF::@61::@62 b
For binary nodes (and, or, eqv)
const char * output(void) const
Template for linear congruential generators.
unsigned int node(void) const
const std::string & intVarName(int i) const
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)
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)
IntPropLevel
Propagation levels for integer propagators.
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.
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.
const std::string & setVarName(int i) const
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.
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.
const std::string & boolVarName(int i) const
FlatZincOptions(const char *s)
Constructor.
Restart with constant sequence.
IntSharedArray _lnsInitialSolution
Initial solution to start the LNS (or NULL for no LNS)
void parse(int &argc, char *argv[])
virtual void help(void)
Print help text.