set.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 * Christian Schulte <schulte@gecode.org> 00006 * 00007 * Copyright: 00008 * Guido Tack, 2004 00009 * Christian Schulte, 2004 00010 * 00011 * Last modified: 00012 * $Date: 2009-02-05 11:48:53 +0100 (Thu, 05 Feb 2009) $ by $Author: schulte $ 00013 * $Revision: 8155 $ 00014 * 00015 * This file is part of Gecode, the generic constraint 00016 * development environment: 00017 * http://www.gecode.org 00018 * 00019 * Permission is hereby granted, free of charge, to any person obtaining 00020 * a copy of this software and associated documentation files (the 00021 * "Software"), to deal in the Software without restriction, including 00022 * without limitation the rights to use, copy, modify, merge, publish, 00023 * distribute, sublicense, and/or sell copies of the Software, and to 00024 * permit persons to whom the Software is furnished to do so, subject to 00025 * the following conditions: 00026 * 00027 * The above copyright notice and this permission notice shall be 00028 * included in all copies or substantial portions of the Software. 00029 * 00030 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00031 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00032 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00033 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 00034 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 00035 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 00036 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00037 * 00038 */ 00039 00040 #include <gecode/set.hh> 00041 00042 00043 namespace Gecode { namespace Set { 00044 00045 /* 00046 * "Standard" tell operations 00047 * 00048 */ 00049 ModEvent 00050 SetVarImp::cardMin_full(Space& home) { 00051 ModEvent me = ME_SET_CARD; 00052 if (cardMin() == lub.size()) { 00053 glb.become(home, lub); 00054 me = ME_SET_VAL; 00055 } 00056 SetDelta d; 00057 return notify(home, me, d); 00058 } 00059 00060 ModEvent 00061 SetVarImp::cardMax_full(Space& home) { 00062 ModEvent me = ME_SET_CARD; 00063 if (cardMax() == glb.size()) { 00064 lub.become(home, glb); 00065 me = ME_SET_VAL; 00066 } 00067 SetDelta d; 00068 return notify(home, me, d); 00069 } 00070 00071 ModEvent 00072 SetVarImp::processLubChange(Space& home, SetDelta& d) { 00073 ModEvent me = ME_SET_LUB; 00074 if (cardMax() > lub.size()) { 00075 lub.card(lub.size()); 00076 if (cardMin() > cardMax()) { 00077 glb.become(home, lub); 00078 glb.card(glb.size()); 00079 lub.card(glb.size()); 00080 return ME_SET_FAILED; 00081 } 00082 me = ME_SET_CLUB; 00083 } 00084 if (cardMax() == lub.size() && cardMin() == cardMax()) { 00085 glb.become(home, lub); 00086 me = ME_SET_VAL; 00087 assert(d.glbMin() == 1); 00088 assert(d.glbMax() == 0); 00089 } 00090 return notify(home, me, d); 00091 } 00092 00093 ModEvent 00094 SetVarImp::processGlbChange(Space& home, SetDelta& d) { 00095 ModEvent me = ME_SET_GLB; 00096 if (cardMin() < glb.size()) { 00097 glb.card(glb.size()); 00098 if (cardMin() > cardMax()) { 00099 glb.become(home, lub); 00100 glb.card(glb.size()); 00101 lub.card(glb.size()); 00102 return ME_SET_FAILED; 00103 } 00104 me = ME_SET_CGLB; 00105 } 00106 if (cardMin() == glb.size() && cardMin() == cardMax()) { 00107 lub.become(home, glb); 00108 me = ME_SET_VAL; 00109 assert(d.lubMin() == 1); 00110 assert(d.lubMax() == 0); 00111 } 00112 return notify(home, me, d); 00113 } 00114 00115 /* 00116 * Copying variables 00117 * 00118 */ 00119 00120 forceinline 00121 SetVarImp::SetVarImp(Space& home, bool share, SetVarImp& x) 00122 : SetVarImpBase(home,share,x) { 00123 lub.update(home, x.lub); 00124 glb.card(x.cardMin()); 00125 lub.card(x.cardMax()); 00126 if (x.assigned()) { 00127 glb.become(home,lub); 00128 } else { 00129 glb.update(home,x.glb); 00130 } 00131 } 00132 00133 00134 SetVarImp* 00135 SetVarImp::perform_copy(Space& home, bool share) { 00136 return new (home) SetVarImp(home,share,*this); 00137 } 00138 00139 }} 00140 00141 // STATISTICS: set-var 00142