Generated on Sun Mar 19 2017 08:30:25 for Gecode by doxygen 1.8.13
flatzinc.cpp
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  * Last modified:
14  * $Date: 2015-03-19 11:47:57 +0100 (Thu, 19 Mar 2015) $ by $Author: tack $
15  * $Revision: 14463 $
16  *
17  * This file is part of Gecode, the generic constraint
18  * development environment:
19  * http://www.gecode.org
20  *
21  * Permission is hereby granted, free of charge, to any person obtaining
22  * a copy of this software and associated documentation files (the
23  * "Software"), to deal in the Software without restriction, including
24  * without limitation the rights to use, copy, modify, merge, publish,
25  * distribute, sublicense, and/or sell copies of the Software, and to
26  * permit persons to whom the Software is furnished to do so, subject to
27  * the following conditions:
28  *
29  * The above copyright notice and this permission notice shall be
30  * included in all copies or substantial portions of the Software.
31  *
32  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
34  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
36  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
37  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
38  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39  *
40  */
41 
42 #include <gecode/flatzinc.hh>
45 
46 #include <gecode/search.hh>
47 
48 #include <vector>
49 #include <string>
50 #include <sstream>
51 #include <limits>
52 using namespace std;
53 
54 namespace Gecode { namespace FlatZinc {
55 
68  class AuxVarBrancher : public Brancher {
69  protected:
71  bool done;
74  IntValBranch int_valsel0,
75  TieBreak<IntVarBranch> bool_varsel0,
76  IntValBranch bool_valsel0
78  ,
79  SetVarBranch set_varsel0,
80  SetValBranch set_valsel0
81 #endif
83  ,
84  TieBreak<FloatVarBranch> float_varsel0,
85  FloatValBranch float_valsel0
86 #endif
87  )
88  : Brancher(home), done(false),
89  int_varsel(int_varsel0), int_valsel(int_valsel0),
90  bool_varsel(bool_varsel0), bool_valsel(bool_valsel0)
91 #ifdef GECODE_HAS_SET_VARS
92  , set_varsel(set_varsel0), set_valsel(set_valsel0)
93 #endif
94 #ifdef GECODE_HAS_FLOAT_VARS
95  , float_varsel(float_varsel0), float_valsel(float_valsel0)
96 #endif
97  {}
99  AuxVarBrancher(Space& home, bool share, AuxVarBrancher& b)
100  : Brancher(home, share, b), done(b.done) {}
101 
103  class Choice : public Gecode::Choice {
104  public:
106  bool fail;
108  Choice(const Brancher& b, bool fail0)
109  : Gecode::Choice(b,1), fail(fail0) {}
111  virtual size_t size(void) const {
112  return sizeof(Choice);
113  }
115  virtual void archive(Archive& e) const {
117  e.put(fail);
118  }
119  };
120 
125 #ifdef GECODE_HAS_SET_VARS
128 #endif
129 #ifdef GECODE_HAS_FLOAT_VARS
132 #endif
133 
134  public:
136  virtual bool status(const Space& _home) const {
137  if (done) return false;
138  const FlatZincSpace& home = static_cast<const FlatZincSpace&>(_home);
139  for (int i=0; i<home.iv_aux.size(); i++)
140  if (!home.iv_aux[i].assigned()) return true;
141  for (int i=0; i<home.bv_aux.size(); i++)
142  if (!home.bv_aux[i].assigned()) return true;
143 #ifdef GECODE_HAS_SET_VARS
144  for (int i=0; i<home.sv_aux.size(); i++)
145  if (!home.sv_aux[i].assigned()) return true;
146 #endif
147 #ifdef GECODE_HAS_FLOAT_VARS
148  for (int i=0; i<home.fv_aux.size(); i++)
149  if (!home.fv_aux[i].assigned()) return true;
150 #endif
151  // No non-assigned variables left
152  return false;
153  }
155  virtual Choice* choice(Space& home) {
156  done = true;
157  FlatZincSpace& fzs = static_cast<FlatZincSpace&>(*home.clone());
158  fzs.needAuxVars = false;
159  branch(fzs,fzs.iv_aux,int_varsel,int_valsel);
160  branch(fzs,fzs.bv_aux,bool_varsel,bool_valsel);
161 #ifdef GECODE_HAS_SET_VARS
162  branch(fzs,fzs.sv_aux,set_varsel,set_valsel);
163 #endif
164 #ifdef GECODE_HAS_FLOAT_VARS
165  branch(fzs,fzs.fv_aux,float_varsel,float_valsel);
166 #endif
167  Search::Options opt; opt.clone = false;
168  FlatZincSpace* sol = dfs(&fzs, opt);
169  if (sol) {
170  delete sol;
171  return new Choice(*this,false);
172  } else {
173  return new Choice(*this,true);
174  }
175  }
177  virtual Choice* choice(const Space&, Archive& e) {
178  bool fail; e >> fail;
179  return new Choice(*this, fail);
180  }
182  virtual ExecStatus commit(Space&, const Gecode::Choice& c, unsigned int) {
183  return static_cast<const Choice&>(c).fail ? ES_FAILED : ES_OK;
184  }
186  virtual void print(const Space&, const Gecode::Choice& c,
187  unsigned int,
188  std::ostream& o) const {
189  o << "FlatZinc("
190  << (static_cast<const Choice&>(c).fail ? "fail" : "ok")
191  << ")";
192  }
194  virtual Actor* copy(Space& home, bool share) {
195  return new (home) AuxVarBrancher(home, share, *this);
196  }
198  static void post(Home home,
199  TieBreak<IntVarBranch> int_varsel,
200  IntValBranch int_valsel,
201  TieBreak<IntVarBranch> bool_varsel,
202  IntValBranch bool_valsel
203 #ifdef GECODE_HAS_SET_VARS
204  ,
205  SetVarBranch set_varsel,
206  SetValBranch set_valsel
207 #endif
209  ,
210  TieBreak<FloatVarBranch> float_varsel,
211  FloatValBranch float_valsel
212 #endif
213  ) {
214  (void) new (home) AuxVarBrancher(home, int_varsel, int_valsel,
215  bool_varsel, bool_valsel
216 #ifdef GECODE_HAS_SET_VARS
217  , set_varsel, set_valsel
218 #endif
219 #ifdef GECODE_HAS_FLOAT_VARS
220  , float_varsel, float_valsel
221 #endif
222  );
223  }
225  virtual size_t dispose(Space&) {
226  return sizeof(*this);
227  }
228  };
229 
231  private:
232  struct BI {
233  string r0;
234  string r1;
235  vector<string> n;
236  BI(void) : r0(""), r1(""), n(0) {}
237  BI(const string& r00, const string& r10, const vector<string>& n0)
238  : r0(r00), r1(r10), n(n0) {}
239  };
240  vector<BI> v;
241  BranchInformationO(vector<BI> v0) : v(v0) {}
242  public:
244  virtual ~BranchInformationO(void) {}
245  virtual SharedHandle::Object* copy(void) const {
246  return new BranchInformationO(v);
247  }
249  void add(const BrancherHandle& bh,
250  const string& rel0,
251  const string& rel1,
252  const vector<string>& n) {
253  v.resize(std::max(static_cast<unsigned int>(v.size()),bh.id()+1));
254  v[bh.id()] = BI(rel0,rel1,n);
255  }
257  void print(const BrancherHandle& bh,
258  int a, int i, int n, ostream& o) const {
259  const BI& bi = v[bh.id()];
260  o << bi.n[i] << " " << (a==0 ? bi.r0 : bi.r1) << " " << n;
261  }
262 #ifdef GECODE_HAS_FLOAT_VARS
263  void print(const BrancherHandle& bh,
264  int a, int i, const FloatNumBranch& nl, ostream& o) const {
265  const BI& bi = v[bh.id()];
266  o << bi.n[i] << " "
267  << (((a == 0) == nl.l) ? "<=" : ">=") << nl.n;
268  }
269 #endif
270  };
271 
272  BranchInformation::BranchInformation(void)
273  : SharedHandle(NULL) {}
274 
276  : SharedHandle(bi) {}
277 
278  void
280  assert(object() == NULL);
281  object(new BranchInformationO());
282  }
283 
284  void
286  const std::string& rel0,
287  const std::string& rel1,
288  const std::vector<std::string>& n) {
289  static_cast<BranchInformationO*>(object())->add(bh,rel0,rel1,n);
290  }
291  void
293  int n, std::ostream& o) const {
294  static_cast<const BranchInformationO*>(object())->print(bh,a,i,n,o);
295  }
296 #ifdef GECODE_HAS_FLOAT_VARS
297  void
299  const FloatNumBranch& nl, std::ostream& o) const {
300  static_cast<const BranchInformationO*>(object())->print(bh,a,i,nl,o);
301  }
302 #endif
303  template<class Var>
304  void varValPrint(const Space &home, const BrancherHandle& bh,
305  unsigned int a,
306  Var, int i, const int& n,
307  std::ostream& o) {
308  static_cast<const FlatZincSpace&>(home).branchInfo.print(bh,a,i,n,o);
309  }
310 
311 #ifdef GECODE_HAS_FLOAT_VARS
312  void varValPrintF(const Space &home, const BrancherHandle& bh,
313  unsigned int a,
314  FloatVar, int i, const FloatNumBranch& nl,
315  std::ostream& o) {
316  static_cast<const FlatZincSpace&>(home).branchInfo.print(bh,a,i,nl,o);
317  }
318 #endif
319 
320  FznRnd::FznRnd(unsigned int s) : random(s) {}
321 
322  unsigned int
323  FznRnd::operator ()(unsigned int n) {
324  Support::Lock lock(mutex);
325  return random(n);
326  }
327 
329  if (vs->assigned) {
330  return IntSet(vs->i,vs->i);
331  }
332  if (vs->domain()) {
333  AST::SetLit* sl = vs->domain.some();
334  if (sl->interval) {
335  return IntSet(sl->min, sl->max);
336  } else {
337  int* newdom = heap.alloc<int>(static_cast<unsigned long int>(sl->s.size()));
338  for (int i=sl->s.size(); i--;)
339  newdom[i] = sl->s[i];
340  IntSet ret(newdom, sl->s.size());
341  heap.free(newdom, static_cast<unsigned long int>(sl->s.size()));
342  return ret;
343  }
344  }
346  }
347 
348  int vs2bsl(BoolVarSpec* bs) {
349  if (bs->assigned) {
350  return bs->i;
351  }
352  if (bs->domain()) {
353  AST::SetLit* sl = bs->domain.some();
354  assert(sl->interval);
355  return std::min(1, std::max(0, sl->min));
356  }
357  return 0;
358  }
359 
360  int vs2bsh(BoolVarSpec* bs) {
361  if (bs->assigned) {
362  return bs->i;
363  }
364  if (bs->domain()) {
365  AST::SetLit* sl = bs->domain.some();
366  assert(sl->interval);
367  return std::max(0, std::min(1, sl->max));
368  }
369  return 1;
370  }
371 
372  TieBreak<IntVarBranch> ann2ivarsel(AST::Node* ann, Rnd rnd, double decay) {
373  if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
374  if (s->id == "input_order")
376  if (s->id == "first_fail")
378  if (s->id == "anti_first_fail")
380  if (s->id == "smallest")
382  if (s->id == "largest")
384  if (s->id == "occurrence")
386  if (s->id == "max_regret")
388  if (s->id == "most_constrained")
391  if (s->id == "random") {
392  return TieBreak<IntVarBranch>(INT_VAR_RND(rnd));
393  }
394  if (s->id == "dom_w_deg") {
396  }
397  if (s->id == "afc_min")
399  if (s->id == "afc_max")
401  if (s->id == "afc_size_min")
403  if (s->id == "afc_size_max") {
405  }
406  if (s->id == "activity_min")
408  if (s->id == "activity_max")
410  if (s->id == "activity_size_min")
412  if (s->id == "activity_size_max")
414  }
415  std::cerr << "Warning, ignored search annotation: ";
416  ann->print(std::cerr);
417  std::cerr << std::endl;
419  }
420 
421  IntValBranch ann2ivalsel(AST::Node* ann, std::string& r0, std::string& r1,
422  Rnd rnd) {
423  if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
424  if (s->id == "indomain_min") {
425  r0 = "="; r1 = "!=";
426  return INT_VAL_MIN();
427  }
428  if (s->id == "indomain_max") {
429  r0 = "="; r1 = "!=";
430  return INT_VAL_MAX();
431  }
432  if (s->id == "indomain_median") {
433  r0 = "="; r1 = "!=";
434  return INT_VAL_MED();
435  }
436  if (s->id == "indomain_split") {
437  r0 = "<="; r1 = ">";
438  return INT_VAL_SPLIT_MIN();
439  }
440  if (s->id == "indomain_reverse_split") {
441  r0 = ">"; r1 = "<=";
442  return INT_VAL_SPLIT_MAX();
443  }
444  if (s->id == "indomain_random") {
445  r0 = "="; r1 = "!=";
446  return INT_VAL_RND(rnd);
447  }
448  if (s->id == "indomain") {
449  r0 = "="; r1 = "=";
450  return INT_VALUES_MIN();
451  }
452  if (s->id == "indomain_middle") {
453  std::cerr << "Warning, replacing unsupported annotation "
454  << "indomain_middle with indomain_median" << std::endl;
455  r0 = "="; r1 = "!=";
456  return INT_VAL_MED();
457  }
458  if (s->id == "indomain_interval") {
459  std::cerr << "Warning, replacing unsupported annotation "
460  << "indomain_interval with indomain_split" << std::endl;
461  r0 = "<="; r1 = ">";
462  return INT_VAL_SPLIT_MIN();
463  }
464  }
465  std::cerr << "Warning, ignored search annotation: ";
466  ann->print(std::cerr);
467  std::cerr << std::endl;
468  r0 = "="; r1 = "!=";
469  return INT_VAL_MIN();
470  }
471 
473  if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
474  if (s->id == "indomain_min")
475  return INT_ASSIGN_MIN();
476  if (s->id == "indomain_max")
477  return INT_ASSIGN_MAX();
478  if (s->id == "indomain_median")
479  return INT_ASSIGN_MED();
480  if (s->id == "indomain_random") {
481  return INT_ASSIGN_RND(rnd);
482  }
483  }
484  std::cerr << "Warning, ignored search annotation: ";
485  ann->print(std::cerr);
486  std::cerr << std::endl;
487  return INT_ASSIGN_MIN();
488  }
489 
490 #ifdef GECODE_HAS_SET_VARS
491  SetVarBranch ann2svarsel(AST::Node* ann, Rnd rnd, double decay) {
492  if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
493  if (s->id == "input_order")
494  return SET_VAR_NONE();
495  if (s->id == "first_fail")
496  return SET_VAR_SIZE_MIN();
497  if (s->id == "anti_first_fail")
498  return SET_VAR_SIZE_MAX();
499  if (s->id == "smallest")
500  return SET_VAR_MIN_MIN();
501  if (s->id == "largest")
502  return SET_VAR_MAX_MAX();
503  if (s->id == "afc_min")
504  return SET_VAR_AFC_MIN(decay);
505  if (s->id == "afc_max")
506  return SET_VAR_AFC_MAX(decay);
507  if (s->id == "afc_size_min")
508  return SET_VAR_AFC_SIZE_MIN(decay);
509  if (s->id == "afc_size_max")
510  return SET_VAR_AFC_SIZE_MAX(decay);
511  if (s->id == "activity_min")
512  return SET_VAR_ACTIVITY_MIN(decay);
513  if (s->id == "activity_max")
514  return SET_VAR_ACTIVITY_MAX(decay);
515  if (s->id == "activity_size_min")
516  return SET_VAR_ACTIVITY_SIZE_MIN(decay);
517  if (s->id == "activity_size_max")
518  return SET_VAR_ACTIVITY_SIZE_MAX(decay);
519  if (s->id == "random") {
520  return SET_VAR_RND(rnd);
521  }
522  }
523  std::cerr << "Warning, ignored search annotation: ";
524  ann->print(std::cerr);
525  std::cerr << std::endl;
526  return SET_VAR_NONE();
527  }
528 
529  SetValBranch ann2svalsel(AST::Node* ann, std::string r0, std::string r1,
530  Rnd rnd) {
531  (void) rnd;
532  if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
533  if (s->id == "indomain_min") {
534  r0 = "in"; r1 = "not in";
535  return SET_VAL_MIN_INC();
536  }
537  if (s->id == "indomain_max") {
538  r0 = "in"; r1 = "not in";
539  return SET_VAL_MAX_INC();
540  }
541  if (s->id == "outdomain_min") {
542  r1 = "in"; r0 = "not in";
543  return SET_VAL_MIN_EXC();
544  }
545  if (s->id == "outdomain_max") {
546  r1 = "in"; r0 = "not in";
547  return SET_VAL_MAX_EXC();
548  }
549  }
550  std::cerr << "Warning, ignored search annotation: ";
551  ann->print(std::cerr);
552  std::cerr << std::endl;
553  r0 = "in"; r1 = "not in";
554  return SET_VAL_MIN_INC();
555  }
556 #endif
557 
558 #ifdef GECODE_HAS_FLOAT_VARS
560  double decay) {
561  if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
562  if (s->id == "input_order")
564  if (s->id == "first_fail")
566  if (s->id == "anti_first_fail")
568  if (s->id == "smallest")
570  if (s->id == "largest")
572  if (s->id == "occurrence")
574  if (s->id == "most_constrained")
577  if (s->id == "random") {
579  }
580  if (s->id == "afc_min")
582  if (s->id == "afc_max")
584  if (s->id == "afc_size_min")
586  if (s->id == "afc_size_max")
588  if (s->id == "activity_min")
590  if (s->id == "activity_max")
592  if (s->id == "activity_size_min")
594  if (s->id == "activity_size_max")
596  }
597  std::cerr << "Warning, ignored search annotation: ";
598  ann->print(std::cerr);
599  std::cerr << std::endl;
601  }
602 
603  FloatValBranch ann2fvalsel(AST::Node* ann, std::string r0, std::string r1) {
604  if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
605  if (s->id == "indomain_split") {
606  r0 = "<="; r1 = ">";
607  return FLOAT_VAL_SPLIT_MIN();
608  }
609  if (s->id == "indomain_reverse_split") {
610  r1 = "<="; r0 = ">";
611  return FLOAT_VAL_SPLIT_MAX();
612  }
613  }
614  std::cerr << "Warning, ignored search annotation: ";
615  ann->print(std::cerr);
616  std::cerr << std::endl;
617  r0 = "<="; r1 = ">";
618  return FLOAT_VAL_SPLIT_MIN();
619  }
620 
621 #endif
622 
624  : Space(share, f), _random(f._random),
625  _solveAnnotations(NULL), iv_boolalias(NULL),
627  step(f.step),
628 #endif
629  needAuxVars(f.needAuxVars) {
630  _optVar = f._optVar;
632  _method = f._method;
633  _lns = f._lns;
634  branchInfo.update(*this, share, f.branchInfo);
635  iv.update(*this, share, f.iv);
636  iv_lns.update(*this, share, f.iv_lns);
638 
639  if (needAuxVars) {
640  IntVarArgs iva;
641  for (int i=0; i<f.iv_aux.size(); i++) {
642  if (!f.iv_aux[i].assigned()) {
643  iva << IntVar();
644  iva[iva.size()-1].update(*this, share, f.iv_aux[i]);
645  }
646  }
647  iv_aux = IntVarArray(*this, iva);
648  }
649 
650  bv.update(*this, share, f.bv);
652  if (needAuxVars) {
653  BoolVarArgs bva;
654  for (int i=0; i<f.bv_aux.size(); i++) {
655  if (!f.bv_aux[i].assigned()) {
656  bva << BoolVar();
657  bva[bva.size()-1].update(*this, share, f.bv_aux[i]);
658  }
659  }
660  bv_aux = BoolVarArray(*this, bva);
661  }
662 
663 #ifdef GECODE_HAS_SET_VARS
664  sv.update(*this, share, f.sv);
666  if (needAuxVars) {
667  SetVarArgs sva;
668  for (int i=0; i<f.sv_aux.size(); i++) {
669  if (!f.sv_aux[i].assigned()) {
670  sva << SetVar();
671  sva[sva.size()-1].update(*this, share, f.sv_aux[i]);
672  }
673  }
674  sv_aux = SetVarArray(*this, sva);
675  }
676 #endif
677 #ifdef GECODE_HAS_FLOAT_VARS
678  fv.update(*this, share, f.fv);
680  if (needAuxVars) {
681  FloatVarArgs fva;
682  for (int i=0; i<f.fv_aux.size(); i++) {
683  if (!f.fv_aux[i].assigned()) {
684  fva << FloatVar();
685  fva[fva.size()-1].update(*this, share, f.fv_aux[i]);
686  }
687  }
688  fv_aux = FloatVarArray(*this, fva);
689  }
690 #endif
691  }
692 
694  : intVarCount(-1), boolVarCount(-1), floatVarCount(-1), setVarCount(-1),
695  _optVar(-1), _optVarIsInt(true), _lns(0), _random(random),
696  _solveAnnotations(NULL), needAuxVars(true) {
697  branchInfo.init();
698  }
699 
700  void
701  FlatZincSpace::init(int intVars, int boolVars,
702  int setVars, int floatVars) {
703  (void) setVars;
704  (void) floatVars;
705 
706  intVarCount = 0;
707  iv = IntVarArray(*this, intVars);
708  iv_introduced = std::vector<bool>(2*intVars);
709  iv_boolalias = alloc<int>(intVars+(intVars==0?1:0));
710  boolVarCount = 0;
711  bv = BoolVarArray(*this, boolVars);
712  bv_introduced = std::vector<bool>(2*boolVars);
713 #ifdef GECODE_HAS_SET_VARS
714  setVarCount = 0;
715  sv = SetVarArray(*this, setVars);
716  sv_introduced = std::vector<bool>(2*setVars);
717 #endif
718 #ifdef GECODE_HAS_FLOAT_VARS
719  floatVarCount = 0;
720  fv = FloatVarArray(*this, floatVars);
721  fv_introduced = std::vector<bool>(2*floatVars);
722 #endif
723  }
724 
725  void
727  if (vs->alias) {
728  iv[intVarCount++] = iv[vs->i];
729  } else {
730  IntSet dom(vs2is(vs));
731  if (dom.size()==0) {
732  fail();
733  return;
734  } else {
735  iv[intVarCount++] = IntVar(*this, dom);
736  }
737  }
738  iv_introduced[2*(intVarCount-1)] = vs->introduced;
739  iv_introduced[2*(intVarCount-1)+1] = vs->funcDep;
740  iv_boolalias[intVarCount-1] = -1;
741  }
742 
743  void
745  iv_boolalias[iv] = bv;
746  }
747  int
749  return iv_boolalias[iv];
750  }
751 
752  void
754  if (vs->alias) {
755  bv[boolVarCount++] = bv[vs->i];
756  } else {
757  bv[boolVarCount++] = BoolVar(*this, vs2bsl(vs), vs2bsh(vs));
758  }
760  bv_introduced[2*(boolVarCount-1)+1] = vs->funcDep;
761  }
762 
763 #ifdef GECODE_HAS_SET_VARS
764  void
766  if (vs->alias) {
767  sv[setVarCount++] = sv[vs->i];
768  } else if (vs->assigned) {
769  assert(vs->upperBound());
770  AST::SetLit* vsv = vs->upperBound.some();
771  if (vsv->interval) {
772  IntSet d(vsv->min, vsv->max);
773  sv[setVarCount++] = SetVar(*this, d, d);
774  } else {
775  int* is = heap.alloc<int>(static_cast<unsigned long int>(vsv->s.size()));
776  for (int i=vsv->s.size(); i--; )
777  is[i] = vsv->s[i];
778  IntSet d(is, vsv->s.size());
779  heap.free(is,static_cast<unsigned long int>(vsv->s.size()));
780  sv[setVarCount++] = SetVar(*this, d, d);
781  }
782  } else if (vs->upperBound()) {
783  AST::SetLit* vsv = vs->upperBound.some();
784  if (vsv->interval) {
785  IntSet d(vsv->min, vsv->max);
786  sv[setVarCount++] = SetVar(*this, IntSet::empty, d);
787  } else {
788  int* is = heap.alloc<int>(static_cast<unsigned long int>(vsv->s.size()));
789  for (int i=vsv->s.size(); i--; )
790  is[i] = vsv->s[i];
791  IntSet d(is, vsv->s.size());
792  heap.free(is,static_cast<unsigned long int>(vsv->s.size()));
793  sv[setVarCount++] = SetVar(*this, IntSet::empty, d);
794  }
795  } else {
796  sv[setVarCount++] = SetVar(*this, IntSet::empty,
799  }
800  sv_introduced[2*(setVarCount-1)] = vs->introduced;
801  sv_introduced[2*(setVarCount-1)+1] = vs->funcDep;
802  }
803 #else
804  void
806  throw FlatZinc::Error("Gecode", "set variables not supported");
807  }
808 #endif
809 
810 #ifdef GECODE_HAS_FLOAT_VARS
811  void
813  if (vs->alias) {
814  fv[floatVarCount++] = fv[vs->i];
815  } else {
816  double dmin, dmax;
817  if (vs->domain()) {
818  dmin = vs->domain.some().first;
819  dmax = vs->domain.some().second;
820  if (dmin > dmax) {
821  fail();
822  return;
823  }
824  } else {
825  dmin = Float::Limits::min;
826  dmax = Float::Limits::max;
827  }
828  fv[floatVarCount++] = FloatVar(*this, dmin, dmax);
829  }
831  fv_introduced[2*(floatVarCount-1)+1] = vs->funcDep;
832  }
833 #else
834  void
836  throw FlatZinc::Error("Gecode", "float variables not supported");
837  }
838 #endif
839 
840  namespace {
841  struct ConExprOrder {
842  bool operator() (ConExpr* ce0, ConExpr* ce1) {
843  return ce0->args->a.size() < ce1->args->a.size();
844  }
845  };
846  }
847 
848  void
849  FlatZincSpace::postConstraints(std::vector<ConExpr*>& ces) {
850  ConExprOrder ceo;
851  std::sort(ces.begin(), ces.end(), ceo);
852 
853  for (unsigned int i=0; i<ces.size(); i++) {
854  const ConExpr& ce = *ces[i];
855  try {
856  registry().post(*this, ce);
857  } catch (Gecode::Exception& e) {
858  throw FlatZinc::Error("Gecode", e.what());
859  } catch (AST::TypeError& e) {
860  throw FlatZinc::Error("Type error", e.what());
861  }
862  delete ces[i];
863  ces[i] = NULL;
864  }
865  }
866 
867  void flattenAnnotations(AST::Array* ann, std::vector<AST::Node*>& out) {
868  for (unsigned int i=0; i<ann->a.size(); i++) {
869  if (ann->a[i]->isCall("seq_search")) {
870  AST::Call* c = ann->a[i]->getCall();
871  if (c->args->isArray())
872  flattenAnnotations(c->args->getArray(), out);
873  else
874  out.push_back(c->args);
875  } else {
876  out.push_back(ann->a[i]);
877  }
878  }
879  }
880 
881  void
882  FlatZincSpace::createBranchers(AST::Node* ann, int seed, double decay,
883  bool ignoreUnknown,
884  std::ostream& err) {
885  Rnd rnd(static_cast<unsigned int>(seed));
886  TieBreak<IntVarBranch> def_int_varsel = INT_VAR_AFC_SIZE_MAX(0.99);
887  IntValBranch def_int_valsel = INT_VAL_MIN();
888  TieBreak<IntVarBranch> def_bool_varsel = INT_VAR_AFC_MAX(0.99);
889  IntValBranch def_bool_valsel = INT_VAL_MIN();
890 #ifdef GECODE_HAS_SET_VARS
891  SetVarBranch def_set_varsel = SET_VAR_AFC_SIZE_MAX(0.99);
892  SetValBranch def_set_valsel = SET_VAL_MIN_INC();
893 #endif
894 #ifdef GECODE_HAS_FLOAT_VARS
895  TieBreak<FloatVarBranch> def_float_varsel = FLOAT_VAR_SIZE_MIN();
896  FloatValBranch def_float_valsel = FLOAT_VAL_SPLIT_MIN();
897 #endif
898 
899  std::vector<bool> iv_searched(iv.size());
900  for (unsigned int i=iv.size(); i--;)
901  iv_searched[i] = false;
902  std::vector<bool> bv_searched(bv.size());
903  for (unsigned int i=bv.size(); i--;)
904  bv_searched[i] = false;
905 #ifdef GECODE_HAS_SET_VARS
906  std::vector<bool> sv_searched(sv.size());
907  for (unsigned int i=sv.size(); i--;)
908  sv_searched[i] = false;
909 #endif
910 #ifdef GECODE_HAS_FLOAT_VARS
911  std::vector<bool> fv_searched(fv.size());
912  for (unsigned int i=fv.size(); i--;)
913  fv_searched[i] = false;
914 #endif
915 
916  _lns = 0;
917  if (ann) {
918  std::vector<AST::Node*> flatAnn;
919  if (ann->isArray()) {
920  flattenAnnotations(ann->getArray() , flatAnn);
921  } else {
922  flatAnn.push_back(ann);
923  }
924 
925  for (unsigned int i=0; i<flatAnn.size(); i++) {
926  if (flatAnn[i]->isCall("relax_and_reconstruct")) {
927  if (_lns != 0)
928  throw FlatZinc::Error("FlatZinc",
929  "Only one relax_and_reconstruct annotation allowed");
930  AST::Call *call = flatAnn[i]->getCall("relax_and_reconstruct");
931  AST::Array *args = call->getArgs(2);
932  _lns = args->a[1]->getInt();
933  AST::Array *vars = args->a[0]->getArray();
934  int k=vars->a.size();
935  for (int i=vars->a.size(); i--;)
936  if (vars->a[i]->isInt())
937  k--;
938  iv_lns = IntVarArray(*this, k);
939  k = 0;
940  for (unsigned int i=0; i<vars->a.size(); i++) {
941  if (vars->a[i]->isInt())
942  continue;
943  iv_lns[k++] = iv[vars->a[i]->getIntVar()];
944  }
945  } else if (flatAnn[i]->isCall("gecode_search")) {
946  AST::Call* c = flatAnn[i]->getCall();
947  branchWithPlugin(c->args);
948  } else if (flatAnn[i]->isCall("int_search")) {
949  AST::Call *call = flatAnn[i]->getCall("int_search");
950  AST::Array *args = call->getArgs(4);
951  AST::Array *vars = args->a[0]->getArray();
952  int k=vars->a.size();
953  for (int i=vars->a.size(); i--;)
954  if (vars->a[i]->isInt())
955  k--;
956  IntVarArgs va(k);
957  vector<string> names;
958  k=0;
959  for (unsigned int i=0; i<vars->a.size(); i++) {
960  if (vars->a[i]->isInt())
961  continue;
962  va[k++] = iv[vars->a[i]->getIntVar()];
963  iv_searched[vars->a[i]->getIntVar()] = true;
964  names.push_back(vars->a[i]->getVarName());
965  }
966  std::string r0, r1;
967  BrancherHandle bh = branch(*this, va,
968  ann2ivarsel(args->a[1],rnd,decay),
969  ann2ivalsel(args->a[2],r0,r1,rnd),
970  NULL,
971  &varValPrint<IntVar>);
972  branchInfo.add(bh,r0,r1,names);
973  } else if (flatAnn[i]->isCall("int_assign")) {
974  AST::Call *call = flatAnn[i]->getCall("int_assign");
975  AST::Array *args = call->getArgs(2);
976  AST::Array *vars = args->a[0]->getArray();
977  int k=vars->a.size();
978  for (int i=vars->a.size(); i--;)
979  if (vars->a[i]->isInt())
980  k--;
981  IntVarArgs va(k);
982  k=0;
983  for (unsigned int i=0; i<vars->a.size(); i++) {
984  if (vars->a[i]->isInt())
985  continue;
986  va[k++] = iv[vars->a[i]->getIntVar()];
987  iv_searched[vars->a[i]->getIntVar()] = true;
988  }
989  assign(*this, va, ann2asnivalsel(args->a[1],rnd), NULL,
990  &varValPrint<IntVar>);
991  } else if (flatAnn[i]->isCall("bool_search")) {
992  AST::Call *call = flatAnn[i]->getCall("bool_search");
993  AST::Array *args = call->getArgs(4);
994  AST::Array *vars = args->a[0]->getArray();
995  int k=vars->a.size();
996  for (int i=vars->a.size(); i--;)
997  if (vars->a[i]->isBool())
998  k--;
999  BoolVarArgs va(k);
1000  k=0;
1001  vector<string> names;
1002  for (unsigned int i=0; i<vars->a.size(); i++) {
1003  if (vars->a[i]->isBool())
1004  continue;
1005  va[k++] = bv[vars->a[i]->getBoolVar()];
1006  bv_searched[vars->a[i]->getBoolVar()] = true;
1007  names.push_back(vars->a[i]->getVarName());
1008  }
1009 
1010  std::string r0, r1;
1011  BrancherHandle bh = branch(*this, va,
1012  ann2ivarsel(args->a[1],rnd,decay),
1013  ann2ivalsel(args->a[2],r0,r1,rnd), NULL,
1014  &varValPrint<BoolVar>);
1015  branchInfo.add(bh,r0,r1,names);
1016  } else if (flatAnn[i]->isCall("int_default_search")) {
1017  AST::Call *call = flatAnn[i]->getCall("int_default_search");
1018  AST::Array *args = call->getArgs(2);
1019  def_int_varsel = ann2ivarsel(args->a[0],rnd,decay);
1020  std::string r0;
1021  def_int_valsel = ann2ivalsel(args->a[1],r0,r0,rnd);
1022  } else if (flatAnn[i]->isCall("bool_default_search")) {
1023  AST::Call *call = flatAnn[i]->getCall("bool_default_search");
1024  AST::Array *args = call->getArgs(2);
1025  def_bool_varsel = ann2ivarsel(args->a[0],rnd,decay);
1026  std::string r0;
1027  def_bool_valsel = ann2ivalsel(args->a[1],r0,r0,rnd);
1028  } else if (flatAnn[i]->isCall("set_search")) {
1029 #ifdef GECODE_HAS_SET_VARS
1030  AST::Call *call = flatAnn[i]->getCall("set_search");
1031  AST::Array *args = call->getArgs(4);
1032  AST::Array *vars = args->a[0]->getArray();
1033  int k=vars->a.size();
1034  for (int i=vars->a.size(); i--;)
1035  if (vars->a[i]->isSet())
1036  k--;
1037  SetVarArgs va(k);
1038  k=0;
1039  vector<string> names;
1040  for (unsigned int i=0; i<vars->a.size(); i++) {
1041  if (vars->a[i]->isSet())
1042  continue;
1043  va[k++] = sv[vars->a[i]->getSetVar()];
1044  sv_searched[vars->a[i]->getSetVar()] = true;
1045  names.push_back(vars->a[i]->getVarName());
1046  }
1047  std::string r0, r1;
1048  BrancherHandle bh = branch(*this, va,
1049  ann2svarsel(args->a[1],rnd,decay),
1050  ann2svalsel(args->a[2],r0,r1,rnd),
1051  NULL,
1052  &varValPrint<SetVar>);
1053  branchInfo.add(bh,r0,r1,names);
1054 #else
1055  if (!ignoreUnknown) {
1056  err << "Warning, ignored search annotation: ";
1057  flatAnn[i]->print(err);
1058  err << std::endl;
1059  }
1060 #endif
1061  } else if (flatAnn[i]->isCall("set_default_search")) {
1062 #ifdef GECODE_HAS_SET_VARS
1063  AST::Call *call = flatAnn[i]->getCall("set_default_search");
1064  AST::Array *args = call->getArgs(2);
1065  def_set_varsel = ann2svarsel(args->a[0],rnd,decay);
1066  std::string r0;
1067  def_set_valsel = ann2svalsel(args->a[1],r0,r0,rnd);
1068 #else
1069  if (!ignoreUnknown) {
1070  err << "Warning, ignored search annotation: ";
1071  flatAnn[i]->print(err);
1072  err << std::endl;
1073  }
1074 #endif
1075  } else if (flatAnn[i]->isCall("float_default_search")) {
1076 #ifdef GECODE_HAS_FLOAT_VARS
1077  AST::Call *call = flatAnn[i]->getCall("float_default_search");
1078  AST::Array *args = call->getArgs(2);
1079  def_float_varsel = ann2fvarsel(args->a[0],rnd,decay);
1080  std::string r0;
1081  def_float_valsel = ann2fvalsel(args->a[1],r0,r0);
1082 #else
1083  if (!ignoreUnknown) {
1084  err << "Warning, ignored search annotation: ";
1085  flatAnn[i]->print(err);
1086  err << std::endl;
1087  }
1088 #endif
1089  } else if (flatAnn[i]->isCall("float_search")) {
1090 #ifdef GECODE_HAS_FLOAT_VARS
1091  AST::Call *call = flatAnn[i]->getCall("float_search");
1092  AST::Array *args = call->getArgs(5);
1093  AST::Array *vars = args->a[0]->getArray();
1094  int k=vars->a.size();
1095  for (int i=vars->a.size(); i--;)
1096  if (vars->a[i]->isFloat())
1097  k--;
1098  FloatVarArgs va(k);
1099  k=0;
1100  vector<string> names;
1101  for (unsigned int i=0; i<vars->a.size(); i++) {
1102  if (vars->a[i]->isFloat())
1103  continue;
1104  va[k++] = fv[vars->a[i]->getFloatVar()];
1105  fv_searched[vars->a[i]->getFloatVar()] = true;
1106  names.push_back(vars->a[i]->getVarName());
1107  }
1108  std::string r0, r1;
1109  BrancherHandle bh = branch(*this, va,
1110  ann2fvarsel(args->a[2],rnd,decay),
1111  ann2fvalsel(args->a[3],r0,r1),
1112  NULL,
1113  &varValPrintF);
1114  branchInfo.add(bh,r0,r1,names);
1115 #else
1116  if (!ignoreUnknown) {
1117  err << "Warning, ignored search annotation: ";
1118  flatAnn[i]->print(err);
1119  err << std::endl;
1120  }
1121 #endif
1122  } else {
1123  if (!ignoreUnknown) {
1124  err << "Warning, ignored search annotation: ";
1125  flatAnn[i]->print(err);
1126  err << std::endl;
1127  }
1128  }
1129  }
1130  }
1131  int introduced = 0;
1132  int funcdep = 0;
1133  int searched = 0;
1134  for (int i=iv.size(); i--;) {
1135  if (iv_searched[i] || (_method != SAT && _optVarIsInt && _optVar==i)) {
1136  searched++;
1137  } else if (iv_introduced[2*i]) {
1138  if (iv_introduced[2*i+1]) {
1139  funcdep++;
1140  } else {
1141  introduced++;
1142  }
1143  }
1144  }
1145  IntVarArgs iv_sol(iv.size()-(introduced+funcdep+searched));
1146  IntVarArgs iv_tmp(introduced);
1147  for (int i=iv.size(), j=0, k=0; i--;) {
1148  if (iv_searched[i] || (_method != SAT && _optVarIsInt && _optVar==i))
1149  continue;
1150  if (iv_introduced[2*i]) {
1151  if (!iv_introduced[2*i+1]) {
1152  iv_tmp[j++] = iv[i];
1153  }
1154  } else {
1155  iv_sol[k++] = iv[i];
1156  }
1157  }
1158 
1159  introduced = 0;
1160  funcdep = 0;
1161  searched = 0;
1162  for (int i=bv.size(); i--;) {
1163  if (bv_searched[i]) {
1164  searched++;
1165  } else if (bv_introduced[2*i]) {
1166  if (bv_introduced[2*i+1]) {
1167  funcdep++;
1168  } else {
1169  introduced++;
1170  }
1171  }
1172  }
1173  BoolVarArgs bv_sol(bv.size()-(introduced+funcdep+searched));
1174  BoolVarArgs bv_tmp(introduced);
1175  for (int i=bv.size(), j=0, k=0; i--;) {
1176  if (bv_searched[i])
1177  continue;
1178  if (bv_introduced[2*i]) {
1179  if (!bv_introduced[2*i+1]) {
1180  bv_tmp[j++] = bv[i];
1181  }
1182  } else {
1183  bv_sol[k++] = bv[i];
1184  }
1185  }
1186 
1187  if (iv_sol.size() > 0) {
1188  branch(*this, iv_sol, def_int_varsel, def_int_valsel);
1189  }
1190  if (bv_sol.size() > 0)
1191  branch(*this, bv_sol, def_bool_varsel, def_bool_valsel);
1192 #ifdef GECODE_HAS_FLOAT_VARS
1193  introduced = 0;
1194  funcdep = 0;
1195  searched = 0;
1196  for (int i=fv.size(); i--;) {
1197  if (fv_searched[i] || (_method != SAT && !_optVarIsInt && _optVar==i)) {
1198  searched++;
1199  } else if (fv_introduced[2*i]) {
1200  if (fv_introduced[2*i+1]) {
1201  funcdep++;
1202  } else {
1203  introduced++;
1204  }
1205  }
1206  }
1207  FloatVarArgs fv_sol(fv.size()-(introduced+funcdep+searched));
1208  FloatVarArgs fv_tmp(introduced);
1209  for (int i=fv.size(), j=0, k=0; i--;) {
1210  if (fv_searched[i] || (_method != SAT && !_optVarIsInt && _optVar==i))
1211  continue;
1212  if (fv_introduced[2*i]) {
1213  if (!fv_introduced[2*i+1]) {
1214  fv_tmp[j++] = fv[i];
1215  }
1216  } else {
1217  fv_sol[k++] = fv[i];
1218  }
1219  }
1220 
1221  if (fv_sol.size() > 0)
1222  branch(*this, fv_sol, def_float_varsel, def_float_valsel);
1223 #endif
1224 #ifdef GECODE_HAS_SET_VARS
1225  introduced = 0;
1226  funcdep = 0;
1227  searched = 0;
1228  for (int i=sv.size(); i--;) {
1229  if (sv_searched[i]) {
1230  searched++;
1231  } else if (sv_introduced[2*i]) {
1232  if (sv_introduced[2*i+1]) {
1233  funcdep++;
1234  } else {
1235  introduced++;
1236  }
1237  }
1238  }
1239  SetVarArgs sv_sol(sv.size()-(introduced+funcdep+searched));
1240  SetVarArgs sv_tmp(introduced);
1241  for (int i=sv.size(), j=0, k=0; i--;) {
1242  if (sv_searched[i])
1243  continue;
1244  if (sv_introduced[2*i]) {
1245  if (!sv_introduced[2*i+1]) {
1246  sv_tmp[j++] = sv[i];
1247  }
1248  } else {
1249  sv_sol[k++] = sv[i];
1250  }
1251  }
1252 
1253  if (sv_sol.size() > 0)
1254  branch(*this, sv_sol, def_set_varsel, def_set_valsel);
1255 #endif
1256  iv_aux = IntVarArray(*this, iv_tmp);
1257  bv_aux = BoolVarArray(*this, bv_tmp);
1258  int n_aux = iv_aux.size() + bv_aux.size();
1259 #ifdef GECODE_HAS_SET_VARS
1260  sv_aux = SetVarArray(*this, sv_tmp);
1261  n_aux += sv_aux.size();
1262 #endif
1263 #ifdef GECODE_HAS_FLOAT_VARS
1264  fv_aux = FloatVarArray(*this, fv_tmp);
1265  n_aux += fv_aux.size();
1266 #endif
1267 
1268  if (_method == MIN) {
1269  if (_optVarIsInt) {
1270  branch(*this, iv[_optVar], INT_VAL_MIN());
1271  } else {
1272 #ifdef GECODE_HAS_FLOAT_VARS
1273  branch(*this, fv[_optVar], FLOAT_VAL_SPLIT_MIN());
1274 #endif
1275  }
1276  } else if (_method == MAX) {
1277  if (_optVarIsInt) {
1278  branch(*this, iv[_optVar], INT_VAL_MAX());
1279  } else {
1280 #ifdef GECODE_HAS_FLOAT_VARS
1281  branch(*this, fv[_optVar], FLOAT_VAL_SPLIT_MAX());
1282 #endif
1283  }
1284  }
1285 
1286  if (n_aux > 0) {
1287  if (_method == SAT) {
1288  AuxVarBrancher::post(*this, def_int_varsel, def_int_valsel,
1289  def_bool_varsel, def_bool_valsel
1290 #ifdef GECODE_HAS_SET_VARS
1291  , def_set_varsel, def_set_valsel
1292 #endif
1293 #ifdef GECODE_HAS_FLOAT_VARS
1294  , def_float_varsel, def_float_valsel
1295 #endif
1296  );
1297  } else {
1298  branch(*this,iv_aux,def_int_varsel,def_int_valsel);
1299  branch(*this,bv_aux,def_bool_varsel,def_bool_valsel);
1300  #ifdef GECODE_HAS_SET_VARS
1301  branch(*this,sv_aux,def_set_varsel,def_set_valsel);
1302  #endif
1303  #ifdef GECODE_HAS_FLOAT_VARS
1304  branch(*this,fv_aux,def_float_varsel,def_float_valsel);
1305  #endif
1306 
1307  }
1308  }
1309  }
1310 
1311  AST::Array*
1313  return _solveAnnotations;
1314  }
1315 
1316  void
1318  _method = SAT;
1319  _solveAnnotations = ann;
1320  }
1321 
1322  void
1323  FlatZincSpace::minimize(int var, bool isInt, AST::Array* ann) {
1324  _method = MIN;
1325  _optVar = var;
1326  _optVarIsInt = isInt;
1327  _solveAnnotations = ann;
1328  }
1329 
1330  void
1331  FlatZincSpace::maximize(int var, bool isInt, AST::Array* ann) {
1332  _method = MAX;
1333  _optVar = var;
1334  _optVarIsInt = isInt;
1335  _solveAnnotations = ann;
1336  }
1337 
1339  delete _solveAnnotations;
1340  }
1341 
1342 #ifdef GECODE_HAS_GIST
1343 
1347  template<class Engine>
1348  class GistEngine {
1349  };
1350 
1352  template<typename S>
1353  class GistEngine<DFS<S> > {
1354  public:
1355  static void explore(S* root, const FlatZincOptions& opt,
1358  o.c_d = opt.c_d(); o.a_d = opt.a_d();
1359  o.inspect.click(i);
1360  o.inspect.compare(c);
1361  (void) Gecode::Gist::dfs(root, o);
1362  }
1363  };
1364 
1366  template<typename S>
1367  class GistEngine<BAB<S> > {
1368  public:
1369  static void explore(S* root, const FlatZincOptions& opt,
1372  o.c_d = opt.c_d(); o.a_d = opt.a_d();
1373  o.inspect.click(i);
1374  o.inspect.compare(c);
1375  (void) Gecode::Gist::bab(root, o);
1376  }
1377  };
1378 
1380  template<class S>
1381  class FZPrintingInspector
1383  private:
1384  const Printer& p;
1385  public:
1387  FZPrintingInspector(const Printer& p0);
1389  virtual void inspect(const Space& node);
1391  virtual void finalize(void);
1392  };
1393 
1394  template<class S>
1395  FZPrintingInspector<S>::FZPrintingInspector(const Printer& p0)
1396  : TextOutput("Gecode/FlatZinc"), p(p0) {}
1397 
1398  template<class S>
1399  void
1400  FZPrintingInspector<S>::inspect(const Space& node) {
1401  init();
1402  dynamic_cast<const S&>(node).print(getStream(), p);
1403  getStream() << std::endl;
1404  }
1405 
1406  template<class S>
1407  void
1408  FZPrintingInspector<S>::finalize(void) {
1410  }
1411 
1412  template<class S>
1413  class FZPrintingComparator
1414  : public Gecode::Gist::VarComparator<S> {
1415  private:
1416  const Printer& p;
1417  public:
1419  FZPrintingComparator(const Printer& p0);
1420 
1422  virtual void compare(const Space& s0, const Space& s1);
1423  };
1424 
1425  template<class S>
1426  FZPrintingComparator<S>::FZPrintingComparator(const Printer& p0)
1427  : Gecode::Gist::VarComparator<S>("Gecode/FlatZinc"), p(p0) {}
1428 
1429  template<class S>
1430  void
1431  FZPrintingComparator<S>::compare(const Space& s0, const Space& s1) {
1432  this->init();
1433  try {
1434  dynamic_cast<const S&>(s0).compare(dynamic_cast<const S&>(s1),
1435  this->getStream(), p);
1436  } catch (Exception& e) {
1437  this->getStream() << "Exception: " << e.what();
1438  }
1439  this->getStream() << std::endl;
1440  }
1441 
1442 #endif
1443 
1444 
1445  template<template<class> class Engine>
1446  void
1447  FlatZincSpace::runEngine(std::ostream& out, const Printer& p,
1448  const FlatZincOptions& opt, Support::Timer& t_total) {
1449  if (opt.restart()==RM_NONE) {
1450  runMeta<Engine,Driver::EngineToMeta>(out,p,opt,t_total);
1451  } else {
1452  runMeta<Engine,RBS>(out,p,opt,t_total);
1453  }
1454  }
1455 
1456  template<template<class> class Engine,
1457  template<template<class> class,class> class Meta>
1458  void
1459  FlatZincSpace::runMeta(std::ostream& out, const Printer& p,
1460  const FlatZincOptions& opt, Support::Timer& t_total) {
1461 #ifdef GECODE_HAS_GIST
1462  if (opt.mode() == SM_GIST) {
1463  FZPrintingInspector<FlatZincSpace> pi(p);
1464  FZPrintingComparator<FlatZincSpace> pc(p);
1465  (void) GistEngine<Engine<FlatZincSpace> >::explore(this,opt,&pi,&pc);
1466  return;
1467  }
1468 #endif
1469  StatusStatistics sstat;
1470  unsigned int n_p = 0;
1471  Support::Timer t_solve;
1472  t_solve.start();
1473  if (status(sstat) != SS_FAILED) {
1474  n_p = propagators();
1475  }
1476  Search::Options o;
1477  o.stop = Driver::CombinedStop::create(opt.node(), opt.fail(), opt.time(),
1478  true);
1479  o.c_d = opt.c_d();
1480  o.a_d = opt.a_d();
1481 #ifdef GECODE_HAS_FLOAT_VARS
1482  step = opt.step();
1483 #endif
1484  o.threads = opt.threads();
1485  o.nogoods_limit = opt.nogoods() ? opt.nogoods_limit() : 0;
1486  o.cutoff = Driver::createCutoff(opt);
1487  if (opt.interrupt())
1489  Meta<Engine,FlatZincSpace> se(this,o);
1490  int noOfSolutions = opt.solutions();
1491  if (noOfSolutions == -1) {
1492  noOfSolutions = (_method == SAT) ? 1 : 0;
1493  }
1494  bool printAll = _method == SAT || opt.allSolutions() || noOfSolutions != 0;
1495  int findSol = noOfSolutions;
1496  FlatZincSpace* sol = NULL;
1497  while (FlatZincSpace* next_sol = se.next()) {
1498  delete sol;
1499  sol = next_sol;
1500  if (printAll) {
1501  sol->print(out, p);
1502  out << "----------" << std::endl;
1503  }
1504  if (--findSol==0)
1505  goto stopped;
1506  }
1507  if (sol && !printAll) {
1508  sol->print(out, p);
1509  out << "----------" << std::endl;
1510  }
1511  if (!se.stopped()) {
1512  if (sol) {
1513  out << "==========" << endl;
1514  } else {
1515  out << "=====UNSATISFIABLE=====" << endl;
1516  }
1517  } else if (!sol) {
1518  out << "=====UNKNOWN=====" << endl;
1519  }
1520  delete sol;
1521  stopped:
1522  if (opt.interrupt())
1524  if (opt.mode() == SM_STAT) {
1525  Gecode::Search::Statistics stat = se.statistics();
1526  out << endl
1527  << "%% runtime: ";
1528  Driver::stop(t_total,out);
1529  out << endl
1530  << "%% solvetime: ";
1531  Driver::stop(t_solve,out);
1532  out << endl
1533  << "%% solutions: "
1534  << std::abs(noOfSolutions - findSol) << endl
1535  << "%% variables: "
1536  << (intVarCount + boolVarCount + setVarCount) << endl
1537  << "%% propagators: " << n_p << endl
1538  << "%% propagations: " << sstat.propagate+stat.propagate << endl
1539  << "%% nodes: " << stat.node << endl
1540  << "%% failures: " << stat.fail << endl
1541  << "%% restarts: " << stat.restart << endl
1542  << "%% peak depth: " << stat.depth << endl
1543  << endl;
1544  }
1545  delete o.stop;
1546  }
1547 
1548 #ifdef GECODE_HAS_QT
1549  void
1550  FlatZincSpace::branchWithPlugin(AST::Node* ann) {
1551  if (AST::Call* c = dynamic_cast<AST::Call*>(ann)) {
1552  QString pluginName(c->id.c_str());
1553  if (QLibrary::isLibrary(pluginName+".dll")) {
1554  pluginName += ".dll";
1555  } else if (QLibrary::isLibrary(pluginName+".dylib")) {
1556  pluginName = "lib" + pluginName + ".dylib";
1557  } else if (QLibrary::isLibrary(pluginName+".so")) {
1558  // Must check .so after .dylib so that Mac OS uses .dylib
1559  pluginName = "lib" + pluginName + ".so";
1560  }
1561  QPluginLoader pl(pluginName);
1562  QObject* plugin_o = pl.instance();
1563  if (!plugin_o) {
1564  throw FlatZinc::Error("FlatZinc",
1565  "Error loading plugin "+pluginName.toStdString()+
1566  ": "+pl.errorString().toStdString());
1567  }
1568  BranchPlugin* pb = qobject_cast<BranchPlugin*>(plugin_o);
1569  if (!pb) {
1570  throw FlatZinc::Error("FlatZinc",
1571  "Error loading plugin "+pluginName.toStdString()+
1572  ": does not contain valid PluginBrancher");
1573  }
1574  pb->branch(*this, c);
1575  }
1576  }
1577 #else
1578  void
1579  FlatZincSpace::branchWithPlugin(AST::Node*) {
1580  throw FlatZinc::Error("FlatZinc",
1581  "Branching with plugins not supported (requires Qt support)");
1582  }
1583 #endif
1584 
1585  void
1586  FlatZincSpace::run(std::ostream& out, const Printer& p,
1587  const FlatZincOptions& opt, Support::Timer& t_total) {
1588  switch (_method) {
1589  case MIN:
1590  case MAX:
1591  runEngine<BAB>(out,p,opt,t_total);
1592  break;
1593  case SAT:
1594  runEngine<DFS>(out,p,opt,t_total);
1595  break;
1596  }
1597  }
1598 
1599  void
1601  if (_optVarIsInt) {
1602  if (_method == MIN)
1603  rel(*this, iv[_optVar], IRT_LE,
1604  static_cast<const FlatZincSpace*>(&s)->iv[_optVar].val());
1605  else if (_method == MAX)
1606  rel(*this, iv[_optVar], IRT_GR,
1607  static_cast<const FlatZincSpace*>(&s)->iv[_optVar].val());
1608  } else {
1609 #ifdef GECODE_HAS_FLOAT_VARS
1610  if (_method == MIN)
1611  rel(*this, fv[_optVar], FRT_LE,
1612  static_cast<const FlatZincSpace*>(&s)->fv[_optVar].val()-step);
1613  else if (_method == MAX)
1614  rel(*this, fv[_optVar], FRT_GR,
1615  static_cast<const FlatZincSpace*>(&s)->fv[_optVar].val()+step);
1616 #endif
1617  }
1618  }
1619 
1620  bool
1622  if (cri.restart() != 0 && _lns > 0 && cri.last()) {
1623  const FlatZincSpace& last = static_cast<const FlatZincSpace&>(*cri.last());
1624  for (unsigned int i=iv_lns.size(); i--;) {
1625  if ((*_random)(99) <= _lns) {
1626  rel(*this, iv_lns[i], IRT_EQ, last.iv_lns[i]);
1627  }
1628  }
1629  return false;
1630  }
1631  return true;
1632  }
1633 
1634  Space*
1635  FlatZincSpace::copy(bool share) {
1636  return new FlatZincSpace(share, *this);
1637  }
1638 
1641  return _method;
1642  }
1643 
1644  int
1646  return _optVar;
1647  }
1648 
1649  bool
1651  return _optVarIsInt;
1652  }
1653 
1654  void
1655  FlatZincSpace::print(std::ostream& out, const Printer& p) const {
1656  p.print(out, iv, bv
1657 #ifdef GECODE_HAS_SET_VARS
1658  , sv
1659 #endif
1660 #ifdef GECODE_HAS_FLOAT_VARS
1661  , fv
1662 #endif
1663  );
1664  }
1665 
1666  void
1667  FlatZincSpace::compare(const Space& s, std::ostream& out) const {
1668  (void) s; (void) out;
1669 #ifdef GECODE_HAS_GIST
1670  const FlatZincSpace& fs = dynamic_cast<const FlatZincSpace&>(s);
1671  for (int i = 0; i < iv.size(); ++i) {
1672  std::stringstream ss;
1673  ss << "iv[" << i << "]";
1674  std::string result(Gecode::Gist::Comparator::compare(ss.str(), iv[i],
1675  fs.iv[i]));
1676  if (result.length() > 0) out << result << std::endl;
1677  }
1678  for (int i = 0; i < bv.size(); ++i) {
1679  std::stringstream ss;
1680  ss << "bv[" << i << "]";
1681  std::string result(Gecode::Gist::Comparator::compare(ss.str(), bv[i],
1682  fs.bv[i]));
1683  if (result.length() > 0) out << result << std::endl;
1684  }
1685 #ifdef GECODE_HAS_SET_VARS
1686  for (int i = 0; i < sv.size(); ++i) {
1687  std::stringstream ss;
1688  ss << "sv[" << i << "]";
1689  std::string result(Gecode::Gist::Comparator::compare(ss.str(), sv[i],
1690  fs.sv[i]));
1691  if (result.length() > 0) out << result << std::endl;
1692  }
1693 #endif
1694 #ifdef GECODE_HAS_FLOAT_VARS
1695  for (int i = 0; i < fv.size(); ++i) {
1696  std::stringstream ss;
1697  ss << "fv[" << i << "]";
1698  std::string result(Gecode::Gist::Comparator::compare(ss.str(), fv[i],
1699  fs.fv[i]));
1700  if (result.length() > 0) out << result << std::endl;
1701  }
1702 #endif
1703 #endif
1704  }
1705 
1706  void
1707  FlatZincSpace::compare(const FlatZincSpace& s, std::ostream& out,
1708  const Printer& p) const {
1709  p.printDiff(out, iv, s.iv, bv, s.bv
1710 #ifdef GECODE_HAS_SET_VARS
1711  , sv, s.sv
1712 #endif
1713 #ifdef GECODE_HAS_FLOAT_VARS
1714  , fv, s.fv
1715 #endif
1716  );
1717  }
1718 
1719  void
1721  p.shrinkArrays(*this, _optVar, _optVarIsInt, iv, bv
1722 #ifdef GECODE_HAS_SET_VARS
1723  , sv
1724 #endif
1725 #ifdef GECODE_HAS_FLOAT_VARS
1726  , fv
1727 #endif
1728  );
1729  }
1730 
1731  IntArgs
1733  AST::Array* a = arg->getArray();
1734  IntArgs ia(a->a.size()+offset);
1735  for (int i=offset; i--;)
1736  ia[i] = 0;
1737  for (int i=a->a.size(); i--;)
1738  ia[i+offset] = a->a[i]->getInt();
1739  return ia;
1740  }
1741  IntArgs
1743  AST::Array* a = arg->getArray();
1744  IntArgs ia(a->a.size()+offset);
1745  for (int i=offset; i--;)
1746  ia[i] = 0;
1747  for (int i=a->a.size(); i--;)
1748  ia[i+offset] = a->a[i]->getBool();
1749  return ia;
1750  }
1751  IntSet
1753  AST::SetLit* sl = n->getSet();
1754  IntSet d;
1755  if (sl->interval) {
1756  d = IntSet(sl->min, sl->max);
1757  } else {
1758  Region re(*this);
1759  int* is = re.alloc<int>(static_cast<unsigned long int>(sl->s.size()));
1760  for (int i=sl->s.size(); i--; )
1761  is[i] = sl->s[i];
1762  d = IntSet(is, sl->s.size());
1763  }
1764  return d;
1765  }
1766  IntSetArgs
1768  AST::Array* a = arg->getArray();
1769  if (a->a.size() == 0) {
1770  IntSetArgs emptyIa(0);
1771  return emptyIa;
1772  }
1773  IntSetArgs ia(a->a.size()+offset);
1774  for (int i=offset; i--;)
1775  ia[i] = IntSet::empty;
1776  for (int i=a->a.size(); i--;) {
1777  ia[i+offset] = arg2intset(a->a[i]);
1778  }
1779  return ia;
1780  }
1781  IntVarArgs
1783  AST::Array* a = arg->getArray();
1784  if (a->a.size() == 0) {
1785  IntVarArgs emptyIa(0);
1786  return emptyIa;
1787  }
1788  IntVarArgs ia(a->a.size()+offset);
1789  for (int i=offset; i--;)
1790  ia[i] = IntVar(*this, 0, 0);
1791  for (int i=a->a.size(); i--;) {
1792  if (a->a[i]->isIntVar()) {
1793  ia[i+offset] = iv[a->a[i]->getIntVar()];
1794  } else {
1795  int value = a->a[i]->getInt();
1796  IntVar iv(*this, value, value);
1797  ia[i+offset] = iv;
1798  }
1799  }
1800  return ia;
1801  }
1802  BoolVarArgs
1803  FlatZincSpace::arg2boolvarargs(AST::Node* arg, int offset, int siv) {
1804  AST::Array* a = arg->getArray();
1805  if (a->a.size() == 0) {
1806  BoolVarArgs emptyIa(0);
1807  return emptyIa;
1808  }
1809  BoolVarArgs ia(a->a.size()+offset-(siv==-1?0:1));
1810  for (int i=offset; i--;)
1811  ia[i] = BoolVar(*this, 0, 0);
1812  for (int i=0; i<static_cast<int>(a->a.size()); i++) {
1813  if (i==siv)
1814  continue;
1815  if (a->a[i]->isBool()) {
1816  bool value = a->a[i]->getBool();
1817  BoolVar iv(*this, value, value);
1818  ia[offset++] = iv;
1819  } else if (a->a[i]->isIntVar() &&
1820  aliasBool2Int(a->a[i]->getIntVar()) != -1) {
1821  ia[offset++] = bv[aliasBool2Int(a->a[i]->getIntVar())];
1822  } else {
1823  ia[offset++] = bv[a->a[i]->getBoolVar()];
1824  }
1825  }
1826  return ia;
1827  }
1828  BoolVar
1830  BoolVar x0;
1831  if (n->isBool()) {
1832  x0 = BoolVar(*this, n->getBool(), n->getBool());
1833  }
1834  else {
1835  x0 = bv[n->getBoolVar()];
1836  }
1837  return x0;
1838  }
1839  IntVar
1841  IntVar x0;
1842  if (n->isIntVar()) {
1843  x0 = iv[n->getIntVar()];
1844  } else {
1845  x0 = IntVar(*this, n->getInt(), n->getInt());
1846  }
1847  return x0;
1848  }
1849  bool
1851  AST::Array* a = b->getArray();
1852  singleInt = -1;
1853  if (a->a.size() == 0)
1854  return true;
1855  for (int i=a->a.size(); i--;) {
1856  if (a->a[i]->isBoolVar() || a->a[i]->isBool()) {
1857  } else if (a->a[i]->isIntVar()) {
1858  if (aliasBool2Int(a->a[i]->getIntVar()) == -1) {
1859  if (singleInt != -1) {
1860  return false;
1861  }
1862  singleInt = i;
1863  }
1864  } else {
1865  return false;
1866  }
1867  }
1868  return singleInt==-1 || a->a.size() > 1;
1869  }
1870 #ifdef GECODE_HAS_SET_VARS
1871  SetVar
1873  SetVar x0;
1874  if (!n->isSetVar()) {
1875  IntSet d = arg2intset(n);
1876  x0 = SetVar(*this, d, d);
1877  } else {
1878  x0 = sv[n->getSetVar()];
1879  }
1880  return x0;
1881  }
1882  SetVarArgs
1883  FlatZincSpace::arg2setvarargs(AST::Node* arg, int offset, int doffset,
1884  const IntSet& od) {
1885  AST::Array* a = arg->getArray();
1886  SetVarArgs ia(a->a.size()+offset);
1887  for (int i=offset; i--;) {
1888  IntSet d = i<doffset ? od : IntSet::empty;
1889  ia[i] = SetVar(*this, d, d);
1890  }
1891  for (int i=a->a.size(); i--;) {
1892  ia[i+offset] = arg2SetVar(a->a[i]);
1893  }
1894  return ia;
1895  }
1896 #endif
1897 #ifdef GECODE_HAS_FLOAT_VARS
1898  FloatValArgs
1900  AST::Array* a = arg->getArray();
1901  FloatValArgs fa(a->a.size()+offset);
1902  for (int i=offset; i--;)
1903  fa[i] = 0.0;
1904  for (int i=a->a.size(); i--;)
1905  fa[i+offset] = a->a[i]->getFloat();
1906  return fa;
1907  }
1908  FloatVarArgs
1910  AST::Array* a = arg->getArray();
1911  if (a->a.size() == 0) {
1912  FloatVarArgs emptyFa(0);
1913  return emptyFa;
1914  }
1915  FloatVarArgs fa(a->a.size()+offset);
1916  for (int i=offset; i--;)
1917  fa[i] = FloatVar(*this, 0.0, 0.0);
1918  for (int i=a->a.size(); i--;) {
1919  if (a->a[i]->isFloatVar()) {
1920  fa[i+offset] = fv[a->a[i]->getFloatVar()];
1921  } else {
1922  double value = a->a[i]->getFloat();
1923  FloatVar fv(*this, value, value);
1924  fa[i+offset] = fv;
1925  }
1926  }
1927  return fa;
1928  }
1929  FloatVar
1931  FloatVar x0;
1932  if (n->isFloatVar()) {
1933  x0 = fv[n->getFloatVar()];
1934  } else {
1935  x0 = FloatVar(*this, n->getFloat(), n->getFloat());
1936  }
1937  return x0;
1938  }
1939 #endif
1940  IntConLevel
1942  if (ann) {
1943  if (ann->hasAtom("val"))
1944  return ICL_VAL;
1945  if (ann->hasAtom("domain"))
1946  return ICL_DOM;
1947  if (ann->hasAtom("bounds") ||
1948  ann->hasAtom("boundsR") ||
1949  ann->hasAtom("boundsD") ||
1950  ann->hasAtom("boundsZ"))
1951  return ICL_BND;
1952  }
1953  return ICL_DEF;
1954  }
1955 
1956 
1957  void
1959  _output = output;
1960  }
1961 
1962  void
1963  Printer::printElem(std::ostream& out,
1964  AST::Node* ai,
1965  const Gecode::IntVarArray& iv,
1966  const Gecode::BoolVarArray& bv
1967 #ifdef GECODE_HAS_SET_VARS
1968  , const Gecode::SetVarArray& sv
1969 #endif
1970 #ifdef GECODE_HAS_FLOAT_VARS
1971  ,
1972  const Gecode::FloatVarArray& fv
1973 #endif
1974  ) const {
1975  int k;
1976  if (ai->isInt(k)) {
1977  out << k;
1978  } else if (ai->isIntVar()) {
1979  out << iv[ai->getIntVar()];
1980  } else if (ai->isBoolVar()) {
1981  if (bv[ai->getBoolVar()].min() == 1) {
1982  out << "true";
1983  } else if (bv[ai->getBoolVar()].max() == 0) {
1984  out << "false";
1985  } else {
1986  out << "false..true";
1987  }
1988 #ifdef GECODE_HAS_SET_VARS
1989  } else if (ai->isSetVar()) {
1990  if (!sv[ai->getSetVar()].assigned()) {
1991  out << sv[ai->getSetVar()];
1992  return;
1993  }
1994  SetVarGlbRanges svr(sv[ai->getSetVar()]);
1995  if (!svr()) {
1996  out << "{}";
1997  return;
1998  }
1999  int min = svr.min();
2000  int max = svr.max();
2001  ++svr;
2002  if (svr()) {
2003  SetVarGlbValues svv(sv[ai->getSetVar()]);
2004  int i = svv.val();
2005  out << "{" << i;
2006  ++svv;
2007  for (; svv(); ++svv)
2008  out << ", " << svv.val();
2009  out << "}";
2010  } else {
2011  out << min << ".." << max;
2012  }
2013 #endif
2014 #ifdef GECODE_HAS_FLOAT_VARS
2015  } else if (ai->isFloatVar()) {
2016  if (fv[ai->getFloatVar()].assigned()) {
2017  FloatVal vv = fv[ai->getFloatVar()].val();
2018  FloatNum v;
2019  if (vv.singleton())
2020  v = vv.min();
2021  else if (vv < 0.0)
2022  v = vv.max();
2023  else
2024  v = vv.min();
2025  std::ostringstream oss;
2026  // oss << std::scientific;
2027  oss << std::setprecision(std::numeric_limits<double>::digits10);
2028  oss << v;
2029  if (oss.str().find(".") == std::string::npos)
2030  oss << ".0";
2031  out << oss.str();
2032  } else {
2033  out << fv[ai->getFloatVar()];
2034  }
2035 #endif
2036  } else if (ai->isBool()) {
2037  out << (ai->getBool() ? "true" : "false");
2038  } else if (ai->isSet()) {
2039  AST::SetLit* s = ai->getSet();
2040  if (s->interval) {
2041  out << s->min << ".." << s->max;
2042  } else {
2043  out << "{";
2044  for (unsigned int i=0; i<s->s.size(); i++) {
2045  out << s->s[i] << (i < s->s.size()-1 ? ", " : "}");
2046  }
2047  }
2048  } else if (ai->isString()) {
2049  std::string s = ai->getString();
2050  for (unsigned int i=0; i<s.size(); i++) {
2051  if (s[i] == '\\' && i<s.size()-1) {
2052  switch (s[i+1]) {
2053  case 'n': out << "\n"; break;
2054  case '\\': out << "\\"; break;
2055  case 't': out << "\t"; break;
2056  default: out << "\\" << s[i+1];
2057  }
2058  i++;
2059  } else {
2060  out << s[i];
2061  }
2062  }
2063  }
2064  }
2065 
2066  void
2067  Printer::printElemDiff(std::ostream& out,
2068  AST::Node* ai,
2069  const Gecode::IntVarArray& iv1,
2070  const Gecode::IntVarArray& iv2,
2071  const Gecode::BoolVarArray& bv1,
2072  const Gecode::BoolVarArray& bv2
2073 #ifdef GECODE_HAS_SET_VARS
2074  , const Gecode::SetVarArray& sv1,
2075  const Gecode::SetVarArray& sv2
2076 #endif
2077 #ifdef GECODE_HAS_FLOAT_VARS
2078  , const Gecode::FloatVarArray& fv1,
2079  const Gecode::FloatVarArray& fv2
2080 #endif
2081  ) const {
2082 #ifdef GECODE_HAS_GIST
2083  using namespace Gecode::Gist;
2084  int k;
2085  if (ai->isInt(k)) {
2086  out << k;
2087  } else if (ai->isIntVar()) {
2088  std::string res(Comparator::compare("",iv1[ai->getIntVar()],
2089  iv2[ai->getIntVar()]));
2090  if (res.length() > 0) {
2091  res.erase(0, 1); // Remove '='
2092  out << res;
2093  } else {
2094  out << iv1[ai->getIntVar()];
2095  }
2096  } else if (ai->isBoolVar()) {
2097  std::string res(Comparator::compare("",bv1[ai->getBoolVar()],
2098  bv2[ai->getBoolVar()]));
2099  if (res.length() > 0) {
2100  res.erase(0, 1); // Remove '='
2101  out << res;
2102  } else {
2103  out << bv1[ai->getBoolVar()];
2104  }
2105 #ifdef GECODE_HAS_SET_VARS
2106  } else if (ai->isSetVar()) {
2107  std::string res(Comparator::compare("",sv1[ai->getSetVar()],
2108  sv2[ai->getSetVar()]));
2109  if (res.length() > 0) {
2110  res.erase(0, 1); // Remove '='
2111  out << res;
2112  } else {
2113  out << sv1[ai->getSetVar()];
2114  }
2115 #endif
2116 #ifdef GECODE_HAS_FLOAT_VARS
2117  } else if (ai->isFloatVar()) {
2118  std::string res(Comparator::compare("",fv1[ai->getFloatVar()],
2119  fv2[ai->getFloatVar()]));
2120  if (res.length() > 0) {
2121  res.erase(0, 1); // Remove '='
2122  out << res;
2123  } else {
2124  out << fv1[ai->getFloatVar()];
2125  }
2126 #endif
2127  } else if (ai->isBool()) {
2128  out << (ai->getBool() ? "true" : "false");
2129  } else if (ai->isSet()) {
2130  AST::SetLit* s = ai->getSet();
2131  if (s->interval) {
2132  out << s->min << ".." << s->max;
2133  } else {
2134  out << "{";
2135  for (unsigned int i=0; i<s->s.size(); i++) {
2136  out << s->s[i] << (i < s->s.size()-1 ? ", " : "}");
2137  }
2138  }
2139  } else if (ai->isString()) {
2140  std::string s = ai->getString();
2141  for (unsigned int i=0; i<s.size(); i++) {
2142  if (s[i] == '\\' && i<s.size()-1) {
2143  switch (s[i+1]) {
2144  case 'n': out << "\n"; break;
2145  case '\\': out << "\\"; break;
2146  case 't': out << "\t"; break;
2147  default: out << "\\" << s[i+1];
2148  }
2149  i++;
2150  } else {
2151  out << s[i];
2152  }
2153  }
2154  }
2155 #else
2156  (void) out;
2157  (void) ai;
2158  (void) iv1;
2159  (void) iv2;
2160  (void) bv1;
2161  (void) bv2;
2162 #ifdef GECODE_HAS_SET_VARS
2163  (void) sv1;
2164  (void) sv2;
2165 #endif
2166 #ifdef GECODE_HAS_FLOAT_VARS
2167  (void) fv1;
2168  (void) fv2;
2169 #endif
2170 
2171 #endif
2172  }
2173 
2174  void
2175  Printer::print(std::ostream& out,
2176  const Gecode::IntVarArray& iv,
2177  const Gecode::BoolVarArray& bv
2178 #ifdef GECODE_HAS_SET_VARS
2179  ,
2180  const Gecode::SetVarArray& sv
2181 #endif
2182 #ifdef GECODE_HAS_FLOAT_VARS
2183  ,
2184  const Gecode::FloatVarArray& fv
2185 #endif
2186  ) const {
2187  if (_output == NULL)
2188  return;
2189  for (unsigned int i=0; i< _output->a.size(); i++) {
2190  AST::Node* ai = _output->a[i];
2191  if (ai->isArray()) {
2192  AST::Array* aia = ai->getArray();
2193  int size = aia->a.size();
2194  out << "[";
2195  for (int j=0; j<size; j++) {
2196  printElem(out,aia->a[j],iv,bv
2197 #ifdef GECODE_HAS_SET_VARS
2198  ,sv
2199 #endif
2200 #ifdef GECODE_HAS_FLOAT_VARS
2201  ,fv
2202 #endif
2203  );
2204  if (j<size-1)
2205  out << ", ";
2206  }
2207  out << "]";
2208  } else {
2209  printElem(out,ai,iv,bv
2210 #ifdef GECODE_HAS_SET_VARS
2211  ,sv
2212 #endif
2213 #ifdef GECODE_HAS_FLOAT_VARS
2214  ,fv
2215 #endif
2216  );
2217  }
2218  }
2219  }
2220 
2221  void
2222  Printer::printDiff(std::ostream& out,
2223  const Gecode::IntVarArray& iv1,
2224  const Gecode::IntVarArray& iv2,
2225  const Gecode::BoolVarArray& bv1,
2226  const Gecode::BoolVarArray& bv2
2227 #ifdef GECODE_HAS_SET_VARS
2228  ,
2229  const Gecode::SetVarArray& sv1,
2230  const Gecode::SetVarArray& sv2
2231 #endif
2232 #ifdef GECODE_HAS_FLOAT_VARS
2233  ,
2234  const Gecode::FloatVarArray& fv1,
2235  const Gecode::FloatVarArray& fv2
2236 #endif
2237  ) const {
2238  if (_output == NULL)
2239  return;
2240  for (unsigned int i=0; i< _output->a.size(); i++) {
2241  AST::Node* ai = _output->a[i];
2242  if (ai->isArray()) {
2243  AST::Array* aia = ai->getArray();
2244  int size = aia->a.size();
2245  out << "[";
2246  for (int j=0; j<size; j++) {
2247  printElemDiff(out,aia->a[j],iv1,iv2,bv1,bv2
2248 #ifdef GECODE_HAS_SET_VARS
2249  ,sv1,sv2
2250 #endif
2251 #ifdef GECODE_HAS_FLOAT_VARS
2252  ,fv1,fv2
2253 #endif
2254  );
2255  if (j<size-1)
2256  out << ", ";
2257  }
2258  out << "]";
2259  } else {
2260  printElemDiff(out,ai,iv1,iv2,bv1,bv2
2261 #ifdef GECODE_HAS_SET_VARS
2262  ,sv1,sv2
2263 #endif
2264 #ifdef GECODE_HAS_FLOAT_VARS
2265  ,fv1,fv2
2266 #endif
2267  );
2268  }
2269  }
2270  }
2271 
2272  void
2274  std::map<int,int>& iv, std::map<int,int>& bv,
2275  std::map<int,int>& sv, std::map<int,int>& fv) {
2276  if (node->isIntVar()) {
2277  AST::IntVar* x = static_cast<AST::IntVar*>(node);
2278  if (iv.find(x->i) == iv.end()) {
2279  int newi = iv.size();
2280  iv[x->i] = newi;
2281  }
2282  x->i = iv[x->i];
2283  } else if (node->isBoolVar()) {
2284  AST::BoolVar* x = static_cast<AST::BoolVar*>(node);
2285  if (bv.find(x->i) == bv.end()) {
2286  int newi = bv.size();
2287  bv[x->i] = newi;
2288  }
2289  x->i = bv[x->i];
2290  } else if (node->isSetVar()) {
2291  AST::SetVar* x = static_cast<AST::SetVar*>(node);
2292  if (sv.find(x->i) == sv.end()) {
2293  int newi = sv.size();
2294  sv[x->i] = newi;
2295  }
2296  x->i = sv[x->i];
2297  } else if (node->isFloatVar()) {
2298  AST::FloatVar* x = static_cast<AST::FloatVar*>(node);
2299  if (fv.find(x->i) == fv.end()) {
2300  int newi = fv.size();
2301  fv[x->i] = newi;
2302  }
2303  x->i = fv[x->i];
2304  }
2305  }
2306 
2307  void
2309  int& optVar, bool optVarIsInt,
2310  Gecode::IntVarArray& iv,
2312 #ifdef GECODE_HAS_SET_VARS
2313  ,
2315 #endif
2316 #ifdef GECODE_HAS_FLOAT_VARS
2317  ,
2319 #endif
2320  ) {
2321  if (_output == NULL) {
2322  if (optVarIsInt && optVar != -1) {
2323  IntVar ov = iv[optVar];
2324  iv = IntVarArray(home, 1);
2325  iv[0] = ov;
2326  optVar = 0;
2327  } else {
2328  iv = IntVarArray(home, 0);
2329  }
2330  bv = BoolVarArray(home, 0);
2331 #ifdef GECODE_HAS_SET_VARS
2332  sv = SetVarArray(home, 0);
2333 #endif
2334 #ifdef GECODE_HAS_FLOAT_VARS
2335  if (!optVarIsInt && optVar != -1) {
2336  FloatVar ov = fv[optVar];
2337  fv = FloatVarArray(home, 1);
2338  fv[0] = ov;
2339  optVar = 0;
2340  } else {
2341  fv = FloatVarArray(home,0);
2342  }
2343 #endif
2344  return;
2345  }
2346  std::map<int,int> iv_new;
2347  std::map<int,int> bv_new;
2348  std::map<int,int> sv_new;
2349  std::map<int,int> fv_new;
2350 
2351  if (optVar != -1) {
2352  if (optVarIsInt)
2353  iv_new[optVar] = 0;
2354  else
2355  fv_new[optVar] = 0;
2356  optVar = 0;
2357  }
2358 
2359  for (unsigned int i=0; i< _output->a.size(); i++) {
2360  AST::Node* ai = _output->a[i];
2361  if (ai->isArray()) {
2362  AST::Array* aia = ai->getArray();
2363  for (unsigned int j=0; j<aia->a.size(); j++) {
2364  shrinkElement(aia->a[j],iv_new,bv_new,sv_new,fv_new);
2365  }
2366  } else {
2367  shrinkElement(ai,iv_new,bv_new,sv_new,fv_new);
2368  }
2369  }
2370 
2371  IntVarArgs iva(iv_new.size());
2372  for (map<int,int>::iterator i=iv_new.begin(); i != iv_new.end(); ++i) {
2373  iva[(*i).second] = iv[(*i).first];
2374  }
2375  iv = IntVarArray(home, iva);
2376 
2377  BoolVarArgs bva(bv_new.size());
2378  for (map<int,int>::iterator i=bv_new.begin(); i != bv_new.end(); ++i) {
2379  bva[(*i).second] = bv[(*i).first];
2380  }
2381  bv = BoolVarArray(home, bva);
2382 
2383 #ifdef GECODE_HAS_SET_VARS
2384  SetVarArgs sva(sv_new.size());
2385  for (map<int,int>::iterator i=sv_new.begin(); i != sv_new.end(); ++i) {
2386  sva[(*i).second] = sv[(*i).first];
2387  }
2388  sv = SetVarArray(home, sva);
2389 #endif
2390 
2391 #ifdef GECODE_HAS_FLOAT_VARS
2392  FloatVarArgs fva(fv_new.size());
2393  for (map<int,int>::iterator i=fv_new.begin(); i != fv_new.end(); ++i) {
2394  fva[(*i).second] = fv[(*i).first];
2395  }
2396  fv = FloatVarArray(home, fva);
2397 #endif
2398  }
2399 
2401  delete _output;
2402  }
2403 
2404 }}
2405 
2406 // STATISTICS: flatzinc-any
void click(Inspector *i)
Add inspector that reacts on node double clicks.
Definition: gist.hpp:174
SetVarBranch SET_VAR_SIZE_MIN(BranchTbl tbl)
Select variable with smallest unknown set.
Definition: var.hpp:183
void shrinkArrays(Printer &p)
Remove all variables not needed for output.
Definition: flatzinc.cpp:1720
static void post(Home home, TieBreak< IntVarBranch > int_varsel, IntValBranch int_valsel, TieBreak< IntVarBranch > bool_varsel, IntValBranch bool_valsel, SetVarBranch set_varsel, SetValBranch set_valsel, TieBreak< FloatVarBranch > float_varsel, FloatValBranch float_valsel)
Post brancher.
Definition: flatzinc.cpp:198
unsigned int a_d
Create a clone during recomputation if distance is greater than a_d (adaptive distance) ...
Definition: search.hh:458
Which values to select for branching first.
Definition: set.hh:1382
Gecode::SetVarArray sv_aux
The introduced set variables.
Definition: flatzinc.hh:448
SetVarBranch SET_VAR_AFC_MIN(double d, BranchTbl tbl)
Select variable with smallest accumulated failure count with decay factor d.
Definition: var.hpp:123
unsigned int propagators(void) const
Return number of propagators.
Definition: core.cpp:196
const Space * last(void) const
Return last solution found (possibly NULL)
Definition: core.hpp:2721
int floatVarCount
Number of float variables.
Definition: flatzinc.hh:388
const Gecode::FloatNum step
Definition: arithmetic.cpp:789
Passing float arguments.
Definition: float.hh:937
void varValPrintF(const Space &home, const BrancherHandle &bh, unsigned int a, FloatVar, int i, const FloatNumBranch &nl, std::ostream &o)
Definition: flatzinc.cpp:312
Option< AST::SetLit *> domain
Definition: varspec.hh:78
Options for running FlatZinc models
Definition: flatzinc.hh:205
FloatVarBranch FLOAT_VAR_DEGREE_MAX(BranchTbl tbl)
Select variable with largest degree.
Definition: var.hpp:119
unsigned int nogoods_limit
Depth limit for extraction of no-goods.
Definition: search.hh:460
virtual Choice * choice(Space &home)
Return choice.
Definition: flatzinc.cpp:155
IntVarBranch INT_VAR_NONE(void)
Select first unassigned variable.
Definition: var.hpp:108
RestartMode restart(void) const
Definition: flatzinc.hh:319
Combine variable selection criteria for tie-breaking.
IntSet vs2is(IntVarSpec *vs)
Definition: flatzinc.cpp:328
virtual void print(const Space &, const Gecode::Choice &c, unsigned int, std::ostream &o) const
Print explanation.
Definition: flatzinc.cpp:186
Gecode::Support::RandomGenerator random
The actual random number generator.
Definition: flatzinc.hh:361
Which values to select for branching first.
Definition: float.hh:1646
IntConLevel
Consistency levels for integer propagators.
Definition: int.hh:937
The shared handle.
Definition: core.hpp:79
IntArgs arg2intargs(AST::Node *arg, int offset=0)
Convert arg (array of integers) to IntArgs.
Definition: flatzinc.cpp:1732
void post(FlatZincSpace &s, const ConExpr &ce)
Post constraint specified by ce.
Definition: registry.cpp:63
FloatValBranch FLOAT_VAL_SPLIT_MAX(void)
Select values greater than mean of smallest and largest value.
Definition: val.hpp:64
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1662
SetVarBranch SET_VAR_NONE(void)
Select first unassigned variable.
Definition: var.hpp:91
void createBranchers(AST::Node *ann, int seed, double decay, bool ignoreUnknown, std::ostream &err=std::cerr)
Create branchers corresponding to the solve item annotations.
Definition: flatzinc.cpp:882
Search engine statistics
Definition: search.hh:136
Boolean variable node.
Definition: ast.hh:201
const int min
Smallest allowed integer in integer set.
Definition: set.hh:101
FloatVarArgs arg2floatvarargs(AST::Node *arg, int offset=0)
Convert n to FloatVarArgs.
Definition: flatzinc.cpp:1909
bool isBool(void)
Test if node is a Boolean node.
Definition: ast.hh:494
virtual Gecode::Space * copy(bool share)
Copy function.
Definition: flatzinc.cpp:1635
std::vector< bool > sv_introduced
Indicates whether a set variable is introduced by mzn2fzn.
Definition: flatzinc.hh:450
bool getBool(void)
Cast this node to a Boolean node.
Definition: ast.hh:450
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:985
const FloatNum max
Largest allowed float value.
Definition: float.hh:831
#define GECODE_HAS_SET_VARS
Definition: config.hpp:44
Gecode::BoolVarArray bv
The Boolean variables.
Definition: flatzinc.hh:439
void put(unsigned int i)
Add i to the contents.
Definition: archive.hpp:177
Meth _method
Whether to solve as satisfaction or optimization problem.
Definition: flatzinc.hh:398
unsigned int c_d
Create a clone after every c_d commits (commit distance)
Definition: search.hh:456
T * alloc(long unsigned int n)
Allocate block of n objects of type T from region.
Definition: region.hpp:326
SetValBranch ann2svalsel(AST::Node *ann, std::string r0, std::string r1, Rnd rnd)
Definition: flatzinc.cpp:529
Which values to select for branching first.
Definition: int.hh:3981
Search engine options
Definition: search.hh:449
SetLit * getSet(void)
Cast this node to a set literal node.
Definition: ast.hh:462
void newIntVar(IntVarSpec *vs)
Create new integer variable from specification.
Definition: flatzinc.cpp:726
Abstract base class for comparators.
Definition: gist.hh:123
Call * getCall(void)
Return function call.
Definition: ast.hh:347
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:57
Value propagation or consistency (naive)
Definition: int.hh:938
int getFloatVar(void)
Cast this node to a Float variable node.
Definition: ast.hh:432
Gecode::ScriptMode mode(void) const
Definition: flatzinc.hh:314
Gecode::IntVarArray iv
The integer variables.
Definition: flatzinc.hh:427
SetVarBranch SET_VAR_ACTIVITY_MIN(double d, BranchTbl tbl)
Select variable with lowest activity with decay factor d.
Definition: var.hpp:143
void abs(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition: arithmetic.cpp:49
void stop(Support::Timer &timer, std::ostream &os)
Get time since start of timer and print user friendly time information.
Definition: script.cpp:46
IntAssign INT_ASSIGN_MED(void)
Select greatest value not greater than the median.
Definition: assign.hpp:64
Handle for brancher.
Definition: core.hpp:1157
Passing float variables.
Definition: float.hh:966
Specification for set variables.
Definition: varspec.hh:143
BranchInformation branchInfo
Information for printing branches.
Definition: flatzinc.hh:547
void compare(const Space &s, std::ostream &out) const
Compare this space with space s and print the differences on out.
Definition: flatzinc.cpp:1667
int boolVarCount
Number of Boolean variables.
Definition: flatzinc.hh:386
bool assigned(void) const
Test if all variables are assigned.
Definition: array.hpp:1085
SetValBranch SET_VAL_MIN_INC(void)
Include smallest element.
Definition: val.hpp:59
SetVarBranch SET_VAR_ACTIVITY_SIZE_MIN(double d, BranchTbl tbl)
Select variable with smallest activity divided by domain size with decay factor d.
Definition: var.hpp:223
bool singleton(void) const
Test whether float is a singleton.
Definition: val.hpp:96
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Definition: dom.cpp:44
bool optVarIsInt(void) const
Return whether variable used for optimization is integer (or float)
Definition: flatzinc.cpp:1650
IntVarBranch INT_VAR_SIZE_MIN(BranchTbl tbl)
Select variable with smallest domain size.
Definition: var.hpp:212
void minimize(int var, bool isInt, AST::Array *annotation)
Post that integer variable var should be minimized.
Definition: flatzinc.cpp:1323
IntVarBranch INT_VAR_MIN_MIN(BranchTbl tbl)
Select variable with smallest min.
Definition: var.hpp:192
unsigned long int fail
Number of failed nodes in search tree.
Definition: search.hh:139
bool isSetVar(void)
Test if node is a set variable node.
Definition: ast.hh:482
bool isBoolVar(void)
Test if node is a Boolean variable node.
Definition: ast.hh:478
virtual SharedHandle::Object * copy(void) const
Return fresh copy for update.
Definition: flatzinc.cpp:245
std::vector< Node * > a
Definition: ast.hh:237
unsigned long int depth
Maximum depth of search stack.
Definition: search.hh:143
TieBreak< IntVarBranch > ann2ivarsel(AST::Node *ann, Rnd rnd, double decay)
Definition: flatzinc.cpp:372
Integer variable array.
Definition: int.hh:741
FloatVarBranch FLOAT_VAR_AFC_MIN(double d, BranchTbl tbl)
Select variable with smallest accumulated failure count with decay factor d.
Definition: var.hpp:124
FloatValBranch ann2fvalsel(AST::Node *ann, std::string r0, std::string r1)
Definition: flatzinc.cpp:603
unsigned int id(void) const
Return brancher id.
Definition: core.hpp:3090
No restarts.
Definition: driver.hh:110
FloatVarBranch FLOAT_VAR_ACTIVITY_SIZE_MAX(double d, BranchTbl tbl)
Select variable with largest activity divided by domain size with decay factor d. ...
Definition: var.hpp:234
Less ( )
Definition: float.hh:1058
IntVarBranch INT_VAR_ACTIVITY_MAX(double d, BranchTbl tbl)
Select variable with highest activity with decay factor d.
Definition: var.hpp:182
int vs2bsh(BoolVarSpec *bs)
Definition: flatzinc.cpp:360
void init(int intVars, int boolVars, int setVars, int floatVars)
Initialize space with given number of variables.
Definition: flatzinc.cpp:701
Handle to region.
Definition: region.hpp:61
Greater ( )
Definition: int.hh:909
AuxVarBrancher(Space &home, bool share, AuxVarBrancher &b)
Copy constructor.
Definition: flatzinc.cpp:99
Meth method(void) const
Return whether to solve a satisfaction or optimization problem.
Definition: flatzinc.cpp:1640
FloatVarBranch FLOAT_VAR_ACTIVITY_MAX(double d, BranchTbl tbl)
Select variable with highest activity with decay factor d.
Definition: var.hpp:154
unsigned long int propagate
Number of propagator executions.
Definition: core.hpp:1313
Search::Cutoff * createCutoff(const Options &o)
Create cutoff object from options.
Definition: script.hpp:157
const int max
Largest allowed integer in integer set.
Definition: set.hh:99
Array * getArray(void)
Cast this node to an array node.
Definition: ast.hh:400
A thread-safe random number generator.
Definition: flatzinc.hh:358
const int max
Largest allowed integer value.
Definition: int.hh:113
Float variable array.
Definition: float.hh:1016
int vs2bsl(BoolVarSpec *bs)
Definition: flatzinc.cpp:348
Current restart information during search.
Definition: core.hpp:1265
Computation spaces.
Definition: core.hpp:1362
Abstract base class for inspectors.
Definition: gist.hh:103
FloatVarBranch FLOAT_VAR_NONE(void)
Select first unassigned variable.
Definition: var.hpp:92
const int min
Smallest allowed integer value.
Definition: int.hh:115
IntVarBranch INT_VAR_REGRET_MIN_MAX(BranchTbl tbl)
Select variable with largest min-regret.
Definition: var.hpp:277
Base-class for both propagators and branchers.
Definition: core.hpp:666
virtual size_t size(void) const
Report size occupied.
Definition: flatzinc.cpp:111
SetVarBranch SET_VAR_SIZE_MAX(BranchTbl tbl)
Select variable with largest unknown set.
Definition: var.hpp:188
Statistics for execution of status
Definition: core.hpp:1310
IntConLevel ann2icl(AST::Node *ann)
Convert ann to IntConLevel.
Definition: flatzinc.cpp:1941
void newSetVar(SetVarSpec *vs)
Create new set variable from specification.
Definition: flatzinc.cpp:765
IntAssign INT_ASSIGN_MIN(void)
Select smallest value.
Definition: assign.hpp:59
IntValBranch INT_VAL_RND(Rnd r)
Select random value.
Definition: val.hpp:83
virtual Choice * choice(const Space &, Archive &e)
Return choice.
Definition: flatzinc.cpp:177
Heap heap
The single global heap.
Definition: heap.cpp:49
std::vector< bool > iv_introduced
Indicates whether an integer variable is introduced by mzn2fzn.
Definition: flatzinc.hh:435
Gecode::IntSet d(v, 7)
TieBreak< IntVarBranch > bool_varsel
Definition: flatzinc.cpp:123
void newBoolVar(BoolVarSpec *vs)
Create new Boolean variable from specification.
Definition: flatzinc.cpp:753
Gecode::Support::Mutex mutex
A mutex for the random number generator.
Definition: flatzinc.hh:363
void update(Space &, bool share, VarArray< Var > &a)
Update array to be a clone of array a.
Definition: array.hpp:1072
const BoolInstr * bi[]
Definition: mm-bool.cpp:4169
bool alias
Whether the variable aliases another variable.
Definition: varspec.hh:63
SetVarBranch ann2svarsel(AST::Node *ann, Rnd rnd, double decay)
Definition: flatzinc.cpp:491
void start(void)
Start timer.
Definition: timer.hpp:70
SetVar arg2SetVar(AST::Node *n)
Convert n to SetVar.
Definition: flatzinc.cpp:1872
unsigned int nogoods_limit(void) const
Definition: flatzinc.hh:325
int getSetVar(void)
Cast this node to a set variable node.
Definition: ast.hh:438
double getFloat(void)
Cast this node to a Float node.
Definition: ast.hh:456
Gecode::FloatVal c(-8, 8)
Cutoff * cutoff
Cutoff for restart-based search.
Definition: search.hh:464
int optVar(void) const
Return index of variable used for optimization.
Definition: flatzinc.cpp:1645
double threads
Number of threads to use.
Definition: search.hh:454
void sort(TaskViewArray< TaskView > &t)
Sort task view array t according to sto and inc (increasing or decreasing)
Definition: sort.hpp:137
FloatVarBranch FLOAT_VAR_AFC_SIZE_MAX(double d, BranchTbl tbl)
Select variable with largest accumulated failure count divided by domain size with decay factor d...
Definition: var.hpp:214
T * alloc(long unsigned int n)
Allocate block of n objects of type T from heap.
Definition: heap.hpp:400
IntVarBranch INT_VAR_AFC_MAX(double d, BranchTbl tbl)
Select variable with largest accumulated failure count with decay factor d.
Definition: var.hpp:162
Gecode::FloatVarArray fv
The float variables.
Definition: flatzinc.hh:454
const FloatNum min
Smallest allowed float value.
Definition: float.hh:833
Gecode::IntArgs i(4, 1, 2, 3, 4)
IntAssign ann2asnivalsel(AST::Node *ann, Rnd rnd)
Definition: flatzinc.cpp:472
Base-class for branchers.
Definition: core.hpp:1071
FloatNum n
The middle value for branching.
Definition: float.hh:1375
virtual bool status(const Space &_home) const
Check status of brancher, return true if alternatives left.
Definition: flatzinc.cpp:136
void print(const BrancherHandle &bh, int a, int i, int n, ostream &o) const
Output branch information.
Definition: flatzinc.cpp:257
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Equality ( )
Definition: int.hh:904
IntVarBranch INT_VAR_DEGREE_MAX(BranchTbl tbl)
Select variable with largest degree.
Definition: var.hpp:147
std::vector< bool > fv_introduced
Indicates whether a float variable is introduced by mzn2fzn.
Definition: flatzinc.hh:458
Options opt
The options.
Definition: test.cpp:101
Option< std::pair< double, double > > domain
Definition: varspec.hh:125
IntVarBranch INT_VAR_ACTIVITY_MIN(double d, BranchTbl tbl)
Select variable with lowest activity with decay factor d.
Definition: var.hpp:172
void add(const BrancherHandle &bh, const string &rel0, const string &rel1, const vector< string > &n)
Add new brancher information.
Definition: flatzinc.cpp:249
struct Gecode::Space::@55::@56 p
Data only available during propagation.
int dfs(Space *root, const Gist::Options &opt)
Create a new stand-alone Gist for root.
Definition: gist.hpp:207
FloatVarBranch FLOAT_VAR_AFC_SIZE_MIN(double d, BranchTbl tbl)
Select variable with smalllest accumulated failure count divided by domain size with decay factor d...
Definition: var.hpp:204
IntAssign INT_ASSIGN_RND(Rnd r)
Select random value.
Definition: assign.hpp:74
Execution has resulted in failure.
Definition: core.hpp:525
Specification for Boolean variables.
Definition: varspec.hh:101
Value description class for branching.
Definition: float.hh:1372
double threads(void) const
Definition: flatzinc.hh:304
Node representing an atom
Definition: ast.hh:294
A lock as a scoped frontend for a mutex.
Definition: thread.hpp:199
SharedHandle::Object * object(void) const
Access to the shared object.
Definition: core.hpp:2619
int _optVar
Index of the variable to optimize.
Definition: flatzinc.hh:393
int getIntVar(void)
Cast this node to an integer variable node.
Definition: ast.hh:420
void finalize(void)
Clean up when Gist exits.
Definition: gist.cpp:67
Output support class for FlatZinc interpreter.
Definition: flatzinc.hh:111
IntVar arg2IntVar(AST::Node *n)
Convert n to IntVar.
Definition: flatzinc.cpp:1840
Choice(const Brancher &b, bool fail0)
Initialize choice for brancher b.
Definition: flatzinc.cpp:108
static void installCtrlHandler(bool install, bool force=false)
Install handler for catching Ctrl-C.
Definition: script.hpp:120
static Search::Stop * create(unsigned int node, unsigned int fail, unsigned int time, bool intr)
Create appropriate stop-object.
Definition: script.hpp:94
IntAssign INT_ASSIGN_MAX(void)
Select largest value.
Definition: assign.hpp:69
SetVarBranch SET_VAR_ACTIVITY_MAX(double d, BranchTbl tbl)
Select variable with highest activity with decay factor d.
Definition: var.hpp:153
unsigned int operator()(unsigned int n)
Returns a random integer from the interval [0..n)
Definition: flatzinc.cpp:323
int getBoolVar(void)
Cast this node to a Boolean variable node.
Definition: ast.hh:426
The Gecode Interactive Search Tool.
virtual const char * what(void) const
Return information.
Definition: exception.cpp:59
virtual void archive(Archive &e) const
Archive into e.
Definition: flatzinc.cpp:115
bool isSet(void)
Test if node is a set literal node.
Definition: ast.hh:502
std::vector< int > s
Definition: ast.hh:179
void fail(void)
Fail space.
Definition: core.hpp:3428
FznRnd * _random
Random number generator.
Definition: flatzinc.hh:404
unsigned int size(void) const
Return size (cardinality) of set.
Definition: int-set-1.hpp:161
BoolVarArgs arg2boolvarargs(AST::Node *arg, int offset=0, int siv=-1)
Convert arg to BoolVarArgs.
Definition: flatzinc.cpp:1803
IntValBranch INT_VAL_MIN(void)
Select smallest value.
Definition: val.hpp:68
std::string what(void) const
Definition: ast.hh:65
unsigned int size(I &i)
Size of all ranges of range iterator i.
void newFloatVar(FloatVarSpec *vs)
Create new float variable from specification.
Definition: flatzinc.cpp:812
virtual ExecStatus commit(Space &, const Gecode::Choice &c, unsigned int)
Perform commit for choice c.
Definition: flatzinc.cpp:182
IntValBranch INT_VAL_SPLIT_MAX(void)
Select values greater than mean of smallest and largest value.
Definition: val.hpp:93
IntVarBranch INT_VAR_MAX_MAX(BranchTbl tbl)
Select variable with largest max.
Definition: var.hpp:207
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)
Definition: flatzinc.cpp:2273
bool l
Whether to try the lower or upper half first.
Definition: float.hh:1377
IntVarBranch INT_VAR_RND(Rnd r)
Select random variable (uniform distribution, for tie breaking)
Definition: var.hpp:113
iterator begin(void)
Return an iterator at the beginning of the array.
Definition: array.hpp:1682
IntVarBranch INT_VAR_AFC_MIN(double d, BranchTbl tbl)
Select variable with smallest accumulated failure count with decay factor d.
Definition: var.hpp:152
SetValBranch SET_VAL_MAX_EXC(void)
Exclude largest element.
Definition: val.hpp:84
IntVarBranch INT_VAR_ACTIVITY_SIZE_MAX(double d, BranchTbl tbl)
Select variable with largest activity divided by domain size with decay factor d. ...
Definition: var.hpp:262
Iterator for the greatest lower bound ranges of a set variable.
Definition: set.hh:272
Gecode::BoolVarArray bv_aux
The introduced Boolean variables.
Definition: flatzinc.hh:441
bool clone
Whether engines create a clone when being initialized.
Definition: search.hh:452
void print(std::ostream &out, const Gecode::IntVarArray &iv, const Gecode::BoolVarArray &bv, const Gecode::SetVarArray &sv, const Gecode::FloatVarArray &fv) const
Definition: flatzinc.cpp:2175
FznRnd(unsigned int s=1)
Constructor.
Definition: flatzinc.cpp:320
Array * getArgs(unsigned int n)
Definition: ast.hh:269
struct Gecode::@519::NNF::@60::@62 a
For atomic nodes.
SetValBranch SET_VAL_MAX_INC(void)
Include largest element.
Definition: val.hpp:79
SetVarBranch SET_VAR_MAX_MAX(BranchTbl tbl)
Select variable with largest maximum unknown element.
Definition: var.hpp:178
FloatValBranch FLOAT_VAL_SPLIT_MIN(void)
Select values not greater than mean of smallest and largest value.
Definition: val.hpp:59
bool funcDep
Whether the variable functionally depends on another variable.
Definition: varspec.hh:69
Less ( )
Definition: int.hh:907
Integer sets.
Definition: int.hh:171
Float variable node.
Definition: ast.hh:218
virtual void compare(const Space &s0, const Space &s1)=0
Call-back function.
Set variable node
Definition: ast.hh:226
Choice that only signals failure or success
Definition: flatzinc.cpp:103
SetVarBranch SET_VAR_AFC_SIZE_MIN(double d, BranchTbl tbl)
Select variable with smallest accumulated failure count divided by domain size with decay factor d...
Definition: var.hpp:203
A simple comparator.
Definition: gist.hh:215
unsigned int node(void) const
Definition: flatzinc.hh:308
Option< AST::SetLit *> domain
Definition: varspec.hh:103
FlatZincSpace(bool share, FlatZincSpace &)
Copy constructor.
Definition: flatzinc.cpp:623
FloatVarBranch FLOAT_VAR_MAX_MAX(BranchTbl tbl)
Select variable with largest max.
Definition: var.hpp:179
IntVarArgs arg2intvarargs(AST::Node *arg, int offset=0)
Convert arg to IntVarArgs.
Definition: flatzinc.cpp:1782
virtual void constrain(const Space &s)
Implement optimization.
Definition: flatzinc.cpp:1600
bool isIntVar(void)
Test if node is an integer variable node.
Definition: ast.hh:474
FloatVarBranch FLOAT_VAR_RND(Rnd r)
Select random variable (uniform distribution, for tie breaking)
Definition: var.hpp:109
Passing integer variables.
Definition: int.hh:636
bool isBoolArray(AST::Node *b, int &singleInt)
Check if b is array of Booleans (or has a single integer)
Definition: flatzinc.cpp:1850
std::vector< bool > bv_introduced
Indicates whether a Boolean variable is introduced by mzn2fzn.
Definition: flatzinc.hh:443
bool done
Flag whether brancher is done.
Definition: flatzinc.cpp:71
Passing integer arguments.
Definition: int.hh:607
Passing Boolean variables.
Definition: int.hh:690
static const IntSet empty
Empty set.
Definition: int.hh:262
IntVarBranch INT_VAR_AFC_SIZE_MIN(double d, BranchTbl tbl)
Select variable with smallest accumulated failure count divided by domain size with decay factor d...
Definition: var.hpp:232
bool isInt(int &i)
Test if node is int, if yes set i to the value.
Definition: ast.hh:368
bool _optVarIsInt
Whether variable to optimize is integer (or float)
Definition: flatzinc.hh:395
IntSet arg2intset(AST::Node *n)
Convert n to IntSet.
Definition: flatzinc.cpp:1752
Gecode::FloatVarArray fv_aux
The introduced float variables.
Definition: flatzinc.hh:456
SetValBranch SET_VAL_MIN_EXC(void)
Exclude smallest element.
Definition: val.hpp:64
Boolean variable array.
Definition: int.hh:786
Greater ( )
Definition: float.hh:1060
SetVarBranch SET_VAR_AFC_SIZE_MAX(double d, BranchTbl tbl)
Select variable with largest accumulated failure count divided by domain size with decay factor d...
Definition: var.hpp:213
Boolean integer variables.
Definition: int.hh:491
bool isString(void)
Test if node is a string node.
Definition: ast.hh:506
const int v[7]
Definition: distinct.cpp:207
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:75
BrancherHandle bh
bool assigned
Whether the variable is assigned.
Definition: varspec.hh:65
AuxVarBrancher(Home home, TieBreak< IntVarBranch > int_varsel0, IntValBranch int_valsel0, TieBreak< IntVarBranch > bool_varsel0, IntValBranch bool_valsel0, SetVarBranch set_varsel0, SetValBranch set_valsel0, TieBreak< FloatVarBranch > float_varsel0, FloatValBranch float_valsel0)
Construct brancher.
Definition: flatzinc.cpp:73
void update(Space &home, bool share, SharedHandle &sh)
Updating during cloning.
Definition: core.hpp:2656
IntValBranch INT_VAL_MAX(void)
Select largest value.
Definition: val.hpp:78
AST::Array * args
Constraint arguments.
Definition: conexpr.hh:52
int getInt(void)
Cast this node to an integer node.
Definition: ast.hh:444
Integer variable node.
Definition: ast.hh:210
void print(const BrancherHandle &bh, int a, int i, int n, std::ostream &o) const
Output branch information.
Definition: flatzinc.cpp:292
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
Definition: flatzinc.cpp:2222
Passing set variables.
Definition: set.hh:490
struct Gecode::@519::NNF::@60::@61 b
For binary nodes (and, or, eqv)
void print(const BrancherHandle &bh, int a, int i, const FloatNumBranch &nl, ostream &o) const
Definition: flatzinc.cpp:263
void postConstraints(std::vector< ConExpr *> &ces)
Post a constraint specified by ce.
Definition: flatzinc.cpp:849
Exception: Base-class for exceptions
Definition: exception.hpp:46
Print statistics for script.
Definition: driver.hh:101
SetVarBranch SET_VAR_RND(Rnd r)
Select random variable (uniform distribution, for tie breaking)
Definition: var.hpp:96
Base class for variables.
Definition: var.hpp:44
Float value type.
Definition: float.hh:321
IntValBranch INT_VALUES_MIN(void)
Try all values starting from smallest.
Definition: val.hpp:120
void free(T *b, long unsigned int n)
Delete n objects starting at b.
Definition: heap.hpp:426
Space * clone(bool share=true, CloneStatistics &stat=unused_clone) const
Clone space.
Definition: core.hpp:2854
BrancherHandle assign(Home home, const FloatVarArgs &x, FloatAssign fa, FloatBranchFilter bf, FloatVarValPrint vvp)
Assign all x with value selection vals.
Definition: branch.cpp:113
virtual void print(std::ostream &)=0
Output string representation.
BranchInformation(void)
Constructor.
Definition: flatzinc.cpp:272
Exception signaling type error
Definition: ast.hh:59
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
FloatVarBranch FLOAT_VAR_MIN_MIN(BranchTbl tbl)
Select variable with smallest min.
Definition: var.hpp:164
Set variables
Definition: set.hh:129
Home operator()(Propagator &p)
Return a home for this space with the information that p is being rewritten.
Definition: core.hpp:2902
void print(std::ostream &out, const Printer &p) const
Produce output on out using p.
Definition: flatzinc.cpp:1655
virtual void archive(Archive &e) const
Archive into e.
Definition: core.cpp:670
Choice for performing commit
Definition: core.hpp:1036
unsigned int fail(void) const
Definition: flatzinc.hh:309
struct Gecode::Space::@55::@57 c
Data available only during copying.
bool hasAtom(const std::string &id)
Test if node has atom with id.
Definition: ast.hh:325
bool isFloatVar(void)
Test if node is a float variable node.
Definition: ast.hh:486
Archive representation
Definition: archive.hpp:45
int i
Variable index.
Definition: varspec.hh:61
Set literal node
Definition: ast.hh:175
void init(void)
Initialise for use.
Definition: flatzinc.cpp:279
ExecStatus
Definition: core.hpp:523
void flattenAnnotations(AST::Array *ann, std::vector< AST::Node *> &out)
Definition: flatzinc.cpp:867
Integer variables.
Definition: int.hh:350
Iterator for the values in the greatest lower bound of a set variable.
Definition: set.hh:368
Which values to select for assignment.
Definition: int.hh:4081
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition: rel.cpp:47
Exception class for FlatZinc errors
Definition: flatzinc.hh:597
Specification for floating point variables.
Definition: varspec.hh:123
TieBreak< FloatVarBranch > ann2fvarsel(AST::Node *ann, Rnd rnd, double decay)
Definition: flatzinc.cpp:559
IntVarBranch INT_VAR_AFC_SIZE_MAX(double d, BranchTbl tbl)
Select variable with largest accumulated failure count divided by domain size with decay factor d...
Definition: var.hpp:242
The default consistency for a constraint.
Definition: int.hh:941
int bab(Space *root, const Gist::Options &opt)
Create a new stand-alone Gist for branch-and-bound search of root.
Definition: gist.hpp:212
AST::Array * _solveAnnotations
Annotations on the solve item.
Definition: flatzinc.hh:407
unsigned int c_d(void) const
Definition: flatzinc.hh:306
IntValBranch INT_VAL_MED(void)
Select greatest value not greater than the median.
Definition: val.hpp:73
IntVarBranch INT_VAR_ACTIVITY_SIZE_MIN(double d, BranchTbl tbl)
Select variable with smallest activity divided by domain size with decay factor d.
Definition: var.hpp:252
~FlatZincSpace(void)
Destructor.
Definition: flatzinc.cpp:1338
An window for simple text output.
Definition: gist.hh:164
Run script in Gist.
Definition: driver.hh:102
bool needAuxVars
Whether the introduced variables still need to be copied.
Definition: flatzinc.hh:463
SpaceStatus status(StatusStatistics &stat=unused_status)
Query space status.
Definition: core.cpp:252
void solve(AST::Array *annotation)
Post the solve item.
Definition: flatzinc.cpp:1317
unsigned int time(void) const
Definition: flatzinc.hh:310
The shared object.
Definition: core.hpp:88
Execution is okay.
Definition: core.hpp:527
unsigned long int restart
Number of restarts.
Definition: search.hh:145
AST::Array * solveAnnotations(void) const
Return the solve item annotations.
Definition: flatzinc.cpp:1312
#define GECODE_HAS_FLOAT_VARS
Definition: config.hpp:23
void varValPrint(const Space &home, const BrancherHandle &bh, unsigned int a, Var, int i, const int &n, std::ostream &o)
Definition: flatzinc.cpp:304
TieBreak< FloatVarBranch > float_varsel
Definition: flatzinc.cpp:130
bool isArray(void)
Test if node is an array node.
Definition: ast.hh:510
Float variables.
Definition: float.hh:857
virtual Actor * copy(Space &home, bool share)
Copy brancher.
Definition: flatzinc.cpp:194
void aliasBool2Int(int iv, int bv)
Link integer variable iv to Boolean variable bv.
Definition: flatzinc.cpp:744
A space that can be initialized with a FlatZinc model.
Definition: flatzinc.hh:375
Gecode::IntVarArray iv_aux
The introduced integer variables.
Definition: flatzinc.hh:429
Set variable array
Definition: set.hh:571
void shrinkArrays(Space &home, int &optVar, bool optVarIsInt, Gecode::IntVarArray &iv, Gecode::BoolVarArray &bv, Gecode::SetVarArray &sv, Gecode::FloatVarArray &fv)
Definition: flatzinc.cpp:2308
CompareStatus compare(I &i, J &j)
Check whether range iterator i is a subset of j, or whether they are disjoint.
Bounds propagation or consistency.
Definition: int.hh:939
Stop * stop
Stop object for stopping search.
Definition: search.hh:462
class Gecode::Gist::Options::_I inspect
IntValBranch INT_VAL_SPLIT_MIN(void)
Select values not greater than mean of smallest and largest value.
Definition: val.hpp:88
int explore(Space *root, bool bab, const Options &opt)
Create a new stand-alone Gist for root using bab.
Definition: gist.cpp:105
void run(std::ostream &out, const Printer &p, const FlatZincOptions &opt, Gecode::Support::Timer &t_total)
Run the search.
Definition: flatzinc.cpp:1586
Gecode toplevel namespace
int * iv_boolalias
Indicates whether an integer variable aliases a Boolean variable.
Definition: flatzinc.hh:437
unsigned long int node
Number of nodes expanded.
Definition: search.hh:141
void maximize(int var, bool isInt, AST::Array *annotation)
Post that integer variable var should be maximized.
Definition: flatzinc.cpp:1331
int setVarCount
Number of set variables.
Definition: flatzinc.hh:390
Node representing a function call
Definition: ast.hh:259
int intVarCount
Number of integer variables.
Definition: flatzinc.hh:384
unsigned int a_d(void) const
Definition: flatzinc.hh:307
IntValBranch ann2ivalsel(AST::Node *ann, std::string &r0, std::string &r1, Rnd rnd)
Definition: flatzinc.cpp:421
SetVarArgs arg2setvarargs(AST::Node *arg, int offset=0, int doffset=0, const IntSet &od=IntSet::empty)
Convert n to SetVarArgs.
Definition: flatzinc.cpp:1883
A node in a FlatZinc abstract syntax tree.
Definition: ast.hh:71
virtual bool slave(const CRI &cri)
Slave configuration function for restart meta search engine.
Definition: flatzinc.cpp:1621
SetVarBranch SET_VAR_ACTIVITY_SIZE_MAX(double d, BranchTbl tbl)
Select variable with largest activity divided by domain size with decay factor d. ...
Definition: var.hpp:233
IntArgs arg2boolargs(AST::Node *arg, int offset=0)
Convert arg (array of Booleans) to IntArgs.
Definition: flatzinc.cpp:1742
BrancherHandle branch(Home home, const FloatVarArgs &x, FloatVarBranch vars, FloatValBranch vals, FloatBranchFilter bf, FloatVarValPrint vvp)
Branch over x with variable selection vars and value selection vals.
Definition: branch.cpp:43
Which variable to select for branching.
Definition: set.hh:1253
Random number generator.
Definition: rnd.hpp:46
FloatVarBranch FLOAT_VAR_ACTIVITY_MIN(double d, BranchTbl tbl)
Select variable with lowest activity with decay factor d.
Definition: var.hpp:144
SetVarBranch SET_VAR_MIN_MIN(BranchTbl tbl)
Select variable with smallest minimum unknown element.
Definition: var.hpp:163
FloatVarBranch FLOAT_VAR_ACTIVITY_SIZE_MIN(double d, BranchTbl tbl)
Select variable with smallest activity divided by domain size with decay factor d.
Definition: var.hpp:224
Space is failed
Definition: core.hpp:1301
unsigned int _lns
Percentage of variables to keep in LNS (or 0 for no LNS)
Definition: flatzinc.hh:401
FloatVarBranch FLOAT_VAR_SIZE_MAX(BranchTbl tbl)
Select variable with largest domain size.
Definition: var.hpp:189
friend FloatVal max(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:390
iterator end(void)
Return an iterator past the end of the array.
Definition: array.hpp:1694
unsigned long int restart(void) const
Return number of restarts.
Definition: core.hpp:2709
friend FloatVal min(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:402
Gecode::SetVarArray sv
The set variables.
Definition: flatzinc.hh:446
Gecode::FloatNum step
Step by which a next solution has to have lower cost.
Definition: flatzinc.hh:460
Home class for posting propagators
Definition: core.hpp:717
Options for Gist
Definition: gist.hh:238
double FloatNum
Floating point number base type.
Definition: float.hh:108
Specification for integer variables.
Definition: varspec.hh:76
void compare(Comparator *c)
Add comparator.
Definition: gist.hpp:186
SetVarBranch SET_VAR_AFC_MAX(double d, BranchTbl tbl)
Select variable with largest accumulated failure count with decay factor d.
Definition: var.hpp:133
bool introduced
Whether the variable was introduced in the mzn2fzn translation.
Definition: varspec.hh:67
std::string getString(void)
Cast this node to a string node.
Definition: ast.hh:468
FloatVarBranch FLOAT_VAR_AFC_MAX(double d, BranchTbl tbl)
Select variable with largest accumulated failure count with decay factor d.
Definition: var.hpp:134
Gecode::IntVarArray iv_lns
The integer variables used in LNS.
Definition: flatzinc.hh:432
FloatVar arg2FloatVar(AST::Node *n)
Convert n to FloatVar.
Definition: flatzinc.cpp:1930
Domain propagation or consistency.
Definition: int.hh:940
Branching on the introduced variables.
Definition: flatzinc.cpp:68
const Val & some(void) const
Definition: option.hh:51
IntVarBranch INT_VAR_SIZE_MAX(BranchTbl tbl)
Select variable with largest domain size.
Definition: var.hpp:217
void add(const BrancherHandle &bh, const std::string &rel0, const std::string &rel1, const std::vector< std::string > &n)
Add new brancher information.
Definition: flatzinc.cpp:285
Registry & registry(void)
Return global registry object.
Definition: registry.cpp:57
FloatValArgs arg2floatargs(AST::Node *arg, int offset=0)
Convert n to FloatValArgs.
Definition: flatzinc.cpp:1899
Option< AST::SetLit * > upperBound
Definition: varspec.hh:145
virtual size_t dispose(Space &)
Delete brancher and return its size.
Definition: flatzinc.cpp:225
T * a
Element array.
Definition: array.hpp:528
bool fail
Whether brancher should fail.
Definition: flatzinc.cpp:106
TieBreak< IntVarBranch > int_varsel
Definition: flatzinc.cpp:121
FloatVarBranch FLOAT_VAR_SIZE_MIN(BranchTbl tbl)
Select variable with smallest domain size.
Definition: var.hpp:184
void init(AST::Array *output)
Definition: flatzinc.cpp:1958
BoolVar arg2BoolVar(AST::Node *n)
Convert n to BoolVar.
Definition: flatzinc.cpp:1829
IntSetArgs arg2intsetargs(AST::Node *arg, int offset=0)
Convert arg to IntSetArgs.
Definition: flatzinc.cpp:1767
Abstract representation of a constraint.
Definition: conexpr.hh:47