rel-op-singleton.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-03-03 17:40:32 +0100 (Wed, 03 Mar 2010) $ by $Author: schulte $ 00014 * $Revision: 10365 $ 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/rel-op.hh> 00042 00043 namespace Gecode { 00044 using namespace Gecode::Set; 00045 using namespace Gecode::Set::Rel; 00046 using namespace Gecode::Set::RelOp; 00047 00048 void 00049 rel(Home home, SetOpType op, const IntVarArgs& x, SetVar y) { 00050 if (home.failed()) return; 00051 ViewArray<SingletonView> xa(home,x.size()); 00052 for (int i=x.size(); i--;) { 00053 Int::IntView iv(x[i]); 00054 SingletonView sv(iv); 00055 xa[i] = sv; 00056 } 00057 00058 switch (op) { 00059 case SOT_UNION: 00060 GECODE_ES_FAIL((RelOp::UnionN<SingletonView,SetView> 00061 ::post(home, xa, y))); 00062 break; 00063 case SOT_DUNION: 00064 GECODE_ES_FAIL((RelOp::PartitionN<SingletonView,SetView> 00065 ::post(home, xa, y))); 00066 break; 00067 case SOT_INTER: 00068 GECODE_ES_FAIL( 00069 (RelOp::IntersectionN<SingletonView,SetView> 00070 ::post(home, xa, y))); 00071 break; 00072 case SOT_MINUS: 00073 throw IllegalOperation("Set::rel"); 00074 break; 00075 default: 00076 throw UnknownOperation("Set::rel"); 00077 } 00078 } 00079 00080 void 00081 rel(Home home, SetOpType op, const IntVarArgs& x, const IntSet& z, 00082 SetVar y) { 00083 if (home.failed()) return; 00084 Set::Limits::check(z, "Set::rel"); 00085 ViewArray<SingletonView> xa(home,x.size()); 00086 for (int i=x.size(); i--;) { 00087 Int::IntView iv(x[i]); 00088 SingletonView sv(iv); 00089 xa[i] = sv; 00090 } 00091 00092 switch (op) { 00093 case SOT_UNION: 00094 GECODE_ES_FAIL((RelOp::UnionN<SingletonView,SetView> 00095 ::post(home, xa, z, y))); 00096 break; 00097 case SOT_DUNION: 00098 GECODE_ES_FAIL((RelOp::PartitionN<SingletonView,SetView> 00099 ::post(home, xa, z, y))); 00100 break; 00101 case SOT_INTER: 00102 GECODE_ES_FAIL( 00103 (RelOp::IntersectionN<SingletonView,SetView> 00104 ::post(home, xa, z, y))); 00105 break; 00106 case SOT_MINUS: 00107 throw IllegalOperation("set::rel"); 00108 break; 00109 default: 00110 throw UnknownOperation("Set::rel"); 00111 } 00112 } 00113 } 00114 00115 // STATISTICS: set-post