main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Mar 24 2020 14:04:04 for Gecode by
doxygen
1.8.17
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
* This file is part of Gecode, the generic constraint
10
* development environment:
11
* http://www.gecode.org
12
*
13
* Permission is hereby granted, free of charge, to any person obtaining
14
* a copy of this software and associated documentation files (the
15
* "Software"), to deal in the Software without restriction, including
16
* without limitation the rights to use, copy, modify, merge, publish,
17
* distribute, sublicense, and/or sell copies of the Software, and to
18
* permit persons to whom the Software is furnished to do so, subject to
19
* the following conditions:
20
*
21
* The above copyright notice and this permission notice shall be
22
* included in all copies or substantial portions of the Software.
23
*
24
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
*
32
*/
33
34
#include <
gecode/int/linear.hh
>
35
36
namespace
Gecode
{
37
38
using namespace
Int;
39
40
void
41
linear
(
Home
home,
const
BoolVarArgs
&
x
,
IntRelType
irt,
int
c
,
42
IntPropLevel
ipl) {
43
GECODE_POST
;
44
45
int
n
=
x
.size();
46
Region
re;
47
Linear::Term<BoolView>
*
t
= re.
alloc
<
Linear::Term<BoolView>
>(
n
);
48
for
(
int
i
=0;
i
<
n
;
i
++) {
49
t
[
i
].a=1;
t
[
i
].x=
x
[
i
];
50
}
51
52
Linear::post
(home,
t
,
n
,irt,
c
,ipl);
53
}
54
55
void
56
linear
(
Home
home,
const
BoolVarArgs
&
x
,
IntRelType
irt,
IntVar
y
,
57
IntPropLevel
ipl) {
58
GECODE_POST
;
59
60
int
n
=
x
.size();
61
Region
re;
62
Linear::Term<BoolView>
*
t
= re.
alloc
<
Linear::Term<BoolView>
>(
n
);
63
for
(
int
i
=0;
i
<
n
;
i
++) {
64
t
[
i
].a=1;
t
[
i
].x=
x
[
i
];
65
}
66
67
Linear::post
(home,
t
,
n
,irt,
y
,0,ipl);
68
}
69
70
void
71
linear
(
Home
home,
72
const
IntArgs
&
a
,
const
BoolVarArgs
&
x
,
IntRelType
irt,
int
c
,
73
IntPropLevel
ipl) {
74
if
(
a
.size() !=
x
.size())
75
throw
ArgumentSizeMismatch
(
"Int::linear"
);
76
77
GECODE_POST
;
78
79
int
n
=
x
.size();
80
Region
re;
81
Linear::Term<BoolView>
*
t
= re.
alloc
<
Linear::Term<BoolView>
>(
n
);
82
for
(
int
i
=0;
i
<
n
;
i
++) {
83
t
[
i
].a=
a
[
i
];
t
[
i
].x=
x
[
i
];
84
}
85
86
Linear::post
(home,
t
,
n
,irt,
c
,ipl);
87
}
88
89
void
90
linear
(
Home
home,
91
const
IntArgs
&
a
,
const
BoolVarArgs
&
x
,
IntRelType
irt,
IntVar
y
,
92
IntPropLevel
ipl) {
93
if
(
a
.size() !=
x
.size())
94
throw
ArgumentSizeMismatch
(
"Int::linear"
);
95
96
GECODE_POST
;
97
98
int
n
=
x
.size();
99
Region
re;
100
Linear::Term<BoolView>
*
t
=
101
re.
alloc
<
Linear::Term<BoolView>
>(
n
);
102
for
(
int
i
=0;
i
<
n
;
i
++) {
103
t
[
i
].a=
a
[
i
];
t
[
i
].x=
x
[
i
];
104
}
105
int
min
,
max
;
106
estimate
(
t
,
n
,0,
min
,
max
);
107
IntView
v
(
y
);
108
switch
(irt) {
109
case
IRT_EQ
:
110
GECODE_ME_FAIL
(
v
.gq(home,
min
));
GECODE_ME_FAIL
(
v
.lq(home,
max
));
111
break
;
112
case
IRT_GQ
:
113
GECODE_ME_FAIL
(
v
.lq(home,
max
));
114
break
;
115
case
IRT_LQ
:
116
GECODE_ME_FAIL
(
v
.gq(home,
min
));
117
break
;
118
default
: ;
119
}
120
if
(home.
failed
())
return
;
121
Linear::post
(home,
t
,
n
,irt,
y
,0,ipl);
122
}
123
124
void
125
linear
(
Home
home,
const
BoolVarArgs
&
x
,
IntRelType
irt,
int
c
,
126
Reify
r
,
IntPropLevel
ipl) {
127
GECODE_POST
;
128
129
int
n
=
x
.size();
130
Region
re;
131
Linear::Term<BoolView>
*
t
= re.
alloc
<
Linear::Term<BoolView>
>(
n
);
132
for
(
int
i
=0;
i
<
n
;
i
++) {
133
t
[
i
].a=1;
t
[
i
].x=
x
[
i
];
134
}
135
136
Linear::post
(home,
t
,
n
,irt,
c
,
r
,ipl);
137
}
138
139
void
140
linear
(
Home
home,
const
BoolVarArgs
&
x
,
IntRelType
irt,
IntVar
y
,
141
Reify
r
,
IntPropLevel
ipl) {
142
GECODE_POST
;
143
144
int
n
=
x
.size();
145
Region
re;
146
Linear::Term<BoolView>
*
t
= re.
alloc
<
Linear::Term<BoolView>
>(
n
);
147
for
(
int
i
=0;
i
<
n
;
i
++) {
148
t
[
i
].a=1;
t
[
i
].x=
x
[
i
];
149
}
150
151
Linear::post
(home,
t
,
n
,irt,
y
,
r
,ipl);
152
}
153
154
void
155
linear
(
Home
home,
156
const
IntArgs
&
a
,
const
BoolVarArgs
&
x
,
IntRelType
irt,
int
c
,
157
Reify
r
,
IntPropLevel
ipl) {
158
if
(
a
.size() !=
x
.size())
159
throw
ArgumentSizeMismatch
(
"Int::linear"
);
160
GECODE_POST
;
161
162
int
n
=
x
.size();
163
Region
re;
164
Linear::Term<BoolView>
*
t
= re.
alloc
<
Linear::Term<BoolView>
>(
n
);
165
for
(
int
i
=0;
i
<
n
;
i
++) {
166
t
[
i
].a=
a
[
i
];
t
[
i
].x=
x
[
i
];
167
}
168
169
Linear::post
(home,
t
,
n
,irt,
c
,
r
,ipl);
170
}
171
172
void
173
linear
(
Home
home,
174
const
IntArgs
&
a
,
const
BoolVarArgs
&
x
,
IntRelType
irt,
IntVar
y
,
175
Reify
r
,
IntPropLevel
ipl) {
176
if
(
a
.size() !=
x
.size())
177
throw
ArgumentSizeMismatch
(
"Int::linear"
);
178
GECODE_POST
;
179
180
int
n
=
x
.size();
181
Region
re;
182
Linear::Term<BoolView>
*
t
= re.
alloc
<
Linear::Term<BoolView>
>(
n
);
183
for
(
int
i
=0;
i
<
n
;
i
++) {
184
t
[
i
].a=
a
[
i
];
t
[
i
].x=
x
[
i
];
185
}
186
187
Linear::post
(home,
t
,
n
,irt,
y
,
r
,ipl);
188
}
189
190
}
191
192
// STATISTICS: int-post
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::IntRelType
IntRelType
Relation types for integers.
Definition:
int.hh:925
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
Gecode::max
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition:
arithmetic.cpp:49
Gecode::IRT_GQ
@ IRT_GQ
Greater or equal ( )
Definition:
int.hh:930
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
linear.hh
Gecode::IntPropLevel
IntPropLevel
Propagation levels for integer propagators.
Definition:
int.hh:974
Gecode
Gecode toplevel namespace
Gecode::Reify
Reification specification.
Definition:
int.hh:876
Gecode::BoolVarArgs
Passing Boolean variables.
Definition:
int.hh:712
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::IntVar
Integer variables.
Definition:
int.hh:371
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
Test::Int::Distinct::v
const int v[7]
Definition:
distinct.cpp:259
GECODE_POST
#define GECODE_POST
Check for failure in a constraint post function.
Definition:
macros.hpp:40
Gecode::Int::IntView
Integer view for integer variables.
Definition:
view.hpp:129
GECODE_ME_FAIL
#define GECODE_ME_FAIL(me)
Check whether modification event me is failed, and fail space home.
Definition:
macros.hpp:77
Gecode::IRT_EQ
@ IRT_EQ
Equality ( )
Definition:
int.hh:926
Gecode::Int::Linear::post
void post(Home home, Term< BoolView > *t, int n, IntRelType irt, IntView x, int c, IntPropLevel)
Post propagator for linear constraint over Booleans.
Definition:
bool-post.cpp:589
Gecode::min
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition:
arithmetic.cpp:67
Test::Float::Arithmetic::c
Gecode::FloatVal c(-8, 8)
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:234
Gecode::IntArgs
Passing integer arguments.
Definition:
int.hh:628
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})
Gecode::IRT_LQ
@ IRT_LQ
Less or equal ( )
Definition:
int.hh:928