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

gcc.cc

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Patrick Pekczynski <pekczynski@ps.uni-sb.de>
00005  *
00006  *  Contributing authors:
00007  *     Christian Schulte <schulte@gecode.org>
00008  *
00009  *  Copyright:
00010  *     Patrick Pekczynski, 2005
00011  *     Christian Schulte, 2007
00012  *
00013  *  Last modified:
00014  *     $Date: 2008-02-27 11:24:12 +0100 (Wed, 27 Feb 2008) $ by $Author: tack $
00015  *     $Revision: 6323 $
00016  *
00017  *  This file is part of Gecode, the generic constraint
00018  *  development environment:
00019  *     http://www.gecode.org
00020  *
00021  *  Permission is hereby granted, free of charge, to any person obtaining
00022  *  a copy of this software and associated documentation files (the
00023  *  "Software"), to deal in the Software without restriction, including
00024  *  without limitation the rights to use, copy, modify, merge, publish,
00025  *  distribute, sublicense, and/or sell copies of the Software, and to
00026  *  permit persons to whom the Software is furnished to do so, subject to
00027  *  the following conditions:
00028  *
00029  *  The above copyright notice and this permission notice shall be
00030  *  included in all copies or substantial portions of the Software.
00031  *
00032  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00033  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00034  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00035  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00036  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00037  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00038  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00039  *
00040  */        
00041 
00042 #include "test/int.hh"
00043 
00044 namespace Test { namespace Int {
00045 
00047    namespace GCC {
00048    
00054 
00055      class IntAllMinMax : public Test {
00056      public:
00058        IntAllMinMax(Gecode::IntConLevel icl)
00059          : Test("GCC::Int::All::MinMax::"+str(icl),4,1,4,false,icl) {}
00061        virtual bool solution(const Assignment& x) const {
00062          int n[4];
00063          for (int i=4; i--; )
00064            n[i]=0;
00065          for (int i=x.size(); i--; )
00066            n[x[i]-1]++;
00067          if (n[2] > 0)
00068            return false;
00069          for (int i=4; i--;)
00070            if (n[i]>2)
00071              return false;
00072          return true;
00073        }
00075        virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00076          using namespace Gecode;
00077          IntArgs values(4);
00078          IntSet fixed(0,2);
00079          IntSetArgs cards(4);
00080          for (int i=0; i<4; i++) {
00081            values[i] = i+1; cards[i] = fixed;
00082          }
00083          cards[2] = IntSet(0,0);
00084          count(home, x, cards, values, icl);
00085        }
00086      };
00087 
00089      class IntAllMinMaxDef : public Test {
00090      public:
00092        IntAllMinMaxDef(Gecode::IntConLevel icl)
00093          : Test("GCC::Int::All::MinMaxDef::"+str(icl),4,0,3,false,icl) {}
00095        virtual bool solution(const Assignment& x) const {
00096          int n[4];
00097          for (int i=4; i--; )
00098            n[i]=0;
00099          for (int i=x.size(); i--; )
00100            n[x[i]]++;
00101          if (n[2] > 0)
00102            return false;
00103          for (int i=4; i--;)
00104            if (n[i]>2)
00105              return false;
00106          return true;
00107        }
00109        virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00110          using namespace Gecode;
00111          IntSet fixed(0,2);
00112          IntSetArgs cards(4);
00113          for (int i=0; i<4; i++) {
00114            cards[i] = fixed;
00115          }
00116          cards[2] = IntSet(0,0);
00117          count(home, x, cards, icl);
00118        }
00119      };
00120      
00122      class IntAllMax : public Test {
00123      public:
00125        IntAllMax(Gecode::IntConLevel icl)
00126          : Test("GCC::Int::All::Max::"+str(icl), 4, 1,2, false, icl) {}
00128        virtual bool solution(const Assignment& x) const {
00129          int n[2];
00130          for (int i=2; i--; )
00131            n[i] = 0;
00132          for (int i=x.size(); i--; )
00133            n[x[i] - 1]++;
00134          if (n[0] != 2 || n[1] != 2)
00135            return false;
00136          return true;
00137        }
00139        virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00140          Gecode::IntArgs values(2, 1,2);
00141          Gecode::count(home, x, Gecode::IntSet(2,2), values, icl);
00142        }
00143      };
00144      
00145      
00147      template <bool hole>
00148      class IntSome : public Test {
00149      public:
00151        IntSome(Gecode::IntConLevel icl)
00152          : Test(std::string("GCC::Int::Some::")+
00153                 (hole ? "::Hole" : "::Full")+str(icl),4,1,4,false,icl) {}
00155        virtual bool solution(const Assignment& x) const {
00156          int n[4];
00157          for (int i=4; i--; )
00158            n[i]=0;
00159          for (int i=x.size(); i--; )
00160            n[x[i]-1]++;
00161          if ((n[0] < 2) || (n[1] < 2) || (n[2] > 0) || (n[3] > 0))
00162            return false;
00163          return true;
00164        }
00166        virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00167          using namespace Gecode;
00168          IntArgs values(2, 1,2);
00169          Gecode::IntSet fixed;
00170          if (!hole) {
00171            fixed = IntSet(0,2);
00172          } else {
00173            int ish[] = {0,2};
00174            fixed = IntSet(ish,2);
00175          }
00176          Gecode::IntSetArgs cards(2);
00177          cards[0]=fixed; cards[1]=fixed;
00178          count(home, x, cards, values, icl);
00179        }
00180      };
00181      
00183      class VarAll : public Test {
00184      protected:
00186        static const int n = 4;
00187      public:
00189        VarAll(Gecode::IntConLevel icl)
00190          : Test("GCC::Var::All::"+str(icl),7,0,2,false,icl) {}
00192        virtual bool solution(const Assignment& x) const {
00193          // Number of cardinality variables
00194          int m = x.size()-n;
00195          for (int i=0; i<n; i++)
00196            if ((x[i] < 0) || (x[i] > 2))
00197              return false;
00198          GECODE_AUTOARRAY(int, card, m);
00199          for (int i=0; i<m; i++) {
00200            card[i] = 0;
00201            if ((x[n+i] < 0) || (x[n+i] > 2))
00202              return false;
00203          }
00204          for (int i=0; i<n; i++)
00205            card[x[i]]++;
00206          for (int i=0; i<m; i++)
00207            if (card[i] != x[n+i])
00208              return false;
00209          return true;
00210        }
00212        virtual void post(Gecode::Space* home, Gecode::IntVarArray& xy) {
00213          using namespace Gecode;
00214          // Number of cardinality variables
00215          int m = xy.size()-n;
00216    
00217          IntVarArgs x(n), y(m);
00218          for (int i=0; i<n; i++)
00219            x[i]=xy[i];
00220          for (int i=0; i<m; i++)
00221            y[i]=xy[n+i];
00222          count(home, x, y, icl);
00223        }
00224      };
00225    
00227      class VarSome : public Test {
00228      protected:
00230        static const int n = 4;
00231      public:
00233        VarSome(Gecode::IntConLevel icl)
00234          : Test("GCC::Var::Some::"+str(icl),6,0,2,false,icl) {}
00236        virtual bool solution(const Assignment& x) const {
00237          // Number of cardinality variables
00238          int m = x.size()-n;
00239          for (int i=0; i<n; i++)
00240            if ((x[i] < 0) || (x[i] > 1))
00241              return false;
00242          GECODE_AUTOARRAY(int, card, m);
00243          for (int i=0; i<m; i++) {
00244            card[i] = 0;
00245            if ((x[n+i] < 0) || (x[n+i] > 2))
00246              return false;
00247          }
00248          for (int i=0; i<n; i++)
00249            card[x[i]]++;
00250          for (int i=0; i<m; i++)
00251            if (card[i] != x[n+i])
00252              return false;
00253          return true;
00254        }
00256        virtual void post(Gecode::Space* home, Gecode::IntVarArray& xy) {
00257          using namespace Gecode;
00258          // Number of cardinality variables
00259          int m = xy.size()-n;
00260          IntVarArgs x(n), y(m);
00261          for (int i=0; i<n; i++)
00262            x[i]=xy[i];
00263          for (int i=0; i<m; i++)
00264            y[i]=xy[n+i];
00265          IntArgs values(2, 0,1);
00266          count(home,x,y,values,icl);
00267        }
00268      };
00269    
00271      class Create {
00272      public:
00274        Create(void) {
00275          for (IntConLevels icls; icls(); ++icls) {
00276            (void) new IntAllMinMax(icls.icl());
00277            (void) new IntAllMinMaxDef(icls.icl());
00278            (void) new IntAllMax(icls.icl());
00279            (void) new IntSome<false>(icls.icl());
00280            (void) new IntSome<true>(icls.icl());
00281            (void) new VarAll(icls.icl());
00282            (void) new VarSome(icls.icl());
00283          }
00284        }
00285      };
00286    
00287      Create c;
00289    
00290    }
00291 }}
00292 
00293 // STATISTICS: test-int