card.hpp
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 * Gabor Szokoli <szokoli@gecode.org> 00007 * 00008 * Copyright: 00009 * Guido Tack, 2004 00010 * Christian Schulte, 2004 00011 * Gabor Szokoli, 2004 00012 * 00013 * Last modified: 00014 * $Date: 2010-03-30 15:34:12 +0200 (Tue, 30 Mar 2010) $ by $Author: tack $ 00015 * $Revision: 10603 $ 00016 * 00017 * This file is part of Gecode, the generic constraint 00018 * development environment: 00019 * http://www.gecode.org 00020 * 00021 * Permission is hereby granted, free of charge, to any person obtaining 00022 * a copy of this software and associated documentation files (the 00023 * "Software"), to deal in the Software without restriction, including 00024 * without limitation the rights to use, copy, modify, merge, publish, 00025 * distribute, sublicense, and/or sell copies of the Software, and to 00026 * permit persons to whom the Software is furnished to do so, subject to 00027 * the following conditions: 00028 * 00029 * The above copyright notice and this permission notice shall be 00030 * included in all copies or substantial portions of the Software. 00031 * 00032 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00033 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00034 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00035 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 00036 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 00037 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 00038 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00039 * 00040 */ 00041 00042 #include <gecode/set.hh> 00043 #include <gecode/int.hh> 00044 00045 namespace Gecode { namespace Set { namespace Int { 00046 00047 template<class View> 00048 forceinline 00049 Card<View>::Card(Home home, View y0, Gecode::Int::IntView y1) 00050 : MixBinaryPropagator<View,PC_SET_CARD, 00051 Gecode::Int::IntView,Gecode::Int::PC_INT_BND> (home, y0, y1) {} 00052 00053 template<class View> 00054 forceinline ExecStatus 00055 Card<View>::post(Home home, View x0, Gecode::Int::IntView x1) { 00056 GECODE_ME_CHECK(x1.gq(home,0)); 00057 GECODE_ME_CHECK(x0.cardMax(home, Gecode::Int::Limits::max)); 00058 (void) new (home) Card(home,x0,x1); 00059 return ES_OK; 00060 } 00061 00062 template<class View> 00063 forceinline 00064 Card<View>::Card(Space& home, bool share, Card& p) 00065 : MixBinaryPropagator<View,PC_SET_CARD, 00066 Gecode::Int::IntView,Gecode::Int::PC_INT_BND> (home, share, p) {} 00067 00068 template<class View> 00069 Actor* 00070 Card<View>::copy(Space& home, bool share) { 00071 return new (home) Card(home,share,*this); 00072 } 00073 00074 template<class View> 00075 ExecStatus 00076 Card<View>::propagate(Space& home, const ModEventDelta&) { 00077 int x1min, x1max; 00078 do { 00079 x1min = x1.min(); 00080 x1max = x1.max(); 00081 GECODE_ME_CHECK(x0.cardMin(home,static_cast<unsigned int>(x1min))); 00082 GECODE_ME_CHECK(x0.cardMax(home,static_cast<unsigned int>(x1max))); 00083 GECODE_ME_CHECK(x1.gq(home,static_cast<int>(x0.cardMin()))); 00084 GECODE_ME_CHECK(x1.lq(home,static_cast<int>(x0.cardMax()))); 00085 } while (x1.min() > x1min || x1.max() < x1max); 00086 if (x1.assigned()) 00087 return home.ES_SUBSUMED(*this); 00088 return ES_FIX; 00089 } 00090 00091 }}} 00092 00093 // STATISTICS: set-prop