Generated on Thu Mar 22 10:39:37 2012 for Gecode by doxygen 1.6.3

int.hpp

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: 2010-06-03 13:11:11 +0200 (Thu, 03 Jun 2010) $ by $Author: tack $
00013  *     $Revision: 11013 $
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   forceinline int
00113   RandomMixAssignment::randval(const Gecode::IntSet& d) {
00114     unsigned int skip = Base::rand(d.size());
00115     for (Gecode::IntSetRanges it(d); true; ++it) {
00116       if (it.width() > skip)
00117         return it.min() + static_cast<int>(skip);
00118       skip -= it.width();
00119     }
00120     GECODE_NEVER;
00121     return 0;
00122   }
00123 
00124   inline
00125   RandomMixAssignment::RandomMixAssignment(int n0, const Gecode::IntSet& d0,
00126                                            int n1, const Gecode::IntSet& d1, 
00127                                            int a0)
00128     : Assignment(n0+n1,d0),vals(new int[n0+n1]),a(a0),_n1(n1),_d1(d1) {
00129     for (int i=n0; i--; )
00130       vals[i] = randval(d);
00131     for (int i=n1; i--; )
00132       vals[n0+i] = randval(_d1);
00133   }
00134 
00135   inline bool
00136   RandomMixAssignment::operator()(void) const {
00137     return a>0;
00138   }
00139 
00140   inline int
00141   RandomMixAssignment::operator[](int i) const {
00142     assert((i>=0) && (i<n));
00143     return vals[i];
00144   }
00145 
00146   inline
00147   RandomMixAssignment::~RandomMixAssignment(void) {
00148     delete [] vals;
00149   }
00150 
00151   /*
00152    * Tests with integer constraints
00153    *
00154    */
00155   inline
00156   Test::Test(const std::string& s, int a, const Gecode::IntSet& d,
00157              bool r, Gecode::IntConLevel i)
00158     : Base("Int::"+s), arity(a), dom(d), reified(r), icl(i),
00159       contest(icl == Gecode::ICL_DOM ? CTL_DOMAIN : CTL_NONE),
00160       testsearch(true), testfix(true) {}
00161 
00162   inline
00163   Test::Test(const std::string& s, int a, int min, int max,
00164              bool r, Gecode::IntConLevel i)
00165     : Base("Int::"+s), arity(a), dom(min,max), reified(r), icl(i),
00166       contest(icl == Gecode::ICL_DOM ? CTL_DOMAIN : CTL_NONE),
00167       testsearch(true), testfix(true) {}
00168 
00169   inline
00170   std::string
00171   Test::str(Gecode::ExtensionalPropKind epk) {
00172     using namespace Gecode;
00173     switch (epk) {
00174     case EPK_MEMORY: return "Memory";
00175     case EPK_SPEED:  return "Speed";
00176     default: return "Def";
00177     }
00178   }
00179 
00180   inline
00181   std::string
00182   Test::str(Gecode::IntConLevel icl) {
00183     using namespace Gecode;
00184     switch (icl) {
00185     case ICL_VAL: return "Val";
00186     case ICL_BND: return "Bnd";
00187     case ICL_DOM: return "Dom";
00188     default: return "Def";
00189     }
00190   }
00191 
00192   inline
00193   std::string
00194   Test::str(Gecode::IntRelType irt) {
00195     using namespace Gecode;
00196     switch (irt) {
00197     case IRT_LQ: return "Lq";
00198     case IRT_LE: return "Le";
00199     case IRT_GQ: return "Gq";
00200     case IRT_GR: return "Gr";
00201     case IRT_EQ: return "Eq";
00202     case IRT_NQ: return "Nq";
00203     default: ;
00204     }
00205     GECODE_NEVER;
00206     return "NONE";
00207   }
00208 
00209   inline std::string
00210   Test::str(Gecode::BoolOpType bot) {
00211     using namespace Gecode;
00212     switch (bot) {
00213     case BOT_AND: return "And";
00214     case BOT_OR:  return "Or";
00215     case BOT_IMP: return "Imp";
00216     case BOT_EQV: return "Eqv";
00217     case BOT_XOR: return "Xor";
00218     default: GECODE_NEVER;
00219     }
00220     GECODE_NEVER;
00221     return "NONE";
00222   }
00223 
00224   inline
00225   std::string
00226   Test::str(int i) {
00227     std::stringstream s;
00228     s << i;
00229     return s.str();
00230   }
00231 
00232   inline
00233   std::string
00234   Test::str(const Gecode::IntArgs& x) {
00235     std::string s = "";
00236     for (int i=0; i<x.size()-1; i++)
00237       s += str(x[i]) + ",";
00238     return "[" + s + str(x[x.size()-1]) + "]";
00239   }
00240 
00241   template<class T>
00242   inline bool
00243   Test::cmp(T x, Gecode::IntRelType r, T y) {
00244     using namespace Gecode;
00245     switch (r) {
00246     case IRT_EQ: return x == y;
00247     case IRT_NQ: return x != y;
00248     case IRT_LQ: return x <= y;
00249     case IRT_LE: return x < y;
00250     case IRT_GR: return x > y;
00251     case IRT_GQ: return x >= y;
00252     default: ;
00253     }
00254     return false;
00255   }
00256 
00257 
00258   inline
00259   IntConLevels::IntConLevels(void)
00260     : i(sizeof(icls)/sizeof(Gecode::IntConLevel)-1) {}
00261   inline bool
00262   IntConLevels::operator()(void) const {
00263     return i>=0;
00264   }
00265   inline void
00266   IntConLevels::operator++(void) {
00267     i--;
00268   }
00269   inline Gecode::IntConLevel
00270   IntConLevels::icl(void) const {
00271     return icls[i];
00272   }
00273 
00274 
00275   inline
00276   IntRelTypes::IntRelTypes(void)
00277     : i(sizeof(irts)/sizeof(Gecode::IntRelType)-1) {}
00278   inline void
00279   IntRelTypes::reset(void) {
00280     i = sizeof(irts)/sizeof(Gecode::IntRelType)-1;
00281   }
00282   inline bool
00283   IntRelTypes::operator()(void) const {
00284     return i>=0;
00285   }
00286   inline void
00287   IntRelTypes::operator++(void) {
00288     i--;
00289   }
00290   inline Gecode::IntRelType
00291   IntRelTypes::irt(void) const {
00292     return irts[i];
00293   }
00294 
00295   inline
00296   BoolOpTypes::BoolOpTypes(void)
00297     : i(sizeof(bots)/sizeof(Gecode::BoolOpType)-1) {}
00298   inline bool
00299   BoolOpTypes::operator()(void) const {
00300     return i>=0;
00301   }
00302   inline void
00303   BoolOpTypes::operator++(void) {
00304     i--;
00305   }
00306   inline Gecode::BoolOpType
00307   BoolOpTypes::bot(void) const {
00308     return bots[i];
00309   }
00310 
00311 }}
00312 
00313 // STATISTICS: test-int
00314