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 #include <algorithm>
00037
00038 namespace Gecode { namespace Int { namespace Cumulative {
00039
00040 template<class OptTask, class Cap, class PL>
00041 forceinline
00042 OptProp<OptTask,Cap,PL>::OptProp(Home home, Cap c0, TaskArray<OptTask>& t)
00043 : TaskProp<OptTask,PL>(home,t), c(c0) {
00044 c.subscribe(home,*this,PC_INT_BND);
00045 }
00046
00047 template<class OptTask, class Cap, class PL>
00048 forceinline
00049 OptProp<OptTask,Cap,PL>::OptProp(Space& home, OptProp<OptTask,Cap,PL>& p)
00050 : TaskProp<OptTask,PL>(home,p) {
00051 c.update(home,p.c);
00052 }
00053
00054 template<class OptTask, class Cap, class PL>
00055 ExecStatus
00056 OptProp<OptTask,Cap,PL>::post(Home home, Cap c, TaskArray<OptTask>& t) {
00057
00058 GECODE_ME_CHECK(c.gq(home, 0));
00059
00060 int n=t.size(), m=0;
00061 for (int i=n; i--; ) {
00062 if (t[i].c() > c.max())
00063 GECODE_ME_CHECK(t[i].excluded(home));
00064 if (t[i].excluded())
00065 t[i]=t[--n];
00066 else if (t[i].mandatory())
00067 m++;
00068 }
00069 t.size(n);
00070 if (t.size() < 2) {
00071 if (t.size() == 1) {
00072 if (t[0].mandatory()) {
00073 GECODE_ME_CHECK(c.gq(home, t[0].c()));
00074 return ES_OK;
00075 } else if (c.min() >= t[0].c()) {
00076 return ES_OK;
00077 }
00078 } else {
00079 return ES_OK;
00080 }
00081 }
00082 if (c.assigned() && (c.val() == 1)) {
00083 TaskArray<typename TaskTraits<OptTask>::UnaryTask> mt(home,t.size());
00084 for (int i=0; i<t.size(); i++)
00085 mt[i]=t[i];
00086 return Unary::OptProp<typename TaskTraits<OptTask>::UnaryTask,PL>
00087 ::post(home,mt);
00088 }
00089 if (m == t.size()) {
00090 TaskArray<typename TaskTraits<OptTask>::ManTask> mt(home,m);
00091 for (int i=0; i<m; i++)
00092 mt[i].init(t[i]);
00093 return ManProp<typename TaskTraits<OptTask>::ManTask,Cap,PL>
00094 ::post(home,c,mt);
00095 }
00096 (void) new (home) OptProp<OptTask,Cap,PL>(home,c,t);
00097 return ES_OK;
00098 }
00099
00100 template<class OptTask, class Cap, class PL>
00101 Actor*
00102 OptProp<OptTask,Cap,PL>::copy(Space& home) {
00103 return new (home) OptProp<OptTask,Cap,PL>(home,*this);
00104 }
00105
00106 template<class OptTask, class Cap, class PL>
00107 forceinline size_t
00108 OptProp<OptTask,Cap,PL>::dispose(Space& home) {
00109 (void) TaskProp<OptTask,PL>::dispose(home);
00110 c.cancel(home,*this,PC_INT_BND);
00111 return sizeof(*this);
00112 }
00113
00114 template<class OptTask, class Cap, class PL>
00115 ExecStatus
00116 OptProp<OptTask,Cap,PL>::propagate(Space& home, const ModEventDelta& med) {
00117
00118 if (BoolView::me(med) == ME_BOOL_VAL)
00119 GECODE_ES_CHECK((purge<OptTask,PL>(home,*this,t,c)));
00120
00121
00122 if (IntView::me(med) != ME_INT_DOM)
00123 GECODE_ES_CHECK(overload(home,c.max(),t));
00124
00125 if (PL::basic)
00126 GECODE_ES_CHECK(timetabling(home,*this,c,t));
00127
00128 if (PL::advanced) {
00129
00130 int n = t.size();
00131 int i=0, j=n-1;
00132 while (true) {
00133 while ((i < n) && t[i].mandatory()) i++;
00134 while ((j >= 0) && !t[j].mandatory()) j--;
00135 if (i >= j) break;
00136 std::swap(t[i],t[j]);
00137 }
00138
00139 if (i > 1) {
00140
00141 t.size(i);
00142 GECODE_ES_CHECK(edgefinding(home,c.max(),t));
00143
00144 t.size(n);
00145 }
00146 }
00147
00148 if (Cap::varderived() && c.assigned() && c.val()==1) {
00149
00150 for (int i=0; i<t.size(); i++)
00151 if (t[i].c() > 1)
00152 GECODE_ME_CHECK(t[i].excluded(home));
00153
00154 TaskArray<typename TaskTraits<OptTask>::UnaryTask> ut(home,t.size());
00155 for (int i=0; i<t.size(); i++)
00156 ut[i]=t[i];
00157 GECODE_REWRITE(*this,
00158 (Unary::OptProp<typename TaskTraits<OptTask>::UnaryTask,PL>
00159 ::post(home(*this),ut)));
00160 }
00161
00162 if (!PL::basic && c.assigned())
00163 GECODE_ES_CHECK(subsumed(home,*this,c.val(),t));
00164
00165 return ES_NOFIX;
00166 }
00167
00168 }}}
00169
00170