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

partition.cc

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Guido Tack <tack@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Guido Tack, 2005
00008  *
00009  *  Last modified:
00010  *     $Date: 2007-11-09 10:29:51 +0100 (Fri, 09 Nov 2007) $ by $Author: tack $
00011  *     $Revision: 5228 $
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/cpltset.hh"
00039 
00040 using namespace Gecode;
00041 using namespace Test::Set;
00042 
00043 namespace Test { namespace CpltSet {
00044 
00046   namespace Partition {
00047 
00053 
00054     static const int d1r[2][2] = {
00055       {-4,-4},{3,5}
00056     };
00057     static IntSet d1(d1r,2);
00058 
00059     static IntSet ds_33(-3,3);
00060     static IntSet ds_4(4,4);
00061     static IntSet ds_13(1,3);
00062 
00064     class CpltSetPartition : public CpltSetTest {
00065     public:
00067       CpltSetPartition(const char* t) : CpltSetTest(t,2,ds_13,false) {}
00069       virtual bool solution(const SetAssignment& x) const {
00070         CountableSetRanges xr1(x.lub, x[0]);
00071         CountableSetRanges xr2(x.lub, x[1]);
00072 
00073         Iter::Ranges::Inter<CountableSetRanges, CountableSetRanges>
00074           d(xr1, xr2);
00075         Iter::Ranges::Union<CountableSetRanges, CountableSetRanges>
00076           u(xr1, xr2);
00077         IntSetRanges ir(ds_13);
00078 
00079         bool empty = !d();
00080         bool same  = Iter::Ranges::equal(u, ir);
00081 
00082         return empty && same;
00083       }
00084 
00086       virtual void post(Space* home, CpltSetVarArray& x, IntVarArray&) {
00087         // Test lex-bit order
00088         Gecode::partition(home, x);
00089       }
00090     };
00091     CpltSetPartition _cpltsetpartition("Partition");
00092 
00094     class CpltSetPartitionLex : public CpltSetTest {
00095     public:
00097       CpltSetPartitionLex(const char* t) : CpltSetTest(t,2,ds_13,false) {}
00099       virtual bool solution(const SetAssignment& x) const {
00100         CountableSetRanges xr1(x.lub, x[0]);
00101         CountableSetRanges xr2(x.lub, x[1]);
00102 
00103         Iter::Ranges::Inter<CountableSetRanges, CountableSetRanges>
00104           d(xr1, xr2);
00105         Iter::Ranges::Union<CountableSetRanges, CountableSetRanges>
00106           u(xr1, xr2);
00107         IntSetRanges ir(ds_13);
00108 
00109         bool empty = !d();
00110         bool same  = Iter::Ranges::equal(u, ir);
00111 
00112         CountableSetValues xv1(x.lub, x[0]);
00113         CountableSetValues xv2(x.lub, x[1]);
00114         int a = iter2int(xv1, 3);
00115         int b = iter2int(xv2, 3);
00116     
00117         return empty && same && (a < b);
00118       }
00119 
00121       virtual void post(Space* home, CpltSetVarArray& x, IntVarArray&) {
00122         Gecode::partitionLex(home, x, SRT_LE);
00123       }
00124     };
00125     CpltSetPartitionLex _cpltsetpartitionlex("Partition::Lex");
00126 
00128     class CpltSetPartitionNaryOne : public CpltSetTest {
00129     public:
00131       CpltSetPartitionNaryOne(const char* t)
00132       : CpltSetTest(t,3,ds_13,false, 0, 200, 10) {}
00134       virtual bool solution(const SetAssignment& x) const {
00135         CountableSetRanges xr1(x.lub, x[0]);
00136         CountableSetRanges xr2(x.lub, x[1]);
00137         CountableSetRanges xr3(x.lub, x[2]);
00138 
00139         Iter::Ranges::Inter<CountableSetRanges, CountableSetRanges>
00140           d(xr1, xr2);
00141         Iter::Ranges::Union<CountableSetRanges, CountableSetRanges>
00142           u(xr1, xr2);
00143 
00144         bool empty = !d();
00145         bool same  = Iter::Ranges::equal(u, xr3);
00146 
00147         return empty && same;
00148       }
00149 
00151       virtual void post(Space* home, CpltSetVarArray& x, IntVarArray&) {
00152         // Test lex-bit order
00153         int n = x.size() - 1;
00154         CpltSetVarArgs z(n);
00155         for (int i = 0; i < n; i++)
00156           z[i] = x[i];
00157         CpltSetVar y = x[n];
00158         partition(home, z, y);
00159       }
00160     };
00161     CpltSetPartitionNaryOne _cpltsetpartitionnaryone("Partition::NaryOne");
00162 
00164     class CpltSetPartitionNaryOneBigger : public CpltSetTest {
00165     public:
00167       CpltSetPartitionNaryOneBigger(const char* t)
00168       : CpltSetTest(t,3,d1,false, 0, 200, 80) {}
00170       virtual bool solution(const SetAssignment& x) const {
00171         CountableSetRanges xr1(x.lub, x[0]);
00172         CountableSetRanges xr2(x.lub, x[1]);
00173         CountableSetRanges xr3(x.lub, x[2]);
00174         Iter::Ranges::Cache<CountableSetRanges> cxr3(xr3);
00175 
00176         Iter::Ranges::Inter<CountableSetRanges, CountableSetRanges>
00177           d(xr1, xr2);
00178         Iter::Ranges::Union<CountableSetRanges, CountableSetRanges>
00179           u(xr1, xr2);
00180 
00181         bool empty = !d();
00182         bool same  = Iter::Ranges::equal(u, cxr3);
00183 
00184         cxr3.reset();
00185         Iter::Ranges::Singleton m(3,5);
00186 
00187         bool fixed = Iter::Ranges::equal(m, cxr3);
00188 
00189         return empty && same && fixed;
00190       }
00191 
00193       virtual void post(Space* home, CpltSetVarArray& x, IntVarArray&) {
00194         int n = x.size() - 1;
00195         CpltSetVarArgs z(n);
00196         for (int i = 0; i < n; i++)
00197           z[i] = x[i];
00198         CpltSetVar y = x[n];
00199         partition(home, z, y);
00200         dom(home, y, SRT_EQ, 3, 5);
00201       }
00202     };
00203     CpltSetPartitionNaryOneBigger 
00204       _cpltsetpartitionnaryonebigger("Partition::NaryOne::Bigger");
00205 
00207 
00208 }}}
00209 
00210 // STATISTICS: test-cpltset