main page
modules
namespaces
classes
files
Gecode home
Generated on Sun Aug 9 2020 05:34:08 for Gecode by
doxygen
1.8.18
gecode
int
linear-int.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, 2002
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,
42
const
IntVarArgs
&
x
,
IntRelType
irt,
int
c
,
43
IntPropLevel
ipl) {
44
GECODE_POST
;
45
Region
re;
46
Linear::Term<IntView>
*
t
= re.
alloc
<
Linear::Term<IntView>
>(
x
.size());
47
for
(
int
i
=0;
i
<
x
.size();
i
++) {
48
t
[
i
].a=1;
t
[
i
].x=
x
[
i
];
49
}
50
Linear::post
(home,
t
,
x
.size(),irt,
c
,ipl);
51
}
52
53
void
54
linear
(
Home
home,
55
const
IntVarArgs
&
x
,
IntRelType
irt,
int
c
,
Reify
r
,
56
IntPropLevel
) {
57
GECODE_POST
;
58
Region
re;
59
Linear::Term<IntView>
*
t
= re.
alloc
<
Linear::Term<IntView>
>(
x
.size());
60
for
(
int
i
=0;
i
<
x
.size();
i
++) {
61
t
[
i
].a=1;
t
[
i
].x=
x
[
i
];
62
}
63
Linear::post
(home,
t
,
x
.size(),irt,
c
,
r
);
64
}
65
66
void
67
linear
(
Home
home,
68
const
IntArgs
&
a
,
const
IntVarArgs
&
x
,
IntRelType
irt,
int
c
,
69
IntPropLevel
ipl) {
70
if
(
a
.size() !=
x
.size())
71
throw
ArgumentSizeMismatch
(
"Int::linear"
);
72
GECODE_POST
;
73
Region
re;
74
Linear::Term<IntView>
*
t
= re.
alloc
<
Linear::Term<IntView>
>(
x
.size());
75
for
(
int
i
=0;
i
<
x
.size();
i
++) {
76
t
[
i
].a=
a
[
i
];
t
[
i
].x=
x
[
i
];
77
}
78
Linear::post
(home,
t
,
x
.size(),irt,
c
,ipl);
79
}
80
81
void
82
linear
(
Home
home,
83
const
IntArgs
&
a
,
const
IntVarArgs
&
x
,
IntRelType
irt,
int
c
,
84
Reify
r
,
IntPropLevel
) {
85
if
(
a
.size() !=
x
.size())
86
throw
ArgumentSizeMismatch
(
"Int::linear"
);
87
GECODE_POST
;
88
Region
re;
89
Linear::Term<IntView>
*
t
= re.
alloc
<
Linear::Term<IntView>
>(
x
.size());
90
for
(
int
i
=0;
i
<
x
.size();
i
++) {
91
t
[
i
].a=
a
[
i
];
t
[
i
].x=
x
[
i
];
92
}
93
Linear::post
(home,
t
,
x
.size(),irt,
c
,
r
);
94
}
95
96
void
97
linear
(
Home
home,
98
const
IntVarArgs
&
x
,
IntRelType
irt,
IntVar
y
,
99
IntPropLevel
ipl) {
100
GECODE_POST
;
101
Region
re;
102
Linear::Term<IntView>
*
t
= re.
alloc
<
Linear::Term<IntView>
>(
x
.size()+1);
103
for
(
int
i
=0;
i
<
x
.size();
i
++) {
104
t
[
i
].a=1;
t
[
i
].x=
x
[
i
];
105
}
106
int
min
,
max
;
107
estimate
(
t
,
x
.size(),0,
min
,
max
);
108
IntView
v
(
y
);
109
switch
(irt) {
110
case
IRT_EQ
:
111
GECODE_ME_FAIL
(
v
.gq(home,
min
));
GECODE_ME_FAIL
(
v
.lq(home,
max
));
112
break
;
113
case
IRT_GQ
:
114
GECODE_ME_FAIL
(
v
.lq(home,
max
));
115
break
;
116
case
IRT_LQ
:
117
GECODE_ME_FAIL
(
v
.gq(home,
min
));
118
break
;
119
default
: ;
120
}
121
if
(home.
failed
())
return
;
122
t
[
x
.size()].a=-1;
t
[
x
.size()].x=
y
;
123
Linear::post
(home,
t
,
x
.size()+1,irt,0,ipl);
124
}
125
126
void
127
linear
(
Home
home,
128
const
IntVarArgs
&
x
,
IntRelType
irt,
IntVar
y
,
Reify
r
,
129
IntPropLevel
) {
130
GECODE_POST
;
131
Region
re;
132
Linear::Term<IntView>
*
t
= re.
alloc
<
Linear::Term<IntView>
>(
x
.size()+1);
133
for
(
int
i
=0;
i
<
x
.size();
i
++) {
134
t
[
i
].a=1;
t
[
i
].x=
x
[
i
];
135
}
136
t
[
x
.size()].a=-1;
t
[
x
.size()].x=
y
;
137
Linear::post
(home,
t
,
x
.size()+1,irt,0,
r
);
138
}
139
140
void
141
linear
(
Home
home,
142
const
IntArgs
&
a
,
const
IntVarArgs
&
x
,
IntRelType
irt,
IntVar
y
,
143
IntPropLevel
ipl) {
144
if
(
a
.size() !=
x
.size())
145
throw
ArgumentSizeMismatch
(
"Int::linear"
);
146
GECODE_POST
;
147
Region
re;
148
Linear::Term<IntView>
*
t
= re.
alloc
<
Linear::Term<IntView>
>(
x
.size()+1);
149
for
(
int
i
=0;
i
<
x
.size();
i
++) {
150
t
[
i
].a=
a
[
i
];
t
[
i
].x=
x
[
i
];
151
}
152
int
min
,
max
;
153
estimate
(
t
,
x
.size(),0,
min
,
max
);
154
IntView
v
(
y
);
155
switch
(irt) {
156
case
IRT_EQ
:
157
GECODE_ME_FAIL
(
v
.gq(home,
min
));
GECODE_ME_FAIL
(
v
.lq(home,
max
));
158
break
;
159
case
IRT_GQ
:
160
GECODE_ME_FAIL
(
v
.lq(home,
max
));
161
break
;
162
case
IRT_LQ
:
163
GECODE_ME_FAIL
(
v
.gq(home,
min
));
164
break
;
165
default
: ;
166
}
167
if
(home.
failed
())
return
;
168
t
[
x
.size()].a=-1;
t
[
x
.size()].x=
y
;
169
Linear::post
(home,
t
,
x
.size()+1,irt,0,ipl);
170
}
171
172
void
173
linear
(
Home
home,
174
const
IntArgs
&
a
,
const
IntVarArgs
&
x
,
IntRelType
irt,
IntVar
y
,
175
Reify
r
,
IntPropLevel
) {
176
if
(
a
.size() !=
x
.size())
177
throw
ArgumentSizeMismatch
(
"Int::linear"
);
178
GECODE_POST
;
179
Region
re;
180
Linear::Term<IntView>
*
t
= re.
alloc
<
Linear::Term<IntView>
>(
x
.size()+1);
181
for
(
int
i
=0;
i
<
x
.size();
i
++) {
182
t
[
i
].a=
a
[
i
];
t
[
i
].x=
x
[
i
];
183
}
184
t
[
x
.size()].a=-1;
t
[
x
.size()].x=
y
;
185
Linear::post
(home,
t
,
x
.size()+1,irt,0,
r
);
186
}
187
188
}
189
190
// 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::IntVarArgs
Passing integer variables.
Definition:
int.hh:656
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::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)
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