event.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 namespace Gecode { namespace Int {
00035
00036 forceinline void
00037 Event::init(Event::Type e0, int t0, int i0) {
00038 ei=static_cast<unsigned int>(e0 | (i0 << 3)); t=t0;
00039 }
00040
00041 forceinline Event::Type
00042 Event::type(void) const {
00043 return static_cast<Type>(ei & 7);
00044 }
00045 forceinline int
00046 Event::time(void) const {
00047 return t;
00048 }
00049 forceinline int
00050 Event::idx(void) const {
00051 return static_cast<int>(ei >> 3);;
00052 }
00053
00054 forceinline bool
00055 Event::operator <(const Event& e) const {
00056 if (time() == e.time())
00057 return type() < e.type();
00058 return time() < e.time();
00059 }
00060
00061
00062 template<class Char, class Traits>
00063 inline std::basic_ostream<Char,Traits>&
00064 operator <<(std::basic_ostream<Char,Traits>& os, const Event& e) {
00065 std::basic_ostringstream<Char,Traits> s;
00066 s.copyfmt(os); s.width(0);
00067 s << '[';
00068 switch (e.type()) {
00069 case Event::LRT: s << "LRT"; break;
00070 case Event::LCT: s << "LCT"; break;
00071 case Event::EST: s << "EST"; break;
00072 case Event::ZRO: s << "ZRO"; break;
00073 case Event::ERT: s << "ERT"; break;
00074 default: GECODE_NEVER;
00075 }
00076 s << ',' << e.time() << ',' << e.idx() << ']';
00077 return os << s.str();
00078 }
00079
00080
00081 template<class Task>
00082 forceinline Event*
00083 Event::events(Region& r, const TaskArray<Task>& t, bool& assigned) {
00084 Event* e = r.alloc<Event>(4*t.size()+1);
00085
00086
00087 assigned=true;
00088 bool required=false;
00089
00090 int n=0;
00091 for (int i=0; i<t.size(); i++)
00092 if (t[i].assigned()) {
00093
00094 if (t[i].pmin() > 0) {
00095 required = true;
00096 e[n++].init(Event::ERT,t[i].lst(),i);
00097 e[n++].init(Event::LRT,t[i].ect(),i);
00098 } else if (t[i].pmax() == 0) {
00099 required = true;
00100 e[n++].init(Event::ZRO,t[i].lst(),i);
00101 }
00102 } else {
00103 assigned = false;
00104 e[n++].init(Event::EST,t[i].est(),i);
00105 e[n++].init(Event::LCT,t[i].lct(),i);
00106
00107 if (t[i].lst() < t[i].ect()) {
00108 required = true;
00109 e[n++].init(Event::ERT,t[i].lst(),i);
00110 e[n++].init(Event::LRT,t[i].ect(),i);
00111 }
00112 }
00113
00114 if (!required)
00115 return NULL;
00116
00117
00118 Support::quicksort(e, n);
00119
00120
00121 e[n++].init(Event::END,Limits::infinity,0);
00122
00123 return e;
00124 }
00125
00126 template<class Task>
00127 forceinline Event*
00128 Event::events(Region& r, const TaskArray<Task>& t) {
00129 Event* e = r.alloc<Event>(2*t.size()+1);
00130
00131
00132 int n=0;
00133 for (int i=0; i<t.size(); i++)
00134 if (t[i].assigned() && t[i].mandatory()) {
00135 if (t[i].pmin() > 0) {
00136 e[n++].init(Event::ERT,t[i].lst(),i);
00137 e[n++].init(Event::LRT,t[i].ect(),i);
00138 } else if (t[i].pmax() == 0) {
00139 e[n++].init(Event::ZRO,t[i].lst(),i);
00140 }
00141 } else {
00142 assert(!t[i].excluded());
00143 return NULL;
00144 }
00145
00146
00147 Support::quicksort(e, n);
00148
00149
00150 e[n++].init(Event::END,Limits::infinity,0);
00151
00152 return e;
00153 }
00154
00155 }}
00156
00157