val-sel.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
00039
00040 namespace Gecode { namespace Set { namespace Branch {
00041
00042 forceinline
00043 ValSelMin::ValSelMin(Space& home, const ValBranch<Var>& vb)
00044 : ValSel<SetView,int>(home,vb) {}
00045 forceinline
00046 ValSelMin::ValSelMin(Space& home, ValSelMin& vs)
00047 : ValSel<SetView,int>(home,vs) {}
00048 forceinline int
00049 ValSelMin::val(const Space&, SetView x, int) {
00050 UnknownRanges<SetView> u(x);
00051 return u.min();
00052 }
00053
00054 forceinline
00055 ValSelMax::ValSelMax(Space& home, const ValBranch<Var>& vb)
00056 : ValSel<SetView,int>(home,vb) {}
00057 forceinline
00058 ValSelMax::ValSelMax(Space& home, ValSelMax& vs)
00059 : ValSel<SetView,int>(home,vs) {}
00060 forceinline int
00061 ValSelMax::val(const Space&, SetView x, int) {
00062 int max = 0;
00063 for (UnknownRanges<SetView> u(x); u(); ++u)
00064 max = u.max();
00065 return max;
00066 }
00067
00068 forceinline
00069 ValSelMed::ValSelMed(Space& home, const ValBranch<Var>& vb)
00070 : ValSel<SetView,int>(home,vb) {}
00071 forceinline
00072 ValSelMed::ValSelMed(Space& home, ValSelMed& vs)
00073 : ValSel<SetView,int>(home,vs) {}
00074 forceinline int
00075 ValSelMed::val(const Space&, SetView x, int) {
00076 UnknownRanges<SetView> u1(x);
00077 unsigned int i = Iter::Ranges::size(u1) / 2;
00078 UnknownRanges<SetView> u2(x);
00079 int med = (u2.min()+u2.max()) / 2;
00080 ++u2;
00081 if (!u2()) {
00082 return med;
00083 }
00084 UnknownRanges<SetView> u3(x);
00085 while (i >= u3.width()) {
00086 i -= u3.width();
00087 ++u3;
00088 }
00089 return u3.min() + static_cast<int>(i);
00090 }
00091
00092 forceinline
00093 ValSelRnd::ValSelRnd(Space& home, const ValBranch<Var>& vb)
00094 : ValSel<SetView,int>(home,vb), r(vb.rnd()) {}
00095 forceinline
00096 ValSelRnd::ValSelRnd(Space& home, ValSelRnd& vs)
00097 : ValSel<SetView,int>(home,vs), r(vs.r) {
00098 }
00099 forceinline int
00100 ValSelRnd::val(const Space&, SetView x, int) {
00101 UnknownRanges<SetView> u(x);
00102 unsigned int p = r(Iter::Ranges::size(u));
00103 for (UnknownRanges<SetView> i(x); i(); ++i) {
00104 if (i.width() > p)
00105 return i.min() + static_cast<int>(p);
00106 p -= i.width();
00107 }
00108 GECODE_NEVER;
00109 return 0;
00110 }
00111 forceinline bool
00112 ValSelRnd::notice(void) const {
00113 return true;
00114 }
00115 forceinline void
00116 ValSelRnd::dispose(Space&) {
00117 r.~Rnd();
00118 }
00119
00120 }}}
00121
00122
00123