00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef GECODEEXTENSIONS_HH_
00021 #define GECODEEXTENSIONS_HH_
00022
00023
00024 #include <gecode/int/count.hh>
00025
00026 namespace Gecode {
00027
00028 void
00029 count(Space* home, const IntVarArgs& xa, const IntArgs& ya,
00030 IntRelType r, int z, IntConLevel icl);
00031
00032 void
00033 atmost(Space* home, const IntVarArgs& x, const IntArgs& ya, int m,
00034 IntConLevel icl=ICL_DEF);
00035
00036 void
00037 atleast(Space* home, const IntVarArgs& x, const IntArgs& ya, int m,
00038 IntConLevel icl=ICL_DEF);
00039
00040 void
00041 exactly(Space* home, const IntVarArgs& x, const IntArgs& ya, int m,
00042 IntConLevel icl=ICL_DEF);
00043
00044
00045 inline
00046 void
00047 count(Space* home, const IntVarArgs& xa, const IntArgs& ya,
00048 IntRelType r, int z, IntConLevel icl) {
00049 using namespace Int;
00050 if (home->failed()) return;
00051 ViewArray<OffsetView> x(home,xa.size());
00052 for (int i = ya.size(); i--; )
00053 if ((-ya[i] < Limits::Int::int_min) || (-ya[i] > Limits::Int::int_max))
00054 throw NumericalOverflow("Int::count");
00055 else
00056 x[i].init(xa[i],-ya[i]);
00057 ConstIntView yv(0);
00058 switch (r) {
00059 case IRT_EQ:
00060 GECODE_ES_FAIL(home,(Count::EqInt<OffsetView,ConstIntView>
00061 ::post(home,x,yv,z)));
00062 break;
00063 case IRT_NQ:
00064 GECODE_ES_FAIL(home,(Count::NqInt<OffsetView,ConstIntView>
00065 ::post(home,x,yv,z)));
00066 break;
00067 case IRT_LE:
00068 GECODE_ES_FAIL(home,(Count::LqInt<OffsetView,ConstIntView>
00069 ::post(home,x,yv,z-1)));
00070 break;
00071 case IRT_LQ:
00072 GECODE_ES_FAIL(home,(Count::LqInt<OffsetView,ConstIntView>
00073 ::post(home,x,yv,z)));
00074 break;
00075 case IRT_GR:
00076 GECODE_ES_FAIL(home,(Count::GqInt<OffsetView,ConstIntView>
00077 ::post(home,x,yv,z+1)));
00078 break;
00079 case IRT_GQ:
00080 GECODE_ES_FAIL(home,(Count::GqInt<OffsetView,ConstIntView>
00081 ::post(home,x,yv,z)));
00082 break;
00083 default:
00084 throw UnknownRelation("Int::count");
00085 }
00086 }
00087
00088 inline
00089 void
00090 atmost(Space* home, const IntVarArgs& x, const IntArgs& ya, int m,
00091 IntConLevel icl)
00092 {
00093 count(home,x,ya,IRT_LQ,m,icl);
00094 }
00095
00096 inline
00097 void
00098 atleast(Space* home, const IntVarArgs& x, const IntArgs& ya, int m,
00099 IntConLevel icl)
00100 {
00101 count(home,x,ya,IRT_GQ,m,icl);
00102 }
00103
00104 inline
00105 void
00106 exactly(Space* home, const IntVarArgs& x, const IntArgs& ya, int m,
00107 IntConLevel icl)
00108 {
00109 count(home,x,ya,IRT_EQ,m,icl);
00110 }
00111
00112 }
00113
00114
00115
00116
00117 #endif