rel-op-const-vcc.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 * Contributing authors: 00007 * Gabor Szokoli <szokoli@gecode.org> 00008 * 00009 * Copyright: 00010 * Guido Tack, 2004, 2005 00011 * 00012 * Last modified: 00013 * $Date: 2010-06-07 14:18:14 +0200 (Mon, 07 Jun 2010) $ by $Author: tack $ 00014 * $Revision: 11048 $ 00015 * 00016 * This file is part of Gecode, the generic constraint 00017 * development environment: 00018 * http://www.gecode.org 00019 * 00020 * Permission is hereby granted, free of charge, to any person obtaining 00021 * a copy of this software and associated documentation files (the 00022 * "Software"), to deal in the Software without restriction, including 00023 * without limitation the rights to use, copy, modify, merge, publish, 00024 * distribute, sublicense, and/or sell copies of the Software, and to 00025 * permit persons to whom the Software is furnished to do so, subject to 00026 * the following conditions: 00027 * 00028 * The above copyright notice and this permission notice shall be 00029 * included in all copies or substantial portions of the Software. 00030 * 00031 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00032 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00033 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00034 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 00035 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 00036 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 00037 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00038 * 00039 */ 00040 00041 #include <gecode/set.hh> 00042 #include <gecode/set/rel.hh> 00043 #include <gecode/set/rel-op.hh> 00044 00045 namespace Gecode { 00046 using namespace Gecode::Set; 00047 using namespace Gecode::Set::Rel; 00048 using namespace Gecode::Set::RelOp; 00049 00050 void 00051 rel(Home home, SetVar x, SetOpType op, const IntSet& y, SetRelType r, 00052 const IntSet& z) { 00053 Set::Limits::check(y, "Set::rel"); 00054 Set::Limits::check(z, "Set::rel"); 00055 ConstSetView yv(home, y); 00056 ConstSetView zv(home, z); 00057 00058 if (op==SOT_MINUS) { 00059 switch (r) { 00060 case SRT_EQ: 00061 { 00062 GlbRanges<ConstSetView> yr(yv); 00063 RangesCompl<GlbRanges<ConstSetView> > yrc(yr); 00064 IntSet yc(yrc); 00065 ConstSetView cy(home, yc); 00066 GECODE_ES_FAIL( 00067 (Intersection<ConstSetView, 00068 SetView,ConstSetView> 00069 ::post(home,cy,x,zv))); 00070 } 00071 break; 00072 case SRT_NQ: 00073 { 00074 SetVar tmp(home); 00075 GECODE_ES_FAIL( 00076 (Distinct<SetView,ConstSetView> 00077 ::post(home,tmp,zv))); 00078 GlbRanges<ConstSetView> yr(yv); 00079 RangesCompl<GlbRanges<ConstSetView> > yrc(yr); 00080 IntSet yc(yrc); 00081 ConstSetView cy(home, yc); 00082 GECODE_ES_FAIL( 00083 (Intersection<ConstSetView, 00084 SetView,SetView> 00085 ::post(home,cy,x,tmp))); 00086 } 00087 break; 00088 case SRT_SUB: 00089 { 00090 GlbRanges<ConstSetView> yr(yv); 00091 RangesCompl<GlbRanges<ConstSetView> > yrc(yr); 00092 IntSet yc(yrc); 00093 ConstSetView cy(home, yc); 00094 GECODE_ES_FAIL( 00095 (SuperOfInter<ConstSetView,SetView,ConstSetView> 00096 ::post(home,cy,x,zv))); 00097 00098 } 00099 break; 00100 case SRT_SUP: 00101 { 00102 // z <= tmp 00103 SetVar tmp(home,z,Limits::min, Limits::max); 00104 SetView xv(x); 00105 00106 GlbRanges<ConstSetView> yr(yv); 00107 RangesCompl<GlbRanges<ConstSetView> > yrc(yr); 00108 IntSet yc(yrc); 00109 ConstSetView cy(home, yc); 00110 00111 GECODE_ES_FAIL( 00112 (Intersection<ConstSetView, 00113 SetView,SetView> 00114 ::post(home,cy,xv,tmp))); 00115 } 00116 break; 00117 case SRT_DISJ: 00118 { 00119 SetVar tmp(home); 00120 SetView tmpv(tmp); 00121 IntSetRanges zi(z); 00122 GECODE_ME_FAIL( tmpv.excludeI(home, zi)); 00123 00124 GlbRanges<ConstSetView> yr(yv); 00125 RangesCompl<GlbRanges<ConstSetView> > yrc(yr); 00126 IntSet yc(yrc); 00127 ConstSetView cy(home, yc); 00128 GECODE_ES_FAIL( 00129 (Intersection<ConstSetView, 00130 SetView,SetView> 00131 ::post(home,cy,x,tmp))); 00132 } 00133 break; 00134 case SRT_CMPL: 00135 { 00136 SetView xv(x); 00137 ComplementView<SetView> cx(xv); 00138 GECODE_ES_FAIL( 00139 (Union<ConstSetView, 00140 ComplementView<SetView>, 00141 ConstSetView>::post(home, yv, cx, zv))); 00142 } 00143 break; 00144 default: 00145 throw UnknownRelation("Set::rel"); 00146 } 00147 } else { 00148 rel(home, y, op, x, r, z); 00149 } 00150 } 00151 00152 } 00153 00154 // STATISTICS: set-post