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
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
* Last modified:
10
* $Date: 2016-05-23 22:18:23 +0200 (Mon, 23 May 2016) $ by $Author: schulte $
11
* $Revision: 15073 $
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
39
#include <
gecode/float/rel.hh
>
40
41
namespace
Gecode
{
42
43
void
44
dom
(
Home
home,
FloatVar
x
,
FloatVal
n
) {
45
using namespace
Float;
46
Limits::check
(
n
,
"Float::dom"
);
47
GECODE_POST
;
48
FloatView xv(
x
);
49
GECODE_ME_FAIL
(xv.eq(home,
n
));
50
}
51
52
void
53
dom
(
Home
home,
const
FloatVarArgs
&
x
,
FloatVal
n
) {
54
using namespace
Float;
55
Limits::check
(
n
,
"Float::dom"
);
56
GECODE_POST
;
57
for
(
int
i
=
x
.size();
i
--; ) {
58
FloatView xv(
x
[
i
]);
59
GECODE_ME_FAIL
(xv.eq(home,
n
));
60
}
61
}
62
63
void
64
dom
(
Home
home,
FloatVar
x
,
FloatNum
min
,
FloatNum
max
) {
65
using namespace
Float;
66
Limits::check
(
min
,
"Float::dom"
);
67
Limits::check
(
max
,
"Float::dom"
);
68
GECODE_POST
;
69
FloatView xv(
x
);
70
GECODE_ME_FAIL
(xv.gq(home,
min
));
71
GECODE_ME_FAIL
(xv.lq(home,
max
));
72
}
73
74
void
75
dom
(
Home
home,
const
FloatVarArgs
&
x
,
FloatNum
min
,
FloatNum
max
) {
76
using namespace
Float;
77
Limits::check
(
min
,
"Float::dom"
);
78
Limits::check
(
max
,
"Float::dom"
);
79
GECODE_POST
;
80
for
(
int
i
=
x
.size();
i
--; ) {
81
FloatView xv(
x
[
i
]);
82
GECODE_ME_FAIL
(xv.gq(home,
min
));
83
GECODE_ME_FAIL
(xv.lq(home,
max
));
84
}
85
}
86
87
void
88
dom
(
Home
home,
FloatVar
x
,
FloatVal
n
,
Reify
r
) {
89
using namespace
Float;
90
Limits::check
(
n
,
"Float::dom"
);
91
GECODE_POST
;
92
switch
(
r
.mode()) {
93
case
RM_EQV
:
94
GECODE_ES_FAIL
((Rel::ReEqFloat<FloatView,Int::BoolView,RM_EQV>
95
::
post
(home,
x
,
n
,
r
.var())));
96
break
;
97
case
RM_IMP
:
98
GECODE_ES_FAIL
((Rel::ReEqFloat<FloatView,Int::BoolView,RM_IMP>
99
::
post
(home,
x
,
n
,
r
.var())));
100
break
;
101
case
RM_PMI
:
102
GECODE_ES_FAIL
((Rel::ReEqFloat<FloatView,Int::BoolView,RM_PMI>
103
::
post
(home,
x
,
n
,
r
.var())));
104
break
;
105
default
:
throw
Int::UnknownReifyMode
(
"Float::dom"
);
106
}
107
}
108
109
void
110
dom
(
Home
home,
FloatVar
x
,
FloatNum
min
,
FloatNum
max
,
Reify
r
) {
111
using namespace
Float;
112
if
(
min
>
max
) {
113
Int::BoolView
b
(
r
.var());
114
switch
(
r
.mode()) {
115
case
RM_EQV
:
116
case
RM_IMP
:
117
GECODE_ME_FAIL
(
b
.zero(home));
118
break
;
119
case
RM_PMI
:
120
break
;
121
default
:
throw
Int::UnknownReifyMode
(
"Float::dom"
);
122
}
123
}
else
{
124
FloatVal
n
(
min
,
max
);
125
dom
(home,
x
,
n
,
r
);
126
}
127
}
128
129
void
130
dom
(
Home
home,
FloatVar
x
,
FloatVar
d
) {
131
using namespace
Float;
132
GECODE_POST
;
133
FloatView xv(
x
), dv(
d
);
134
if
(!
same
(xv,dv)) {
135
GECODE_ME_FAIL
(xv.lq(home,dv.max()));
136
GECODE_ME_FAIL
(xv.gq(home,dv.min()));
137
}
138
}
139
140
void
141
dom
(
Home
home,
const
FloatVarArgs
&
x
,
const
FloatVarArgs
&
d
) {
142
using namespace
Float;
143
if
(
x
.size() !=
d
.
size
())
144
throw
ArgumentSizeMismatch
(
"Float::dom"
);
145
for
(
int
i
=
x
.size();
i
--; ) {
146
GECODE_POST
;
147
FloatView xv(
x
[
i
]), dv(
d
[
i
]);
148
if
(!
same
(xv,dv)) {
149
GECODE_ME_FAIL
(xv.lq(home,dv.max()));
150
GECODE_ME_FAIL
(xv.gq(home,dv.min()));
151
}
152
}
153
}
154
155
}
156
157
// STATISTICS: float-post
158
Gecode::Int::UnknownReifyMode
Exception: Unknown reification mode passed as argument
Definition:
exception.hpp:119
Gecode::FloatVarArgs
Passing float variables.
Definition:
float.hh:981
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:784
Gecode::Int::ArgumentSizeMismatch
Exception: Arguments are of different size
Definition:
exception.hpp:77
Gecode::RM_PMI
@ RM_PMI
Inverse implication for reification.
Definition:
int.hh:850
GECODE_ES_FAIL
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition:
macros.hpp:107
Gecode::max
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition:
arithmetic.cpp:53
rel.hh
Gecode::RM_IMP
@ RM_IMP
Implication for reification.
Definition:
int.hh:843
Test::Int::Basic::i
Gecode::IntArgs i(4, 1, 2, 3, 4)
Gecode::Int::BinPacking::same
bool same(const Item &i, const Item &j)
Whether two items are the same.
Definition:
propagate.hpp:76
Gecode::IntSet::size
unsigned int size(void) const
Return size (cardinality) of set.
Definition:
int-set-1.hpp:161
Gecode::Int::BoolView
Boolean view for Boolean variables.
Definition:
view.hpp:1315
Gecode
Gecode toplevel namespace
Gecode::Reify
Reification specification.
Definition:
int.hh:857
Gecode::RM_EQV
@ RM_EQV
Equivalence for reification (default)
Definition:
int.hh:836
Gecode::Home
Home class for posting propagators
Definition:
core.hpp:922
b
struct Gecode::@579::NNF::@61::@62 b
For binary nodes (and, or, eqv)
Gecode::dom
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Definition:
dom.cpp:44
Gecode::r
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition:
set.hh:784
Gecode::FloatNum
double FloatNum
Floating point number base type.
Definition:
float.hh:110
Gecode::post
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Definition:
trace-filter.cpp:142
Gecode::FloatVal
Float value type.
Definition:
float.hh:338
Gecode::FloatVar
Float variables.
Definition:
float.hh:874
GECODE_POST
#define GECODE_POST
Check for failure in a constraint post function.
Definition:
macros.hpp:44
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:48
GECODE_ME_FAIL
#define GECODE_ME_FAIL(me)
Check whether modification event me is failed, and fail space home.
Definition:
macros.hpp:81
Gecode::min
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition:
arithmetic.cpp:71
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:238