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
dom.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
*
6
* Copyright:
7
* Christian Schulte, 2013
8
*
9
* This file is part of Gecode, the generic constraint
10
* development environment:
11
* http://www.gecode.org
12
*
13
* Permission is hereby granted, free of charge, to any person obtaining
14
* a copy of this software and associated documentation files (the
15
* "Software"), to deal in the Software without restriction, including
16
* without limitation the rights to use, copy, modify, merge, publish,
17
* distribute, sublicense, and/or sell copies of the Software, and to
18
* permit persons to whom the Software is furnished to do so, subject to
19
* the following conditions:
20
*
21
* The above copyright notice and this permission notice shall be
22
* included in all copies or substantial portions of the Software.
23
*
24
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
*
32
*/
33
34
35
#include <
gecode/float/rel.hh
>
36
37
namespace
Gecode
{
38
39
void
40
dom
(
Home
home,
FloatVar
x
,
FloatVal
n
) {
41
using namespace
Float;
42
Limits::check
(
n
,
"Float::dom"
);
43
GECODE_POST
;
44
FloatView xv(
x
);
45
GECODE_ME_FAIL
(xv.eq(home,
n
));
46
}
47
48
void
49
dom
(
Home
home,
const
FloatVarArgs
&
x
,
FloatVal
n
) {
50
using namespace
Float;
51
Limits::check
(
n
,
"Float::dom"
);
52
GECODE_POST
;
53
for
(
int
i
=
x
.size();
i
--; ) {
54
FloatView xv(
x
[
i
]);
55
GECODE_ME_FAIL
(xv.eq(home,
n
));
56
}
57
}
58
59
void
60
dom
(
Home
home,
FloatVar
x
,
FloatNum
min
,
FloatNum
max
) {
61
using namespace
Float;
62
Limits::check
(
min
,
"Float::dom"
);
63
Limits::check
(
max
,
"Float::dom"
);
64
GECODE_POST
;
65
FloatView xv(
x
);
66
GECODE_ME_FAIL
(xv.gq(home,
min
));
67
GECODE_ME_FAIL
(xv.lq(home,
max
));
68
}
69
70
void
71
dom
(
Home
home,
const
FloatVarArgs
&
x
,
FloatNum
min
,
FloatNum
max
) {
72
using namespace
Float;
73
Limits::check
(
min
,
"Float::dom"
);
74
Limits::check
(
max
,
"Float::dom"
);
75
GECODE_POST
;
76
for
(
int
i
=
x
.size();
i
--; ) {
77
FloatView xv(
x
[
i
]);
78
GECODE_ME_FAIL
(xv.gq(home,
min
));
79
GECODE_ME_FAIL
(xv.lq(home,
max
));
80
}
81
}
82
83
void
84
dom
(
Home
home,
FloatVar
x
,
FloatVal
n
,
Reify
r
) {
85
using namespace
Float;
86
Limits::check
(
n
,
"Float::dom"
);
87
GECODE_POST
;
88
switch
(
r
.mode()) {
89
case
RM_EQV
:
90
GECODE_ES_FAIL
((Rel::ReEqFloat<FloatView,Int::BoolView,RM_EQV>
91
::
post
(home,
x
,
n
,
r
.var())));
92
break
;
93
case
RM_IMP
:
94
GECODE_ES_FAIL
((Rel::ReEqFloat<FloatView,Int::BoolView,RM_IMP>
95
::
post
(home,
x
,
n
,
r
.var())));
96
break
;
97
case
RM_PMI
:
98
GECODE_ES_FAIL
((Rel::ReEqFloat<FloatView,Int::BoolView,RM_PMI>
99
::
post
(home,
x
,
n
,
r
.var())));
100
break
;
101
default
:
throw
Int::UnknownReifyMode
(
"Float::dom"
);
102
}
103
}
104
105
void
106
dom
(
Home
home,
FloatVar
x
,
FloatNum
min
,
FloatNum
max
,
Reify
r
) {
107
using namespace
Float;
108
if
(
min
>
max
) {
109
Int::BoolView
b
(
r
.var());
110
switch
(
r
.mode()) {
111
case
RM_EQV
:
112
case
RM_IMP
:
113
GECODE_ME_FAIL
(
b
.zero(home));
114
break
;
115
case
RM_PMI
:
116
break
;
117
default
:
throw
Int::UnknownReifyMode
(
"Float::dom"
);
118
}
119
}
else
{
120
FloatVal
n
(
min
,
max
);
121
dom
(home,
x
,
n
,
r
);
122
}
123
}
124
125
void
126
dom
(
Home
home,
FloatVar
x
,
FloatVar
d
) {
127
using namespace
Float;
128
GECODE_POST
;
129
FloatView xv(
x
), dv(
d
);
130
if
(xv != dv) {
131
GECODE_ME_FAIL
(xv.lq(home,dv.max()));
132
GECODE_ME_FAIL
(xv.gq(home,dv.min()));
133
}
134
}
135
136
void
137
dom
(
Home
home,
const
FloatVarArgs
&
x
,
const
FloatVarArgs
&
d
) {
138
using namespace
Float;
139
if
(
x
.size() !=
d
.
size
())
140
throw
ArgumentSizeMismatch
(
"Float::dom"
);
141
for
(
int
i
=
x
.size();
i
--; ) {
142
GECODE_POST
;
143
FloatView xv(
x
[
i
]), dv(
d
[
i
]);
144
if
(xv != dv) {
145
GECODE_ME_FAIL
(xv.lq(home,dv.max()));
146
GECODE_ME_FAIL
(xv.gq(home,dv.min()));
147
}
148
}
149
}
150
151
}
152
153
// STATISTICS: float-post
154
Gecode::Int::UnknownReifyMode
Exception: Unknown reification mode passed as argument
Definition:
exception.hpp:115
b
struct Gecode::@602::NNF::@65::@66 b
For binary nodes (and, or, eqv)
Gecode::FloatVarArgs
Passing float variables.
Definition:
float.hh:979
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:767
Gecode::Int::ArgumentSizeMismatch
Exception: Arguments are of different size
Definition:
exception.hpp:73
Gecode::RM_PMI
Inverse implication for reification.
Definition:
int.hh:869
GECODE_ES_FAIL
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition:
macros.hpp:103
Gecode::max
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition:
arithmetic.cpp:49
rel.hh
Gecode::RM_IMP
Implication for reification.
Definition:
int.hh:862
Gecode::IntSet::size
unsigned int size(void) const
Return size (cardinality) of set.
Definition:
int-set-1.hpp:198
Gecode::Int::BoolView
Boolean view for Boolean variables.
Definition:
view.hpp:1380
Gecode
Gecode toplevel namespace
Gecode::Reify
Reification specification.
Definition:
int.hh:876
Gecode::RM_EQV
Equivalence for reification (default)
Definition:
int.hh:855
Gecode::Home
Home class for posting propagators
Definition:
core.hpp:856
Gecode::dom
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Definition:
dom.cpp:40
Gecode::r
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition:
set.hh:767
Gecode::FloatNum
double FloatNum
Floating point number base type.
Definition:
float.hh:106
Gecode::post
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Definition:
filter.cpp:138
Gecode::FloatVal
Float value type.
Definition:
float.hh:334
Gecode::FloatVar
Float variables.
Definition:
float.hh:870
GECODE_POST
#define GECODE_POST
Check for failure in a constraint post function.
Definition:
macros.hpp:40
Test::Int::Dom::d
Gecode::IntSet d(r, 4)
Gecode::Float::Limits::check
void check(const FloatVal &n, const char *l)
Check whether float n is a valid number, otherwise throw out of limits exception with information l.
Definition:
limits.hpp:44
GECODE_ME_FAIL
#define GECODE_ME_FAIL(me)
Check whether modification event me is failed, and fail space home.
Definition:
macros.hpp:77
Gecode::min
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition:
arithmetic.cpp:67
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:234
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})