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