Generated on Wed Jan 4 17:49:08 2006 for Gecode by doxygen 1.4.6

count.cc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Christian Schulte <schulte@gecode.org>
00004  *
00005  *  Copyright:
00006  *     Christian Schulte, 2002
00007  *
00008  *  Last modified:
00009  *     $Date: 2005-11-04 13:56:04 +0100 (Fri, 04 Nov 2005) $ by $Author: schulte $
00010  *     $Revision: 2497 $
00011  *
00012  *  This file is part of Gecode, the generic constraint
00013  *  development environment:
00014  *     http://www.gecode.org
00015  *
00016  *  See the file "LICENSE" for information on usage and
00017  *  redistribution of this file, and for a
00018  *     DISCLAIMER OF ALL WARRANTIES.
00019  *
00020  */
00021 
00022 #include "int/count.hh"
00023 
00024 namespace Gecode {
00025 
00026   using namespace Int;
00027 
00028 #define CREATE(VY,VZ,C)                                                  \
00029 if (icl == ICL_BND) {                                                    \
00030   if (C<IntView,VY,VZ,Count::RelEqBnd<IntView>,true>::post(home,x,y,z,c) \
00031       == ES_FAILED)                                                      \
00032     home->fail();                                                        \
00033 } else {                                                                 \
00034   if (C<IntView,VY,VZ,Count::RelEqDom<IntView>,true>::post(home,x,y,z,c) \
00035       == ES_FAILED)                                                      \
00036     home->fail();                                                        \
00037 }
00038 
00039   void
00040   count(Space* home, const IntVarArgs& xa, int yn,
00041         IntRelType r, int zn, IntConLevel icl) {
00042     if (home->failed()) return;
00043     ViewArray<IntView> x(home,xa);
00044     ConstIntView y(yn);
00045     ConstIntView z(zn);
00046     int c = 0;
00047     switch (r) {
00048     case IRT_EQ: 
00049       CREATE(ConstIntView,ConstIntView,Count::Eq); break;
00050     case IRT_NQ: 
00051       CREATE(ConstIntView,ConstIntView,Count::Nq); break;
00052     case IRT_LE: 
00053       c = 1; // Fall through
00054     case IRT_LQ: 
00055       CREATE(ConstIntView,ConstIntView,Count::Lq); break;
00056     case IRT_GR: 
00057       c = -1; // Fall through
00058     case IRT_GQ: 
00059       CREATE(ConstIntView,ConstIntView,Count::Gq); break;
00060     default: 
00061       throw UnknownRelation("Int::count");
00062     }
00063   }
00064 
00065   void
00066   count(Space* home, const IntVarArgs& xa, int yn,
00067         IntRelType r, IntVar z, IntConLevel icl) {
00068     if (home->failed()) return;
00069     ViewArray<IntView> x(home,xa);
00070     ConstIntView y(yn);
00071     int c = 0;
00072     switch (r) {
00073     case IRT_EQ: 
00074       CREATE(ConstIntView,IntView,Count::Eq); break;
00075     case IRT_NQ: 
00076       CREATE(ConstIntView,IntView,Count::Nq); break;
00077     case IRT_LE: 
00078       c = 1; // Fall through
00079     case IRT_LQ: 
00080       CREATE(ConstIntView,IntView,Count::Lq); break;
00081     case IRT_GR: 
00082       c = -1; // Fall through
00083     case IRT_GQ: 
00084       CREATE(ConstIntView,IntView,Count::Gq); break;
00085     default: 
00086       throw UnknownRelation("Int::count");
00087     }
00088   }
00089 
00090   void
00091   count(Space* home, const IntVarArgs& xa, IntVar y,
00092         IntRelType r, int zn, IntConLevel icl) {
00093     if (home->failed()) return;
00094     ViewArray<IntView> x(home,xa);
00095     ConstIntView z(zn);
00096     int c = 0;
00097     switch (r) {
00098     case IRT_EQ: 
00099       CREATE(IntView,ConstIntView,Count::Eq); break;
00100     case IRT_NQ: 
00101       CREATE(IntView,ConstIntView,Count::Nq); break;
00102     case IRT_LE: 
00103       c = 1; // Fall through
00104     case IRT_LQ: 
00105       CREATE(IntView,ConstIntView,Count::Lq); break;
00106     case IRT_GR: 
00107       c = -1; // Fall through
00108     case IRT_GQ: 
00109       CREATE(IntView,ConstIntView,Count::Gq); break;
00110     default: 
00111       throw UnknownRelation("Int::count");
00112     }
00113   }
00114 
00115   void
00116   count(Space* home, const IntVarArgs& xa, IntVar y,
00117         IntRelType r, IntVar z, IntConLevel icl) {
00118     if (home->failed()) return;
00119     ViewArray<IntView> x(home,xa);
00120     int c = 0;
00121     switch (r) {
00122     case IRT_EQ: 
00123       CREATE(IntView,IntView,Count::Eq); break;
00124     case IRT_NQ: 
00125       CREATE(IntView,IntView,Count::Nq); break;
00126     case IRT_LE: 
00127       c = 1; // Fall through
00128     case IRT_LQ: 
00129       CREATE(IntView,IntView,Count::Lq); break;
00130     case IRT_GR: 
00131       c = -1; // Fall through
00132     case IRT_GQ: 
00133       CREATE(IntView,IntView,Count::Gq); break;
00134     default: 
00135       throw UnknownRelation("Int::count");
00136     }
00137   }
00138 
00139 }
00140 
00141 // STATISTICS: int-post
00142