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"
101namespace Gecode {
namespace FlatZinc {
110 std::vector<std::string> iv_names;
112 std::vector<std::string> bv_names;
113#ifdef GECODE_HAS_FLOAT_VARS
115 std::vector<std::string> fv_names;
117#ifdef GECODE_HAS_SET_VARS
119 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);
187 const std::string&
intVarName(
int i)
const {
return iv_names[i]; }
188 void addBoolVarName(
const std::string&
n);
189 const std::string&
boolVarName(
int i)
const {
return bv_names[i]; }
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);
196 const std::string&
setVarName(
int i)
const {
return sv_names[i]; }
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
562 std::string getDomains(const Printer& p) const;
566 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);
619 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
644 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
651 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,
struct Gecode::@603::NNF::@65::@66 b
For binary nodes (and, or, eqv)
int p
Number of positive literals for node type.
int n
Number of negative literals for node type.
struct Gecode::@603::NNF::@65::@67 a
For atomic nodes.
Base class for script options.
void add(Driver::BaseOption &o)
Add new option o.
virtual void help(void)
Print help text.
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
Passing Boolean variables.
Boolean integer variables.
Base-class for branchers.
Deterministic finite automaton (DFA)
void value(bool v)
Set default value to v.
void value(double v)
Set default value to v.
void value(int v)
Set default value to v.
String-valued option (integer value defined by strings)
void value(int v)
Set default value to v.
void add(int v, const char *o, const char *h=NULL)
Add option value for value v, string o, and help text h.
void value(const char *v)
Set default value to v.
void value(unsigned int v)
Set default value to v.
A node in a FlatZinc abstract syntax tree.
Exception class for FlatZinc errors
Error(const std::string &where, const std::string &what)
const std::string & toString(void) const
Options for running FlatZinc models
Gecode::Driver::BoolOption _interrupt
Whether to catch SIGINT.
Gecode::Driver::BoolOption _nogoods
Whether to use no-goods.
Gecode::Driver::BoolOption _allSolutions
Return all solutions.
Gecode::Driver::BoolOption _stat
Emit statistics.
unsigned int time(void) const
Script mode to run.
void allSolutions(bool b)
Script mode to run.
bool allSolutions(void) const
Script mode to run.
unsigned int fail(void) const
Script mode to run.
Gecode::Driver::BoolOption _free
Use free search.
FlatZincOptions(const char *s)
Constructor.
int seed(void) const
Script mode to run.
double decay(void) const
Script mode to run.
Gecode::Driver::IntOption _profiler_id
Use this execution id for the CP-profiler.
unsigned int nogoods_limit(void) const
Script mode to run.
Gecode::Driver::UnsignedIntOption _nogoods_limit
Depth limit for extracting no-goods.
const char * output(void) const
Script mode to run.
RestartMode restart(void) const
Script mode to run.
Gecode::Driver::UnsignedIntOption _r_scale
Restart scale factor.
double restart_base(void) const
Script mode to run.
virtual void help(void)
Script mode to run.
int solutions(void) const
Script mode to run.
Gecode::Driver::UnsignedIntOption _time_limit
Cutoff for time (for compatibility with flatzinc command line)
Gecode::Driver::UnsignedIntOption _node
Cutoff for number of nodes.
bool nogoods(void) const
Script mode to run.
double step(void) const
Script mode to run.
Gecode::Driver::DoubleOption _step
Step option.
Gecode::ScriptMode mode(void) const
Script mode to run.
bool interrupt(void) const
Script mode to run.
Gecode::Driver::StringValueOption _output
Output file.
void parse(int &argc, char *argv[])
Script mode to run.
unsigned int profiler_port(void) const
Script mode to run.
Gecode::Driver::BoolOption _profiler_info
Whether solution information should be sent to the CP-profiler.
void restart(RestartMode rm)
Script mode to run.
Gecode::Driver::DoubleOption _r_base
Restart base.
Gecode::Driver::UnsignedIntOption _profiler_port
Connect to this port.
Gecode::Driver::UnsignedIntOption _c_d
Copy recomputation distance.
int profiler_id(void) const
Script mode to run.
void restart_scale(int i)
Script mode to run.
Gecode::Driver::StringOption _mode
Script mode to run.
unsigned int restart_scale(void) const
Script mode to run.
unsigned int a_d(void) const
Script mode to run.
unsigned int c_d(void) const
Script mode to run.
bool profiler_info(void) const
Script mode to run.
Gecode::Driver::UnsignedIntOption _a_d
Adaptive recomputation distance.
Gecode::Driver::UnsignedIntOption _fail
Cutoff for number of failures.
unsigned int node(void) const
Script mode to run.
bool free(void) const
Script mode to run.
Gecode::Driver::DoubleOption _threads
How many threads to use.
Gecode::Driver::IntOption _seed
Random seed.
Gecode::Driver::IntOption _solutions
How many solutions.
Gecode::Driver::DoubleOption _decay
Decay option.
double threads(void) const
Script mode to run.
Gecode::Driver::UnsignedIntOption _time
Cutoff for time.
Gecode::Driver::StringOption _restart
Restart method option.
void restart_base(double d)
Script mode to run.
A space that can be initialized with a FlatZinc model.
unsigned int _lns
Percentage of variables to keep in LNS (or 0 for no LNS)
Rnd _random
Random number generator.
AST::Array * _solveAnnotations
Annotations on the solve item.
int _optVar
Index of the variable to optimize.
bool _optVarIsInt
Whether variable to optimize is integer (or float)
FlatZincSpaceInitData * _initData
Initialisation data (only used for posting constraints)
int floatVarCount
Number of float variables.
int boolVarCount
Number of Boolean variables.
int setVarCount
Number of set variables.
IntSharedArray _lnsInitialSolution
Initial solution to start the LNS (or NULL for no LNS)
Meth _method
Whether to solve as satisfaction or optimization problem.
int intVarCount
Number of integer variables.
Output support class for FlatZinc interpreter.
const std::string & setVarName(int i) const
const std::string & boolVarName(int i) const
const std::string & intVarName(int i) const
const std::string & floatVarName(int i) const
Value description class for branching.
Passing integer arguments.
Passing integer variables.
Class represeting a set of tuples.
#define GECODE_FLATZINC_EXPORT
ScriptMode
Different modes for executing scripts.
RestartMode
Different modes for restart-based search.
@ SM_STAT
Print statistics for script.
@ SM_SOLUTION
Print solution and some statistics.
@ SM_GIST
Run script in Gist.
@ SM_CPPROFILER
Run script with CP-profiler.
@ RM_CONSTANT
Restart with constant sequence.
@ RM_LINEAR
Restart with linear sequence.
@ RM_LUBY
Restart with Luby sequence.
@ RM_GEOMETRIC
Restart with geometric sequence.
double FloatNum
Floating point number base type.
IntPropLevel
Propagation levels for integer propagators.
void print(const Search::Statistics &stat, bool restart)
Print statistics.
void solve(const JobShopOptions &opt)
Solver.
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.
GECODE_FLATZINC_EXPORT Rnd defrnd
Uninitialized default random number generator.
Gecode toplevel namespace
#define GECODE_HAS_FLOAT_VARS
#define GECODE_HAS_SET_VARS
#define GECODE_FLATZINC_VERSION
#define GECODE_VTABLE_EXPORT