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"
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),
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;
355 unsigned int c_d(
void)
const {
return _c_d.value(); }
356 unsigned int a_d(
void)
const {
return _a_d.value(); }
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;
473 template<
template<
class>
class Engine>
475 runEngine(std::ostream& out,
const Printer&
p,
478 template<
template<
class>
class Engine,
479 template<
class,
template<
class>
class>
class Meta>
484 branchWithPlugin(AST::Node* ann);
504#ifdef GECODE_HAS_SET_VARS
512#ifdef GECODE_HAS_FLOAT_VARS
531 void
init(int intVars, int boolVars, int setVars, int floatVars);
550 void
solve(AST::Array* annotation);
552 void
minimize(int var, bool isInt, AST::Array* annotation);
554 void
maximize(int var, bool isInt, AST::Array* annotation);
557 void
run(std::ostream& out, const Printer& p,
558 const FlatZincOptions& opt, Gecode::Support::Timer& t_total);
561 void
print(std::ostream& out, const Printer& p) const;
562#ifdef GECODE_HAS_CPPROFILER
564 std::string
getDomains(const Printer& p) const;
568 void
compare(const Space& s, std::ostream& out) const;
571 void
compare(const FlatZincSpace& s, std::ostream& out,
572 const Printer& p) const;
602 FlatZincOptions& opt, bool ignoreUnknown,
603 std::ostream& err = std::cerr);
616 virtual bool
slave(const MetaInfo& mi);
644#ifdef GECODE_HAS_SET_VARS
649 const IntSet& od=IntSet::empty);
651#ifdef GECODE_HAS_FLOAT_VARS
669 const std::string msg;
671 Error(
const std::string& where,
const std::string& what)
672 : msg(where+
": "+what) {}
673 const std::string&
toString(
void)
const {
return msg; }
683 Printer& p, std::ostream& err = std::cerr,
693 Printer& p, std::ostream& err = std::cerr,
Base class for script options.
BaseOptions(const char *s)
Initialize options for script with name s.
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)
String-valued option (integer value defined by strings)
A node in a FlatZinc abstract syntax tree.
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.
void createBranchers(Printer &p, AST::Node *ann, FlatZincOptions &opt, bool ignoreUnknown, std::ostream &err=std::cerr)
Create branchers corresponding to the solve item annotations.
Gecode::IntVarArray iv_lns
The integer variables used in LNS.
void shrinkArrays(Printer &p)
Remove all variables not needed for output.
unsigned int _lns
Percentage of variables to keep in LNS (or 0 for no LNS)
void maximize(int var, bool isInt, AST::Array *annotation)
Post that integer variable var should be maximized.
IntVarArgs arg2intvarargs(AST::Node *arg, int offset=0)
Convert arg to IntVarArgs.
Gecode::FloatVarArray fv
The float variables.
Rnd _random
Random number generator.
void newBoolVar(BoolVarSpec *vs)
Create new Boolean variable from specification.
FloatVar arg2FloatVar(AST::Node *n)
Convert n to FloatVar.
void print(std::ostream &out, const Printer &p) const
Produce output on out using p.
std::vector< bool > fv_introduced
Indicates whether a float variable is introduced by mzn2fzn.
AST::Array * _solveAnnotations
Annotations on the solve item.
int _optVar
Index of the variable to optimize.
BranchInformation branchInfo
Information for printing branches.
void run(std::ostream &out, const Printer &p, const FlatZincOptions &opt, Gecode::Support::Timer &t_total)
Run the search.
DFA getSharedDFA(DFA &a)
Share DFA a if possible.
void newFloatVar(FloatVarSpec *vs)
Create new float variable from specification.
SetVar arg2SetVar(AST::Node *n)
Convert n to SetVar.
int * iv_boolalias
Indicates whether an integer variable aliases a Boolean variable.
virtual bool slave(const MetaInfo &mi)
Slave function for restarts.
void postConstraints(std::vector< ConExpr * > &ces)
Post a constraint specified by ce.
SetVarArgs arg2setvarargs(AST::Node *arg, int offset=0, int doffset=0, const IntSet &od=IntSet::empty)
Convert n to SetVarArgs.
bool _optVarIsInt
Whether variable to optimize is integer (or float)
FlatZincSpace(FlatZincSpace &)
Copy constructor.
Gecode::BoolVarArray bv
The Boolean variables.
void newSetVar(SetVarSpec *vs)
Create new set variable from specification.
bool optVarIsInt(void) const
Return whether variable used for optimization is integer (or float)
std::vector< bool > iv_introduced
Indicates whether an integer variable is introduced by mzn2fzn.
IntVar arg2IntVar(AST::Node *n)
Convert n to IntVar.
std::string getDomains(const Printer &p) const
Get string representing the domains of variables (for cpprofiler)
FlatZincSpaceInitData * _initData
Initialisation data (only used for posting constraints)
Meth method(void) const
Return whether to solve a satisfaction or optimization problem.
std::vector< bool > sv_introduced
Indicates whether a set variable is introduced by mzn2fzn.
IntSet arg2intset(AST::Node *n)
Convert n to IntSet.
std::vector< bool > bv_introduced
Indicates whether a Boolean variable is introduced by mzn2fzn.
Gecode::FloatVarArray fv_aux
The introduced float variables.
void minimize(int var, bool isInt, AST::Array *annotation)
Post that integer variable var should be minimized.
virtual void constrain(const Space &s)
Implement optimization.
IntArgs arg2boolargs(AST::Node *arg, int offset=0)
Convert arg (array of Booleans) to IntArgs.
Gecode::SetVarArray sv_aux
The introduced set variables.
int floatVarCount
Number of float variables.
int boolVarCount
Number of Boolean variables.
Gecode::SetVarArray sv
The set variables.
int setVarCount
Number of set variables.
int optVar(void) const
Return index of variable used for optimization.
FloatVarArgs arg2floatvarargs(AST::Node *arg, int offset=0)
Convert n to FloatVarArgs.
IntSharedArray arg2boolsharedarray(AST::Node *arg, int offset=0)
Convert arg (array of integers) to IntSharedArray.
void solve(AST::Array *annotation)
Post the solve item.
Gecode::FloatNum step
Step by which a next solution has to have lower cost.
IntSharedArray _lnsInitialSolution
Initial solution to start the LNS (or NULL for no LNS)
Gecode::BoolVarArray bv_aux
The introduced Boolean variables.
IntSharedArray arg2intsharedarray(AST::Node *arg, int offset=0)
Convert arg (array of integers) to IntSharedArray.
BoolVarArgs arg2boolvarargs(AST::Node *arg, int offset=0, int siv=-1)
Convert arg to BoolVarArgs.
void aliasBool2Int(int iv, int bv)
Link integer variable iv to Boolean variable bv.
AST::Array * solveAnnotations(void) const
Return the solve item annotations.
Gecode::IntVarArray iv_aux
The introduced integer variables.
Gecode::IntVarArray iv
The integer variables.
virtual Gecode::Space * copy(void)
Copy function.
void init(int intVars, int boolVars, int setVars, int floatVars)
Initialize space with given number of variables.
bool isBoolArray(AST::Node *b, int &singleInt)
Check if b is array of Booleans (or has a single integer)
IntPropLevel ann2ipl(AST::Node *ann)
Convert ann to integer propagation level.
void newIntVar(IntVarSpec *vs)
Create new integer variable from specification.
Meth _method
Whether to solve as satisfaction or optimization problem.
void compare(const Space &s, std::ostream &out) const
Compare this space with space s and print the differences on out.
int intVarCount
Number of integer variables.
BoolVar arg2BoolVar(AST::Node *n)
Convert n to BoolVar.
TupleSet arg2tupleset(const IntArgs &a, int noOfVars)
Convert a to TupleSet.
IntSetArgs arg2intsetargs(AST::Node *arg, int offset=0)
Convert arg to IntSetArgs.
FloatValArgs arg2floatargs(AST::Node *arg, int offset=0)
Convert n to FloatValArgs.
bool needAuxVars
Whether the introduced variables still need to be copied.
IntArgs arg2intargs(AST::Node *arg, int offset=0)
Convert arg (array of integers) to IntArgs.
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.
SharedHandle(void)
Create shared handle with no object pointing to.
struct Gecode::Space::@055132133326276162005044145100211202071356247106::@275070317317120154232063063134255170030071110047 p
Data only available during propagation or branching.
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.
Space(void)
Default constructor.
void print(const Search::Statistics &stat, bool restart)
Print statistics.
Interpreter for the FlatZinc language.
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
ArgArray< IntSet > IntSetArgs
Passing set arguments.
SharedArray< int > IntSharedArray
Arrays of integers that can be shared among several element constraints.
#define GECODE_HAS_FLOAT_VARS
#define GECODE_HAS_SET_VARS
#define GECODE_FLATZINC_VERSION
#define GECODE_VTABLE_EXPORT