main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Oct 22 2013 00:49:00 for Gecode by
doxygen
1.8.4
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: 2013-01-29 17:43:05 +0100 (Tue, 29 Jan 2013) $ by $Author: schulte $
13
* $Revision: 13241 $
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,
FloatNum
c
) {
47
using namespace
Float;
48
if
(home.
failed
())
return
;
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,
FloatNum
c
,
Reify
r
) {
60
using namespace
Float;
61
if
(home.
failed
())
return
;
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
FloatNum
c
) {
74
using namespace
Float;
75
if
(a.
size
() != x.
size
())
76
throw
ArgumentSizeMismatch
(
"Float::linear"
);
77
if
(home.
failed
())
return
;
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
FloatNum
c
,
Reify
r
) {
90
using namespace
Float;
91
if
(a.
size
() != x.
size
())
92
throw
ArgumentSizeMismatch
(
"Float::linear"
);
93
if
(home.
failed
())
return
;
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
if
(home.
failed
())
return
;
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
if
(home.
failed
())
return
;
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
if
(home.
failed
())
return
;
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
if
(home.
failed
())
return
;
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