int-gq.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 GqInt<VY>::GqInt(Home home, ValSet& vs, ViewArray<IntView>& x, VY y)
00046 : IntBase<VY>(home,vs,x,y) {}
00047
00048 template<class VY>
00049 inline ExecStatus
00050 GqInt<VY>::post(Home home, ViewArray<IntView>& x, VY y) {
00051 if (x.size() == 0) {
00052 GECODE_ME_CHECK(y.lq(home,0));
00053 return ES_OK;
00054 }
00055
00056 x.unique(home);
00057
00058 if (x.size() == 1) {
00059 GECODE_ME_CHECK(y.lq(home,1));
00060 return ES_OK;
00061 }
00062
00063 GECODE_ME_CHECK(y.lq(home,x.size()));
00064
00065 if (y.max() <= 1)
00066 return ES_OK;
00067
00068 if (y.min() == x.size()) {
00069 assert(y.assigned());
00070 return Distinct::Dom<IntView>::post(home,x);
00071 }
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.lq(home,n + vs.size()));
00083
00084 if (n == 0) {
00085 assert(vs.size() >= y.max());
00086 return ES_OK;
00087 }
00088
00089 x.size(n);
00090
00091 (void) new (home) GqInt<VY>(home, vs, x, y);
00092 return ES_OK;
00093 }
00094
00095 template<class VY>
00096 forceinline
00097 GqInt<VY>::GqInt(Space& home, bool share, GqInt<VY>& p)
00098 : IntBase<VY>(home, share, p) {}
00099
00100 template<class VY>
00101 Propagator*
00102 GqInt<VY>::copy(Space& home, bool share) {
00103 return new (home) GqInt<VY>(home, share, *this);
00104 }
00105
00106 template<class VY>
00107 ExecStatus
00108 GqInt<VY>::propagate(Space& home, const ModEventDelta& med) {
00109 if (IntView::me(med) == ME_INT_VAL)
00110 add(home);
00111
00112
00113 eliminate(home);
00114
00115 GECODE_ME_CHECK(y.lq(home, x.size() + vs.size()));
00116
00117 if (x.size() == 0)
00118 return home.ES_SUBSUMED(*this);
00119
00120 if (vs.size() >= y.max())
00121 return home.ES_SUBSUMED(*this);
00122
00123 GECODE_ES_CHECK(prune_upper(home,g));
00124
00125 return ES_NOFIX;
00126 }
00127
00128 }}}
00129
00130