main page
modules
namespaces
classes
files
Gecode home
Generated on Fri Jan 10 2020 11:38:25 for Gecode by
doxygen
1.8.16
gecode
float
arithmetic
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
38
namespace
Gecode
{
namespace
Float {
namespace
Arithmetic {
39
40
/*
41
* Positive bounds consistent squaring
42
*
43
*/
44
template
<
class
VA,
class
VB>
45
forceinline
46
SqrPlus<VA,VB>::SqrPlus
(
Home
home, VA x0, VB x1)
47
:
MixBinaryPropagator
<VA,
PC_FLOAT_BND
,VB,
PC_FLOAT_BND
>(home,x0,x1) {}
48
49
template
<
class
VA,
class
VB>
50
forceinline
ExecStatus
51
SqrPlus<VA,VB>::post
(
Home
home, VA x0, VB x1) {
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>
65
forceinline
66
SqrPlus<VA,VB>::SqrPlus
(
Space
& home,
SqrPlus<VA,VB>
&
p
)
67
:
MixBinaryPropagator
<VA,
PC_FLOAT_BND
,VB,
PC_FLOAT_BND
>(home,
p
) {}
68
69
template
<
class
VA,
class
VB>
70
Actor
*
71
SqrPlus<VA,VB>::copy
(
Space
& home) {
72
return
new
(home)
SqrPlus<VA,VB>
(home,*
this
);
73
}
74
75
template
<
class
VA,
class
VB>
76
ExecStatus
77
SqrPlus<VA,VB>::propagate
(
Space
& home,
const
ModEventDelta
&) {
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>
99
forceinline
100
Sqr<View>::Sqr
(
Home
home, View x0, View x1)
101
:
BinaryPropagator
<View,
PC_FLOAT_BND
>(home,x0,x1) {}
102
103
template
<
class
View>
104
forceinline
ExecStatus
105
Sqr<View>::post
(
Home
home, View x0, View x1) {
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));
111
return
SqrPlus<FloatView,FloatView>::post
(home,x0,x1);
112
}
else
{
113
if
(x0.min() >= 0)
114
return
SqrPlus<FloatView,FloatView>::post
(home,x0,x1);
115
if
(x0.max() <= 0)
116
return
SqrPlus<MinusView,FloatView>::post
(home,
MinusView
(x0),x1);
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>
124
forceinline
125
Sqr<View>::Sqr
(
Space
& home,
Sqr<View>
&
p
)
126
:
BinaryPropagator
<View,
PC_FLOAT_BND
>(home,
p
) {}
127
128
template
<
class
View>
129
Actor
*
130
Sqr<View>::copy
(
Space
& home) {
131
return
new
(home)
Sqr<View>
(home,*
this
);
132
}
133
134
template
<
class
View>
135
ExecStatus
136
Sqr<View>::propagate
(
Space
& home,
const
ModEventDelta
&) {
137
assert(x1.min() >= 0);
138
if
(x0.min() >= 0)
139
GECODE_REWRITE
(*
this
,(
SqrPlus<FloatView,FloatView>::post
(home(*
this
),x0,x1)));
140
if
(x0.max() <= 0)
141
GECODE_REWRITE
(*
this
,(
SqrPlus<MinusView,FloatView>::post
(home(*
this
),
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>
164
forceinline
165
Sqrt<A,B>::Sqrt
(
Home
home, A x0, B x1)
166
:
MixBinaryPropagator
<A,
PC_FLOAT_BND
,B,
PC_FLOAT_BND
>(home,x0,x1) {}
167
168
template
<
class
A,
class
B>
169
ExecStatus
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>
185
forceinline
186
Sqrt<A,B>::Sqrt
(
Space
& home,
Sqrt<A,B>
&
p
)
187
:
MixBinaryPropagator
<A,
PC_FLOAT_BND
,B,
PC_FLOAT_BND
>(home,
p
) {}
188
189
template
<
class
A,
class
B>
190
Actor
*
191
Sqrt<A,B>::copy
(
Space
& home) {
192
return
new
(home)
Sqrt<A,B>
(home,*
this
);
193
}
194
195
template
<
class
A,
class
B>
196
ExecStatus
197
Sqrt<A,B>::propagate
(
Space
& home,
const
ModEventDelta
&) {
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
Gecode::Float::Arithmetic::SqrPlus::post
static ExecStatus post(Home home, VA x0, VB x1)
Post propagator .
Definition:
sqr-sqrt.hpp:51
Gecode::Space::ES_SUBSUMED
ExecStatus ES_SUBSUMED(Propagator &p)
Definition:
core.hpp:3563
Gecode::Float::Arithmetic::Sqrt
Propagator for bounds consistent square root operator
Definition:
arithmetic.hh:109
Gecode::Float::PC_FLOAT_BND
const Gecode::PropCond PC_FLOAT_BND
Propagate when minimum or maximum of a view changes.
Definition:
var-type.hpp:292
Gecode::sqr
void sqr(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition:
arithmetic.cpp:95
Gecode::z
Post propagator for SetVar SetOpType SetVar SetRelType SetVar z
Definition:
set.hh:767
Gecode::Float::Arithmetic::Sqrt::copy
virtual Actor * copy(Space &home)
Create copy during cloning.
Definition:
sqr-sqrt.hpp:191
Gecode::Float::Arithmetic::SqrPlus::copy
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition:
sqr-sqrt.hpp:71
Gecode::Space
Computation spaces.
Definition:
core.hpp:1742
Gecode::Actor
Base-class for both propagators and branchers.
Definition:
core.hpp:628
Gecode::Float::Arithmetic::Sqr::Sqr
Sqr(Space &home, Sqr &p)
Constructor for cloning p.
Definition:
sqr-sqrt.hpp:125
Gecode::Float::Arithmetic::SqrPlus::SqrPlus
SqrPlus(Home home, VA x0, VB x1)
Constructor for posting.
Definition:
sqr-sqrt.hpp:46
Gecode::Float::Arithmetic::Sqr
Propagator for bounds consistent square operator
Definition:
arithmetic.hh:82
Gecode
Gecode toplevel namespace
Gecode::MixBinaryPropagator
Mixed binary propagator.
Definition:
pattern.hpp:204
Gecode::Float::Arithmetic::Sqrt::Sqrt
Sqrt(Space &home, Sqrt &p)
Constructor for cloning p.
Definition:
sqr-sqrt.hpp:186
Gecode::Float::Arithmetic::Sqrt::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition:
sqr-sqrt.hpp:197
Gecode::Home
Home class for posting propagators
Definition:
core.hpp:856
Gecode::sqrt
void sqrt(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition:
arithmetic.cpp:102
Gecode::r
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition:
set.hh:767
Gecode::Float::Rounding
Floating point rounding policy.
Definition:
float.hh:154
Gecode::Float::MinusView
Minus float view.
Definition:
view.hpp:154
Gecode::FloatVal
Float value type.
Definition:
float.hh:334
Gecode::Float::Arithmetic::Sqrt::post
static ExecStatus post(Home home, A x0, B x1)
Post propagator for .
Definition:
sqr-sqrt.hpp:170
Gecode::Float::Arithmetic::Sqr::copy
virtual Actor * copy(Space &home)
Create copy during cloning.
Definition:
sqr-sqrt.hpp:130
Gecode::ES_FIX
Propagation has computed fixpoint.
Definition:
core.hpp:477
Gecode::Float::Arithmetic::SqrPlus
Bounds consistent positive square propagator.
Definition:
arithmetic.hh:58
Gecode::Float::Arithmetic::SqrPlus::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition:
sqr-sqrt.hpp:77
forceinline
#define forceinline
Definition:
config.hpp:185
GECODE_ME_CHECK
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition:
macros.hpp:52
Gecode::Float::hull
FloatVal hull(const FloatVal &x, const FloatVal &y)
Definition:
val.hpp:507
Gecode::Float::Arithmetic::Sqr::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition:
sqr-sqrt.hpp:136
Gecode::ES_FAILED
Execution has resulted in failure.
Definition:
core.hpp:474
Gecode::BinaryPropagator
Binary propagator.
Definition:
pattern.hpp:84
Gecode::Float::Arithmetic::Sqr::post
static ExecStatus post(Home home, View x0, View x1)
Post propagator for .
Definition:
sqr-sqrt.hpp:105
Gecode::ModEventDelta
int ModEventDelta
Modification event deltas.
Definition:
core.hpp:89
Gecode::ES_NOFIX
Propagation has not computed fixpoint.
Definition:
core.hpp:475
GECODE_REWRITE
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition:
macros.hpp:116
Gecode::ES_OK
Execution is okay.
Definition:
core.hpp:476
p
int p
Number of positive literals for node type.
Definition:
bool-expr.cpp:232
Gecode::ExecStatus
ExecStatus
Definition:
core.hpp:472