Generated on Sun Aug 9 2020 05:34:08 for Gecode by doxygen 1.8.18
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");
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");
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
69  }
70 
71  void
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
Post propagator for SetVar x
Definition: set.hh:767
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:767
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition: macros.hpp:103
Passing set variables.
Definition: set.hh:488
Gecode toplevel namespace
const unsigned int card
Maximum cardinality of an integer set.
Definition: set.hh:101
Reification specification.
Definition: int.hh:876
Home class for posting propagators
Definition: core.hpp:856
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:767
Set variables
Definition: set.hh:127
LinIntExpr cardinality(const SetExpr &e)
Cardinality of set expression.
Definition: set-expr.cpp:817
Integer variables.
Definition: int.hh:371
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition: rel.cpp:43
Set view for set variables
Definition: view.hpp:56
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
#define GECODE_POST
Check for failure in a constraint post function.
Definition: macros.hpp:40
Propagator for cardinality
Definition: int.hh:231
#define GECODE_ME_FAIL(me)
Check whether modification event me is failed, and fail space home.
Definition: macros.hpp:77
@ IRT_EQ
Equality ( )
Definition: int.hh:926
Gecode::IntArgs i({1, 2, 3, 4})