main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Oct 22 2013 00:49:05 for Gecode by
doxygen
1.8.4
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: 2012-10-19 05:58:26 +0200 (Fri, 19 Oct 2012) $ by $Author: tack $
13
* $Revision: 13156 $
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
namespace
Gecode {
46
47
void
48
rel
(
Home
home,
SetVar
s,
IntRelType
r
,
IntVar
x
) {
49
if
(home.
failed
())
return
;
50
switch
(r) {
51
case
IRT_EQ
:
52
{
53
Gecode::Int::IntView
xv(x);
54
Set::SingletonView
xsingle(xv);
55
GECODE_ES_FAIL
(
56
(
Set::Rel::Eq<Set::SetView,Set::SingletonView>
57
::
post
(home,s,xsingle)));
58
59
}
60
break
;
61
case
IRT_NQ
:
62
{
63
Gecode::Set::SetView
sv(s);
64
GECODE_ME_FAIL
( sv.
cardMin
(home, 1));
65
Gecode::Int::IntView
xv(x);
66
Set::SingletonView
xsingle(xv);
67
GECODE_ES_FAIL
(
68
(
Set::Rel::NoSubset<Set::SingletonView,Set::SetView>
69
::
post
(home,xsingle,sv)));
70
71
}
72
break
;
73
case
IRT_LQ
:
74
{
75
IntVar
tmp(home,
Int::Limits::min
,
Int::Limits::max
);
76
rel
(home, tmp,
IRT_LQ
, x);
77
GECODE_ES_FAIL
(
Set::Int::MaxElement<Set::SetView>::post
(home,s,tmp));
78
}
79
break
;
80
case
IRT_LE
:
81
{
82
IntVar
tmp(home,
Int::Limits::min
,
Int::Limits::max
);
83
rel
(home, tmp,
IRT_LE
, x);
84
GECODE_ES_FAIL
(
Set::Int::MaxElement<Set::SetView>::post
(home,s,tmp));
85
}
86
break
;
87
case
IRT_GQ
:
88
{
89
IntVar
tmp(home,
Int::Limits::min
,
Int::Limits::max
);
90
rel
(home, tmp,
IRT_GQ
, x);
91
GECODE_ES_FAIL
(
Set::Int::MinElement<Set::SetView>::post
(home,s,tmp));
92
}
93
break
;
94
case
IRT_GR
:
95
{
96
IntVar
tmp(home,
Int::Limits::min
,
Int::Limits::max
);
97
rel
(home, tmp,
IRT_GR
, x);
98
GECODE_ES_FAIL
(
Set::Int::MinElement<Set::SetView>::post
(home,s,tmp));
99
}
100
break
;
101
default
:
102
throw
Int::UnknownRelation
(
"Set::rel"
);
103
}
104
105
}
106
107
void
108
rel
(
Home
home,
IntVar
x
,
IntRelType
r
,
SetVar
s) {
109
IntRelType
rr;
110
switch
(r) {
111
case
IRT_LE
: rr=
IRT_GR
;
break
;
112
case
IRT_LQ
: rr=
IRT_GQ
;
break
;
113
case
IRT_GR
: rr=
IRT_LE
;
break
;
114
case
IRT_GQ
: rr=
IRT_LQ
;
break
;
115
default
: rr=
r
;
116
}
117
rel
(home, s, rr, x);
118
}
119
120
void
121
min
(
Home
home,
SetVar
s,
IntVar
x
){
122
if
(home.
failed
())
return
;
123
GECODE_ES_FAIL
(
Set::Int::MinElement<Set::SetView>::post
(home,s,x));
124
}
125
void
126
notMin
(
Home
home,
SetVar
s,
IntVar
x
){
127
if
(home.
failed
())
return
;
128
GECODE_ES_FAIL
(
Set::Int::NotMinElement<Set::SetView>::post
(home,s,x));
129
}
130
void
131
min
(
Home
home,
SetVar
s,
IntVar
x
,
Reify
r
){
132
if
(home.
failed
())
return
;
133
switch
(r.
mode
()) {
134
case
RM_EQV
:
135
GECODE_ES_FAIL
((
Set::Int::ReMinElement<Set::SetView,RM_EQV>
136
::
post
(home,s,x,r.
var
())));
137
break
;
138
case
RM_IMP
:
139
GECODE_ES_FAIL
((
Set::Int::ReMinElement<Set::SetView,RM_IMP>
140
::
post
(home,s,x,r.
var
())));
141
break
;
142
case
RM_PMI
:
143
GECODE_ES_FAIL
((
Set::Int::ReMinElement<Set::SetView,RM_PMI>
144
::
post
(home,s,x,r.
var
())));
145
break
;
146
default
:
throw
Gecode::Int::UnknownReifyMode
(
"Set::min"
);
147
}
148
}
149
void
150
max
(
Home
home,
SetVar
s,
IntVar
x
){
151
if
(home.
failed
())
return
;
152
GECODE_ES_FAIL
(
Set::Int::MaxElement<Set::SetView>::post
(home,s,x));
153
}
154
void
155
notMax
(
Home
home,
SetVar
s,
IntVar
x
){
156
if
(home.
failed
())
return
;
157
GECODE_ES_FAIL
(
Set::Int::NotMaxElement<Set::SetView>::post
(home,s,x));
158
}
159
void
160
max
(
Home
home,
SetVar
s,
IntVar
x
,
Reify
r
){
161
if
(home.
failed
())
return
;
162
switch
(r.
mode
()) {
163
case
RM_EQV
:
164
GECODE_ES_FAIL
((
Set::Int::ReMaxElement<Set::SetView,RM_EQV>
165
::
post
(home,s,x,r.
var
())));
166
break
;
167
case
RM_IMP
:
168
GECODE_ES_FAIL
((
Set::Int::ReMaxElement<Set::SetView,RM_IMP>
169
::
post
(home,s,x,r.
var
())));
170
break
;
171
case
RM_PMI
:
172
GECODE_ES_FAIL
((
Set::Int::ReMaxElement<Set::SetView,RM_PMI>
173
::
post
(home,s,x,r.
var
())));
174
break
;
175
default
:
throw
Gecode::Int::UnknownReifyMode
(
"Set::max"
);
176
}
177
}
178
179
void
weights
(
Home
home,
IntSharedArray
elements,
IntSharedArray
weights
,
180
SetVar
x
,
IntVar
y) {
181
if
(home.
failed
())
return
;
182
GECODE_ES_FAIL
(
Set::Int::Weights<Set::SetView>::post
(home,elements,
183
weights,x,y));
184
}
185
186
}
187
188
// STATISTICS: set-post