Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
distinct.cpp
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Guido Tack <tack@gecode.org>
5 *
6 * 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
41 namespace Distinct {
42
48
49 static IntSet ds_33(-2,2);
50 static IntSet ds_44(-4,4);
51
53 class AtmostOne : public SetTest {
54 public:
56 AtmostOne(const char* t)
57 : SetTest(t,3,ds_33,false) {}
59 virtual bool solution(const SetAssignment& x) const {
60 {
61 CountableSetRanges xr0(x.lub, x[0]);
62 CountableSetRanges xr1(x.lub, x[1]);
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]);
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]);
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 }
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
109
110}}}
111
112// STATISTICS: test-set
NodeType t
Type of node.
Node * x
Pointer to corresponding Boolean expression node.
Integer sets.
Definition int.hh:174
static const IntSet empty
Empty set.
Definition int.hh:283
Integer variable array.
Definition int.hh:763
Range iterator for computing intersection (binary)
Set variable array
Definition set.hh:570
Set variables
Definition set.hh:127
Propagator for negated equality
Definition rel.hh:268
Computation spaces.
Definition core.hpp:1742
Range iterator producing subsets of an IntSet.
Definition set.hh:99
Test for the atmostone propagator
Definition distinct.cpp:53
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition distinct.cpp:59
AtmostOne(const char *t)
Create and register test.
Definition distinct.cpp:56
virtual void post(Space &home, SetVarArray &x, IntVarArray &)
Post constraint on x.
Definition distinct.cpp:96
Generate all set assignments.
Definition set.hh:142
Base class for tests with set constraints
Definition set.hh:273
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVar x1)
Post propagator for .
Definition rel.cpp:68
@ SOT_INTER
Intersection
Definition set.hh:663
@ SRT_EQ
Equality ( )
Definition set.hh:644
unsigned int size(I &i)
Size of all ranges of range iterator i.
Gecode toplevel namespace
void atmostOne(Home home, const SetVarArgs &xa, unsigned int c)
Definition distinct.cpp:41
AtmostOne _atmostone("Distinct::AtmostOne")
General test support.
Definition afc.cpp:39