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 namespace Gecode { namespace CpltSet { namespace Branch {
00039
00040 template <bool exclude>
00041 forceinline int
00042 ValMinUnknown<exclude>::val(const Space*, CpltSetView x) const {
00043 UnknownValues<CpltSetView> unknown(x);
00044 int v = unknown.val();
00045 return v;
00046 }
00047
00048 template <bool exclude>
00049 forceinline ModEvent
00050 ValMinUnknown<exclude>::tell(Space* home, unsigned int a,
00051 CpltSetView x, int v) {
00052 return (a == (int) exclude) ? x.include(home,v) : x.exclude(home,v);
00053 }
00054
00055 template<bool exclude>
00056 inline Support::Symbol
00057 ValMinUnknown<exclude>::type(void) {
00058 return Support::Symbol("CpltSet::Branch::ValMinUnknown");
00059 }
00060
00061 template<bool exclude>
00062 forceinline void
00063 ValMinUnknown<exclude>::branchingSpec(const Space* home,
00064 Reflection::VarMap& m,
00065 Reflection::BranchingSpec& bs,
00066 int alt, CpltSetView x, int n) const {
00067 assert(alt <= 2);
00068 Reflection::ArrayArg* a0 = Reflection::Arg::newArray(2);
00069 std::stringstream s;
00070 s << n;
00071 if (exclude) {
00072 (*a0)[0] = Reflection::Arg::newString((s.str()+" not in ").c_str());
00073 } else {
00074 (*a0)[0] = Reflection::Arg::newString((s.str()+" in ").c_str());
00075 }
00076 (*a0)[1] = x.spec(home, m);
00077 bs[0] = a0;
00078 if (alt == 2) {
00079 Reflection::ArrayArg* a1 = Reflection::Arg::newArray(2);
00080 if (exclude) {
00081 (*a1)[0] = Reflection::Arg::newString((s.str()+" in ").c_str());
00082 } else {
00083 (*a1)[0] = Reflection::Arg::newString((s.str()+" not in ").c_str());
00084 }
00085 (*a1)[1] = x.spec(home, m);
00086 bs[1] = a1;
00087 }
00088 }
00089
00090 template <bool exclude>
00091 forceinline int
00092 ValMaxUnknown<exclude>::val(const Space*, CpltSetView x) const {
00093 int maxElem = 0;
00094 Set::UnknownRanges<CpltSetView> unknown(x);
00095 while (unknown()) {
00096 maxElem = unknown.max();
00097 ++unknown;
00098 }
00099 return maxElem;
00100 }
00101
00102 template <bool exclude>
00103 forceinline ModEvent
00104 ValMaxUnknown<exclude>::tell(Space* home, unsigned int a,
00105 CpltSetView x, int v) {
00106 return (a == (int) exclude) ? x.include(home,v) : x.exclude(home,v);
00107 }
00108
00109 template<bool exclude>
00110 inline Support::Symbol
00111 ValMaxUnknown<exclude>::type(void) {
00112 return Support::Symbol("CpltSet::Branch::ValMaxUnknown");
00113 }
00114
00115 template<bool exclude>
00116 forceinline void
00117 ValMaxUnknown<exclude>::branchingSpec(const Space* home,
00118 Reflection::VarMap& m,
00119 Reflection::BranchingSpec& bs,
00120 int alt, CpltSetView x, int n) const {
00121 assert(alt <= 2);
00122 Reflection::ArrayArg* a0 = Reflection::Arg::newArray(2);
00123 std::stringstream s;
00124 s << n;
00125 if (exclude) {
00126 (*a0)[0] = Reflection::Arg::newString((s.str()+" not in ").c_str());
00127 } else {
00128 (*a0)[0] = Reflection::Arg::newString((s.str()+" in ").c_str());
00129 }
00130 (*a0)[1] = x.spec(home, m);
00131 bs[0] = a0;
00132 if (alt == 2) {
00133 Reflection::ArrayArg* a1 = Reflection::Arg::newArray(2);
00134 if (exclude) {
00135 (*a1)[0] = Reflection::Arg::newString((s.str()+" in ").c_str());
00136 } else {
00137 (*a1)[0] = Reflection::Arg::newString((s.str()+" not in ").c_str());
00138 }
00139 (*a1)[1] = x.spec(home, m);
00140 bs[1] = a1;
00141 }
00142 }
00143
00144 template <class SelView>
00145 static void
00146 create(Space* home, ViewArray<CpltSetView>& x, CpltSetValBranch vals) {
00147 switch (vals) {
00148 case CPLTSET_VAL_MIN_UNKNOWN:
00149 (void) new (home) ViewValBranching<CpltSetView,int,SelView,ValMinUnknown<false> >(home,x);
00150 break;
00151 case CPLTSET_VAL_MIN_UNKNOWN_EX_FIRST:
00152 (void) new (home) ViewValBranching<CpltSetView,int,SelView,ValMinUnknown<true> >(home,x);
00153 break;
00154 case CPLTSET_VAL_MAX_UNKNOWN:
00155 (void) new (home) ViewValBranching<CpltSetView,int,SelView,ValMaxUnknown<false> >(home,x);
00156 break;
00157 case CPLTSET_VAL_MAX_UNKNOWN_EX_FIRST:
00158 (void) new (home) ViewValBranching<CpltSetView,int,SelView,ValMaxUnknown<true> >(home,x);
00159 break;
00160 default:
00161 throw UnknownBranching("CpltSet::branch");
00162 }
00163 }
00164
00165 }}}
00166
00167