Generated on Thu Apr 5 2018 19:44:19 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  * Last modified:
16  * $Date$ by $Author$
17  * $Revision$
18  *
19  * This file is part of Gecode, the generic constraint
20  * development environment:
21  * http://www.gecode.org
22  *
23  * Permission is hereby granted, free of charge, to any person obtaining
24  * a copy of this software and associated documentation files (the
25  * "Software"), to deal in the Software without restriction, including
26  * without limitation the rights to use, copy, modify, merge, publish,
27  * distribute, sublicense, and/or sell copies of the Software, and to
28  * permit persons to whom the Software is furnished to do so, subject to
29  * the following conditions:
30  *
31  * The above copyright notice and this permission notice shall be
32  * included in all copies or substantial portions of the Software.
33  *
34  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
35  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
37  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
38  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
39  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
40  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41  *
42  */
43 
44 #include "test/int.hh"
45 
46 #include <gecode/minimodel.hh>
47 #include <climits>
48 
49 namespace Test { namespace Int {
50 
52  namespace Extensional {
53 
59  class RegSimpleA : public Test {
61  public:
63  RegSimpleA(void) : Test("Extensional::Reg::Simple::A",4,2,2) {}
65  virtual bool solution(const Assignment& x) const {
66  return (((x[0] == 0) || (x[0] == 2)) &&
67  ((x[1] == -1) || (x[1] == 1)) &&
68  ((x[2] == 0) || (x[2] == 1)) &&
69  ((x[3] == 0) || (x[3] == 1)));
70  }
72  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
73  using namespace Gecode;
74  extensional(home, x,
75  (REG(0) | REG(2)) +
76  (REG(-1) | REG(1)) +
77  (REG(7) | REG(0) | REG(1)) +
78  (REG(0) | REG(1)));
79  }
80  };
81 
83  class RegSimpleB : public Test {
84  public:
86  RegSimpleB(void) : Test("Extensional::Reg::Simple::B",4,2,2) {}
88  virtual bool solution(const Assignment& x) const {
89  return (x[0]<x[1]) && (x[1]<x[2]) && (x[2]<x[3]);
90  }
92  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
93  using namespace Gecode;
94  extensional(home, x,
95  (REG(-2) + REG(-1) + REG(0) + REG(1)) |
96  (REG(-2) + REG(-1) + REG(0) + REG(2)) |
97  (REG(-2) + REG(-1) + REG(1) + REG(2)) |
98  (REG(-2) + REG(0) + REG(1) + REG(2)) |
99  (REG(-1) + REG(0) + REG(1) + REG(2)));
100  }
101  };
102 
104  class RegSimpleC : public Test {
105  public:
107  RegSimpleC(void) : Test("Extensional::Reg::Simple::C",6,0,1) {}
109  virtual bool solution(const Assignment& x) const {
110  int pos = 0;
111  int s = x.size();
112 
113  while (pos < s && x[pos] == 0) ++pos;
114  if (pos + 4 > s) return false;
115 
116  for (int i = 0; i < 2; ++i, ++pos)
117  if (x[pos] != 1) return false;
118  if (pos + 2 > s) return false;
119 
120  for (int i = 0; i < 1; ++i, ++pos)
121  if (x[pos] != 0) return false;
122  while (pos < s && x[pos] == 0) ++pos;
123  if (pos + 1 > s) return false;
124 
125  for (int i = 0; i < 1; ++i, ++pos)
126  if (x[pos] != 1) return false;
127  while (pos < s) if (x[pos++] != 0) return false;
128  return true;
129 
130  }
132  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
133  using namespace Gecode;
134  extensional(home, x,
135  *REG(0) + REG(1)(2,2) + +REG(0) + REG(1)(1,1) + *REG(0));
136  }
137  };
138 
140  class RegDistinct : public Test {
141  public:
143  RegDistinct(void) : Test("Extensional::Reg::Distinct",4,-1,4) {}
145  virtual bool solution(const Assignment& x) const {
146  for (int i=0; i<x.size(); i++) {
147  if ((x[i] < 0) || (x[i] > 3))
148  return false;
149  for (int j=i+1; j<x.size(); j++)
150  if (x[i]==x[j])
151  return false;
152  }
153  return true;
154  }
156  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
157  using namespace Gecode;
158  extensional(home, x,
159  (REG(0)+REG(1)+REG(2)+REG(3)) |
160  (REG(0)+REG(1)+REG(3)+REG(2)) |
161  (REG(0)+REG(2)+REG(1)+REG(3)) |
162  (REG(0)+REG(2)+REG(3)+REG(1)) |
163  (REG(0)+REG(3)+REG(1)+REG(2)) |
164  (REG(0)+REG(3)+REG(2)+REG(1)) |
165  (REG(1)+REG(0)+REG(2)+REG(3)) |
166  (REG(1)+REG(0)+REG(3)+REG(2)) |
167  (REG(1)+REG(2)+REG(0)+REG(3)) |
168  (REG(1)+REG(2)+REG(3)+REG(0)) |
169  (REG(1)+REG(3)+REG(0)+REG(2)) |
170  (REG(1)+REG(3)+REG(2)+REG(0)) |
171  (REG(2)+REG(0)+REG(1)+REG(3)) |
172  (REG(2)+REG(0)+REG(3)+REG(1)) |
173  (REG(2)+REG(1)+REG(0)+REG(3)) |
174  (REG(2)+REG(1)+REG(3)+REG(0)) |
175  (REG(2)+REG(3)+REG(0)+REG(1)) |
176  (REG(2)+REG(3)+REG(1)+REG(0)) |
177  (REG(3)+REG(0)+REG(1)+REG(2)) |
178  (REG(3)+REG(0)+REG(2)+REG(1)) |
179  (REG(3)+REG(1)+REG(0)+REG(2)) |
180  (REG(3)+REG(1)+REG(2)+REG(0)) |
181  (REG(3)+REG(2)+REG(0)+REG(1)) |
182  (REG(3)+REG(2)+REG(1)+REG(0)));
183  }
184  };
185 
187  class RegRoland : public Test {
188  public:
191  : Test("Extensional::Reg::Roland::"+str(n),n,0,1) {}
193  virtual bool solution(const Assignment& x) const {
194  int n = x.size();
195  return
196  ((n > 1) && (x[n-2] == 0)) ||
197  ((n > 0) && (x[n-1] == 0));
198  }
200  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
201  using namespace Gecode;
202  REG r0(0), r1(1);
203  REG r01 = r0 | r1;
204  extensional(home, x, *r01 + r0 + r01(0,1));
205  }
206  };
207 
209  class RegSharedA : public Test {
210  public:
212  RegSharedA(void) : Test("Extensional::Reg::Shared::A",4,2,2) {}
214  virtual bool solution(const Assignment& x) const {
215  return (((x[0] == 0) || (x[0] == 2)) &&
216  ((x[1] == -1) || (x[1] == 1)) &&
217  ((x[2] == 0) || (x[2] == 1)) &&
218  ((x[3] == 0) || (x[3] == 1)));
219  }
221  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
222  using namespace Gecode;
223  IntVarArgs y(8);
224  for (int i=0; i<4; i++)
225  y[i]=y[i+4]=x[i];
226  unshare(home,y);
227  extensional(home, y,
228  ((REG(0) | REG(2)) +
229  (REG(-1) | REG(1)) +
230  (REG(7) | REG(0) | REG(1)) +
231  (REG(0) | REG(1)))(2,2));
232  }
233  };
234 
236  class RegSharedB : public Test {
237  public:
239  RegSharedB(void) : Test("Extensional::Reg::Shared::B",4,2,2) {}
241  virtual bool solution(const Assignment& x) const {
242  return (((x[0] == 0) || (x[0] == 2)) &&
243  ((x[1] == -1) || (x[1] == 1)) &&
244  ((x[2] == 0) || (x[2] == 1)) &&
245  ((x[3] == 0) || (x[3] == 1)));
246  }
248  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
249  using namespace Gecode;
250  IntVarArgs y(12);
251  for (int i=0; i<4; i++)
252  y[i]=y[i+4]=y[i+8]=x[i];
253  unshare(home,y);
254  extensional(home, y,
255  ((REG(0) | REG(2)) +
256  (REG(-1) | REG(1)) +
257  (REG(7) | REG(0) | REG(1)) +
258  (REG(0) | REG(1)))(3,3));
259  }
260  };
261 
263  class RegSharedC : public Test {
264  public:
266  RegSharedC(void) : Test("Extensional::Reg::Shared::C",4,0,1) {}
268  virtual bool solution(const Assignment& x) const {
269  return (x[1]==1) && (x[2]==0) && (x[3]==1);
270  }
272  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
273  using namespace Gecode;
275  for (int i=0; i<4; i++)
276  y[i]=y[i+4]=channel(home,x[i]);
277  unshare(home,y);
278  extensional(home,y,
279  ((REG(0) | REG(1)) + REG(1) + REG(0) + REG(1))(2,2));
280  }
281  };
282 
284  class RegSharedD : public Test {
285  public:
287  RegSharedD(void) : Test("Extensional::Reg::Shared::D",4,0,1) {}
289  virtual bool solution(const Assignment& x) const {
290  return (x[1]==1) && (x[2]==0) && (x[3]==1);
291  }
293  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
294  using namespace Gecode;
296  for (int i=0; i<4; i++)
297  y[i]=y[i+4]=y[i+8]=channel(home,x[i]);
298  unshare(home, y);
299  extensional(home, y,
300  ((REG(0) | REG(1)) + REG(1) + REG(0) + REG(1))(3,3));
301  }
302  };
303 
305  class RegEmptyDFA : public Test {
306  public:
308  RegEmptyDFA(void) : Test("Extensional::Reg::Empty::DFA",1,0,0) {
309  testsearch = false;
310  }
312  virtual bool solution(const Assignment& x) const {
313  (void)x;
314  return false;
315  }
317  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
318  Gecode::DFA d;
319  Gecode::extensional(home, x, d);
320  }
321  };
322 
324  class RegEmptyREG : public Test {
325  public:
327  RegEmptyREG(void) : Test("Extensional::Reg::Empty::REG",1,0,0) {
328  testsearch = false;
329  }
331  virtual bool solution(const Assignment& x) const {
332  (void)x;
333  return false;
334  }
336  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
337  Gecode::REG r;
338  Gecode::extensional(home, x, r);
339  }
340  };
341 
343  class RegOpt : public Test {
344  protected:
346  int n;
347  public:
349  RegOpt(int n0)
350  : Test("Extensional::Reg::Opt::"+str(n0),1,0,15), n(n0) {}
352  virtual bool solution(const Assignment& x) const {
353  return (x[0] < n) && ((x[0] & 1) == 0);
354  }
356  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
357  using namespace Gecode;
358  DFA::Transition* t = new DFA::Transition[n+1];
359  DFA::Transition* ti = t;
360  int* f = new int[n+1];
361  int* fi = f;
362  for (int i=0; i<n; i++) {
363  ti->i_state = 0;
364  ti->symbol = i;
365  ti->o_state = i+1;
366  ti++;
367  if ((i & 1) == 0) {
368  *fi = i+1; fi++;
369  }
370  }
371  ti->i_state = -1;
372  *fi = -1;
373  DFA d(0, t, f, false);
374  delete [] t;
375  delete [] f;
376  extensional(home, x, d);
377  }
378 
379  };
380 
383  using namespace Gecode;
384  REG expression;
385  for (int i = 0; i<ts.tuples(); i++) {
386  REG r;
387  for (int j = 0; j<ts.arity(); j++) {
388  r += REG(ts[i][j]);
389  }
390  expression |= r;
391  }
392  DFA dfa(expression);
393  return dfa;
394  }
395 
397  class TupleSetBase : public Test {
398  public:
401  : Test("Extensional::TupleSet::Base",
402  4,1,5,false,Gecode::IPL_DOM) {}
404  virtual bool solution(const Assignment& x) const {
405  return ((x[0] == 1 && x[1] == 3 && x[2] == 2 && x[3] == 3) ||
406  (x[0] == 2 && x[1] == 1 && x[2] == 2 && x[3] == 4) ||
407  (x[0] == 2 && x[1] == 2 && x[2] == 1 && x[3] == 4) ||
408  (x[0] == 3 && x[1] == 3 && x[2] == 3 && x[3] == 2) ||
409  (x[0] == 4 && x[1] == 3 && x[2] == 4 && x[3] == 1)
410  );
411  }
413  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
414  using namespace Gecode;
415  TupleSet t(4);
416  IntArgs t1(4, 2, 1, 2, 4);
417  IntArgs t2(4, 2, 2, 1, 4);
418  IntArgs t3(4, 4, 3, 4, 1);
419  IntArgs t4(4, 1, 3, 2, 3);
420  IntArgs t5(4, 3, 3, 3, 2);
421  t.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  .add(t1).add(t1).add(t2).add(t2)
426  .add(t3).add(t3).add(t4).add(t4)
427  .add(t5).add(t5).add(t5).add(t5)
428  .add(t5).add(t5).add(t5).add(t5)
429  .finalize();
430 
431  TupleSet ts = TupleSet(t.arity(),tupleset2dfa(t));
432  assert(t == ts);
433  extensional(home, x, t, ipl);
434  }
435  };
436 
438  class TupleSetTest : public Test {
439  protected:
443  bool toDFA;
444  public:
446  TupleSetTest(const std::string& s,
447  Gecode::IntSet d0, Gecode::TupleSet ts0, bool td)
448  : Test("Extensional::TupleSet::"+s,
449  ts0.arity(),d0,false,Gecode::IPL_DOM), ts(ts0) {
450  toDFA = td;
451  }
453  virtual bool solution(const Assignment& x) const {
454  using namespace Gecode;
455  for (int i=ts.tuples(); i--; ) {
456  TupleSet::Tuple t = ts[i];
457  bool same = true;
458  for (int j=0; (j < ts.arity()) && same; j++)
459  if (t[j] != x[j])
460  same = false;
461  if (same)
462  return true;
463  }
464  return false;
465  }
467  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
468  using namespace Gecode;
469 
470  if (toDFA) {
471  TupleSet t = TupleSet(ts.arity(),tupleset2dfa(ts));
472  assert(ts == t);
473  }
474  extensional(home, x, ts, ipl);
475  }
476  };
477 
479  public:
481  RandomTupleSetTest(const std::string& s,
483  : TupleSetTest(s,d0,ts0,false) {
484  testsearch = false;
485  }
487  virtual Assignment* assignment(void) const {
488  using namespace Gecode;
489  return new RandomAssignment(arity,dom,1000);
490  }
491  };
492 
494  class TupleSetLarge : public Test {
495  mutable Gecode::TupleSet t;
496  public:
498  TupleSetLarge(double prob)
499  : Test("Extensional::TupleSet::Large",
500  5,1,5,false,Gecode::IPL_DOM), t(5) {
501  using namespace Gecode;
502 
503  CpltAssignment ass(5, IntSet(1, 5));
504  while (ass()) {
505  if (Base::rand(100) <= prob*100) {
506  IntArgs tuple(5);
507  for (int i = 5; i--; ) tuple[i] = ass[i];
508  t.add(tuple);
509  }
510  ++ass;
511  }
512  t.finalize();
513  }
515  virtual bool solution(const Assignment& x) const {
516  using namespace Gecode;
517  for (int i = 0; i < t.tuples(); ++i) {
518  TupleSet::Tuple l = t[i];
519  bool same = true;
520  for (int j = 0; j < t.arity() && same; ++j)
521  if (l[j] != x[j]) same = false;
522  if (same) return true;
523  }
524  return false;
525  }
527  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
528  using namespace Gecode;
529  extensional(home, x, t, ipl);
530  }
531  };
532 
534  class TupleSetBool : public Test {
535  mutable Gecode::TupleSet t;
536  public:
538  TupleSetBool(double prob)
539  : Test("Extensional::TupleSet::Bool",
540  5,0,1,false), t(5) {
541  using namespace Gecode;
542 
543  CpltAssignment ass(5, IntSet(0, 1));
544  while (ass()) {
545  if (Base::rand(100) <= prob*100) {
546  IntArgs tuple(5);
547  for (int i = 5; i--; ) tuple[i] = ass[i];
548  t.add(tuple);
549  }
550  ++ass;
551  }
552  t.finalize();
553  }
555  virtual bool solution(const Assignment& x) const {
556  using namespace Gecode;
557  for (int i = 0; i < t.tuples(); ++i) {
558  TupleSet::Tuple l = t[i];
559  bool same = true;
560  for (int j = 0; j < t.arity() && same; ++j)
561  if (l[j] != x[j]) same = false;
562  if (same) return true;
563  }
564  return false;
565  }
567  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
568  using namespace Gecode;
569  BoolVarArgs y(x.size());
570  for (int i = x.size(); i--; )
571  y[i] = channel(home, x[i]);
572  extensional(home, y, t, ipl);
573  }
574  };
575 
578  public:
581  using namespace Gecode;
583  int arity = 2;
584  int n_tuples = 5*5;
585  while (n_tuples < size) {
586  arity++;
587  n_tuples*=5;
588  }
590  TupleSet ts(arity);
591  CpltAssignment ass(arity, IntSet(0, 4));
592  for (int i = size; i--; ) {
593  assert(ass());
594  IntArgs tuple(arity);
595  for (int j = arity; j--; ) tuple[j] = ass[j];
596  ts.add(tuple);
597  ++ass;
598  }
599  ts.finalize();
600  assert(ts.tuples() == size);
601  // Create and register test
602  (void) new TupleSetTest(std::to_string(size),IntSet(0,4),ts,
603  size <= 128);
604  }
605  };
606 
607  Gecode::TupleSet randomTupleSet(int n, int min, int max, double prob) {
608  using namespace Gecode;
609  TupleSet t(n);
610  CpltAssignment ass(n, IntSet(min, max));
611  while (ass()) {
612  if (Base::rand(100) <= prob*100) {
613  IntArgs tuple(n);
614  for (int i = n; i--; ) tuple[i] = ass[i];
615  t.add(tuple);
616  }
617  ++ass;
618  }
619  t.finalize();
620  return t;
621  }
622 
624  class Create {
625  public:
627  Create(void) {
628  using namespace Gecode;
629  {
630  TupleSet ts(4);
631  ts.add(2, 1, 2, 4).add(2, 2, 1, 4)
632  .add(4, 3, 4, 1).add(1, 3, 2, 3)
633  .add(3, 3, 3, 2).add(5, 1, 4, 4)
634  .add(2, 5, 1, 5).add(4, 3, 5, 1)
635  .add(1, 5, 2, 5).add(5, 3, 3, 2)
636  .finalize();
637  (void) new TupleSetTest("A",IntSet(0,6),ts,true);
638  }
639  {
640  TupleSet ts(4);
641  ts.finalize();
642  (void) new TupleSetTest("Empty",IntSet(1,2),ts,true);
643  }
644  {
645  TupleSet ts(4);
646  for (int n=1024*16; n--; )
647  ts.add(1,2,3,4);
648  ts.finalize();
649  (void) new TupleSetTest("Assigned",IntSet(1,4),ts,true);
650  }
651  {
652  TupleSet ts(1);
653  ts.add(1).add(2).add(3).finalize();
654  (void) new TupleSetTest("Single",IntSet(-4,4),ts,true);
655  }
656  {
657  int m = Gecode::Int::Limits::min;
658  TupleSet ts(3);
659  ts.add(m+0,m+1,m+2).add(m+4,m+1,m+3)
660  .add(m+2,m+3,m+0).add(m+2,m+3,m+0)
661  .add(m+1,m+2,m+5).add(m+2,m+3,m+0)
662  .add(m+3,m+6,m+5).finalize();
663  (void) new TupleSetTest("Min",IntSet(m,m+7),ts,true);
664  }
665  {
666  int M = Gecode::Int::Limits::max;
667  TupleSet ts(3);
668  ts.add(M-0,M-1,M-2).add(M-4,M-1,M-3)
669  .add(M-2,M-3,M-0).add(M-2,M-3,M-0)
670  .add(M-1,M-2,M-5).add(M-2,M-3,M-0)
671  .add(M-3,M-6,M-5).finalize();
672  (void) new TupleSetTest("Max",IntSet(M-7,M),ts,true);
673  }
674  {
675  int m = Gecode::Int::Limits::min;
676  int M = Gecode::Int::Limits::max;
677  TupleSet ts(3);
678  ts.add(M-0,m+1,M-2).add(m+4,M-1,M-3)
679  .add(m+2,M-3,m+0).add(M-2,M-3,M-0)
680  .finalize();
681  (void) new TupleSetTest("MinMax",
682  IntSet(IntArgs(6, m,m+1,m+4,M-3,M-2,M)),
683  ts,true);
684  }
685  {
686  TupleSet ts(7);
687  for (int i = 0; i < 10000; i++) {
688  IntArgs tuple(7);
689  for (int j = 0; j < 7; j++) {
690  tuple[j] = Base::rand(j+1);
691  }
692  ts.add(tuple);
693  }
694  ts.finalize();
695  (void) new RandomTupleSetTest("Triangle",IntSet(0,6),ts);
696  }
697  {
698  for (int i = 0; i <= 64*6; i+=32)
699  (void) new TupleSetTestSize(i);
700  }
701  {
702  (void) new RandomTupleSetTest("Rand(10,-1,2)", IntSet(-1,2),
703  randomTupleSet(10,-1,2,0.05));
704  (void) new RandomTupleSetTest("Rand(5,-10,10)", IntSet(-10,10),
705  randomTupleSet(5,-10,10,0.05));
706  }
707  {
708  TupleSet t(5);
709  CpltAssignment ass(4, IntSet(1, 4));
710  while (ass()) {
711  IntArgs tuple(5);
712  tuple[4] = 1;
713  for (int i = 4; i--; ) tuple[i] = ass[i];
714  t.add(tuple);
715  ++ass;
716  }
717  t.add(2,2,4,3,4);
718  t.finalize();
719  (void) new TupleSetTest("FewLast",IntSet(1,4),t,false);
720  }
721  {
722  TupleSet t(4);
723  CpltAssignment ass(4, IntSet(1, 6));
724  while (ass()) {
725  t.add(ass[0],0,ass[1],ass[2]);
726  ++ass;
727  }
728  t.add(2,-1,3,4);
729  t.finalize();
730  (void) new TupleSetTest("FewMiddle",IntSet(-1,6),t,false);
731  }
732  {
733  TupleSet t(10);
734  CpltAssignment ass(9, IntSet(1, 4));
735  while (ass()) {
736  if (Base::rand(100) <= 0.25*100) {
737  IntArgs tuple(10);
738  tuple[0] = 2;
739  for (int i = 9; i--; ) tuple[i+1] = ass[i];
740  t.add(tuple);
741  }
742  ++ass;
743  }
744  t.add(1,1,1,1,1,1,1,1,1,1);
745  t.add(1,2,3,4,4,2,1,2,3,3);
746  t.finalize();
747  (void) new RandomTupleSetTest("FewHuge",IntSet(1,4),t);
748  }
749  }
750  };
751 
753 
757 
759 
760  RegRoland rr1(1);
761  RegRoland rr2(2);
762  RegRoland rr3(3);
763  RegRoland rr4(4);
764 
769 
772 
773  RegOpt ro0(CHAR_MAX-1);
774  RegOpt ro1(CHAR_MAX);
775  RegOpt ro2(static_cast<int>(UCHAR_MAX-1));
776  RegOpt ro3(static_cast<int>(UCHAR_MAX));
777  RegOpt ro4(SHRT_MAX-1);
778  RegOpt ro5(SHRT_MAX);
779  RegOpt ro6(static_cast<int>(USHRT_MAX-1));
780  RegOpt ro7(static_cast<int>(USHRT_MAX));
781 
783 
784  TupleSetLarge tsl(0.05);
785 
786  TupleSetBool tsbool(0.3);
788 
789  }
790 }}
791 
792 
793 // 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:2039
NodeType t
Type of node.
Definition: bool-expr.cpp:234
static std::string str(Gecode::IntPropLevel ipl)
Map integer propagation level to string.
Definition: int.hpp:212
Gecode::TupleSet randomTupleSet(int n, int min, int max, double prob)
void finalize(void)
Finalize tuple set.
Definition: tuple-set.hpp:159
NNF * l
Left subtree.
Definition: bool-expr.cpp:244
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:45
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:973
const FloatNum max
Largest allowed float value.
Definition: float.hh:848
Test for optimizations
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: extensional.cpp:72
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:50
int arity(void) const
Arity of tuple set.
Definition: tuple-set.hpp:185
Test with regular expression for distinct constraint
static Gecode::Support::RandomGenerator rand
Random number generator.
Definition: test.hh:138
Regular expressions over integer values.
Definition: minimodel.hh:1522
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:45
Test with simple regular expression
Definition: extensional.cpp:83
int * Tuple
Type of a tuple.
Definition: int.hh:2150
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:232
void unshare(Home home, VarArgArray< Var > &x, IntPropLevel ipl)
Replace unassigned shared variables by fresh, yet equal variables.
Definition: unshare.cpp:112
virtual bool solution(const Assignment &x) const
Test whether x is solution
Integer variable array.
Definition: int.hh:742
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:116
Computation spaces.
Definition: core.hpp:1668
Generate random selection of assignments.
Definition: int.hh:100
int i_state
input state
Definition: int.hh:2038
RegOpt ro1(CHAR_MAX)
RegOpt ro0(CHAR_MAX-1)
const int min
Smallest allowed integer value.
Definition: int.hh:118
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:189
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:2027
const FloatNum min
Smallest allowed float value.
Definition: float.hh:850
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:238
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:47
Specification of a DFA transition.
Definition: int.hh:2036
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:174
int o_state
output state Default constructor
Definition: int.hh:2040
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: extensional.cpp:92
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:238
Passing integer variables.
Definition: int.hh:637
Passing integer arguments.
Definition: int.hh:608
Passing Boolean variables.
Definition: int.hh:691
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:2144
RegSharedD(void)
Create and register test.
General test support.
Definition: afc.cpp:43
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:769
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: extensional.cpp:88
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
virtual bool solution(const Assignment &x) const
Test whether x is solution
bool testsearch
Whether to perform search test.
Definition: int.hh:242
Region r
Definition: region.cpp:69
Base class for assignments
Definition: int.hh:63
void extensional(Home home, const BoolVarArgs &x, const TupleSet &t, IntPropLevel)
Post propagator for .
Definition: extensional.cpp:89
bool same(const Item &i, const Item &j)
Whether two items are the same.
Definition: propagate.hpp:76
Test with simple regular expression and shared variables (uses unsharing)
Domain propagation Options: basic versus advanced propagation.
Definition: int.hh:958
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:146
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:65
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:230
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:83
virtual bool solution(const Assignment &x) const
Test whether x is solution
RegSimpleA(void)
Create and register test.
Definition: extensional.cpp:63
RegSimpleB(void)
Create and register test.
Definition: extensional.cpp:86
Test with simple regular expression
Definition: extensional.cpp:60