Generated on Sat Jun 2 2018 07:17:44 for Gecode by doxygen 1.8.13
extensional.cpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Mikael Lagerkvist <lagerkvist@gecode.org>
5  * Christian Schulte <schulte@gecode.org>
6  *
7  * Contributing authors:
8  * Linnea Ingmar <linnea.ingmar@hotmail.com>
9  *
10  * Copyright:
11  * Linnea Ingmar, 2017
12  * Mikael Lagerkvist, 2007
13  * Christian Schulte, 2005
14  *
15  * This file is part of Gecode, the generic constraint
16  * development environment:
17  * http://www.gecode.org
18  *
19  * Permission is hereby granted, free of charge, to any person obtaining
20  * a copy of this software and associated documentation files (the
21  * "Software"), to deal in the Software without restriction, including
22  * without limitation the rights to use, copy, modify, merge, publish,
23  * distribute, sublicense, and/or sell copies of the Software, and to
24  * permit persons to whom the Software is furnished to do so, subject to
25  * the following conditions:
26  *
27  * The above copyright notice and this permission notice shall be
28  * included in all copies or substantial portions of the Software.
29  *
30  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37  *
38  */
39 
40 #include "test/int.hh"
41 
42 #include <gecode/minimodel.hh>
43 #include <climits>
44 
45 namespace Test { namespace Int {
46 
48  namespace Extensional {
49 
55  class RegSimpleA : public Test {
57  public:
59  RegSimpleA(void) : Test("Extensional::Reg::Simple::A",4,2,2) {}
61  virtual bool solution(const Assignment& x) const {
62  return (((x[0] == 0) || (x[0] == 2)) &&
63  ((x[1] == -1) || (x[1] == 1)) &&
64  ((x[2] == 0) || (x[2] == 1)) &&
65  ((x[3] == 0) || (x[3] == 1)));
66  }
68  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
69  using namespace Gecode;
70  extensional(home, x,
71  (REG(0) | REG(2)) +
72  (REG(-1) | REG(1)) +
73  (REG(7) | REG(0) | REG(1)) +
74  (REG(0) | REG(1)));
75  }
76  };
77 
79  class RegSimpleB : public Test {
80  public:
82  RegSimpleB(void) : Test("Extensional::Reg::Simple::B",4,2,2) {}
84  virtual bool solution(const Assignment& x) const {
85  return (x[0]<x[1]) && (x[1]<x[2]) && (x[2]<x[3]);
86  }
88  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
89  using namespace Gecode;
90  extensional(home, x,
91  (REG(-2) + REG(-1) + REG(0) + REG(1)) |
92  (REG(-2) + REG(-1) + REG(0) + REG(2)) |
93  (REG(-2) + REG(-1) + REG(1) + REG(2)) |
94  (REG(-2) + REG(0) + REG(1) + REG(2)) |
95  (REG(-1) + REG(0) + REG(1) + REG(2)));
96  }
97  };
98 
100  class RegSimpleC : public Test {
101  public:
103  RegSimpleC(void) : Test("Extensional::Reg::Simple::C",6,0,1) {}
105  virtual bool solution(const Assignment& x) const {
106  int pos = 0;
107  int s = x.size();
108 
109  while (pos < s && x[pos] == 0) ++pos;
110  if (pos + 4 > s) return false;
111 
112  for (int i = 0; i < 2; ++i, ++pos)
113  if (x[pos] != 1) return false;
114  if (pos + 2 > s) return false;
115 
116  for (int i = 0; i < 1; ++i, ++pos)
117  if (x[pos] != 0) return false;
118  while (pos < s && x[pos] == 0) ++pos;
119  if (pos + 1 > s) return false;
120 
121  for (int i = 0; i < 1; ++i, ++pos)
122  if (x[pos] != 1) return false;
123  while (pos < s) if (x[pos++] != 0) return false;
124  return true;
125 
126  }
128  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
129  using namespace Gecode;
130  extensional(home, x,
131  *REG(0) + REG(1)(2,2) + +REG(0) + REG(1)(1,1) + *REG(0));
132  }
133  };
134 
136  class RegDistinct : public Test {
137  public:
139  RegDistinct(void) : Test("Extensional::Reg::Distinct",4,-1,4) {}
141  virtual bool solution(const Assignment& x) const {
142  for (int i=0; i<x.size(); i++) {
143  if ((x[i] < 0) || (x[i] > 3))
144  return false;
145  for (int j=i+1; j<x.size(); j++)
146  if (x[i]==x[j])
147  return false;
148  }
149  return true;
150  }
152  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
153  using namespace Gecode;
154  extensional(home, x,
155  (REG(0)+REG(1)+REG(2)+REG(3)) |
156  (REG(0)+REG(1)+REG(3)+REG(2)) |
157  (REG(0)+REG(2)+REG(1)+REG(3)) |
158  (REG(0)+REG(2)+REG(3)+REG(1)) |
159  (REG(0)+REG(3)+REG(1)+REG(2)) |
160  (REG(0)+REG(3)+REG(2)+REG(1)) |
161  (REG(1)+REG(0)+REG(2)+REG(3)) |
162  (REG(1)+REG(0)+REG(3)+REG(2)) |
163  (REG(1)+REG(2)+REG(0)+REG(3)) |
164  (REG(1)+REG(2)+REG(3)+REG(0)) |
165  (REG(1)+REG(3)+REG(0)+REG(2)) |
166  (REG(1)+REG(3)+REG(2)+REG(0)) |
167  (REG(2)+REG(0)+REG(1)+REG(3)) |
168  (REG(2)+REG(0)+REG(3)+REG(1)) |
169  (REG(2)+REG(1)+REG(0)+REG(3)) |
170  (REG(2)+REG(1)+REG(3)+REG(0)) |
171  (REG(2)+REG(3)+REG(0)+REG(1)) |
172  (REG(2)+REG(3)+REG(1)+REG(0)) |
173  (REG(3)+REG(0)+REG(1)+REG(2)) |
174  (REG(3)+REG(0)+REG(2)+REG(1)) |
175  (REG(3)+REG(1)+REG(0)+REG(2)) |
176  (REG(3)+REG(1)+REG(2)+REG(0)) |
177  (REG(3)+REG(2)+REG(0)+REG(1)) |
178  (REG(3)+REG(2)+REG(1)+REG(0)));
179  }
180  };
181 
183  class RegRoland : public Test {
184  public:
187  : Test("Extensional::Reg::Roland::"+str(n),n,0,1) {}
189  virtual bool solution(const Assignment& x) const {
190  int n = x.size();
191  return
192  ((n > 1) && (x[n-2] == 0)) ||
193  ((n > 0) && (x[n-1] == 0));
194  }
196  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
197  using namespace Gecode;
198  REG r0(0), r1(1);
199  REG r01 = r0 | r1;
200  extensional(home, x, *r01 + r0 + r01(0,1));
201  }
202  };
203 
205  class RegSharedA : public Test {
206  public:
208  RegSharedA(void) : Test("Extensional::Reg::Shared::A",4,2,2) {}
210  virtual bool solution(const Assignment& x) const {
211  return (((x[0] == 0) || (x[0] == 2)) &&
212  ((x[1] == -1) || (x[1] == 1)) &&
213  ((x[2] == 0) || (x[2] == 1)) &&
214  ((x[3] == 0) || (x[3] == 1)));
215  }
217  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
218  using namespace Gecode;
219  IntVarArgs y(8);
220  for (int i=0; i<4; i++)
221  y[i]=y[i+4]=x[i];
222  unshare(home,y);
223  extensional(home, y,
224  ((REG(0) | REG(2)) +
225  (REG(-1) | REG(1)) +
226  (REG(7) | REG(0) | REG(1)) +
227  (REG(0) | REG(1)))(2,2));
228  }
229  };
230 
232  class RegSharedB : public Test {
233  public:
235  RegSharedB(void) : Test("Extensional::Reg::Shared::B",4,2,2) {}
237  virtual bool solution(const Assignment& x) const {
238  return (((x[0] == 0) || (x[0] == 2)) &&
239  ((x[1] == -1) || (x[1] == 1)) &&
240  ((x[2] == 0) || (x[2] == 1)) &&
241  ((x[3] == 0) || (x[3] == 1)));
242  }
244  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
245  using namespace Gecode;
246  IntVarArgs y(12);
247  for (int i=0; i<4; i++)
248  y[i]=y[i+4]=y[i+8]=x[i];
249  unshare(home,y);
250  extensional(home, y,
251  ((REG(0) | REG(2)) +
252  (REG(-1) | REG(1)) +
253  (REG(7) | REG(0) | REG(1)) +
254  (REG(0) | REG(1)))(3,3));
255  }
256  };
257 
259  class RegSharedC : public Test {
260  public:
262  RegSharedC(void) : Test("Extensional::Reg::Shared::C",4,0,1) {}
264  virtual bool solution(const Assignment& x) const {
265  return (x[1]==1) && (x[2]==0) && (x[3]==1);
266  }
268  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
269  using namespace Gecode;
271  for (int i=0; i<4; i++)
272  y[i]=y[i+4]=channel(home,x[i]);
273  unshare(home,y);
274  extensional(home,y,
275  ((REG(0) | REG(1)) + REG(1) + REG(0) + REG(1))(2,2));
276  }
277  };
278 
280  class RegSharedD : public Test {
281  public:
283  RegSharedD(void) : Test("Extensional::Reg::Shared::D",4,0,1) {}
285  virtual bool solution(const Assignment& x) const {
286  return (x[1]==1) && (x[2]==0) && (x[3]==1);
287  }
289  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
290  using namespace Gecode;
292  for (int i=0; i<4; i++)
293  y[i]=y[i+4]=y[i+8]=channel(home,x[i]);
294  unshare(home, y);
295  extensional(home, y,
296  ((REG(0) | REG(1)) + REG(1) + REG(0) + REG(1))(3,3));
297  }
298  };
299 
301  class RegEmptyDFA : public Test {
302  public:
304  RegEmptyDFA(void) : Test("Extensional::Reg::Empty::DFA",1,0,0) {
305  testsearch = false;
306  }
308  virtual bool solution(const Assignment& x) const {
309  (void)x;
310  return false;
311  }
313  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
314  Gecode::DFA d;
315  Gecode::extensional(home, x, d);
316  }
317  };
318 
320  class RegEmptyREG : public Test {
321  public:
323  RegEmptyREG(void) : Test("Extensional::Reg::Empty::REG",1,0,0) {
324  testsearch = false;
325  }
327  virtual bool solution(const Assignment& x) const {
328  (void)x;
329  return false;
330  }
332  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
333  Gecode::REG r;
334  Gecode::extensional(home, x, r);
335  }
336  };
337 
339  class RegOpt : public Test {
340  protected:
342  int n;
343  public:
345  RegOpt(int n0)
346  : Test("Extensional::Reg::Opt::"+str(n0),1,0,15), n(n0) {}
348  virtual bool solution(const Assignment& x) const {
349  return (x[0] < n) && ((x[0] & 1) == 0);
350  }
352  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
353  using namespace Gecode;
354  DFA::Transition* t = new DFA::Transition[n+1];
355  DFA::Transition* ti = t;
356  int* f = new int[n+1];
357  int* fi = f;
358  for (int i=0; i<n; i++) {
359  ti->i_state = 0;
360  ti->symbol = i;
361  ti->o_state = i+1;
362  ti++;
363  if ((i & 1) == 0) {
364  *fi = i+1; fi++;
365  }
366  }
367  ti->i_state = -1;
368  *fi = -1;
369  DFA d(0, t, f, false);
370  delete [] t;
371  delete [] f;
372  extensional(home, x, d);
373  }
374 
375  };
376 
379  using namespace Gecode;
380  REG expression;
381  for (int i = 0; i<ts.tuples(); i++) {
382  REG r;
383  for (int j = 0; j<ts.arity(); j++) {
384  r += REG(ts[i][j]);
385  }
386  expression |= r;
387  }
388  DFA dfa(expression);
389  return dfa;
390  }
391 
393  class TupleSetBase : public Test {
394  public:
397  : Test("Extensional::TupleSet::Base",
398  4,1,5,false,Gecode::IPL_DOM) {}
400  virtual bool solution(const Assignment& x) const {
401  return ((x[0] == 1 && x[1] == 3 && x[2] == 2 && x[3] == 3) ||
402  (x[0] == 2 && x[1] == 1 && x[2] == 2 && x[3] == 4) ||
403  (x[0] == 2 && x[1] == 2 && x[2] == 1 && x[3] == 4) ||
404  (x[0] == 3 && x[1] == 3 && x[2] == 3 && x[3] == 2) ||
405  (x[0] == 4 && x[1] == 3 && x[2] == 4 && x[3] == 1)
406  );
407  }
409  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
410  using namespace Gecode;
411  TupleSet t(4);
412  IntArgs t1(4, 2, 1, 2, 4);
413  IntArgs t2(4, 2, 2, 1, 4);
414  IntArgs t3(4, 4, 3, 4, 1);
415  IntArgs t4(4, 1, 3, 2, 3);
416  IntArgs t5(4, 3, 3, 3, 2);
417  t.add(t1).add(t1).add(t2).add(t2)
418  .add(t3).add(t3).add(t4).add(t4)
419  .add(t5).add(t5).add(t5).add(t5)
420  .add(t5).add(t5).add(t5).add(t5)
421  .add(t1).add(t1).add(t2).add(t2)
422  .add(t3).add(t3).add(t4).add(t4)
423  .add(t5).add(t5).add(t5).add(t5)
424  .add(t5).add(t5).add(t5).add(t5)
425  .finalize();
426 
427  TupleSet ts = TupleSet(t.arity(),tupleset2dfa(t));
428  assert(t == ts);
429  extensional(home, x, t, ipl);
430  }
431  };
432 
434  class TupleSetTest : public Test {
435  protected:
439  bool toDFA;
440  public:
442  TupleSetTest(const std::string& s,
443  Gecode::IntSet d0, Gecode::TupleSet ts0, bool td)
444  : Test("Extensional::TupleSet::"+s,
445  ts0.arity(),d0,false,Gecode::IPL_DOM), ts(ts0) {
446  toDFA = td;
447  }
449  virtual bool solution(const Assignment& x) const {
450  using namespace Gecode;
451  for (int i=ts.tuples(); i--; ) {
452  TupleSet::Tuple t = ts[i];
453  bool same = true;
454  for (int j=0; (j < ts.arity()) && same; j++)
455  if (t[j] != x[j])
456  same = false;
457  if (same)
458  return true;
459  }
460  return false;
461  }
463  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
464  using namespace Gecode;
465 
466  if (toDFA) {
467  TupleSet t = TupleSet(ts.arity(),tupleset2dfa(ts));
468  assert(ts == t);
469  }
470  extensional(home, x, ts, ipl);
471  }
472  };
473 
475  public:
477  RandomTupleSetTest(const std::string& s,
479  : TupleSetTest(s,d0,ts0,false) {
480  testsearch = false;
481  }
483  virtual Assignment* assignment(void) const {
484  using namespace Gecode;
485  return new RandomAssignment(arity,dom,1000);
486  }
487  };
488 
490  class TupleSetLarge : public Test {
491  mutable Gecode::TupleSet t;
492  public:
494  TupleSetLarge(double prob)
495  : Test("Extensional::TupleSet::Large",
496  5,1,5,false,Gecode::IPL_DOM), t(5) {
497  using namespace Gecode;
498 
499  CpltAssignment ass(5, IntSet(1, 5));
500  while (ass()) {
501  if (Base::rand(100) <= prob*100) {
502  IntArgs tuple(5);
503  for (int i = 5; i--; ) tuple[i] = ass[i];
504  t.add(tuple);
505  }
506  ++ass;
507  }
508  t.finalize();
509  }
511  virtual bool solution(const Assignment& x) const {
512  using namespace Gecode;
513  for (int i = 0; i < t.tuples(); ++i) {
514  TupleSet::Tuple l = t[i];
515  bool same = true;
516  for (int j = 0; j < t.arity() && same; ++j)
517  if (l[j] != x[j]) same = false;
518  if (same) return true;
519  }
520  return false;
521  }
523  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
524  using namespace Gecode;
525  extensional(home, x, t, ipl);
526  }
527  };
528 
530  class TupleSetBool : public Test {
531  mutable Gecode::TupleSet t;
532  public:
534  TupleSetBool(double prob)
535  : Test("Extensional::TupleSet::Bool",
536  5,0,1,false), t(5) {
537  using namespace Gecode;
538 
539  CpltAssignment ass(5, IntSet(0, 1));
540  while (ass()) {
541  if (Base::rand(100) <= prob*100) {
542  IntArgs tuple(5);
543  for (int i = 5; i--; ) tuple[i] = ass[i];
544  t.add(tuple);
545  }
546  ++ass;
547  }
548  t.finalize();
549  }
551  virtual bool solution(const Assignment& x) const {
552  using namespace Gecode;
553  for (int i = 0; i < t.tuples(); ++i) {
554  TupleSet::Tuple l = t[i];
555  bool same = true;
556  for (int j = 0; j < t.arity() && same; ++j)
557  if (l[j] != x[j]) same = false;
558  if (same) return true;
559  }
560  return false;
561  }
563  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
564  using namespace Gecode;
565  BoolVarArgs y(x.size());
566  for (int i = x.size(); i--; )
567  y[i] = channel(home, x[i]);
568  extensional(home, y, t, ipl);
569  }
570  };
571 
574  public:
577  using namespace Gecode;
579  int arity = 2;
580  int n_tuples = 5*5;
581  while (n_tuples < size) {
582  arity++;
583  n_tuples*=5;
584  }
586  TupleSet ts(arity);
587  CpltAssignment ass(arity, IntSet(0, 4));
588  for (int i = size; i--; ) {
589  assert(ass());
590  IntArgs tuple(arity);
591  for (int j = arity; j--; ) tuple[j] = ass[j];
592  ts.add(tuple);
593  ++ass;
594  }
595  ts.finalize();
596  assert(ts.tuples() == size);
597  // Create and register test
598  (void) new TupleSetTest(std::to_string(size),IntSet(0,4),ts,
599  size <= 128);
600  }
601  };
602 
603  Gecode::TupleSet randomTupleSet(int n, int min, int max, double prob) {
604  using namespace Gecode;
605  TupleSet t(n);
606  CpltAssignment ass(n, IntSet(min, max));
607  while (ass()) {
608  if (Base::rand(100) <= prob*100) {
609  IntArgs tuple(n);
610  for (int i = n; i--; ) tuple[i] = ass[i];
611  t.add(tuple);
612  }
613  ++ass;
614  }
615  t.finalize();
616  return t;
617  }
618 
620  class Create {
621  public:
623  Create(void) {
624  using namespace Gecode;
625  {
626  TupleSet ts(4);
627  ts.add(2, 1, 2, 4).add(2, 2, 1, 4)
628  .add(4, 3, 4, 1).add(1, 3, 2, 3)
629  .add(3, 3, 3, 2).add(5, 1, 4, 4)
630  .add(2, 5, 1, 5).add(4, 3, 5, 1)
631  .add(1, 5, 2, 5).add(5, 3, 3, 2)
632  .finalize();
633  (void) new TupleSetTest("A",IntSet(0,6),ts,true);
634  }
635  {
636  TupleSet ts(4);
637  ts.finalize();
638  (void) new TupleSetTest("Empty",IntSet(1,2),ts,true);
639  }
640  {
641  TupleSet ts(4);
642  for (int n=1024*16; n--; )
643  ts.add(1,2,3,4);
644  ts.finalize();
645  (void) new TupleSetTest("Assigned",IntSet(1,4),ts,true);
646  }
647  {
648  TupleSet ts(1);
649  ts.add(1).add(2).add(3).finalize();
650  (void) new TupleSetTest("Single",IntSet(-4,4),ts,true);
651  }
652  {
653  int m = Gecode::Int::Limits::min;
654  TupleSet ts(3);
655  ts.add(m+0,m+1,m+2).add(m+4,m+1,m+3)
656  .add(m+2,m+3,m+0).add(m+2,m+3,m+0)
657  .add(m+1,m+2,m+5).add(m+2,m+3,m+0)
658  .add(m+3,m+6,m+5).finalize();
659  (void) new TupleSetTest("Min",IntSet(m,m+7),ts,true);
660  }
661  {
662  int M = Gecode::Int::Limits::max;
663  TupleSet ts(3);
664  ts.add(M-0,M-1,M-2).add(M-4,M-1,M-3)
665  .add(M-2,M-3,M-0).add(M-2,M-3,M-0)
666  .add(M-1,M-2,M-5).add(M-2,M-3,M-0)
667  .add(M-3,M-6,M-5).finalize();
668  (void) new TupleSetTest("Max",IntSet(M-7,M),ts,true);
669  }
670  {
671  int m = Gecode::Int::Limits::min;
672  int M = Gecode::Int::Limits::max;
673  TupleSet ts(3);
674  ts.add(M-0,m+1,M-2).add(m+4,M-1,M-3)
675  .add(m+2,M-3,m+0).add(M-2,M-3,M-0)
676  .finalize();
677  (void) new TupleSetTest("MinMax",
678  IntSet(IntArgs(6, m,m+1,m+4,M-3,M-2,M)),
679  ts,true);
680  }
681  {
682  TupleSet ts(7);
683  for (int i = 0; i < 10000; i++) {
684  IntArgs tuple(7);
685  for (int j = 0; j < 7; j++) {
686  tuple[j] = Base::rand(j+1);
687  }
688  ts.add(tuple);
689  }
690  ts.finalize();
691  (void) new RandomTupleSetTest("Triangle",IntSet(0,6),ts);
692  }
693  {
694  for (int i = 0; i <= 64*6; i+=32)
695  (void) new TupleSetTestSize(i);
696  }
697  {
698  (void) new RandomTupleSetTest("Rand(10,-1,2)", IntSet(-1,2),
699  randomTupleSet(10,-1,2,0.05));
700  (void) new RandomTupleSetTest("Rand(5,-10,10)", IntSet(-10,10),
701  randomTupleSet(5,-10,10,0.05));
702  }
703  {
704  TupleSet t(5);
705  CpltAssignment ass(4, IntSet(1, 4));
706  while (ass()) {
707  IntArgs tuple(5);
708  tuple[4] = 1;
709  for (int i = 4; i--; ) tuple[i] = ass[i];
710  t.add(tuple);
711  ++ass;
712  }
713  t.add(2,2,4,3,4);
714  t.finalize();
715  (void) new TupleSetTest("FewLast",IntSet(1,4),t,false);
716  }
717  {
718  TupleSet t(4);
719  CpltAssignment ass(4, IntSet(1, 6));
720  while (ass()) {
721  t.add(ass[0],0,ass[1],ass[2]);
722  ++ass;
723  }
724  t.add(2,-1,3,4);
725  t.finalize();
726  (void) new TupleSetTest("FewMiddle",IntSet(-1,6),t,false);
727  }
728  {
729  TupleSet t(10);
730  CpltAssignment ass(9, IntSet(1, 4));
731  while (ass()) {
732  if (Base::rand(100) <= 0.25*100) {
733  IntArgs tuple(10);
734  tuple[0] = 2;
735  for (int i = 9; i--; ) tuple[i+1] = ass[i];
736  t.add(tuple);
737  }
738  ++ass;
739  }
740  t.add(1,1,1,1,1,1,1,1,1,1);
741  t.add(1,2,3,4,4,2,1,2,3,3);
742  t.finalize();
743  (void) new RandomTupleSetTest("FewHuge",IntSet(1,4),t);
744  }
745  }
746  };
747 
749 
753 
755 
756  RegRoland rr1(1);
757  RegRoland rr2(2);
758  RegRoland rr3(3);
759  RegRoland rr4(4);
760 
765 
768 
769  RegOpt ro0(CHAR_MAX-1);
770  RegOpt ro1(CHAR_MAX);
771  RegOpt ro2(static_cast<int>(UCHAR_MAX-1));
772  RegOpt ro3(static_cast<int>(UCHAR_MAX));
773  RegOpt ro4(SHRT_MAX-1);
774  RegOpt ro5(SHRT_MAX);
775  RegOpt ro6(static_cast<int>(USHRT_MAX-1));
776  RegOpt ro7(static_cast<int>(USHRT_MAX));
777 
779 
780  TupleSetLarge tsl(0.05);
781 
782  TupleSetBool tsbool(0.3);
784 
785  }
786 }}
787 
788 
789 // STATISTICS: test-int
RegRoland(int n)
Create and register test.
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
TupleSetLarge(double prob)
Create and register test.
Test with simple regular expression and shared variables (uses unsharing)
int symbol
symbol
Definition: int.hh:2035
NodeType t
Type of node.
Definition: bool-expr.cpp:230
static std::string str(Gecode::IntPropLevel ipl)
Map integer propagation level to string.
Definition: int.hpp:208
Gecode::TupleSet randomTupleSet(int n, int min, int max, double prob)
void finalize(void)
Finalize tuple set.
Definition: tuple-set.hpp:155
NNF * l
Left subtree.
Definition: bool-expr.cpp:240
RegEmptyREG(void)
Create and register test.
RandomTupleSetTest(const std::string &s, Gecode::IntSet d0, Gecode::TupleSet ts0)
Create and register test.
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
virtual bool solution(const Assignment &x) const
Test whether x is solution
Create(void)
Perform creation and registration.
void channel(Home home, FloatVar x0, IntVar x1)
Post propagator for channeling a float and an integer variable .
Definition: channel.cpp:41
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:969
const FloatNum max
Largest allowed float value.
Definition: float.hh:844
Test for optimizations
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: extensional.cpp:68
TupleSetTest(const std::string &s, Gecode::IntSet d0, Gecode::TupleSet ts0, bool td)
Create and register test.
int size(void) const
Return number of variables.
Definition: int.hpp:46
int arity(void) const
Arity of tuple set.
Definition: tuple-set.hpp:181
Test with regular expression for distinct constraint
static Gecode::Support::RandomGenerator rand
Random number generator.
Definition: test.hh:134
Regular expressions over integer values.
Definition: minimodel.hh:1518
RegOpt ro3(static_cast< int >(UCHAR_MAX))
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
RegDistinct(void)
Create and register test.
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
bool pos(const View &x)
Test whether x is postive.
Definition: mult.hpp:41
Test with simple regular expression
Definition: extensional.cpp:79
int * Tuple
Type of a tuple.
Definition: int.hh:2146
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
virtual Assignment * assignment(void) const
Create and register initial assignment.
Gecode::IntSet dom
Domain of variables.
Definition: int.hh:228
void unshare(Home home, VarArgArray< Var > &x, IntPropLevel ipl)
Replace unassigned shared variables by fresh, yet equal variables.
Definition: unshare.cpp:108
virtual bool solution(const Assignment &x) const
Test whether x is solution
Integer variable array.
Definition: int.hh:738
Test with simple regular expression and shared variables (uses unsharing)
virtual bool solution(const Assignment &x) const
Test whether x is solution
Test with simple regular expression
const int max
Largest allowed integer value.
Definition: int.hh:112
Computation spaces.
Definition: core.hpp:1701
Generate random selection of assignments.
Definition: int.hh:96
int i_state
input state
Definition: int.hh:2034
RegOpt ro1(CHAR_MAX)
RegOpt ro0(CHAR_MAX-1)
const int min
Smallest allowed integer value.
Definition: int.hh:114
TupleSetBool tsbool(0.3)
virtual bool solution(const Assignment &x) const
Test whether x is solution
Gecode::IntSet d(v, 7)
virtual bool solution(const Assignment &x) const
Test whether x is solution
int tuples(void) const
Number of tuples.
Definition: tuple-set.hpp:185
virtual bool solution(const Assignment &x) const
Test whether x is solution
virtual bool solution(const Assignment &x) const
Test whether x is solution
Deterministic finite automaton (DFA)
Definition: int.hh:2023
const FloatNum min
Smallest allowed float value.
Definition: float.hh:846
Gecode::IntArgs i(4, 1, 2, 3, 4)
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
RegOpt ro5(SHRT_MAX)
void extensional(Home home, const IntVarArgs &x, DFA dfa, IntPropLevel)
Post domain consistent propagator for extensional constraint described by a DFA.
Definition: extensional.cpp:43
Specification of a DFA transition.
Definition: int.hh:2032
unsigned int size(I &i)
Size of all ranges of range iterator i.
Gecode::TupleSet ts
The tuple set to use.
RegSharedB(void)
Create and register test.
RegOpt ro7(static_cast< int >(USHRT_MAX))
Gecode::DFA tupleset2dfa(Gecode::TupleSet ts)
% Transform a TupleSet into a DFA
bool toDFA
Whether to validate dfa2tupleset.
TupleSetLarge tsl(0.05)
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
RegEmptyDFA(void)
Create and register test.
Integer sets.
Definition: int.hh:170
int o_state
output state Default constructor
Definition: int.hh:2036
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: extensional.cpp:88
virtual bool solution(const Assignment &x) const
Test whether x is solution
TupleSetBase(void)
Create and register test.
Gecode::IntPropLevel ipl
Propagation level.
Definition: int.hh:234
Passing integer variables.
Definition: int.hh:633
Passing integer arguments.
Definition: int.hh:604
Passing Boolean variables.
Definition: int.hh:687
virtual bool solution(const Assignment &x) const
Test whether x is solution
TupleSetBool(double prob)
Create and register test.
Class represeting a set of tuples.
Definition: int.hh:2140
RegSharedD(void)
Create and register test.
General test support.
Definition: afc.cpp:39
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:765
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: extensional.cpp:84
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:249
virtual bool solution(const Assignment &x) const
Test whether x is solution
bool testsearch
Whether to perform search test.
Definition: int.hh:238
Region r
Definition: region.cpp:65
Base class for assignments
Definition: int.hh:59
void extensional(Home home, const BoolVarArgs &x, const TupleSet &t, IntPropLevel)
Post propagator for .
Definition: extensional.cpp:85
bool same(const Item &i, const Item &j)
Whether two items are the same.
Definition: propagate.hpp:72
Test with simple regular expression and shared variables (uses unsharing)
Domain propagation Options: basic versus advanced propagation.
Definition: int.hh:954
Help class to create and register tests with a fixed table size.
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
virtual bool solution(const Assignment &x) const
Test whether x is solution
RegOpt(int n0)
Create and register test.
TupleSet & add(const IntArgs &t)
Add tuple t to tuple set.
Definition: tuple-set.hpp:142
Test with simple regular expression from Roland Yap
int n
DFA size characteristic.
RegSimpleC(void)
Create and register test.
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: extensional.cpp:61
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Gecode toplevel namespace
virtual bool solution(const Assignment &x) const
Test whether x is solution
RegOpt ro4(SHRT_MAX-1)
Test for empty regular expression
Help class to create and register tests.
int arity
Number of variables.
Definition: int.hh:226
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
virtual bool solution(const Assignment &x) const
Test whether x is solution
RegOpt ro6(static_cast< int >(USHRT_MAX-1))
RegOpt ro2(static_cast< int >(UCHAR_MAX-1))
RegSharedA(void)
Create and register test.
Test with bool tuple set
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
TupleSetTestSize(int size)
Perform creation and registration.
RegSharedC(void)
Create and register test.
Test with large tuple set
Test with simple regular expression and shared variables (uses unsharing)
Generate all assignments.
Definition: int.hh:79
virtual bool solution(const Assignment &x) const
Test whether x is solution
RegSimpleA(void)
Create and register test.
Definition: extensional.cpp:59
RegSimpleB(void)
Create and register test.
Definition: extensional.cpp:82
Test with simple regular expression
Definition: extensional.cpp:56