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 #include <algorithm>
00041
00042 namespace Gecode { namespace Scheduling { namespace Cumulative {
00043
00044 template<class OptTask>
00045 forceinline
00046 OptProp<OptTask>::OptProp(Home home, int c0, TaskArray<OptTask>& t)
00047 : TaskProp<OptTask,Int::PC_INT_DOM>(home,t), c(c0) {}
00048
00049 template<class OptTask>
00050 forceinline
00051 OptProp<OptTask>::OptProp(Space& home, bool shared, OptProp<OptTask>& p)
00052 : TaskProp<OptTask,Int::PC_INT_DOM>(home,shared,p), c(p.c) {}
00053
00054 template<class OptTask>
00055 forceinline ExecStatus
00056 OptProp<OptTask>::post(Home home, int c, TaskArray<OptTask>& t) {
00057
00058 int n=t.size(), m=0;
00059 for (int i=n; i--; ) {
00060 if (t[i].c() > c)
00061 GECODE_ME_CHECK(t[i].excluded(home));
00062 if (t[i].excluded())
00063 t[i]=t[--n];
00064 else if (t[i].mandatory())
00065 m++;
00066 }
00067 t.size(n);
00068 if (t.size() < 2)
00069 return ES_OK;
00070 if (m == t.size()) {
00071 TaskArray<typename TaskTraits<OptTask>::ManTask> mt(home,m);
00072 for (int i=m; i--; )
00073 mt[i].init(t[i]);
00074 return ManProp<typename TaskTraits<OptTask>::ManTask>::post(home,c,mt);
00075 }
00076 (void) new (home) OptProp<OptTask>(home,c,t);
00077 return ES_OK;
00078 }
00079
00080 template<class OptTask>
00081 Actor*
00082 OptProp<OptTask>::copy(Space& home, bool share) {
00083 return new (home) OptProp<OptTask>(home,share,*this);
00084 }
00085
00086 template<class OptTask>
00087 forceinline size_t
00088 OptProp<OptTask>::dispose(Space& home) {
00089 (void) TaskProp<OptTask,Int::PC_INT_DOM>::dispose(home);
00090 return sizeof(*this);
00091 }
00092
00093 template<class OptTask>
00094 ExecStatus
00095 OptProp<OptTask>::propagate(Space& home, const ModEventDelta& med) {
00096
00097 if (Int::BoolView::me(med) == Int::ME_BOOL_VAL)
00098 GECODE_ES_CHECK((purge<OptTask,Int::PC_INT_DOM>(home,*this,t)));
00099
00100 if (Int::IntView::me(med) != Int::ME_INT_DOM)
00101 GECODE_ES_CHECK(overload(home,c,t));
00102
00103 GECODE_ES_CHECK(basic(home,*this,c,t));
00104
00105
00106 int n = t.size();
00107 int i=0, j=n-1;
00108 while (true) {
00109 while ((i < n) && t[i].mandatory()) i++;
00110 while ((j >= 0) && !t[j].mandatory()) j--;
00111 if (i >= j) break;
00112 std::swap(t[i],t[j]);
00113 }
00114
00115 if (i > 1) {
00116
00117 t.size(i);
00118 GECODE_ES_CHECK(edgefinding(home,c,t));
00119
00120 t.size(n);
00121 }
00122
00123 return ES_NOFIX;
00124 }
00125
00126 }}}
00127
00128