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

atmost.cc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Guido Tack <tack@gecode.org>
00004  *
00005  *  Copyright:
00006  *     Guido Tack, 2005
00007  *
00008  *  Last modified:
00009  *     $Date: 2007-09-13 21:30:38 +0200 (Thu, 13 Sep 2007) $ by $Author: tack $
00010  *     $Revision: 5029 $
00011  *
00012  *  This file is part of Gecode, the generic constraint
00013  *  development environment:
00014  *     http://www.gecode.org
00015  *
00016  *  Permission is hereby granted, free of charge, to any person obtaining
00017  *  a copy of this software and associated documentation files (the
00018  *  "Software"), to deal in the Software without restriction, including
00019  *  without limitation the rights to use, copy, modify, merge, publish,
00020  *  distribute, sublicense, and/or sell copies of the Software, and to
00021  *  permit persons to whom the Software is furnished to do so, subject to
00022  *  the following conditions:
00023  *
00024  *  The above copyright notice and this permission notice shall be
00025  *  included in all copies or substantial portions of the Software.
00026  *
00027  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00028  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00029  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00030  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00031  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00032  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00033  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00034  *
00035  */
00036 
00037 #include "test/cpltset.hh"
00038 
00039 using namespace Gecode;
00040 using namespace Test::Set;
00041 
00042 namespace Test { namespace CpltSet {
00043 
00045   namespace AtMost {
00046 
00052 
00053     static const int d1r[4][2] = {
00054       {-4,-3},{-1,-1},{1,1},{3,5}
00055     };
00056     static IntSet d1(d1r,4);
00057 
00058     static IntSet ds_33(-3,3);
00059     static IntSet ds_4(4,4);
00060     static IntSet ds_13(1,3);
00061 
00063     class CpltSetAtmost : public CpltSetTest {
00064     public:
00066       CpltSetAtmost(const char* t) : CpltSetTest(t,2,ds_13,false) {}
00068       virtual bool solution(const SetAssignment& x) const {
00069         CountableSetRanges xr1(x.lub, x[0]);
00070         CountableSetRanges xr2(x.lub, x[1]);
00071 
00072         Iter::Ranges::Inter<CountableSetRanges, CountableSetRanges>
00073           d(xr1, xr2);
00074         int c = 0;
00075         while (d()) {
00076           c += d.width();
00077           ++d;
00078         }
00079         return (c <= 1);
00080       }
00081 
00083       virtual void post(Space* home, CpltSetVarArray& x, IntVarArray&) {
00084         // Test lex-bit order
00085         Gecode::atmost(home, x[0], x[1], 1);
00086       }
00087     };
00088     CpltSetAtmost _cpltsetatmost("Atmost::1");
00089 
00091     class CpltSetAtmostLexLe : public CpltSetTest {
00092     public:
00094       CpltSetAtmostLexLe(const char* t) : CpltSetTest(t,2,ds_13,false) {}
00096       virtual bool solution(const SetAssignment& x) const {
00097         CountableSetRanges xr1(x.lub, x[0]);
00098         CountableSetRanges xr2(x.lub, x[1]);
00099 
00100         Iter::Ranges::Inter<CountableSetRanges, CountableSetRanges>
00101           d(xr1, xr2);
00102         int c = 0;
00103         while (d()) {
00104           c += d.width();
00105           ++d;
00106         }
00107 
00108         CountableSetValues xv1(x.lub, x[0]);
00109         CountableSetValues xv2(x.lub, x[1]);
00110         int a = iter2int(xv1, 3);
00111         int b = iter2int(xv2, 3);
00112     
00113         return (c <= 1) && a < b;
00114       }
00115 
00117       virtual void post(Space* home, CpltSetVarArray& x, IntVarArray&) {
00118         // Test lex-bit order
00119         Gecode::atmostLex(home, x[0], x[1], 1, SRT_LE);
00120       }
00121     };
00122     CpltSetAtmostLexLe _cpltsetatmostlexle("Atmost::Lex::Le");
00123 
00125     class CpltSetAtmostIntSet : public CpltSetTest {
00126     public:
00128       CpltSetAtmostIntSet(const char* t) : CpltSetTest(t,1,ds_33,false) {}
00130       virtual bool solution(const SetAssignment& x) const {
00131         CountableSetRanges xr1(x.lub, x[0]);
00132         IntSetRanges ir(ds_33);
00133         Iter::Ranges::Inter<CountableSetRanges, IntSetRanges>  d(xr1, ir);
00134         int c = 0;
00135         while (d()) {
00136           c += d.width();
00137           ++d;
00138         }
00139     
00140         return (c <= 1);
00141       }
00142 
00144       virtual void post(Space* home, CpltSetVarArray& x, IntVarArray&) {
00145         // Test lex-bit order
00146         Gecode::atmost(home, x[0], ds_33, 1);
00147       }
00148     };
00149     CpltSetAtmostIntSet _cpltsetatmostintset("Atmost::IntSet");
00150 
00152 
00153 }}}
00154 
00155 // STATISTICS: test-cpltset