Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
arithmetic.cpp
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 * Vincent Barichard <Vincent.Barichard@univ-angers.fr>
6 *
7 * Copyright:
8 * Christian Schulte, 2002
9 * Vincent Barichard, 2012
10 *
11 * This file is part of Gecode, the generic constraint
12 * development environment:
13 * http://www.gecode.org
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
37
38namespace Gecode {
39
40 void
41 abs(Home home, FloatVar x0, FloatVar x1) {
42 using namespace Float;
44 GECODE_ES_FAIL((Arithmetic::Abs<FloatView,FloatView>::post(home,x0,x1)));
45 }
46
47
48 void
49 max(Home home, FloatVar x0, FloatVar x1, FloatVar x2) {
50 using namespace Float;
52 GECODE_ES_FAIL((Arithmetic::Max<FloatView,FloatView,FloatView>::post(home,x0,x1,x2)));
53 }
54
55 void
56 max(Home home, const FloatVarArgs& x, FloatVar y) {
57 using namespace Float;
58 if (x.size() == 0)
59 throw TooFewArguments("Float::max");
61 ViewArray<FloatView> xv(home,x);
62 GECODE_ES_FAIL(Arithmetic::NaryMax<FloatView>::post(home,xv,y));
63 }
64
65
66 void
67 min(Home home, FloatVar x0, FloatVar x1, FloatVar x2) {
68 using namespace Float;
70 GECODE_ES_FAIL((Arithmetic::Min<FloatView,FloatView,FloatView>::post(home,x0,x1,x2)));
71 }
72
73 void
74 min(Home home, const FloatVarArgs& x, FloatVar y) {
75 using namespace Float;
76 if (x.size() == 0)
77 throw TooFewArguments("Float::min");
79 ViewArray<MinusView> m(home,x.size());
80 for (int i=x.size(); i--; )
81 m[i] = MinusView(x[i]);
82 MinusView my(y);
83 GECODE_ES_FAIL(Arithmetic::NaryMax<MinusView>::post(home,m,my));
84 }
85
86
87 void
88 mult(Home home, FloatVar x0, FloatVar x1, FloatVar x2) {
89 using namespace Float;
91 GECODE_ES_FAIL((Arithmetic::Mult<FloatView>::post(home,x0,x1,x2)));
92 }
93
94 void
95 sqr(Home home, FloatVar x0, FloatVar x1) {
96 using namespace Float;
98 GECODE_ES_FAIL((Arithmetic::Sqr<FloatView>::post(home,x0,x1)));
99 }
100
101 void
102 sqrt(Home home, FloatVar x0, FloatVar x1) {
103 using namespace Float;
105 GECODE_ES_FAIL((Arithmetic::Sqrt<FloatView,FloatView>::post(home,x0,x1)));
106 }
107
108 void
109 pow(Home home, FloatVar x0, int n, FloatVar x1) {
110 using namespace Float;
111 if (n < 0)
112 throw OutOfLimits("pow");
114 GECODE_ES_FAIL((Arithmetic::Pow<FloatView,FloatView>::post(home,x0,x1,n)));
115 }
116
117 void
118 nroot(Home home, FloatVar x0, int n, FloatVar x1) {
119 using namespace Float;
120 if (n < 0)
121 throw OutOfLimits("nroot");
123 GECODE_ES_FAIL((Arithmetic::NthRoot<FloatView,FloatView>::post(home,x0,x1,n)));
124 }
125
126 void
127 div(Home home, FloatVar x0, FloatVar x1, FloatVar x2) {
128 using namespace Float;
131 (Arithmetic::Div<FloatView,FloatView,FloatView>::post(home,x0,x1,x2)));
132 }
133
134}
135
136// STATISTICS: float-post
Passing float variables.
Definition float.hh:982
Float variables.
Definition float.hh:870
Home class for posting propagators
Definition core.hpp:856
Minus integer view.
Definition view.hpp:282
Exception: Value out of limits
Definition exception.hpp:44
Exception: Too few arguments available in argument array
Definition exception.hpp:66
View arrays.
Definition array.hpp:253
#define GECODE_POST
Check for failure in a constraint post function.
Definition macros.hpp:40
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition macros.hpp:103
Floating point numbers.
Gecode toplevel namespace
void sqr(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
void abs(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
void div(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
void mult(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
void sqrt(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Post propagator for SetVar SetOpType SetVar y
Definition set.hh:773
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
void pow(Home home, FloatVar x0, int n, FloatVar x1)
Post propagator for for $n\geq 0$.
Post propagator for SetVar x
Definition set.hh:773
void nroot(Home home, FloatVar x0, int n, FloatVar x1)
Post propagator for for $n\geq 0$.