select-val.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
00039
00040
00041
00042
00043
00044 namespace Gecode { namespace Set { namespace Branch {
00045
00046 forceinline int
00047 ValMin::val(const Space*, SetView x) const {
00048 UnknownRanges<SetView> unknown(x);
00049 return unknown.min();
00050 }
00051 forceinline ModEvent
00052 ValMin::tell(Space* home, unsigned int a, SetView x, int v) {
00053 return (a == 0) ? x.include(home,v) : x.exclude(home,v);
00054 }
00055 inline Support::Symbol
00056 ValMin::type(void) {
00057 return Support::Symbol("Gecode::Set::Branch::ValMin");
00058 }
00059 forceinline void
00060 ValMin::branchingSpec(const Space* home,
00061 Reflection::VarMap& m, Reflection::BranchingSpec& bs,
00062 int alt, SetView x, int n) const {
00063 assert(alt <= 2);
00064 Reflection::ArrayArg* a0 = Reflection::Arg::newArray(2);
00065 std::stringstream s;
00066 s << n;
00067 (*a0)[0] = Reflection::Arg::newString((s.str()+" in ").c_str());
00068 (*a0)[1] = x.spec(home, m);
00069 bs[0] = a0;
00070 if (alt == 2) {
00071 Reflection::ArrayArg* a1 = Reflection::Arg::newArray(2);
00072 (*a1)[0] = Reflection::Arg::newString((s.str()+" not in ").c_str());
00073 (*a1)[1] = x.spec(home, m);
00074 bs[1] = a1;
00075 }
00076 }
00077
00078 forceinline int
00079 ValMax::val(const Space*, SetView x) const {
00080 int maxElem = 0;
00081 UnknownRanges<SetView> unknown(x);
00082 while (unknown()) {
00083 maxElem = unknown.max();
00084 ++unknown;
00085 }
00086 return maxElem;
00087 }
00088 forceinline ModEvent
00089 ValMax::tell(Space* home, unsigned int a, SetView x, int v) {
00090 return (a == 0) ? x.include(home,v) : x.exclude(home,v);
00091 }
00092 inline Support::Symbol
00093 ValMax::type(void) {
00094 return Support::Symbol("Gecode::Set::Branch::ValMax");
00095 }
00096 forceinline void
00097 ValMax::branchingSpec(const Space* home,
00098 Reflection::VarMap& m, Reflection::BranchingSpec& bs,
00099 int alt, SetView x, int n) const {
00100 assert(alt <= 2);
00101 Reflection::ArrayArg* a0 = Reflection::Arg::newArray(2);
00102 std::stringstream s;
00103 s << n;
00104 (*a0)[0] = Reflection::Arg::newString((s.str()+" in ").c_str());
00105 (*a0)[1] = x.spec(home, m);
00106 bs[0] = a0;
00107 if (alt == 2) {
00108 Reflection::ArrayArg* a1 = Reflection::Arg::newArray(2);
00109 (*a1)[0] = Reflection::Arg::newString((s.str()+" not in ").c_str());
00110 (*a1)[1] = x.spec(home, m);
00111 bs[1] = a1;
00112 }
00113 }
00114
00115 template <class SelView>
00116 static void
00117 create(Space* home, ViewArray<SetView>& x, SetValBranch vals) {
00118 switch (vals) {
00119 case SET_VAL_MIN:
00120 (void) new (home) ViewValBranching<SetView,int,SelView,ValMin>(home,x);
00121 break;
00122 case SET_VAL_MAX:
00123 (void) new (home) ViewValBranching<SetView,int,SelView,ValMax>(home,x);
00124 break;
00125 default:
00126 throw UnknownBranching("Set::branch");
00127 }
00128 }
00129
00130 }}}
00131
00132