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/unary.hh>
00041
00042 #include <algorithm>
00043
00044 namespace Gecode {
00045
00046 void
00047 unary(Home home, const IntVarArgs& s, const IntArgs& p) {
00048 using namespace Gecode::Scheduling;
00049 using namespace Gecode::Scheduling::Unary;
00050 if (s.same(home))
00051 throw Int::ArgumentSame("Scheduling::unary");
00052 if (s.size() != p.size())
00053 throw Int::ArgumentSizeMismatch("Scheduling::unary");
00054 for (int i=p.size(); i--; ) {
00055 Int::Limits::nonnegative(p[i],"Scheduling::unary");
00056 Int::Limits::check(static_cast<double>(s[i].max()) + p[i],
00057 "Scheduling::unary");
00058 }
00059 if (home.failed()) return;
00060 TaskArray<ManFixPTask> t(home,s.size());
00061 for (int i=s.size(); i--; )
00062 t[i].init(s[i],p[i]);
00063 GECODE_ES_FAIL(ManProp<ManFixPTask>::post(home,t));
00064 }
00065
00066 void
00067 unary(Home home, const TaskTypeArgs& t,
00068 const IntVarArgs& s, const IntArgs& p) {
00069 using namespace Gecode::Scheduling;
00070 using namespace Gecode::Scheduling::Unary;
00071 if ((s.size() != p.size()) || (s.size() != t.size()))
00072 throw Int::ArgumentSizeMismatch("Scheduling::unary");
00073 for (int i=p.size(); i--; ) {
00074 if (t[i] == TT_FIXP)
00075 Int::Limits::nonnegative(p[i],"Scheduling::unary");
00076 else
00077 Int::Limits::check(p[i],"Scheduling::unary");
00078 Int::Limits::check(static_cast<double>(s[i].max()) + p[i],
00079 "Scheduling::unary");
00080 }
00081 if (home.failed()) return;
00082 bool fixp = true;
00083 for (int i=t.size(); i--;)
00084 if (t[i] != TT_FIXP) {
00085 fixp = false; break;
00086 }
00087 if (fixp) {
00088 TaskArray<ManFixPTask> tasks(home,s.size());
00089 for (int i=s.size(); i--; )
00090 tasks[i].init(s[i],p[i]);
00091 GECODE_ES_FAIL(ManProp<ManFixPTask>::post(home,tasks));
00092 } else {
00093 TaskArray<ManFixPSETask> tasks(home,s.size());
00094 for (int i=s.size(); i--;)
00095 tasks[i].init(t[i],s[i],p[i]);
00096 GECODE_ES_FAIL(ManProp<ManFixPSETask>::post(home,tasks));
00097 }
00098 }
00099
00100 void
00101 unary(Home home, const IntVarArgs& s, const IntArgs& p,
00102 const BoolVarArgs& m) {
00103 using namespace Gecode::Scheduling;
00104 using namespace Gecode::Scheduling::Unary;
00105 if (s.same(home))
00106 throw Int::ArgumentSame("Scheduling::unary");
00107 if ((s.size() != p.size()) || (s.size() != m.size()))
00108 throw Int::ArgumentSizeMismatch("Scheduling::unary");
00109 for (int i=p.size(); i--; ) {
00110 Int::Limits::nonnegative(p[i],"Scheduling::unary");
00111 Int::Limits::check(static_cast<double>(s[i].max()) + p[i],
00112 "Scheduling::unary");
00113 }
00114 if (home.failed()) return;
00115 TaskArray<OptFixPTask> t(home,s.size());
00116 for (int i=s.size(); i--; )
00117 t[i].init(s[i],p[i],m[i]);
00118 GECODE_ES_FAIL(OptProp<OptFixPTask>::post(home,t));
00119 }
00120
00121 void
00122 unary(Home home, const TaskTypeArgs& t,
00123 const IntVarArgs& s, const IntArgs& p, const BoolVarArgs& m) {
00124 using namespace Gecode::Scheduling;
00125 using namespace Gecode::Scheduling::Unary;
00126 if ((s.size() != p.size()) || (s.size() != t.size()) ||
00127 (s.size() != m.size()))
00128 throw Int::ArgumentSizeMismatch("Scheduling::unary");
00129 for (int i=p.size(); i--; ) {
00130 if (t[i] == TT_FIXP)
00131 Int::Limits::nonnegative(p[i],"Scheduling::unary");
00132 else
00133 Int::Limits::check(p[i],"Scheduling::unary");
00134 Int::Limits::check(static_cast<double>(s[i].max()) + p[i],
00135 "Scheduling::unary");
00136 }
00137 if (home.failed()) return;
00138 bool fixp = true;
00139 for (int i=t.size(); i--;)
00140 if (t[i] != TT_FIXP) {
00141 fixp = false; break;
00142 }
00143 if (fixp) {
00144 TaskArray<OptFixPTask> tasks(home,s.size());
00145 for (int i=s.size(); i--; )
00146 tasks[i].init(s[i],p[i],m[i]);
00147 GECODE_ES_FAIL(OptProp<OptFixPTask>::post(home,tasks));
00148 } else {
00149 TaskArray<OptFixPSETask> tasks(home,s.size());
00150 for (int i=s.size(); i--;)
00151 tasks[i].init(t[i],s[i],p[i],m[i]);
00152 GECODE_ES_FAIL(OptProp<OptFixPSETask>::post(home,tasks));
00153 }
00154 }
00155
00156 void
00157 unary(Home home, const IntVarArgs& s, const IntVarArgs& p,
00158 const IntVarArgs& e) {
00159 using namespace Gecode::Scheduling;
00160 using namespace Gecode::Scheduling::Unary;
00161 if ((s.size() != p.size()) || (s.size() != e.size()))
00162 throw Int::ArgumentSizeMismatch("Scheduling::unary");
00163 if (home.failed()) return;
00164 for (int i=p.size(); i--; ) {
00165 rel(home, p[i], IRT_GQ, 0);
00166 }
00167 TaskArray<ManFlexTask> t(home,s.size());
00168 for (int i=s.size(); i--; )
00169 t[i].init(s[i],p[i],e[i]);
00170 GECODE_ES_FAIL(ManProp<ManFlexTask>::post(home,t));
00171 }
00172
00173 void
00174 unary(Home home, const IntVarArgs& s, const IntVarArgs& p,
00175 const IntVarArgs& e, const BoolVarArgs& m) {
00176 using namespace Gecode::Scheduling;
00177 using namespace Gecode::Scheduling::Unary;
00178 if ((s.size() != p.size()) || (s.size() != m.size()) ||
00179 (s.size() != e.size()))
00180 throw Int::ArgumentSizeMismatch("Scheduling::unary");
00181 if (home.failed()) return;
00182 for (int i=p.size(); i--; ) {
00183 rel(home, p[i], IRT_GQ, 0);
00184 }
00185 TaskArray<OptFlexTask> t(home,s.size());
00186 for (int i=s.size(); i--; )
00187 t[i].init(s[i],p[i],e[i],m[i]);
00188 GECODE_ES_FAIL(OptProp<OptFlexTask>::post(home,t));
00189 }
00190
00191 }
00192
00193