detectable.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 namespace Gecode { namespace Int { namespace Unary {
00039
00040 template<class ManTaskView>
00041 forceinline ExecStatus
00042 detectable(Space& home, TaskViewArray<ManTaskView>& t) {
00043 sort<ManTaskView,STO_ECT,true>(t);
00044
00045 Region r(home);
00046
00047 OmegaTree<ManTaskView> o(r,t);
00048 TaskViewIter<ManTaskView,STO_LST,true> q(r,t);
00049 int* est = r.alloc<int>(t.size());
00050
00051 for (int i=0; i<t.size(); i++) {
00052 while (q() && (t[i].ect() > t[q.task()].lst())) {
00053 o.insert(q.task()); ++q;
00054 }
00055 est[i] = o.ect(i);
00056 }
00057
00058 for (int i=t.size(); i--; )
00059 GECODE_ME_CHECK(t[i].est(home,est[i]));
00060
00061 return ES_OK;
00062 }
00063
00064 template<class ManTask>
00065 ExecStatus
00066 detectable(Space& home, TaskArray<ManTask>& t) {
00067 TaskViewArray<typename TaskTraits<ManTask>::TaskViewFwd> f(t);
00068 GECODE_ES_CHECK(detectable(home,f));
00069 TaskViewArray<typename TaskTraits<ManTask>::TaskViewBwd> b(t);
00070 return detectable(home,b);
00071 }
00072
00073
00074 template<class OptTaskView, class PL>
00075 forceinline ExecStatus
00076 detectable(Space& home, Propagator& p, TaskViewArray<OptTaskView>& t) {
00077 sort<OptTaskView,STO_ECT,true>(t);
00078
00079 Region r(home);
00080
00081 OmegaTree<OptTaskView> o(r,t);
00082 ManTaskViewIter<OptTaskView,STO_LST,true> q(r,t);
00083 int* est = r.alloc<int>(t.size());
00084
00085 for (int i=0; i<t.size(); i++) {
00086 while (q() && (t[i].ect() > t[q.task()].lst())) {
00087 o.insert(q.task()); ++q;
00088 }
00089 est[i] = o.ect(i);
00090 }
00091
00092 int n = t.size();
00093 for (int i=n; i--; )
00094 if (t[i].mandatory()) {
00095 GECODE_ME_CHECK(t[i].est(home,est[i]));
00096 } else if (est[i] > t[i].lst()) {
00097 GECODE_ME_CHECK(t[i].excluded(home));
00098 t[i].cancel(home,p,PL::pc); t[i]=t[--n];
00099 }
00100 t.size(n);
00101
00102 return (t.size() < 2) ? home.ES_SUBSUMED(p) : ES_OK;
00103 }
00104
00105 template<class OptTask, class PL>
00106 ExecStatus
00107 detectable(Space& home, Propagator& p, TaskArray<OptTask>& t) {
00108 TaskViewArray<typename TaskTraits<OptTask>::TaskViewFwd> f(t);
00109 GECODE_ES_CHECK((detectable<typename TaskTraits<OptTask>::TaskViewFwd,PL>
00110 (home,p,f)));
00111 TaskViewArray<typename TaskTraits<OptTask>::TaskViewBwd> b(t);
00112 return detectable<typename TaskTraits<OptTask>::TaskViewBwd,PL>
00113 (home,p,b);
00114 }
00115
00116 }}}
00117
00118