Go to the documentation of this file.
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,
156 void print(std::ostream& out,
169 void printDiff(std::ostream& out,
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,
257 #ifdef GECODE_HAS_CPPROFILER
270 _solutions(
"n",
"number of solutions (0 = all, -1 = one/best)",-1),
272 _threads(
"p",
"number of threads (0 = #processing units)",
274 _free(
"f",
"free search, no need to follow search-specification"),
275 _decay(
"decay",
"decay factor",0.99),
276 _c_d(
"c-d",
"recomputation commit distance",
Gecode::Search::Config::
c_d),
277 _a_d(
"a-d",
"recomputation adaption distance",
Gecode::Search::Config::
a_d),
278 _node(
"node",
"node cutoff (0 = none, solution mode)"),
279 _fail(
"fail",
"failure cutoff (0 = none, solution mode)"),
280 _time(
"time",
"time (in ms) cutoff (0 = none, solution mode)"),
281 _time_limit(
"t",
"time (in ms) cutoff (0 = none, solution mode)"),
282 _seed(
"r",
"random seed",0),
284 _r_base(
"restart-base",
"base for geometric restart sequence",1.5),
285 _r_scale(
"restart-scale",
"scale factor for restart sequence",250),
286 _nogoods(
"nogoods",
"whether to use no-goods from restarts",false),
287 _nogoods_limit(
"nogoods-limit",
"depth limit for no-good extraction",
289 _interrupt(
"interrupt",
"whether to catch Ctrl-C (true) or not (false)",
291 _step(
"step",
"step distance for float optimization",0.0),
293 _stat(
"s",
"emit statistics"),
294 _output(
"o",
"file to send output to")
296 #ifdef GECODE_HAS_CPPROFILER
298 _profiler_id(
"cpprofiler-id",
"use this execution id with cpprofiler", 0),
299 _profiler_port(
"cpprofiler-port",
"connect to cpprofiler on this port", 6565),
300 _profiler_info(
"cpprofiler-info",
"send solution information to cpprofiler", false)
325 #ifdef GECODE_HAS_CPPROFILER
332 void parse(
int& argc,
char* argv[]) {
345 std::cerr <<
"Gecode FlatZinc interpreter" << std::endl
347 << std::endl << std::endl;
383 #ifdef GECODE_HAS_CPPROFILER
404 const std::string& rel0,
405 const std::string& rel1,
406 const std::vector<std::string>&
n);
409 unsigned int a,
int i,
int n, std::ostream& o)
const;
410 #ifdef GECODE_HAS_FLOAT_VARS
414 std::ostream& o)
const;
471 template<
template<
class>
class Engine>
473 runEngine(std::ostream& out,
const Printer&
p,
476 template<
template<
class>
class Engine,
477 template<
class,
template<
class>
class>
class Meta>
482 branchWithPlugin(AST::Node* ann);
493 std::vector<bool> iv_introduced;
501 std::vector<bool> bv_introduced;
502 #ifdef GECODE_HAS_SET_VARS
508 std::vector<bool> sv_introduced;
510 #ifdef GECODE_HAS_FLOAT_VARS
516 std::vector<bool> fv_introduced;
529 void init(int intVars, int boolVars, int setVars, int floatVars);
532 void newIntVar(IntVarSpec* vs);
534 void aliasBool2Int(int iv, int bv);
536 int aliasBool2Int(int iv);
538 void newBoolVar(BoolVarSpec* vs);
540 void newSetVar(SetVarSpec* vs);
542 void newFloatVar(FloatVarSpec* vs);
545 void postConstraints(std::vector<ConExpr*>& ces);
548 void
solve(AST::Array* annotation);
550 void minimize(int var, bool isInt, AST::Array* annotation);
552 void maximize(int var, bool isInt, AST::Array* annotation);
555 void run(std::ostream& out, const Printer& p,
556 const FlatZincOptions& opt, Gecode::Support::Timer& t_total);
559 void
print(std::ostream& out, const Printer& p) const;
560 #ifdef GECODE_HAS_CPPROFILER
561 std::string getDomains(const Printer& p) const;
564 void
compare(const Space& s, std::ostream& out) const;
569 void
compare(const FlatZincSpace& s, std::ostream& out,
570 const Printer& p) const;
580 void shrinkArrays(Printer& p);
583 Meth method(void) const;
586 int optVar(void) const;
588 bool optVarIsInt(void) const;
599 void createBranchers(Printer& p, AST::Node* ann,
600 FlatZincOptions& opt, bool ignoreUnknown,
601 std::ostream& err = std::cerr);
610 virtual void constrain(const Space& s);
614 virtual bool slave(const MetaInfo& mi);
618 IntArgs arg2intargs(AST::Node* arg, int offset = 0);
621 IntSharedArray arg2intsharedarray(AST::Node* arg, int offset = 0);
623 IntArgs arg2boolargs(AST::Node* arg, int offset = 0);
625 IntSharedArray arg2boolsharedarray(AST::Node* arg, int offset = 0);
627 IntSet arg2intset(AST::Node* n);
629 IntSetArgs arg2intsetargs(AST::Node* arg, int offset = 0);
631 IntVarArgs arg2intvarargs(AST::Node* arg, int offset = 0);
633 BoolVarArgs arg2boolvarargs(AST::Node* arg, int offset = 0, int siv=-1);
635 BoolVar arg2BoolVar(AST::Node* n);
637 IntVar arg2IntVar(AST::Node* n);
639 TupleSet arg2tupleset(const IntArgs& a, int noOfVars);
641 bool isBoolArray(AST::Node* b, int& singleInt);
642 #ifdef GECODE_HAS_SET_VARS
643 SetVar arg2SetVar(AST::Node* n);
646 SetVarArgs arg2setvarargs(AST::Node* arg, int offset = 0, int doffset = 0,
647 const IntSet& od=IntSet::empty);
649 #ifdef GECODE_HAS_FLOAT_VARS
650 FloatValArgs arg2floatargs(AST::Node* arg, int offset = 0);
653 FloatVar arg2FloatVar(AST::Node* n);
655 FloatVarArgs arg2floatvarargs(AST::Node* arg, int offset = 0);
660 DFA getSharedDFA(DFA& a);
667 const std::string msg;
669 Error(
const std::string& where,
const std::string& what)
670 : msg(where+
": "+what) {}
671 const std::string&
toString(
void)
const {
return msg; }
681 Printer&
p, std::ostream& err = std::cerr,
691 Printer&
p, std::ostream& err = std::cerr,
A node in a FlatZinc abstract syntax tree.
FlatZincOptions(const char *s)
Constructor.
const Gecode::FloatNum step
bool free(void) const
Script mode to run.
#define GECODE_VTABLE_EXPORT
double restart_base(void) const
Script mode to run.
int solutions(void) const
Script mode to run.
unsigned int nogoods_limit(void) const
Script mode to run.
void value(const char *v)
Set default value to v.
Output support class for FlatZinc interpreter.
A space that can be initialized with a FlatZinc model.
int boolVarCount
Number of Boolean variables.
Passing integer variables.
Gecode::Driver::BoolOption _stat
Emit statistics.
Gecode::Driver::UnsignedIntOption _time_limit
Cutoff for time (for compatibility with flatzinc command line)
Meth _method
Whether to solve as satisfaction or optimization problem.
void add(Driver::BaseOption &o)
Add new option o.
String-valued option (integer value defined by strings)
void value(int v)
Set default value to v.
unsigned int profiler_port(void) const
Script mode to run.
IntPropLevel
Propagation levels for integer propagators.
Gecode::Driver::UnsignedIntOption _r_scale
Restart scale factor.
#define GECODE_FLATZINC_VERSION
int profiler_id(void) const
Script mode to run.
#define GECODE_HAS_FLOAT_VARS
Gecode::Driver::BoolOption _profiler_info
Whether solution information should be sent to the CP-profiler.
@ RM_LUBY
Restart with Luby sequence.
Gecode::Driver::IntOption _solutions
How many solutions.
@ RM_LINEAR
Restart with linear sequence.
double threads(void) const
Script mode to run.
Gecode::Driver::UnsignedIntOption _profiler_port
Connect to this port.
bool allSolutions(void) const
Script mode to run.
Gecode::Driver::UnsignedIntOption _time
Cutoff for time.
Options for running FlatZinc models
void value(unsigned int v)
Set default value to v.
Gecode::Driver::StringValueOption _output
Output file.
Gecode toplevel namespace
Gecode::Driver::BoolOption _allSolutions
Return all solutions.
Gecode::Driver::UnsignedIntOption _a_d
Adaptive recomputation distance.
RestartMode restart(void) const
Script mode to run.
int _optVar
Index of the variable to optimize.
Gecode::Driver::BoolOption _nogoods
Whether to use no-goods.
@ RM_GEOMETRIC
Restart with geometric sequence.
Gecode::Driver::DoubleOption _decay
Decay option.
@ SM_STAT
Print statistics for script.
@ SM_SOLUTION
Print solution and some statistics.
Base-class for branchers.
unsigned int node(void) const
Script mode to run.
void value(int v)
Set default value to v.
Passing Boolean variables.
Gecode::Driver::IntOption _profiler_id
Use this execution id for the CP-profiler.
#define GECODE_HAS_SET_VARS
double FloatNum
Floating point number base type.
Boolean integer variables.
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
void add(int v, const char *o, const char *h=NULL)
Add option value for value v, string o, and help text h.
RestartMode
Different modes for restart-based search.
const std::string & intVarName(int i) const
const std::string & floatVarName(int i) const
Value description class for branching.
@ RM_CONSTANT
Restart with constant sequence.
struct Gecode::@602::NNF::@65::@66 b
For binary nodes (and, or, eqv)
@ SM_GIST
Run script in Gist.
bool _optVarIsInt
Whether variable to optimize is integer (or float)
FlatZincSpaceInitData * _initData
Initialisation data (only used for posting constraints)
Class represeting a set of tuples.
void value(double v)
Set default value to v.
unsigned int fail(void) const
Script mode to run.
Gecode::Driver::UnsignedIntOption _node
Cutoff for number of nodes.
void value(bool v)
Set default value to v.
Base class for script options.
struct Gecode::@602::NNF::@65::@67 a
For atomic nodes.
void restart_base(double d)
Script mode to run.
Gecode::Driver::DoubleOption _threads
How many threads to use.
virtual void help(void)
Print help text.
Exception class for FlatZinc errors
Deterministic finite automaton (DFA)
void restart(RestartMode rm)
Script mode to run.
void allSolutions(bool b)
Script mode to run.
virtual void help(void)
Script mode to run.
Rnd defrnd(0)
Uninitialized default random number generator.
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.
AST::Array * _solveAnnotations
Annotations on the solve item.
Gecode::Driver::UnsignedIntOption _fail
Cutoff for number of failures.
Gecode::Driver::StringOption _mode
Script mode to run.
Gecode::Driver::UnsignedIntOption _nogoods_limit
Depth limit for extracting no-goods.
void solve(const JobShopOptions &opt)
Solver.
@ SM_CPPROFILER
Run script with CP-profiler.
Gecode::Driver::BoolOption _interrupt
Whether to catch SIGINT.
Gecode::Driver::DoubleOption _r_base
Restart base.
const std::string & setVarName(int i) const
#define GECODE_FLATZINC_EXPORT
int setVarCount
Number of set variables.
int intVarCount
Number of integer variables.
int seed(void) const
Script mode to run.
unsigned int c_d(void) const
Script mode to run.
double decay(void) const
Script mode to run.
const std::string & toString(void) const
Rnd _random
Random number generator.
ScriptMode
Different modes for executing scripts.
void parse(int &argc, char *argv[])
Script mode to run.
const std::string & boolVarName(int i) const
Gecode::ScriptMode mode(void) const
Script mode to run.
Gecode::Driver::UnsignedIntOption _c_d
Copy recomputation distance.
int n
Number of negative literals for node type.
bool nogoods(void) const
Script mode to run.
double step(void) const
Script mode to run.
bool interrupt(void) const
Script mode to run.
Gecode::Driver::IntOption _seed
Random seed.
IntSharedArray _lnsInitialSolution
Initial solution to start the LNS (or NULL for no LNS)
Gecode::Driver::StringOption _restart
Restart method option.
unsigned int restart_scale(void) const
Script mode to run.
Error(const std::string &where, const std::string &what)
Passing integer arguments.
CompareStatus compare(I &i, J &j)
Check whether range iterator i is a subset of j, or whether they are disjoint.
void restart_scale(int i)
Script mode to run.
Gecode::Driver::BoolOption _free
Use free search.
unsigned int time(void) const
Script mode to run.
Gecode::IntArgs i({1, 2, 3, 4})
bool profiler_info(void) const
Script mode to run.
int p
Number of positive literals for node type.
unsigned int _lns
Percentage of variables to keep in LNS (or 0 for no LNS)
Gecode::Driver::DoubleOption _step
Step option.
const char * output(void) const
Script mode to run.
unsigned int a_d(void) const
Script mode to run.
int floatVarCount
Number of float variables.
void print(const Search::Statistics &stat, bool restart)
Print statistics.