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: 2010-04-08 12:35:31 +0200 (Thu, 08 Apr 2010) $ by $Author: schulte $ 00011 * $Revision: 10684 $ 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){} 00067 bool solution(const SetAssignment& x) const { 00068 int x1 = shared ? x[0] : x[1]; 00069 CountableSetRanges xr0(x.lub, x[0]); 00070 CountableSetRanges xr1(x.lub, x1); 00071 switch (srt) { 00072 case SRT_EQ: return Iter::Ranges::equal(xr0, xr1); 00073 case SRT_NQ: return !Iter::Ranges::equal(xr0, xr1); 00074 case SRT_SUB: return Iter::Ranges::subset(xr0, xr1); 00075 case SRT_SUP: return Iter::Ranges::subset(xr1, xr0); 00076 case SRT_DISJ: 00077 { 00078 Iter::Ranges::Inter<CountableSetRanges,CountableSetRanges> 00079 inter(xr0,xr1); 00080 return !inter(); 00081 } 00082 case SRT_CMPL: 00083 { 00084 Gecode::Set::RangesCompl<CountableSetRanges> rc(xr0); 00085 return Iter::Ranges::equal(rc,xr1); 00086 } 00087 default: 00088 GECODE_NEVER; 00089 } 00090 GECODE_NEVER; 00091 return false; 00092 } 00094 void post(Space& home, SetVarArray& x, IntVarArray&) { 00095 if (!shared) 00096 Gecode::rel(home, x[0], srt, x[1]); 00097 else 00098 Gecode::rel(home, x[0], srt, x[0]); 00099 } 00101 void post(Space& home, SetVarArray& x, IntVarArray&, BoolVar b) { 00102 if (!shared) 00103 Gecode::rel(home, x[0], srt, x[1], b); 00104 else 00105 Gecode::rel(home, x[0], srt, x[0], b); 00106 } 00107 }; 00108 RelBin _relbin_eq(Gecode::SRT_EQ,false); 00109 RelBin _relbin_nq(Gecode::SRT_NQ,false); 00110 RelBin _relbin_sub(Gecode::SRT_SUB,false); 00111 RelBin _relbin_sup(Gecode::SRT_SUP,false); 00112 RelBin _relbin_disj(Gecode::SRT_DISJ,false); 00113 RelBin _relbin_cmpl(Gecode::SRT_CMPL,false); 00114 RelBin _relbin_shared_eq(Gecode::SRT_EQ,true); 00115 RelBin _relbin_shared_nq(Gecode::SRT_NQ,true); 00116 RelBin _relbin_shared_sub(Gecode::SRT_SUB,true); 00117 RelBin _relbin_shared_sup(Gecode::SRT_SUP,true); 00118 RelBin _relbin_shared_disj(Gecode::SRT_DISJ,true); 00119 RelBin _relbin_shared_cmpl(Gecode::SRT_CMPL,true); 00120 00122 00123 }}} 00124 00125 // STATISTICS: test-set