Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
sqr-sqrt.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.org>
5 * Guido Tack <tack@gecode.org>
6 * Vincent Barichard <Vincent.Barichard@univ-angers.fr>
7 *
8 * Copyright:
9 * Christian Schulte, 2004
10 * Guido Tack, 2006
11 * Vincent Barichard, 2012
12 *
13 * This file is part of Gecode, the generic constraint
14 * development environment:
15 * http://www.gecode.org
16 *
17 * Permission is hereby granted, free of charge, to any person obtaining
18 * a copy of this software and associated documentation files (the
19 * "Software"), to deal in the Software without restriction, including
20 * without limitation the rights to use, copy, modify, merge, publish,
21 * distribute, sublicense, and/or sell copies of the Software, and to
22 * permit persons to whom the Software is furnished to do so, subject to
23 * the following conditions:
24 *
25 * The above copyright notice and this permission notice shall be
26 * included in all copies or substantial portions of the Software.
27 *
28 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 *
36 */
37
38namespace Gecode { namespace Float { namespace Arithmetic {
39
40 /*
41 * Positive bounds consistent squaring
42 *
43 */
44 template<class VA, class VB>
48
49 template<class VA, class VB>
52 if (x0 == x1) {
53 if (x0.assigned())
54 return ((x0.val() == 0) || (x0.val() == 1))? ES_OK : ES_FAILED;
55 } else {
56 GECODE_ME_CHECK(x0.eq(home,sqrt(x1.val())));
57 GECODE_ME_CHECK(x1.eq(home,sqr(x0.val())));
58 }
59
60 (void) new (home) SqrPlus<VA,VB>(home,x0,x1);
61 return ES_OK;
62 }
63
64 template<class VA, class VB>
68
69 template<class VA, class VB>
70 Actor*
72 return new (home) SqrPlus<VA,VB>(home,*this);
73 }
74
75 template<class VA, class VB>
78 if (x0 == x1) {
79 if (x0.max() < 1) GECODE_ME_CHECK(x0.eq(home,0));
80 else if (x0.min() > 0) GECODE_ME_CHECK(x0.eq(home,1));
81 if (x0.assigned())
82 return ((x0.val() == 0) || (x0.val() == 1))? home.ES_SUBSUMED(*this) : ES_FAILED;
83 } else {
84 GECODE_ME_CHECK(x0.eq(home,sqrt(x1.val())));
85 GECODE_ME_CHECK(x1.eq(home,sqr(x0.val())));
86 if (x0.assigned() || x1.assigned()) return home.ES_SUBSUMED(*this);
87 }
88
89 return ES_FIX;
90 }
91
92
93 /*
94 * Bounds consistent squaring
95 *
96 */
97
98 template<class View>
102
103 template<class View>
106 GECODE_ME_CHECK(x1.gq(home,0));
107 if (x0 == x1) {
108 if (x0.assigned())
109 return ((x0.val() == 0) || (x0.val() == 1))? ES_OK : ES_FAILED;
110 GECODE_ME_CHECK(x1.lq(home,1));
112 } else {
113 if (x0.min() >= 0)
115 if (x0.max() <= 0)
117 GECODE_ME_CHECK(x1.eq(home,sqr(x0.val())));
118 (void) new (home) Sqr<View>(home,x0,x1);
119 }
120 return ES_OK;
121 }
122
123 template<class View>
127
128 template<class View>
129 Actor*
131 return new (home) Sqr<View>(home,*this);
132 }
133
134 template<class View>
137 assert(x1.min() >= 0);
138 if (x0.min() >= 0)
140 if (x0.max() <= 0)
142 MinusView(x0),x1)));
143
144 GECODE_ME_CHECK(x1.eq(home,sqr(x0.val())));
145 Rounding r;
146 FloatVal z = sqrt(x1.val());
147 if (x0.min() > -r.sqrt_up(x1.min()))
148 GECODE_ME_CHECK(x0.eq(home,z));
149 else if (x0.max() < r.sqrt_down(x1.min()))
150 GECODE_ME_CHECK(x0.eq(home,-z));
151 else
152 GECODE_ME_CHECK(x0.eq(home,hull(z,-z)));
153
154 return ES_NOFIX;
155 }
156
157
158 /*
159 * Bounds consistent square root operator
160 *
161 */
162
163 template<class A, class B>
167
168 template<class A, class B>
170 Sqrt<A,B>::post(Home home, A x0, B x1) {
171 GECODE_ME_CHECK(x0.gq(home,0));
172 if (x0 == x1) {
173 if (x0.assigned())
174 return ((x0.val() == 0) || (x0.val() == 1))? ES_OK : ES_FAILED;
175 GECODE_ME_CHECK(x0.lq(home,1));
176 (void) new (home) Sqrt<A,B>(home,x0,x1);
177 } else {
178 GECODE_ME_CHECK(x1.eq(home,sqrt(x0.val())));
179 (void) new (home) Sqrt<A,B>(home,x0,x1);
180 }
181 return ES_OK;
182 }
183
184 template<class A, class B>
188
189 template<class A, class B>
190 Actor*
192 return new (home) Sqrt<A,B>(home,*this);
193 }
194
195 template<class A, class B>
198 if (x0 == x1) {
199 if (x0.max() < 1) GECODE_ME_CHECK(x0.eq(home,0));
200 else if (x0.min() > 0) GECODE_ME_CHECK(x0.eq(home,1));
201 if (x0.assigned())
202 return ((x0.val() == 0) || (x0.val() == 1))? home.ES_SUBSUMED(*this) : ES_FAILED;
203 } else {
204 GECODE_ME_CHECK(x0.eq(home,sqr(x1.val())));
205 GECODE_ME_CHECK(x1.eq(home,sqrt(x0.val())));
206 if (x0.assigned() || x1.assigned()) return home.ES_SUBSUMED(*this);
207 }
208
209 return ES_FIX;
210 }
211
212}}}
213
214// STATISTICS: float-prop
215
Base-class for both propagators and branchers.
Definition core.hpp:628
Binary propagator.
Definition pattern.hpp:84
BinaryPropagator(Space &home, BinaryPropagator &p)
Float value type.
Definition float.hh:334
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition sqr-sqrt.hpp:77
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition sqr-sqrt.hpp:71
SqrPlus(Home home, VA x0, VB x1)
Constructor for posting.
Definition sqr-sqrt.hpp:46
static ExecStatus post(Home home, VA x0, VB x1)
Post propagator .
Definition sqr-sqrt.hpp:51
Propagator for bounds consistent square operator
Definition arithmetic.hh:82
virtual Actor * copy(Space &home)
Create copy during cloning.
Definition sqr-sqrt.hpp:130
static ExecStatus post(Home home, View x0, View x1)
Post propagator for .
Definition sqr-sqrt.hpp:105
Sqr(Space &home, Sqr &p)
Constructor for cloning p.
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition sqr-sqrt.hpp:136
Sqrt(Space &home, Sqrt &p)
Constructor for cloning p.
Definition sqr-sqrt.hpp:186
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition sqr-sqrt.hpp:197
static ExecStatus post(Home home, A x0, B x1)
Post propagator for .
Definition sqr-sqrt.hpp:170
virtual Actor * copy(Space &home)
Create copy during cloning.
Definition sqr-sqrt.hpp:191
Minus float view.
Definition view.hpp:154
Floating point rounding policy.
Definition float.hh:154
Home class for posting propagators
Definition core.hpp:856
friend class Space
Definition core.hpp:1068
Computation spaces.
Definition core.hpp:1744
ExecStatus ES_SUBSUMED(Propagator &p)
Propagator p is subsumed
Definition core.hpp:3570
int ModEventDelta
Modification event deltas.
Definition core.hpp:89
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition macros.hpp:52
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition macros.hpp:116
Arithmetic propagators
Floating point numbers.
FloatVal hull(const FloatVal &x, const FloatVal &y)
Definition val.hpp:507
const Gecode::PropCond PC_FLOAT_BND
Propagate when minimum or maximum of a view changes.
Definition var-type.hpp:292
Gecode toplevel namespace
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition set.hh:773
void sqr(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Post propagator for SetVar SetOpType SetVar SetRelType SetVar z
Definition set.hh:773
void sqrt(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
ExecStatus
Definition core.hpp:472
@ ES_OK
Execution is okay.
Definition core.hpp:476
@ ES_FIX
Propagation has computed fixpoint.
Definition core.hpp:477
@ ES_FAILED
Execution has resulted in failure.
Definition core.hpp:474
@ ES_NOFIX
Propagation has not computed fixpoint.
Definition core.hpp:475
#define forceinline
Definition config.hpp:194