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
00039
00040 #include <gecode/scheduling/cumulative.hh>
00041
00042 #include <algorithm>
00043
00044 namespace Gecode {
00045
00046 void
00047 cumulative(Home home, int c, const TaskTypeArgs& t,
00048 const IntVarArgs& s, const IntArgs& p, const IntArgs& u) {
00049 using namespace Gecode::Scheduling;
00050 using namespace Gecode::Scheduling::Cumulative;
00051 if ((s.size() != p.size()) || (s.size() != u.size()) ||
00052 (s.size() != t.size()))
00053 throw Int::ArgumentSizeMismatch("Scheduling::cumulative");
00054 double w = 0.0;
00055 for (int i=p.size(); i--; ) {
00056 Int::Limits::nonnegative(p[i],"Scheduling::cumulative");
00057 Int::Limits::nonnegative(u[i],"Scheduling::cumulative");
00058 Int::Limits::check(static_cast<double>(s[i].max()) + p[i],
00059 "Scheduling::cumulative");
00060 Int::Limits::double_check(static_cast<double>(p[i]) * u[i],
00061 "Scheduling::cumulative");
00062 w += s[i].width();
00063 }
00064 Int::Limits::double_check(c * w * s.size(),
00065 "Scheduling::cumulative");
00066 if (home.failed()) return;
00067 bool fixp = true;
00068 for (int i=t.size(); i--;)
00069 if (t[i] != TT_FIXP) {
00070 fixp = false; break;
00071 }
00072 if (fixp) {
00073 TaskArray<ManFixPTask> tasks(home,s.size());
00074 for (int i=0; i<s.size(); i++)
00075 tasks[i].init(s[i],p[i],u[i]);
00076 GECODE_ES_FAIL(ManProp<ManFixPTask>::post(home,c,tasks));
00077 } else {
00078 TaskArray<ManFixPSETask> tasks(home,s.size());
00079 for (int i=s.size(); i--;)
00080 tasks[i].init(t[i],s[i],p[i],u[i]);
00081 GECODE_ES_FAIL(ManProp<ManFixPSETask>::post(home,c,tasks));
00082 }
00083 }
00084
00085 void
00086 cumulative(Home home, int c, const TaskTypeArgs& t,
00087 const IntVarArgs& s, const IntArgs& p, const IntArgs& u,
00088 const BoolVarArgs& m) {
00089 using namespace Gecode::Scheduling;
00090 using namespace Gecode::Scheduling::Cumulative;
00091 if ((s.size() != p.size()) || (s.size() != u.size()) ||
00092 (s.size() != t.size()) || (s.size() != m.size()))
00093 throw Int::ArgumentSizeMismatch("Scheduling::cumulative");
00094 double w = 0.0;
00095 for (int i=p.size(); i--; ) {
00096 Int::Limits::nonnegative(p[i],"Scheduling::cumulative");
00097 Int::Limits::nonnegative(u[i],"Scheduling::cumulative");
00098 Int::Limits::check(static_cast<double>(s[i].max()) + p[i],
00099 "Scheduling::cumulative");
00100 Int::Limits::double_check(static_cast<double>(p[i]) * u[i],
00101 "Scheduling::cumulative");
00102 w += s[i].width();
00103 }
00104 Int::Limits::double_check(c * w * s.size(),
00105 "Scheduling::cumulative");
00106 if (home.failed()) return;
00107 bool fixp = true;
00108 for (int i=t.size(); i--;)
00109 if (t[i] != TT_FIXP) {
00110 fixp = false; break;
00111 }
00112 if (fixp) {
00113 TaskArray<OptFixPTask> tasks(home,s.size());
00114 for (int i=0; i<s.size(); i++)
00115 tasks[i].init(s[i],p[i],u[i],m[i]);
00116 GECODE_ES_FAIL(OptProp<OptFixPTask>::post(home,c,tasks));
00117 } else {
00118 TaskArray<OptFixPSETask> tasks(home,s.size());
00119 for (int i=s.size(); i--;)
00120 tasks[i].init(t[i],s[i],p[i],u[i],m[i]);
00121 GECODE_ES_FAIL(OptProp<OptFixPSETask>::post(home,c,tasks));
00122 }
00123 }
00124 void
00125 cumulative(Home home, int c, const IntVarArgs& s,
00126 const IntArgs& p, const IntArgs& u) {
00127 using namespace Gecode::Scheduling;
00128 using namespace Gecode::Scheduling::Cumulative;
00129 if ((s.size() != p.size()) || (s.size() != u.size()))
00130 throw Int::ArgumentSizeMismatch("Scheduling::cumulative");
00131 double w = 0.0;
00132 for (int i=p.size(); i--; ) {
00133 Int::Limits::nonnegative(p[i],"Scheduling::cumulative");
00134 Int::Limits::nonnegative(u[i],"Scheduling::cumulative");
00135 Int::Limits::check(static_cast<double>(s[i].max()) + p[i],
00136 "Scheduling::cumulative");
00137 Int::Limits::double_check(static_cast<double>(p[i]) * u[i],
00138 "Scheduling::cumulative");
00139 w += s[i].width();
00140 }
00141 Int::Limits::double_check(c * w * s.size(),
00142 "Scheduling::cumulative");
00143 if (home.failed()) return;
00144 TaskArray<ManFixPTask> t(home,s.size());
00145 for (int i=0; i<s.size(); i++) {
00146 t[i].init(s[i],p[i],u[i]);
00147 }
00148 GECODE_ES_FAIL(ManProp<ManFixPTask>::post(home,c,t));
00149 }
00150
00151 void
00152 cumulative(Home home, int c, const IntVarArgs& s, const IntArgs& p,
00153 const IntArgs& u, const BoolVarArgs& m) {
00154 using namespace Gecode::Scheduling;
00155 using namespace Gecode::Scheduling::Cumulative;
00156 if ((s.size() != p.size()) || (s.size() != u.size()) ||
00157 (s.size() != m.size()))
00158 throw Int::ArgumentSizeMismatch("Scheduling::cumulative");
00159 double w = 0.0;
00160 for (int i=p.size(); i--; ) {
00161 Int::Limits::nonnegative(p[i],"Scheduling::cumulative");
00162 Int::Limits::nonnegative(u[i],"Scheduling::cumulative");
00163 Int::Limits::check(static_cast<double>(s[i].max()) + p[i],
00164 "Scheduling::cumulative");
00165 Int::Limits::double_check(static_cast<double>(p[i]) * u[i],
00166 "Scheduling::cumulative");
00167 w += s[i].width();
00168 }
00169 Int::Limits::double_check(c * w * s.size(),
00170 "Scheduling::cumulative");
00171 if (home.failed()) return;
00172 TaskArray<OptFixPTask> t(home,s.size());
00173 for (int i=0; i<s.size(); i++) {
00174 t[i].init(s[i],p[i],u[i],m[i]);
00175 }
00176 GECODE_ES_FAIL(OptProp<OptFixPTask>::post(home,c,t));
00177 }
00178
00179 void
00180 cumulative(Home home, int c, const IntVarArgs& s,
00181 const IntVarArgs& p, const IntVarArgs& e,
00182 const IntArgs& u) {
00183 using namespace Gecode::Scheduling;
00184 using namespace Gecode::Scheduling::Cumulative;
00185 if ((s.size() != p.size()) || (s.size() != e.size()) ||
00186 (s.size() != u.size()))
00187 throw Int::ArgumentSizeMismatch("Scheduling::cumulative");
00188 double w = 0.0;
00189 for (int i=p.size(); i--; ) {
00190 rel(home, p[i], IRT_GQ, 0);
00191 }
00192 for (int i=p.size(); i--; ) {
00193 Int::Limits::nonnegative(u[i],"Scheduling::cumulative");
00194 Int::Limits::check(static_cast<double>(s[i].max()) + p[i].max(),
00195 "Scheduling::cumulative");
00196 Int::Limits::double_check(static_cast<double>(p[i].max()) * u[i],
00197 "Scheduling::cumulative");
00198 w += s[i].width();
00199 }
00200 Int::Limits::double_check(c * w * s.size(),
00201 "Scheduling::cumulative");
00202 if (home.failed()) return;
00203 TaskArray<ManFlexTask> t(home,s.size());
00204 for (int i=s.size(); i--; )
00205 t[i].init(s[i],p[i],e[i],u[i]);
00206 GECODE_ES_FAIL(ManProp<ManFlexTask>::post(home,c,t));
00207 }
00208
00209 void
00210 cumulative(Home home, int c, const IntVarArgs& s, const IntVarArgs& p,
00211 const IntVarArgs& e, const IntArgs& u, const BoolVarArgs& m) {
00212 using namespace Gecode::Scheduling;
00213 using namespace Gecode::Scheduling::Cumulative;
00214 if ((s.size() != p.size()) || (s.size() != u.size()) ||
00215 (s.size() != e.size()) || (s.size() != m.size()))
00216 throw Int::ArgumentSizeMismatch("Scheduling::cumulative");
00217 for (int i=p.size(); i--; ) {
00218 rel(home, p[i], IRT_GQ, 0);
00219 }
00220 double w = 0.0;
00221 for (int i=p.size(); i--; ) {
00222 Int::Limits::nonnegative(u[i],"Scheduling::cumulative");
00223 Int::Limits::check(static_cast<double>(s[i].max()) + p[i].max(),
00224 "Scheduling::cumulative");
00225 Int::Limits::double_check(static_cast<double>(p[i].max()) * u[i],
00226 "Scheduling::cumulative");
00227 w += s[i].width();
00228 }
00229 Int::Limits::double_check(c * w * s.size(),
00230 "Scheduling::cumulative");
00231 if (home.failed()) return;
00232 TaskArray<OptFlexTask> t(home,s.size());
00233 for (int i=s.size(); i--; )
00234 t[i].init(s[i],p[i],e[i],u[i],m[i]);
00235 GECODE_ES_FAIL(OptProp<OptFlexTask>::post(home,c,t));
00236 }
00237
00238 }
00239
00240