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
00041
00042 namespace Gecode { namespace Int { namespace Channel {
00043
00048 template<class View>
00049 class ValInfo {
00050 public:
00052 View view;
00054 bool a;
00056 void init(View x, int n);
00058 void update(Space& home, bool share, ValInfo<View>& vi);
00060 bool doval(void) const;
00062 bool dodom(void) const;
00064 void assigned(void);
00066 void removed(int i);
00068 void done(void);
00069 };
00070
00071 template<class View>
00072 forceinline void
00073 ValInfo<View>::init(View x, int) {
00074 view = x; a = false;
00075 }
00076
00077 template<class View>
00078 forceinline void
00079 ValInfo<View>::update(Space& home, bool share, ValInfo<View>& vi) {
00080 view.update(home,share,vi.view); a = vi.a;
00081 }
00082
00083 template<class View>
00084 forceinline bool
00085 ValInfo<View>::doval(void) const {
00086 return !a && view.assigned();
00087 }
00088
00089 template<class View>
00090 forceinline bool
00091 ValInfo<View>::dodom(void) const {
00092 return false;
00093 }
00094
00095 template<class View>
00096 forceinline void
00097 ValInfo<View>::assigned(void) {
00098 a = true;
00099 }
00100
00101 template<class View>
00102 forceinline void
00103 ValInfo<View>::removed(int) {}
00104
00105 template<class View>
00106 forceinline void
00107 ValInfo<View>::done(void) {}
00108
00109
00110
00111 template<class View, class Info>
00112 ExecStatus
00113 doprop_val(Space& home, int n, Info* x, Info* y,
00114 int& n_na, ProcessStack& xa, ProcessStack& ya) {
00115 do {
00116 int i = xa.pop();
00117 int j = x[i].view.val();
00118
00119 {
00120 ModEvent me = y[j].view.eq(home,i);
00121 if (me_failed(me))
00122 return ES_FAILED;
00123
00124 if (me_modified(me))
00125 ya.push(j);
00126 }
00127
00128 for (int k=i; k--; ) {
00129 ModEvent me = x[k].view.nq(home,j);
00130 if (me_failed(me))
00131 return ES_FAILED;
00132 if (me_modified(me)) {
00133 if (me == ME_INT_VAL) {
00134
00135 xa.push(k);
00136 } else {
00137
00138
00139
00140 x[k].removed(j);
00141 }
00142 }
00143 }
00144
00145 for (int k=i+1; k<n; k++) {
00146 ModEvent me = x[k].view.nq(home,j);
00147 if (me_failed(me))
00148 return ES_FAILED;
00149 if (me_modified(me)) {
00150 if (me == ME_INT_VAL) {
00151
00152 xa.push(k);
00153 } else {
00154
00155
00156
00157 x[k].removed(j);
00158 }
00159 }
00160 }
00161 x[i].assigned(); n_na--;
00162 } while (!xa.empty());
00163 return ES_OK;
00164 }
00165
00166
00167 template<class View, class Info>
00168 forceinline ExecStatus
00169 prop_val(Space& home, int n, Info* x, Info* y,
00170 int& n_na, ProcessStack& xa, ProcessStack& ya) {
00171 if (xa.empty())
00172 return ES_OK;
00173 return doprop_val<View,Info>(home,n,x,y,n_na,xa,ya);
00174 }
00175
00176
00177
00178
00179
00180 template<class View, bool shared>
00181 forceinline
00182 Val<View,shared>::Val(Home home, int n, ValInfo<View>* xy)
00183 : Base<ValInfo<View>,PC_INT_VAL>(home,n,xy) {}
00184
00185 template<class View, bool shared>
00186 forceinline
00187 Val<View,shared>::Val(Space& home, bool share, Val<View,shared>& p)
00188 : Base<ValInfo<View>,PC_INT_VAL>(home,share,p) {}
00189
00190 template<class View, bool shared>
00191 Actor*
00192 Val<View,shared>::copy(Space& home, bool share) {
00193 return new (home) Val<View,shared>(home,share,*this);
00194 }
00195
00196 template<class View, bool shared>
00197 ExecStatus
00198 Val<View,shared>::propagate(Space& home, const ModEventDelta&) {
00199 Region r(home);
00200 ProcessStack xa(r,n);
00201 ProcessStack ya(r,n);
00202
00203 ValInfo<View>* x = xy;
00204 ValInfo<View>* y = xy+n;
00205
00206
00207 for (int i = n; i--; ) {
00208 if (x[i].doval()) xa.push(i);
00209 if (y[i].doval()) ya.push(i);
00210 }
00211
00212 do {
00213
00214 GECODE_ES_CHECK((prop_val<View,ValInfo<View> >(home,n,x,y,n_na,xa,ya)));
00215
00216 GECODE_ES_CHECK((prop_val<View,ValInfo<View> >(home,n,y,x,n_na,ya,xa)));
00217 assert(ya.empty());
00218 } while (!xa.empty());
00219
00220 if (n_na == 0)
00221 return home.ES_SUBSUMED(*this);
00222 return shared ? ES_NOFIX : ES_FIX;
00223 }
00224
00225 template<class View, bool shared>
00226 ExecStatus
00227 Val<View,shared>::post(Home home, int n, ValInfo<View>* xy) {
00228 assert(n > 0);
00229 if (n == 1) {
00230 GECODE_ME_CHECK(xy[0].view.eq(home,0));
00231 GECODE_ME_CHECK(xy[1].view.eq(home,0));
00232 return ES_OK;
00233 }
00234 for (int i=2*n; i--; ) {
00235 GECODE_ME_CHECK(xy[i].view.gq(home,0));
00236 GECODE_ME_CHECK(xy[i].view.le(home,n));
00237 }
00238 (void) new (home) Val<View,shared>(home,n,xy);
00239 return ES_OK;
00240 }
00241
00242 }}}
00243
00244
00245