basic.icc
Go to the documentation of this file.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 namespace Gecode { namespace Int { namespace Extensional {
00039
00040
00041
00042
00043
00044 template <class View>
00045 forceinline
00046 Basic<View>::Basic(Space* home, ViewArray<View>& x, const TupleSet& t)
00047 : Base<View>(home,x,t) {
00048 }
00049
00050 template <class View>
00051 ExecStatus
00052 Basic<View>::post(Space* home, ViewArray<View>& x, const TupleSet& t) {
00053 (void) new (home) Basic<View>(home,x,t);
00054 return ES_OK;
00055 }
00056
00057 template <class View>
00058 forceinline
00059 Basic<View>::Basic(Space* home, bool share, Basic<View>& p)
00060 : Base<View>(home,share,p) {
00061 }
00062
00063 template <class View>
00064 PropCost
00065 Basic<View>::cost(ModEventDelta med) const {
00066 return (View::me(med) == ME_INT_VAL)
00067 ? PC_QUADRATIC_HI : PC_CUBIC_HI;
00068 }
00069
00070 template <class View>
00071 Actor*
00072 Basic<View>::copy(Space* home, bool share) {
00073 return new (home) Basic<View>(home,share,*this);
00074 }
00075
00076 template <class View>
00077 Gecode::Support::Symbol
00078 Basic<View>::ati(void) {
00079 return Reflection::mangle<View>("Gecode::Int::Extensional::Basic");
00080 }
00081
00082 template <class View>
00083 Reflection::ActorSpec
00084 Basic<View>::spec(const Space* home, Reflection::VarMap& m) const {
00085 Reflection::ActorSpec s(ati());
00086 return s << x.spec(home, m)
00087 << tupleSet.spec(m);
00088 }
00089
00090 template <class View>
00091 void
00092 Basic<View>::post(Space* home, Reflection::VarMap& vars,
00093 const Reflection::ActorSpec& spec) {
00094 spec.checkArity(2);
00095 ViewArray<View> x(home, vars, spec[0]);
00096 TupleSet tupleSet(vars, spec[1]);
00097 (void) new (home) Basic<View>(home,x,tupleSet);
00098 }
00099
00100
00101 template <class View>
00102 ExecStatus
00103 Basic<View>::propagate(Space* home, ModEventDelta) {
00107 GECODE_AUTOARRAY(BitSet, dom, x.size());
00108 init_dom(home, dom);
00109
00111 GECODE_AUTOARRAY(BitSet, has_support, x.size());
00112 for (int i = x.size(); i--; )
00113 has_support[i].init(home, ts()->domsize);
00114
00115
00117 GECODE_AUTOARRAY(int,nq, ts()->domsize*x.size());
00118 int n_nq = 0;
00119
00120
00121 ExecStatus es = ES_FIX;
00122
00125 for (int var = x.size(); var--; ) {
00126 for (ViewValues<View> vv(x[var]); vv(); ++vv) {
00127
00128 int val = vv.val() - ts()->min;
00129 if (!has_support[var].get(val)) {
00130
00131 Tuple l = find_support(dom, var, val);
00132 if (l == NULL) {
00133
00134 nq[n_nq] = vv.val();
00135 n_nq++;
00136 } else {
00137
00138
00139
00140 for (int i = var; i--; ) {
00141 has_support[i].set(l[i]- ts()->min);
00142 assert(has_support[i].get(l[i]- ts()->min));
00143 }
00144 }
00145 }
00146 }
00147
00148
00149 while (n_nq-- > 0) {
00150 ModEvent me = x[var].nq(home,nq[n_nq]);
00151 if (me_failed(me))
00152 return ES_FAILED;
00153 if (me_modified(me))
00154 es = ES_NOFIX;
00155 }
00156 n_nq = 0;
00157 }
00158
00159 for (int i = x.size(); i--; )
00160 if (!x[i].assigned())
00161 return es;
00162 return ES_SUBSUMED(this, home);
00163 }
00164 }}}
00165
00166