Generated on for Gecode by doxygen 1.17.0
flatzinc.hh
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Guido Tack <tack@gecode.dev>
5 *
6 * Contributing authors:
7 * Gabriel Hjort Blindell <gabriel.hjort.blindell@gmail.com>
8 *
9 * Copyright:
10 * Guido Tack, 2007-2012
11 * Gabriel Hjort Blindell, 2012
12 *
13 * This file is part of Gecode, the generic constraint
14 * development environment:
15 * http://www.gecode.dev
16 *
17 * Permission is hereby granted, free of charge, to any person obtaining
18 * a copy of this software and associated documentation files (the
19 * "Software"), to deal in the Software without restriction, including
20 * without limitation the rights to use, copy, modify, merge, publish,
21 * distribute, sublicense, and/or sell copies of the Software, and to
22 * permit persons to whom the Software is furnished to do so, subject to
23 * the following conditions:
24 *
25 * The above copyright notice and this permission notice shall be
26 * included in all copies or substantial portions of the Software.
27 *
28 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 *
36 */
37
38#ifndef GECODE_FLATZINC_HH
39#define GECODE_FLATZINC_HH
40
41#include <iostream>
42
43#include <gecode/kernel.hh>
44#include <gecode/int.hh>
45#ifdef GECODE_HAS_SET_VARS
46#include <gecode/set.hh>
47#endif
48#ifdef GECODE_HAS_FLOAT_VARS
49#include <gecode/float.hh>
50#endif
51#include <map>
52
53/*
54 * Support for DLLs under Windows
55 *
56 */
57
58#if !defined(GECODE_STATIC_LIBS) && \
59 (defined(__CYGWIN__) || defined(__MINGW32__) || defined(_MSC_VER))
60
61#ifdef GECODE_BUILD_FLATZINC
62#define GECODE_FLATZINC_EXPORT __declspec( dllexport )
63#else
64#define GECODE_FLATZINC_EXPORT __declspec( dllimport )
65#endif
66
67#else
68
69#ifdef GECODE_GCC_HAS_CLASS_VISIBILITY
70
71#define GECODE_FLATZINC_EXPORT __attribute__ ((visibility("default")))
72
73#else
74
75#define GECODE_FLATZINC_EXPORT
76
77#endif
78#endif
79
80// Configure auto-linking
81#ifndef GECODE_BUILD_FLATZINC
82#define GECODE_LIBRARY_NAME "FlatZinc"
84#endif
85
86#include <gecode/driver.hh>
87
91
100
101namespace Gecode { namespace FlatZinc {
102
108 private:
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;
116#endif
117#ifdef GECODE_HAS_SET_VARS
119 std::vector<std::string> sv_names;
120#endif
121 AST::Array* _output;
122 void printElem(std::ostream& out,
123 AST::Node* ai,
124 const Gecode::IntVarArray& iv,
125 const Gecode::BoolVarArray& bv
126#ifdef GECODE_HAS_SET_VARS
127 ,
128 const Gecode::SetVarArray& sv
129#endif
130#ifdef GECODE_HAS_FLOAT_VARS
131 ,
132 const Gecode::FloatVarArray& fv
133#endif
134 ) const;
135 void printElemDiff(std::ostream& out,
136 AST::Node* ai,
137 const Gecode::IntVarArray& iv1,
138 const Gecode::IntVarArray& iv2,
139 const Gecode::BoolVarArray& bv1,
140 const Gecode::BoolVarArray& bv2
141#ifdef GECODE_HAS_SET_VARS
142 ,
143 const Gecode::SetVarArray& sv1,
144 const Gecode::SetVarArray& sv2
145#endif
146#ifdef GECODE_HAS_FLOAT_VARS
147 ,
148 const Gecode::FloatVarArray& fv1,
149 const Gecode::FloatVarArray& fv2
150#endif
151 ) const;
152 public:
153 Printer(void) : _output(nullptr) {}
154 void init(AST::Array* output);
155
156 void print(std::ostream& out,
157 const Gecode::IntVarArray& iv,
158 const Gecode::BoolVarArray& bv
159#ifdef GECODE_HAS_SET_VARS
160 ,
161 const Gecode::SetVarArray& sv
162#endif
163#ifdef GECODE_HAS_FLOAT_VARS
164 ,
165 const Gecode::FloatVarArray& fv
166#endif
167 ) const;
168
169 void printDiff(std::ostream& out,
170 const Gecode::IntVarArray& iv1, const Gecode::IntVarArray& iv2,
171 const Gecode::BoolVarArray& bv1, const Gecode::BoolVarArray& bv2
172#ifdef GECODE_HAS_SET_VARS
173 ,
174 const Gecode::SetVarArray& sv1, const Gecode::SetVarArray& sv2
175#endif
176#ifdef GECODE_HAS_FLOAT_VARS
177 ,
178 const Gecode::FloatVarArray& fv1,
179 const Gecode::FloatVarArray& fv2
180#endif
181 ) const;
182
183
184 ~Printer(void);
185
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);
192 const std::string& floatVarName(int i) const { return fv_names[i]; }
193#endif
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]; }
197#endif
198
200 std::map<int,int>& iv, std::map<int,int>& bv,
201 std::map<int,int>& sv, std::map<int,int>& fv);
202
203 void shrinkArrays(Space& home,
204 int& optVar, bool optVarIsInt,
207#ifdef GECODE_HAS_SET_VARS
208 ,
210#endif
211#ifdef GECODE_HAS_FLOAT_VARS
212 ,
214#endif
215 );
216
217 private:
218 Printer(const Printer&);
219 Printer& operator=(const Printer&);
220 };
221
227 protected:
229
251
253
257
258#ifdef GECODE_HAS_CPPROFILER
260#endif
261
263 public:
265 FlatZincOptions(const char* s)
266 : Gecode::BaseOptions(s),
267 _solutions("n","number of solutions (0 = all, -1 = one/best)",-1),
268 _allSolutions("a", "return all solutions (equal to -n 0)"),
269 _threads("p","number of threads (0 = #processing units)",
270 Gecode::Search::Config::threads),
271 _free("f", "free search, no need to follow search-specification"),
272 _decay("decay","decay factor",0.99),
273 _c_d("c-d","recomputation commit distance",Gecode::Search::Config::c_d),
274 _a_d("a-d","recomputation adaption distance",Gecode::Search::Config::a_d),
275 _node("node","node cutoff (0 = none, solution mode)"),
276 _fail("fail","failure cutoff (0 = none, solution mode)"),
277 _time("time","time (in ms) cutoff (0 = none, solution mode)"),
278 _time_limit("t","time (in ms) cutoff (0 = none, solution mode)"),
279 _seed("r","random seed",0),
280 _restart("restart","restart sequence type",RM_NONE),
281 _r_base("restart-base","base for geometric restart sequence",1.5),
282 _r_scale("restart-scale","scale factor for restart sequence",250),
283 _r_limit("restart-limit","restart cutoff (0 = none, solution mode)"),
284 _nogoods("nogoods","whether to use no-goods from restarts",false),
285 _nogoods_limit("nogoods-limit","depth limit for no-good extraction",
286 Search::Config::nogoods_limit),
287 _interrupt("interrupt","whether to catch Ctrl-C (true) or not (false)",
288 true),
289 _step("step","step distance for float optimization",0.0),
290 _mode("mode","how to execute script",Gecode::SM_SOLUTION),
291 _stat("s","emit statistics"),
292 _output("o","file to send output to")
293
294#ifdef GECODE_HAS_CPPROFILER
295 ,
296 _profiler("cp-profiler", "use this execution id and port (comma separated) with CP-profiler")
297#endif
298 {
299 _mode.add(Gecode::SM_SOLUTION, "solution");
300 _mode.add(Gecode::SM_STAT, "stat");
301 _mode.add(Gecode::SM_GIST, "gist");
302 _restart.add(RM_NONE,"none");
303 _restart.add(RM_CONSTANT,"constant");
304 _restart.add(RM_LINEAR,"linear");
305 _restart.add(RM_LUBY,"luby");
306 _restart.add(RM_GEOMETRIC,"geometric");
307
310 add(_free);
311 add(_decay);
313 add(_seed);
314 add(_step);
317 add(_mode); add(_stat);
318 add(_output);
319#ifdef GECODE_HAS_CPPROFILER
320 add(_profiler);
321#endif
322 }
323
324 void parse(int& argc, char* argv[]) {
326 if (_allSolutions.value() && _solutions.value()==-1) {
327 _solutions.value(0);
328 }
329 if (_time_limit.value()) {
330 _time.value(_time_limit.value());
331 }
332 if (_stat.value() && (_mode.value() == Gecode::SM_SOLUTION))
333 _mode.value(Gecode::SM_STAT);
334 }
335
336 virtual void help(void) {
337 std::cerr << "Gecode FlatZinc interpreter" << std::endl
338 << " - FlatZinc text interface"
339 << std::endl << std::endl;
341 }
342
343 int solutions(void) const { return _solutions.value(); }
344 bool allSolutions(void) const { return _allSolutions.value(); }
345 double threads(void) const { return _threads.value(); }
346 bool free(void) const { return _free.value(); }
347 unsigned int c_d(void) const { return _c_d.value(); }
348 unsigned int a_d(void) const { return _a_d.value(); }
349 unsigned long long int node(void) const { return _node.value(); }
350 unsigned long long int fail(void) const { return _fail.value(); }
351 double time(void) const { return _time.value(); }
352 int seed(void) const { return _seed.value(); }
353 double step(void) const { return _step.value(); }
354 const char* output(void) const { return _output.value(); }
355
357 return static_cast<Gecode::ScriptMode>(_mode.value());
358 }
359
360 double decay(void) const { return _decay.value(); }
361 RestartMode restart(void) const {
362 return static_cast<RestartMode>(_restart.value());
363 }
365 _restart.value(rm);
366 }
367 double restart_base(void) const { return _r_base.value(); }
368 void restart_base(double d) { _r_base.value(d); }
369 unsigned int restart_scale(void) const { return _r_scale.value(); }
370 void restart_scale(int i) { _r_scale.value(i); }
371 unsigned long long int restart_limit(void) const { return _r_limit.value(); }
372 bool nogoods(void) const { return _nogoods.value(); }
373 unsigned int nogoods_limit(void) const { return _nogoods_limit.value(); }
374 bool interrupt(void) const { return _interrupt.value(); }
375
376#ifdef GECODE_HAS_CPPROFILER
377
378 int profiler_id(void) const { return _profiler.execution_id(); }
379 unsigned int profiler_port(void) const { return _profiler.port(); }
380 bool profiler_info(void) const { return true; }
381
382#endif
383
384 void allSolutions(bool b) { _allSolutions.value(b); }
385 };
386
388 public:
394 void init(void);
397 const std::string& rel0,
398 const std::string& rel1,
399 const std::vector<std::string>& n);
401 void print(const Brancher& b,
402 unsigned int a, int i, int n, std::ostream& o) const;
403#ifdef GECODE_HAS_FLOAT_VARS
405 void print(const Brancher& b,
406 unsigned int a, int i, const FloatNumBranch& nl,
407 std::ostream& o) const;
408#endif
411 };
412
415 extern Rnd defrnd;
416
417 class FlatZincSpaceInitData;
418 class BlackBoxAccess;
419
425 public:
426 enum Meth {
427 SAT, //< Solve as satisfaction problem
428 MIN, //< Solve as minimization problem
429 MAX //< Solve as maximization problem
430 };
431 protected:
433 FlatZincSpaceInitData* _initData;
442
447
450
452 unsigned int _lns;
453
456
459
462
465 private:
466 friend class BlackBoxAccess;
468 template<template<class> class Engine>
469 void
470 runEngine(std::ostream& out, const Printer& p,
471 const FlatZincOptions& opt, Gecode::Support::Timer& t_total);
473 template<template<class> class Engine,
474 template<class, template<class> class> class Meta>
475 void
476 runMeta(std::ostream& out, const Printer& p,
477 const FlatZincOptions& opt, Gecode::Support::Timer& t_total);
478 void
479 branchWithPlugin(AST::Node* ann);
480 public:
485
488
489 /* === Experimental `on_restart` support === */
491 protected:
493 public:
495 bool mark_complete = false;
497 std::vector<std::pair<int, int>> uniform_range_int;
498#ifdef GECODE_HAS_FLOAT_VARS
499 std::vector<std::pair<FloatVal, FloatVal>> uniform_range_float;
500#endif
502 std::vector<bool> last_val_bool;
503 std::vector<int> last_val_int;
504#ifdef GECODE_HAS_SET_VARS
505 std::vector<IntSet> last_val_set;
506#endif
507#ifdef GECODE_HAS_FLOAT_VARS
508 std::vector<FloatVal> last_val_float;
509#endif
519 bool on_restart_status = false;
520 };
521 public:
524 OnRestartHandle& operator =(const OnRestartHandle& handle) {
525 return static_cast<OnRestartHandle&>(SharedHandle::operator =(handle));
526 }
527 virtual ~OnRestartHandle() {};
528
529 void init() {
530 if (object() == nullptr) {
531 object(new OnRestartData());
532 }
533 }
534 bool initialized() const { return object() != nullptr; }
535 OnRestartData& operator ()() {
536 return *static_cast<OnRestartData*>(object());
537 };
538 };
544#ifdef GECODE_HAS_SET_VARS
547#endif
548#ifdef GECODE_HAS_FLOAT_VARS
551#endif
552 /* === End `on_restart` === */
553
555 std::vector<bool> iv_introduced;
563 std::vector<bool> bv_introduced;
564#ifdef GECODE_HAS_SET_VARS
570 std::vector<bool> sv_introduced;
571#endif
572#ifdef GECODE_HAS_FLOAT_VARS
578 std::vector<bool> fv_introduced;
581#endif
586
589
591 void init(int intVars, int boolVars, int setVars, int floatVars);
592
596 void aliasBool2Int(int iv, int bv);
605
607 void postConstraints(std::vector<ConExpr*>& ces);
608
610 void solve(AST::Array* annotation);
612 void minimize(int var, bool isInt, AST::Array* annotation);
614 void maximize(int var, bool isInt, AST::Array* annotation);
615
617 void run(std::ostream& out, const Printer& p,
618 const FlatZincOptions& opt, Gecode::Support::Timer& t_total);
619
621 void print(std::ostream& out, const Printer& p) const;
622#ifdef GECODE_HAS_CPPROFILER
624 std::string getDomains(const Printer& p) const;
625#endif
628 void compare(const Space& s, std::ostream& out) const;
631 void compare(const FlatZincSpace& s, std::ostream& out,
632 const Printer& p) const;
633
643
645 Meth method(void) const;
646
648 int optVar(void) const;
650 bool optVarIsInt(void) const;
651
662 FlatZincOptions& opt, bool ignoreUnknown,
663 std::ostream& err = std::cerr);
664
667
670
672 virtual void constrain(const Space& s);
674 virtual Gecode::Space* copy(void);
676 virtual bool slave(const MetaInfo& mi);
677
679
680
681 IntArgs arg2intargs(AST::Node* arg, int offset = 0);
685 IntArgs arg2boolargs(AST::Node* arg, int offset = 0);
691 IntSetArgs arg2intsetargs(AST::Node* arg, int offset = 0);
693 IntVarArgs arg2intvarargs(AST::Node* arg, int offset = 0);
695 BoolVarArgs arg2boolvarargs(AST::Node* arg, int offset = 0, int siv=-1);
701 TupleSet arg2tupleset(const IntArgs& a, int noOfVars);
703 bool isBoolArray(AST::Node* b, int& singleInt);
704#ifdef GECODE_HAS_SET_VARS
708 SetVarArgs arg2setvarargs(AST::Node* arg, int offset = 0, int doffset = 0,
709 const IntSet& od=IntSet::empty);
710#endif
711#ifdef GECODE_HAS_FLOAT_VARS
713 FloatValArgs arg2floatargs(AST::Node* arg, int offset = 0);
718#endif
724 };
725
728 private:
729 const std::string msg;
730 public:
731 Error(const std::string& where, const std::string& what)
732 : msg(where+": "+what) {}
733 Error(const std::string& where, const std::string& what, AST::Array *const ann)
734 : msg(make_message(where, what, ann)) {}
735 const std::string& toString(void) const { return msg; }
736 private:
737 static std::string make_message(const std::string &where, const std::string &what, AST::Array *const ann) {
738 std::ostringstream result;
739 result << where << ": " << what;
740
741 std::vector<std::string> names = get_constraint_names(ann);
742 if (names.size() > 1) {
743 result << " in constraints ";
744 for (unsigned int i = 0; i < names.size(); ++i) {
745 result << '\"' << names[i] << '\"';
746 if (i < names.size() - 1) {
747 result << ",";
748 }
749 result << " ";
750 }
751 } else if (names.size() == 1) {
752 result << " in constraint " << '\"' << names[0] << '\"';
753 }
754
755 return result.str();
756 }
757 static std::vector<std::string> get_constraint_names(AST::Array *const ann) {
758 std::vector<std::string> result;
759 if (ann) {
760 for (const auto & i : ann->a) {
761 if (i->isArray()) {
762 auto nested_result = get_constraint_names(i->getArray());
763 result.insert(result.end(), nested_result.begin(), nested_result.end());
764 } else if (i->isCall("mzn_constraint_name")) {
765 result.emplace_back(i->getCall()->args->getString());
766 }
767 }
768 }
769 return result;
770 }
771 };
772
779 FlatZincSpace* parse(const std::string& fileName,
780 Printer& p, std::ostream& err = std::cerr,
781 FlatZincSpace* fzs=nullptr, Rnd& rnd=defrnd);
782
789 FlatZincSpace* parse(std::istream& is,
790 Printer& p, std::ostream& err = std::cerr,
791 FlatZincSpace* fzs=nullptr, Rnd& rnd=defrnd);
792
793}}
794
795#endif
796
797// STATISTICS: flatzinc-any
Base class for script options.
Definition driver.hh:375
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.
Definition int.hh:738
Boolean variable array.
Definition int.hh:839
Boolean integer variables.
Definition int.hh:533
Group of branchers.
Definition core.hpp:806
Base-class for branchers.
Definition core.hpp:1453
Deterministic finite automaton (DFA).
Definition int.hh:2203
Boolean option.
Definition driver.hh:289
Integer option.
Definition driver.hh:208
String-valued option (integer value defined by strings).
Definition driver.hh:173
String-valued option.
Definition driver.hh:150
Unsigned integer option.
Definition driver.hh:228
Unsigned long long integer option.
Definition driver.hh:248
A node in a FlatZinc abstract syntax tree.
Definition ast.hh:67
Access to the model-local blackbox context while posting and searching.
Definition blackbox.hh:81
Specification for Boolean variables.
Definition varspec.hh:97
void init(void)
Initialise for use.
void print(const Brancher &b, unsigned int a, int i, int n, std::ostream &o) const
Output branch information.
BranchInformation & operator=(const BranchInformation &)=default
Assignment operator.
BranchInformation(const BranchInformation &bi)
Copy constructor.
void add(BrancherGroup bg, const std::string &rel0, const std::string &rel1, const std::vector< std::string > &n)
Add new brancher information.
void print(const Brancher &b, unsigned int a, int i, const FloatNumBranch &nl, std::ostream &o) const
Output branch information.
Error(const std::string &where, const std::string &what)
Definition flatzinc.hh:731
Error(const std::string &where, const std::string &what, AST::Array *const ann)
Definition flatzinc.hh:733
const std::string & toString(void) const
Definition flatzinc.hh:735
Options for running FlatZinc models
Definition flatzinc.hh:226
Gecode::Driver::BoolOption _interrupt
Whether to catch SIGINT.
Definition flatzinc.hh:248
Gecode::Driver::BoolOption _nogoods
Whether to use no-goods.
Definition flatzinc.hh:246
Gecode::Driver::ProfilerOption _profiler
Use this execution id for the CP-profiler.
Definition flatzinc.hh:259
Gecode::Driver::BoolOption _allSolutions
Return all solutions.
Definition flatzinc.hh:231
Gecode::Driver::BoolOption _stat
Emit statistics.
Definition flatzinc.hh:255
void allSolutions(bool b)
Script mode to run.
Definition flatzinc.hh:384
bool allSolutions(void) const
Script mode to run.
Definition flatzinc.hh:344
Gecode::Driver::BoolOption _free
Use free search.
Definition flatzinc.hh:233
FlatZincOptions(const char *s)
Constructor.
Definition flatzinc.hh:265
int seed(void) const
Script mode to run.
Definition flatzinc.hh:352
double decay(void) const
Script mode to run.
Definition flatzinc.hh:360
unsigned int nogoods_limit(void) const
Script mode to run.
Definition flatzinc.hh:373
Gecode::Driver::UnsignedIntOption _nogoods_limit
Depth limit for extracting no-goods.
Definition flatzinc.hh:247
const char * output(void) const
Script mode to run.
Definition flatzinc.hh:354
RestartMode restart(void) const
Script mode to run.
Definition flatzinc.hh:361
Gecode::Driver::UnsignedIntOption _r_scale
Restart scale factor.
Definition flatzinc.hh:244
double restart_base(void) const
Script mode to run.
Definition flatzinc.hh:367
virtual void help(void)
Script mode to run.
Definition flatzinc.hh:336
int solutions(void) const
Script mode to run.
Definition flatzinc.hh:343
bool nogoods(void) const
Script mode to run.
Definition flatzinc.hh:372
double step(void) const
Script mode to run.
Definition flatzinc.hh:353
Gecode::Driver::DoubleOption _step
Step option.
Definition flatzinc.hh:249
Gecode::ScriptMode mode(void) const
Script mode to run.
Definition flatzinc.hh:356
bool interrupt(void) const
Script mode to run.
Definition flatzinc.hh:374
Gecode::Driver::StringValueOption _output
Output file.
Definition flatzinc.hh:256
double time(void) const
Script mode to run.
Definition flatzinc.hh:351
void parse(int &argc, char *argv[])
Script mode to run.
Definition flatzinc.hh:324
unsigned int profiler_port(void) const
Script mode to run.
Definition flatzinc.hh:379
void restart(RestartMode rm)
Script mode to run.
Definition flatzinc.hh:364
Gecode::Driver::DoubleOption _r_base
Restart base.
Definition flatzinc.hh:243
Gecode::Driver::UnsignedIntOption _c_d
Copy recomputation distance.
Definition flatzinc.hh:235
int profiler_id(void) const
Script mode to run.
Definition flatzinc.hh:378
void restart_scale(int i)
Script mode to run.
Definition flatzinc.hh:370
Gecode::Driver::UnsignedLongLongIntOption _fail
Cutoff for number of failures.
Definition flatzinc.hh:238
unsigned long long int fail(void) const
Script mode to run.
Definition flatzinc.hh:350
Gecode::Driver::DoubleOption _time_limit
Cutoff for time (for compatibility with flatzinc command line).
Definition flatzinc.hh:240
Gecode::Driver::StringOption _mode
Script mode to run.
Definition flatzinc.hh:254
unsigned int restart_scale(void) const
Script mode to run.
Definition flatzinc.hh:369
unsigned int a_d(void) const
Script mode to run.
Definition flatzinc.hh:348
unsigned int c_d(void) const
Script mode to run.
Definition flatzinc.hh:347
Gecode::Driver::UnsignedLongLongIntOption _r_limit
Cutoff for number of restarts.
Definition flatzinc.hh:245
unsigned long long int restart_limit(void) const
Script mode to run.
Definition flatzinc.hh:371
bool profiler_info(void) const
Script mode to run.
Definition flatzinc.hh:380
Gecode::Driver::UnsignedIntOption _a_d
Adaptive recomputation distance.
Definition flatzinc.hh:236
unsigned long long int node(void) const
Script mode to run.
Definition flatzinc.hh:349
bool free(void) const
Script mode to run.
Definition flatzinc.hh:346
Gecode::Driver::DoubleOption _time
Cutoff for time.
Definition flatzinc.hh:239
Gecode::Driver::DoubleOption _threads
How many threads to use.
Definition flatzinc.hh:232
Gecode::Driver::IntOption _seed
Random seed.
Definition flatzinc.hh:241
Gecode::Driver::IntOption _solutions
How many solutions.
Definition flatzinc.hh:230
Gecode::Driver::UnsignedLongLongIntOption _node
Cutoff for number of nodes.
Definition flatzinc.hh:237
Gecode::Driver::DoubleOption _decay
Decay option.
Definition flatzinc.hh:234
double threads(void) const
Script mode to run.
Definition flatzinc.hh:345
Gecode::Driver::StringOption _restart
Restart method option.
Definition flatzinc.hh:242
void restart_base(double d)
Script mode to run.
Definition flatzinc.hh:368
std::vector< bool > last_val_bool
Last assigned values for different types of decisions.
Definition flatzinc.hh:502
bool on_restart_status
Whether the last on_restart_iv should be set to the restart status.
Definition flatzinc.hh:519
std::vector< std::pair< int, int > > uniform_range_int
Inclusive ranges to assign random values.
Definition flatzinc.hh:497
bool mark_complete
Marker set to true if solve process can be marked as complete.
Definition flatzinc.hh:495
std::vector< std::pair< FloatVal, FloatVal > > uniform_range_float
Definition flatzinc.hh:499
int on_restart_iv_sol
Number of sol calls for which variables are stored in on_restart_iv. In the array you first find this...
Definition flatzinc.hh:514
OnRestartHandle(const OnRestartHandle &handle)
Definition flatzinc.hh:523
A space that can be initialized with a FlatZinc model.
Definition flatzinc.hh:424
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.
Definition flatzinc.hh:487
Meth method(void) const
Return whether to solve a satisfaction or optimization problem.
void shrinkArrays(Printer &p)
Remove all variables not needed for output.
void compare(const FlatZincSpace &s, std::ostream &out, const Printer &p) const
Compare this space with space s and print the differences on out using p.
unsigned int _lns
Percentage of variables to keep in LNS (or 0 for no LNS).
Definition flatzinc.hh:452
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.
Definition flatzinc.hh:574
Rnd _random
Random number generator.
Definition flatzinc.hh:458
Gecode::FloatVarArray on_restart_fv
On Restart Tracked Floating Point Variables.
Definition flatzinc.hh:550
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.
Definition flatzinc.hh:578
AST::Array * _solveAnnotations
Annotations on the solve item.
Definition flatzinc.hh:461
int _optVar
Index of the variable to optimize.
Definition flatzinc.hh:444
BranchInformation branchInfo
Information for printing branches.
Definition flatzinc.hh:669
void run(std::ostream &out, const Printer &p, const FlatZincOptions &opt, Gecode::Support::Timer &t_total)
Run the search.
virtual Gecode::Space * copy(void)
Copy function.
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.
Definition flatzinc.hh:557
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).
Definition flatzinc.hh:446
FlatZincSpace(FlatZincSpace &)
Copy constructor.
Gecode::BoolVarArray bv
The Boolean variables.
Definition flatzinc.hh:559
void newSetVar(SetVarSpec *vs)
Create new set variable from specification.
bool optVarIsInt(void) const
Return whether variable used for optimization is integer (or float).
Gecode::SetVarArray on_restart_sv
On Restart Tracked Set Variables.
Definition flatzinc.hh:546
std::vector< bool > iv_introduced
Indicates whether an integer variable is introduced by mzn2fzn.
Definition flatzinc.hh:555
virtual bool slave(const MetaInfo &mi)
Slave function for restarts.
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).
Definition flatzinc.hh:433
std::vector< bool > sv_introduced
Indicates whether a set variable is introduced by mzn2fzn.
Definition flatzinc.hh:570
IntSet arg2intset(AST::Node *n)
Convert n to IntSet.
std::vector< bool > bv_introduced
Indicates whether a Boolean variable is introduced by mzn2fzn.
Definition flatzinc.hh:563
Gecode::FloatVarArray fv_aux
The introduced float variables.
Definition flatzinc.hh:576
void minimize(int var, bool isInt, AST::Array *annotation)
Post that integer variable var should be minimized.
IntArgs arg2boolargs(AST::Node *arg, int offset=0)
Convert arg (array of Booleans) to IntArgs.
Gecode::SetVarArray sv_aux
The introduced set variables.
Definition flatzinc.hh:568
int aliasBool2Int(int iv)
Return linked Boolean variable for integer variable iv.
int floatVarCount
Number of float variables.
Definition flatzinc.hh:439
int boolVarCount
Number of Boolean variables.
Definition flatzinc.hh:437
Gecode::SetVarArray sv
The set variables.
Definition flatzinc.hh:566
int setVarCount
Number of set variables.
Definition flatzinc.hh:441
Gecode::IntVarArray on_restart_iv
On Restart Tracked Integer Variables.
Definition flatzinc.hh:541
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.
Definition flatzinc.hh:580
IntSharedArray _lnsInitialSolution
Initial solution to start the LNS (or nullptr for no LNS).
Definition flatzinc.hh:455
Gecode::BoolVarArray bv_aux
The introduced Boolean variables.
Definition flatzinc.hh:561
IntSharedArray arg2intsharedarray(AST::Node *arg, int offset=0)
Convert arg (array of integers) to IntSharedArray.
virtual void constrain(const Space &s)
Implement optimization.
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.
Definition flatzinc.hh:484
Gecode::IntVarArray iv
The integer variables.
Definition flatzinc.hh:482
void init(int intVars, int boolVars, int setVars, int floatVars)
Initialize space with given number of variables.
Gecode::BoolVarArray on_restart_bv
On Restart Tracked Boolean Variables.
Definition flatzinc.hh:543
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.
Definition flatzinc.hh:449
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.
Definition flatzinc.hh:435
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.
FlatZincSpace(Rnd &random=defrnd)
Construct empty space.
FloatValArgs arg2floatargs(AST::Node *arg, int offset=0)
Convert n to FloatValArgs.
bool needAuxVars
Whether the introduced variables still need to be copied.
Definition flatzinc.hh:583
IntArgs arg2intargs(AST::Node *arg, int offset=0)
Convert arg (array of integers) to IntArgs.
Specification for floating point variables.
Definition varspec.hh:119
Specification for integer variables.
Definition varspec.hh:72
Output support class for FlatZinc interpreter.
Definition flatzinc.hh:107
const std::string & setVarName(int i) const
Definition flatzinc.hh:196
void addFloatVarName(const std::string &n)
void printDiff(std::ostream &out, const Gecode::IntVarArray &iv1, const Gecode::IntVarArray &iv2, const Gecode::BoolVarArray &bv1, const Gecode::BoolVarArray &bv2, const Gecode::SetVarArray &sv1, const Gecode::SetVarArray &sv2, const Gecode::FloatVarArray &fv1, const Gecode::FloatVarArray &fv2) const
void addSetVarName(const std::string &n)
void init(AST::Array *output)
const std::string & boolVarName(int i) const
Definition flatzinc.hh:189
void print(std::ostream &out, const Gecode::IntVarArray &iv, const Gecode::BoolVarArray &bv, const Gecode::SetVarArray &sv, const Gecode::FloatVarArray &fv) const
void shrinkArrays(Space &home, int &optVar, bool optVarIsInt, Gecode::IntVarArray &iv, Gecode::BoolVarArray &bv, Gecode::SetVarArray &sv, Gecode::FloatVarArray &fv)
const std::string & intVarName(int i) const
Definition flatzinc.hh:187
const std::string & floatVarName(int i) const
Definition flatzinc.hh:192
void addIntVarName(const std::string &n)
void addBoolVarName(const std::string &n)
void shrinkElement(AST::Node *node, std::map< int, int > &iv, std::map< int, int > &bv, std::map< int, int > &sv, std::map< int, int > &fv)
Specification for set variables.
Definition varspec.hh:139
Value description class for branching.
Definition float.hh:1469
Passing float arguments.
Definition float.hh:953
Passing float variables.
Definition float.hh:982
Float variable array.
Definition float.hh:1035
Float variables.
Definition float.hh:870
Passing integer arguments.
Definition int.hh:652
Integer sets.
Definition int.hh:178
static const IntSet empty
Empty set.
Definition int.hh:301
Passing integer variables.
Definition int.hh:680
Integer variable array.
Definition int.hh:791
Integer variables.
Definition int.hh:389
Information passed by meta search engines.
Definition core.hpp:1628
Random number generator.
Definition rnd.hpp:42
Passing set variables.
Definition set.hh:491
Set variable array
Definition set.hh:575
Set variables
Definition set.hh:127
SharedHandle(void)
Create shared handle with no object pointing to.
SharedHandle::Object * object(void) const
Access to the shared object.
Computation spaces.
Definition core.hpp:1775
struct Gecode::Space::@055132133326276162005044145100211202071356247106::@275070317317120154232063063134255170030071110047 p
Data only available during propagation or branching.
Class representing a set of tuples.
Definition int.hh:2382
#define GECODE_FLATZINC_EXPORT
Definition flatzinc.hh:75
ScriptMode
Different modes for executing scripts.
Definition driver.hh:94
RestartMode
Different modes for restart-based search.
Definition driver.hh:105
@ SM_STAT
Print statistics for script.
Definition driver.hh:97
@ SM_SOLUTION
Print solution and some statistics.
Definition driver.hh:95
@ SM_GIST
Run script in Gist.
Definition driver.hh:98
@ RM_CONSTANT
Restart with constant sequence.
Definition driver.hh:107
@ RM_LINEAR
Restart with linear sequence.
Definition driver.hh:108
@ RM_LUBY
Restart with Luby sequence.
Definition driver.hh:109
@ RM_NONE
No restarts.
Definition driver.hh:106
@ RM_GEOMETRIC
Restart with geometric sequence.
Definition driver.hh:110
double FloatNum
Floating point number base type.
Definition float.hh:106
IntPropLevel
Propagation levels for integer propagators.
Definition int.hh:1008
Space(void)
Default constructor.
Interpreter for the FlatZinc language.
GECODE_FLATZINC_EXPORT Rnd defrnd
Uninitialized default random number generator.
GECODE_FLATZINC_EXPORT FlatZincSpace * parse(const std::string &fileName, Printer &p, std::ostream &err=std::cerr, FlatZincSpace *fzs=nullptr, Rnd &rnd=defrnd)
Parse FlatZinc file fileName into fzs and return it.
Search engines
Gecode toplevel namespace
ArgArray< IntSet > IntSetArgs
Passing set arguments.
Definition int.hh:643
SharedArray< int > IntSharedArray
Arrays of integers that can be shared among several element constraints.
Definition int.hh:1512
#define GECODE_VTABLE_EXPORT
Definition support.hh:76