time-tabling.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 namespace Gecode { namespace Int { namespace Cumulative {
00037
00039 template<class Task>
00040 class TaskByDecCap {
00041 public:
00043 bool operator ()(const Task& t1, const Task& t2) const;
00044 };
00045
00046 template<class Task>
00047 forceinline bool
00048 TaskByDecCap<Task>::operator ()(const Task& t1, const Task& t2) const {
00049 return t1.c() > t2.c();
00050 }
00051
00052
00053 template<class Task, class Cap>
00054 forceinline ExecStatus
00055 timetabling(Space& home, Propagator& p, Cap c, TaskArray<Task>& t) {
00056 int ccur = c.max();
00057 int cmax = ccur;
00058 int cmin = ccur;
00059
00060
00061 TaskByDecCap<Task> tbdc;
00062 Support::quicksort(&t[0], t.size(), tbdc);
00063
00064 Region r;
00065
00066 bool assigned;
00067 if (Event* e = Event::events(r,t,assigned)) {
00068
00069 Support::BitSet<Region> tasks(r,static_cast<unsigned int>(t.size()));
00070
00071
00072 do {
00073
00074 int time = e->time();
00075
00076
00077 for ( ; (e->type() == Event::LRT) && (e->time() == time); e++)
00078 if (t[e->idx()].mandatory()) {
00079 tasks.set(static_cast<unsigned int>(e->idx()));
00080 ccur += t[e->idx()].c();
00081 }
00082
00083 for ( ; (e->type() == Event::LCT) && (e->time() == time); e++)
00084 tasks.clear(static_cast<unsigned int>(e->idx()));
00085
00086 for ( ; (e->type() == Event::EST) && (e->time() == time); e++)
00087 tasks.set(static_cast<unsigned int>(e->idx()));
00088
00089 for ( ; (e->type() == Event::ZRO) && (e->time() == time); e++) {
00090 ccur -= t[e->idx()].c();
00091 if (ccur < cmin) cmin=ccur;
00092 if (ccur < 0)
00093 return ES_FAILED;
00094 ccur += t[e->idx()].c();
00095 }
00096
00097
00098 int nrstime = time;
00099
00100 for ( ; (e->type() == Event::ERT) && (e->time() == time); e++)
00101 if (t[e->idx()].mandatory()) {
00102 tasks.clear(static_cast<unsigned int>(e->idx()));
00103 ccur -= t[e->idx()].c();
00104 if (ccur < cmin) cmin=ccur;
00105 nrstime = time+1;
00106 if (ccur < 0)
00107 return ES_FAILED;
00108 } else if (t[e->idx()].optional() && (t[e->idx()].c() > ccur)) {
00109 GECODE_ME_CHECK(t[e->idx()].excluded(home));
00110 }
00111
00112
00113 for (Iter::Values::BitSet<Support::BitSet<Region> > j(tasks);
00114 j() && (t[j.val()].c() > ccur); ++j)
00115
00116 if (t[j.val()].mandatory())
00117 GECODE_ME_CHECK(t[j.val()].norun(home, nrstime, e->time() - 1));
00118 } while (e->type() != Event::END);
00119
00120 GECODE_ME_CHECK(c.gq(home,cmax-cmin));
00121 }
00122
00123 if (assigned)
00124 return home.ES_SUBSUMED(p);
00125 return ES_NOFIX;
00126 }
00127
00128 }}}
00129
00130