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, 2015
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 <gecode/int/distinct.hh>
35
36#include <algorithm>
37
38namespace Gecode { namespace Int { namespace Distinct {
39
40 PropCost
41 EqIte::cost(const Space&, const ModEventDelta&) const {
42 return PropCost::binary(PropCost::HI);
43 }
44
45 Actor*
46 EqIte::copy(Space& home) {
47 return new (home) EqIte(home,*this);
48 }
49
50 ExecStatus
51 EqIte::propagate(Space& home, const ModEventDelta&) {
52 switch (rtest_eq_dom(x0,c0)) {
53 case RT_TRUE:
54 GECODE_ME_CHECK(x1.eq(home,c1));
55 return home.ES_SUBSUMED(*this);
56 case RT_FALSE:
57 GECODE_REWRITE(*this,(Rel::EqDom<IntView,IntView>
58 ::post(home(*this),x0,x1)));
59 GECODE_NEVER;
60 case RT_MAYBE:
61 break;
62 default: GECODE_NEVER;
63 }
64
65 GECODE_ME_CHECK(x1.lq(home,std::max(x0.max(),c1)));
66 GECODE_ME_CHECK(x1.gq(home,std::min(x0.min(),c1)));
67
68 RelTest eq_then = rtest_eq_dom(x1,c1);
69 RelTest eq_else = rtest_eq_dom(x1,x0);
70
71 if ((eq_then == RT_FALSE) && (eq_else == RT_FALSE))
72 return ES_FAILED;
73
74 if (eq_then == RT_FALSE) {
75 // x1 and c1 are not equal
76 GECODE_ME_CHECK(x0.nq(home,c0));
77 if (eq_else == RT_TRUE)
78 return home.ES_SUBSUMED(*this);
79 else
80 GECODE_REWRITE(*this,
81 (Rel::EqDom<IntView,IntView>::post(home(*this),x0,x1)));
82 }
83
84 if (eq_else == RT_FALSE) {
85 // x0 and x1 are not equal
86 GECODE_ME_CHECK(x0.eq(home,c0));
87 GECODE_ME_CHECK(x1.eq(home,c1));
88 return home.ES_SUBSUMED(*this);
89 }
90
91
92 assert((eq_then != RT_TRUE) || (eq_else != RT_TRUE));
93
94 ViewRanges<IntView> r0(x0);
95 Iter::Ranges::Singleton r1(c1,c1);
96 Iter::Ranges::Union<ViewRanges<IntView>,
97 Iter::Ranges::Singleton > u(r0,r1);
98
99 GECODE_ME_CHECK(x1.inter_r(home,u,true));
100
101 return ES_FIX;
102 }
103
104}}}
105
106// STATISTICS: int-prop