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

rel.cpp

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: 2011-08-24 16:34:16 +0200 (Wed, 24 Aug 2011) $ by $Author: tack $
00011  *     $Revision: 12346 $
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/set.hh"
00039 
00040 using namespace Gecode;
00041 
00042 namespace Test { namespace Set {
00043 
00045   namespace Rel {
00046 
00052 
00053     static IntSet ds_33(-3,3);
00054 
00056     class RelBin : public SetTest {
00057     private:
00058       Gecode::SetRelType srt;
00059       bool shared;
00060     public:
00062       RelBin(Gecode::SetRelType srt0, bool shared0)
00063         : SetTest("Rel::Bin::"+str(srt0)+"::S"+(shared0 ? "1":"0"),
00064                   shared ? 1 : 2,ds_33,true)
00065         , srt(srt0), shared(shared0){}
00066       int minSymDiff(const SetAssignment& x) const {
00067         int x1 = shared ? x[0] : x[1];
00068         typedef Iter::Ranges::Diff<CountableSetRanges,CountableSetRanges> Diff;
00069         CountableSetRanges xr00(x.lub, x[0]);
00070         CountableSetRanges xr10(x.lub, x1);
00071         Diff a(xr00,xr10);
00072         CountableSetRanges xr01(x.lub, x[0]);
00073         CountableSetRanges xr11(x.lub, x1);
00074         Diff b(xr11,xr01);
00075         Iter::Ranges::Union<Diff,Diff> u(a,b);
00076         return u() ? u.min() : Gecode::Set::Limits::max+1;
00077       }
00078       bool in(int i, CountableSetRanges& c, bool eq=false) const {
00079         if (eq && i==Gecode::Set::Limits::max+1)
00080           return true;
00081         Iter::Ranges::Singleton s(i,i);
00082         return Iter::Ranges::subset(s,c);
00083       }
00085       bool solution(const SetAssignment& x) const {
00086         int x1 = shared ? x[0] : x[1];
00087         CountableSetRanges xr0(x.lub, x[0]);
00088         CountableSetRanges xr1(x.lub, x1);
00089         switch (srt) {
00090         case SRT_EQ: return Iter::Ranges::equal(xr0, xr1);
00091         case SRT_NQ: return !Iter::Ranges::equal(xr0, xr1);
00092         
00093         case SRT_LQ: return (!xr0()) || in(minSymDiff(x),xr1,true);
00094         case SRT_LE: return xr0() ? in(minSymDiff(x),xr1) : xr1();
00095         case SRT_GQ: return (!xr1()) || in(minSymDiff(x),xr0,true);
00096         case SRT_GR: return xr1() ? in(minSymDiff(x),xr0) : xr0();
00097         
00098         case SRT_SUB: return Iter::Ranges::subset(xr0, xr1);
00099         case SRT_SUP: return Iter::Ranges::subset(xr1, xr0);
00100         case SRT_DISJ:
00101           {
00102             Iter::Ranges::Inter<CountableSetRanges,CountableSetRanges>
00103               inter(xr0,xr1);
00104             return !inter();
00105           }
00106         case SRT_CMPL:
00107           {
00108             Gecode::Set::RangesCompl<CountableSetRanges> rc(xr0);
00109             return Iter::Ranges::equal(rc,xr1);
00110           }
00111         default:
00112           GECODE_NEVER;
00113         }
00114         GECODE_NEVER;
00115         return false;
00116       }
00118       void post(Space& home, SetVarArray& x, IntVarArray&) {
00119         if (!shared)
00120           Gecode::rel(home, x[0], srt, x[1]);
00121         else
00122           Gecode::rel(home, x[0], srt, x[0]);
00123       }
00125       void post(Space& home, SetVarArray& x, IntVarArray&, BoolVar b) {
00126         if (!shared)
00127           Gecode::rel(home, x[0], srt, x[1], b);
00128         else
00129           Gecode::rel(home, x[0], srt, x[0], b);
00130       }
00131     };
00132     RelBin _relbin_eq(Gecode::SRT_EQ,false);
00133     RelBin _relbin_lq(Gecode::SRT_LQ,false);
00134     RelBin _relbin_le(Gecode::SRT_LE,false);
00135     RelBin _relbin_gq(Gecode::SRT_GQ,false);
00136     RelBin _relbin_gr(Gecode::SRT_GR,false);
00137     RelBin _relbin_nq(Gecode::SRT_NQ,false);
00138     RelBin _relbin_sub(Gecode::SRT_SUB,false);
00139     RelBin _relbin_sup(Gecode::SRT_SUP,false);
00140     RelBin _relbin_disj(Gecode::SRT_DISJ,false);
00141     RelBin _relbin_cmpl(Gecode::SRT_CMPL,false);
00142     RelBin _relbin_shared_eq(Gecode::SRT_EQ,true);
00143     RelBin _relbin_shared_lq(Gecode::SRT_LQ,true);
00144     RelBin _relbin_shared_le(Gecode::SRT_LE,true);
00145     RelBin _relbin_shared_gq(Gecode::SRT_GQ,true);
00146     RelBin _relbin_shared_gr(Gecode::SRT_GR,true);
00147     RelBin _relbin_shared_nq(Gecode::SRT_NQ,true);
00148     RelBin _relbin_shared_sub(Gecode::SRT_SUB,true);
00149     RelBin _relbin_shared_sup(Gecode::SRT_SUP,true);
00150     RelBin _relbin_shared_disj(Gecode::SRT_DISJ,true);
00151     RelBin _relbin_shared_cmpl(Gecode::SRT_CMPL,true);
00152 
00154 
00155 }}}
00156 
00157 // STATISTICS: test-set