int.hh
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: 2010-04-08 12:35:31 +0200 (Thu, 08 Apr 2010) $ by $Author: schulte $ 00013 * $Revision: 10684 $ 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 #ifndef __GECODE_SET_INT_HH__ 00041 #define __GECODE_SET_INT_HH__ 00042 00043 #include <gecode/set.hh> 00044 00045 namespace Gecode { namespace Set { namespace Int { 00046 00058 template<class View> 00059 class MinElement : 00060 public MixBinaryPropagator<View,PC_SET_ANY, 00061 Gecode::Int::IntView,Gecode::Int::PC_INT_BND> { 00062 protected: 00063 using MixBinaryPropagator<View,PC_SET_ANY, 00064 Gecode::Int::IntView,Gecode::Int::PC_INT_BND>::x0; 00065 using MixBinaryPropagator<View,PC_SET_ANY, 00066 Gecode::Int::IntView,Gecode::Int::PC_INT_BND>::x1; 00068 MinElement(Space& home, bool share,MinElement& p); 00070 MinElement(Home home, View, Gecode::Int::IntView); 00071 public: 00073 virtual Actor* copy(Space& home,bool); 00075 virtual ExecStatus propagate(Space& home, const ModEventDelta& med); 00077 static ExecStatus post(Home home, View s, Gecode::Int::IntView x); 00078 }; 00079 00086 template<class View> 00087 class NotMinElement : 00088 public MixBinaryPropagator<View,PC_SET_ANY, 00089 Gecode::Int::IntView,Gecode::Int::PC_INT_DOM> { 00090 protected: 00091 using MixBinaryPropagator<View,PC_SET_ANY, 00092 Gecode::Int::IntView,Gecode::Int::PC_INT_DOM>::x0; 00093 using MixBinaryPropagator<View,PC_SET_ANY, 00094 Gecode::Int::IntView,Gecode::Int::PC_INT_DOM>::x1; 00096 NotMinElement(Space& home, bool share,NotMinElement& p); 00098 NotMinElement(Home home, View, Gecode::Int::IntView); 00099 public: 00101 virtual Actor* copy(Space& home,bool); 00103 virtual ExecStatus propagate(Space& home, const ModEventDelta& med); 00105 static ExecStatus post(Home home, View s, Gecode::Int::IntView x); 00106 }; 00107 00114 template<class View> 00115 class ReMinElement : 00116 public Gecode::Int::ReMixBinaryPropagator<View,PC_SET_ANY, 00117 Gecode::Int::IntView,Gecode::Int::PC_INT_DOM,Gecode::Int::BoolView> { 00118 protected: 00119 using Gecode::Int::ReMixBinaryPropagator<View,PC_SET_ANY, 00120 Gecode::Int::IntView,Gecode::Int::PC_INT_DOM,Gecode::Int::BoolView>::x0; 00121 using Gecode::Int::ReMixBinaryPropagator<View,PC_SET_ANY, 00122 Gecode::Int::IntView,Gecode::Int::PC_INT_DOM,Gecode::Int::BoolView>::x1; 00123 using Gecode::Int::ReMixBinaryPropagator<View,PC_SET_ANY, 00124 Gecode::Int::IntView,Gecode::Int::PC_INT_DOM,Gecode::Int::BoolView>::b; 00126 ReMinElement(Space& home, bool share,ReMinElement& p); 00128 ReMinElement(Home home, View, Gecode::Int::IntView, 00129 Gecode::Int::BoolView); 00130 public: 00132 virtual Actor* copy(Space& home,bool); 00134 virtual ExecStatus propagate(Space& home, const ModEventDelta& med); 00136 static ExecStatus post(Home home, View s, Gecode::Int::IntView x, 00137 Gecode::Int::BoolView b); 00138 }; 00139 00146 template<class View> 00147 class MaxElement : 00148 public MixBinaryPropagator<View,PC_SET_ANY,Gecode::Int::IntView,Gecode::Int::PC_INT_BND> { 00149 protected: 00150 using MixBinaryPropagator<View,PC_SET_ANY, 00151 Gecode::Int::IntView,Gecode::Int::PC_INT_BND>::x0; 00152 using MixBinaryPropagator<View,PC_SET_ANY, 00153 Gecode::Int::IntView,Gecode::Int::PC_INT_BND>::x1; 00155 MaxElement(Space& home, bool share,MaxElement& p); 00157 MaxElement(Home home, View, Gecode::Int::IntView); 00158 public: 00160 virtual Actor* copy(Space& home,bool); 00162 virtual ExecStatus propagate(Space& home, const ModEventDelta& med); 00164 static ExecStatus post(Home home, View s, Gecode::Int::IntView x); 00165 }; 00166 00173 template<class View> 00174 class NotMaxElement : 00175 public MixBinaryPropagator<View,PC_SET_ANY, 00176 Gecode::Int::IntView,Gecode::Int::PC_INT_DOM> { 00177 protected: 00178 using MixBinaryPropagator<View,PC_SET_ANY, 00179 Gecode::Int::IntView,Gecode::Int::PC_INT_DOM>::x0; 00180 using MixBinaryPropagator<View,PC_SET_ANY, 00181 Gecode::Int::IntView,Gecode::Int::PC_INT_DOM>::x1; 00183 NotMaxElement(Space& home, bool share,NotMaxElement& p); 00185 NotMaxElement(Home home, View, Gecode::Int::IntView); 00186 public: 00188 virtual Actor* copy(Space& home,bool); 00190 virtual ExecStatus propagate(Space& home, const ModEventDelta& med); 00192 static ExecStatus post(Home home, View s, Gecode::Int::IntView x); 00193 }; 00194 00201 template<class View> 00202 class ReMaxElement : 00203 public Gecode::Int::ReMixBinaryPropagator<View,PC_SET_ANY, 00204 Gecode::Int::IntView,Gecode::Int::PC_INT_DOM,Gecode::Int::BoolView> { 00205 protected: 00206 using Gecode::Int::ReMixBinaryPropagator<View,PC_SET_ANY, 00207 Gecode::Int::IntView,Gecode::Int::PC_INT_DOM,Gecode::Int::BoolView>::x0; 00208 using Gecode::Int::ReMixBinaryPropagator<View,PC_SET_ANY, 00209 Gecode::Int::IntView,Gecode::Int::PC_INT_DOM,Gecode::Int::BoolView>::x1; 00210 using Gecode::Int::ReMixBinaryPropagator<View,PC_SET_ANY, 00211 Gecode::Int::IntView,Gecode::Int::PC_INT_DOM,Gecode::Int::BoolView>::b; 00213 ReMaxElement(Space& home, bool share,ReMaxElement& p); 00215 ReMaxElement(Home home, View, Gecode::Int::IntView, Gecode::Int::BoolView); 00216 public: 00218 virtual Actor* copy(Space& home,bool); 00220 virtual ExecStatus propagate(Space& home, const ModEventDelta& med); 00222 static ExecStatus post(Home home, View s, Gecode::Int::IntView x, 00223 Gecode::Int::BoolView b); 00224 }; 00225 00232 template<class View> 00233 class Card : 00234 public MixBinaryPropagator<View,PC_SET_CARD, 00235 Gecode::Int::IntView,Gecode::Int::PC_INT_BND> { 00236 protected: 00237 using MixBinaryPropagator<View,PC_SET_CARD, 00238 Gecode::Int::IntView,Gecode::Int::PC_INT_BND>::x0; 00239 using MixBinaryPropagator<View,PC_SET_CARD, 00240 Gecode::Int::IntView,Gecode::Int::PC_INT_BND>::x1; 00242 Card(Space& home, bool share,Card& p); 00244 Card(Home home, View, Gecode::Int::IntView); 00245 public: 00247 virtual Actor* copy(Space& home,bool); 00249 virtual ExecStatus propagate(Space& home, const ModEventDelta& med); 00251 static ExecStatus post(Home home, View s, Gecode::Int::IntView x); 00252 }; 00253 00254 00261 template<class View> 00262 class Match : public Propagator { 00263 protected: 00265 View x0; 00267 ViewArray<Gecode::Int::IntView> xs; 00268 00270 Match(Space& home, bool share,Match& p); 00272 Match(Home home, View, ViewArray<Gecode::Int::IntView>&); 00273 public: 00275 virtual Actor* copy(Space& home,bool); 00277 virtual PropCost cost(const Space& home, const ModEventDelta& med) const; 00279 virtual size_t dispose(Space& home); 00281 virtual ExecStatus propagate(Space& home, const ModEventDelta& med); 00283 static ExecStatus post(Home home, View s, 00284 ViewArray<Gecode::Int::IntView>& x); 00285 }; 00286 00304 template<class View> 00305 class ChannelInt : public Propagator { 00306 protected: 00308 ViewArray<Gecode::Int::IntView> xs; 00310 ViewArray<View> ys; 00311 00313 ChannelInt(Space& home, bool share,ChannelInt& p); 00315 ChannelInt(Home home,ViewArray<Gecode::Int::IntView>&, 00316 ViewArray<View>&); 00317 public: 00319 virtual Actor* copy(Space& home,bool); 00321 virtual PropCost cost(const Space& home, const ModEventDelta& med) const; 00323 virtual size_t dispose(Space& home); 00325 virtual ExecStatus propagate(Space& home, const ModEventDelta& med); 00327 static ExecStatus post(Home home,ViewArray<Gecode::Int::IntView>& x, 00328 ViewArray<View>& y); 00329 }; 00330 00342 template<class View> 00343 class ChannelBool 00344 : public MixNaryOnePropagator<Gecode::Int::BoolView, 00345 Gecode::Int::PC_BOOL_VAL, 00346 View,PC_GEN_NONE> { 00347 protected: 00348 typedef MixNaryOnePropagator<Gecode::Int::BoolView, 00349 Gecode::Int::PC_BOOL_VAL, 00350 View,PC_GEN_NONE> Super; 00351 using Super::x; 00352 using Super::y; 00353 00355 ChannelBool(Space& home, bool share,ChannelBool& p); 00357 ChannelBool(Home home,ViewArray<Gecode::Int::BoolView>&, 00358 View); 00359 00361 class IndexAdvisor : public Advisor { 00362 protected: 00364 int idx; 00365 public: 00367 template<class A> 00368 IndexAdvisor(Space& home, ChannelBool<View>& p, Council<A>& c, 00369 int index); 00371 IndexAdvisor(Space& home, bool share, IndexAdvisor& a); 00373 int index(void) const; 00375 template<class A> 00376 void dispose(Space& home, Council<A>& c); 00377 }; 00378 00380 Council<IndexAdvisor> co; 00382 SetDelta delta; 00384 GLBndSet zeros; 00386 GLBndSet ones; 00388 bool running; 00389 public: 00391 virtual Actor* copy(Space& home,bool); 00393 virtual PropCost cost(const Space& home, const ModEventDelta& med) const; 00395 virtual size_t dispose(Space& home); 00397 virtual ExecStatus propagate(Space& home, const ModEventDelta& med); 00399 virtual ExecStatus advise(Space& home, Advisor& a, const Delta& d); 00401 static ExecStatus post(Home home,ViewArray<Gecode::Int::BoolView>& x, 00402 View y); 00403 }; 00404 00411 template<class View> 00412 class Weights : public Propagator { 00413 protected: 00415 SharedArray<int> elements; 00417 SharedArray<int> weights; 00418 00420 View x; 00422 Gecode::Int::IntView y; 00423 00425 Weights(Space& home, bool share,Weights& p); 00427 Weights(Home home, const SharedArray<int>&, const SharedArray<int>&, 00428 View, Gecode::Int::IntView); 00429 public: 00431 virtual Actor* copy(Space& home,bool); 00433 virtual PropCost cost(const Space& home, const ModEventDelta& med) const; 00435 virtual size_t dispose(Space& home); 00437 virtual ExecStatus propagate(Space& home, const ModEventDelta& med); 00439 static ExecStatus post(Home home, 00440 const SharedArray<int>& elements, 00441 const SharedArray<int>& weights, 00442 View x, Gecode::Int::IntView y); 00443 }; 00444 00445 }}} 00446 00447 #include <gecode/set/int/minmax.hpp> 00448 #include <gecode/set/int/card.hpp> 00449 #include <gecode/set/int/match.hpp> 00450 #include <gecode/set/int/channel-int.hpp> 00451 #include <gecode/set/int/channel-bool.hpp> 00452 #include <gecode/set/int/weights.hpp> 00453 00454 #endif 00455 00456 // STATISTICS: set-prop