main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Jan 28 2020 00:00:00 for Gecode by
doxygen
1.8.17
gecode
float
arithmetic
pow-nroot.hpp
Go to the documentation of this file.
1
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
/*
3
* Main authors:
4
* Vincent Barichard <Vincent.Barichard@univ-angers.fr>
5
*
6
* Copyright:
7
* Vincent Barichard, 2012
8
*
9
* Last modified:
10
* $Date: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
11
* $Revision: 14967 $
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
/*
42
* Bounds consistent square operator
43
*
44
*/
45
46
template
<
class
A,
class
B>
47
forceinline
48
Pow<A,B>::Pow
(
Home
home, A x0, B x1,
int
n
)
49
:
MixBinaryPropagator
<A,
PC_FLOAT_BND
,B,
PC_FLOAT_BND
>(home,x0,x1), m_n(
n
) {}
50
51
template
<
class
A,
class
B>
52
ExecStatus
53
Pow<A,B>::post
(
Home
home, A x0, B x1,
int
n
) {
54
if
(
n
== 0) {
55
if
((x0.min() == 0.0) && (x0.max() == 0.0))
return
ES_FAILED
;
56
GECODE_ME_CHECK
(x1.eq(home,1.0));
57
return
ES_OK
;
58
}
59
60
GECODE_ME_CHECK
(x1.eq(home,
pow
(x0.domain(),
n
)));
61
if
((x1.min() == 0.0) && (x1.max() == 0.0)) {
62
GECODE_ME_CHECK
(x1.eq(home,0.0));
63
return
ES_OK
;
64
}
65
66
if
((
n
% 2) == 0)
67
{
68
if
(x0.min() >= 0)
69
GECODE_ME_CHECK
(x0.eq(home,
nroot
(x1.domain(),
n
)));
70
else
if
(x0.max() <= 0)
71
GECODE_ME_CHECK
(x0.eq(home,-
nroot
(x1.domain(),
n
)));
72
else
73
GECODE_ME_CHECK
(x0.eq(home,
74
hull
(
75
nroot
(x1.domain(),
n
),
76
-
nroot
(x1.domain(),
n
)
77
)
78
));
79
}
else
80
GECODE_ME_CHECK
(x0.eq(home,
nroot
(x1.domain(),
n
)));
81
82
if
(!x0.assigned()) (void)
new
(home)
Pow<A,B>
(home,x0,x1,
n
);
83
return
ES_OK
;
84
}
85
86
template
<
class
A,
class
B>
87
forceinline
88
Pow<A,B>::Pow
(
Space
& home,
bool
share,
Pow<A,B>
&
p
)
89
:
MixBinaryPropagator
<A,
PC_FLOAT_BND
,B,
PC_FLOAT_BND
>(home,share,
p
), m_n(
p
.m_n) {}
90
91
template
<
class
A,
class
B>
92
Actor
*
93
Pow<A,B>::copy
(
Space
& home,
bool
share) {
94
return
new
(home)
Pow<A,B>
(home,share,*
this
);
95
}
96
97
template
<
class
A,
class
B>
98
ExecStatus
99
Pow<A,B>::propagate
(
Space
& home,
const
ModEventDelta
&) {
100
if
((x0.min() == 0.0) && (x0.max() == 0.0))
return
ES_FAILED
;
101
GECODE_ME_CHECK
(x1.eq(home,
pow
(x0.domain(),m_n)));
102
103
if
((x1.min() == 0.0) && (x1.max() == 0.0)) {
104
GECODE_ME_CHECK
(x1.eq(home,0.0));
105
return
home.
ES_SUBSUMED
(*
this
);
106
}
107
108
if
((m_n % 2) == 0)
109
{
110
if
(x0.min() >= 0)
111
GECODE_ME_CHECK
(x0.eq(home,
nroot
(x1.domain(),m_n)));
112
else
if
(x0.max() <= 0)
113
GECODE_ME_CHECK
(x0.eq(home,-
nroot
(x1.domain(),m_n)));
114
else
115
GECODE_ME_CHECK
(x0.eq(home,
116
hull
(
117
nroot
(x1.domain(),m_n),
118
-
nroot
(x1.domain(),m_n)
119
)
120
));
121
}
else
122
GECODE_ME_CHECK
(x0.eq(home,
nroot
(x1.domain(),m_n)));
123
return
x0.assigned() ? home.
ES_SUBSUMED
(*
this
) :
ES_FIX
;
124
}
125
126
/*
127
* Bounds consistent square root operator
128
*
129
*/
130
131
template
<
class
A,
class
B>
132
forceinline
133
NthRoot<A,B>::NthRoot
(
Home
home, A x0, B x1,
int
n
)
134
:
MixBinaryPropagator
<A,
PC_FLOAT_BND
,B,
PC_FLOAT_BND
>(home,x0,x1), m_n(
n
) {}
135
136
template
<
class
A,
class
B>
137
ExecStatus
138
NthRoot<A,B>::post
(
Home
home, A x0, B x1,
int
n
) {
139
if
(
n
== 0)
return
ES_FAILED
;
140
GECODE_ME_CHECK
(x0.gq(home,0.0));
141
(void)
new
(home)
NthRoot<A,B>
(home,x0,x1,
n
);
142
return
ES_OK
;
143
}
144
145
template
<
class
A,
class
B>
146
forceinline
147
NthRoot<A,B>::NthRoot
(
Space
& home,
bool
share,
NthRoot<A,B>
&
p
)
148
:
MixBinaryPropagator
<A,
PC_FLOAT_BND
,B,
PC_FLOAT_BND
>(home,share,
p
), m_n(
p
.m_n) {}
149
150
template
<
class
A,
class
B>
151
Actor
*
152
NthRoot<A,B>::copy
(
Space
& home,
bool
share) {
153
return
new
(home)
NthRoot<A,B>
(home,share,*
this
);
154
}
155
156
template
<
class
A,
class
B>
157
ExecStatus
158
NthRoot<A,B>::propagate
(
Space
& home,
const
ModEventDelta
&) {
159
GECODE_ME_CHECK
(x1.eq(home,
nroot
(x0.domain(),m_n)));
160
GECODE_ME_CHECK
(x0.eq(home,
pow
(x1.domain(),m_n)));
161
return
x0.assigned() ? home.
ES_SUBSUMED
(*
this
) :
ES_FIX
;
162
}
163
164
165
}}}
166
167
// STATISTICS: float-prop
168
Gecode::pow
void pow(Home home, FloatVar x0, int n, FloatVar x1)
Post propagator for for $n\geq 0$.
Definition:
arithmetic.cpp:113
Gecode::Float::Arithmetic::Pow::post
static ExecStatus post(Home home, A x0, B x1, int n)
Post propagator for .
Definition:
pow-nroot.hpp:53
Gecode::Float::Arithmetic::Pow::copy
virtual Actor * copy(Space &home, bool share)
Create copy during cloning.
Definition:
pow-nroot.hpp:93
forceinline
#define forceinline
Definition:
config.hpp:173
Gecode::Space::ES_SUBSUMED
ExecStatus ES_SUBSUMED(Propagator &p)
Definition:
core.hpp:3614
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::Float::Arithmetic::NthRoot::copy
virtual Actor * copy(Space &home, bool share)
Create copy during cloning.
Definition:
pow-nroot.hpp:152
Gecode::Space
Computation spaces.
Definition:
core.hpp:1748
Gecode::Actor
Base-class for both propagators and branchers.
Definition:
core.hpp:696
Gecode
Gecode toplevel namespace
Gecode::MixBinaryPropagator
Mixed binary propagator.
Definition:
propagator.hpp:213
Gecode::Float::Arithmetic::Pow::Pow
Pow(Space &home, bool share, Pow &p)
Constructor for cloning p.
Definition:
pow-nroot.hpp:88
Gecode::Float::Arithmetic::NthRoot::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition:
pow-nroot.hpp:158
Gecode::nroot
void nroot(Home home, FloatVar x0, int n, FloatVar x1)
Post propagator for for $n\geq 0$.
Definition:
arithmetic.cpp:122
Gecode::Home
Home class for posting propagators
Definition:
core.hpp:922
Gecode::Float::Arithmetic::Pow
Propagator for bounds consistent pow operator
Definition:
arithmetic.hh:169
Gecode::Float::Arithmetic::Pow::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition:
pow-nroot.hpp:99
Gecode::ES_FIX
@ ES_FIX
Propagation has computed fixpoint.
Definition:
core.hpp:545
Gecode::Float::Arithmetic::NthRoot
Propagator for bounds consistent nth root operator
Definition:
arithmetic.hh:197
Gecode::Float::Arithmetic::NthRoot::NthRoot
NthRoot(Space &home, bool share, NthRoot &p)
Constructor for cloning p.
Definition:
pow-nroot.hpp:147
GECODE_ME_CHECK
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition:
macros.hpp:56
Gecode::Float::hull
FloatVal hull(const FloatVal &x, const FloatVal &y)
Definition:
val.hpp:511
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:238
Gecode::ES_FAILED
@ ES_FAILED
Execution has resulted in failure.
Definition:
core.hpp:542
Gecode::ModEventDelta
int ModEventDelta
Modification event deltas.
Definition:
core.hpp:169
Gecode::ES_OK
@ ES_OK
Execution is okay.
Definition:
core.hpp:544
p
int p
Number of positive literals for node type.
Definition:
bool-expr.cpp:236
Gecode::Float::Arithmetic::NthRoot::post
static ExecStatus post(Home home, A x0, B x1, int n)
Post propagator for .
Definition:
pow-nroot.hpp:138
Gecode::ExecStatus
ExecStatus
Definition:
core.hpp:540