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

element.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-07-11 09:36:57 +0200 (Fri, 11 Jul 2008) $ by $Author: tack $
00011  *     $Revision: 7295 $
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 #include "gecode/minimodel.hh"
00041 
00042 namespace Test { namespace Int {
00043 
00045    namespace Element {
00046    
00052 
00053      class IntIntVar : public Test {
00054      protected:
00056        Gecode::IntArgs c;
00057      public:
00059        IntIntVar(const std::string& s, const Gecode::IntArgs& c0)
00060          : Test("Element::Int::Int::Var::"+s,2,-4,8), c(c0) {}
00062        virtual bool solution(const Assignment& x) const {
00063          return (x[0]>= 0) && (x[0]<c.size()) && c[x[0]]==x[1];
00064        }
00066        virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00067          Gecode::element(home, c, x[0], x[1]);
00068        }
00069      };
00070    
00072      class IntIntInt : public Test {
00073      protected:
00075        Gecode::IntArgs c;
00077        int r;
00078      public:
00080        IntIntInt(const std::string& s, const Gecode::IntArgs& c0, int r0)
00081          : Test("Element::Int::Int::Int::"+s+"::"+str(r0),1,-4,8), 
00082            c(c0), r(r0) {}
00084        virtual bool solution(const Assignment& x) const {
00085          return (x[0]>= 0) && (x[0]<c.size()) && c[x[0]]==r;
00086        }
00088        virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00089          Gecode::element(home, c, x[0], r);
00090        }
00091      };
00092    
00094      class IntIntShared : public Test {
00095      protected:
00097        Gecode::IntArgs c;
00098      public:
00100        IntIntShared(const std::string& s, const Gecode::IntArgs& c0,
00101                     int minDomain=-4)
00102          : Test("Element::Int::Int::Shared::"+s,1,minDomain,8), c(c0) {}
00104        virtual bool solution(const Assignment& x) const {
00105          return (x[0]>= 0) && (x[0]<c.size()) && c[x[0]]==x[0];
00106        }
00108        virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00109          Gecode::element(home, c, x[0], x[0]);
00110        }
00111      };
00112    
00114      class IntBoolVar : public Test {
00115      protected:
00117        Gecode::IntArgs c;
00118      public:
00120        IntBoolVar(const std::string& s, const Gecode::IntArgs& c0)
00121          : Test("Element::Int::Bool::Var::"+s,2,-4,8), c(c0) {}
00123        virtual bool solution(const Assignment& x) const {
00124          return (x[0]>= 0) && (x[0]<c.size()) && c[x[0]]==x[1];
00125        }
00127        virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00128          Gecode::element(home, c, x[0], Gecode::channel(home,x[1]));
00129        }
00130      };
00131    
00133      class IntBoolInt : public Test {
00134      protected:
00136        Gecode::IntArgs c;
00138        int r;
00139      public:
00141        IntBoolInt(const std::string& s, const Gecode::IntArgs& c0, int r0)
00142          : Test("Element::Int::Bool::Int::"+s+"::"+str(r0),1,-4,8), 
00143            c(c0), r(r0) {}
00145        virtual bool solution(const Assignment& x) const {
00146          return (x[0]>= 0) && (x[0]<c.size()) && c[x[0]]==r;
00147        }
00149        virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00150          Gecode::element(home, c, x[0], r);
00151        }
00152      };
00153    
00155      class VarIntVar : public Test {
00156      public:
00158        VarIntVar(Gecode::IntConLevel icl)
00159          : Test("Element::Var::Int::Var::"+str(icl),6,-1,3,false,icl) {}
00161        virtual bool solution(const Assignment& x) const {
00162          return (x[0]>= 0) && (x[0]<x.size()-2) && x[2+x[0]]==x[1];
00163        }
00165        virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00166          Gecode::IntVarArgs c(x.size()-2);
00167          for (int i=0; i<x.size()-2; i++)
00168            c[i]=x[2+i];
00169          Gecode::element(home, c, x[0], x[1], icl);
00170        }
00171      };
00172    
00174      class VarIntInt : public Test {
00175      protected:
00177        int r;
00178      public:
00180        VarIntInt(Gecode::IntConLevel icl, int r0)
00181          : Test("Element::Var::Int::Int::"+str(icl)+"::"+str(r0),
00182                 5,-1,3,false,icl), r(r0) {
00183          testdomcon = false;
00184        }
00186        virtual bool solution(const Assignment& x) const {
00187          return (x[0]>= 0) && (x[0]<x.size()-1) && x[1+x[0]]==r;
00188        }
00190        virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00191          Gecode::IntVarArgs c(x.size()-1);
00192          for (int i=0; i<x.size()-1; i++)
00193            c[i]=x[1+i];
00194          Gecode::element(home, c, x[0], r, icl);
00195        }
00196      };
00197    
00199      class VarIntShared : public Test {
00200      public:
00202        VarIntShared(Gecode::IntConLevel icl)
00203          : Test("Element::Var::Int::Shared::"+str(icl),5,-1,3,false,icl) {}
00205        virtual bool solution(const Assignment& x) const {
00206          return (x[0]>= 0) && (x[0]<x.size()-1) && x[1+x[0]]==x[0];
00207        }
00209        virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00210          Gecode::IntVarArgs c(x.size()-1);
00211          for (int i=0; i<x.size()-1; i++)
00212            c[i]=x[1+i];
00213          Gecode::element(home, c, x[0], x[0], icl);
00214        }
00215      };
00216    
00218      class VarBoolVar : public Test {
00219      public:
00221        VarBoolVar(void) : Test("Element::Var::Bool::Var",6,-1,3,false) {}
00223        virtual bool solution(const Assignment& x) const {
00224          for (int i=0; i<x.size()-2; i++)
00225            if ((x[2+i] < 0) || (x[2+i]>1))
00226              return false;
00227          return ((x[0]>= 0) && (x[0]<x.size()-2) && x[2+x[0]]==x[1] 
00228                  && (x[1]>=0) && (x[1]<=1));
00229        }
00231        virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00232          using namespace Gecode;
00233          BoolVarArgs c(x.size()-2);
00234          for (int i=0; i<x.size()-2; i++)
00235            c[i]=channel(home,x[2+i]);
00236          element(home, c, x[0], channel(home,x[1]));
00237        }
00238      };
00239    
00241      class VarBoolInt : public Test {
00242      protected:
00244        int r;
00245      public:
00247        VarBoolInt(int r0) 
00248          : Test("Element::Var::Bool::Int::"+str(r0),5,-1,3,false), r(r0) {}
00250        virtual bool solution(const Assignment& x) const {
00251          for (int i=0; i<x.size()-1; i++)
00252            if ((x[1+i] < 0) || (x[1+i]>1))
00253              return false;
00254          return ((x[0]>= 0) && (x[0]<x.size()-1) && x[1+x[0]]==r);
00255        }
00257        virtual void post(Gecode::Space* home, Gecode::IntVarArray& x) {
00258          using namespace Gecode;
00259          BoolVarArgs c(x.size()-1);
00260          for (int i=0; i<x.size()-1; i++)
00261            c[i]=channel(home,x[1+i]);
00262          element(home, c, x[0], r);
00263        }
00264      };
00265    
00267      class Create {
00268      public:
00270        Create(void) {
00271          using namespace Gecode;
00272          IntArgs ic1(5, -1,1,-3,3,-4);
00273          IntArgs ic2(8, -1,1,-1,1,-1,1,0,0);
00274          IntArgs ic3(1, -1);
00275          IntArgs ic4(7, 0,-1,2,-2,4,-3,6);
00276          IntArgs ic5(6, 0,0,1,2,3,4);
00277          
00278          IntArgs bc1(5, 0,1,1,0,1);
00279          IntArgs bc2(8, 1,1,0,1,0,1,0,0);
00280          IntArgs bc3(1, 1);
00281    
00282          (void) new IntIntVar("A",ic1);
00283          (void) new IntIntVar("B",ic2);
00284          (void) new IntIntVar("C",ic3);
00285          (void) new IntIntVar("D",ic4);
00286 
00287          for (int i=-4; i<=4; i++) {
00288            (void) new IntIntInt("A",ic1,i);
00289            (void) new IntIntInt("B",ic2,i);
00290            (void) new IntIntInt("C",ic3,i);
00291            (void) new IntIntInt("D",ic4,i);
00292          }
00293          
00294          (void) new IntIntShared("A",ic1);
00295          (void) new IntIntShared("B",ic2);
00296          (void) new IntIntShared("C",ic3);
00297          (void) new IntIntShared("D",ic4);
00298          (void) new IntIntShared("E",ic5,1);
00299          
00300          (void) new IntBoolVar("A",bc1);
00301          (void) new IntBoolVar("B",bc2);
00302          (void) new IntBoolVar("C",bc3);
00303          
00304          for (int i=0; i<=1; i++) {
00305            (void) new IntBoolInt("A",bc1,i);
00306            (void) new IntBoolInt("B",bc2,i);
00307            (void) new IntBoolInt("C",bc3,i);
00308          }
00309 
00310          (void) new VarIntVar(ICL_BND);
00311          (void) new VarIntVar(ICL_DOM);
00312 
00313          for (int i=-4; i<=4; i++) {
00314            (void) new VarIntInt(ICL_BND,i);
00315            (void) new VarIntInt(ICL_DOM,i);
00316          }
00317          
00318          (void) new VarIntShared(ICL_BND);
00319          (void) new VarIntShared(ICL_DOM);
00320      
00321          (void) new VarBoolVar();
00322          (void) new VarBoolInt(0);
00323          (void) new VarBoolInt(1);
00324        }
00325      };
00326    
00327      Create c;
00329    
00330    }
00331 }}
00332 
00333 // STATISTICS: test-int