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