File: arithmetic.cpp

package info (click to toggle)
gecode 3.4.0-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 10,136 kB
  • ctags: 16,905
  • sloc: cpp: 124,581; perl: 2,004; makefile: 1,453; sh: 247
file content (772 lines) | stat: -rwxr-xr-x 29,037 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
 *  Main authors:
 *     Christian Schulte <schulte@gecode.org>
 *
 *  Copyright:
 *     Christian Schulte, 2005
 *
 *  Last modified:
 *     $Date: 2010-04-08 12:35:31 +0200 (Thu, 08 Apr 2010) $ by $Author: schulte $
 *     $Revision: 10684 $
 *
 *  This file is part of Gecode, the generic constraint
 *  development environment:
 *     http://www.gecode.org
 *
 *  Permission is hereby granted, free of charge, to any person obtaining
 *  a copy of this software and associated documentation files (the
 *  "Software"), to deal in the Software without restriction, including
 *  without limitation the rights to use, copy, modify, merge, publish,
 *  distribute, sublicense, and/or sell copies of the Software, and to
 *  permit persons to whom the Software is furnished to do so, subject to
 *  the following conditions:
 *
 *  The above copyright notice and this permission notice shall be
 *  included in all copies or substantial portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */

#include "test/int.hh"

#include <cmath>
#include <algorithm>

namespace Test { namespace Int {

   /// %Tests for arithmetic constraints
   namespace Arithmetic {

     /**
      * \defgroup TaskTestIntArithmetic Arithmetic constraints
      * \ingroup TaskTestInt
      */
     //@{
     /// %Test for multiplication constraint
     class MultXYZ : public Test {
     public:
       /// Create and register test
       MultXYZ(const std::string& s, const Gecode::IntSet& d,
               Gecode::IntConLevel icl)
         : Test("Arithmetic::Mult::XYZ::"+str(icl)+"::"+s,3,d,false,icl) {}
       /// %Test whether \a x is solution
       virtual bool solution(const Assignment& x) const {
         double d0 = static_cast<double>(x[0]);
         double d1 = static_cast<double>(x[1]);
         double d2 = static_cast<double>(x[2]);
         return d0*d1 == d2;
       }
       /// Post constraint on \a x
       virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
         Gecode::mult(home, x[0], x[1], x[2], icl);
       }
     };

     /// %Test for multiplication constraint with shared variables
     class MultXXY : public Test {
     public:
       /// Create and register test
       MultXXY(const std::string& s, const Gecode::IntSet& d,
               Gecode::IntConLevel icl)
         : Test("Arithmetic::Mult::XXY::"+str(icl)+"::"+s,2,d,false,icl) {}
       /// %Test whether \a x is solution
       virtual bool solution(const Assignment& x) const {
         double d0 = static_cast<double>(x[0]);
         double d1 = static_cast<double>(x[0]);
         double d2 = static_cast<double>(x[1]);
         return d0*d1 == d2;
       }
       /// Post constraint on \a x
       virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
         Gecode::mult(home, x[0], x[0], x[1], icl);
       }
     };

