brancher-filter.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 <functional>
00039
00040 namespace Gecode {
00041
00043 template<class Var>
00044 using BranchFilter = std::function<bool(const Space& home,
00045 Var x, int i)>;
00046
00048 template<class View>
00049 class BrancherFilter {
00050 public:
00052 typedef typename View::VarType Var;
00053 protected:
00054 SharedData<BranchFilter<Var>> f;
00055 public:
00057 BrancherFilter(BranchFilter<Var> bf);
00059 BrancherFilter(Space& home, bool shared, BrancherFilter& bf);
00061 operator bool(void) const;
00063 bool operator ()(const Space& home, View x, int i) const;
00065 bool notice(void) const;
00067 void dispose(Space& home);
00068 };
00069
00071 template<class View>
00072 class BrancherNoFilter {
00073 public:
00075 typedef typename View::VarType Var;
00076 public:
00078 BrancherNoFilter(BranchFilter<Var> bf);
00080 BrancherNoFilter(Space& home, bool shared, BrancherNoFilter& bf);
00082 operator bool(void) const;
00084 bool operator ()(const Space& home, View x, int i) const;
00086 bool notice(void) const;
00088 void dispose(Space& home);
00089 };
00090
00091
00092 template<class View>
00093 forceinline
00094 BrancherFilter<View>::BrancherFilter(BranchFilter<Var> bf) : f(bf) {
00095 if (!bf)
00096 throw Gecode::InvalidFunction("BrancherFilter::BrancherFilter");
00097 }
00098
00099 template<class View>
00100 forceinline
00101 BrancherFilter<View>::BrancherFilter(Space& home, bool shared,
00102 BrancherFilter<View>& bf) {
00103 f.update(home,shared,bf.f);
00104 }
00105
00106 template<class View>
00107 forceinline
00108 BrancherFilter<View>::operator bool(void) const {
00109 return true;
00110 }
00111
00112 template<class View>
00113 forceinline bool
00114 BrancherFilter<View>::operator ()(const Space& home, View x, int i) const {
00115 GECODE_VALID_FUNCTION(f());
00116 Var xv(x.varimp());
00117 return f()(home,xv,i);
00118 }
00119
00120 template<class View>
00121 forceinline bool
00122 BrancherFilter<View>::notice(void) const {
00123 return true;
00124 }
00125
00126 template<class View>
00127 forceinline void
00128 BrancherFilter<View>::dispose(Space&) {
00129 f.~SharedData<BranchFilter<Var>>();
00130 }
00131
00132
00133 template<class View>
00134 forceinline
00135 BrancherNoFilter<View>::BrancherNoFilter(BranchFilter<Var> bf) {
00136 assert(!bf);
00137 }
00138
00139 template<class View>
00140 forceinline
00141 BrancherNoFilter<View>::BrancherNoFilter(Space&, bool,
00142 BrancherNoFilter<View>&) {}
00143
00144 template<class View>
00145 forceinline
00146 BrancherNoFilter<View>::operator bool(void) const {
00147 return false;
00148 }
00149
00150 template<class View>
00151 forceinline bool
00152 BrancherNoFilter<View>::operator ()(const Space&, View, int) const {
00153 return true;
00154 }
00155 template<class View>
00156 forceinline bool
00157 BrancherNoFilter<View>::notice(void) const {
00158 return false;
00159 }
00160
00161 template<class View>
00162 forceinline void
00163 BrancherNoFilter<View>::dispose(Space&) {
00164 }
00165
00166 }
00167
00168