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, 2016
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/float/rel.hh>
35
36namespace Gecode { namespace Float { namespace Bool {
37
38 template<class View>
39 forceinline
40 Ite<View>::Ite(Home home, Int::BoolView b0, View y0, View y1, View y2)
41 : Propagator(home), b(b0), x0(y0), x1(y1), x2(y2) {
42 b.subscribe(home,*this,Int::PC_BOOL_VAL);
43 x0.subscribe(home,*this,PC_FLOAT_BND);
44 x1.subscribe(home,*this,PC_FLOAT_BND);
45 x2.subscribe(home,*this,PC_FLOAT_BND);
46 }
47
48 template<class View>
49 forceinline
50 Ite<View>::Ite(Space& home, Ite<View>& p)
51 : Propagator(home,p) {
52 b.update(home,p.b);
53 x0.update(home,p.x0);
54 x1.update(home,p.x1);
55 x2.update(home,p.x2);
56 }
57
58 template<class View>
59 PropCost
60 Ite<View>::cost(const Space&, const ModEventDelta&) const {
61 return PropCost::ternary(PropCost::LO);
62 }
63
64 template<class View>
65 void
66 Ite<View>::reschedule(Space& home) {
67 b.reschedule(home,*this,Int::PC_BOOL_VAL);
68 x0.reschedule(home,*this,PC_FLOAT_BND);
69 x1.reschedule(home,*this,PC_FLOAT_BND);
70 x2.reschedule(home,*this,PC_FLOAT_BND);
71 }
72
73 template<class View>
74 forceinline size_t
75 Ite<View>::dispose(Space& home) {
76 b.cancel(home,*this,Int::PC_BOOL_VAL);
77 x0.cancel(home,*this,PC_FLOAT_BND);
78 x1.cancel(home,*this,PC_FLOAT_BND);
79 x2.cancel(home,*this,PC_FLOAT_BND);
80 (void) Propagator::dispose(home);
81 return sizeof(*this);
82 }
83
84
85
86 template<class View>
87 Actor*
88 Ite<View>::copy(Space& home) {
89 return new (home) Ite<View>(home,*this);
90 }
91
92 template<class View>
93 inline ExecStatus
94 Ite<View>::post(Home home, Int::BoolView b, View x0, View x1, View x2) {
95 if (b.one())
96 return Rel::Eq<View,View>::post(home,x2,x0);
97 if (b.zero())
98 return Rel::Eq<View,View>::post(home,x2,x1);
99 GECODE_ME_CHECK(x2.lq(home,std::max(x0.max(),x1.max())));
100 GECODE_ME_CHECK(x2.gq(home,std::min(x0.min(),x1.min())));
101 (void) new (home) Ite<View>(home,b,x0,x1,x2);
102 return ES_OK;
103 }
104
105 template<class View>
106 ExecStatus
107 Ite<View>::propagate(Space& home, const ModEventDelta&) {
108 if (b.one())
109 GECODE_REWRITE(*this,(Rel::Eq<View,View>::post(home(*this),x2,x0)));
110 if (b.zero())
111 GECODE_REWRITE(*this,(Rel::Eq<View,View>::post(home(*this),x2,x1)));
112
113 GECODE_ME_CHECK(x2.lq(home,std::max(x0.max(),x1.max())));
114 GECODE_ME_CHECK(x2.gq(home,std::min(x0.min(),x1.min())));
115
116 RelTest eq20 = rtest_eq(x2,x0);
117 RelTest eq21 = rtest_eq(x2,x1);
118
119 if ((eq20 == RT_FALSE) && (eq21 == RT_FALSE))
120 return ES_FAILED;
121
122 if (eq20 == RT_FALSE) {
123 GECODE_ME_CHECK(b.zero_none(home));
124 if (eq21 == RT_TRUE)
125 return home.ES_SUBSUMED(*this);
126 else
127 GECODE_REWRITE(*this,(Rel::Eq<View,View>::post(home(*this),x2,x1)));
128 }
129
130 if (eq21 == RT_FALSE) {
131 GECODE_ME_CHECK(b.one_none(home));
132 if (eq20 == RT_TRUE)
133 return home.ES_SUBSUMED(*this);
134 else
135 GECODE_REWRITE(*this,(Rel::Eq<View,View>::post(home(*this),x2,x0)));
136 }
137
138 if ((eq20 == RT_TRUE) && (eq21 == RT_TRUE))
139 return home.ES_SUBSUMED(*this);
140
141 return ES_FIX;
142 }
143
144}}}
145
146// STATISTICS: float-prop