this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Guido Tack <tack@gecode.org>
5 *
6 * Copyright:
7 * Guido Tack, 2005
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.org
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 *
32 */
33
34#include "test/set.hh"
35
36using namespace Gecode;
37
38namespace Test { namespace Set {
39
40 /// %Tests for distinctness constraints
41 namespace Distinct {
42
43 /**
44 * \defgroup TaskTestSetDistinct Distinctness constraints
45 * \ingroup TaskTestSet
46 */
47 //@{
48
49 static IntSet ds_33(-2,2);
50 static IntSet ds_44(-4,4);
51
52 /// %Test for the atmostone propagator
53 class AtmostOne : public SetTest {
54 public:
55 /// Create and register test
56 AtmostOne(const char* t)
57 : SetTest(t,3,ds_33,false) {}
58 /// %Test whether \a x is solution
59 virtual bool solution(const SetAssignment& x) const {
60 {
61 CountableSetRanges xr0(x.lub, x[0]);
62 CountableSetRanges xr1(x.lub, x[1]);
63 Iter::Ranges::Inter<CountableSetRanges,CountableSetRanges>
64 i(xr0,xr1);
65 if (Iter::Ranges::size(i)>1)
66 return false;
67 }
68 {
69 CountableSetRanges xr0(x.lub, x[0]);
70 CountableSetRanges xr2(x.lub, x[2]);
71 Iter::Ranges::Inter<CountableSetRanges,CountableSetRanges>
72 i(xr0,xr2);
73 if (Iter::Ranges::size(i)>1)
74 return false;
75 }
76 {
77 CountableSetRanges xr1(x.lub, x[1]);
78 CountableSetRanges xr2(x.lub, x[2]);
79 Iter::Ranges::Inter<CountableSetRanges,CountableSetRanges>
80 i(xr1,xr2);
81 if (Iter::Ranges::size(i)>1)
82 return false;
83 }
84 {
85 CountableSetRanges xr0(x.lub, x[0]);
86 CountableSetRanges xr1(x.lub, x[1]);
87 CountableSetRanges xr2(x.lub, x[2]);
88 if (Iter::Ranges::size(xr0)!=3 ||
89 Iter::Ranges::size(xr1)!=3 ||
90 Iter::Ranges::size(xr2)!=3)
91 return false;
92 }
93 return true;
94 }
95 /// Post constraint on \a x
96 virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
97 SetVar s1(home, IntSet::empty, -2, 2, 0U, 1U);
98 Gecode::rel(home, x[0], SOT_INTER, x[1], SRT_EQ, s1);
99 SetVar s2(home, IntSet::empty, -2, 2, 0U, 1U);
100 Gecode::rel(home, x[0], SOT_INTER, x[2], SRT_EQ, s2);
101 SetVar s3(home, IntSet::empty, -2, 2, 0U, 1U);
102 Gecode::rel(home, x[1], SOT_INTER, x[2], SRT_EQ, s3);
103 Gecode::atmostOne(home, x, 3);
104 }
105 };
106 AtmostOne _atmostone("Distinct::AtmostOne");
107
108 //@}
109
110}}}
111
112// STATISTICS: test-set