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 Scheduling {
00039
00041 template<class TaskView, bool inc>
00042 class StoEst {
00043 public:
00045 bool operator ()(const TaskView& t1, const TaskView& t2) const;
00046 };
00047
00049 template<class TaskView, bool inc>
00050 class StoEct {
00051 public:
00053 bool operator ()(const TaskView& t1, const TaskView& t2) const;
00054 };
00055
00057 template<class TaskView, bool inc>
00058 class StoLst {
00059 public:
00061 bool operator ()(const TaskView& t1, const TaskView& t2) const;
00062 };
00063
00065 template<class TaskView, bool inc>
00066 class StoLct {
00067 public:
00069 bool operator ()(const TaskView& t1, const TaskView& t2) const;
00070 };
00071
00073 template<class TaskView, template<class,bool> class STO, bool inc>
00074 class SortMap {
00075 private:
00077 const TaskViewArray<TaskView>& tasks;
00079 STO<TaskView,inc> sto;
00080 public:
00082 SortMap(const TaskViewArray<TaskView>& t);
00084 bool operator ()(int& i, int& j) const;
00085 };
00086
00087 template<class TaskView, bool inc>
00088 forceinline bool
00089 StoEst<TaskView,inc>::operator ()
00090 (const TaskView& t1, const TaskView& t2) const {
00091 return inc ? (t1.est() < t2.est()) : (t2.est() < t1.est());
00092 }
00093
00094 template<class TaskView, bool inc>
00095 forceinline bool
00096 StoEct<TaskView,inc>::operator ()
00097 (const TaskView& t1, const TaskView& t2) const {
00098 return inc ? (t1.ect() < t2.ect()) : (t2.ect() < t1.ect());
00099 }
00100
00101 template<class TaskView, bool inc>
00102 forceinline bool
00103 StoLst<TaskView,inc>::operator ()
00104 (const TaskView& t1, const TaskView& t2) const {
00105 return inc ? (t1.lst() < t2.lst()) : (t2.lst() < t1.lst());
00106 }
00107
00108 template<class TaskView, bool inc>
00109 forceinline bool
00110 StoLct<TaskView,inc>::operator ()
00111 (const TaskView& t1, const TaskView& t2) const {
00112 return inc ? (t1.lct() < t2.lct()) : (t2.lct() < t1.lct());
00113 }
00114
00115
00116 template<class TaskView, template<class,bool> class STO, bool inc>
00117 forceinline
00118 SortMap<TaskView,STO,inc>::SortMap(const TaskViewArray<TaskView>& t)
00119 : tasks(t) {}
00120 template<class TaskView, template<class,bool> class STO, bool inc>
00121 forceinline bool
00122 SortMap<TaskView,STO,inc>::operator ()(int& i, int& j) const {
00123 return sto(tasks[i],tasks[j]);
00124 }
00125
00126 template<class TaskView, SortTaskOrder sto, bool inc>
00127 forceinline void
00128 sort(TaskViewArray<TaskView>& t) {
00129 switch (sto) {
00130 case STO_EST:
00131 {
00132 StoEst<TaskView,inc> o; Support::quicksort(&t[0], t.size(), o);
00133 }
00134 break;
00135 case STO_ECT:
00136 {
00137 StoEct<TaskView,inc> o; Support::quicksort(&t[0], t.size(), o);
00138 }
00139 break;
00140 case STO_LST:
00141 {
00142 StoLst<TaskView,inc> o; Support::quicksort(&t[0], t.size(), o);
00143 }
00144 break;
00145 case STO_LCT:
00146 {
00147 StoLct<TaskView,inc> o; Support::quicksort(&t[0], t.size(), o);
00148 }
00149 break;
00150 default:
00151 GECODE_NEVER;
00152 }
00153 }
00154
00155 template<class TaskView, SortTaskOrder sto, bool inc>
00156 forceinline void
00157 sort(int* map, const TaskViewArray<TaskView>& t) {
00158 for (int i=t.size(); i--; )
00159 map[i]=i;
00160 switch (sto) {
00161 case STO_EST:
00162 {
00163 SortMap<TaskView,StoEst,inc> o(t);
00164 Support::quicksort(map, t.size(), o);
00165 }
00166 break;
00167 case STO_ECT:
00168 {
00169 SortMap<TaskView,StoEct,inc> o(t);
00170 Support::quicksort(map, t.size(), o);
00171 }
00172 break;
00173 case STO_LST:
00174 {
00175 SortMap<TaskView,StoLst,inc> o(t);
00176 Support::quicksort(map, t.size(), o);
00177 }
00178 break;
00179 case STO_LCT:
00180 {
00181 SortMap<TaskView,StoLct,inc> o(t);
00182 Support::quicksort(map, t.size(), o);
00183 }
00184 break;
00185 default:
00186 GECODE_NEVER;
00187 }
00188 }
00189
00190 template<class TaskView, SortTaskOrder sto, bool inc>
00191 forceinline void
00192 sort(int* map, int n, const TaskViewArray<TaskView>& t) {
00193 switch (sto) {
00194 case STO_EST:
00195 {
00196 SortMap<TaskView,StoEst,inc> o(t);
00197 Support::quicksort(map, n, o);
00198 }
00199 break;
00200 case STO_ECT:
00201 {
00202 SortMap<TaskView,StoEct,inc> o(t);
00203 Support::quicksort(map, n, o);
00204 }
00205 break;
00206 case STO_LST:
00207 {
00208 SortMap<TaskView,StoLst,inc> o(t);
00209 Support::quicksort(map, n, o);
00210 }
00211 break;
00212 case STO_LCT:
00213 {
00214 SortMap<TaskView,StoLct,inc> o(t);
00215 Support::quicksort(map, n, o);
00216 }
00217 break;
00218 default:
00219 GECODE_NEVER;
00220 }
00221 }
00222
00223 }}
00224
00225