Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.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.org>
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.org
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
127 ,
128 const Gecode::SetVarArray& sv
129#endif
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
142 ,
143 const Gecode::SetVarArray& sv1,
144 const Gecode::SetVarArray& sv2
145#endif
147 ,
148 const Gecode::FloatVarArray& fv1,
149 const Gecode::FloatVarArray& fv2
150#endif
151 ) const;
152 public:
153 Printer(void) : _output(NULL) {}
154 void init(AST::Array* output);
155
156 void print(std::ostream& out,
157 const Gecode::IntVarArray& iv,
158 const Gecode::BoolVarArray& bv
160 ,
161 const Gecode::SetVarArray& sv
162#endif
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
173 ,
174 const Gecode::SetVarArray& sv1, const Gecode::SetVarArray& sv2
175#endif
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
199 void shrinkElement(AST::Node* node,
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,
208 ,
210#endif
212 ,
214#endif
215 );
216
217 private:
218 Printer(const Printer&);
219 Printer& operator=(const Printer&);
220 };
221
227 protected:
229
250
252
256
257#ifdef GECODE_HAS_CPPROFILER
258
262
263#endif
264
266 public:
268 FlatZincOptions(const char* s)
269 : Gecode::BaseOptions(s),
270 _solutions("n","number of solutions (0 = all, -1 = one/best)",-1),
271 _allSolutions("a", "return all solutions (equal to -n 0)"),
272 _threads("p","number of threads (0 = #processing units)",
273 Gecode::Search::Config::threads),
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),
283 _restart("restart","restart sequence type",RM_NONE),
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",
288 Search::Config::nogoods_limit),
289 _interrupt("interrupt","whether to catch Ctrl-C (true) or not (false)",
290 true),
291 _step("step","step distance for float optimization",0.0),
292 _mode("mode","how to execute script",Gecode::SM_SOLUTION),
293 _stat("s","emit statistics"),
294 _output("o","file to send output to")
295
296#ifdef GECODE_HAS_CPPROFILER
297 ,
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)
301
302#endif
303 {
304 _mode.add(Gecode::SM_SOLUTION, "solution");
305 _mode.add(Gecode::SM_STAT, "stat");
306 _mode.add(Gecode::SM_GIST, "gist");
307 _mode.add(Gecode::SM_CPPROFILER, "cpprofiler");
308 _restart.add(RM_NONE,"none");
309 _restart.add(RM_CONSTANT,"constant");
310 _restart.add(RM_LINEAR,"linear");
311 _restart.add(RM_LUBY,"luby");
312 _restart.add(RM_GEOMETRIC,"geometric");
313
316 add(_free);
317 add(_decay);
319 add(_seed);
320 add(_step);
323 add(_mode); add(_stat);
324 add(_output);
325#ifdef GECODE_HAS_CPPROFILER
329#endif
330 }
331
332 void parse(int& argc, char* argv[]) {
334 if (_allSolutions.value() && _solutions.value()==-1) {
335 _solutions.value(0);
336 }
337 if (_time_limit.value()) {
338 _time.value(_time_limit.value());
339 }
340 if (_stat.value())
341 _mode.value(Gecode::SM_STAT);
342 }
343
344 virtual void help(void) {
345 std::cerr << "Gecode FlatZinc interpreter" << std::endl
346 << " - Supported FlatZinc version: " << GECODE_FLATZINC_VERSION
347 << std::endl << std::endl;
349 }
350
351 int solutions(void) const { return _solutions.value(); }
352 bool allSolutions(void) const { return _allSolutions.value(); }
353 double threads(void) const { return _threads.value(); }
354 bool free(void) const { return _free.value(); }
355 unsigned int c_d(void) const { return _c_d.value(); }
356 unsigned int a_d(void) const { return _a_d.value(); }
357 unsigned int node(void) const { return _node.value(); }
358 unsigned int fail(void) const { return _fail.value(); }
359 unsigned int time(void) const { return _time.value(); }
360 int seed(void) const { return _seed.value(); }
361 double step(void) const { return _step.value(); }
362 const char* output(void) const { return _output.value(); }
363
365 return static_cast<Gecode::ScriptMode>(_mode.value());
366 }
367
368 double decay(void) const { return _decay.value(); }
369 RestartMode restart(void) const {
370 return static_cast<RestartMode>(_restart.value());
371 }
373 _restart.value(rm);
374 }
375 double restart_base(void) const { return _r_base.value(); }
376 void restart_base(double d) { _r_base.value(d); }
377 unsigned int restart_scale(void) const { return _r_scale.value(); }
378 void restart_scale(int i) { _r_scale.value(i); }
379 bool nogoods(void) const { return _nogoods.value(); }
380 unsigned int nogoods_limit(void) const { return _nogoods_limit.value(); }
381 bool interrupt(void) const { return _interrupt.value(); }
382
383#ifdef GECODE_HAS_CPPROFILER
384
385 int profiler_id(void) const { return _profiler_id.value(); }
386 unsigned int profiler_port(void) const { return _profiler_port.value(); }
387 bool profiler_info(void) const { return _profiler_info.value(); }
388
389#endif
390
391 void allSolutions(bool b) { _allSolutions.value(b); }
392 };
393
395 public:
397 BranchInformation(void);
401 void init(void);
403 void add(BrancherGroup bg,
404 const std::string& rel0,
405 const std::string& rel1,
406 const std::vector<std::string>& n);
408 void print(const Brancher& b,
409 unsigned int a, int i, int n, std::ostream& o) const;
410#ifdef GECODE_HAS_FLOAT_VARS
412 void print(const Brancher& b,
413 unsigned int a, int i, const FloatNumBranch& nl,
414 std::ostream& o) const;
415#endif
418 };
419
422 extern Rnd defrnd;
423
425
431 public:
432 enum Meth {
433 SAT, //< Solve as satisfaction problem
434 MIN, //< Solve as minimization problem
435 MAX //< Solve as maximization problem
436 };
437 protected:
448
453
456
458 unsigned int _lns;
459
462
465
468
471 private:
473 template<template<class> class Engine>
474 void
475 runEngine(std::ostream& out, const Printer& p,
476 const FlatZincOptions& opt, Gecode::Support::Timer& t_total);
478 template<template<class> class Engine,
479 template<class, template<class> class> class Meta>
480 void
481 runMeta(std::ostream& out, const Printer& p,
482 const FlatZincOptions& opt, Gecode::Support::Timer& t_total);
483 void
484 branchWithPlugin(AST::Node* ann);
485 public:
490
493
495 std::vector<bool> iv_introduced;
503 std::vector<bool> bv_introduced;
504#ifdef GECODE_HAS_SET_VARS
510 std::vector<bool> sv_introduced;
511#endif
512#ifdef GECODE_HAS_FLOAT_VARS
518 std::vector<bool> fv_introduced;
521#endif
525 FlatZincSpace(Rnd& random = defrnd);
526
528 ~FlatZincSpace(void);
529
531 void init(int intVars, int boolVars, int setVars, int floatVars);
532
534 void newIntVar(IntVarSpec* vs);
536 void aliasBool2Int(int iv, int bv);
538 int aliasBool2Int(int iv);
540 void newBoolVar(BoolVarSpec* vs);
542 void newSetVar(SetVarSpec* vs);
544 void newFloatVar(FloatVarSpec* vs);
545
547 void postConstraints(std::vector<ConExpr*>& ces);
548
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);
555
557 void run(std::ostream& out, const Printer& p,
558 const FlatZincOptions& opt, Gecode::Support::Timer& t_total);
559
561 void print(std::ostream& out, const Printer& p) const;
562#ifdef GECODE_HAS_CPPROFILER
564 std::string getDomains(const Printer& p) const;
565#endif
568 void compare(const Space& s, std::ostream& out) const;
571 void compare(const FlatZincSpace& s, std::ostream& out,
572 const Printer& p) const;
573
582 void shrinkArrays(Printer& p);
583
585 Meth method(void) const;
586
588 int optVar(void) const;
590 bool optVarIsInt(void) const;
591
601 void createBranchers(Printer& p, AST::Node* ann,
602 FlatZincOptions& opt, bool ignoreUnknown,
603 std::ostream& err = std::cerr);
604
606 AST::Array* solveAnnotations(void) const;
607
610
612 virtual void constrain(const Space& s);
614 virtual Gecode::Space* copy(void);
616 virtual bool slave(const MetaInfo& mi);
617
619
620
621 IntArgs arg2intargs(AST::Node* arg, int offset = 0);
623 IntSharedArray arg2intsharedarray(AST::Node* arg, int offset = 0);
625 IntArgs arg2boolargs(AST::Node* arg, int offset = 0);
627 IntSharedArray arg2boolsharedarray(AST::Node* arg, int offset = 0);
629 IntSet arg2intset(AST::Node* n);
631 IntSetArgs arg2intsetargs(AST::Node* arg, int offset = 0);
633 IntVarArgs arg2intvarargs(AST::Node* arg, int offset = 0);
635 BoolVarArgs arg2boolvarargs(AST::Node* arg, int offset = 0, int siv=-1);
637 BoolVar arg2BoolVar(AST::Node* n);
639 IntVar arg2IntVar(AST::Node* n);
641 TupleSet arg2tupleset(const IntArgs& a, int noOfVars);
643 bool isBoolArray(AST::Node* b, int& singleInt);
644#ifdef GECODE_HAS_SET_VARS
646 SetVar arg2SetVar(AST::Node* n);
648 SetVarArgs arg2setvarargs(AST::Node* arg, int offset = 0, int doffset = 0,
649 const IntSet& od=IntSet::empty);
650#endif
651#ifdef GECODE_HAS_FLOAT_VARS
653 FloatValArgs arg2floatargs(AST::Node* arg, int offset = 0);
655 FloatVar arg2FloatVar(AST::Node* n);
657 FloatVarArgs arg2floatvarargs(AST::Node* arg, int offset = 0);
658#endif
660 IntPropLevel ann2ipl(AST::Node* ann);
662 DFA getSharedDFA(DFA& a);
664 };
665
668 private:
669 const std::string msg;
670 public:
671 Error(const std::string& where, const std::string& what)
672 : msg(where+": "+what) {}
673 const std::string& toString(void) const { return msg; }
674 };
675
682 FlatZincSpace* parse(const std::string& fileName,
683 Printer& p, std::ostream& err = std::cerr,
684 FlatZincSpace* fzs=NULL, Rnd& rnd=defrnd);
685
692 FlatZincSpace* parse(std::istream& is,
693 Printer& p, std::ostream& err = std::cerr,
694 FlatZincSpace* fzs=NULL, Rnd& rnd=defrnd);
695
696}}
697
698#endif
699
700// STATISTICS: flatzinc-any
Base class for script options.
Definition driver.hh:331
BaseOptions(const char *s)
Initialize options for script with name s.
Definition options.cpp:483
void add(Driver::BaseOption &o)
Add new option o.
Definition options.cpp:474
virtual void help(void)
Print help text.
Definition options.cpp:494
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
Definition options.cpp:548
Passing Boolean variables.
Definition int.hh:721
Boolean variable array.
Definition int.hh:820
Boolean integer variables.
Definition int.hh:515
Group of branchers.
Definition core.hpp:799
Base-class for branchers.
Definition core.hpp:1444
Deterministic finite automaton (DFA)
Definition int.hh:2064
Boolean option.
Definition driver.hh:269
Integer option.
Definition driver.hh:209
String-valued option (integer value defined by strings)
Definition driver.hh:174
String-valued option.
Definition driver.hh:151
Unsigned integer option.
Definition driver.hh:229
A node in a FlatZinc abstract syntax tree.
Definition ast.hh:67
void init(void)
Initialise for use.
Definition flatzinc.cpp:315
void print(const Brancher &b, unsigned int a, int i, int n, std::ostream &o) const
Output branch information.
Definition flatzinc.cpp:328
BranchInformation & operator=(const BranchInformation &)=default
Assignment operator.
void add(BrancherGroup bg, const std::string &rel0, const std::string &rel1, const std::vector< std::string > &n)
Add new brancher information.
Definition flatzinc.cpp:321
Error(const std::string &where, const std::string &what)
Definition flatzinc.hh:671
const std::string & toString(void) const
Definition flatzinc.hh:673
Options for running FlatZinc models
Definition flatzinc.hh:226
Gecode::Driver::BoolOption _interrupt
Whether to catch SIGINT.
Definition flatzinc.hh:247
Gecode::Driver::BoolOption _nogoods
Whether to use no-goods.
Definition flatzinc.hh:245
Gecode::Driver::BoolOption _allSolutions
Return all solutions.
Definition flatzinc.hh:231
Gecode::Driver::BoolOption _stat
Emit statistics.
Definition flatzinc.hh:254
unsigned int time(void) const
Script mode to run.
Definition flatzinc.hh:359
void allSolutions(bool b)
Script mode to run.
Definition flatzinc.hh:391
bool allSolutions(void) const
Script mode to run.
Definition flatzinc.hh:352
unsigned int fail(void) const
Script mode to run.
Definition flatzinc.hh:358
Gecode::Driver::BoolOption _free
Use free search.
Definition flatzinc.hh:233
FlatZincOptions(const char *s)
Constructor.
Definition flatzinc.hh:268
int seed(void) const
Script mode to run.
Definition flatzinc.hh:360
double decay(void) const
Script mode to run.
Definition flatzinc.hh:368
Gecode::Driver::IntOption _profiler_id
Use this execution id for the CP-profiler.
Definition flatzinc.hh:259
unsigned int nogoods_limit(void) const
Script mode to run.
Definition flatzinc.hh:380
Gecode::Driver::UnsignedIntOption _nogoods_limit
Depth limit for extracting no-goods.
Definition flatzinc.hh:246
const char * output(void) const
Script mode to run.
Definition flatzinc.hh:362
RestartMode restart(void) const
Script mode to run.
Definition flatzinc.hh:369
Gecode::Driver::UnsignedIntOption _r_scale
Restart scale factor.
Definition flatzinc.hh:244
double restart_base(void) const
Script mode to run.
Definition flatzinc.hh:375
virtual void help(void)
Script mode to run.
Definition flatzinc.hh:344
int solutions(void) const
Script mode to run.
Definition flatzinc.hh:351
Gecode::Driver::UnsignedIntOption _time_limit
Cutoff for time (for compatibility with flatzinc command line)
Definition flatzinc.hh:240
Gecode::Driver::UnsignedIntOption _node
Cutoff for number of nodes.
Definition flatzinc.hh:237
bool nogoods(void) const
Script mode to run.
Definition flatzinc.hh:379
double step(void) const
Script mode to run.
Definition flatzinc.hh:361
Gecode::Driver::DoubleOption _step
Step option.
Definition flatzinc.hh:248
Gecode::ScriptMode mode(void) const
Script mode to run.
Definition flatzinc.hh:364
bool interrupt(void) const
Script mode to run.
Definition flatzinc.hh:381
Gecode::Driver::StringValueOption _output
Output file.
Definition flatzinc.hh:255
void parse(int &argc, char *argv[])
Script mode to run.
Definition flatzinc.hh:332
unsigned int profiler_port(void) const
Script mode to run.
Definition flatzinc.hh:386
Gecode::Driver::BoolOption _profiler_info
Whether solution information should be sent to the CP-profiler.
Definition flatzinc.hh:261
void restart(RestartMode rm)
Script mode to run.
Definition flatzinc.hh:372
Gecode::Driver::DoubleOption _r_base
Restart base.
Definition flatzinc.hh:243
Gecode::Driver::UnsignedIntOption _profiler_port
Connect to this port.
Definition flatzinc.hh:260
Gecode::Driver::UnsignedIntOption _c_d
Copy recomputation distance.
Definition flatzinc.hh:235
int profiler_id(void) const
Script mode to run.
Definition flatzinc.hh:385
void restart_scale(int i)
Script mode to run.
Definition flatzinc.hh:378
Gecode::Driver::StringOption _mode
Script mode to run.
Definition flatzinc.hh:253
unsigned int restart_scale(void) const
Script mode to run.
Definition flatzinc.hh:377
unsigned int a_d(void) const
Script mode to run.
Definition flatzinc.hh:356
unsigned int c_d(void) const
Script mode to run.
Definition flatzinc.hh:355
bool profiler_info(void) const
Script mode to run.
Definition flatzinc.hh:387
Gecode::Driver::UnsignedIntOption _a_d
Adaptive recomputation distance.
Definition flatzinc.hh:236
Gecode::Driver::UnsignedIntOption _fail
Cutoff for number of failures.
Definition flatzinc.hh:238
unsigned int node(void) const
Script mode to run.
Definition flatzinc.hh:357
bool free(void) const
Script mode to run.
Definition flatzinc.hh:354
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::DoubleOption _decay
Decay option.
Definition flatzinc.hh:234
double threads(void) const
Script mode to run.
Definition flatzinc.hh:353
Gecode::Driver::UnsignedIntOption _time
Cutoff for time.
Definition flatzinc.hh:239
Gecode::Driver::StringOption _restart
Restart method option.
Definition flatzinc.hh:242
void restart_base(double d)
Script mode to run.
Definition flatzinc.hh:376
A space that can be initialized with a FlatZinc model.
Definition flatzinc.hh:430
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:492
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)
Definition flatzinc.hh:458
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:514
Rnd _random
Random number generator.
Definition flatzinc.hh:464
void newBoolVar(BoolVarSpec *vs)
Create new Boolean variable from specification.
Definition flatzinc.cpp:908
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:518
AST::Array * _solveAnnotations
Annotations on the solve item.
Definition flatzinc.hh:467
int _optVar
Index of the variable to optimize.
Definition flatzinc.hh:450
BranchInformation branchInfo
Information for printing branches.
Definition flatzinc.hh:609
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.
Definition flatzinc.cpp:967
SetVar arg2SetVar(AST::Node *n)
Convert n to SetVar.
int * iv_boolalias
Indicates whether an integer variable aliases a Boolean variable.
Definition flatzinc.hh:497
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)
Definition flatzinc.hh:452
FlatZincSpace(FlatZincSpace &)
Copy constructor.
Definition flatzinc.cpp:774
Gecode::BoolVarArray bv
The Boolean variables.
Definition flatzinc.hh:499
void newSetVar(SetVarSpec *vs)
Create new set variable from specification.
Definition flatzinc.cpp:920
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.
Definition flatzinc.hh:495
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:439
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.
Definition flatzinc.hh:510
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:503
Gecode::FloatVarArray fv_aux
The introduced float variables.
Definition flatzinc.hh:516
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.
Definition flatzinc.hh:508
int floatVarCount
Number of float variables.
Definition flatzinc.hh:445
int boolVarCount
Number of Boolean variables.
Definition flatzinc.hh:443
Gecode::SetVarArray sv
The set variables.
Definition flatzinc.hh:506
int setVarCount
Number of set variables.
Definition flatzinc.hh:447
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:520
IntSharedArray _lnsInitialSolution
Initial solution to start the LNS (or NULL for no LNS)
Definition flatzinc.hh:461
Gecode::BoolVarArray bv_aux
The introduced Boolean variables.
Definition flatzinc.hh:501
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.
Definition flatzinc.cpp:899
AST::Array * solveAnnotations(void) const
Return the solve item annotations.
Gecode::IntVarArray iv_aux
The introduced integer variables.
Definition flatzinc.hh:489
Gecode::IntVarArray iv
The integer variables.
Definition flatzinc.hh:487
virtual Gecode::Space * copy(void)
Copy function.
void init(int intVars, int boolVars, int setVars, int floatVars)
Initialize space with given number of variables.
Definition flatzinc.cpp:856
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.
Definition flatzinc.cpp:881
Meth _method
Whether to solve as satisfaction or optimization problem.
Definition flatzinc.hh:455
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:441
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.
Definition flatzinc.hh:523
IntArgs arg2intargs(AST::Node *arg, int offset=0)
Convert arg (array of integers) to IntArgs.
Output support class for FlatZinc interpreter.
Definition flatzinc.hh:107
const std::string & setVarName(int i) const
Definition flatzinc.hh:196
const std::string & boolVarName(int i) const
Definition flatzinc.hh:189
const std::string & intVarName(int i) const
Definition flatzinc.hh:187
const std::string & floatVarName(int i) const
Definition flatzinc.hh:192
Value description class for branching.
Definition float.hh:1468
Passing float arguments.
Definition float.hh:953
Passing float variables.
Definition float.hh:982
Float variable array.
Definition float.hh:1033
Float variables.
Definition float.hh:870
Passing integer arguments.
Definition int.hh:634
Integer sets.
Definition int.hh:174
Passing integer variables.
Definition int.hh:662
Integer variable array.
Definition int.hh:772
Integer variables.
Definition int.hh:371
Random number generator.
Definition rnd.hpp:42
Passing set variables.
Definition set.hh:491
Set variable array
Definition set.hh:573
Set variables
Definition set.hh:127
SharedHandle(void)
Create shared handle with no object pointing to.
Computation spaces.
Definition core.hpp:1744
struct Gecode::Space::@055132133326276162005044145100211202071356247106::@275070317317120154232063063134255170030071110047 p
Data only available during propagation or branching.
Class represeting a set of tuples.
Definition int.hh:2206
#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:106
@ 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
@ SM_CPPROFILER
Run script with CP-profiler.
Definition driver.hh:99
@ RM_CONSTANT
Restart with constant sequence.
Definition driver.hh:108
@ RM_LINEAR
Restart with linear sequence.
Definition driver.hh:109
@ RM_LUBY
Restart with Luby sequence.
Definition driver.hh:110
@ RM_NONE
No restarts.
Definition driver.hh:107
@ RM_GEOMETRIC
Restart with geometric sequence.
Definition driver.hh:111
double FloatNum
Floating point number base type.
Definition float.hh:106
IntPropLevel
Propagation levels for integer propagators.
Definition int.hh:989
Space(void)
Default constructor.
Definition core.cpp:115
void print(const Search::Statistics &stat, bool restart)
Print statistics.
Definition job-shop.cpp:606
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.
Search engines
Gecode toplevel namespace
ArgArray< IntSet > IntSetArgs
Passing set arguments.
Definition int.hh:625
SharedArray< int > IntSharedArray
Arrays of integers that can be shared among several element constraints.
Definition int.hh:1492
#define GECODE_HAS_FLOAT_VARS
Definition config.hpp:35
#define GECODE_HAS_SET_VARS
Definition config.hpp:56
#define GECODE_FLATZINC_VERSION
Definition config.hpp:17
#define GECODE_VTABLE_EXPORT
Definition support.hh:72