Generated on Mon Aug 25 11:35:36 2008 for Gecode by doxygen 1.5.6

count.cc

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Christian Schulte, 2005
00008  *
00009  *  Last modified:
00010  *     $Date: 2008-02-19 11:41:53 +0100 (Tue, 19 Feb 2008) $ by $Author: schulte $
00011  *     $Revision: 6233 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 #include "test/int.hh"
00039 
00040 namespace Test { namespace Int {
00041 
00043    namespace Count {
00044    
00050 
00051      class IntInt : public Test {
00052      protected:
00054        Gecode::IntRelType irt;
00055      public:
00057        IntInt(Gecode::IntRelType irt0)
00058          : Test("Count::Int::Int::"+str(irt0),4,-2,2), irt(irt0) {}
00060        virtual bool solution(const Assignment& x) const {
00061          int m = 0;
00062          for (int i=x.size(); i--; )
00063            if (x[i] == 0)
00064              m++;
00065          return cmp(m,irt,2);
00066        }
00068        virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00069          Gecode::count(home, x,0,irt,2);
00070        }
00071      };
00072    
00074      class IntIntDup : public Test {
00075      protected:
00077        Gecode::IntRelType irt;
00078      public:
00080        IntIntDup(Gecode::IntRelType irt0)
00081          : Test("Count::Int::Int::Dup::"+str(irt0),4,-2,2), irt(irt0) {}
00083        virtual bool solution(const Assignment& x) const {
00084          int m = 0;
00085          for (int i=x.size(); i--; )
00086            if (x[i] == 0)
00087              m += 2;
00088          return cmp(m,irt,4);
00089        }
00091        virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00092          Gecode::IntVarArgs y(8);
00093          for (int i=x.size(); i--; )
00094            y[i]=y[4+i]=x[i];
00095          Gecode::count(home, y, 0, irt, 4);
00096        }
00097      };
00098    
00100      class IntVar : public Test {
00101      protected:
00103        Gecode::IntRelType irt;
00104      public:
00106        IntVar(Gecode::IntRelType irt0)
00107          : Test("Count::Int::Var::"+str(irt0),5,-2,2), irt(irt0) {}
00109        virtual bool solution(const Assignment& x) const {
00110          int m = 0;
00111          for (int i=0; i<4; i++)
00112            if (x[i] == 0)
00113              m++;
00114          return cmp(m,irt,x[4]);
00115        }
00117        virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00118          Gecode::IntVarArgs y(4);
00119          for (int i=0; i<4; i++)
00120            y[i]=x[i];
00121          Gecode::count(home, y, 0, irt, x[4]);
00122        }
00123      };
00124    
00125      Gecode::IntArgs ints(4, 1,0,3,2);
00126    
00128      class IntArrayInt : public Test {
00129      protected:
00131        Gecode::IntRelType irt;
00132      public:
00134        IntArrayInt(Gecode::IntRelType irt0)
00135          : Test("Count::IntArray::Int::"+str(irt0),5,-2,2), irt(irt0) {}
00137        virtual bool solution(const Assignment& x) const {
00138          int m = 0;
00139          for (int i=0; i<4; i++)
00140            if (x[i] == ints[i])
00141              m++;
00142          return cmp(m,irt,2);
00143        }
00145        virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00146          Gecode::IntVarArgs y(4);
00147          for (int i=0; i<4; i++)
00148            y[i]=x[i];
00149          Gecode::count(home, y, ints, irt, 2);
00150        }
00151      };
00152    
00154      class IntArrayVar : public Test {
00155      protected:
00157        Gecode::IntRelType irt;
00158      public:
00160        IntArrayVar(Gecode::IntRelType irt0)
00161          : Test("Count::IntArray::Var::"+str(irt0),5,-2,2), irt(irt0) {}
00163        virtual bool solution(const Assignment& x) const {
00164          int m = 0;
00165          for (int i=0; i<4; i++)
00166            if (x[i] == ints[i])
00167              m++;
00168          return cmp(m,irt,x[4]);
00169        }
00171        virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00172          Gecode::IntVarArgs y(4);
00173          for (int i=0; i<4; i++)
00174            y[i]=x[i];
00175          Gecode::count(home, y, ints, irt, x[4]);
00176        }
00177      };
00178    
00180      class IntVarShared : public Test {
00181      protected:
00183        Gecode::IntRelType irt;
00184      public:
00186        IntVarShared(Gecode::IntRelType irt0)
00187          : Test("Count::Int::Var::Shared::"+str(irt0),4,-2,2), irt(irt0) {}
00189        virtual bool solution(const Assignment& x) const {
00190          int m = 0;
00191          for (int i=0; i<4; i++)
00192            if (x[i] == 0)
00193              m++;
00194          return cmp(m,irt,x[2]);
00195        }
00197        virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00198          Gecode::count(home, x, 0, irt, x[2]);
00199        }
00200      };
00201    
00203      class VarVar : public Test {
00204      protected:
00206        Gecode::IntRelType irt;
00207      public:
00209        VarVar(Gecode::IntRelType irt0)
00210          : Test("Count::Var::Var::"+str(irt0),5,-2,2), irt(irt0) {}
00212        virtual bool solution(const Assignment& x) const {
00213          int m = 0;
00214          for (int i=0; i<3; i++)
00215            if (x[i] == x[3])
00216              m++;
00217          return cmp(m,irt,x[4]);
00218        }
00220        virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00221          Gecode::IntVarArgs y(3);
00222          for (int i=0; i<3; i++)
00223            y[i]=x[i];
00224          Gecode::count(home, y, x[3], irt, x[4]);
00225        }
00226      };
00227    
00229      class VarInt : public Test {
00230      protected:
00232        Gecode::IntRelType irt;
00233      public:
00235        VarInt(Gecode::IntRelType irt0)
00236          : Test("Count::Var::Int::"+str(irt0),4,-2,2), irt(irt0) {}
00238        virtual bool solution(const Assignment& x) const {
00239          int m = 0;
00240          for (int i=0; i<3; i++)
00241            if (x[i] == x[3])
00242              m++;
00243          return cmp(m,irt,2);
00244        }
00246        virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00247          Gecode::IntVarArgs y(3);
00248          for (int i=0; i<3; i++)
00249            y[i]=x[i];
00250          Gecode::count(home, y, x[3], irt, 2);
00251        }
00252      };
00253    
00255      class VarVarSharedA : public Test {
00256      protected:
00258        Gecode::IntRelType irt;
00259      public:
00261        VarVarSharedA(Gecode::IntRelType irt0)
00262          : Test("Count::Var::Var::Shared::A::"+str(irt0),5,-2,2), irt(irt0) {}
00264        virtual bool solution(const Assignment& x) const {
00265          int m = 0;
00266          for (int i=0; i<4; i++)
00267            if (x[i] == x[1])
00268              m++;
00269          return cmp(m,irt,x[4]);
00270        }
00272        virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00273          Gecode::IntVarArgs y(4);
00274          for (int i=0; i<4; i++)
00275            y[i]=x[i];
00276          Gecode::count(home, y, x[1], irt, x[4]);
00277        }
00278      };
00279    
00281      class VarVarSharedB : public Test {
00282      protected:
00284        Gecode::IntRelType irt;
00285      public:
00287        VarVarSharedB(Gecode::IntRelType irt0)
00288          : Test("Count::Var::Var::Shared::B::"+str(irt0),5,-2,2), irt(irt0) {}
00290        virtual bool solution(const Assignment& x) const {
00291          int m = 0;
00292          for (int i=0; i<4; i++)
00293            if (x[i] == x[4])
00294              m++;
00295          return cmp(m,irt,x[3]);
00296        }
00298        virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00299          Gecode::IntVarArgs y(4);
00300          for (int i=0; i<4; i++)
00301            y[i]=x[i];
00302          Gecode::count(home, y, x[4], irt, x[3]);
00303        }
00304      };
00305    
00307      class VarVarSharedC : public Test {
00308      protected:
00310        Gecode::IntRelType irt;
00311      public:
00313        VarVarSharedC(Gecode::IntRelType irt0)
00314          : Test("Count::Var::Var::Shared::A::"+str(irt0),4,-2,2), irt(irt0) {}
00316        virtual bool solution(const Assignment& x) const {
00317          int m = 0;
00318          for (int i=0; i<4; i++)
00319            if (x[i] == x[1])
00320              m++;
00321          return cmp(m,irt,x[3]);
00322        }
00324        virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00325          Gecode::count(home, x, x[1], irt, x[3]);
00326        }
00327      };
00328    
00330      class Create {
00331      public:
00333        Create(void) {
00334          for (IntRelTypes irts; irts(); ++irts) {
00335            (void) new IntInt(irts.irt());
00336            (void) new IntIntDup(irts.irt());
00337            (void) new IntVar(irts.irt());
00338            (void) new IntArrayInt(irts.irt());
00339            (void) new IntArrayVar(irts.irt());
00340            (void) new IntVarShared(irts.irt());
00341            (void) new VarVar(irts.irt());
00342            (void) new VarInt(irts.irt());
00343            (void) new VarVarSharedA(irts.irt());
00344            (void) new VarVarSharedB(irts.irt());
00345            (void) new VarVarSharedC(irts.irt());
00346          }
00347        }
00348      };
00349    
00350      Create c;
00352    
00353    }
00354 }}
00355 
00356 // STATISTICS: test-int
00357