main page
modules
namespaces
classes
files
Gecode home
Generated on Sat Aug 25 2012 03:32:48 for Gecode by
doxygen
1.8.1.2
gecode
int
linear-bool.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, 2006
8
*
9
* Last modified:
10
* $Date: 2010-03-04 03:40:32 +1100 (Thu, 04 Mar 2010) $ by $Author: schulte $
11
* $Revision: 10365 $
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
#include <
gecode/int/linear.hh
>
39
40
namespace
Gecode {
41
42
using namespace
Int;
43
44
void
45
linear
(
Home
home,
const
BoolVarArgs
& x,
IntRelType
r
,
int
c
,
46
IntConLevel
icl) {
47
if
(home.
failed
())
return
;
48
49
int
n=x.
size
();
50
Region
re(home);
51
Linear::Term<BoolView>
* t = re.
alloc
<
Linear::Term<BoolView>
>(n);
52
for
(
int
i
=n;
i
--; ) {
53
t[
i
].
a
=1; t[
i
].
x
=x[
i
];
54
}
55
56
Linear::post
(home,t,n,r,c,icl);
57
}
58
59
void
60
linear
(
Home
home,
const
BoolVarArgs
& x,
IntRelType
r
,
IntVar
y,
61
IntConLevel
icl) {
62
if
(home.
failed
())
return
;
63
64
int
n=x.
size
();
65
Region
re(home);
66
Linear::Term<BoolView>
* t = re.
alloc
<
Linear::Term<BoolView>
>(n);
67
for
(
int
i
=n;
i
--; ) {
68
t[
i
].
a
=1; t[
i
].
x
=x[
i
];
69
}
70
71
Linear::post
(home,t,n,r,y,0,icl);
72
}
73
74
void
75
linear
(
Home
home,
76
const
IntArgs
&
a
,
const
BoolVarArgs
& x,
IntRelType
r
,
int
c
,
77
IntConLevel
icl) {
78
if
(a.
size
() != x.
size
())
79
throw
ArgumentSizeMismatch
(
"Int::linear"
);
80
if
(home.
failed
())
81
return
;
82
83
int
n=x.
size
();
84
Region
re(home);
85
Linear::Term<BoolView>
* t = re.
alloc
<
Linear::Term<BoolView>
>(n);
86
for
(
int
i
=n;
i
--; ) {
87
t[
i
].
a
=a[
i
]; t[
i
].
x
=x[
i
];
88
}
89
90
Linear::post
(home,t,n,r,c,icl);
91
}
92
93
void
94
linear
(
Home
home,
95
const
IntArgs
&
a
,
const
BoolVarArgs
& x,
IntRelType
r
,
IntVar
y,
96
IntConLevel
icl) {
97
if
(a.
size
() != x.
size
())
98
throw
ArgumentSizeMismatch
(
"Int::linear"
);
99
if
(home.
failed
())
100
return
;
101
102
int
n=x.
size
();
103
Region
re(home);
104
Linear::Term<BoolView>
* t =
105
re.
alloc
<
Linear::Term<BoolView>
>(n);
106
for
(
int
i
=n;
i
--; ) {
107
t[
i
].
a
=a[
i
]; t[
i
].
x
=x[
i
];
108
}
109
int
min
,
max
;
110
estimate
(t,n,0,min,max);
111
IntView
v
(y);
112
switch
(r) {
113
case
IRT_EQ
:
114
GECODE_ME_FAIL
(v.
gq
(home,min));
GECODE_ME_FAIL
(v.
lq
(home,max));
115
break
;
116
case
IRT_GQ
:
117
GECODE_ME_FAIL
(v.
lq
(home,max));
118
break
;
119
case
IRT_LQ
:
120
GECODE_ME_FAIL
(v.
gq
(home,min));
121
break
;
122
default
: ;
123
}
124
if
(home.
failed
())
return
;
125
Linear::post
(home,t,n,r,y,0,icl);
126
}
127
128
void
129
linear
(
Home
home,
const
BoolVarArgs
& x,
IntRelType
r
,
int
c
,
130
BoolVar
b
,
IntConLevel
icl) {
131
if
(home.
failed
())
return
;
132
133
int
n=x.
size
();
134
Region
re(home);
135
Linear::Term<BoolView>
* t = re.
alloc
<
Linear::Term<BoolView>
>(n);
136
for
(
int
i
=n;
i
--; ) {
137
t[
i
].
a
=1; t[
i
].
x
=x[
i
];
138
}
139
140
Linear::post
(home,t,n,r,c,b,icl);
141
}
142
143
void
144
linear
(
Home
home,
const
BoolVarArgs
& x,
IntRelType
r
,
IntVar
y,
145
BoolVar
b
,
IntConLevel
icl) {
146
if
(home.
failed
())
return
;
147
148
int
n=x.
size
();
149
Region
re(home);
150
Linear::Term<BoolView>
* t = re.
alloc
<
Linear::Term<BoolView>
>(n);
151
for
(
int
i
=n;
i
--; ) {
152
t[
i
].
a
=1; t[
i
].
x
=x[
i
];
153
}
154
155
Linear::post
(home,t,n,r,y,b,icl);
156
}
157
158
void
159
linear
(
Home
home,
160
const
IntArgs
&
a
,
const
BoolVarArgs
& x,
IntRelType
r
,
int
c
,
161
BoolVar
b
,
IntConLevel
icl) {
162
if
(a.
size
() != x.
size
())
163
throw
ArgumentSizeMismatch
(
"Int::linear"
);
164
if
(home.
failed
())
return
;
165
166
int
n=x.
size
();
167
Region
re(home);
168
Linear::Term<BoolView>
* t = re.
alloc
<
Linear::Term<BoolView>
>(n);
169
for
(
int
i
=n;
i
--; ) {
170
t[
i
].
a
=a[
i
]; t[
i
].
x
=x[
i
];
171
}
172
173
Linear::post
(home,t,n,r,c,b,icl);
174
}
175
176
void
177
linear
(
Home
home,
178
const
IntArgs
&
a
,
const
BoolVarArgs
& x,
IntRelType
r
,
IntVar
y,
179
BoolVar
b
,
IntConLevel
icl) {
180
if
(a.
size
() != x.
size
())
181
throw
ArgumentSizeMismatch
(
"Int::linear"
);
182
if
(home.
failed
())
return
;
183
184
int
n=x.
size
();
185
Region
re(home);
186
Linear::Term<BoolView>
* t = re.
alloc
<
Linear::Term<BoolView>
>(n);
187
for
(
int
i
=n;
i
--; ) {
188
t[
i
].
a
=a[
i
]; t[
i
].
x
=x[
i
];
189
}
190
191
Linear::post
(home,t,n,r,y,b,icl);
192
}
193
194
}
195
196
// STATISTICS: int-post