this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Christian Schulte <schulte@gecode.org>
5 *
6 * Copyright:
7 * Christian Schulte, 2003
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
34namespace Gecode { namespace Int { namespace Distinct {
35
36
37 /*
38 * Ternary domain consistent distinct
39 *
40 */
41
42 template<class View>
43 forceinline
44 TerDom<View>::TerDom(Home home, View x0, View x1, View x2)
45 : TernaryPropagator<View,PC_INT_DOM>(home,x0,x1,x2) {}
46
47 template<class View>
48 ExecStatus
49 TerDom<View>::post(Home home, View x0, View x1, View x2) {
50 (void) new (home) TerDom<View>(home,x0,x1,x2);
51 return ES_OK;
52 }
53
54 template<class View>
55 forceinline
56 TerDom<View>::TerDom(Space& home, TerDom<View>& p)
57 : TernaryPropagator<View,PC_INT_DOM>(home,p) {}
58
59 template<class View>
60 Actor*
61 TerDom<View>::copy(Space& home) {
62 return new (home) TerDom<View>(home,*this);
63 }
64
65 /// Check whether x0 forms a Hall set of cardinality one
66#define GECODE_INT_HALL_ONE(x0,x1,x2) \
67 if (x0.assigned()) { \
68 GECODE_ME_CHECK(x1.nq(home,x0.val())); \
69 GECODE_ME_CHECK(x2.nq(home,x0.val())); \
70 if (x1.assigned()) { \
71 GECODE_ME_CHECK(x2.nq(home,x1.val())); \
72 return home.ES_SUBSUMED(*this); \
73 } \
74 if (x2.assigned()) { \
75 GECODE_ME_CHECK(x1.nq(home,x2.val())); \
76 return home.ES_SUBSUMED(*this); \
77 } \
78 return ES_FIX; \
79 }
80
81
82 /// Check whether x0 and x1 form a Hall set of cardinality two
83#define GECODE_INT_HALL_TWO(x0,x1,x2) \
84 if ((x0.size() == 2) && (x1.size() == 2) && \
85 (x0.min() == x1.min()) && (x0.max() == x1.max())) { \
86 GECODE_ME_CHECK(x2.nq(home,x0.min())); \
87 GECODE_ME_CHECK(x2.nq(home,x0.max())); \
88 return ES_FIX; \
89 }
90
91 template<class View>
92 ExecStatus
93 TerDom<View>::propagate(Space& home, const ModEventDelta&) {
94 GECODE_INT_HALL_ONE(x0,x1,x2);
95 GECODE_INT_HALL_ONE(x1,x0,x2);
96 GECODE_INT_HALL_ONE(x2,x0,x1);
97 GECODE_INT_HALL_TWO(x0,x1,x2);
98 GECODE_INT_HALL_TWO(x0,x2,x1);
99 GECODE_INT_HALL_TWO(x1,x2,x0);
100 return ES_FIX;
101 }
102
103#undef GECODE_INT_HALL_ONE
104#undef GECODE_INT_HALL_TWO
105
106}}}
107
108// STATISTICS: int-prop
109