     /// %Test for multiplication constraint with shared variables
     class MultXYX : public Test {
     public:
       /// Create and register test
       MultXYX(const std::string& s, const Gecode::IntSet& d,
               Gecode::IntConLevel icl)
         : Test("Arithmetic::Mult::XYX::"+str(icl)+"::"+s,2,d,false,icl) {}
       /// %Test whether \a x is solution
       virtual bool solution(const Assignment& x) const {
         double d0 = static_cast<double>(x[0]);
         double d1 = static_cast<double>(x[1]);
         double d2 = static_cast<double>(x[0]);
         return d0*d1 == d2;
       }
       /// Post constraint on \a x
       virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
         Gecode::mult(home, x[0], x[1], x[0], icl);
       }
     };

     /// %Test for multiplication constraint with shared variables
     class MultXYY : public Test {
     public:
       /// Create and register test
       MultXYY(const std::string& s, const Gecode::IntSet& d,
               Gecode::IntConLevel icl)
         : Test("Arithmetic::Mult::XYY::"+str(icl)+"::"+s,2,d,false,icl) {}
       /// %Test whether \a x is solution
       virtual bool solution(const Assignment& x) const {
         double d0 = static_cast<double>(x[0]);
         double d1 = static_cast<double>(x[1]);
         double d2 = static_cast<double>(x[1]);
         return d0*d1 == d2;
       }
       /// Post constraint on \a x
       virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
         Gecode::mult(home, x[0], x[1], x[1], icl);
       }
     };

     /// %Test for multiplication constraint with shared variables
     class MultXXX : public Test {
     public:
       /// Create and register test
       MultXXX(const std::string& s, const Gecode::IntSet& d,
               Gecode::IntConLevel icl)
         : Test("Arithmetic::Mult::XXX::"+str(icl)+"::"+s,1,d,false,icl) {}
       /// %Test whether \a x is solution
       virtual bool solution(const Assignment& x) const {
         double d0 = static_cast<double>(x[0]);
         double d1 = static_cast<double>(x[0]);
         double d2 = static_cast<double>(x[0]);
         return d0*d1 == d2;
       }
       /// Post constraint on \a x
       virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
         Gecode::mult(home, x[0], x[0], x[0], icl);
       }
     };

     /// %Test for squaring constraint
     class SqrXY : public Test {
     public:
       /// Create and register test
       SqrXY(const std::string& s, const Gecode::IntSet& d,
             Gecode::IntConLevel icl)
         : Test("Arithmetic::Sqr::XY::"+str(icl)+"::"+s,2,d,false,icl) {}
       /// %Test whether \a x is solution
       virtual bool solution(const Assignment& x) const {
         double d0 = static_cast<double>(x[0]);
         double d1 = static_cast<double>(x[1]);
         return d0*d0 == d1;
       }
       /// Post constraint on \a x
       virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
         Gecode::sqr(home, x[0], x[1], icl);
       }
     };

     /// %Test for squaring constraint with shared variables
     class SqrXX : public Test {
     public:
       /// Create and register test
       SqrXX(const std::string& s, const Gecode::IntSet& d,
             Gecode::IntConLevel icl)
         : Test("Arithmetic::Sqr::XX::"+str(icl)+"::"+s,1,d,false,icl) {}
       /// %Test whether \a x is solution
       virtual bool solution(const Assignment& x) const {
         double d0 = static_cast<double>(x[0]);
         return d0*d0 == d0;
       }
       /// Post constraint on \a x
       virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
         Gecode::sqr(home, x[0], x[0], icl);
       }
     };

     /// %Test for square root constraint
     class SqrtXY : public Test {
     public:
       /// Create and register test
       SqrtXY(const std::string& s, const Gecode::IntSet& d,
              Gecode::IntConLevel icl)
         : Test("Arithmetic::Sqrt::XY::"+str(icl)+"::"+s,2,d,false,icl) {}
       /// %Test whether \a x is solution
       virtual bool solution(const Assignment& x) const {
         double d0 = static_cast<double>(x[0]);
         double d1 = static_cast<double>(x[1]);
         return (d0 >= 0) && (d0 >= d1*d1) && (d0 < (d1+1)*(d1+1));
       }
       /// Post constraint on \a x
       virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
         Gecode::sqrt(home, x[0], x[1], icl);
       }
     };

     /// %Test for square root constraint with shared variables
     class SqrtXX : public Test {
     public:
       /// Create and register test
       SqrtXX(const std::string& s, const Gecode::IntSet& d,
              Gecode::IntConLevel icl)
         : Test("Arithmetic::Sqrt::XX::"+str(icl)+"::"+s,1,d,false,icl) {}
       /// %Test whether \a x is solution
       virtual bool solution(const Assignment& x) const {
         double d0 = static_cast<double>(x[0]);
         return (d0 >= 0) && (d0 >= d0*d0) && (d0 < (d0+1)*(d0+1));
       }
       /// Post constraint on \a x
       virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
         Gecode::sqrt(home, x[0], x[0], icl);
       }
     };

     /// %Test for division/modulo constraint
     class DivMod : public Test {
     private:
       static int abs(int a) { return a<0 ? -a:a; }
       static int sgn(int a) { return a<0 ? -1:1; }
     public:
       /// Create and register test
       DivMod(const std::string& s, const Gecode::IntSet& d)
         : Test("Arithmetic::DivMod::"+s,4,d,false,icl) {}
       /// %Test whether \a x is solution
       virtual bool solution(const Assignment& x) const {
         return x[0] == x[1]*x[2]+x[3] &&
                abs(x[3]) < abs(x[1]) &&
                (x[3] == 0 || sgn(x[3]) == sgn(x[0]));
       }
       /// Post constraint on \a x
       virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
         Gecode::divmod(home, x[0], x[1], x[2], x[3], icl);
       }
     };

     /// %Test for division constraint
     class Div : public Test {
     public:
       /// Create and register test
       Div(const std::string& s, const Gecode::IntSet& d)
         : Test("Arithmetic::Div::"+s,3,d,false,icl) {}
       /// %Test whether \a x is solution
       virtual bool solution(const Assignment& x) const {
         if (x[1] == 0)
           return false;
         int divsign = (x[0] / x[1] < 0) ? -1 : 1;
         int divresult =
           divsign *
           static_cast<int>(floor(static_cast<double>(std::abs(x[0]))/
                                  static_cast<double>(std::abs(x[1]))));
         return x[2] == divresult;
       }
       /// Post constraint on \a x
       virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
         Gecode::div(home, x[0], x[1], x[2], icl);
       }
     };

     /// %Test for modulo constraint
     class Mod : public Test {
     public:
       /// Create and register test
       Mod(const std::string& s, const Gecode::IntSet& d)
         : Test("Arithmetic::Mod::"+s,3,d,false,icl) {}
       /// %Test whether \a x is solution
       virtual bool solution(const Assignment& x) const {
         if (x[1] == 0)
           return false;
         int divsign = (x[0] / x[1] < 0) ? -1 : 1;
         int divresult =
           divsign *
           static_cast<int>(floor(static_cast<double>(std::abs(x[0]))/
                                  static_cast<double>(std::abs(x[1]))));
         return x[0] == x[1]*divresult+x[2];
       }
       /// Post constraint on \a x
       virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
         Gecode::mod(home, x[0], x[1], x[2], icl);
       }
     };

     /// %Test for absolute value constraint
     class AbsXY : public Test {
     public:
       /// Create and register test
       AbsXY(const std::string& s, const Gecode::IntSet& d,
             Gecode::IntConLevel icl)
         : Test("Arithmetic::Abs::XY::"+str(icl)+"::"+s,2,d,false,icl) {}
       /// %Test whether \a x is solution
       virtual bool solution(const Assignment& x) const {
         double d0 = static_cast<double>(x[0]);
         double d1 = static_cast<double>(x[1]);
         return (d0<0 ? -d0 : d0) == d1;
       }
       /// Post constraint on \a x
       virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
         Gecode::abs(home, x[0], x[1], icl);
       }
     };

     /// %Test for absolute value constraint with shared variables
     class AbsXX : public Test {
     public:
       /// Create and register test
       AbsXX(const std::string& s, const Gecode::IntSet& d,
             Gecode::IntConLevel icl)
         : Test("Arithmetic::Abs::XX::"+str(icl)+"::"+s,1,d,false,icl) {}
       /// %Test whether \a x is solution
       virtual bool solution(const Assignment& x) const {
         double d0 = static_cast<double>(x[0]);
         double d1 = static_cast<double>(x[0]);
         return (d0<0 ? -d0 : d0) == d1;
       }
       /// Post constraint on \a x
       virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
         Gecode::abs(home, x[0], x[0], icl);
       }
     };

     /// %Test for binary minimum constraint
     class MinXYZ : public Test {
     public:
       /// Create and register test
       MinXYZ(const std::string& s, const Gecode::IntSet& d,
              Gecode::IntConLevel icl)
         : Test("Arithmetic::Min::Bin::XYZ::"+str(icl)+"::"+s,3,d,false,icl) {}
       /// %Test whether \a x is solution
       virtual bool solution(const Assignment& x) const {
         return std::min(x[0],x[1]) == x[2];
       }
       /// Post constraint on \a x
       virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
         Gecode::min(home, x[0], x[1], x[2], icl);
       }
     };

     /// %Test for binary minimum constraint with shared variables
     class MinXXY : public Test {
     public:
       /// Create and register test
       MinXXY(const std::string& s, const Gecode::IntSet& d,
              Gecode::IntConLevel icl)
         : Test("Arithmetic::Min::Bin::XYX::"+str(icl)+"::"+s,2,d) {}
       /// %Test whether \a x is solution
       virtual bool solution(const Assignment& x) const {
         return std::min(x[0],x[0]) == x[1];
       }
       /// Post constraint on \a x
       virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
         Gecode::min(home, x[0], x[0], x[1], icl);
       }
     };

     /// %Test for binary minimum constraint with shared variables
     class MinXYX : public Test {
     public:
       /// Create and register test
       MinXYX(const std::string& s, const Gecode::IntSet& d,
              Gecode::IntConLevel icl)
         : Test("Arithmetic::Min::Bin::XYX::"+str(icl)+"::"+s,2,d) {}
       /// %Test whether \a x is solution
       virtual bool solution(const Assignment& x) const {
         return std::min(x[0],x[1]) == x[0];
       }
       /// Post constraint on \a x
       virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
         Gecode::min(home, x[0], x[1], x[0], icl);
       }
     };

     /// %Test for binary minimum constraint with shared variables
     class MinXYY : public Test {
     public:
       /// Create and register test
       MinXYY(const std::string& s, const Gecode::IntSet& d,
              Gecode::IntConLevel icl)
         : Test("Arithmetic::Min::Bin::XYY::"+str(icl)+"::"+s,2,d) {}
       /// %Test whether \a x is solution
       virtual bool solution(const Assignment& x) const {
         return std::min(x[0],x[1]) == x[1];
       }
       /// Post constraint on \a x
       virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
         Gecode::min(home, x[0], x[1], x[1], icl);
       }
     };

     /// %Test for binary minimum constraint with shared variables
     class MinXXX : public Test {
     public:
       /// Create and register test
       MinXXX(const std::string& s, const Gecode::IntSet& d,
              Gecode::IntConLevel icl)
         : Test("Arithmetic::Min::Bin::XXX::"+str(icl)+"::"+s,1,d) {}
       /// %Test whether \a x is solution
       virtual bool solution(const Assignment& x) const {
         return std::min(x[0],x[0]) == x[0];
       }
       /// Post constraint on \a x
       virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
         Gecode::min(home, x[0], x[0], x[0], icl);
       }
     };

     /// %Test for binary maximum constraint
     class MaxXYZ : public Test {
     public:
       /// Create and register test
       MaxXYZ(const std::string& s, const Gecode::IntSet& d,
              Gecode::IntConLevel icl)
         : Test("Arithmetic::Max::Bin::XYZ::"+str(icl)+"::"+s,3,d) {
         contest = CTL_BOUNDS_Z;
       }
       /// %Test whether \a x is solution
       virtual bool solution(const Assignment& x) const {
         return std::max(x[0],x[1]) == x[2];
       }
       /// Post constraint on \a x
       virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
         Gecode::max(home, x[0], x[1], x[2], icl);
       }
     };

     /// %Test for binary maximum constraint with shared variables
     class MaxXXY : public Test {
     public:
       /// Create and register test
       MaxXXY(const std::string& s, const Gecode::IntSet& d,
              Gecode::IntConLevel icl)
         : Test("Arithmetic::Max::Bin::XXY::"+str(icl)+"::"+s,2,d) {}
       /// %Test whether \a x is solution
       virtual bool solution(const Assignment& x) const {
         return std::max(x[0],x[0]) == x[1];
       }
       /// Post constraint on \a x
       virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
         Gecode::max(home, x[0], x[0], x[1], icl);
       }
     };

     /// %Test for binary maximum constraint with shared variables
     class MaxXYX : public Test {
     public:
       /// Create and register test
       MaxXYX(const std::string& s, const Gecode::IntSet& d,
              Gecode::IntConLevel icl)
         : Test("Arithmetic::Max::Bin::XYX::"+str(icl)+"::"+s,2,d) {}
       /// %Test whether \a x is solution
       virtual bool solution(const Assignment& x) const {
         return std::max(x[0],x[1]) == x[0];
       }
       /// Post constraint on \a x
       virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
         Gecode::max(home, x[0], x[1], x[0], icl);
       }
     };

     /// %Test for binary maximum constraint with shared variables
     class MaxXYY : public Test {
     public:
       /// Create and register test
       MaxXYY(const std::string& s, const Gecode::IntSet& d,
              Gecode::IntConLevel icl)
         : Test("Arithmetic::Max::Bin::XYY::"+str(icl)+"::"+s,2,d) {}
       /// %Test whether \a x is solution
       virtual bool solution(const Assignment& x) const {
         return std::max(x[0],x[1]) == x[1];
       }
       /// Post constraint on \a x
       virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
         Gecode::max(home, x[0], x[1], x[1], icl);
       }
     };

     /// %Test for binary maximum constraint with shared variables
     class MaxXXX : public Test {
     public:
       /// Create and register test
       MaxXXX(const std::string& s, const Gecode::IntSet& d,
              Gecode::IntConLevel icl)
         : Test("Arithmetic::Max::Bin::XXX::"+str(icl)+"::"+s,1,d) {}
       /// %Test whether \a x is solution
       virtual bool solution(const Assignment& x) const {
         return std::max(x[0],x[0]) == x[0];
       }
       /// Post constraint on \a x
       virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
         Gecode::max(home, x[0], x[0], x[0], icl);
       }
     };

     /// %Test for n-ary minimmum constraint
     class MinNary : public Test {
     public:
       /// Create and register test
       MinNary(Gecode::IntConLevel icl)
         : Test("Arithmetic::Min::Nary::"+str(icl),4,-4,4,false,icl) {}
       /// %Test whether \a x is solution
       virtual bool solution(const Assignment& x) const {
         return std::min(std::min(x[0],x[1]), x[2]) == x[3];
       }
       /// Post constraint on \a x
       virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
         Gecode::IntVarArgs m(3);
         m[0]=x[0]; m[1]=x[1]; m[2]=x[2];
         Gecode::min(home, m, x[3], icl);
       }
     };

     /// %Test for n-ary minimmum constraint with shared variables
     class MinNaryShared : public Test {
     public:
       /// Create and register test
       MinNaryShared(Gecode::IntConLevel icl)
         : Test("Arithmetic::Min::Nary::Shared::"+str(icl),3,-4,4,false,icl) {}
       /// %Test whether \a x is solution
       virtual bool solution(const Assignment& x) const {
         return std::min(std::min(x[0],x[1]), x[2]) == x[1];
       }
       /// Post constraint on \a x
       virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
         Gecode::IntVarArgs m(3);
         m[0]=x[0]; m[1]=x[1]; m[2]=x[2];
         Gecode::min(home, m, x[1], icl);
       }
     };

     /// %Test for n-ary maximum constraint
     class MaxNary : public Test {
     public:
       /// Create and register test
       MaxNary(Gecode::IntConLevel icl)
         : Test("Arithmetic::Max::Nary::"+str(icl),4,-4,4,false,icl) {}
       /// %Test whether \a x is solution
       virtual bool solution(const Assignment& x) const {
         return std::max(std::max(x[0],x[1]), x[2]) == x[3];
       }
       /// Post constraint on \a x
       virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
         Gecode::IntVarArgs m(3);
         m[0]=x[0]; m[1]=x[1]; m[2]=x[2];
         Gecode::max(home, m, x[3], icl);
       }
     };

     /// %Test for n-ary maximum constraint with shared variables
     class MaxNaryShared : public Test {
     public:
       /// Create and register test
       MaxNaryShared(Gecode::IntConLevel icl)
         : Test("Arithmetic::Max::Nary::Shared::"+str(icl),3,-4,4,false,icl) {}
       /// %Test whether \a x is solution
       virtual bool solution(const Assignment& x) const {
         return std::max(std::max(x[0],x[1]), x[2]) == x[1];
       }
       /// Post constraint on \a x
       virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
         Gecode::IntVarArgs m(3);
         m[0]=x[0]; m[1]=x[1]; m[2]=x[2];
         Gecode::max(home, m, x[1], icl);
       }
     };



     const int va[7] = {
       Gecode::Int::Limits::min, Gecode::Int::Limits::min+1,
       -1,0,1,
       Gecode::Int::Limits::max-1, Gecode::Int::Limits::max
     };
     const int vb[9] = {
       static_cast<int>(-sqrt(static_cast<double>
                              (-Gecode::Int::Limits::min))),
       -4,-2,-1,0,1,2,4,
       static_cast<int>(sqrt(static_cast<double>
                             (Gecode::Int::Limits::max)))
     };

     Gecode::IntSet a(va,7);
     Gecode::IntSet b(vb,9);
     Gecode::IntSet c(-8,8);

     MultXYZ mult_xyz_b_a("A",a,Gecode::ICL_BND);
     MultXYZ mult_xyz_b_b("B",b,Gecode::ICL_BND);
     MultXYZ mult_xyz_b_c("C",c,Gecode::ICL_BND);

     MultXXY mult_xxy_b_a("A",a,Gecode::ICL_BND);
     MultXXY mult_xxy_b_b("B",b,Gecode::ICL_BND);
     MultXXY mult_xxy_b_c("C",c,Gecode::ICL_BND);

     MultXYX mult_xyx_b_a("A",a,Gecode::ICL_BND);
     MultXYX mult_xyx_b_b("B",b,Gecode::ICL_BND);
     MultXYX mult_xyx_b_c("C",c,Gecode::ICL_BND);

     MultXYY mult_xyy_b_a("A",a,Gecode::ICL_BND);
     MultXYY mult_xyy_b_b("B",b,Gecode::ICL_BND);
     MultXYY mult_xyy_b_c("C",c,Gecode::ICL_BND);

     MultXXX mult_xxx_b_a("A",a,Gecode::ICL_BND);
     MultXXX mult_xxx_b_b("B",b,Gecode::ICL_BND);
     MultXXX mult_xxx_b_c("C",c,Gecode::ICL_BND);

     MultXYZ mult_xyz_d_a("A",a,Gecode::ICL_DOM);
     MultXYZ mult_xyz_d_b("B",b,Gecode::ICL_DOM);
     MultXYZ mult_xyz_d_c("C",c,Gecode::ICL_DOM);

     MultXXY mult_xxy_d_a("A",a,Gecode::ICL_DOM);
     MultXXY mult_xxy_d_b("B",b,Gecode::ICL_DOM);
     MultXXY mult_xxy_d_c("C",c,Gecode::ICL_DOM);

     MultXYX mult_xyx_d_a("A",a,Gecode::ICL_DOM);
     MultXYX mult_xyx_d_b("B",b,Gecode::ICL_DOM);
     MultXYX mult_xyx_d_c("C",c,Gecode::ICL_DOM);

     MultXYY mult_xyy_d_a("A",a,Gecode::ICL_DOM);
     MultXYY mult_xyy_d_b("B",b,Gecode::ICL_DOM);
     MultXYY mult_xyy_d_c("C",c,Gecode::ICL_DOM);

     MultXXX mult_xxx_d_a("A",a,Gecode::ICL_DOM);
     MultXXX mult_xxx_d_b("B",b,Gecode::ICL_DOM);
     MultXXX mult_xxx_d_c("C",c,Gecode::ICL_DOM);

     SqrXY sqr_xy_b_a("A",a,Gecode::ICL_BND);
     SqrXY sqr_xy_b_b("B",b,Gecode::ICL_BND);
     SqrXY sqr_xy_b_c("C",c,Gecode::ICL_BND);
     SqrXY sqr_xy_d_a("A",a,Gecode::ICL_DOM);
     SqrXY sqr_xy_d_b("B",b,Gecode::ICL_DOM);
     SqrXY sqr_xy_d_c("C",c,Gecode::ICL_DOM);

     SqrXX sqr_xx_b_a("A",a,Gecode::ICL_BND);
     SqrXX sqr_xx_b_b("B",b,Gecode::ICL_BND);
     SqrXX sqr_xx_b_c("C",c,Gecode::ICL_BND);
     SqrXX sqr_xx_d_a("A",a,Gecode::ICL_DOM);
     SqrXX sqr_xx_d_b("B",b,Gecode::ICL_DOM);
     SqrXX sqr_xx_d_c("C",c,Gecode::ICL_DOM);

     SqrtXY sqrt_xy_b_a("A",a,Gecode::ICL_BND);
     SqrtXY sqrt_xy_b_b("B",b,Gecode::ICL_BND);
     SqrtXY sqrt_xy_b_c("C",c,Gecode::ICL_BND);
     SqrtXY sqrt_xy_d_a("A",a,Gecode::ICL_DOM);
     SqrtXY sqrt_xy_d_b("B",b,Gecode::ICL_DOM);
     SqrtXY sqrt_xy_d_c("C",c,Gecode::ICL_DOM);

     SqrtXX sqrt_xx_b_a("A",a,Gecode::ICL_BND);
     SqrtXX sqrt_xx_b_b("B",b,Gecode::ICL_BND);
     SqrtXX sqrt_xx_b_c("C",c,Gecode::ICL_BND);
     SqrtXX sqrt_xx_d_a("A",a,Gecode::ICL_DOM);
     SqrtXX sqrt_xx_d_b("B",b,Gecode::ICL_DOM);
     SqrtXX sqrt_xx_d_c("C",c,Gecode::ICL_DOM);

     DivMod divmod_a_bnd("A",a);
     DivMod divmod_b_bnd("B",b);
     DivMod divmod_c_bnd("C",c);

     Div div_a_bnd("A",a);
     Div div_b_bnd("B",b);
     Div div_c_bnd("C",c);

     Mod mod_a_bnd("A",a);
     Mod mod_b_bnd("B",b);
     Mod mod_c_bnd("C",c);

     AbsXY abs_xy_b_a("A",a,Gecode::ICL_BND);
     AbsXY abs_xy_b_b("B",b,Gecode::ICL_BND);
     AbsXY abs_xy_b_c("C",c,Gecode::ICL_BND);
     AbsXY abs_xy_d_a("A",a,Gecode::ICL_DOM);
     AbsXY abs_xy_d_b("B",b,Gecode::ICL_DOM);
     AbsXY abs_xy_d_c("C",c,Gecode::ICL_DOM);

     AbsXX abs_xx_b_a("A",a,Gecode::ICL_BND);
     AbsXX abs_xx_b_b("B",b,Gecode::ICL_BND);
     AbsXX abs_xx_b_c("C",c,Gecode::ICL_BND);
     AbsXX abs_xx_d_a("A",a,Gecode::ICL_DOM);
     AbsXX abs_xx_d_b("B",b,Gecode::ICL_DOM);
     AbsXX abs_xx_d_c("C",c,Gecode::ICL_DOM);

     MinXYZ min_xyz_b_a("A",a,Gecode::ICL_BND);
     MinXYZ min_xyz_b_b("B",b,Gecode::ICL_BND);
     MinXYZ min_xyz_b_c("C",c,Gecode::ICL_BND);
     MinXYZ min_xyz_d_a("A",a,Gecode::ICL_DOM);
     MinXYZ min_xyz_d_b("B",b,Gecode::ICL_DOM);
     MinXYZ min_xyz_d_c("C",c,Gecode::ICL_DOM);

     MinXXY min_xxy_b_a("A",a,Gecode::ICL_BND);
     MinXXY min_xxy_b_b("B",b,Gecode::ICL_BND);
     MinXXY min_xxy_b_c("C",c,Gecode::ICL_BND);
     MinXXY min_xxy_d_a("A",a,Gecode::ICL_DOM);
     MinXXY min_xxy_d_b("B",b,Gecode::ICL_DOM);
     MinXXY min_xxy_d_c("C",c,Gecode::ICL_DOM);

     MinXYX min_xyx_b_a("A",a,Gecode::ICL_BND);
     MinXYX min_xyx_b_b("B",b,Gecode::ICL_BND);
     MinXYX min_xyx_b_c("C",c,Gecode::ICL_BND);
     MinXYX min_xyx_d_a("A",a,Gecode::ICL_DOM);
     MinXYX min_xyx_d_b("B",b,Gecode::ICL_DOM);
     MinXYX min_xyx_d_c("C",c,Gecode::ICL_DOM);

     MinXYY min_xyy_b_a("A",a,Gecode::ICL_BND);
     MinXYY min_xyy_b_b("B",b,Gecode::ICL_BND);
     MinXYY min_xyy_b_c("C",c,Gecode::ICL_BND);
     MinXYY min_xyy_d_a("A",a,Gecode::ICL_DOM);
     MinXYY min_xyy_d_b("B",b,Gecode::ICL_DOM);
     MinXYY min_xyy_d_c("C",c,Gecode::ICL_DOM);

     MinXXX min_xxx_b_a("A",a,Gecode::ICL_BND);
     MinXXX min_xxx_b_b("B",b,Gecode::ICL_BND);
     MinXXX min_xxx_b_c("C",c,Gecode::ICL_BND);
     MinXXX min_xxx_d_a("A",a,Gecode::ICL_DOM);
     MinXXX min_xxx_d_b("B",b,Gecode::ICL_DOM);
     MinXXX min_xxx_d_c("C",c,Gecode::ICL_DOM);

     MaxXYZ max_xyz_b_a("A",a,Gecode::ICL_BND);
     MaxXYZ max_xyz_b_b("B",b,Gecode::ICL_BND);
     MaxXYZ max_xyz_b_c("C",c,Gecode::ICL_BND);
     MaxXYZ max_xyz_d_a("A",a,Gecode::ICL_DOM);
     MaxXYZ max_xyz_d_b("B",b,Gecode::ICL_DOM);
     MaxXYZ max_xyz_d_c("C",c,Gecode::ICL_DOM);

     MaxXXY max_xxy_b_a("A",a,Gecode::ICL_BND);
     MaxXXY max_xxy_b_b("B",b,Gecode::ICL_BND);
     MaxXXY max_xxy_b_c("C",c,Gecode::ICL_BND);
     MaxXXY max_xxy_d_a("A",a,Gecode::ICL_DOM);
     MaxXXY max_xxy_d_b("B",b,Gecode::ICL_DOM);
     MaxXXY max_xxy_d_c("C",c,Gecode::ICL_DOM);

     MaxXYX max_xyx_b_a("A",a,Gecode::ICL_BND);
     MaxXYX max_xyx_b_b("B",b,Gecode::ICL_BND);
     MaxXYX max_xyx_b_c("C",c,Gecode::ICL_BND);
     MaxXYX max_xyx_d_a("A",a,Gecode::ICL_DOM);
     MaxXYX max_xyx_d_b("B",b,Gecode::ICL_DOM);
     MaxXYX max_xyx_d_c("C",c,Gecode::ICL_DOM);

     MaxXYY max_xyy_b_a("A",a,Gecode::ICL_BND);
     MaxXYY max_xyy_b_b("B",b,Gecode::ICL_BND);
     MaxXYY max_xyy_b_c("C",c,Gecode::ICL_BND);
     MaxXYY max_xyy_d_a("A",a,Gecode::ICL_DOM);
     MaxXYY max_xyy_d_b("B",b,Gecode::ICL_DOM);
     MaxXYY max_xyy_d_c("C",c,Gecode::ICL_DOM);

     MaxXXX max_xxx_b_a("A",a,Gecode::ICL_BND);
     MaxXXX max_xxx_b_b("B",b,Gecode::ICL_BND);
     MaxXXX max_xxx_b_c("C",c,Gecode::ICL_BND);
     MaxXXX max_xxx_d_a("A",a,Gecode::ICL_DOM);
     MaxXXX max_xxx_d_b("B",b,Gecode::ICL_DOM);
     MaxXXX max_xxx_d_c("C",c,Gecode::ICL_DOM);

     MinNary       min_nary_b(Gecode::ICL_BND);
     MinNary       min_nary_d(Gecode::ICL_DOM);
     MinNaryShared min_s_nary_b(Gecode::ICL_BND);
     MinNaryShared min_s_nary_d(Gecode::ICL_DOM);
     MaxNary       max_nary_b(Gecode::ICL_BND);
     MaxNary       max_nary_d(Gecode::ICL_DOM);
     MaxNaryShared max_s_nary_b(Gecode::ICL_BND);
     MaxNaryShared max_s_nary_d(Gecode::ICL_DOM);
     //@}

   }
}}

// STATISTICS: test-int