38 #ifndef __GECODE_FLATZINC_HH__ 39 #define __GECODE_FLATZINC_HH__ 45 #ifdef GECODE_HAS_SET_VARS 48 #ifdef GECODE_HAS_FLOAT_VARS 58 #if !defined(GECODE_STATIC_LIBS) && \ 59 (defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER)) 61 #ifdef GECODE_BUILD_FLATZINC 62 #define GECODE_FLATZINC_EXPORT __declspec( dllexport ) 64 #define GECODE_FLATZINC_EXPORT __declspec( dllimport ) 69 #ifdef GECODE_GCC_HAS_CLASS_VISIBILITY 71 #define GECODE_FLATZINC_EXPORT __attribute__ ((visibility("default"))) 75 #define GECODE_FLATZINC_EXPORT 81 #ifndef GECODE_BUILD_FLATZINC 82 #define GECODE_LIBRARY_NAME "FlatZinc" 101 namespace Gecode {
namespace FlatZinc {
110 std::vector<std::string> iv_names;
112 std::vector<std::string> bv_names;
113 #ifdef GECODE_HAS_FLOAT_VARS 114 std::vector<std::string> fv_names;
117 #ifdef GECODE_HAS_SET_VARS 118 std::vector<std::string> sv_names;
122 void printElem(std::ostream& out,
135 void printElemDiff(std::ostream& out,
141 #ifdef GECODE_HAS_SET_VARS
146 #ifdef GECODE_HAS_FLOAT_VARS
156 void print(std::ostream& out,
159 #ifdef GECODE_HAS_SET_VARS
163 #ifdef GECODE_HAS_FLOAT_VARS
169 void printDiff(std::ostream& out,
172 #ifdef GECODE_HAS_SET_VARS
176 #ifdef GECODE_HAS_FLOAT_VARS
186 void addIntVarName(
const std::string&
n);
188 void addBoolVarName(
const std::string& n);
190 #ifdef GECODE_HAS_FLOAT_VARS 191 void addFloatVarName(
const std::string& n);
194 #ifdef GECODE_HAS_SET_VARS 195 void addSetVarName(
const std::string& n);
200 std::map<int,int>& iv, std::map<int,int>& bv,
201 std::map<int,int>& sv, std::map<int,int>& fv);
203 void shrinkArrays(
Space& home,
204 int& optVar,
bool optVarIsInt,
207 #ifdef GECODE_HAS_SET_VARS
211 #ifdef GECODE_HAS_FLOAT_VARS
256 #ifdef GECODE_HAS_CPPROFILER 269 _solutions(
"n",
"number of solutions (0 = all, -1 = one/best)",-1),
270 _allSolutions(
"a",
"return all solutions (equal to -n 0)"),
271 _threads(
"p",
"number of threads (0 = #processing units)",
273 _free(
"f",
"free search, no need to follow search-specification"),
274 _decay(
"decay",
"decay factor",0.99),
275 _c_d(
"c-d",
"recomputation commit distance",
Gecode::Search::Config::
c_d),
276 _a_d(
"a-d",
"recomputation adaption distance",
Gecode::Search::Config::
a_d),
277 _node(
"node",
"node cutoff (0 = none, solution mode)"),
278 _fail(
"fail",
"failure cutoff (0 = none, solution mode)"),
279 _time(
"time",
"time (in ms) cutoff (0 = none, solution mode)"),
280 _seed(
"r",
"random seed",0),
281 _restart(
"restart",
"restart sequence type",
RM_NONE),
282 _r_base(
"restart-base",
"base for geometric restart sequence",1.5),
283 _r_scale(
"restart-scale",
"scale factor for restart sequence",250),
284 _nogoods(
"nogoods",
"whether to use no-goods from restarts",false),
285 _nogoods_limit(
"nogoods-limit",
"depth limit for no-good extraction",
287 _interrupt(
"interrupt",
"whether to catch Ctrl-C (true) or not (false)",
289 _step(
"step",
"step distance for float optimization",0.0),
291 _stat(
"s",
"emit statistics"),
292 _output(
"o",
"file to send output to")
294 #ifdef GECODE_HAS_CPPROFILER
296 _profiler_id(
"cpprofiler-id",
"use this execution id with cpprofiler", 0),
297 _profiler_port(
"cpprofiler-port",
"connect to cpprofiler on this port", 6565),
298 _profiler_info(
"cpprofiler-info",
"send solution information to cpprofiler", false)
312 add(_solutions); add(_threads); add(_c_d); add(_a_d);
316 add(_node); add(_fail); add(_time); add(_interrupt);
319 add(_restart); add(_r_base); add(_r_scale);
320 add(_nogoods); add(_nogoods_limit);
321 add(_mode); add(_stat);
323 #ifdef GECODE_HAS_CPPROFILER 330 void parse(
int& argc,
char* argv[]) {
332 if (_allSolutions.
value() && _solutions.
value()==-1) {
340 std::cerr <<
"Gecode FlatZinc interpreter" << std::endl
342 << std::endl << std::endl;
350 unsigned int c_d(
void)
const {
return _c_d.
value(); }
351 unsigned int a_d(
void)
const {
return _a_d.
value(); }
378 #ifdef GECODE_HAS_CPPROFILER 399 const std::string& rel0,
400 const std::string& rel1,
401 const std::vector<std::string>&
n);
404 unsigned int a,
int i,
int n, std::ostream& o)
const;
405 #ifdef GECODE_HAS_FLOAT_VARS 409 std::ostream& o)
const;
466 template<
template<
class>
class Engine>
468 runEngine(std::ostream& out,
const Printer&
p,
471 template<
template<
class>
class Engine,
472 template<
class,
template<
class>
class>
class Meta>
477 branchWithPlugin(AST::Node* ann);
488 std::vector<bool> iv_introduced;
496 std::vector<bool> bv_introduced;
497 #ifdef GECODE_HAS_SET_VARS 503 std::vector<bool> sv_introduced;
505 #ifdef GECODE_HAS_FLOAT_VARS 511 std::vector<bool> fv_introduced;
524 void init(int intVars, int boolVars, int setVars, int floatVars);
527 void newIntVar(IntVarSpec* vs);
529 void aliasBool2Int(int iv, int bv);
531 int aliasBool2Int(int iv);
533 void newBoolVar(BoolVarSpec* vs);
535 void newSetVar(SetVarSpec* vs);
537 void newFloatVar(FloatVarSpec* vs);
540 void postConstraints(std::vector<ConExpr*>& ces);
543 void solve(AST::Array* annotation);
545 void minimize(int var, bool isInt, AST::Array* annotation);
547 void maximize(int var, bool isInt, AST::Array* annotation);
550 void run(std::ostream& out, const Printer& p,
551 const FlatZincOptions& opt, Gecode::Support::Timer& t_total);
554 void
print(std::ostream& out, const Printer& p) const;
555 #ifdef GECODE_HAS_CPPROFILER 556 std::string getDomains(const Printer& p) const;
559 void
compare(const Space& s, std::ostream& out) const;
564 void
compare(const FlatZincSpace& s, std::ostream& out,
565 const Printer& p) const;
575 void shrinkArrays(Printer& p);
578 Meth method(void) const;
581 int optVar(void) const;
583 bool optVarIsInt(void) const;
594 void createBranchers(Printer& p, AST::Node* ann,
595 FlatZincOptions& opt, bool ignoreUnknown,
596 std::ostream& err = std::cerr);
605 virtual void constrain(const Space& s);
609 virtual bool slave(const MetaInfo& mi);
613 IntArgs arg2intargs(AST::Node* arg, int offset = 0);
616 IntSharedArray arg2intsharedarray(AST::Node* arg, int offset = 0);
618 IntArgs arg2boolargs(AST::Node* arg, int offset = 0);
620 IntSharedArray arg2boolsharedarray(AST::Node* arg, int offset = 0);
622 IntSet arg2intset(AST::Node* n);
624 IntSetArgs arg2intsetargs(AST::Node* arg, int offset = 0);
626 IntVarArgs arg2intvarargs(AST::Node* arg, int offset = 0);
628 BoolVarArgs arg2boolvarargs(AST::Node* arg, int offset = 0, int siv=-1);
630 BoolVar arg2BoolVar(AST::Node* n);
632 IntVar arg2IntVar(AST::Node* n);
634 TupleSet arg2tupleset(AST::Node* n, int noOfVars);
636 bool isBoolArray(AST::Node* b, int& singleInt);
637 #ifdef GECODE_HAS_SET_VARS 638 SetVar arg2SetVar(AST::Node* n);
641 SetVarArgs arg2setvarargs(AST::Node* arg, int offset = 0, int doffset = 0,
642 const IntSet& od=IntSet::empty);
644 #ifdef GECODE_HAS_FLOAT_VARS 645 FloatValArgs arg2floatargs(AST::Node* arg, int offset = 0);
648 FloatVar arg2FloatVar(AST::Node* n);
650 FloatVarArgs arg2floatvarargs(AST::Node* arg, int offset = 0);
655 DFA getSharedDFA(DFA& a);
662 const std::string msg;
664 Error(
const std::string& where,
const std::string& what)
665 : msg(where+
": "+what) {}
666 const std::string&
toString(
void)
const {
return msg; }
676 Printer&
p, std::ostream& err = std::cerr,
686 Printer& p, std::ostream& err = std::cerr,
#define GECODE_FLATZINC_VERSION
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::Driver::UnsignedIntOption _time
Cutoff for time.
Gecode::Driver::BoolOption _allSolutions
Return all solutions.
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
GECODE_FLATZINC_EXPORT FlatZincSpace * parse(const std::string &fileName, Printer &p, std::ostream &err=std::cerr, FlatZincSpace *fzs=NULL, Rnd &rnd=defrnd)
Parse FlatZinc file fileName into fzs and return it.
void add(int v, const char *o, const char *h=NULL)
Add option value for value v, string o, and help text h.
void restart_scale(int i)
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 profiler_info(void) const
bool allSolutions(void) const
Rnd defrnd(0)
Uninitialized default random number generator.
Gecode::Driver::BoolOption _stat
Emit statistics.
RestartMode
Different modes for restart-based search.
Gecode::Driver::UnsignedIntOption _a_d
Adaptive recomputation distance.
unsigned int profiler_port(void) const
Gecode::Driver::DoubleOption _decay
Decay option.
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
Gecode::Driver::IntOption _profiler_id
Use this execution id for the CP-profiler.
int profiler_id(void) const
Deterministic finite automaton (DFA)
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.
#define GECODE_HAS_SET_VARS
Gecode::Driver::StringOption _mode
Script mode to run.
Gecode::Driver::BoolOption _profiler_info
Whether solution information should be sent to the CP-profiler.
Print solution and some statistics.
Value description class for branching.
double threads(void) const
void restart(RestartMode rm)
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) ...
Gecode::Driver::UnsignedIntOption _profiler_port
Connect to this port.
Base class for script options.
Gecode::Driver::DoubleOption _step
Step option.
const std::string & floatVarName(int i) const
Error(const std::string &where, const std::string &what)
const char * output(void) const
FlatZincSpaceInitData * _initData
Initialisation data (only used for posting constraints)
unsigned int node(void) const
const std::string & intVarName(int i) 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)
Class represeting a set of tuples.
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.
struct Gecode::@585::NNF::@62::@63 b
For binary nodes (and, or, eqv)
Gecode::Driver::BoolOption _interrupt
Whether to catch SIGINT.
Print statistics for script.
Run script with CP-profiler.
Gecode::Driver::DoubleOption _r_base
Restart base.
void value(const char *v)
Set default value to v.
struct Gecode::@585::NNF::@62::@64 a
For atomic nodes.
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
bool interrupt(void) const
Rnd _random
Random number generator.
#define GECODE_HAS_FLOAT_VARS
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.
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.
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 restart_base(double d)
void parse(int &argc, char *argv[])
virtual void help(void)
Print help text.