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
set
cardinality.cpp
Go to the documentation of this file.
1
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
/*
3
* Main authors:
4
* Gabor Szokoli <szokoli@gecode.org>
5
* Guido Tack <tack@gecode.org>
6
* Christian Schulte <schulte@gecode.org>
7
*
8
* Copyright:
9
* Gabor Szokoli, 2004
10
* Guido Tack, 2004
11
* Christian Schulte, 2004
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/set.hh
>
39
#include <
gecode/set/int.hh
>
40
41
namespace
Gecode
{
42
43
void
44
cardinality
(
Home
home,
SetVar
x
,
unsigned
int
i
,
unsigned
int
j) {
45
Set::Limits::check
(
i
,
"Set::cardinality"
);
46
Set::Limits::check
(j,
"Set::cardinality"
);
47
GECODE_POST
;
48
Set::SetView
_x(
x
);
49
GECODE_ME_FAIL
(_x.cardMin(home,
i
));
50
GECODE_ME_FAIL
(_x.cardMax(home, j));
51
}
52
53
void
54
cardinality
(
Home
home,
const
SetVarArgs
&
x
,
unsigned
int
i
,
unsigned
int
j) {
55
Set::Limits::check
(
i
,
"Set::cardinality"
);
56
Set::Limits::check
(j,
"Set::cardinality"
);
57
GECODE_POST
;
58
for
(
int
k=
x
.size(); k--; ) {
59
Set::SetView
_x(
x
[k]);
60
GECODE_ME_FAIL
(_x.cardMin(home,
i
));
61
GECODE_ME_FAIL
(_x.cardMax(home, j));
62
}
63
}
64
65
void
66
cardinality
(
Home
home,
SetVar
s,
IntVar
x
) {
67
GECODE_POST
;
68
GECODE_ES_FAIL
(
Set::Int::Card<Set::SetView>::post
(home,s,
x
));
69
}
70
71
void
72
cardinality
(
Home
home,
SetVar
s,
IntVar
x
,
Reify
r
) {
73
IntVar
y
(home, 0,
static_cast<
int
>
(
Set::Limits::card
));
74
rel
(home,
x
,
IRT_EQ
,
y
,
r
);
75
cardinality
(home, s,
y
);
76
}
77
78
}
79
80
// STATISTICS: set-post
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:767
Gecode::y
Post propagator for SetVar SetOpType SetVar y
Definition:
set.hh:767
GECODE_ES_FAIL
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition:
macros.hpp:103
Gecode::SetVarArgs
Passing set variables.
Definition:
set.hh:488
Gecode
Gecode toplevel namespace
Gecode::Set::Limits::card
const unsigned int card
Maximum cardinality of an integer set.
Definition:
set.hh:101
Gecode::Reify
Reification specification.
Definition:
int.hh:876
Gecode::Home
Home class for posting propagators
Definition:
core.hpp:856
Gecode::r
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition:
set.hh:767
Gecode::SetVar
Set variables
Definition:
set.hh:127
Gecode::cardinality
LinIntExpr cardinality(const SetExpr &e)
Cardinality of set expression.
Definition:
set-expr.cpp:817
Gecode::IntVar
Integer variables.
Definition:
int.hh:371
Gecode::rel
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition:
rel.cpp:43
Gecode::Set::SetView
Set view for set variables
Definition:
view.hpp:56
Gecode::Set::Limits::check
void check(int n, const char *l)
Check whether integer n is in range, otherwise throw overflow exception with information l.
Definition:
limits.hpp:37
GECODE_POST
#define GECODE_POST
Check for failure in a constraint post function.
Definition:
macros.hpp:40
Gecode::Set::Int::Card
Propagator for cardinality
Definition:
int.hh:229
set.hh
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
int.hh
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})