Generated on for Gecode by doxygen 1.17.0
mult.hpp
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Christian Schulte <schulte@gecode.dev>
5 * Vincent Barichard <Vincent.Barichard@univ-angers.fr>
6 *
7 * Copyright:
8 * Christian Schulte, 2004
9 * Vincent Barichard, 2012
10 *
11 * This file is part of Gecode, the generic constraint
12 * development environment:
13 * http://www.gecode.dev
14 *
15 * Permission is hereby granted, free of charge, to any person obtaining
16 * a copy of this software and associated documentation files (the
17 * "Software"), to deal in the Software without restriction, including
18 * without limitation the rights to use, copy, modify, merge, publish,
19 * distribute, sublicense, and/or sell copies of the Software, and to
20 * permit persons to whom the Software is furnished to do so, subject to
21 * the following conditions:
22 *
23 * The above copyright notice and this permission notice shall be
24 * included in all copies or substantial portions of the Software.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 *
34 */
35
36namespace Gecode { namespace Float { namespace Arithmetic {
37
39 template<class View>
40 forceinline bool
41 pos(const View& x) {
42 return x.min() >= 0.0;
43 }
44
45 template<class View>
46 forceinline bool
47 neg(const View& x) {
48 return x.max() <= 0.0;
49 }
50
51 template<class View>
52 forceinline bool
53 any(const View& x) {
54 return (x.min() <= 0.0) && (x.max() >= 0.0);
55 }
56
57 /*
58 * Propagator for x * y = x
59 *
60 */
61
62 template<class View>
63 forceinline
66
67 template<class View>
68 forceinline ExecStatus
70 switch (rtest_eq(x0,0.0)) {
71 case RT_FALSE:
72 GECODE_ME_CHECK(x1.eq(home,1.0));
73 break;
74 case RT_TRUE:
75 break;
76 case RT_MAYBE:
77 switch (rtest_eq(x1,1.0)) {
78 case RT_FALSE:
79 GECODE_ME_CHECK(x0.eq(home,0.0));
80 break;
81 case RT_TRUE:
82 break;
83 case RT_MAYBE:
84 (void) new (home) MultZeroOne<View>(home,x0,x1);
85 break;
86 default: GECODE_NEVER;
87 }
88 break;
89 default: GECODE_NEVER;
90 }
91 return ES_OK;
92 }
93
94 template<class View>
95 forceinline
98
99 template<class View>
100 Actor*
102 return new (home) MultZeroOne<View>(home,*this);
103 }
104
105 template<class View>
108 switch (rtest_eq(x0,0.0)) {
109 case RT_FALSE:
110 GECODE_ME_CHECK(x1.eq(home,1.0));
111 break;
112 case RT_TRUE:
113 break;
114 case RT_MAYBE:
115 switch (rtest_eq(x1,1.0)) {
116 case RT_FALSE:
117 GECODE_ME_CHECK(x0.eq(home,0.0));
118 break;
119 case RT_TRUE:
120 break;
121 case RT_MAYBE:
122 return ES_FIX;
123 default: GECODE_NEVER;
124 }
125 break;
126 default: GECODE_NEVER;
127 }
128 return home.ES_SUBSUMED(*this);
129 }
130
131
132 /*
133 * Positive bounds consistent multiplication
134 *
135 */
136 template<class VA, class VB, class VC>
137 forceinline
141
142 template<class VA, class VB, class VC>
143 forceinline
147
148 template<class VA, class VB, class VC>
149 Actor*
151 return new (home) MultPlus<VA,VB,VC>(home,*this);
152 }
153
154 template<class VA, class VB, class VC>
157 if (x1.min() != 0.0)
158 GECODE_ME_CHECK(x0.eq(home,x2.val() / x1.val()));
159 if (x0.min() != 0.0)
160 GECODE_ME_CHECK(x1.eq(home,x2.val() / x0.val()));
161 GECODE_ME_CHECK(x2.eq(home,x0.val() * x1.val()));
162 if (x0.assigned() && x1.assigned() && x2.assigned())
163 return home.ES_SUBSUMED(*this);
164 return ES_NOFIX;
165 }
166
167 template<class VA, class VB, class VC>
168 forceinline ExecStatus
170 GECODE_ME_CHECK(x0.gq(home,0.0));
171 GECODE_ME_CHECK(x1.gq(home,0.0));
172 Rounding r;
173 GECODE_ME_CHECK(x2.gq(home,r.mul_down(x0.min(),x1.min())));
174 (void) new (home) MultPlus<VA,VB,VC>(home,x0,x1,x2);
175 return ES_OK;
176 }
177
178
179 /*
180 * Bounds consistent multiplication
181 *
182 */
183 template<class View>
184 forceinline
187
188 template<class View>
189 forceinline
192
193 template<class View>
194 Actor*
196 return new (home) Mult<View>(home,*this);
197 }
198
200 template<class View>
201 forceinline ModEvent
202 div_zero_endpoint(Home home, View x, const FloatVal& n, const View& d) {
203 if ((d.min() == 0.0) && (d.max() > 0.0)) {
204 const FloatVal q = n / FloatVal(d.max());
205 if (n.min() > 0.0)
206 return x.gq(home,q.min());
207 if (n.max() < 0.0)
208 return x.lq(home,q.max());
209 } else if ((d.max() == 0.0) && (d.min() < 0.0)) {
210 const FloatVal q = n / FloatVal(d.min());
211 if (n.min() > 0.0)
212 return x.lq(home,q.max());
213 if (n.max() < 0.0)
214 return x.gq(home,q.min());
215 }
216 return ME_FLOAT_NONE;
217 }
218
219 template<class View>
222 GECODE_ME_CHECK(x2.eq(home,x0.val()*x1.val()));
223 if (!x1.zero_in())
224 GECODE_ME_CHECK(x0.eq(home,x2.val() / x1.val()));
225 else
227 if (!x0.zero_in())
228 GECODE_ME_CHECK(x1.eq(home,x2.val() / x0.val()));
229 else
231 GECODE_ME_CHECK(x2.eq(home,x0.val()*x1.val()));
232 if (x0.assigned() && x1.assigned() && x2.assigned())
233 return home.ES_SUBSUMED(*this);
234 return ES_NOFIX;
235 }
236
237 template<class View>
240 if (x0 == x1)
241 return Sqr<View>::post(home,x0,x2);
242 if (x0 == x2)
243 return MultZeroOne<View>::post(home,x0,x1);
244 if (x1 == x2)
245 return MultZeroOne<View>::post(home,x1,x0);
246 GECODE_ME_CHECK(x2.eq(home,x0.val()*x1.val()));
247 if (!x1.zero_in())
248 GECODE_ME_CHECK(x0.eq(home,x2.val() / x1.val()));
249 else
251 if (!x0.zero_in())
252 GECODE_ME_CHECK(x1.eq(home,x2.val() / x0.val()));
253 else
255 GECODE_ME_CHECK(x2.eq(home,x0.val()*x1.val()));
256 if (x0.assigned() && x1.assigned() && x2.assigned())
257 return ES_OK;
258
259 (void) new (home) Mult<View>(home,x0,x1,x2);
260 return ES_OK;
261 }
262
263
264}}}
265
266// STATISTICS: float-prop
Base-class for both propagators and branchers.
Definition core.hpp:635
BinaryPropagator(Space &home, BinaryPropagator &p)
Float value type.
Definition float.hh:334
friend FloatVal max(const FloatVal &x, const FloatVal &y)
Definition val.hpp:403
friend FloatVal min(const FloatVal &x, const FloatVal &y)
Definition val.hpp:415
static ExecStatus post(Home home, VA x0, VB x1, VC x2)
Post propagator .
Definition mult.hpp:169
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition mult.hpp:150
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition mult.hpp:156
MultPlus(Home home, VA x0, VB x1, VC x2)
Constructor for posting.
Definition mult.hpp:138
static ExecStatus post(Home home, View x0, View x1)
Post propagator .
Definition mult.hpp:69
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition mult.hpp:107
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition mult.hpp:101
MultZeroOne(Space &home, MultZeroOne< View > &p)
Constructor for cloning p.
Definition mult.hpp:96
static ExecStatus post(Home home, View x0, View x1, View x2)
Post propagator .
Definition mult.hpp:239
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition mult.hpp:195
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition mult.hpp:221
Mult(Space &home, Mult< View > &p)
Constructor for cloning p.
Definition mult.hpp:190
static ExecStatus post(Home home, View x0, View x1)
Post propagator for .
Definition sqr-sqrt.hpp:105
Floating point rounding policy.
Definition float.hh:154
FloatNum mul_down(FloatNum x, FloatNum y)
Return lower bound of x times y (domain: ).
Home class for posting propagators
Definition core.hpp:863
friend class Space
Definition core.hpp:1075
TernaryPropagator(Space &home, TernaryPropagator &p)
ExecStatus ES_SUBSUMED(Propagator &p)
Propagator p is subsumed
Definition core.hpp:3672
int ModEventDelta
Modification event deltas.
Definition core.hpp:94
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition macros.hpp:52
Arithmetic propagators
bool any(const View &x)
Test whether x is neither positive nor negative.
Definition mult.hpp:53
bool pos(const View &x)
Test whether x is positive.
Definition mult.hpp:41
bool neg(const View &x)
Test whether x is negative.
Definition mult.hpp:47
ModEvent div_zero_endpoint(Home home, View x, const FloatVal &n, const View &d)
Contract a quotient when the denominator has zero as one endpoint.
Definition mult.hpp:202
Floating point numbers.
@ RT_TRUE
Relation does hold.
Definition view.hpp:536
@ RT_FALSE
Relation does not hold.
Definition view.hpp:534
@ RT_MAYBE
Relation may hold or not.
Definition view.hpp:535
RelTest rtest_eq(View x, View y)
Test whether views x and y are equal.
Definition rel-test.hpp:40
const Gecode::ModEvent ME_FLOAT_NONE
Domain operation has not changed domain.
Definition var-type.hpp:270
const Gecode::PropCond PC_FLOAT_BND
Propagate when minimum or maximum of a view changes.
Definition var-type.hpp:300
Gecode toplevel namespace
ExecStatus
Definition core.hpp:479
@ ES_OK
Execution is okay.
Definition core.hpp:483
@ ES_FIX
Propagation has computed fixpoint.
Definition core.hpp:484
@ ES_NOFIX
Propagation has not computed fixpoint.
Definition core.hpp:482
int ModEvent
Type for modification events.
Definition core.hpp:67
#define GECODE_NEVER
Assert that this command is never executed.
Definition macros.hpp:56