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

int.icc

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  *     Mikael Lagerkvist <lagerkvist@gecode.org>
00006  *
00007  *  Copyright:
00008  *     Christian Schulte, 2005
00009  *     Mikael Lagerkvist, 2006
00010  *
00011  *  Last modified:
00012  *     $Date: 2008-02-26 10:40:46 +0100 (Tue, 26 Feb 2008) $ by $Author: schulte $
00013  *     $Revision: 6311 $
00014  *
00015  *  This file is part of Gecode, the generic constraint
00016  *  development environment:
00017  *     http://www.gecode.org
00018  *
00019  *  Permission is hereby granted, free of charge, to any person obtaining
00020  *  a copy of this software and associated documentation files (the
00021  *  "Software"), to deal in the Software without restriction, including
00022  *  without limitation the rights to use, copy, modify, merge, publish,
00023  *  distribute, sublicense, and/or sell copies of the Software, and to
00024  *  permit persons to whom the Software is furnished to do so, subject to
00025  *  the following conditions:
00026  *
00027  *  The above copyright notice and this permission notice shall be
00028  *  included in all copies or substantial portions of the Software.
00029  *
00030  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00031  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00032  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00033  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00034  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00035  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00036  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00037  *
00038  */
00039 
00040 namespace Test { namespace Int {
00041 
00042   /*
00043    * Assignments
00044    *
00045    */
00046   inline
00047   Assignment::Assignment(int n0, const Gecode::IntSet& d0)
00048     : n(n0), d(d0) {}
00049   inline int
00050   Assignment::size(void) const {
00051     return n;
00052   }
00053   inline
00054   Assignment::~Assignment(void) {}
00055   
00056   
00057   inline
00058   CpltAssignment::CpltAssignment(int n, const Gecode::IntSet& d)
00059     : Assignment(n,d), 
00060       dsv(new Gecode::IntSetValues[static_cast<unsigned int>(n)]) {
00061     for (int i=n; i--; )
00062       dsv[i].init(d);
00063   }
00064   inline bool
00065   CpltAssignment::operator()(void) const {
00066     return dsv[0]();
00067   }
00068   inline int
00069   CpltAssignment::operator[](int i) const {
00070     assert((i>=0) && (i<n));
00071     return dsv[i].val();
00072   }
00073   inline 
00074   CpltAssignment::~CpltAssignment(void) {
00075     delete [] dsv;
00076   }
00077   
00078   
00079   forceinline int
00080   RandomAssignment::randval(void) {
00081     unsigned int skip = Base::rand(d.size());
00082     for (Gecode::IntSetRanges it(d); true; ++it) {
00083       if (it.width() > skip)
00084         return it.min() + static_cast<int>(skip);
00085       skip -= it.width();
00086     }
00087     GECODE_NEVER;
00088     return 0;
00089   }
00090 
00091   inline
00092   RandomAssignment::RandomAssignment(int n, const Gecode::IntSet& d, int a0)
00093     : Assignment(n,d), vals(new int[n]), a(a0) {
00094     for (int i=n; i--; )
00095       vals[i] = randval();
00096   }
00097   
00098   inline bool
00099   RandomAssignment::operator()(void) const {
00100     return a>0;
00101   }
00102   inline int
00103   RandomAssignment::operator[](int i) const {
00104     assert((i>=0) && (i<n));
00105     return vals[i];
00106   }
00107   inline
00108   RandomAssignment::~RandomAssignment(void) {
00109     delete [] vals;
00110   }
00111 
00112 
00113 
00114   /*
00115    * Tests with integer constraints
00116    *
00117    */
00118   inline
00119   Test::Test(const std::string& s, int a, const Gecode::IntSet& d, 
00120              bool r, Gecode::IntConLevel i, Gecode::PropKind p)
00121     : Base("Int::"+s), arity(a), dom(d), reified(r), icl(i), pk(p),
00122       testdomcon(true), testsearch(true) {}
00123 
00124   inline
00125   Test::Test(const std::string& s, int a, int min, int max, 
00126              bool r, Gecode::IntConLevel i, Gecode::PropKind p)
00127     : Base("Int::"+s), arity(a), dom(min,max), reified(r), icl(i), pk(p), 
00128       testdomcon(true), testsearch(true) {}
00129 
00130   inline
00131   std::string
00132   Test::str(Gecode::PropKind pk) {
00133     using namespace Gecode;
00134     switch (pk) {
00135     case PK_MEMORY: return "Memory";
00136     case PK_SPEED:  return "Speed";
00137     default: return "Def";
00138     }
00139   }
00140   
00141   inline
00142   std::string
00143   Test::str(Gecode::IntConLevel icl) {
00144     using namespace Gecode;
00145     switch (icl) {
00146     case ICL_VAL: return "Val";
00147     case ICL_BND: return "Bnd";
00148     case ICL_DOM: return "Dom";
00149     default: return "Def";
00150     }
00151   }
00152   
00153   inline
00154   std::string
00155   Test::str(Gecode::IntRelType irt) {
00156     using namespace Gecode;
00157     switch (irt) {
00158     case IRT_LQ: return "Lq";
00159     case IRT_LE: return "Le";
00160     case IRT_GQ: return "Gq";
00161     case IRT_GR: return "Gr";
00162     case IRT_EQ: return "Eq";
00163     case IRT_NQ: return "Nq";
00164     default: ;
00165     }
00166     GECODE_NEVER;
00167     return "NONE";
00168   }
00169   
00170   inline std::string 
00171   Test::str(Gecode::BoolOpType bot) {
00172     using namespace Gecode;
00173     switch (bot) {
00174     case BOT_AND: return "And";
00175     case BOT_OR:  return "Or";
00176     case BOT_IMP: return "Imp";
00177     case BOT_EQV: return "Eqv";
00178     case BOT_XOR: return "Xor";
00179     default: GECODE_NEVER;
00180     }
00181     GECODE_NEVER;
00182     return "NONE";
00183   }
00184 
00185   inline
00186   std::string
00187   Test::str(int i) {
00188     std::stringstream s;
00189     s << i;
00190     return s.str();
00191   }
00192   
00193   template<class T>
00194   inline bool
00195   Test::cmp(T x, Gecode::IntRelType r, T y) {
00196     using namespace Gecode;
00197     switch (r) {
00198     case IRT_EQ: return x == y;
00199     case IRT_NQ: return x != y;
00200     case IRT_LQ: return x <= y;
00201     case IRT_LE: return x < y;
00202     case IRT_GR: return x > y;
00203     case IRT_GQ: return x >= y;
00204     default: ;
00205     }
00206     return false;
00207   }
00208   
00209   
00210   inline
00211   IntConLevels::IntConLevels(void) 
00212     : i(sizeof(icls)/sizeof(Gecode::IntConLevel)-1) {}
00213   inline bool 
00214   IntConLevels::operator()(void) const {
00215     return i>=0;
00216   }
00217   inline void 
00218   IntConLevels::operator++(void) {
00219     i--;
00220   }
00221   inline Gecode::IntConLevel 
00222   IntConLevels::icl(void) const {
00223     return icls[i];
00224   }
00225 
00226 
00227   inline
00228   IntRelTypes::IntRelTypes(void) 
00229     : i(sizeof(irts)/sizeof(Gecode::IntRelType)-1) {}
00230   inline void
00231   IntRelTypes::reset(void) {
00232     i = sizeof(irts)/sizeof(Gecode::IntRelType)-1;
00233   }
00234   inline bool 
00235   IntRelTypes::operator()(void) const {
00236     return i>=0;
00237   }
00238   inline void 
00239   IntRelTypes::operator++(void) {
00240     i--;
00241   }
00242   inline Gecode::IntRelType
00243   IntRelTypes::irt(void) const {
00244     return irts[i];
00245   }
00246 
00247   inline
00248   BoolOpTypes::BoolOpTypes(void) 
00249     : i(sizeof(bots)/sizeof(Gecode::BoolOpType)-1) {}
00250   inline bool 
00251   BoolOpTypes::operator()(void) const {
00252     return i>=0;
00253   }
00254   inline void 
00255   BoolOpTypes::operator++(void) {
00256     i--;
00257   }
00258   inline Gecode::BoolOpType
00259   BoolOpTypes::bot(void) const {
00260     return bots[i];
00261   }
00262 
00263 }}
00264 
00265 // STATISTICS: test-int
00266