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
00039
00040
00041
00042
00043
00044 #include <gecode/int/gcc.hh>
00045
00046 namespace Gecode {
00047
00048 void count(Home home, const IntVarArgs& x,
00049 const IntVarArgs& c, const IntArgs& v,
00050 IntConLevel icl) {
00051 using namespace Int;
00052 if (v.size() != c.size())
00053 throw ArgumentSizeMismatch("Int::count");
00054 if (x.same(home))
00055 throw ArgumentSame("Int::count");
00056 if (home.failed())
00057 return;
00058
00059 ViewArray<IntView> xv(home, x);
00060 ViewArray<GCC::CardView> cv(home, c.size());
00061
00062 for (int i = v.size(); i--; )
00063 cv[i].init(c[i],v[i]);
00064 switch (icl) {
00065 case ICL_BND:
00066 GECODE_ES_FAIL(
00067 (GCC::Bnd<GCC::CardView>::post(home,xv,cv)));
00068 break;
00069 case ICL_DOM:
00070 GECODE_ES_FAIL(
00071 (GCC::Dom<GCC::CardView>::post(home,xv,cv)));
00072 break;
00073 default:
00074 GECODE_ES_FAIL(
00075 (GCC::Val<GCC::CardView>::post(home,xv,cv)));
00076 }
00077 }
00078
00079
00080 void count(Home home, const IntVarArgs& x, const IntVarArgs& c,
00081 IntConLevel icl) {
00082 IntArgs values(c.size());
00083 for (int i = c.size(); i--; )
00084 values[i] = i;
00085 count(home, x, c, values, icl);
00086 }
00087
00088
00089 void count(Home home, const IntVarArgs& x,
00090 const IntSetArgs& c, const IntArgs& v,
00091 IntConLevel icl) {
00092 using namespace Int;
00093 if (v.size() != c.size())
00094 throw ArgumentSizeMismatch("Int::count");
00095 if (x.same(home))
00096 throw ArgumentSame("Int::count");
00097 for (int i=c.size(); i--; ) {
00098 Limits::check(v[i],"Int::count");
00099 Limits::check(c[i].min(),"Int::count");
00100 Limits::check(c[i].max(),"Int::count");
00101 }
00102
00103 if (home.failed())
00104 return;
00105
00106 ViewArray<IntView> xv(home, x);
00107
00108 for (int i = v.size(); i--; ) {
00109 if (c[i].ranges() > 1) {
00110
00111 ViewArray<GCC::CardView> cv(home, v.size());
00112 for (int j = v.size(); j--; )
00113 cv[j].init(home,c[j],v[j]);
00114 switch (icl) {
00115 case ICL_BND:
00116 GECODE_ES_FAIL(
00117 (GCC::Bnd<GCC::CardView>::post(home, xv, cv)));
00118 break;
00119 case ICL_DOM:
00120 GECODE_ES_FAIL(
00121 (GCC::Dom<GCC::CardView>::post(home, xv, cv)));
00122 break;
00123 default:
00124 GECODE_ES_FAIL(
00125 (GCC::Val<GCC::CardView>::post(home, xv, cv)));
00126 }
00127 return;
00128 }
00129 }
00130
00131
00132 ViewArray<GCC::CardConst> cv(home, c.size());
00133
00134 for (int i = c.size(); i--; )
00135 cv[i].init(home,c[i].min(),c[i].max(),v[i]);
00136
00137 switch (icl) {
00138 case ICL_BND:
00139 GECODE_ES_FAIL(
00140 (GCC::Bnd<GCC::CardConst>::post(home, xv, cv)));
00141 break;
00142 case ICL_DOM:
00143 GECODE_ES_FAIL(
00144 (GCC::Dom<GCC::CardConst>::post(home, xv, cv)));
00145 break;
00146 default:
00147 GECODE_ES_FAIL(
00148 (GCC::Val<GCC::CardConst>::post(home, xv, cv)));
00149 }
00150 }
00151
00152
00153 void count(Home home, const IntVarArgs& x, const IntSetArgs& c,
00154 IntConLevel icl) {
00155 IntArgs values(c.size());
00156 for (int i = c.size(); i--; )
00157 values[i] = i;
00158 count(home, x, c, values, icl);
00159 }
00160
00161 void count(Home home, const IntVarArgs& x,
00162 const IntSet& c, const IntArgs& v,
00163 IntConLevel icl) {
00164 IntSetArgs cards(v.size());
00165 for (int i = v.size(); i--; )
00166 cards[i] = c;
00167 count(home, x, cards, v, icl);
00168 }
00169
00170 }
00171
00172