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 * Guido Tack <tack@gecode.org>
6 * Vincent Barichard <Vincent.Barichard@univ-angers.fr>
7 *
8 * Copyright:
9 * Christian Schulte, 2002
10 * Guido Tack, 2004
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
38#ifndef GECODE_FLOAT_ARITHMETIC_HH
39#define GECODE_FLOAT_ARITHMETIC_HH
40
41#include <gecode/int.hh>
42#include <gecode/float.hh>
43#include <gecode/float/rel.hh>
44
45/**
46 * \namespace Gecode::Float::Arithmetic
47 * \brief %Arithmetic propagators
48 */
49
50namespace Gecode { namespace Float { namespace Arithmetic {
51
52 /**
53 * \brief Bounds consistent positive square propagator
54 *
55 * This propagator provides multiplication for positive views only.
56 */
57 template<class VA, class VB>
58 class SqrPlus : public MixBinaryPropagator<VA,PC_FLOAT_BND,VB,PC_FLOAT_BND> {
59 protected:
60 using MixBinaryPropagator<VA,PC_FLOAT_BND,VB,PC_FLOAT_BND>::x0;
61 using MixBinaryPropagator<VA,PC_FLOAT_BND,VB,PC_FLOAT_BND>::x1;
62 /// Constructor for posting
63 SqrPlus(Home home, VA x0, VB x1);
64 /// Constructor for cloning \a p
65 SqrPlus(Space& home, SqrPlus<VA,VB>& p);
66 public:
67 /// Post propagator \f$x_0\cdot x_0=x_1\f$
68 static ExecStatus post(Home home, VA x0, VB x1);
69 /// Copy propagator during cloning
70 virtual Actor* copy(Space& home);
71 /// Perform propagation
72 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
73 };
74
75 /**
76 * \brief %Propagator for bounds consistent square operator
77 *
78 * Requires \code #include <gecode/float/arithmetic.hh> \endcode
79 * \ingroup FuncFloatProp
80 */
81 template<class View>
82 class Sqr : public BinaryPropagator<View,PC_FLOAT_BND> {
83 protected:
84 using BinaryPropagator<View,PC_FLOAT_BND>::x0;
85 using BinaryPropagator<View,PC_FLOAT_BND>::x1;
86
87 /// Constructor for cloning \a p
88 Sqr(Space& home, Sqr& p);
89 /// Constructor for creation
90 Sqr(Home home, View x0, View x1);
91 public:
92 /// Create copy during cloning
93 virtual Actor* copy(Space& home);
94 /// Perform propagation
95 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
96 /// Post propagator for \f$x_0^2 = x_1\f$
97 static ExecStatus post(Home home, View x0, View x1);
98 };
99
100 /**
101 * \brief %Propagator for bounds consistent square root operator
102 *
103 * The types \a A and \a B give the types of the views.
104 *
105 * Requires \code #include <gecode/float/arithmetic.hh> \endcode
106 * \ingroup FuncFloatProp
107 */
108 template<class A, class B>
109 class Sqrt : public MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND> {
110 protected:
111 using MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>::x0;
112 using MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>::x1;
113
114 /// Constructor for cloning \a p
115 Sqrt(Space& home, Sqrt& p);
116 /// Constructor for creation
117 Sqrt(Home home, A x0, B x1);
118 public:
119 /// Create copy during cloning
120 virtual Actor* copy(Space& home);
121 /// Perform propagation
122 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
123 /// Post propagator for \f$x_0^2 = x_1\f$
124 static ExecStatus post(Home home, A x0, B x1);
125 };
126
127 /**
128 * \brief %Propagator for bounds consistent absolute operator
129 *
130 * The types \a A and \a B give the types of the views.
131 *
132 * Requires \code #include <gecode/float/arithmetic.hh> \endcode
133 * \ingroup FuncFloatProp
134 */
135 template<class A, class B>
136 class Abs : public MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND> {
137 protected:
138 using MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>::x0;
139 using MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>::x1;
140
141 /// Constructor for cloning \a p
142 Abs(Space& home, Abs& p);
143 /// Constructor for creation
144 Abs(Home home, A x0, B x1);
145 public:
146 /// Constructor for rewriting \a p during cloning
147 Abs(Space& home, Propagator& p, A x0, B x1);
148 /// Create copy during cloning
149 virtual Actor* copy(Space& home);
150 /// Perform propagation
151 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
152 /// Post propagator for \f$ |x_0| = x_1\f$
153 static ExecStatus post(Home home, A x0, B x1);
154 };
155
156 /**
157 * \brief %Propagator for bounds consistent pow operator
158 *
159 * The types \a A and \a B give the types of the views.
160 *
161 * Requires \code #include <gecode/float/arithmetic.hh> \endcode
162 * \ingroup FuncFloatProp
163 */
164 template<class A, class B>
165 class Pow : public MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND> {
166 protected:
167 using MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>::x0;
168 using MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>::x1;
169 int m_n;
170
171 /// Constructor for cloning \a p
172 Pow(Space& home, Pow& p);
173 /// Constructor for creation
174 Pow(Home home, A x0, B x1, int n);
175 public:
176 /// Create copy during cloning
177 virtual Actor* copy(Space& home);
178 /// Perform propagation
179 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
180 /// Post propagator for \f$x_0^n = x_1\f$
181 static ExecStatus post(Home home, A x0, B x1, int n);
182 };
183
184 /**
185 * \brief %Propagator for bounds consistent nth root operator
186 *
187 * The types \a A and \a B give the types of the views.
188 *
189 * Requires \code #include <gecode/float/arithmetic.hh> \endcode
190 * \ingroup FuncFloatProp
191 */
192 template<class A, class B>
193 class NthRoot : public MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND> {
194 protected:
195 using MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>::x0;
196 using MixBinaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND>::x1;
197 int m_n;
198
199 /// Constructor for cloning \a p
200 NthRoot(Space& home, NthRoot& p);
201 /// Constructor for creation
202 NthRoot(Home home, A x0, B x1, int n);
203 public:
204 /// Create copy during cloning
205 virtual Actor* copy(Space& home);
206 /// Perform propagation
207 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
208 /// Post propagator for \f$x_0^(1/n) = x_1\f$
209 static ExecStatus post(Home home, A x0, B x1, int n);
210 };
211
212 /**
213 * \brief Bounds or domain consistent propagator for \f$x_0\times x_1=x_0\f$
214 *
215 * Requires \code #include <gecode/float/arithmetic.hh> \endcode
216 * \ingroup FuncFloatProp
217 */
218 template<class View>
219 class MultZeroOne : public BinaryPropagator<View,PC_FLOAT_BND> {
220 protected:
221 using BinaryPropagator<View,PC_FLOAT_BND>::x0;
222 using BinaryPropagator<View,PC_FLOAT_BND>::x1;
223
224 /// Constructor for cloning \a p
225 MultZeroOne(Space& home, MultZeroOne<View>& p);
226 /// Constructor for posting
227 MultZeroOne(Home home, View x0, View x1);
228 public:
229 /// Copy propagator during cloning
230 virtual Actor* copy(Space& home);
231 /// Perform propagation
232 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
233 /// Post propagator \f$x_0\cdot x_1=x_0\f$
234 static ExecStatus post(Home home, View x0, View x1);
235 };
236
237
238 /**
239 * \brief Bounds consistent positive multiplication propagator
240 *
241 * This propagator provides multiplication for positive views only.
242 */
243 template<class VA, class VB, class VC>
244 class MultPlus :
245 public MixTernaryPropagator<VA,PC_FLOAT_BND,VB,PC_FLOAT_BND,VC,PC_FLOAT_BND> {
246 protected:
247 using MixTernaryPropagator<VA,PC_FLOAT_BND,VB,PC_FLOAT_BND,VC,PC_FLOAT_BND>::x0;
248 using MixTernaryPropagator<VA,PC_FLOAT_BND,VB,PC_FLOAT_BND,VC,PC_FLOAT_BND>::x1;
249 using MixTernaryPropagator<VA,PC_FLOAT_BND,VB,PC_FLOAT_BND,VC,PC_FLOAT_BND>::x2;
250 public:
251 /// Constructor for posting
252 MultPlus(Home home, VA x0, VB x1, VC x2);
253 /// Constructor for cloning \a p
254 MultPlus(Space& home, MultPlus<VA,VB,VC>& p);
255 /// Post propagator \f$x_0\cdot x_1=x_2\f$
256 static ExecStatus post(Home home, VA x0, VB x1, VC x2);
257 /// Copy propagator during cloning
258 virtual Actor* copy(Space& home);
259 /// Perform propagation
260 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
261 };
262
263 /**
264 * \brief Bounds consistent multiplication propagator
265 *
266 * Requires \code #include <gecode/float/arithmetic.hh> \endcode
267 *
268 * \ingroup FuncFloatProp
269 */
270 template<class View>
271 class Mult : public TernaryPropagator<View,PC_FLOAT_BND> {
272 protected:
273 using TernaryPropagator<View,PC_FLOAT_BND>::x0;
274 using TernaryPropagator<View,PC_FLOAT_BND>::x1;
275 using TernaryPropagator<View,PC_FLOAT_BND>::x2;
276
277 /// Constructor for cloning \a p
278 Mult(Space& home, Mult<View>& p);
279 public:
280 /// Constructor for posting
281 Mult(Home home, View x0, View x1, View x2);
282 /// Post propagator \f$x_0\cdot x_1=x_2\f$
283 static ExecStatus post(Home home, View x0, View x1, View x2);
284 /// Copy propagator during cloning
285 virtual Actor* copy(Space& home);
286 /// Perform propagation
287 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
288 };
289
290
291 /**
292 * \brief %Propagator for bounds division operator
293 *
294 * The types \a A, \a B and \a C give the types of the views.
295 *
296 * Requires \code #include <gecode/float/arithmetic.hh> \endcode
297 * \ingroup FuncFloatProp
298 */
299 template<class A, class B, class C>
300 class Div : public MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND> {
301 protected:
302 using MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND>::x0;
303 using MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND>::x1;
304 using MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND>::x2;
305 /// Constructor for cloning \a p
306 Div(Space& home, Div& p);
307 /// Constructor for creation
308 Div(Home home, A x0, B x1, C x2);
309 public:
310 /// Create copy during cloning
311 virtual Actor* copy(Space& home);
312 /// Perform propagation
313 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
314 /// Post propagator for \f$ x_0 / x_1 = x_2\f$
315 static ExecStatus post(Home home, A x0, B x1, C x2);
316 };
317
318 /**
319 * \brief %Propagator for bounds consistent min operator
320 *
321 * The types \a A, \a B and \a C give the types of the views.
322 *
323 * Requires \code #include <gecode/float/arithmetic.hh> \endcode
324 * \ingroup FuncFloatProp
325 */
326 template<class A, class B, class C>
327 class Min : public MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND> {
328 protected:
329 using MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND>::x0;
330 using MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND>::x1;
331 using MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND>::x2;
332 /// Constructor for cloning \a p
333 Min(Space& home, Min& p);
334 /// Constructor for creation
335 Min(Home home, A x0, B x1, C x2);
336 public:
337 /// Constructor for rewriting \a p during cloning
338 Min(Space& home, Propagator& p, A x0, B x1, C x2);
339 /// Create copy during cloning
340 virtual Actor* copy(Space& home);
341 /// Perform propagation
342 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
343 /// Post propagator for \f$ min(x_0, x_1) = x_2\f$
344 static ExecStatus post(Home home, A x0, B x1, C x2);
345 };
346
347 /**
348 * \brief %Propagator for bounds consistent max operator
349 *
350 * The types \a A, \a B and \a C give the types of the views.
351 *
352 * Requires \code #include <gecode/float/arithmetic.hh> \endcode
353 * \ingroup FuncFloatProp
354 */
355 template<class A, class B, class C>
356 class Max : public MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND> {
357 protected:
358 using MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND>::x0;
359 using MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND>::x1;
360 using MixTernaryPropagator<A,PC_FLOAT_BND,B,PC_FLOAT_BND,C,PC_FLOAT_BND>::x2;
361 /// Constructor for cloning \a p
362 Max(Space& home, Max& p);
363 /// Constructor for creation
364 Max(Home home, A x0, B x1, C x2);
365 public:
366 /// Constructor for rewriting \a p during cloning
367 Max(Space& home, Propagator& p, A x0, B x1, C x2);
368 /// Create copy during cloning
369 virtual Actor* copy(Space& home);
370 /// Perform propagation
371 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
372 /// Post propagator for \f$ max(x_0, x_1) = x_2\f$
373 static ExecStatus post(Home home, A x0, B x1, C x2);
374 };
375
376 /**
377 * \brief Bounds consistent n-ary maximum propagator
378 *
379 * Requires \code #include <gecode/float/arithmetic.hh> \endcode
380 * \ingroup FuncFloatProp
381 */
382 template<class View>
383 class NaryMax : public NaryOnePropagator<View,PC_FLOAT_BND> {
384 protected:
385 using NaryOnePropagator<View,PC_FLOAT_BND>::x;
386 using NaryOnePropagator<View,PC_FLOAT_BND>::y;
387
388 /// Constructor for cloning \a p
389 NaryMax(Space& home, NaryMax& p);
390 /// Constructor for posting
391 NaryMax(Home home, ViewArray<View>& x, View y);
392 public:
393 /// Copy propagator during cloning
394 virtual Actor* copy(Space& home);
395 /// Perform propagation
396 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
397 /// Post propagator \f$ \max x=y\f$
398 static ExecStatus post(Home home, ViewArray<View>& x, View y);
399 };
400
401}}}
402
403#include <gecode/float/arithmetic/sqr-sqrt.hpp>
404#include <gecode/float/arithmetic/abs.hpp>
405#include <gecode/float/arithmetic/pow-nroot.hpp>
406#include <gecode/float/arithmetic/mult.hpp>
407#include <gecode/float/arithmetic/div.hpp>
408#include <gecode/float/arithmetic/min-max.hpp>
409
410#endif
411
412// STATISTICS: float-prop