main page
modules
namespaces
classes
files
Gecode home
Generated on Thu Mar 7 2013 10:21:35 for Gecode by
doxygen
1.8.3.1
gecode
set
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
* Guido Tack <tack@gecode.org>
5
* Christian Schulte <schulte@gecode.org>
6
*
7
* Copyright:
8
* Guido Tack, 2004
9
* Christian Schulte, 2004
10
*
11
* Last modified:
12
* $Date: 2011-08-18 20:26:27 +1000 (Thu, 18 Aug 2011) $ by $Author: tack $
13
* $Revision: 12314 $
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/set.hh
>
41
42
#include <
gecode/set/int.hh
>
43
#include <
gecode/set/rel.hh
>
44
45
using namespace
Gecode::Int;
46
47
namespace
Gecode {
48
49
void
50
rel
(
Home
home,
SetVar
s,
IntRelType
r
,
IntVar
x) {
51
if
(home.
failed
())
return
;
52
switch
(r) {
53
case
IRT_EQ
:
54
{
55
Gecode::Int::IntView
xv(x);
56
Set::SingletonView
xsingle(xv);
57
GECODE_ES_FAIL
(
58
(
Set::Rel::Eq<Set::SetView,Set::SingletonView>
59
::
post
(home,s,xsingle)));
60
61
}
62
break
;
63
case
IRT_NQ
:
64
{
65
Gecode::Set::SetView
sv(s);
66
GECODE_ME_FAIL
( sv.
cardMin
(home, 1));
67
Gecode::Int::IntView
xv(x);
68
Set::SingletonView
xsingle(xv);
69
GECODE_ES_FAIL
(
70
(
Set::Rel::NoSubset<Set::SingletonView,Set::SetView>
71
::
post
(home,xsingle,sv)));
72
73
}
74
break
;
75
case
IRT_LQ
:
76
{
77
IntVar
tmp(home,
Int::Limits::min
,
Int::Limits::max
);
78
rel
(home, tmp,
IRT_LQ
, x);
79
GECODE_ES_FAIL
(
Set::Int::MaxElement<Set::SetView>::post
(home,s,tmp));
80
}
81
break
;
82
case
IRT_LE
:
83
{
84
IntVar
tmp(home,
Int::Limits::min
,
Int::Limits::max
);
85
rel
(home, tmp,
IRT_LE
, x);
86
GECODE_ES_FAIL
(
Set::Int::MaxElement<Set::SetView>::post
(home,s,tmp));
87
}
88
break
;
89
case
IRT_GQ
:
90
{
91
IntVar
tmp(home,
Int::Limits::min
,
Int::Limits::max
);
92
rel
(home, tmp,
IRT_GQ
, x);
93
GECODE_ES_FAIL
(
Set::Int::MinElement<Set::SetView>::post
(home,s,tmp));
94
}
95
break
;
96
case
IRT_GR
:
97
{
98
IntVar
tmp(home,
Int::Limits::min
,
Int::Limits::max
);
99
rel
(home, tmp,
IRT_GR
, x);
100
GECODE_ES_FAIL
(
Set::Int::MinElement<Set::SetView>::post
(home,s,tmp));
101
}
102
break
;
103
default
:
104
throw
UnknownRelation
(
"Set::rel"
);
105
}
106
107
}
108
109
void
110
rel
(
Home
home,
IntVar
x,
IntRelType
r
,
SetVar
s) {
111
IntRelType
rr;
112
switch
(r) {
113
case
IRT_LE
: rr=
IRT_GR
;
break
;
114
case
IRT_LQ
: rr=
IRT_GQ
;
break
;
115
case
IRT_GR
: rr=
IRT_LE
;
break
;
116
case
IRT_GQ
: rr=
IRT_LQ
;
break
;
117
default
: rr=
r
;
118
}
119
rel
(home, s, rr, x);
120
}
121
122
void
123
min
(
Home
home,
SetVar
s,
IntVar
x){
124
if
(home.
failed
())
return
;
125
GECODE_ES_FAIL
(
Set::Int::MinElement<Set::SetView>::post
(home,s,x));
126
}
127
void
128
notMin
(
Home
home,
SetVar
s,
IntVar
x){
129
if
(home.
failed
())
return
;
130
GECODE_ES_FAIL
(
Set::Int::NotMinElement<Set::SetView>::post
(home,s,x));
131
}
132
void
133
min
(
Home
home,
SetVar
s,
IntVar
x,
BoolVar
b
){
134
if
(home.
failed
())
return
;
135
GECODE_ES_FAIL
(
136
Set::Int::ReMinElement<Set::SetView>::post
(home,s,x,b));
137
}
138
void
139
max
(
Home
home,
SetVar
s,
IntVar
x){
140
if
(home.
failed
())
return
;
141
GECODE_ES_FAIL
(
Set::Int::MaxElement<Set::SetView>::post
(home,s,x));
142
}
143
void
144
notMax
(
Home
home,
SetVar
s,
IntVar
x){
145
if
(home.
failed
())
return
;
146
GECODE_ES_FAIL
(
Set::Int::NotMaxElement<Set::SetView>::post
(home,s,x));
147
}
148
void
149
max
(
Home
home,
SetVar
s,
IntVar
x,
BoolVar
b
){
150
if
(home.
failed
())
return
;
151
GECODE_ES_FAIL
(
152
Set::Int::ReMaxElement<Set::SetView>::post
(home,s,x,b));
153
}
154
155
void
156
channelSorted
(
Home
home,
const
IntVarArgs
& x,
SetVar
y) {
157
if
(home.
failed
())
return
;
158
ViewArray<IntView>
xa(home,x);
159
GECODE_ES_FAIL
(
Set::Int::Match<Set::SetView>::post
(home,y,xa));
160
}
161
162
void
163
channel
(
Home
home,
const
IntVarArgs
& x,
const
SetVarArgs
& y) {
164
if
(home.
failed
())
return
;
165
ViewArray<Int::CachedView<Int::IntView>
> xa(home,x.
size
());
166
for
(
int
i
=x.
size
();
i
--;)
167
new
(&xa[
i
])
Int::CachedView<Int::IntView>
(x[
i
]);
168
ViewArray<Set::CachedView<Set::SetView>
> ya(home,y.
size
());
169
for
(
int
i=y.
size
(); i--;)
170
new
(&ya[i])
Set::CachedView<Set::SetView>
(y[
i
]);
171
GECODE_ES_FAIL
((
Set::Int::ChannelInt<Set::SetView>::post
(home,xa,ya)));
172
}
173
174
void
175
channel
(
Home
home,
const
BoolVarArgs
& x,
SetVar
y) {
176
if
(home.
failed
())
return
;
177
ViewArray<Int::BoolView>
xv(home,x);
178
GECODE_ES_FAIL
((
Set::Int::ChannelBool<Set::SetView>
179
::
post
(home,xv,y)));
180
}
181
182
void
weights
(
Home
home,
IntSharedArray
elements,
IntSharedArray
weights
,
183
SetVar
x,
IntVar
y) {
184
if
(home.
failed
())
return
;
185
GECODE_ES_FAIL
(
Set::Int::Weights<Set::SetView>::post
(home,elements,
186
weights,x,y));
187
}
188
189
}
190
191
// STATISTICS: set-post