main page
modules
namespaces
classes
files
Gecode home
Generated on Mon Feb 8 2021 00:00:00 for Gecode by
doxygen
1.8.20
gecode
float
linear.cpp
Go to the documentation of this file.
1
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
/*
3
o * 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
36
#include <
gecode/float/linear.hh
>
37
38
namespace
Gecode
{
39
40
void
41
linear
(
Home
home,
42
const
FloatVarArgs
&
x
,
FloatRelType
frt,
FloatVal
c
) {
43
using namespace
Float;
44
GECODE_POST
;
45
Region
re;
46
Linear::Term
*
t
= re.
alloc
<
Linear::Term
>(
x
.size());
47
for
(
int
i
=
x
.size();
i
--; ) {
48
t
[
i
].a=1.0;
t
[
i
].x=
x
[
i
];
49
}
50
Linear::post
(home,
t
,
x
.size(),frt,
c
);
51
}
52
53
void
54
linear
(
Home
home,
55
const
FloatVarArgs
&
x
,
FloatRelType
frt,
FloatVal
c
,
Reify
r
) {
56
using namespace
Float;
57
GECODE_POST
;
58
Region
re;
59
Linear::Term
*
t
= re.
alloc
<
Linear::Term
>(
x
.size());
60
for
(
int
i
=
x
.size();
i
--; ) {
61
t
[
i
].a=1.0;
t
[
i
].x=
x
[
i
];
62
}
63
Linear::post
(home,
t
,
x
.size(),frt,
c
,
r
);
64
}
65
66
void
67
linear
(
Home
home,
68
const
FloatValArgs
&
a
,
const
FloatVarArgs
&
x
,
FloatRelType
frt,
69
FloatVal
c
) {
70
using namespace
Float;
71
if
(
a
.size() !=
x
.size())
72
throw
ArgumentSizeMismatch
(
"Float::linear"
);
73
GECODE_POST
;
74
Region
re;
75
Linear::Term
*
t
= re.
alloc
<
Linear::Term
>(
x
.size());
76
for
(
int
i
=
x
.size();
i
--; ) {
77
t
[
i
].a=
a
[
i
];
t
[
i
].x=
x
[
i
];
78
}
79
Linear::post
(home,
t
,
x
.size(),frt,
c
);
80
}
81
82
void
83
linear
(
Home
home,
84
const
FloatValArgs
&
a
,
const
FloatVarArgs
&
x
,
FloatRelType
frt,
85
FloatVal
c
,
Reify
r
) {
86
using namespace
Float;
87
if
(
a
.size() !=
x
.size())
88
throw
ArgumentSizeMismatch
(
"Float::linear"
);
89
GECODE_POST
;
90
Region
re;
91
Linear::Term
*
t
= re.
alloc
<
Linear::Term
>(
x
.size());
92
for
(
int
i
=
x
.size();
i
--; ) {
93
t
[
i
].a=
a
[
i
];
t
[
i
].x=
x
[
i
];
94
}
95
Linear::post
(home,
t
,
x
.size(),frt,
c
,
r
);
96
}
97
98
void
99
linear
(
Home
home,
100
const
FloatVarArgs
&
x
,
FloatRelType
frt,
FloatVar
y
) {
101
using namespace
Float;
102
GECODE_POST
;
103
Region
re;
104
Linear::Term
*
t
= re.
alloc
<
Linear::Term
>(
x
.size()+1);
105
for
(
int
i
=
x
.size();
i
--; ) {
106
t
[
i
].a=1.0;
t
[
i
].x=
x
[
i
];
107
}
108
FloatNum
min
,
max
;
109
estimate
(
t
,
x
.size(),0.0,
min
,
max
);
110
FloatView
v
(
y
);
111
switch
(frt) {
112
case
FRT_EQ
:
113
GECODE_ME_FAIL
(
v
.gq(home,
min
));
GECODE_ME_FAIL
(
v
.lq(home,
max
));
114
break
;
115
case
FRT_GQ
:
case
FRT_GR
:
116
GECODE_ME_FAIL
(
v
.lq(home,
max
));
117
break
;
118
case
FRT_LQ
:
case
FRT_LE
:
119
GECODE_ME_FAIL
(
v
.gq(home,
min
));
120
break
;
121
default
: ;
122
}
123
if
(home.
failed
())
return
;
124
t
[
x
.size()].a=-1.0;
t
[
x
.size()].x=
y
;
125
Linear::post
(home,
t
,
x
.size()+1,frt,0.0);
126
}
127
128
void
129
linear
(
Home
home,
130
const
FloatVarArgs
&
x
,
FloatRelType
frt,
FloatVar
y
,
Reify
r
) {
131
using namespace
Float;
132
GECODE_POST
;
133
Region
re;
134
Linear::Term
*
t
= re.
alloc
<
Linear::Term
>(
x
.size()+1);
135
for
(
int
i
=
x
.size();
i
--; ) {
136
t
[
i
].a=1.0;
t
[
i
].x=
x
[
i
];
137
}
138
t
[
x
.size()].a=-1;
t
[
x
.size()].x=
y
;
139
Linear::post
(home,
t
,
x
.size()+1,frt,0.0,
r
);
140
}
141
142
void
143
linear
(
Home
home,
144
const
FloatValArgs
&
a
,
const
FloatVarArgs
&
x
,
FloatRelType
frt,
145
FloatVar
y
) {
146
using namespace
Float;
147
if
(
a
.size() !=
x
.size())
148
throw
ArgumentSizeMismatch
(
"Float::linear"
);
149
GECODE_POST
;
150
Region
re;
151
Linear::Term
*
t
= re.
alloc
<
Linear::Term
>(
x
.size()+1);
152
for
(
int
i
=
x
.size();
i
--; ) {
153
t
[
i
].a=
a
[
i
];
t
[
i
].x=
x
[
i
];
154
}
155
FloatNum
min
,
max
;
156
estimate
(
t
,
x
.size(),0.0,
min
,
max
);
157
FloatView
v
(
y
);
158
switch
(frt) {
159
case
FRT_EQ
:
160
GECODE_ME_FAIL
(
v
.gq(home,
min
));
GECODE_ME_FAIL
(
v
.lq(home,
max
));
161
break
;
162
case
FRT_GQ
:
case
FRT_GR
:
163
GECODE_ME_FAIL
(
v
.lq(home,
max
));
164
break
;
165
case
FRT_LQ
:
case
FRT_LE
:
166
GECODE_ME_FAIL
(
v
.gq(home,
min
));
167
break
;
168
default
: ;
169
}
170
if
(home.
failed
())
return
;
171
t
[
x
.size()].a=-1.0;
t
[
x
.size()].x=
y
;
172
Linear::post
(home,
t
,
x
.size()+1,frt,0.0);
173
}
174
175
void
176
linear
(
Home
home,
177
const
FloatValArgs
&
a
,
const
FloatVarArgs
&
x
,
FloatRelType
frt,
178
FloatVar
y
,
Reify
r
) {
179
using namespace
Float;
180
if
(
a
.size() !=
x
.size())
181
throw
ArgumentSizeMismatch
(
"Float::linear"
);
182
GECODE_POST
;
183
Region
re;
184
Linear::Term
*
t
= re.
alloc
<
Linear::Term
>(
x
.size()+1);
185
for
(
int
i
=
x
.size();
i
--; ) {
186
t
[
i
].a=
a
[
i
];
t
[
i
].x=
x
[
i
];
187
}
188
t
[
x
.size()].a=-1.0;
t
[
x
.size()].x=
y
;
189
Linear::post
(home,
t
,
x
.size()+1,frt,0.0,
r
);
190
}
191
192
}
193
194
// STATISTICS: float-post
Gecode::FRT_LE
@ FRT_LE
Less ( )
Definition:
float.hh:1072
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::y
Post propagator for SetVar SetOpType SetVar y
Definition:
set.hh:767
Gecode::Int::Linear::Term
Class for describing linear term .
Definition:
linear.hh:1336
Test::Int::Linear::c
Create c
Definition:
linear.cpp:392
Gecode::max
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition:
arithmetic.cpp:49
linear.hh
Gecode::Float::Linear::post
void post(Home home, Term *t, int n, FloatRelType frt, FloatVal c)
Post propagator for linear constraint over floats.
Definition:
post.cpp:238
Gecode::Region::alloc
T * alloc(long unsigned int n)
Allocate block of n objects of type T from region.
Definition:
region.hpp:386
t
NodeType t
Type of node.
Definition:
bool-expr.cpp:230
Gecode::FloatValArgs
Passing float arguments.
Definition:
float.hh:950
Gecode::FRT_GR
@ FRT_GR
Greater ( )
Definition:
float.hh:1074
Gecode::FloatRelType
FloatRelType
Relation types for floats.
Definition:
float.hh:1068
Gecode
Gecode toplevel namespace
Gecode::Reify
Reification specification.
Definition:
int.hh:876
Gecode::Home
Home class for posting propagators
Definition:
core.hpp:856
Gecode::Region
Handle to region.
Definition:
region.hpp:55
Gecode::Float::Linear::estimate
void estimate(Term *t, int n, FloatVal c, FloatNum &l, FloatNum &u)
Estimate lower and upper bounds.
Definition:
post.cpp:45
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::FRT_LQ
@ FRT_LQ
Less or equal ( )
Definition:
float.hh:1071
a
struct Gecode::@602::NNF::@65::@67 a
For atomic nodes.
Gecode::linear
void linear(Home home, const FloatVarArgs &x, FloatRelType frt, FloatVal c)
Post propagator for .
Definition:
linear.cpp:41
Gecode::Home::failed
bool failed(void) const
Check whether corresponding space is failed.
Definition:
core.hpp:4048
Gecode::FRT_EQ
@ FRT_EQ
Equality ( )
Definition:
float.hh:1069
Gecode::FloatVal
Float value type.
Definition:
float.hh:334
Test::Int::Distinct::v
const int v[7]
Definition:
distinct.cpp:259
Gecode::FloatVar
Float variables.
Definition:
float.hh:870
Gecode::FRT_GQ
@ FRT_GQ
Greater or equal ( )
Definition:
float.hh:1073
GECODE_POST
#define GECODE_POST
Check for failure in a constraint post function.
Definition:
macros.hpp:40
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
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})