cardinality.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <gecode/set.hh>
00039 #include <gecode/set/int.hh>
00040
00041 namespace Gecode {
00042
00043 void
00044 cardinality(Home home, SetVar x, unsigned int i, unsigned int j) {
00045 Set::Limits::check(i, "Set::cardinality");
00046 Set::Limits::check(j, "Set::cardinality");
00047 GECODE_POST;
00048 Set::SetView _x(x);
00049 GECODE_ME_FAIL(_x.cardMin(home, i));
00050 GECODE_ME_FAIL(_x.cardMax(home, j));
00051 }
00052
00053 void
00054 cardinality(Home home, const SetVarArgs& x, unsigned int i, unsigned int j) {
00055 Set::Limits::check(i, "Set::cardinality");
00056 Set::Limits::check(j, "Set::cardinality");
00057 GECODE_POST;
00058 for (int k=x.size(); k--; ) {
00059 Set::SetView _x(x[k]);
00060 GECODE_ME_FAIL(_x.cardMin(home, i));
00061 GECODE_ME_FAIL(_x.cardMax(home, j));
00062 }
00063 }
00064
00065 void
00066 cardinality(Home home, SetVar s, IntVar x) {
00067 GECODE_POST;
00068 GECODE_ES_FAIL(Set::Int::Card<Set::SetView>::post(home,s, x));
00069 }
00070
00071 void
00072 cardinality(Home home, SetVar s, IntVar x, Reify r) {
00073 IntVar y(home, 0, static_cast<int>(Set::Limits::card));
00074 rel(home, x, IRT_EQ, y, r);
00075 cardinality(home, s, y);
00076 }
00077
00078 }
00079
00080