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
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
* Last modified:
12
* $Date: 2017-04-04 16:15:44 +0200 (Tue, 04 Apr 2017) $ by $Author: schulte $
13
* $Revision: 15627 $
14
*
15
* This file is part of Gecode, the generic constraint
16
* development environment:
17
* http://www.gecode.org
18
*
19
* Permission is hereby granted, free of charge, to any person obtaining
20
* a copy of this software and associated documentation files (the
21
* "Software"), to deal in the Software without restriction, including
22
* without limitation the rights to use, copy, modify, merge, publish,
23
* distribute, sublicense, and/or sell copies of the Software, and to
24
* permit persons to whom the Software is furnished to do so, subject to
25
* the following conditions:
26
*
27
* The above copyright notice and this permission notice shall be
28
* included in all copies or substantial portions of the Software.
29
*
30
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37
*
38
*/
39
40
#include <
gecode/float/linear.hh
>
41
42
namespace
Gecode
{
43
44
void
45
linear
(
Home
home,
46
const
FloatVarArgs
&
x
,
FloatRelType
frt,
FloatVal
c
) {
47
using namespace
Float;
48
GECODE_POST
;
49
Region
re(home);
50
Linear::Term
*
t
= re.
alloc
<
Linear::Term
>(
x
.size());
51
for
(
int
i
=
x
.size();
i
--; ) {
52
t
[
i
].a=1.0;
t
[
i
].x=
x
[
i
];
53
}
54
Linear::post
(home,
t
,
x
.size(),frt,
c
);
55
}
56
57
void
58
linear
(
Home
home,
59
const
FloatVarArgs
&
x
,
FloatRelType
frt,
FloatVal
c
,
Reify
r
) {
60
using namespace
Float;
61
GECODE_POST
;
62
Region
re(home);
63
Linear::Term
*
t
= re.
alloc
<
Linear::Term
>(
x
.size());
64
for
(
int
i
=
x
.size();
i
--; ) {
65
t
[
i
].a=1.0;
t
[
i
].x=
x
[
i
];
66
}
67
Linear::post
(home,
t
,
x
.size(),frt,
c
,
r
);
68
}
69
70
void
71
linear
(
Home
home,
72
const
FloatValArgs
&
a
,
const
FloatVarArgs
&
x
,
FloatRelType
frt,
73
FloatVal
c
) {
74
using namespace
Float;
75
if
(
a
.size() !=
x
.size())
76
throw
ArgumentSizeMismatch
(
"Float::linear"
);
77
GECODE_POST
;
78
Region
re(home);
79
Linear::Term
*
t
= re.
alloc
<
Linear::Term
>(
x
.size());
80
for
(
int
i
=
x
.size();
i
--; ) {
81
t
[
i
].a=
a
[
i
];
t
[
i
].x=
x
[
i
];
82
}
83
Linear::post
(home,
t
,
x
.size(),frt,
c
);
84
}
85
86
void
87
linear
(
Home
home,
88
const
FloatValArgs
&
a
,
const
FloatVarArgs
&
x
,
FloatRelType
frt,
89
FloatVal
c
,
Reify
r
) {
90
using namespace
Float;
91
if
(
a
.size() !=
x
.size())
92
throw
ArgumentSizeMismatch
(
"Float::linear"
);
93
GECODE_POST
;
94
Region
re(home);
95
Linear::Term
*
t
= re.
alloc
<
Linear::Term
>(
x
.size());
96
for
(
int
i
=
x
.size();
i
--; ) {
97
t
[
i
].a=
a
[
i
];
t
[
i
].x=
x
[
i
];
98
}
99
Linear::post
(home,
t
,
x
.size(),frt,
c
,
r
);
100
}
101
102
void
103
linear
(
Home
home,
104
const
FloatVarArgs
&
x
,
FloatRelType
frt,
FloatVar
y
) {
105
using namespace
Float;
106
GECODE_POST
;
107
Region
re(home);
108
Linear::Term
*
t
= re.
alloc
<
Linear::Term
>(
x
.size()+1);
109
for
(
int
i
=
x
.size();
i
--; ) {
110
t
[
i
].a=1.0;
t
[
i
].x=
x
[
i
];
111
}
112
FloatNum
min
,
max
;
113
estimate
(
t
,
x
.size(),0.0,
min
,
max
);
114
FloatView
v
(
y
);
115
switch
(frt) {
116
case
FRT_EQ
:
117
GECODE_ME_FAIL
(
v
.gq(home,
min
));
GECODE_ME_FAIL
(
v
.lq(home,
max
));
118
break
;
119
case
FRT_GQ
:
case
FRT_GR
:
120
GECODE_ME_FAIL
(
v
.lq(home,
max
));
121
break
;
122
case
FRT_LQ
:
case
FRT_LE
:
123
GECODE_ME_FAIL
(
v
.gq(home,
min
));
124
break
;
125
default
: ;
126
}
127
if
(home.
failed
())
return
;
128
t
[
x
.size()].a=-1.0;
t
[
x
.size()].x=
y
;
129
Linear::post
(home,
t
,
x
.size()+1,frt,0.0);
130
}
131
132
void
133
linear
(
Home
home,
134
const
FloatVarArgs
&
x
,
FloatRelType
frt,
FloatVar
y
,
Reify
r
) {
135
using namespace
Float;
136
GECODE_POST
;
137
Region
re(home);
138
Linear::Term
*
t
= re.
alloc
<
Linear::Term
>(
x
.size()+1);
139
for
(
int
i
=
x
.size();
i
--; ) {
140
t
[
i
].a=1.0;
t
[
i
].x=
x
[
i
];
141
}
142
t
[
x
.size()].a=-1;
t
[
x
.size()].x=
y
;
143
Linear::post
(home,
t
,
x
.size()+1,frt,0.0,
r
);
144
}
145
146
void
147
linear
(
Home
home,
148
const
FloatValArgs
&
a
,
const
FloatVarArgs
&
x
,
FloatRelType
frt,
149
FloatVar
y
) {
150
using namespace
Float;
151
if
(
a
.size() !=
x
.size())
152
throw
ArgumentSizeMismatch
(
"Float::linear"
);
153
GECODE_POST
;
154
Region
re(home);
155
Linear::Term
*
t
= re.
alloc
<
Linear::Term
>(
x
.size()+1);
156
for
(
int
i
=
x
.size();
i
--; ) {
157
t
[
i
].a=
a
[
i
];
t
[
i
].x=
x
[
i
];
158
}
159
FloatNum
min
,
max
;
160
estimate
(
t
,
x
.size(),0.0,
min
,
max
);
161
FloatView
v
(
y
);
162
switch
(frt) {
163
case
FRT_EQ
:
164
GECODE_ME_FAIL
(
v
.gq(home,
min
));
GECODE_ME_FAIL
(
v
.lq(home,
max
));
165
break
;
166
case
FRT_GQ
:
case
FRT_GR
:
167
GECODE_ME_FAIL
(
v
.lq(home,
max
));
168
break
;
169
case
FRT_LQ
:
case
FRT_LE
:
170
GECODE_ME_FAIL
(
v
.gq(home,
min
));
171
break
;
172
default
: ;
173
}
174
if
(home.
failed
())
return
;
175
t
[
x
.size()].a=-1.0;
t
[
x
.size()].x=
y
;
176
Linear::post
(home,
t
,
x
.size()+1,frt,0.0);
177
}
178
179
void
180
linear
(
Home
home,
181
const
FloatValArgs
&
a
,
const
FloatVarArgs
&
x
,
FloatRelType
frt,
182
FloatVar
y
,
Reify
r
) {
183
using namespace
Float;
184
if
(
a
.size() !=
x
.size())
185
throw
ArgumentSizeMismatch
(
"Float::linear"
);
186
GECODE_POST
;
187
Region
re(home);
188
Linear::Term
*
t
= re.
alloc
<
Linear::Term
>(
x
.size()+1);
189
for
(
int
i
=
x
.size();
i
--; ) {
190
t
[
i
].a=
a
[
i
];
t
[
i
].x=
x
[
i
];
191
}
192
t
[
x
.size()].a=-1.0;
t
[
x
.size()].x=
y
;
193
Linear::post
(home,
t
,
x
.size()+1,frt,0.0,
r
);
194
}
195
196
}
197
198
// STATISTICS: float-post
Gecode::FRT_LE
@ FRT_LE
Less ( )
Definition:
float.hh:1073
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::y
Post propagator for SetVar SetOpType SetVar y
Definition:
set.hh:784
Gecode::Int::Linear::Term
Class for describing linear term .
Definition:
linear.hh:1340
Test::Int::Linear::c
Create c
Definition:
linear.cpp:395
Gecode::max
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition:
arithmetic.cpp:53
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:228
Test::Int::Basic::i
Gecode::IntArgs i(4, 1, 2, 3, 4)
Gecode::Region::alloc
T * alloc(long unsigned int n)
Allocate block of n objects of type T from region.
Definition:
region.hpp:326
t
NodeType t
Type of node.
Definition:
bool-expr.cpp:234
Gecode::FloatValArgs
Passing float arguments.
Definition:
float.hh:954
Gecode::FRT_GR
@ FRT_GR
Greater ( )
Definition:
float.hh:1075
Gecode::FloatRelType
FloatRelType
Relation types for floats.
Definition:
float.hh:1069
Gecode
Gecode toplevel namespace
Gecode::Reify
Reification specification.
Definition:
int.hh:857
Gecode::Home
Home class for posting propagators
Definition:
core.hpp:922
a
struct Gecode::@579::NNF::@61::@63 a
For atomic nodes.
Gecode::Region
Handle to region.
Definition:
region.hpp:61
Gecode::Float::Linear::estimate
void estimate(Term *t, int n, FloatVal c, FloatNum &l, FloatNum &u)
Estimate lower and upper bounds.
Definition:
post.cpp:49
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::FRT_LQ
@ FRT_LQ
Less or equal ( )
Definition:
float.hh:1072
Gecode::linear
void linear(Home home, const FloatVarArgs &x, FloatRelType frt, FloatVal c)
Post propagator for .
Definition:
linear.cpp:45
Gecode::Home::failed
bool failed(void) const
Check whether corresponding space is failed.
Definition:
core.hpp:4099
Gecode::FRT_EQ
@ FRT_EQ
Equality ( )
Definition:
float.hh:1070
Gecode::FloatVal
Float value type.
Definition:
float.hh:338
Test::Int::Distinct::v
const int v[7]
Definition:
distinct.cpp:263
Gecode::FloatVar
Float variables.
Definition:
float.hh:874
Gecode::FRT_GQ
@ FRT_GQ
Greater or equal ( )
Definition:
float.hh:1074
GECODE_POST
#define GECODE_POST
Check for failure in a constraint post function.
Definition:
macros.hpp:44
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