00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #ifndef __GECODE_INT_ELEMENT_HH__
00041 #define __GECODE_INT_ELEMENT_HH__
00042
00043 #include <gecode/int.hh>
00044 #include <gecode/int/rel.hh>
00045
00051 namespace Gecode { namespace Int { namespace Element {
00052
00059 template<class V0, class V1, class Idx, class Val>
00060 class Int : public Propagator {
00061 protected:
00070 class IdxVal {
00071 public:
00072 Idx idx_next;
00073 Idx val_next;
00074 Idx idx;
00075 Val val;
00076
00077 void mark(void);
00079 bool marked(void) const;
00080 };
00087 class IterIdx {
00088 private:
00089 IdxVal* iv;
00090 Idx i;
00091 public:
00093 IterIdx(IdxVal* iv);
00095 bool operator ()(void) const;
00097 void operator ++(void);
00099 Idx val(void) const;
00100 };
00107 class IterVal {
00108 private:
00109 IdxVal* iv;
00110 Idx i;
00111 public:
00113 IterVal(IdxVal* iv);
00115 bool operator ()(void) const;
00117 void operator ++(void);
00119 Val val(void) const;
00120 };
00122 class ByVal {
00123 protected:
00124 const IdxVal* iv;
00125 public:
00127 ByVal(const IdxVal* iv);
00129 bool operator ()(Idx& i, Idx& j);
00130 };
00131
00133 V0 x0;
00135 V1 x1;
00137 IntSharedArray c;
00139 IdxVal* iv;
00141 Int(Space& home, bool shared, Int& p);
00143 Int(Home home, IntSharedArray& i, V0 x0, V1 x1);
00144 public:
00146 virtual Actor* copy(Space& home, bool share);
00148 virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00150 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00152 static ExecStatus post(Home home, IntSharedArray& i, V0 x0, V1 x1);
00154 virtual size_t dispose(Space& home);
00155 };
00156
00158 template<class V0, class V1>
00159 ExecStatus post_int(Home home, IntSharedArray& c, V0 x0, V1 x1);
00160
00161
00166 template<class ViewB> class IdxView;
00167
00169 template<class View>
00170 class ViewToVarArg {};
00171
00176 template<class View>
00177 class IdxViewArray {
00178 private:
00180 IdxView<View>* xs;
00182 int n;
00183 public:
00185 IdxViewArray(void);
00187 IdxViewArray(const IdxViewArray<View>&);
00189 IdxViewArray(Space& home, const typename ViewToVarArg<View>::argtype& x);
00191 IdxViewArray(Space& home, int n);
00192
00194 int size(void) const;
00196 void size(int n);
00197
00199 IdxView<View>& operator [](int n);
00201 const IdxView<View>& operator [](int) const;
00202
00207 void subscribe(Space& home, Propagator& p, PropCond pc, bool process=true);
00212 void cancel(Space& home, Propagator& p, PropCond pc);
00213
00215 void update(Space& home, bool share, IdxViewArray<View>& x);
00216 };
00217
00222 template<class VA, class VB, class VC, PropCond pc_ac>
00223 class View : public Propagator {
00224 protected:
00226 IdxViewArray<VA> iv;
00228 VB x0;
00230 VC x1;
00232 View(Space& home, bool share, View& p);
00234 View(Home home, IdxViewArray<VA>& iv, VB x0, VC x1);
00235 public:
00236
00237 virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00239 virtual size_t dispose(Space& home);
00240 };
00241
00242
00249 template<class VA, class VB, class VC>
00250 class ViewBnd : public View<VA,VB,VC,PC_INT_BND> {
00251 protected:
00252 using View<VA,VB,VC,PC_INT_BND>::iv;
00253 using View<VA,VB,VC,PC_INT_BND>::x0;
00254 using View<VA,VB,VC,PC_INT_BND>::x1;
00255
00257 ViewBnd(Space& home, bool share, ViewBnd& p);
00259 ViewBnd(Home home, IdxViewArray<VA>& iv, VB x0, VC x1);
00260 public:
00262 virtual Actor* copy(Space& home, bool share);
00264 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00266 static ExecStatus post(Home home, IdxViewArray<VA>& iv, VB x0, VC x1);
00267 };
00268
00279 template<class VA, class VB, class VC>
00280 class ViewDom : public View<VA,VB,VC,PC_INT_DOM> {
00281 protected:
00282 using View<VA,VB,VC,PC_INT_DOM>::iv;
00283 using View<VA,VB,VC,PC_INT_DOM>::x0;
00284 using View<VA,VB,VC,PC_INT_DOM>::x1;
00285
00287 ViewDom(Space& home, bool share, ViewDom& p);
00289 ViewDom(Home home, IdxViewArray<VA>& iv, VB x0, VC x1);
00290 public:
00292 virtual Actor* copy(Space& home, bool share);
00300 virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00302 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00304 static ExecStatus post(Home home, IdxViewArray<VA>& iv,
00305 VB x0, VC x1);
00306 };
00307
00315 class GECODE_VTABLE_EXPORT Pair
00316 : public TernaryPropagator<IntView,PC_INT_DOM> {
00317 protected:
00318 using TernaryPropagator<IntView,PC_INT_DOM>::x0;
00319 using TernaryPropagator<IntView,PC_INT_DOM>::x1;
00320 using TernaryPropagator<IntView,PC_INT_DOM>::x2;
00322 int w;
00324 Pair(Space& home, bool share, Pair& p);
00325 public:
00327 Pair(Home home, IntView x0, IntView x1, IntView x2, int w);
00329 static ExecStatus post(Home home, IntView x0, IntView x1, IntView x2,
00330 int w, int h);
00332 GECODE_INT_EXPORT virtual Actor* copy(Space& home, bool share);
00334 GECODE_INT_EXPORT virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00335 };
00336
00337 }}}
00338
00339 #include <gecode/int/element/int.hpp>
00340 #include <gecode/int/element/view.hpp>
00341 #include <gecode/int/element/pair.hpp>
00342
00343 #endif
00344
00345
00346
00347