Generated on Thu Mar 16 2017 03:24:14 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: 2016-08-26 02:45:29 +0200 (Fri, 26 Aug 2016) $ by $Author: tack $
15  * $Revision: 15155 $
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  }
250  const string& rel0,
251  const string& rel1,
252  const vector<string>& n) {
253  v.resize(std::max(static_cast<unsigned int>(v.size()),bg.id()+1));
254  v[bg.id()] = BI(rel0,rel1,n);
255  }
257  void print(const Brancher& b,
258  unsigned int a, int i, int n, ostream& o) const {
259  const BI& bi = v[b.group().id()];
260  o << bi.n[i] << " " << (a==0 ? bi.r0 : bi.r1) << " " << n;
261  }
262 #ifdef GECODE_HAS_FLOAT_VARS
263  void print(const Brancher& b,
264  unsigned int a, int i, const FloatNumBranch& nl,
265  ostream& o) const {
266  const BI& bi = v[b.group().id()];
267  o << bi.n[i] << " "
268  << (((a == 0) == nl.l) ? "<=" : ">=") << nl.n;
269  }
270 #endif
271  };
272 
273  BranchInformation::BranchInformation(void)
274  : SharedHandle(NULL) {}
275 
277  : SharedHandle(bi) {}
278 
279  void
281  assert(object() == NULL);
282  object(new BranchInformationO());
283  }
284 
285  void
287  const std::string& rel0,
288  const std::string& rel1,
289  const std::vector<std::string>& n) {
290  static_cast<BranchInformationO*>(object())->add(bg,rel0,rel1,n);
291  }
292  void
293  BranchInformation::print(const Brancher& b, unsigned int a, int i,
294  int n, std::ostream& o) const {
295  static_cast<const BranchInformationO*>(object())->print(b,a,i,n,o);
296  }
297 #ifdef GECODE_HAS_FLOAT_VARS
298  void
299  BranchInformation::print(const Brancher& b, unsigned int a, int i,
300  const FloatNumBranch& nl, std::ostream& o) const {
301  static_cast<const BranchInformationO*>(object())->print(b,a,i,nl,o);
302  }
303 #endif
304  template<class Var>
305  void varValPrint(const Space &home, const Brancher& b,
306  unsigned int a,
307  Var, int i, const int& n,
308  std::ostream& o) {
309  static_cast<const FlatZincSpace&>(home).branchInfo.print(b,a,i,n,o);
310  }
311 
312 #ifdef GECODE_HAS_FLOAT_VARS
313  void varValPrintF(const Space &home, const Brancher& b,
314  unsigned int a,
315  FloatVar, int i, const FloatNumBranch& nl,
316  std::ostream& o) {
317  static_cast<const FlatZincSpace&>(home).branchInfo.print(b,a,i,nl,o);
318  }
319 #endif
320 
321  FznRnd::FznRnd(unsigned int s) : random(s) {}
322 
323  unsigned int
324  FznRnd::operator ()(unsigned int n) {
325  Support::Lock lock(mutex);
326  return random(n);
327  }
328 
330  if (vs->assigned) {
331  return IntSet(vs->i,vs->i);
332  }
333  if (vs->domain()) {
334  AST::SetLit* sl = vs->domain.some();
335  if (sl->interval) {
336  return IntSet(sl->min, sl->max);
337  } else {
338  int* newdom = heap.alloc<int>(static_cast<unsigned long int>(sl->s.size()));
339  for (int i=sl->s.size(); i--;)
340  newdom[i] = sl->s[i];
341  IntSet ret(newdom, sl->s.size());
342  heap.free(newdom, static_cast<unsigned long int>(sl->s.size()));
343  return ret;
344  }
345  }
347  }
348 
349  int vs2bsl(BoolVarSpec* bs) {
350  if (bs->assigned) {
351  return bs->i;
352  }
353  if (bs->domain()) {
354  AST::SetLit* sl = bs->domain.some();
355  assert(sl->interval);
356  return std::min(1, std::max(0, sl->min));
357  }
358  return 0;
359  }
360 
361  int vs2bsh(BoolVarSpec* bs) {
362  if (bs->assigned) {
363  return bs->i;
364  }
365  if (bs->domain()) {
366  AST::SetLit* sl = bs->domain.some();
367  assert(sl->interval);
368  return std::max(0, std::min(1, sl->max));
369  }
370  return 1;
371  }
372 
373  TieBreak<IntVarBranch> ann2ivarsel(AST::Node* ann, Rnd rnd, double decay) {
374  if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
375  if (s->id == "input_order")
377  if (s->id == "first_fail")
379  if (s->id == "anti_first_fail")
381  if (s->id == "smallest")
383  if (s->id == "largest")
385  if (s->id == "occurrence")
387  if (s->id == "max_regret")
389  if (s->id == "most_constrained")
392  if (s->id == "random") {
393  return TieBreak<IntVarBranch>(INT_VAR_RND(rnd));
394  }
395  if (s->id == "dom_w_deg") {
397  }
398  if (s->id == "afc_min")
400  if (s->id == "afc_max")
402  if (s->id == "afc_size_min")
404  if (s->id == "afc_size_max") {
406  }
407  if (s->id == "activity_min")
409  if (s->id == "activity_max")
411  if (s->id == "activity_size_min")
413  if (s->id == "activity_size_max")
415  }
416  std::cerr << "Warning, ignored search annotation: ";
417  ann->print(std::cerr);
418  std::cerr << std::endl;
420  }
421 
422  IntValBranch ann2ivalsel(AST::Node* ann, std::string& r0, std::string& r1,
423  Rnd rnd) {
424  if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
425  if (s->id == "indomain_min") {
426  r0 = "="; r1 = "!=";
427  return INT_VAL_MIN();
428  }
429  if (s->id == "indomain_max") {
430  r0 = "="; r1 = "!=";
431  return INT_VAL_MAX();
432  }
433  if (s->id == "indomain_median") {
434  r0 = "="; r1 = "!=";
435  return INT_VAL_MED();
436  }
437  if (s->id == "indomain_split") {
438  r0 = "<="; r1 = ">";
439  return INT_VAL_SPLIT_MIN();
440  }
441  if (s->id == "indomain_reverse_split") {
442  r0 = ">"; r1 = "<=";
443  return INT_VAL_SPLIT_MAX();
444  }
445  if (s->id == "indomain_random") {
446  r0 = "="; r1 = "!=";
447  return INT_VAL_RND(rnd);
448  }
449  if (s->id == "indomain") {
450  r0 = "="; r1 = "=";
451  return INT_VALUES_MIN();
452  }
453  if (s->id == "indomain_middle") {
454  std::cerr << "Warning, replacing unsupported annotation "
455  << "indomain_middle with indomain_median" << std::endl;
456  r0 = "="; r1 = "!=";
457  return INT_VAL_MED();
458  }
459  if (s->id == "indomain_interval") {
460  std::cerr << "Warning, replacing unsupported annotation "
461  << "indomain_interval with indomain_split" << std::endl;
462  r0 = "<="; r1 = ">";
463  return INT_VAL_SPLIT_MIN();
464  }
465  }
466  std::cerr << "Warning, ignored search annotation: ";
467  ann->print(std::cerr);
468  std::cerr << std::endl;
469  r0 = "="; r1 = "!=";
470  return INT_VAL_MIN();
471  }
472 
474  if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
475  if (s->id == "indomain_min")
476  return INT_ASSIGN_MIN();
477  if (s->id == "indomain_max")
478  return INT_ASSIGN_MAX();
479  if (s->id == "indomain_median")
480  return INT_ASSIGN_MED();
481  if (s->id == "indomain_random") {
482  return INT_ASSIGN_RND(rnd);
483  }
484  }
485  std::cerr << "Warning, ignored search annotation: ";
486  ann->print(std::cerr);
487  std::cerr << std::endl;
488  return INT_ASSIGN_MIN();
489  }
490 
491 #ifdef GECODE_HAS_SET_VARS
492  SetVarBranch ann2svarsel(AST::Node* ann, Rnd rnd, double decay) {
493  if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
494  if (s->id == "input_order")
495  return SET_VAR_NONE();
496  if (s->id == "first_fail")
497  return SET_VAR_SIZE_MIN();
498  if (s->id == "anti_first_fail")
499  return SET_VAR_SIZE_MAX();
500  if (s->id == "smallest")
501  return SET_VAR_MIN_MIN();
502  if (s->id == "largest")
503  return SET_VAR_MAX_MAX();
504  if (s->id == "afc_min")
505  return SET_VAR_AFC_MIN(decay);
506  if (s->id == "afc_max")
507  return SET_VAR_AFC_MAX(decay);
508  if (s->id == "afc_size_min")
509  return SET_VAR_AFC_SIZE_MIN(decay);
510  if (s->id == "afc_size_max")
511  return SET_VAR_AFC_SIZE_MAX(decay);
512  if (s->id == "activity_min")
513  return SET_VAR_ACTIVITY_MIN(decay);
514  if (s->id == "activity_max")
515  return SET_VAR_ACTIVITY_MAX(decay);
516  if (s->id == "activity_size_min")
517  return SET_VAR_ACTIVITY_SIZE_MIN(decay);
518  if (s->id == "activity_size_max")
519  return SET_VAR_ACTIVITY_SIZE_MAX(decay);
520  if (s->id == "random") {
521  return SET_VAR_RND(rnd);
522  }
523  }
524  std::cerr << "Warning, ignored search annotation: ";
525  ann->print(std::cerr);
526  std::cerr << std::endl;
527  return SET_VAR_NONE();
528  }
529 
530  SetValBranch ann2svalsel(AST::Node* ann, std::string r0, std::string r1,
531  Rnd rnd) {
532  (void) rnd;
533  if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
534  if (s->id == "indomain_min") {
535  r0 = "in"; r1 = "not in";
536  return SET_VAL_MIN_INC();
537  }
538  if (s->id == "indomain_max") {
539  r0 = "in"; r1 = "not in";
540  return SET_VAL_MAX_INC();
541  }
542  if (s->id == "outdomain_min") {
543  r1 = "in"; r0 = "not in";
544  return SET_VAL_MIN_EXC();
545  }
546  if (s->id == "outdomain_max") {
547  r1 = "in"; r0 = "not in";
548  return SET_VAL_MAX_EXC();
549  }
550  }
551  std::cerr << "Warning, ignored search annotation: ";
552  ann->print(std::cerr);
553  std::cerr << std::endl;
554  r0 = "in"; r1 = "not in";
555  return SET_VAL_MIN_INC();
556  }
557 #endif
558 
559 #ifdef GECODE_HAS_FLOAT_VARS
561  double decay) {
562  if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
563  if (s->id == "input_order")
565  if (s->id == "first_fail")
567  if (s->id == "anti_first_fail")
569  if (s->id == "smallest")
571  if (s->id == "largest")
573  if (s->id == "occurrence")
575  if (s->id == "most_constrained")
578  if (s->id == "random") {
580  }
581  if (s->id == "afc_min")
583  if (s->id == "afc_max")
585  if (s->id == "afc_size_min")
587  if (s->id == "afc_size_max")
589  if (s->id == "activity_min")
591  if (s->id == "activity_max")
593  if (s->id == "activity_size_min")
595  if (s->id == "activity_size_max")
597  }
598  std::cerr << "Warning, ignored search annotation: ";
599  ann->print(std::cerr);
600  std::cerr << std::endl;
602  }
603 
604  FloatValBranch ann2fvalsel(AST::Node* ann, std::string r0, std::string r1) {
605  if (AST::Atom* s = dynamic_cast<AST::Atom*>(ann)) {
606  if (s->id == "indomain_split") {
607  r0 = "<="; r1 = ">";
608  return FLOAT_VAL_SPLIT_MIN();
609  }
610  if (s->id == "indomain_reverse_split") {
611  r1 = "<="; r0 = ">";
612  return FLOAT_VAL_SPLIT_MAX();
613  }
614  }
615  std::cerr << "Warning, ignored search annotation: ";
616  ann->print(std::cerr);
617  std::cerr << std::endl;
618  r0 = "<="; r1 = ">";
619  return FLOAT_VAL_SPLIT_MIN();
620  }
621 
622 #endif
623 
625  : Space(share, f), _random(f._random),
626  _solveAnnotations(NULL), iv_boolalias(NULL),
628  step(f.step),
629 #endif
630  needAuxVars(f.needAuxVars) {
631  _optVar = f._optVar;
633  _method = f._method;
634  _lns = f._lns;
636  branchInfo.update(*this, share, f.branchInfo);
637  iv.update(*this, share, f.iv);
638  iv_lns.update(*this, share, f.iv_lns);
640 
641  if (needAuxVars) {
642  IntVarArgs iva;
643  for (int i=0; i<f.iv_aux.size(); i++) {
644  if (!f.iv_aux[i].assigned()) {
645  iva << IntVar();
646  iva[iva.size()-1].update(*this, share, f.iv_aux[i]);
647  }
648  }
649  iv_aux = IntVarArray(*this, iva);
650  }
651 
652  bv.update(*this, share, f.bv);
654  if (needAuxVars) {
655  BoolVarArgs bva;
656  for (int i=0; i<f.bv_aux.size(); i++) {
657  if (!f.bv_aux[i].assigned()) {
658  bva << BoolVar();
659  bva[bva.size()-1].update(*this, share, f.bv_aux[i]);
660  }
661  }
662  bv_aux = BoolVarArray(*this, bva);
663  }
664 
665 #ifdef GECODE_HAS_SET_VARS
666  sv.update(*this, share, f.sv);
668  if (needAuxVars) {
669  SetVarArgs sva;
670  for (int i=0; i<f.sv_aux.size(); i++) {
671  if (!f.sv_aux[i].assigned()) {
672  sva << SetVar();
673  sva[sva.size()-1].update(*this, share, f.sv_aux[i]);
674  }
675  }
676  sv_aux = SetVarArray(*this, sva);
677  }
678 #endif
679 #ifdef GECODE_HAS_FLOAT_VARS
680  fv.update(*this, share, f.fv);
682  if (needAuxVars) {
683  FloatVarArgs fva;
684  for (int i=0; i<f.fv_aux.size(); i++) {
685  if (!f.fv_aux[i].assigned()) {
686  fva << FloatVar();
687  fva[fva.size()-1].update(*this, share, f.fv_aux[i]);
688  }
689  }
690  fv_aux = FloatVarArray(*this, fva);
691  }
692 #endif
693  }
694 
696  : intVarCount(-1), boolVarCount(-1), floatVarCount(-1), setVarCount(-1),
697  _optVar(-1), _optVarIsInt(true), _lns(0), _lnsInitialSolution(0),
698  _random(random),
699  _solveAnnotations(NULL), needAuxVars(true) {
700  branchInfo.init();
701  }
702 
703  void
704  FlatZincSpace::init(int intVars, int boolVars,
705  int setVars, int floatVars) {
706  (void) setVars;
707  (void) floatVars;
708 
709  intVarCount = 0;
710  iv = IntVarArray(*this, intVars);
711  iv_introduced = std::vector<bool>(2*intVars);
712  iv_boolalias = alloc<int>(intVars+(intVars==0?1:0));
713  boolVarCount = 0;
714  bv = BoolVarArray(*this, boolVars);
715  bv_introduced = std::vector<bool>(2*boolVars);
716 #ifdef GECODE_HAS_SET_VARS
717  setVarCount = 0;
718  sv = SetVarArray(*this, setVars);
719  sv_introduced = std::vector<bool>(2*setVars);
720 #endif
721 #ifdef GECODE_HAS_FLOAT_VARS
722  floatVarCount = 0;
723  fv = FloatVarArray(*this, floatVars);
724  fv_introduced = std::vector<bool>(2*floatVars);
725 #endif
726  }
727 
728  void
730  if (vs->alias) {
731  iv[intVarCount++] = iv[vs->i];
732  } else {
733  IntSet dom(vs2is(vs));
734  if (dom.size()==0) {
735  fail();
736  return;
737  } else {
738  iv[intVarCount++] = IntVar(*this, dom);
739  }
740  }
741  iv_introduced[2*(intVarCount-1)] = vs->introduced;
742  iv_introduced[2*(intVarCount-1)+1] = vs->funcDep;
743  iv_boolalias[intVarCount-1] = -1;
744  }
745 
746  void
748  iv_boolalias[iv] = bv;
749  }
750  int
752  return iv_boolalias[iv];
753  }
754 
755  void
757  if (vs->alias) {
758  bv[boolVarCount++] = bv[vs->i];
759  } else {
760  bv[boolVarCount++] = BoolVar(*this, vs2bsl(vs), vs2bsh(vs));
761  }
763  bv_introduced[2*(boolVarCount-1)+1] = vs->funcDep;
764  }
765 
766 #ifdef GECODE_HAS_SET_VARS
767  void
769  if (vs->alias) {
770  sv[setVarCount++] = sv[vs->i];
771  } else if (vs->assigned) {
772  assert(vs->upperBound());
773  AST::SetLit* vsv = vs->upperBound.some();
774  if (vsv->interval) {
775  IntSet d(vsv->min, vsv->max);
776  sv[setVarCount++] = SetVar(*this, d, d);
777  } else {
778  int* is = heap.alloc<int>(static_cast<unsigned long int>(vsv->s.size()));
779  for (int i=vsv->s.size(); i--; )
780  is[i] = vsv->s[i];
781  IntSet d(is, vsv->s.size());
782  heap.free(is,static_cast<unsigned long int>(vsv->s.size()));
783  sv[setVarCount++] = SetVar(*this, d, d);
784  }
785  } else if (vs->upperBound()) {
786  AST::SetLit* vsv = vs->upperBound.some();
787  if (vsv->interval) {
788  IntSet d(vsv->min, vsv->max);
789  sv[setVarCount++] = SetVar(*this, IntSet::empty, d);
790  } else {
791  int* is = heap.alloc<int>(static_cast<unsigned long int>(vsv->s.size()));
792  for (int i=vsv->s.size(); i--; )
793  is[i] = vsv->s[i];
794  IntSet d(is, vsv->s.size());
795  heap.free(is,static_cast<unsigned long int>(vsv->s.size()));
796  sv[setVarCount++] = SetVar(*this, IntSet::empty, d);
797  }
798  } else {
799  sv[setVarCount++] = SetVar(*this, IntSet::empty,
802  }
803  sv_introduced[2*(setVarCount-1)] = vs->introduced;
804  sv_introduced[2*(setVarCount-1)+1] = vs->funcDep;
805  }
806 #else
807  void
809  throw FlatZinc::Error("Gecode", "set variables not supported");
810  }
811 #endif
812 
813 #ifdef GECODE_HAS_FLOAT_VARS
814  void
816  if (vs->alias) {
817  fv[floatVarCount++] = fv[vs->i];
818  } else {
819  double dmin, dmax;
820  if (vs->domain()) {
821  dmin = vs->domain.some().first;
822  dmax = vs->domain.some().second;
823  if (dmin > dmax) {
824  fail();
825  return;
826  }
827  } else {
828  dmin = Float::Limits::min;
829  dmax = Float::Limits::max;
830  }
831  fv[floatVarCount++] = FloatVar(*this, dmin, dmax);
832  }
834  fv_introduced[2*(floatVarCount-1)+1] = vs->funcDep;
835  }
836 #else
837  void
839  throw FlatZinc::Error("Gecode", "float variables not supported");
840  }
841 #endif
842 
843  namespace {
844  struct ConExprOrder {
845  bool operator() (ConExpr* ce0, ConExpr* ce1) {
846  return ce0->args->a.size() < ce1->args->a.size();
847  }
848  };
849  }
850 
851  void
852  FlatZincSpace::postConstraints(std::vector<ConExpr*>& ces) {
853  ConExprOrder ceo;
854  std::sort(ces.begin(), ces.end(), ceo);
855 
856  for (unsigned int i=0; i<ces.size(); i++) {
857  const ConExpr& ce = *ces[i];
858  try {
859  registry().post(*this, ce);
860  } catch (Gecode::Exception& e) {
861  throw FlatZinc::Error("Gecode", e.what());
862  } catch (AST::TypeError& e) {
863  throw FlatZinc::Error("Type error", e.what());
864  }
865  delete ces[i];
866  ces[i] = NULL;
867  }
868  }
869 
870  void flattenAnnotations(AST::Array* ann, std::vector<AST::Node*>& out) {
871  for (unsigned int i=0; i<ann->a.size(); i++) {
872  if (ann->a[i]->isCall("seq_search")) {
873  AST::Call* c = ann->a[i]->getCall();
874  if (c->args->isArray())
875  flattenAnnotations(c->args->getArray(), out);
876  else
877  out.push_back(c->args);
878  } else {
879  out.push_back(ann->a[i]);
880  }
881  }
882  }
883 
884  void
886  double decay,
887  bool ignoreUnknown,
888  std::ostream& err) {
889  Rnd rnd(static_cast<unsigned int>(seed));
890  TieBreak<IntVarBranch> def_int_varsel = INT_VAR_AFC_SIZE_MAX(0.99);
891  IntValBranch def_int_valsel = INT_VAL_MIN();
892  std::string def_int_rel_left = "=";
893  std::string def_int_rel_right = "!=";
894  TieBreak<IntVarBranch> def_bool_varsel = INT_VAR_AFC_MAX(0.99);
895  IntValBranch def_bool_valsel = INT_VAL_MIN();
896  std::string def_bool_rel_left = "=";
897  std::string def_bool_rel_right = "!=";
898 #ifdef GECODE_HAS_SET_VARS
899  SetVarBranch def_set_varsel = SET_VAR_AFC_SIZE_MAX(0.99);
900  SetValBranch def_set_valsel = SET_VAL_MIN_INC();
901  std::string def_set_rel_left = "in";
902  std::string def_set_rel_right = "not in";
903 #endif
904 #ifdef GECODE_HAS_FLOAT_VARS
905  TieBreak<FloatVarBranch> def_float_varsel = FLOAT_VAR_SIZE_MIN();
906  FloatValBranch def_float_valsel = FLOAT_VAL_SPLIT_MIN();
907  std::string def_float_rel_left = "<=";
908  std::string def_float_rel_right = ">";
909 #endif
910 
911  std::vector<bool> iv_searched(iv.size());
912  for (unsigned int i=iv.size(); i--;)
913  iv_searched[i] = false;
914  std::vector<bool> bv_searched(bv.size());
915  for (unsigned int i=bv.size(); i--;)
916  bv_searched[i] = false;
917 #ifdef GECODE_HAS_SET_VARS
918  std::vector<bool> sv_searched(sv.size());
919  for (unsigned int i=sv.size(); i--;)
920  sv_searched[i] = false;
921 #endif
922 #ifdef GECODE_HAS_FLOAT_VARS
923  std::vector<bool> fv_searched(fv.size());
924  for (unsigned int i=fv.size(); i--;)
925  fv_searched[i] = false;
926 #endif
927 
928  _lns = 0;
929  if (ann) {
930  std::vector<AST::Node*> flatAnn;
931  if (ann->isArray()) {
932  flattenAnnotations(ann->getArray() , flatAnn);
933  } else {
934  flatAnn.push_back(ann);
935  }
936 
937  for (unsigned int i=0; i<flatAnn.size(); i++) {
938  if (flatAnn[i]->isCall("relax_and_reconstruct")) {
939  if (_lns != 0)
940  throw FlatZinc::Error("FlatZinc",
941  "Only one relax_and_reconstruct annotation allowed");
942  AST::Call *call = flatAnn[i]->getCall("relax_and_reconstruct");
943  AST::Array* args;
944  if (call->args->getArray()->a.size()==2) {
945  args = call->getArgs(2);
946  } else {
947  args = call->getArgs(3);
948  }
949  _lns = args->a[1]->getInt();
950  AST::Array *vars = args->a[0]->getArray();
951  int k=vars->a.size();
952  for (int i=vars->a.size(); i--;)
953  if (vars->a[i]->isInt())
954  k--;
955  iv_lns = IntVarArray(*this, k);
956  k = 0;
957  for (unsigned int i=0; i<vars->a.size(); i++) {
958  if (vars->a[i]->isInt())
959  continue;
960  iv_lns[k++] = iv[vars->a[i]->getIntVar()];
961  }
962  if (args->a.size()==3) {
963  AST::Array *initial = args->a[2]->getArray();
964  _lnsInitialSolution = IntSharedArray(initial->a.size());
965  for (unsigned int i=initial->a.size(); i--;)
966  _lnsInitialSolution[i] = initial->a[i]->getInt();
967  }
968  } else if (flatAnn[i]->isCall("gecode_search")) {
969  AST::Call* c = flatAnn[i]->getCall();
970  branchWithPlugin(c->args);
971  } else if (flatAnn[i]->isCall("int_search")) {
972  AST::Call *call = flatAnn[i]->getCall("int_search");
973  AST::Array *args = call->getArgs(4);
974  AST::Array *vars = args->a[0]->getArray();
975  int k=vars->a.size();
976  for (int i=vars->a.size(); i--;)
977  if (vars->a[i]->isInt())
978  k--;
979  IntVarArgs va(k);
980  vector<string> names;
981  k=0;
982  for (unsigned int i=0; i<vars->a.size(); i++) {
983  if (vars->a[i]->isInt())
984  continue;
985  va[k++] = iv[vars->a[i]->getIntVar()];
986  iv_searched[vars->a[i]->getIntVar()] = true;
987  names.push_back(vars->a[i]->getVarName());
988  }
989  std::string r0, r1;
990  {
991  BrancherGroup bg;
992  branch(bg(*this), va,
993  ann2ivarsel(args->a[1],rnd,decay),
994  ann2ivalsel(args->a[2],r0,r1,rnd),
995  NULL,
996  &varValPrint<IntVar>);
997  branchInfo.add(bg,r0,r1,names);
998  }
999  } else if (flatAnn[i]->isCall("int_assign")) {
1000  AST::Call *call = flatAnn[i]->getCall("int_assign");
1001  AST::Array *args = call->getArgs(2);
1002  AST::Array *vars = args->a[0]->getArray();
1003  int k=vars->a.size();
1004  for (int i=vars->a.size(); i--;)
1005  if (vars->a[i]->isInt())
1006  k--;
1007  IntVarArgs va(k);
1008  k=0;
1009  for (unsigned int i=0; i<vars->a.size(); i++) {
1010  if (vars->a[i]->isInt())
1011  continue;
1012  va[k++] = iv[vars->a[i]->getIntVar()];
1013  iv_searched[vars->a[i]->getIntVar()] = true;
1014  }
1015  assign(*this, va, ann2asnivalsel(args->a[1],rnd), NULL,
1016  &varValPrint<IntVar>);
1017  } else if (flatAnn[i]->isCall("bool_search")) {
1018  AST::Call *call = flatAnn[i]->getCall("bool_search");
1019  AST::Array *args = call->getArgs(4);
1020  AST::Array *vars = args->a[0]->getArray();
1021  int k=vars->a.size();
1022  for (int i=vars->a.size(); i--;)
1023  if (vars->a[i]->isBool())
1024  k--;
1025  BoolVarArgs va(k);
1026  k=0;
1027  vector<string> names;
1028  for (unsigned int i=0; i<vars->a.size(); i++) {
1029  if (vars->a[i]->isBool())
1030  continue;
1031  va[k++] = bv[vars->a[i]->getBoolVar()];
1032  bv_searched[vars->a[i]->getBoolVar()] = true;
1033  names.push_back(vars->a[i]->getVarName());
1034  }
1035 
1036  std::string r0, r1;
1037  {
1038  BrancherGroup bg;
1039  branch(bg(*this), va,
1040  ann2ivarsel(args->a[1],rnd,decay),
1041  ann2ivalsel(args->a[2],r0,r1,rnd), NULL,
1042  &varValPrint<BoolVar>);
1043  branchInfo.add(bg,r0,r1,names);
1044  }
1045  } else if (flatAnn[i]->isCall("int_default_search")) {
1046  AST::Call *call = flatAnn[i]->getCall("int_default_search");
1047  AST::Array *args = call->getArgs(2);
1048  def_int_varsel = ann2ivarsel(args->a[0],rnd,decay);
1049  def_int_valsel = ann2ivalsel(args->a[1],
1050  def_int_rel_left,def_int_rel_right,rnd);
1051  } else if (flatAnn[i]->isCall("bool_default_search")) {
1052  AST::Call *call = flatAnn[i]->getCall("bool_default_search");
1053  AST::Array *args = call->getArgs(2);
1054  def_bool_varsel = ann2ivarsel(args->a[0],rnd,decay);
1055  def_bool_valsel = ann2ivalsel(args->a[1],
1056  def_bool_rel_left,def_bool_rel_right,
1057  rnd);
1058  } else if (flatAnn[i]->isCall("set_search")) {
1059 #ifdef GECODE_HAS_SET_VARS
1060  AST::Call *call = flatAnn[i]->getCall("set_search");
1061  AST::Array *args = call->getArgs(4);
1062  AST::Array *vars = args->a[0]->getArray();
1063  int k=vars->a.size();
1064  for (int i=vars->a.size(); i--;)
1065  if (vars->a[i]->isSet())
1066  k--;
1067  SetVarArgs va(k);
1068  k=0;
1069  vector<string> names;
1070  for (unsigned int i=0; i<vars->a.size(); i++) {
1071  if (vars->a[i]->isSet())
1072  continue;
1073  va[k++] = sv[vars->a[i]->getSetVar()];
1074  sv_searched[vars->a[i]->getSetVar()] = true;
1075  names.push_back(vars->a[i]->getVarName());
1076  }
1077  std::string r0, r1;
1078  {
1079  BrancherGroup bg;
1080  branch(bg(*this), va,
1081  ann2svarsel(args->a[1],rnd,decay),
1082  ann2svalsel(args->a[2],r0,r1,rnd),
1083  NULL,
1084  &varValPrint<SetVar>);
1085  branchInfo.add(bg,r0,r1,names);
1086  }
1087 #else
1088  if (!ignoreUnknown) {
1089  err << "Warning, ignored search annotation: ";
1090  flatAnn[i]->print(err);
1091  err << std::endl;
1092  }
1093 #endif
1094  } else if (flatAnn[i]->isCall("set_default_search")) {
1095 #ifdef GECODE_HAS_SET_VARS
1096  AST::Call *call = flatAnn[i]->getCall("set_default_search");
1097  AST::Array *args = call->getArgs(2);
1098  def_set_varsel = ann2svarsel(args->a[0],rnd,decay);
1099  def_set_valsel = ann2svalsel(args->a[1],
1100  def_set_rel_left,def_set_rel_right,rnd);
1101 #else
1102  if (!ignoreUnknown) {
1103  err << "Warning, ignored search annotation: ";
1104  flatAnn[i]->print(err);
1105  err << std::endl;
1106  }
1107 #endif
1108  } else if (flatAnn[i]->isCall("float_default_search")) {
1109 #ifdef GECODE_HAS_FLOAT_VARS
1110  AST::Call *call = flatAnn[i]->getCall("float_default_search");
1111  AST::Array *args = call->getArgs(2);
1112  def_float_varsel = ann2fvarsel(args->a[0],rnd,decay);
1113  def_float_valsel = ann2fvalsel(args->a[1],
1114  def_float_rel_left,def_float_rel_right);
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 if (flatAnn[i]->isCall("float_search")) {
1123 #ifdef GECODE_HAS_FLOAT_VARS
1124  AST::Call *call = flatAnn[i]->getCall("float_search");
1125  AST::Array *args = call->getArgs(5);
1126  AST::Array *vars = args->a[0]->getArray();
1127  int k=vars->a.size();
1128  for (int i=vars->a.size(); i--;)
1129  if (vars->a[i]->isFloat())
1130  k--;
1131  FloatVarArgs va(k);
1132  k=0;
1133  vector<string> names;
1134  for (unsigned int i=0; i<vars->a.size(); i++) {
1135  if (vars->a[i]->isFloat())
1136  continue;
1137  va[k++] = fv[vars->a[i]->getFloatVar()];
1138  fv_searched[vars->a[i]->getFloatVar()] = true;
1139  names.push_back(vars->a[i]->getVarName());
1140  }
1141  std::string r0, r1;
1142  {
1143  BrancherGroup bg;
1144  branch(bg(*this), va,
1145  ann2fvarsel(args->a[2],rnd,decay),
1146  ann2fvalsel(args->a[3],r0,r1),
1147  NULL,
1148  &varValPrintF);
1149  branchInfo.add(bg,r0,r1,names);
1150  }
1151 #else
1152  if (!ignoreUnknown) {
1153  err << "Warning, ignored search annotation: ";
1154  flatAnn[i]->print(err);
1155  err << std::endl;
1156  }
1157 #endif
1158  } else {
1159  if (!ignoreUnknown) {
1160  err << "Warning, ignored search annotation: ";
1161  flatAnn[i]->print(err);
1162  err << std::endl;
1163  }
1164  }
1165  }
1166  }
1167  int introduced = 0;
1168  int funcdep = 0;
1169  int searched = 0;
1170  for (int i=iv.size(); i--;) {
1171  if (iv_searched[i] || (_method != SAT && _optVarIsInt && _optVar==i)) {
1172  searched++;
1173  } else if (iv_introduced[2*i]) {
1174  if (iv_introduced[2*i+1]) {
1175  funcdep++;
1176  } else {
1177  introduced++;
1178  }
1179  }
1180  }
1181  std::vector<std::string> iv_sol_names(iv.size()-(introduced+funcdep+searched));
1182  IntVarArgs iv_sol(iv.size()-(introduced+funcdep+searched));
1183  std::vector<std::string> iv_tmp_names(introduced);
1184  IntVarArgs iv_tmp(introduced);
1185  for (int i=iv.size(), j=0, k=0; i--;) {
1186  if (iv_searched[i] || (_method != SAT && _optVarIsInt && _optVar==i))
1187  continue;
1188  if (iv_introduced[2*i]) {
1189  if (!iv_introduced[2*i+1]) {
1190  iv_tmp_names[j] = p.intVarName(i);
1191  iv_tmp[j++] = iv[i];
1192  }
1193  } else {
1194  iv_sol_names[k] = p.intVarName(i);
1195  iv_sol[k++] = iv[i];
1196  }
1197  }
1198 
1199  introduced = 0;
1200  funcdep = 0;
1201  searched = 0;
1202  for (int i=bv.size(); i--;) {
1203  if (bv_searched[i]) {
1204  searched++;
1205  } else if (bv_introduced[2*i]) {
1206  if (bv_introduced[2*i+1]) {
1207  funcdep++;
1208  } else {
1209  introduced++;
1210  }
1211  }
1212  }
1213  std::vector<std::string> bv_sol_names(bv.size()-(introduced+funcdep+searched));
1214  BoolVarArgs bv_sol(bv.size()-(introduced+funcdep+searched));
1215  BoolVarArgs bv_tmp(introduced);
1216  std::vector<std::string> bv_tmp_names(introduced);
1217  for (int i=bv.size(), j=0, k=0; i--;) {
1218  if (bv_searched[i])
1219  continue;
1220  if (bv_introduced[2*i]) {
1221  if (!bv_introduced[2*i+1]) {
1222  bv_tmp_names[j] = p.boolVarName(i);
1223  bv_tmp[j++] = bv[i];
1224  }
1225  } else {
1226  bv_sol_names[k] = p.boolVarName(i);
1227  bv_sol[k++] = bv[i];
1228  }
1229  }
1230 
1231  if (iv_sol.size() > 0) {
1232  BrancherGroup bg;
1233  branch(bg(*this), iv_sol, def_int_varsel, def_int_valsel,
1234  NULL, &varValPrint<IntVar>);
1235  branchInfo.add(bg,def_int_rel_left,def_int_rel_right,iv_sol_names);
1236  }
1237  if (bv_sol.size() > 0) {
1238  BrancherGroup bg;
1239  branch(bg(*this), bv_sol, def_bool_varsel, def_bool_valsel,
1240  NULL, &varValPrint<BoolVar>);
1241  branchInfo.add(bg,def_bool_rel_left,def_bool_rel_right,bv_sol_names);
1242  }
1243 #ifdef GECODE_HAS_FLOAT_VARS
1244  introduced = 0;
1245  funcdep = 0;
1246  searched = 0;
1247  for (int i=fv.size(); i--;) {
1248  if (fv_searched[i] || (_method != SAT && !_optVarIsInt && _optVar==i)) {
1249  searched++;
1250  } else if (fv_introduced[2*i]) {
1251  if (fv_introduced[2*i+1]) {
1252  funcdep++;
1253  } else {
1254  introduced++;
1255  }
1256  }
1257  }
1258  std::vector<std::string> fv_sol_names(fv.size()-(introduced+funcdep+searched));
1259  FloatVarArgs fv_sol(fv.size()-(introduced+funcdep+searched));
1260  FloatVarArgs fv_tmp(introduced);
1261  std::vector<std::string> fv_tmp_names(introduced);
1262  for (int i=fv.size(), j=0, k=0; i--;) {
1263  if (fv_searched[i] || (_method != SAT && !_optVarIsInt && _optVar==i))
1264  continue;
1265  if (fv_introduced[2*i]) {
1266  if (!fv_introduced[2*i+1]) {
1267  fv_tmp_names[j] = p.floatVarName(i);
1268  fv_tmp[j++] = fv[i];
1269  }
1270  } else {
1271  fv_sol_names[k] = p.floatVarName(i);
1272  fv_sol[k++] = fv[i];
1273  }
1274  }
1275 
1276  if (fv_sol.size() > 0) {
1277  BrancherGroup bg;
1278  branch(bg(*this), fv_sol, def_float_varsel, def_float_valsel,
1279  NULL, &varValPrintF);
1280  branchInfo.add(bg,def_float_rel_left,def_float_rel_right,fv_sol_names);
1281  }
1282 #endif
1283 #ifdef GECODE_HAS_SET_VARS
1284  introduced = 0;
1285  funcdep = 0;
1286  searched = 0;
1287  for (int i=sv.size(); i--;) {
1288  if (sv_searched[i]) {
1289  searched++;
1290  } else if (sv_introduced[2*i]) {
1291  if (sv_introduced[2*i+1]) {
1292  funcdep++;
1293  } else {
1294  introduced++;
1295  }
1296  }
1297  }
1298  std::vector<std::string> sv_sol_names(sv.size()-(introduced+funcdep+searched));
1299  SetVarArgs sv_sol(sv.size()-(introduced+funcdep+searched));
1300  SetVarArgs sv_tmp(introduced);
1301  std::vector<std::string> sv_tmp_names(introduced);
1302  for (int i=sv.size(), j=0, k=0; i--;) {
1303  if (sv_searched[i])
1304  continue;
1305  if (sv_introduced[2*i]) {
1306  if (!sv_introduced[2*i+1]) {
1307  sv_tmp_names[j] = p.setVarName(i);
1308  sv_tmp[j++] = sv[i];
1309  }
1310  } else {
1311  sv_sol_names[k] = p.setVarName(i);
1312  sv_sol[k++] = sv[i];
1313  }
1314  }
1315 
1316  if (sv_sol.size() > 0) {
1317  BrancherGroup bg;
1318  branch(bg(*this), sv_sol, def_set_varsel, def_set_valsel,
1319  NULL, &varValPrint<SetVar>);
1320  branchInfo.add(bg,def_set_rel_left,def_set_rel_right,sv_sol_names);
1321 
1322  }
1323 #endif
1324  iv_aux = IntVarArray(*this, iv_tmp);
1325  bv_aux = BoolVarArray(*this, bv_tmp);
1326  int n_aux = iv_aux.size() + bv_aux.size();
1327 #ifdef GECODE_HAS_SET_VARS
1328  sv_aux = SetVarArray(*this, sv_tmp);
1329  n_aux += sv_aux.size();
1330 #endif
1331 #ifdef GECODE_HAS_FLOAT_VARS
1332  fv_aux = FloatVarArray(*this, fv_tmp);
1333  n_aux += fv_aux.size();
1334 #endif
1335 
1336  if (_method == MIN) {
1337  if (_optVarIsInt) {
1338  std::vector<std::string> names(1);
1339  names[0] = p.intVarName(_optVar);
1340  BrancherGroup bg;
1341  branch(bg(*this), iv[_optVar], INT_VAL_MIN(), &varValPrint<IntVar>);
1342  branchInfo.add(bg,"=","!=",names);
1343  } else {
1344 #ifdef GECODE_HAS_FLOAT_VARS
1345  std::vector<std::string> names(1);
1346  names[0] = p.floatVarName(_optVar);
1347  BrancherGroup bg;
1348  branch(bg(*this), fv[_optVar], FLOAT_VAL_SPLIT_MIN(), &varValPrintF);
1349  branchInfo.add(bg,"<=",">",names);
1350 #endif
1351  }
1352  } else if (_method == MAX) {
1353  if (_optVarIsInt) {
1354  std::vector<std::string> names(1);
1355  names[0] = p.intVarName(_optVar);
1356  BrancherGroup bg;
1357  branch(bg(*this), iv[_optVar], INT_VAL_MAX(), &varValPrint<IntVar>);
1358  branchInfo.add(bg,"=","!=",names);
1359  } else {
1360 #ifdef GECODE_HAS_FLOAT_VARS
1361  std::vector<std::string> names(1);
1362  names[0] = p.floatVarName(_optVar);
1363  BrancherGroup bg;
1364  branch(bg(*this), fv[_optVar], FLOAT_VAL_SPLIT_MAX(), &varValPrintF);
1365  branchInfo.add(bg,"<=",">",names);
1366 #endif
1367  }
1368  }
1369 
1370  if (n_aux > 0) {
1371  if (_method == SAT) {
1372  AuxVarBrancher::post(*this, def_int_varsel, def_int_valsel,
1373  def_bool_varsel, def_bool_valsel
1374 #ifdef GECODE_HAS_SET_VARS
1375  , def_set_varsel, def_set_valsel
1376 #endif
1377 #ifdef GECODE_HAS_FLOAT_VARS
1378  , def_float_varsel, def_float_valsel
1379 #endif
1380  );
1381  } else {
1382  {
1383  BrancherGroup bg;
1384  branch(bg(*this),iv_aux,def_int_varsel,def_int_valsel,
1385  NULL, &varValPrint<IntVar>);
1386  branchInfo.add(bg,def_int_rel_left,def_int_rel_right,iv_tmp_names);
1387  }
1388  {
1389  BrancherGroup bg;
1390  branch(bg(*this),bv_aux,def_bool_varsel,def_bool_valsel,
1391  NULL, &varValPrint<BoolVar>);
1392  branchInfo.add(bg,def_bool_rel_left,def_bool_rel_right,bv_tmp_names);
1393  }
1394  #ifdef GECODE_HAS_SET_VARS
1395  {
1396  BrancherGroup bg;
1397  branch(bg(*this),sv_aux,def_set_varsel,def_set_valsel,
1398  NULL, &varValPrint<SetVar>);
1399  branchInfo.add(bg,def_set_rel_left,def_set_rel_right,sv_tmp_names);
1400  }
1401  #endif
1402  #ifdef GECODE_HAS_FLOAT_VARS
1403  {
1404  BrancherGroup bg;
1405  branch(bg(*this),fv_aux,def_float_varsel,def_float_valsel,
1406  NULL, &varValPrintF);
1407  branchInfo.add(bg,def_float_rel_left,def_float_rel_right,fv_tmp_names);
1408  }
1409  #endif
1410 
1411  }
1412  }
1413  }
1414 
1415  AST::Array*
1417  return _solveAnnotations;
1418  }
1419 
1420  void
1422  _method = SAT;
1423  _solveAnnotations = ann;
1424  }
1425 
1426  void
1427  FlatZincSpace::minimize(int var, bool isInt, AST::Array* ann) {
1428  _method = MIN;
1429  _optVar = var;
1430  _optVarIsInt = isInt;
1431  _solveAnnotations = ann;
1432  }
1433 
1434  void
1435  FlatZincSpace::maximize(int var, bool isInt, AST::Array* ann) {
1436  _method = MAX;
1437  _optVar = var;
1438  _optVarIsInt = isInt;
1439  _solveAnnotations = ann;
1440  }
1441 
1443  delete _solveAnnotations;
1444  }
1445 
1446 #ifdef GECODE_HAS_GIST
1447 
1451  template<class Engine>
1452  class GistEngine {
1453  };
1454 
1456  template<typename S>
1457  class GistEngine<DFS<S> > {
1458  public:
1459  static void explore(S* root, const FlatZincOptions& opt,
1462  o.c_d = opt.c_d(); o.a_d = opt.a_d();
1463  o.inspect.click(i);
1464  o.inspect.compare(c);
1465  (void) Gecode::Gist::dfs(root, o);
1466  }
1467  };
1468 
1470  template<typename S>
1471  class GistEngine<BAB<S> > {
1472  public:
1473  static void explore(S* root, const FlatZincOptions& opt,
1476  o.c_d = opt.c_d(); o.a_d = opt.a_d();
1477  o.inspect.click(i);
1478  o.inspect.compare(c);
1479  (void) Gecode::Gist::bab(root, o);
1480  }
1481  };
1482 
1484  template<class S>
1487  private:
1488  const Printer& p;
1489  public:
1491  FZPrintingInspector(const Printer& p0);
1493  virtual void inspect(const Space& node);
1495  virtual void finalize(void);
1496  };
1497 
1498  template<class S>
1500  : TextOutput("Gecode/FlatZinc"), p(p0) {}
1501 
1502  template<class S>
1503  void
1505  init();
1506  dynamic_cast<const S&>(node).print(getStream(), p);
1507  getStream() << std::endl;
1508  }
1509 
1510  template<class S>
1511  void
1514  }
1515 
1516  template<class S>
1518  : public Gecode::Gist::VarComparator<S> {
1519  private:
1520  const Printer& p;
1521  public:
1523  FZPrintingComparator(const Printer& p0);
1524 
1526  virtual void compare(const Space& s0, const Space& s1);
1527  };
1528 
1529  template<class S>
1531  : Gecode::Gist::VarComparator<S>("Gecode/FlatZinc"), p(p0) {}
1532 
1533  template<class S>
1534  void
1536  this->init();
1537  try {
1538  dynamic_cast<const S&>(s0).compare(dynamic_cast<const S&>(s1),
1539  this->getStream(), p);
1540  } catch (Exception& e) {
1541  this->getStream() << "Exception: " << e.what();
1542  }
1543  this->getStream() << std::endl;
1544  }
1545 
1546 #endif
1547 
1548 
1549  template<template<class> class Engine>
1550  void
1551  FlatZincSpace::runEngine(std::ostream& out, const Printer& p,
1552  const FlatZincOptions& opt, Support::Timer& t_total) {
1553  if (opt.restart()==RM_NONE) {
1554  runMeta<Engine,Driver::EngineToMeta>(out,p,opt,t_total);
1555  } else {
1556  runMeta<Engine,RBS>(out,p,opt,t_total);
1557  }
1558  }
1559 
1560  template<template<class> class Engine,
1561  template<class,template<class> class> class Meta>
1562  void
1563  FlatZincSpace::runMeta(std::ostream& out, const Printer& p,
1564  const FlatZincOptions& opt, Support::Timer& t_total) {
1565 #ifdef GECODE_HAS_GIST
1566  if (opt.mode() == SM_GIST) {
1569  (void) GistEngine<Engine<FlatZincSpace> >::explore(this,opt,&pi,&pc);
1570  return;
1571  }
1572 #endif
1573  StatusStatistics sstat;
1574  unsigned int n_p = 0;
1575  Support::Timer t_solve;
1576  t_solve.start();
1577  if (status(sstat) != SS_FAILED) {
1578  n_p = PropagatorGroup::all.size(*this);
1579  }
1580  Search::Options o;
1581  o.stop = Driver::CombinedStop::create(opt.node(), opt.fail(), opt.time(),
1582  true);
1583  o.c_d = opt.c_d();
1584  o.a_d = opt.a_d();
1585 #ifdef GECODE_HAS_FLOAT_VARS
1586  step = opt.step();
1587 #endif
1588  o.threads = opt.threads();
1589  o.nogoods_limit = opt.nogoods() ? opt.nogoods_limit() : 0;
1591  if (opt.interrupt())
1593  Meta<FlatZincSpace,Engine> se(this,o);
1594  int noOfSolutions = opt.solutions();
1595  if (noOfSolutions == -1) {
1596  noOfSolutions = (_method == SAT) ? 1 : 0;
1597  }
1598  bool printAll = _method == SAT || opt.allSolutions() || noOfSolutions != 0;
1599  int findSol = noOfSolutions;
1600  FlatZincSpace* sol = NULL;
1601  while (FlatZincSpace* next_sol = se.next()) {
1602  delete sol;
1603  sol = next_sol;
1604  if (printAll) {
1605  sol->print(out, p);
1606  out << "----------" << std::endl;
1607  }
1608  if (--findSol==0)
1609  goto stopped;
1610  }
1611  if (sol && !printAll) {
1612  sol->print(out, p);
1613  out << "----------" << std::endl;
1614  }
1615  if (!se.stopped()) {
1616  if (sol) {
1617  out << "==========" << endl;
1618  } else {
1619  out << "=====UNSATISFIABLE=====" << endl;
1620  }
1621  } else if (!sol) {
1622  out << "=====UNKNOWN=====" << endl;
1623  }
1624  delete sol;
1625  stopped:
1626  if (opt.interrupt())
1628  if (opt.mode() == SM_STAT) {
1629  Gecode::Search::Statistics stat = se.statistics();
1630  out << endl
1631  << "%% runtime: ";
1632  Driver::stop(t_total,out);
1633  out << endl
1634  << "%% solvetime: ";
1635  Driver::stop(t_solve,out);
1636  out << endl
1637  << "%% solutions: "
1638  << std::abs(noOfSolutions - findSol) << endl
1639  << "%% variables: "
1640  << (intVarCount + boolVarCount + setVarCount) << endl
1641  << "%% propagators: " << n_p << endl
1642  << "%% propagations: " << sstat.propagate+stat.propagate << endl
1643  << "%% nodes: " << stat.node << endl
1644  << "%% failures: " << stat.fail << endl
1645  << "%% restarts: " << stat.restart << endl
1646  << "%% peak depth: " << stat.depth << endl
1647  << endl;
1648  }
1649  delete o.stop;
1650  }
1651 
1652 #ifdef GECODE_HAS_QT
1653  void
1654  FlatZincSpace::branchWithPlugin(AST::Node* ann) {
1655  if (AST::Call* c = dynamic_cast<AST::Call*>(ann)) {
1656  QString pluginName(c->id.c_str());
1657  if (QLibrary::isLibrary(pluginName+".dll")) {
1658  pluginName += ".dll";
1659  } else if (QLibrary::isLibrary(pluginName+".dylib")) {
1660  pluginName = "lib" + pluginName + ".dylib";
1661  } else if (QLibrary::isLibrary(pluginName+".so")) {
1662  // Must check .so after .dylib so that Mac OS uses .dylib
1663  pluginName = "lib" + pluginName + ".so";
1664  }
1665  QPluginLoader pl(pluginName);
1666  QObject* plugin_o = pl.instance();
1667  if (!plugin_o) {
1668  throw FlatZinc::Error("FlatZinc",
1669  "Error loading plugin "+pluginName.toStdString()+
1670  ": "+pl.errorString().toStdString());
1671  }
1672  BranchPlugin* pb = qobject_cast<BranchPlugin*>(plugin_o);
1673  if (!pb) {
1674  throw FlatZinc::Error("FlatZinc",
1675  "Error loading plugin "+pluginName.toStdString()+
1676  ": does not contain valid PluginBrancher");
1677  }
1678  pb->branch(*this, c);
1679  }
1680  }
1681 #else
1682  void
1683  FlatZincSpace::branchWithPlugin(AST::Node*) {
1684  throw FlatZinc::Error("FlatZinc",
1685  "Branching with plugins not supported (requires Qt support)");
1686  }
1687 #endif
1688 
1689  void
1690  FlatZincSpace::run(std::ostream& out, const Printer& p,
1691  const FlatZincOptions& opt, Support::Timer& t_total) {
1692  switch (_method) {
1693  case MIN:
1694  case MAX:
1695  runEngine<BAB>(out,p,opt,t_total);
1696  break;
1697  case SAT:
1698  runEngine<DFS>(out,p,opt,t_total);
1699  break;
1700  }
1701  }
1702 
1703  void
1705  if (_optVarIsInt) {
1706  if (_method == MIN)
1707  rel(*this, iv[_optVar], IRT_LE,
1708  static_cast<const FlatZincSpace*>(&s)->iv[_optVar].val());
1709  else if (_method == MAX)
1710  rel(*this, iv[_optVar], IRT_GR,
1711  static_cast<const FlatZincSpace*>(&s)->iv[_optVar].val());
1712  } else {
1713 #ifdef GECODE_HAS_FLOAT_VARS
1714  if (_method == MIN)
1715  rel(*this, fv[_optVar], FRT_LE,
1716  static_cast<const FlatZincSpace*>(&s)->fv[_optVar].val()-step);
1717  else if (_method == MAX)
1718  rel(*this, fv[_optVar], FRT_GR,
1719  static_cast<const FlatZincSpace*>(&s)->fv[_optVar].val()+step);
1720 #endif
1721  }
1722  }
1723 
1724  bool
1726  if ((mi.type() == MetaInfo::RESTART) && (mi.restart() != 0) &&
1727  (_lns > 0) && (mi.last()==NULL) && (_lnsInitialSolution.size()>0)) {
1728  for (unsigned int i=iv_lns.size(); i--;) {
1729  if ((*_random)(99) <= _lns) {
1730  rel(*this, iv_lns[i], IRT_EQ, _lnsInitialSolution[i]);
1731  }
1732  }
1733  return false;
1734  } else if ((mi.type() == MetaInfo::RESTART) && (mi.restart() != 0) &&
1735  (_lns > 0) && mi.last()) {
1736  const FlatZincSpace& last =
1737  static_cast<const FlatZincSpace&>(*mi.last());
1738  for (unsigned int i=iv_lns.size(); i--;) {
1739  if ((*_random)(99) <= _lns) {
1740  rel(*this, iv_lns[i], IRT_EQ, last.iv_lns[i]);
1741  }
1742  }
1743  return false;
1744  }
1745  return true;
1746  }
1747 
1748  Space*
1749  FlatZincSpace::copy(bool share) {
1750  return new FlatZincSpace(share, *this);
1751  }
1752 
1755  return _method;
1756  }
1757 
1758  int
1760  return _optVar;
1761  }
1762 
1763  bool
1765  return _optVarIsInt;
1766  }
1767 
1768  void
1769  FlatZincSpace::print(std::ostream& out, const Printer& p) const {
1770  p.print(out, iv, bv
1771 #ifdef GECODE_HAS_SET_VARS
1772  , sv
1773 #endif
1774 #ifdef GECODE_HAS_FLOAT_VARS
1775  , fv
1776 #endif
1777  );
1778  }
1779 
1780  void
1781  FlatZincSpace::compare(const Space& s, std::ostream& out) const {
1782  (void) s; (void) out;
1783 #ifdef GECODE_HAS_GIST
1784  const FlatZincSpace& fs = dynamic_cast<const FlatZincSpace&>(s);
1785  for (int i = 0; i < iv.size(); ++i) {
1786  std::stringstream ss;
1787  ss << "iv[" << i << "]";
1788  std::string result(Gecode::Gist::Comparator::compare(ss.str(), iv[i],
1789  fs.iv[i]));
1790  if (result.length() > 0) out << result << std::endl;
1791  }
1792  for (int i = 0; i < bv.size(); ++i) {
1793  std::stringstream ss;
1794  ss << "bv[" << i << "]";
1795  std::string result(Gecode::Gist::Comparator::compare(ss.str(), bv[i],
1796  fs.bv[i]));
1797  if (result.length() > 0) out << result << std::endl;
1798  }
1799 #ifdef GECODE_HAS_SET_VARS
1800  for (int i = 0; i < sv.size(); ++i) {
1801  std::stringstream ss;
1802  ss << "sv[" << i << "]";
1803  std::string result(Gecode::Gist::Comparator::compare(ss.str(), sv[i],
1804  fs.sv[i]));
1805  if (result.length() > 0) out << result << std::endl;
1806  }
1807 #endif
1808 #ifdef GECODE_HAS_FLOAT_VARS
1809  for (int i = 0; i < fv.size(); ++i) {
1810  std::stringstream ss;
1811  ss << "fv[" << i << "]";
1812  std::string result(Gecode::Gist::Comparator::compare(ss.str(), fv[i],
1813  fs.fv[i]));
1814  if (result.length() > 0) out << result << std::endl;
1815  }
1816 #endif
1817 #endif
1818  }
1819 
1820  void
1821  FlatZincSpace::compare(const FlatZincSpace& s, std::ostream& out,
1822  const Printer& p) const {
1823  p.printDiff(out, iv, s.iv, bv, s.bv
1824 #ifdef GECODE_HAS_SET_VARS
1825  , sv, s.sv
1826 #endif
1827 #ifdef GECODE_HAS_FLOAT_VARS
1828  , fv, s.fv
1829 #endif
1830  );
1831  }
1832 
1833  void
1835  p.shrinkArrays(*this, _optVar, _optVarIsInt, iv, bv
1836 #ifdef GECODE_HAS_SET_VARS
1837  , sv
1838 #endif
1839 #ifdef GECODE_HAS_FLOAT_VARS
1840  , fv
1841 #endif
1842  );
1843  }
1844 
1845  IntArgs
1847  AST::Array* a = arg->getArray();
1848  IntArgs ia(a->a.size()+offset);
1849  for (int i=offset; i--;)
1850  ia[i] = 0;
1851  for (int i=a->a.size(); i--;)
1852  ia[i+offset] = a->a[i]->getInt();
1853  return ia;
1854  }
1855  IntArgs
1857  AST::Array* a = arg->getArray();
1858  IntArgs ia(a->a.size()+offset);
1859  for (int i=offset; i--;)
1860  ia[i] = 0;
1861  for (int i=a->a.size(); i--;)
1862  ia[i+offset] = a->a[i]->getBool();
1863  return ia;
1864  }
1865  IntSet
1867  AST::SetLit* sl = n->getSet();
1868  IntSet d;
1869  if (sl->interval) {
1870  d = IntSet(sl->min, sl->max);
1871  } else {
1872  Region re(*this);
1873  int* is = re.alloc<int>(static_cast<unsigned long int>(sl->s.size()));
1874  for (int i=sl->s.size(); i--; )
1875  is[i] = sl->s[i];
1876  d = IntSet(is, sl->s.size());
1877  }
1878  return d;
1879  }
1880  IntSetArgs
1882  AST::Array* a = arg->getArray();
1883  if (a->a.size() == 0) {
1884  IntSetArgs emptyIa(0);
1885  return emptyIa;
1886  }
1887  IntSetArgs ia(a->a.size()+offset);
1888  for (int i=offset; i--;)
1889  ia[i] = IntSet::empty;
1890  for (int i=a->a.size(); i--;) {
1891  ia[i+offset] = arg2intset(a->a[i]);
1892  }
1893  return ia;
1894  }
1895  IntVarArgs
1897  AST::Array* a = arg->getArray();
1898  if (a->a.size() == 0) {
1899  IntVarArgs emptyIa(0);
1900  return emptyIa;
1901  }
1902  IntVarArgs ia(a->a.size()+offset);
1903  for (int i=offset; i--;)
1904  ia[i] = IntVar(*this, 0, 0);
1905  for (int i=a->a.size(); i--;) {
1906  if (a->a[i]->isIntVar()) {
1907  ia[i+offset] = iv[a->a[i]->getIntVar()];
1908  } else {
1909  int value = a->a[i]->getInt();
1910  IntVar iv(*this, value, value);
1911  ia[i+offset] = iv;
1912  }
1913  }
1914  return ia;
1915  }
1916  BoolVarArgs
1917  FlatZincSpace::arg2boolvarargs(AST::Node* arg, int offset, int siv) {
1918  AST::Array* a = arg->getArray();
1919  if (a->a.size() == 0) {
1920  BoolVarArgs emptyIa(0);
1921  return emptyIa;
1922  }
1923  BoolVarArgs ia(a->a.size()+offset-(siv==-1?0:1));
1924  for (int i=offset; i--;)
1925  ia[i] = BoolVar(*this, 0, 0);
1926  for (int i=0; i<static_cast<int>(a->a.size()); i++) {
1927  if (i==siv)
1928  continue;
1929  if (a->a[i]->isBool()) {
1930  bool value = a->a[i]->getBool();
1931  BoolVar iv(*this, value, value);
1932  ia[offset++] = iv;
1933  } else if (a->a[i]->isIntVar() &&
1934  aliasBool2Int(a->a[i]->getIntVar()) != -1) {
1935  ia[offset++] = bv[aliasBool2Int(a->a[i]->getIntVar())];
1936  } else {
1937  ia[offset++] = bv[a->a[i]->getBoolVar()];
1938  }
1939  }
1940  return ia;
1941  }
1942  BoolVar
1944  BoolVar x0;
1945  if (n->isBool()) {
1946  x0 = BoolVar(*this, n->getBool(), n->getBool());
1947  }
1948  else {
1949  x0 = bv[n->getBoolVar()];
1950  }
1951  return x0;
1952  }
1953  IntVar
1955  IntVar x0;
1956  if (n->isIntVar()) {
1957  x0 = iv[n->getIntVar()];
1958  } else {
1959  x0 = IntVar(*this, n->getInt(), n->getInt());
1960  }
1961  return x0;
1962  }
1963  bool
1965  AST::Array* a = b->getArray();
1966  singleInt = -1;
1967  if (a->a.size() == 0)
1968  return true;
1969  for (int i=a->a.size(); i--;) {
1970  if (a->a[i]->isBoolVar() || a->a[i]->isBool()) {
1971  } else if (a->a[i]->isIntVar()) {
1972  if (aliasBool2Int(a->a[i]->getIntVar()) == -1) {
1973  if (singleInt != -1) {
1974  return false;
1975  }
1976  singleInt = i;
1977  }
1978  } else {
1979  return false;
1980  }
1981  }
1982  return singleInt==-1 || a->a.size() > 1;
1983  }
1984 #ifdef GECODE_HAS_SET_VARS
1985  SetVar
1987  SetVar x0;
1988  if (!n->isSetVar()) {
1989  IntSet d = arg2intset(n);
1990  x0 = SetVar(*this, d, d);
1991  } else {
1992  x0 = sv[n->getSetVar()];
1993  }
1994  return x0;
1995  }
1996  SetVarArgs
1997  FlatZincSpace::arg2setvarargs(AST::Node* arg, int offset, int doffset,
1998  const IntSet& od) {
1999  AST::Array* a = arg->getArray();
2000  SetVarArgs ia(a->a.size()+offset);
2001  for (int i=offset; i--;) {
2002  IntSet d = i<doffset ? od : IntSet::empty;
2003  ia[i] = SetVar(*this, d, d);
2004  }
2005  for (int i=a->a.size(); i--;) {
2006  ia[i+offset] = arg2SetVar(a->a[i]);
2007  }
2008  return ia;
2009  }
2010 #endif
2011 #ifdef GECODE_HAS_FLOAT_VARS
2012  FloatValArgs
2014  AST::Array* a = arg->getArray();
2015  FloatValArgs fa(a->a.size()+offset);
2016  for (int i=offset; i--;)
2017  fa[i] = 0.0;
2018  for (int i=a->a.size(); i--;)
2019  fa[i+offset] = a->a[i]->getFloat();
2020  return fa;
2021  }
2022  FloatVarArgs
2024  AST::Array* a = arg->getArray();
2025  if (a->a.size() == 0) {
2026  FloatVarArgs emptyFa(0);
2027  return emptyFa;
2028  }
2029  FloatVarArgs fa(a->a.size()+offset);
2030  for (int i=offset; i--;)
2031  fa[i] = FloatVar(*this, 0.0, 0.0);
2032  for (int i=a->a.size(); i--;) {
2033  if (a->a[i]->isFloatVar()) {
2034  fa[i+offset] = fv[a->a[i]->getFloatVar()];
2035  } else {
2036  double value = a->a[i]->getFloat();
2037  FloatVar fv(*this, value, value);
2038  fa[i+offset] = fv;
2039  }
2040  }
2041  return fa;
2042  }
2043  FloatVar
2045  FloatVar x0;
2046  if (n->isFloatVar()) {
2047  x0 = fv[n->getFloatVar()];
2048  } else {
2049  x0 = FloatVar(*this, n->getFloat(), n->getFloat());
2050  }
2051  return x0;
2052  }
2053 #endif
2054  IntPropLevel
2056  if (ann) {
2057  if (ann->hasAtom("val"))
2058  return IPL_VAL;
2059  if (ann->hasAtom("domain"))
2060  return IPL_DOM;
2061  if (ann->hasAtom("bounds") ||
2062  ann->hasAtom("boundsR") ||
2063  ann->hasAtom("boundsD") ||
2064  ann->hasAtom("boundsZ"))
2065  return IPL_BND;
2066  }
2067  return IPL_DEF;
2068  }
2069 
2070 
2071  void
2073  _output = output;
2074  }
2075 
2076  void
2077  Printer::printElem(std::ostream& out,
2078  AST::Node* ai,
2079  const Gecode::IntVarArray& iv,
2080  const Gecode::BoolVarArray& bv
2081 #ifdef GECODE_HAS_SET_VARS
2082  , const Gecode::SetVarArray& sv
2083 #endif
2084 #ifdef GECODE_HAS_FLOAT_VARS
2085  ,
2086  const Gecode::FloatVarArray& fv
2087 #endif
2088  ) const {
2089  int k;
2090  if (ai->isInt(k)) {
2091  out << k;
2092  } else if (ai->isIntVar()) {
2093  out << iv[ai->getIntVar()];
2094  } else if (ai->isBoolVar()) {
2095  if (bv[ai->getBoolVar()].min() == 1) {
2096  out << "true";
2097  } else if (bv[ai->getBoolVar()].max() == 0) {
2098  out << "false";
2099  } else {
2100  out << "false..true";
2101  }
2102 #ifdef GECODE_HAS_SET_VARS
2103  } else if (ai->isSetVar()) {
2104  if (!sv[ai->getSetVar()].assigned()) {
2105  out << sv[ai->getSetVar()];
2106  return;
2107  }
2108  SetVarGlbRanges svr(sv[ai->getSetVar()]);
2109  if (!svr()) {
2110  out << "{}";
2111  return;
2112  }
2113  int min = svr.min();
2114  int max = svr.max();
2115  ++svr;
2116  if (svr()) {
2117  SetVarGlbValues svv(sv[ai->getSetVar()]);
2118  int i = svv.val();
2119  out << "{" << i;
2120  ++svv;
2121  for (; svv(); ++svv)
2122  out << ", " << svv.val();
2123  out << "}";
2124  } else {
2125  out << min << ".." << max;
2126  }
2127 #endif
2128 #ifdef GECODE_HAS_FLOAT_VARS
2129  } else if (ai->isFloatVar()) {
2130  if (fv[ai->getFloatVar()].assigned()) {
2131  FloatVal vv = fv[ai->getFloatVar()].val();
2132  FloatNum v;
2133  if (vv.singleton())
2134  v = vv.min();
2135  else if (vv < 0.0)
2136  v = vv.max();
2137  else
2138  v = vv.min();
2139  std::ostringstream oss;
2140  // oss << std::scientific;
2141  oss << std::setprecision(std::numeric_limits<double>::digits10);
2142  oss << v;
2143  if (oss.str().find(".") == std::string::npos)
2144  oss << ".0";
2145  out << oss.str();
2146  } else {
2147  out << fv[ai->getFloatVar()];
2148  }
2149 #endif
2150  } else if (ai->isBool()) {
2151  out << (ai->getBool() ? "true" : "false");
2152  } else if (ai->isSet()) {
2153  AST::SetLit* s = ai->getSet();
2154  if (s->interval) {
2155  out << s->min << ".." << s->max;
2156  } else {
2157  out << "{";
2158  for (unsigned int i=0; i<s->s.size(); i++) {
2159  out << s->s[i] << (i < s->s.size()-1 ? ", " : "}");
2160  }
2161  }
2162  } else if (ai->isString()) {
2163  std::string s = ai->getString();
2164  for (unsigned int i=0; i<s.size(); i++) {
2165  if (s[i] == '\\' && i<s.size()-1) {
2166  switch (s[i+1]) {
2167  case 'n': out << "\n"; break;
2168  case '\\': out << "\\"; break;
2169  case 't': out << "\t"; break;
2170  default: out << "\\" << s[i+1];
2171  }
2172  i++;
2173  } else {
2174  out << s[i];
2175  }
2176  }
2177  }
2178  }
2179 
2180  void
2181  Printer::printElemDiff(std::ostream& out,
2182  AST::Node* ai,
2183  const Gecode::IntVarArray& iv1,
2184  const Gecode::IntVarArray& iv2,
2185  const Gecode::BoolVarArray& bv1,
2186  const Gecode::BoolVarArray& bv2
2187 #ifdef GECODE_HAS_SET_VARS
2188  , const Gecode::SetVarArray& sv1,
2189  const Gecode::SetVarArray& sv2
2190 #endif
2191 #ifdef GECODE_HAS_FLOAT_VARS
2192  , const Gecode::FloatVarArray& fv1,
2193  const Gecode::FloatVarArray& fv2
2194 #endif
2195  ) const {
2196 #ifdef GECODE_HAS_GIST
2197  using namespace Gecode::Gist;
2198  int k;
2199  if (ai->isInt(k)) {
2200  out << k;
2201  } else if (ai->isIntVar()) {
2202  std::string res(Comparator::compare("",iv1[ai->getIntVar()],
2203  iv2[ai->getIntVar()]));
2204  if (res.length() > 0) {
2205  res.erase(0, 1); // Remove '='
2206  out << res;
2207  } else {
2208  out << iv1[ai->getIntVar()];
2209  }
2210  } else if (ai->isBoolVar()) {
2211  std::string res(Comparator::compare("",bv1[ai->getBoolVar()],
2212  bv2[ai->getBoolVar()]));
2213  if (res.length() > 0) {
2214  res.erase(0, 1); // Remove '='
2215  out << res;
2216  } else {
2217  out << bv1[ai->getBoolVar()];
2218  }
2219 #ifdef GECODE_HAS_SET_VARS
2220  } else if (ai->isSetVar()) {
2221  std::string res(Comparator::compare("",sv1[ai->getSetVar()],
2222  sv2[ai->getSetVar()]));
2223  if (res.length() > 0) {
2224  res.erase(0, 1); // Remove '='
2225  out << res;
2226  } else {
2227  out << sv1[ai->getSetVar()];
2228  }
2229 #endif
2230 #ifdef GECODE_HAS_FLOAT_VARS
2231  } else if (ai->isFloatVar()) {
2232  std::string res(Comparator::compare("",fv1[ai->getFloatVar()],
2233  fv2[ai->getFloatVar()]));
2234  if (res.length() > 0) {
2235  res.erase(0, 1); // Remove '='
2236  out << res;
2237  } else {
2238  out << fv1[ai->getFloatVar()];
2239  }
2240 #endif
2241  } else if (ai->isBool()) {
2242  out << (ai->getBool() ? "true" : "false");
2243  } else if (ai->isSet()) {
2244  AST::SetLit* s = ai->getSet();
2245  if (s->interval) {
2246  out << s->min << ".." << s->max;
2247  } else {
2248  out << "{";
2249  for (unsigned int i=0; i<s->s.size(); i++) {
2250  out << s->s[i] << (i < s->s.size()-1 ? ", " : "}");
2251  }
2252  }
2253  } else if (ai->isString()) {
2254  std::string s = ai->getString();
2255  for (unsigned int i=0; i<s.size(); i++) {
2256  if (s[i] == '\\' && i<s.size()-1) {
2257  switch (s[i+1]) {
2258  case 'n': out << "\n"; break;
2259  case '\\': out << "\\"; break;
2260  case 't': out << "\t"; break;
2261  default: out << "\\" << s[i+1];
2262  }
2263  i++;
2264  } else {
2265  out << s[i];
2266  }
2267  }
2268  }
2269 #else
2270  (void) out;
2271  (void) ai;
2272  (void) iv1;
2273  (void) iv2;
2274  (void) bv1;
2275  (void) bv2;
2276 #ifdef GECODE_HAS_SET_VARS
2277  (void) sv1;
2278  (void) sv2;
2279 #endif
2280 #ifdef GECODE_HAS_FLOAT_VARS
2281  (void) fv1;
2282  (void) fv2;
2283 #endif
2284 
2285 #endif
2286  }
2287 
2288  void
2289  Printer::print(std::ostream& out,
2290  const Gecode::IntVarArray& iv,
2291  const Gecode::BoolVarArray& bv
2292 #ifdef GECODE_HAS_SET_VARS
2293  ,
2294  const Gecode::SetVarArray& sv
2295 #endif
2296 #ifdef GECODE_HAS_FLOAT_VARS
2297  ,
2298  const Gecode::FloatVarArray& fv
2299 #endif
2300  ) const {
2301  if (_output == NULL)
2302  return;
2303  for (unsigned int i=0; i< _output->a.size(); i++) {
2304  AST::Node* ai = _output->a[i];
2305  if (ai->isArray()) {
2306  AST::Array* aia = ai->getArray();
2307  int size = aia->a.size();
2308  out << "[";
2309  for (int j=0; j<size; j++) {
2310  printElem(out,aia->a[j],iv,bv
2311 #ifdef GECODE_HAS_SET_VARS
2312  ,sv
2313 #endif
2314 #ifdef GECODE_HAS_FLOAT_VARS
2315  ,fv
2316 #endif
2317  );
2318  if (j<size-1)
2319  out << ", ";
2320  }
2321  out << "]";
2322  } else {
2323  printElem(out,ai,iv,bv
2324 #ifdef GECODE_HAS_SET_VARS
2325  ,sv
2326 #endif
2327 #ifdef GECODE_HAS_FLOAT_VARS
2328  ,fv
2329 #endif
2330  );
2331  }
2332  }
2333  }
2334 
2335  void
2336  Printer::printDiff(std::ostream& out,
2337  const Gecode::IntVarArray& iv1,
2338  const Gecode::IntVarArray& iv2,
2339  const Gecode::BoolVarArray& bv1,
2340  const Gecode::BoolVarArray& bv2
2341 #ifdef GECODE_HAS_SET_VARS
2342  ,
2343  const Gecode::SetVarArray& sv1,
2344  const Gecode::SetVarArray& sv2
2345 #endif
2346 #ifdef GECODE_HAS_FLOAT_VARS
2347  ,
2348  const Gecode::FloatVarArray& fv1,
2349  const Gecode::FloatVarArray& fv2
2350 #endif
2351  ) const {
2352  if (_output == NULL)
2353  return;
2354  for (unsigned int i=0; i< _output->a.size(); i++) {
2355  AST::Node* ai = _output->a[i];
2356  if (ai->isArray()) {
2357  AST::Array* aia = ai->getArray();
2358  int size = aia->a.size();
2359  out << "[";
2360  for (int j=0; j<size; j++) {
2361  printElemDiff(out,aia->a[j],iv1,iv2,bv1,bv2
2362 #ifdef GECODE_HAS_SET_VARS
2363  ,sv1,sv2
2364 #endif
2365 #ifdef GECODE_HAS_FLOAT_VARS
2366  ,fv1,fv2
2367 #endif
2368  );
2369  if (j<size-1)
2370  out << ", ";
2371  }
2372  out << "]";
2373  } else {
2374  printElemDiff(out,ai,iv1,iv2,bv1,bv2
2375 #ifdef GECODE_HAS_SET_VARS
2376  ,sv1,sv2
2377 #endif
2378 #ifdef GECODE_HAS_FLOAT_VARS
2379  ,fv1,fv2
2380 #endif
2381  );
2382  }
2383  }
2384  }
2385 
2386  void
2387  Printer::addIntVarName(const std::string& n) {
2388  iv_names.push_back(n);
2389  }
2390  void
2391  Printer::addBoolVarName(const std::string& n) {
2392  bv_names.push_back(n);
2393  }
2394 #ifdef GECODE_HAS_FLOAT_VARS
2395  void
2396  Printer::addFloatVarName(const std::string& n) {
2397  fv_names.push_back(n);
2398  }
2399 #endif
2400 #ifdef GECODE_HAS_SET_VARS
2401  void
2402  Printer::addSetVarName(const std::string& n) {
2403  sv_names.push_back(n);
2404  }
2405 #endif
2406 
2407  void
2409  std::map<int,int>& iv, std::map<int,int>& bv,
2410  std::map<int,int>& sv, std::map<int,int>& fv) {
2411  if (node->isIntVar()) {
2412  AST::IntVar* x = static_cast<AST::IntVar*>(node);
2413  if (iv.find(x->i) == iv.end()) {
2414  int newi = iv.size();
2415  iv[x->i] = newi;
2416  }
2417  x->i = iv[x->i];
2418  } else if (node->isBoolVar()) {
2419  AST::BoolVar* x = static_cast<AST::BoolVar*>(node);
2420  if (bv.find(x->i) == bv.end()) {
2421  int newi = bv.size();
2422  bv[x->i] = newi;
2423  }
2424  x->i = bv[x->i];
2425  } else if (node->isSetVar()) {
2426  AST::SetVar* x = static_cast<AST::SetVar*>(node);
2427  if (sv.find(x->i) == sv.end()) {
2428  int newi = sv.size();
2429  sv[x->i] = newi;
2430  }
2431  x->i = sv[x->i];
2432  } else if (node->isFloatVar()) {
2433  AST::FloatVar* x = static_cast<AST::FloatVar*>(node);
2434  if (fv.find(x->i) == fv.end()) {
2435  int newi = fv.size();
2436  fv[x->i] = newi;
2437  }
2438  x->i = fv[x->i];
2439  }
2440  }
2441 
2442  void
2444  int& optVar, bool optVarIsInt,
2445  Gecode::IntVarArray& iv,
2447 #ifdef GECODE_HAS_SET_VARS
2448  ,
2450 #endif
2451 #ifdef GECODE_HAS_FLOAT_VARS
2452  ,
2454 #endif
2455  ) {
2456  if (_output == NULL) {
2457  if (optVarIsInt && optVar != -1) {
2458  IntVar ov = iv[optVar];
2459  iv = IntVarArray(home, 1);
2460  iv[0] = ov;
2461  optVar = 0;
2462  } else {
2463  iv = IntVarArray(home, 0);
2464  }
2465  bv = BoolVarArray(home, 0);
2466 #ifdef GECODE_HAS_SET_VARS
2467  sv = SetVarArray(home, 0);
2468 #endif
2469 #ifdef GECODE_HAS_FLOAT_VARS
2470  if (!optVarIsInt && optVar != -1) {
2471  FloatVar ov = fv[optVar];
2472  fv = FloatVarArray(home, 1);
2473  fv[0] = ov;
2474  optVar = 0;
2475  } else {
2476  fv = FloatVarArray(home,0);
2477  }
2478 #endif
2479  return;
2480  }
2481  std::map<int,int> iv_new;
2482  std::map<int,int> bv_new;
2483  std::map<int,int> sv_new;
2484  std::map<int,int> fv_new;
2485 
2486  if (optVar != -1) {
2487  if (optVarIsInt)
2488  iv_new[optVar] = 0;
2489  else
2490  fv_new[optVar] = 0;
2491  optVar = 0;
2492  }
2493 
2494  for (unsigned int i=0; i< _output->a.size(); i++) {
2495  AST::Node* ai = _output->a[i];
2496  if (ai->isArray()) {
2497  AST::Array* aia = ai->getArray();
2498  for (unsigned int j=0; j<aia->a.size(); j++) {
2499  shrinkElement(aia->a[j],iv_new,bv_new,sv_new,fv_new);
2500  }
2501  } else {
2502  shrinkElement(ai,iv_new,bv_new,sv_new,fv_new);
2503  }
2504  }
2505 
2506  IntVarArgs iva(iv_new.size());
2507  for (map<int,int>::iterator i=iv_new.begin(); i != iv_new.end(); ++i) {
2508  iva[(*i).second] = iv[(*i).first];
2509  }
2510  iv = IntVarArray(home, iva);
2511 
2512  BoolVarArgs bva(bv_new.size());
2513  for (map<int,int>::iterator i=bv_new.begin(); i != bv_new.end(); ++i) {
2514  bva[(*i).second] = bv[(*i).first];
2515  }
2516  bv = BoolVarArray(home, bva);
2517 
2518 #ifdef GECODE_HAS_SET_VARS
2519  SetVarArgs sva(sv_new.size());
2520  for (map<int,int>::iterator i=sv_new.begin(); i != sv_new.end(); ++i) {
2521  sva[(*i).second] = sv[(*i).first];
2522  }
2523  sv = SetVarArray(home, sva);
2524 #endif
2525 
2526 #ifdef GECODE_HAS_FLOAT_VARS
2527  FloatVarArgs fva(fv_new.size());
2528  for (map<int,int>::iterator i=fv_new.begin(); i != fv_new.end(); ++i) {
2529  fva[(*i).second] = fv[(*i).first];
2530  }
2531  fv = FloatVarArray(home, fva);
2532 #endif
2533  }
2534 
2536  delete _output;
2537  }
2538 
2539 }}
2540 
2541 // 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:1834
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:455
Bounds propagation.
Definition: int.hh:945
Which values to select for branching first.
Definition: set.hh:1381
Gecode::SetVarArray sv_aux
The introduced set variables.
Definition: flatzinc.hh:477
SetVarBranch SET_VAR_AFC_MIN(double d, BranchTbl tbl)
Select variable with smallest accumulated failure count with decay factor d.
Definition: var.hpp:123
int floatVarCount
Number of float variables.
Definition: flatzinc.hh:414
const Gecode::FloatNum step
Definition: arithmetic.cpp:789
Passing float arguments.
Definition: float.hh:952
Option< AST::SetLit *> domain
Definition: varspec.hh:78
Options for running FlatZinc models
Definition: flatzinc.hh:230
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:467
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:344
Combine variable selection criteria for tie-breaking.
IntSet vs2is(IntVarSpec *vs)
Definition: flatzinc.cpp:329
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:387
Which values to select for branching first.
Definition: float.hh:1665
std::ostream & getStream(void)
Get the stream that is used to output text.
Definition: gist.cpp:89
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:1846
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:1669
Traits class for search engines.
Definition: flatzinc.cpp:1452
SetVarBranch SET_VAR_NONE(void)
Select first unassigned variable.
Definition: var.hpp:91
Search engine statistics
Definition: search.hh:140
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:2023
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:1749
std::vector< bool > sv_introduced
Indicates whether a set variable is introduced by mzn2fzn.
Definition: flatzinc.hh:479
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:846
#define GECODE_HAS_SET_VARS
Definition: config.hpp:47
Gecode::BoolVarArray bv
The Boolean variables.
Definition: flatzinc.hh:468
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:424
unsigned int c_d
Create a clone after every c_d commits (commit distance)
Definition: search.hh:453
Cutoff generator appending two cutoff generators.
Definition: search.hh:336
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:530
Which values to select for branching first.
Definition: int.hh:4153
Search engine options
Definition: search.hh:446
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:729
Group of branchers.
Definition: core.hpp:848
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
int getFloatVar(void)
Cast this node to a Float variable node.
Definition: ast.hh:432
Gecode::ScriptMode mode(void) const
Definition: flatzinc.hh:339
Gecode::IntVarArray iv
The integer variables.
Definition: flatzinc.hh:456
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
static PropagatorGroup all
Group of all propagators.
Definition: core.hpp:838
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
Passing float variables.
Definition: float.hh:979
Specification for set variables.
Definition: varspec.hh:143
virtual void compare(const Space &s0, const Space &s1)
Use the compare method of the template class S to compare two spaces.
Definition: flatzinc.cpp:1535
BranchInformation branchInfo
Information for printing branches.
Definition: flatzinc.hh:576
void compare(const Space &s, std::ostream &out) const
Compare this space with space s and print the differences on out.
Definition: flatzinc.cpp:1781
int boolVarCount
Number of Boolean variables.
Definition: flatzinc.hh:412
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:1764
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:1427
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:143
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
Information is provided by a restart-based engine.
Definition: core.hpp:1547
unsigned long int depth
Maximum depth of search stack.
Definition: search.hh:147
TieBreak< IntVarBranch > ann2ivarsel(AST::Node *ann, Rnd rnd, double decay)
Definition: flatzinc.cpp:373
Integer variable array.
Definition: int.hh:742
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:604
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:1071
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:361
Space * clone(bool share_data=true, bool share_info=true, CloneStatistics &stat=unused_clone) const
Clone space.
Definition: core.hpp:3258
void init(int intVars, int boolVars, int setVars, int floatVars)
Initialize space with given number of variables.
Definition: flatzinc.cpp:704
Handle to region.
Definition: region.hpp:61
Greater ( )
Definition: int.hh:910
static void explore(S *root, const FlatZincOptions &opt, Gist::Inspector *i, Gist::Comparator *c)
Definition: flatzinc.cpp:1459
void varValPrint(const Space &home, const Brancher &b, unsigned int a, Var, int i, const int &n, std::ostream &o)
Definition: flatzinc.cpp:305
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:1754
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:1623
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
unsigned int id(void) const
Return a unique id for the group.
Definition: core.hpp:4755
A thread-safe random number generator.
Definition: flatzinc.hh:384
const int max
Largest allowed integer value.
Definition: int.hh:114
Float variable array.
Definition: float.hh:1029
int vs2bsl(BoolVarSpec *bs)
Definition: flatzinc.cpp:349
Computation spaces.
Definition: core.hpp:1672
An inspector for printing simple text output.
Definition: flatzinc.cpp:1485
Abstract base class for inspectors.
Definition: gist.hh:103
FloatVarBranch FLOAT_VAR_NONE(void)
Select first unassigned variable.
Definition: var.hpp:92
unsigned int size(Space &home) const
Return number of propagators in a group.
Definition: core.cpp:762
const int min
Smallest allowed integer value.
Definition: int.hh:116
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:682
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:1620
void newSetVar(SetVarSpec *vs)
Create new set variable from specification.
Definition: flatzinc.cpp:768
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
std::vector< bool > iv_introduced
Indicates whether an integer variable is introduced by mzn2fzn.
Definition: flatzinc.hh:464
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:756
Gecode::Support::Mutex mutex
A mutex for the random number generator.
Definition: flatzinc.hh:389
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:4173
bool alias
Whether the variable aliases another variable.
Definition: varspec.hh:63
SetVarBranch ann2svarsel(AST::Node *ann, Rnd rnd, double decay)
Definition: flatzinc.cpp:492
void start(void)
Start timer.
Definition: timer.hpp:70
SetVar arg2SetVar(AST::Node *n)
Convert n to SetVar.
Definition: flatzinc.cpp:1986
unsigned int nogoods_limit(void) const
Definition: flatzinc.hh:350
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)
void 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
void add(BrancherGroup bg, const string &rel0, const string &rel1, const vector< string > &n)
Add new brancher information.
Definition: flatzinc.cpp:249
Cutoff * cutoff
Cutoff for restart-based search.
Definition: search.hh:471
int optVar(void) const
Return index of variable used for optimization.
Definition: flatzinc.cpp:1759
double threads
Number of threads to use.
Definition: search.hh:451
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
struct Gecode::@554::NNF::@60::@62 a
For atomic nodes.
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
T * alloc(long unsigned int n)
Allocate block of n objects of type T from heap.
Definition: heap.hpp:435
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:483
const FloatNum min
Smallest allowed float value.
Definition: float.hh:848
Gecode::IntArgs i(4, 1, 2, 3, 4)
IntAssign ann2asnivalsel(AST::Node *ann, Rnd rnd)
Definition: flatzinc.cpp:473
Base-class for branchers.
Definition: core.hpp:1364
FloatNum n
The middle value for branching.
Definition: float.hh:1394
void assign(Home home, const FloatVarArgs &x, FloatAssign fa, FloatBranchFilter bf, FloatVarValPrint vvp)
Assign all x with value selection vals.
Definition: branch.cpp:113
virtual bool status(const Space &_home) const
Check status of brancher, return true if alternatives left.
Definition: flatzinc.cpp:136
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
BrancherGroup group(void) const
Return group brancher belongs to.
Definition: core.hpp:3553
Equality ( )
Definition: int.hh:905
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:487
Options opt
The options.
Definition: test.cpp:101
IntPropLevel ann2ipl(AST::Node *ann)
Convert ann to integer propagation level.
Definition: flatzinc.cpp:2055
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
struct Gecode::Space::@55::@56 p
Data only available during propagation or branching.
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
Depth-first branch-and-bound search engine.
Definition: search.hh:773
void createBranchers(Printer &p, 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:885
Execution has resulted in failure.
Definition: core.hpp:538
Specification for Boolean variables.
Definition: varspec.hh:101
Value description class for branching.
Definition: float.hh:1391
double threads(void) const
Definition: flatzinc.hh:329
const Space * last(void) const
Return last solution found (possibly NULL)
Definition: core.hpp:3118
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:3005
int _optVar
Index of the variable to optimize.
Definition: flatzinc.hh:419
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:68
Output support class for FlatZinc interpreter.
Definition: flatzinc.hh:111
IntVar arg2IntVar(AST::Node *n)
Convert n to IntVar.
Definition: flatzinc.cpp:1954
Choice(const Brancher &b, bool fail0)
Initialize choice for brancher b.
Definition: flatzinc.cpp:108
FZPrintingInspector(const Printer &p0)
Constructor.
Definition: flatzinc.cpp:1499
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:324
Simple propagation levels.
Definition: int.hh:943
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
Type type(void) const
Return type of information.
Definition: core.hpp:3099
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:3949
FznRnd * _random
Random number generator.
Definition: flatzinc.hh:433
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:1917
IntValBranch INT_VAL_MIN(void)
Select smallest value.
Definition: val.hpp:68
const std::string & floatVarName(int i) const
Definition: flatzinc.hh:196
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:815
static void explore(S *root, const FlatZincOptions &opt, Gist::Inspector *i, Gist::Comparator *c)
Definition: flatzinc.cpp:1473
Value propagation.
Definition: int.hh:944
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:2408
bool l
Whether to try the lower or upper half first.
Definition: float.hh:1396
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:1689
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:470
bool clone
Whether engines create a clone when being initialized.
Definition: search.hh:449
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:2289
FznRnd(unsigned int s=1)
Constructor.
Definition: flatzinc.cpp:321
Array * getArgs(unsigned int n)
Definition: ast.hh:269
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
void addSetVarName(const std::string &n)
Definition: flatzinc.cpp:2402
bool funcDep
Whether the variable functionally depends on another variable.
Definition: varspec.hh:69
Less ( )
Definition: int.hh:908
Integer sets.
Definition: int.hh:172
const int * pi[]
Definition: photo.cpp:14266
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:333
Option< AST::SetLit *> domain
Definition: varspec.hh:103
FlatZincSpace(bool share, FlatZincSpace &)
Copy constructor.
Definition: flatzinc.cpp:624
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:1896
virtual void constrain(const Space &s)
Implement optimization.
Definition: flatzinc.cpp:1704
bool isIntVar(void)
Test if node is an integer variable node.
Definition: ast.hh:474
const std::string & intVarName(int i) const
Definition: flatzinc.hh:191
FloatVarBranch FLOAT_VAR_RND(Rnd r)
Select random variable (uniform distribution, for tie breaking)
Definition: var.hpp:109
Passing integer variables.
Definition: int.hh:637
bool isBoolArray(AST::Node *b, int &singleInt)
Check if b is array of Booleans (or has a single integer)
Definition: flatzinc.cpp:1964
std::vector< bool > bv_introduced
Indicates whether a Boolean variable is introduced by mzn2fzn.
Definition: flatzinc.hh:472
SharedArray< int > IntSharedArray
Arrays of integers that can be shared among several element constraints.
Definition: int.hh:1375
bool done
Flag whether brancher is done.
Definition: flatzinc.cpp:71
Passing integer arguments.
Definition: int.hh:608
Passing Boolean variables.
Definition: int.hh:691
static const IntSet empty
Empty set.
Definition: int.hh:263
void print(const Brancher &b, unsigned int a, int i, const FloatNumBranch &nl, ostream &o) const
Definition: flatzinc.cpp:263
void print(const Brancher &b, unsigned int a, int i, int n, ostream &o) const
Output branch information.
Definition: flatzinc.cpp:257
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:421
IntSet arg2intset(AST::Node *n)
Convert n to IntSet.
Definition: flatzinc.cpp:1866
Gecode::FloatVarArray fv_aux
The introduced float variables.
Definition: flatzinc.hh:485
void add(BrancherGroup bg, const std::string &rel0, const std::string &rel1, const std::vector< std::string > &n)
Add new brancher information.
Definition: flatzinc.cpp:286
SetValBranch SET_VAL_MIN_EXC(void)
Exclude smallest element.
Definition: val.hpp:64
Boolean variable array.
Definition: int.hh:787
Greater ( )
Definition: float.hh:1073
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:492
bool isString(void)
Test if node is a string node.
Definition: ast.hh:506
virtual bool slave(const MetaInfo &mi)
Slave function for restarts.
Definition: flatzinc.cpp:1725
void init(void)
Initialize the implementation object.
Definition: gist.cpp:81
const int v[7]
Definition: distinct.cpp:263
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:75
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:3042
IntValBranch INT_VAL_MAX(void)
Select largest value.
Definition: val.hpp:78
IntPropLevel
Propagation levels for integer propagators.
Definition: int.hh:941
Cutoff generator for constant sequence.
Definition: search.hh:225
AST::Array * args
Constraint arguments.
Definition: conexpr.hh:52
int getInt(void)
Cast this node to an integer node.
Definition: ast.hh:444
void print(std::basic_ostream< Char, Traits > &s, bool assigned, IL &lb, IU &ub, unsigned int cardMin, unsigned int cardMax)
Print set view.
Definition: print.hpp:67
Integer variable node.
Definition: ast.hh:210
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:2336
Passing set variables.
Definition: set.hh:490
void postConstraints(std::vector< ConExpr *> &ces)
Post a constraint specified by ce.
Definition: flatzinc.cpp:852
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:336
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:461
virtual void print(std::ostream &)=0
Output string representation.
BranchInformation(void)
Constructor.
Definition: flatzinc.cpp:273
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:3316
void print(std::ostream &out, const Printer &p) const
Produce output on out using p.
Definition: flatzinc.cpp:1769
virtual void archive(Archive &e) const
Archive into e.
Definition: core.cpp:681
Choice for performing commit
Definition: core.hpp:1332
unsigned int fail(void) const
Definition: flatzinc.hh:334
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:280
ExecStatus
Definition: core.hpp:536
void flattenAnnotations(AST::Array *ann, std::vector< AST::Node *> &out)
Definition: flatzinc.cpp:870
Integer variables.
Definition: int.hh:351
Heap heap
The single global heap.
Definition: heap.cpp:48
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:4253
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition: rel.cpp:47
Exception class for FlatZinc errors
Definition: flatzinc.hh:626
Specification for floating point variables.
Definition: varspec.hh:123
Domain propagation Preferences: prefer speed or memory.
Definition: int.hh:946
TieBreak< FloatVarBranch > ann2fvarsel(AST::Node *ann, Rnd rnd, double decay)
Definition: flatzinc.cpp:560
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
unsigned long int restart(void) const
Return number of restarts.
Definition: core.hpp:3103
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:436
virtual void inspect(const Space &node)
Use the print method of the template class S to print a space.
Definition: flatzinc.cpp:1504
unsigned int c_d(void) const
Definition: flatzinc.hh:331
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:1442
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:492
void solve(AST::Array *annotation)
Post the solve item.
Definition: flatzinc.cpp:1421
unsigned int time(void) const
Definition: flatzinc.hh:335
The shared object.
Definition: core.hpp:88
Execution is okay.
Definition: core.hpp:540
unsigned long int restart
Number of restarts.
Definition: search.hh:149
AST::Array * solveAnnotations(void) const
Return the solve item annotations.
Definition: flatzinc.cpp:1416
#define GECODE_HAS_FLOAT_VARS
Definition: config.hpp:26
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:872
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:747
A space that can be initialized with a FlatZinc model.
Definition: flatzinc.hh:401
Gecode::IntVarArray iv_aux
The introduced integer variables.
Definition: flatzinc.hh:458
Set variable array
Definition: set.hh:570
void addBoolVarName(const std::string &n)
Definition: flatzinc.cpp:2391
void shrinkArrays(Space &home, int &optVar, bool optVarIsInt, Gecode::IntVarArray &iv, Gecode::BoolVarArray &bv, Gecode::SetVarArray &sv, Gecode::FloatVarArray &fv)
Definition: flatzinc.cpp:2443
CompareStatus compare(I &i, J &j)
Check whether range iterator i is a subset of j, or whether they are disjoint.
Stop * stop
Stop object for stopping search.
Definition: search.hh:469
class Gecode::Gist::Options::_I inspect
const std::string & setVarName(int i) const
Definition: flatzinc.hh:200
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:106
void print(const Brancher &b, unsigned int a, int i, int n, std::ostream &o) const
Output branch information.
Definition: flatzinc.cpp:293
void run(std::ostream &out, const Printer &p, const FlatZincOptions &opt, Gecode::Support::Timer &t_total)
Run the search.
Definition: flatzinc.cpp:1690
Gecode toplevel namespace
Information passed by meta search engines.
Definition: core.hpp:1542
void addIntVarName(const std::string &n)
Definition: flatzinc.cpp:2387
int * iv_boolalias
Indicates whether an integer variable aliases a Boolean variable.
Definition: flatzinc.hh:466
unsigned long int node
Number of nodes expanded.
Definition: search.hh:145
void maximize(int var, bool isInt, AST::Array *annotation)
Post that integer variable var should be maximized.
Definition: flatzinc.cpp:1435
int setVarCount
Number of set variables.
Definition: flatzinc.hh:416
Node representing a function call
Definition: ast.hh:259
int intVarCount
Number of integer variables.
Definition: flatzinc.hh:410
unsigned int a_d(void) const
Definition: flatzinc.hh:332
FZPrintingComparator(const Printer &p0)
Constructor.
Definition: flatzinc.cpp:1530
IntValBranch ann2ivalsel(AST::Node *ann, std::string &r0, std::string &r1, Rnd rnd)
Definition: flatzinc.cpp:422
SetVarArgs arg2setvarargs(AST::Node *arg, int offset=0, int doffset=0, const IntSet &od=IntSet::empty)
Convert n to SetVarArgs.
Definition: flatzinc.cpp:1997
A node in a FlatZinc abstract syntax tree.
Definition: ast.hh:71
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:1856
Which variable to select for branching.
Definition: set.hh:1252
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
void addFloatVarName(const std::string &n)
Definition: flatzinc.cpp:2396
Space is failed
Definition: core.hpp:1611
unsigned int _lns
Percentage of variables to keep in LNS (or 0 for no LNS)
Definition: flatzinc.hh:427
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:1701
struct Gecode::@554::NNF::@60::@61 b
For binary nodes (and, or, eqv)
void varValPrintF(const Space &home, const Brancher &b, unsigned int a, FloatVar, int i, const FloatNumBranch &nl, std::ostream &o)
Definition: flatzinc.cpp:313
friend FloatVal min(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:402
Gecode::SetVarArray sv
The set variables.
Definition: flatzinc.hh:475
Home class for posting propagators
Definition: core.hpp:905
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
const std::string & boolVarName(int i) const
Definition: flatzinc.hh:193
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
virtual void finalize(void)
Finalize when Gist exits.
Definition: flatzinc.cpp:1512
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:461
FloatVar arg2FloatVar(AST::Node *n)
Convert n to FloatVar.
Definition: flatzinc.cpp:2044
Depth-first search engine.
Definition: search.hh:739
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
IntSharedArray _lnsInitialSolution
Initial solution to start the LNS (or NULL for no LNS)
Definition: flatzinc.hh:430
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:2013
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:531
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:2072
BoolVar arg2BoolVar(AST::Node *n)
Convert n to BoolVar.
Definition: flatzinc.cpp:1943
IntSetArgs arg2intsetargs(AST::Node *arg, int offset=0)
Convert arg to IntSetArgs.
Definition: flatzinc.cpp:1881
Abstract representation of a constraint.
Definition: conexpr.hh:47