int-lq.hpp
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 #include <gecode/int/rel.hh>
00039 #include <gecode/int/distinct.hh>
00040
00041 namespace Gecode { namespace Int { namespace NValues {
00042
00043 template<class VY>
00044 forceinline
00045 LqInt<VY>::LqInt(Home home, ValSet& vs, ViewArray<IntView>& x, VY y)
00046 : IntBase<VY>(home,vs,x,y) {
00047 home.notice(*this, AP_WEAKLY);
00048 }
00049
00050 template<class VY>
00051 inline ExecStatus
00052 LqInt<VY>::post(Home home, ViewArray<IntView>& x, VY y) {
00053 if (x.size() == 0) {
00054 GECODE_ME_CHECK(y.eq(home,0));
00055 return ES_OK;
00056 }
00057
00058 x.unique(home);
00059
00060 GECODE_ME_CHECK(y.gq(home,1));
00061
00062 if (x.size() == 1)
00063 return ES_OK;
00064
00065 if (y.max() == 1) {
00066 assert(y.assigned());
00067 return Rel::NaryEqDom<IntView>::post(home,x);
00068 }
00069
00070 if (y.min() >= x.size())
00071 return ES_OK;
00072
00073
00074 ValSet vs;
00075 int n = x.size();
00076 for (int i=n; i--; )
00077 if (x[i].assigned()) {
00078 vs.add(home, x[i].val());
00079 x[i] = x[--n];
00080 }
00081
00082 GECODE_ME_CHECK(y.gq(home,vs.size()));
00083
00084 if (n == 0) {
00085 assert(y.min() >= vs.size());
00086 return ES_OK;
00087 }
00088
00089 x.size(n);
00090
00091 (void) new (home) LqInt<VY>(home, vs, x, y);
00092 return ES_OK;
00093 }
00094
00095 template<class VY>
00096 forceinline
00097 LqInt<VY>::LqInt(Space& home, bool share, LqInt<VY>& p)
00098 : IntBase<VY>(home, share, p) {}
00099
00100 template<class VY>
00101 Propagator*
00102 LqInt<VY>::copy(Space& home, bool share) {
00103 return new (home) LqInt<VY>(home, share, *this);
00104 }
00105
00106 template<class VY>
00107 forceinline size_t
00108 LqInt<VY>::dispose(Space& home) {
00109 home.ignore(*this, AP_WEAKLY);
00110 (void) IntBase<VY>::dispose(home);
00111 return sizeof(*this);
00112 }
00113
00114 template<class VY>
00115 ExecStatus
00116 LqInt<VY>::propagate(Space& home, const ModEventDelta& med) {
00117
00118 if (IntView::me(med) == ME_INT_VAL)
00119 add(home);
00120
00121 GECODE_ME_CHECK(y.gq(home, vs.size()));
00122
00123 if (x.size() == 0)
00124 return home.ES_SUBSUMED(*this);
00125
00126
00127 if (y.max() == vs.size())
00128 return all_in_valset(home);
00129
00130 if (x.size() + vs.size() <= y.min())
00131 return home.ES_SUBSUMED(*this);
00132
00133
00134 Region r(home);
00135 int* dis; int n_dis;
00136 disjoint(home,r,dis,n_dis);
00137
00138
00139 if (x.size() == 0)
00140 return home.ES_SUBSUMED(*this);
00141
00142
00143 if (n_dis == 0)
00144 return ES_NOFIX;
00145
00146
00147 GECODE_ES_CHECK(prune_lower(home,dis,n_dis));
00148
00149 return ES_NOFIX;
00150 }
00151
00152 }}}
00153
00154