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
00053
00054
00055
00056
00057
00058 typedef SharedArray<int> IntSharedArray;
00059
00066 template <class V0, class V1, class Idx, class Val>
00067 class Int : public Propagator {
00068 protected:
00077 class IdxVal {
00078 public:
00079 Idx idx_next;
00080 Idx val_next;
00081 Idx idx;
00082 Val val;
00083
00084 void mark(void);
00086 bool marked(void) const;
00087 };
00094 class IterIdx {
00095 private:
00096 IdxVal* iv;
00097 Idx i;
00098 public:
00100 IterIdx(IdxVal* iv);
00102 bool operator ()(void) const;
00104 void operator ++(void);
00106 Idx val(void) const;
00107 };
00114 class IterVal {
00115 private:
00116 IdxVal* iv;
00117 Idx i;
00118 public:
00120 IterVal(IdxVal* iv);
00122 bool operator ()(void) const;
00124 void operator ++(void);
00126 Val val(void) const;
00127 };
00129 class ByVal {
00130 protected:
00131 const IdxVal* iv;
00132 public:
00134 ByVal(const IdxVal* iv);
00136 bool operator ()(Idx& i, Idx& j);
00137 };
00138
00140 V0 x0;
00142 V1 x1;
00144 IntSharedArray c;
00146 IdxVal* iv;
00148 Int(Space& home, bool shared, Int& p);
00150 Int(Space& home, IntSharedArray& i, V0 x0, V1 x1);
00151 public:
00153 virtual Actor* copy(Space& home, bool share);
00155 virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00157 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00159 static ExecStatus post(Space& home, IntSharedArray& i, V0 x0, V1 x1);
00161 virtual size_t dispose(Space& home);
00162 };
00163
00165 template <class V0, class V1>
00166 ExecStatus post_int(Space& home, IntSharedArray& c, V0 x0, V1 x1);
00167
00168
00173 template <class ViewB> class IdxView;
00174
00176 template<class View>
00177 class ViewToVarArg {};
00178
00183 template <class View>
00184 class IdxViewArray {
00185 private:
00187 IdxView<View>* xs;
00189 int n;
00190 public:
00192 IdxViewArray(void);
00194 IdxViewArray(const IdxViewArray<View>&);
00196 IdxViewArray(Space& home, const typename ViewToVarArg<View>::argtype& x);
00198 IdxViewArray(Space& home, int n);
00199
00201 int size(void) const;
00203 void size(int n);
00204
00206 IdxView<View>& operator [](int n);
00208 const IdxView<View>& operator [](int) const;
00209
00214 void subscribe(Space& home, Propagator& p, PropCond pc, bool process=true);
00219 void cancel(Space& home, Propagator& p, PropCond pc);
00220
00222 void update(Space& home, bool share, IdxViewArray<View>& x);
00223 };
00224
00229 template <class VA, class VB, class VC, PropCond pc_ac>
00230 class View : public Propagator {
00231 protected:
00233 IdxViewArray<VA> iv;
00235 VB x0;
00237 VC x1;
00239 View(Space& home, bool share, View& p);
00241 View(Space& home, IdxViewArray<VA>& iv, VB x0, VC x1);
00242 public:
00243
00244 virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00246 virtual size_t dispose(Space& home);
00247 };
00248
00249
00256 template <class VA, class VB, class VC>
00257 class ViewBnd : public View<VA,VB,VC,PC_INT_BND> {
00258 protected:
00259 using View<VA,VB,VC,PC_INT_BND>::iv;
00260 using View<VA,VB,VC,PC_INT_BND>::x0;
00261 using View<VA,VB,VC,PC_INT_BND>::x1;
00262
00264 ViewBnd(Space& home, bool share, ViewBnd& p);
00266 ViewBnd(Space& home, IdxViewArray<VA>& iv, VB x0, VC x1);
00267 public:
00269 virtual Actor* copy(Space& home, bool share);
00271 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00273 static ExecStatus post(Space& home, IdxViewArray<VA>& iv, VB x0, VC x1);
00274 };
00275
00286 template <class VA, class VB, class VC>
00287 class ViewDom : public View<VA,VB,VC,PC_INT_DOM> {
00288 protected:
00289 using View<VA,VB,VC,PC_INT_DOM>::iv;
00290 using View<VA,VB,VC,PC_INT_DOM>::x0;
00291 using View<VA,VB,VC,PC_INT_DOM>::x1;
00292
00294 ViewDom(Space& home, bool share, ViewDom& p);
00296 ViewDom(Space& home, IdxViewArray<VA>& iv, VB x0, VC x1);
00297 public:
00299 virtual Actor* copy(Space& home, bool share);
00307 virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00309 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00311 static ExecStatus post(Space& home, IdxViewArray<VA>& iv,
00312 VB x0, VC x1);
00313 };
00314
00315 }}}
00316
00317 #include <gecode/int/element/int.hpp>
00318 #include <gecode/int/element/view.hpp>
00319
00320 #endif
00321
00322
00323
00324