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
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
* Last modified:
10
* $Date: 2016-05-23 22:18:23 +0200 (Mon, 23 May 2016) $ by $Author: schulte $
11
* $Revision: 15073 $
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,
46
const
IntVarArgs
&
x
,
IntRelType
irt,
int
c
,
47
IntPropLevel
ipl) {
48
GECODE_POST
;
49
Region
re(home);
50
Linear::Term<IntView>
*
t
= re.
alloc
<
Linear::Term<IntView>
>(
x
.size());
51
for
(
int
i
=
x
.size();
i
--; ) {
52
t
[
i
].a=1;
t
[
i
].x=
x
[
i
];
53
}
54
Linear::post
(home,
t
,
x
.size(),irt,
c
,ipl);
55
}
56
57
void
58
linear
(
Home
home,
59
const
IntVarArgs
&
x
,
IntRelType
irt,
int
c
,
Reify
r
,
60
IntPropLevel
) {
61
GECODE_POST
;
62
Region
re(home);
63
Linear::Term<IntView>
*
t
= re.
alloc
<
Linear::Term<IntView>
>(
x
.size());
64
for
(
int
i
=
x
.size();
i
--; ) {
65
t
[
i
].a=1;
t
[
i
].x=
x
[
i
];
66
}
67
Linear::post
(home,
t
,
x
.size(),irt,
c
,
r
);
68
}
69
70
void
71
linear
(
Home
home,
72
const
IntArgs
&
a
,
const
IntVarArgs
&
x
,
IntRelType
irt,
int
c
,
73
IntPropLevel
ipl) {
74
if
(
a
.size() !=
x
.size())
75
throw
ArgumentSizeMismatch
(
"Int::linear"
);
76
GECODE_POST
;
77
Region
re(home);
78
Linear::Term<IntView>
*
t
= re.
alloc
<
Linear::Term<IntView>
>(
x
.size());
79
for
(
int
i
=
x
.size();
i
--; ) {
80
t
[
i
].a=
a
[
i
];
t
[
i
].x=
x
[
i
];
81
}
82
Linear::post
(home,
t
,
x
.size(),irt,
c
,ipl);
83
}
84
85
void
86
linear
(
Home
home,
87
const
IntArgs
&
a
,
const
IntVarArgs
&
x
,
IntRelType
irt,
int
c
,
88
Reify
r
,
IntPropLevel
) {
89
if
(
a
.size() !=
x
.size())
90
throw
ArgumentSizeMismatch
(
"Int::linear"
);
91
GECODE_POST
;
92
Region
re(home);
93
Linear::Term<IntView>
*
t
= re.
alloc
<
Linear::Term<IntView>
>(
x
.size());
94
for
(
int
i
=
x
.size();
i
--; ) {
95
t
[
i
].a=
a
[
i
];
t
[
i
].x=
x
[
i
];
96
}
97
Linear::post
(home,
t
,
x
.size(),irt,
c
,
r
);
98
}
99
100
void
101
linear
(
Home
home,
102
const
IntVarArgs
&
x
,
IntRelType
irt,
IntVar
y
,
103
IntPropLevel
ipl) {
104
GECODE_POST
;
105
Region
re(home);
106
Linear::Term<IntView>
*
t
= re.
alloc
<
Linear::Term<IntView>
>(
x
.size()+1);
107
for
(
int
i
=
x
.size();
i
--; ) {
108
t
[
i
].a=1;
t
[
i
].x=
x
[
i
];
109
}
110
int
min
,
max
;
111
estimate
(
t
,
x
.size(),0,
min
,
max
);
112
IntView
v
(
y
);
113
switch
(irt) {
114
case
IRT_EQ
:
115
GECODE_ME_FAIL
(
v
.gq(home,
min
));
GECODE_ME_FAIL
(
v
.lq(home,
max
));
116
break
;
117
case
IRT_GQ
:
118
GECODE_ME_FAIL
(
v
.lq(home,
max
));
119
break
;
120
case
IRT_LQ
:
121
GECODE_ME_FAIL
(
v
.gq(home,
min
));
122
break
;
123
default
: ;
124
}
125
if
(home.
failed
())
return
;
126
t
[
x
.size()].a=-1;
t
[
x
.size()].x=
y
;
127
Linear::post
(home,
t
,
x
.size()+1,irt,0,ipl);
128
}
129
130
void
131
linear
(
Home
home,
132
const
IntVarArgs
&
x
,
IntRelType
irt,
IntVar
y
,
Reify
r
,
133
IntPropLevel
) {
134
GECODE_POST
;
135
Region
re(home);
136
Linear::Term<IntView>
*
t
= re.
alloc
<
Linear::Term<IntView>
>(
x
.size()+1);
137
for
(
int
i
=
x
.size();
i
--; ) {
138
t
[
i
].a=1;
t
[
i
].x=
x
[
i
];
139
}
140
t
[
x
.size()].a=-1;
t
[
x
.size()].x=
y
;
141
Linear::post
(home,
t
,
x
.size()+1,irt,0,
r
);
142
}
143
144
void
145
linear
(
Home
home,
146
const
IntArgs
&
a
,
const
IntVarArgs
&
x
,
IntRelType
irt,
IntVar
y
,
147
IntPropLevel
ipl) {
148
if
(
a
.size() !=
x
.size())
149
throw
ArgumentSizeMismatch
(
"Int::linear"
);
150
GECODE_POST
;
151
Region
re(home);
152
Linear::Term<IntView>
*
t
= re.
alloc
<
Linear::Term<IntView>
>(
x
.size()+1);
153
for
(
int
i
=
x
.size();
i
--; ) {
154
t
[
i
].a=
a
[
i
];
t
[
i
].x=
x
[
i
];
155
}
156
int
min
,
max
;
157
estimate
(
t
,
x
.size(),0,
min
,
max
);
158
IntView
v
(
y
);
159
switch
(irt) {
160
case
IRT_EQ
:
161
GECODE_ME_FAIL
(
v
.gq(home,
min
));
GECODE_ME_FAIL
(
v
.lq(home,
max
));
162
break
;
163
case
IRT_GQ
:
164
GECODE_ME_FAIL
(
v
.lq(home,
max
));
165
break
;
166
case
IRT_LQ
:
167
GECODE_ME_FAIL
(
v
.gq(home,
min
));
168
break
;
169
default
: ;
170
}
171
if
(home.
failed
())
return
;
172
t
[
x
.size()].a=-1;
t
[
x
.size()].x=
y
;
173
Linear::post
(home,
t
,
x
.size()+1,irt,0,ipl);
174
}
175
176
void
177
linear
(
Home
home,
178
const
IntArgs
&
a
,
const
IntVarArgs
&
x
,
IntRelType
irt,
IntVar
y
,
179
Reify
r
,
IntPropLevel
) {
180
if
(
a
.size() !=
x
.size())
181
throw
ArgumentSizeMismatch
(
"Int::linear"
);
182
GECODE_POST
;
183
Region
re(home);
184
Linear::Term<IntView>
*
t
= re.
alloc
<
Linear::Term<IntView>
>(
x
.size()+1);
185
for
(
int
i
=
x
.size();
i
--; ) {
186
t
[
i
].a=
a
[
i
];
t
[
i
].x=
x
[
i
];
187
}
188
t
[
x
.size()].a=-1;
t
[
x
.size()].x=
y
;
189
Linear::post
(home,
t
,
x
.size()+1,irt,0,
r
);
190
}
191
192
}
193
194
// STATISTICS: int-post
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::IntRelType
IntRelType
Relation types for integers.
Definition:
int.hh:906
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
Gecode::max
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition:
arithmetic.cpp:53
Gecode::IRT_GQ
@ IRT_GQ
Greater or equal ( )
Definition:
int.hh:911
Gecode::IntVarArgs
Passing integer variables.
Definition:
int.hh:639
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
linear.hh
Gecode::IntPropLevel
IntPropLevel
Propagation levels for integer propagators.
Definition:
int.hh:955
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::IntVar
Integer variables.
Definition:
int.hh:353
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
Test::Int::Distinct::v
const int v[7]
Definition:
distinct.cpp:263
GECODE_POST
#define GECODE_POST
Check for failure in a constraint post function.
Definition:
macros.hpp:44
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:81
Gecode::IRT_EQ
@ IRT_EQ
Equality ( )
Definition:
int.hh:907
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:593
Gecode::min
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition:
arithmetic.cpp:71
Test::Float::Arithmetic::c
Gecode::FloatVal c(-8, 8)
Gecode::IntArgs
Passing integer arguments.
Definition:
int.hh:610
Gecode::IRT_LQ
@ IRT_LQ
Less or equal ( )
Definition:
int.hh:909