Generated on Tue Apr 18 10:21:54 2017 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: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
00013  *     $Revision: 14967 $
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   forceinline bool
00156   Test::eqv(void) const {
00157     return reified && ((rms & (1 << Gecode::RM_EQV)) != 0);
00158   }
00159   forceinline bool
00160   Test::imp(void) const {
00161     return reified && ((rms & (1 << Gecode::RM_IMP)) != 0);
00162   }
00163   forceinline bool
00164   Test::pmi(void) const {
00165     return reified && ((rms & (1 << Gecode::RM_PMI)) != 0);
00166   }
00167   inline
00168   Test::Test(const std::string& p, const std::string& s,
00169              int a, const Gecode::IntSet& d, bool r,
00170              Gecode::IntPropLevel i)
00171     : Base(p+s), arity(a), dom(d),
00172       reified(r), rms((1 << Gecode::RM_EQV) ||
00173                       (1 << Gecode::RM_IMP) ||
00174                       (1 << Gecode::RM_PMI)),
00175       ipl(i), contest(ipl == Gecode::IPL_DOM ? CTL_DOMAIN : CTL_NONE),
00176       testsearch(true), testfix(true) {}
00177 
00178   inline
00179   Test::Test(const std::string& s,
00180              int a, const Gecode::IntSet& d, bool r,
00181              Gecode::IntPropLevel i)
00182     : Base("Int::"+s), arity(a), dom(d),
00183       reified(r), rms((1 << Gecode::RM_EQV) ||
00184                       (1 << Gecode::RM_IMP) ||
00185                       (1 << Gecode::RM_PMI)),
00186       ipl(i), contest(ipl == Gecode::IPL_DOM ? CTL_DOMAIN : CTL_NONE),
00187       testsearch(true), testfix(true) {}
00188 
00189   inline
00190   Test::Test(const std::string& p, const std::string& s,
00191              int a, int min, int max, bool r,
00192              Gecode::IntPropLevel i)
00193     : Base(p+s), arity(a), dom(min,max),
00194       reified(r), rms((1 << Gecode::RM_EQV) ||
00195                       (1 << Gecode::RM_IMP) ||
00196                       (1 << Gecode::RM_PMI)),
00197       ipl(i), contest(ipl == Gecode::IPL_DOM ? CTL_DOMAIN : CTL_NONE),
00198       testsearch(true), testfix(true) {}
00199 
00200   inline
00201   Test::Test(const std::string& s,
00202              int a, int min, int max, bool r, Gecode::IntPropLevel i)
00203     : Base("Int::"+s), arity(a), dom(min,max),
00204       reified(r), rms((1 << Gecode::RM_EQV) ||
00205                       (1 << Gecode::RM_IMP) ||
00206                       (1 << Gecode::RM_PMI)),
00207       ipl(i), contest(ipl == Gecode::IPL_DOM ? CTL_DOMAIN : CTL_NONE),
00208       testsearch(true), testfix(true) {}
00209 
00210   inline
00211   std::string
00212   Test::str(Gecode::IntPropLevel ipl) {
00213     using namespace Gecode;
00214     std::stringstream s;
00215     switch (vbd(ipl)) {
00216     case IPL_VAL: s << "Val"; break;
00217     case IPL_BND: s << "Bnd"; break;
00218     case IPL_DOM: s << "Dom"; break;
00219     default: s << "Def"; break;
00220     }
00221     if (ipl & IPL_SPEED) s << "+S";
00222     if (ipl & IPL_MEMORY) s << "+M";
00223     if (ipl & IPL_BASIC) s << "+B";
00224     if (ipl & IPL_ADVANCED) s << "+A";
00225     return s.str();
00226   }
00227 
00228   inline
00229   std::string
00230   Test::str(Gecode::IntRelType irt) {
00231     using namespace Gecode;
00232     switch (irt) {
00233     case IRT_LQ: return "Lq";
00234     case IRT_LE: return "Le";
00235     case IRT_GQ: return "Gq";
00236     case IRT_GR: return "Gr";
00237     case IRT_EQ: return "Eq";
00238     case IRT_NQ: return "Nq";
00239     default: ;
00240     }
00241     GECODE_NEVER;
00242     return "NONE";
00243   }
00244 
00245   inline std::string
00246   Test::str(Gecode::BoolOpType bot) {
00247     using namespace Gecode;
00248     switch (bot) {
00249     case BOT_AND: return "And";
00250     case BOT_OR:  return "Or";
00251     case BOT_IMP: return "Imp";
00252     case BOT_EQV: return "Eqv";
00253     case BOT_XOR: return "Xor";
00254     default: GECODE_NEVER;
00255     }
00256     GECODE_NEVER;
00257     return "NONE";
00258   }
00259 
00260   inline
00261   std::string
00262   Test::str(int i) {
00263     std::stringstream s;
00264     s << i;
00265     return s.str();
00266   }
00267 
00268   inline
00269   std::string
00270   Test::str(const Gecode::IntArgs& x) {
00271     std::string s = "";
00272     for (int i=0; i<x.size()-1; i++)
00273       s += str(x[i]) + ",";
00274     return "[" + s + str(x[x.size()-1]) + "]";
00275   }
00276 
00277   template<class T>
00278   inline bool
00279   Test::cmp(T x, Gecode::IntRelType r, T y) {
00280     using namespace Gecode;
00281     switch (r) {
00282     case IRT_EQ: return x == y;
00283     case IRT_NQ: return x != y;
00284     case IRT_LQ: return x <= y;
00285     case IRT_LE: return x < y;
00286     case IRT_GR: return x > y;
00287     case IRT_GQ: return x >= y;
00288     default: ;
00289     }
00290     return false;
00291   }
00292 
00293 
00294 
00295   inline
00296   IntPropLevels::IntPropLevels(void)
00297     : i(sizeof(ipls)/sizeof(Gecode::IntPropLevel)-1) {}
00298   inline bool
00299   IntPropLevels::operator()(void) const {
00300     return i>=0;
00301   }
00302   inline void
00303   IntPropLevels::operator++(void) {
00304     i--;
00305   }
00306   inline Gecode::IntPropLevel
00307   IntPropLevels::ipl(void) const {
00308     return ipls[i];
00309   }
00310 
00311 
00312   inline
00313   IntPropBasicAdvanced::IntPropBasicAdvanced(void)
00314     : i(sizeof(ipls)/sizeof(Gecode::IntPropLevel)-1) {}
00315   inline bool
00316   IntPropBasicAdvanced::operator()(void) const {
00317     return i>=0;
00318   }
00319   inline void
00320   IntPropBasicAdvanced::operator++(void) {
00321     i--;
00322   }
00323   inline Gecode::IntPropLevel
00324   IntPropBasicAdvanced::ipl(void) const {
00325     return ipls[i];
00326   }
00327 
00328 
00329   inline
00330   IntRelTypes::IntRelTypes(void)
00331     : i(sizeof(irts)/sizeof(Gecode::IntRelType)-1) {}
00332   inline void
00333   IntRelTypes::reset(void) {
00334     i = sizeof(irts)/sizeof(Gecode::IntRelType)-1;
00335   }
00336   inline bool
00337   IntRelTypes::operator()(void) const {
00338     return i>=0;
00339   }
00340   inline void
00341   IntRelTypes::operator++(void) {
00342     i--;
00343   }
00344   inline Gecode::IntRelType
00345   IntRelTypes::irt(void) const {
00346     return irts[i];
00347   }
00348 
00349   inline
00350   BoolOpTypes::BoolOpTypes(void)
00351     : i(sizeof(bots)/sizeof(Gecode::BoolOpType)-1) {}
00352   inline bool
00353   BoolOpTypes::operator()(void) const {
00354     return i>=0;
00355   }
00356   inline void
00357   BoolOpTypes::operator++(void) {
00358     i--;
00359   }
00360   inline Gecode::BoolOpType
00361   BoolOpTypes::bot(void) const {
00362     return bots[i];
00363   }
00364 
00365 }}
00366 
00367 // STATISTICS: test-int
00368