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 #include "gecode/int/cumulatives.hh"
00039 #include "gecode/int/linear.hh"
00040
00041 namespace Gecode {
00042
00043 using namespace Int;
00044
00045 namespace {
00046 ViewArray<IntView>
00047 make_view_array(Space* home, const IntVarArgs& in) {
00048 return ViewArray<IntView>(home, in);
00049 }
00050
00051 ViewArray<ConstIntView>
00052 make_view_array(Space* home, const IntArgs& in) {
00053 ViewArray<ConstIntView> res(home, in.size());
00054 for (int i = in.size(); i--; ) {
00055 Limits::check(in[i],"Int::cumulatives");
00056 res[i] = ConstIntView(in[i]);
00057 }
00058
00059 return res;
00060 }
00061
00062 template<class In> class ViewType;
00063
00064 template<>
00065 class ViewType<IntArgs> {
00066 public:
00067 typedef ConstIntView Result;
00068 };
00069
00070 template<>
00071 class ViewType<IntVarArgs> {
00072 public:
00073 typedef IntView Result;
00074 };
00075
00076 void
00077 sum(Space* home, IntVar s, IntVar d, IntVar e) {
00078 GECODE_AUTOARRAY(Linear::Term<IntView>, t, 3);
00079 t[0].a= 1; t[0].x=s;
00080 t[1].a= 1; t[1].x=d;
00081 t[2].a=-1; t[2].x=e;
00082 Linear::post(home, t, 3, IRT_EQ, 0);
00083 }
00084
00085 void
00086 sum(Space* home, IntVar s, int d, IntVar e) {
00087 GECODE_AUTOARRAY(Linear::Term<IntView>, t, 2);
00088 t[0].a= 1; t[0].x=s;
00089 t[1].a=-1; t[1].x=e;
00090 Linear::post(home, t, 2, IRT_EQ, -d);
00091 }
00092
00093 template <class Machine, class Duration, class Height>
00094 void
00095 post_cumulatives(Space* home, const Machine& machine,
00096 const IntVarArgs& start, const Duration& duration,
00097 const IntVarArgs& end, const Height& height,
00098 const IntArgs& limit, bool at_most,
00099 IntConLevel) {
00100 if (machine.size() != start.size() ||
00101 start.size() != duration.size() ||
00102 duration.size() != end.size() ||
00103 end.size() != height.size())
00104 throw ArgumentSizeMismatch("Int::cumulatives");
00105 if (home->failed()) return;
00106
00107 ViewArray<typename ViewType<Machine>::Result>
00108 vmachine = make_view_array(home, machine);
00109 ViewArray<typename ViewType<Duration>::Result>
00110 vduration = make_view_array(home, duration);
00111 ViewArray<typename ViewType<Height>::Result>
00112 vheight = make_view_array(home, height);
00113 ViewArray<IntView>
00114 vstart = make_view_array(home, start),
00115 vend = make_view_array(home, end);
00116
00117
00118 GECODE_ES_FAIL(home,(Cumulatives::Val<
00119 typename ViewType<Machine>::Result,
00120 typename ViewType<Duration>::Result,
00121 typename ViewType<Height>::Result,
00122 IntView>::post(home, vmachine,vstart, vduration,
00123 vend, vheight,limit, at_most)));
00124
00125
00126
00127
00128 for (int i = start.size(); i--; )
00129 sum(home, start[i], duration[i], end[i]);
00130 }
00131 }
00132
00133
00134 void
00135 cumulatives(Space* home, const IntVarArgs& machine,
00136 const IntVarArgs& start, const IntVarArgs& duration,
00137 const IntVarArgs& end, const IntVarArgs& height,
00138 const IntArgs& limit, bool at_most,
00139 IntConLevel cl, PropKind) {
00140 post_cumulatives(home, machine, start, duration, end,
00141 height, limit, at_most, cl);
00142 }
00143
00144 void
00145 cumulatives(Space* home, const IntArgs& machine,
00146 const IntVarArgs& start, const IntVarArgs& duration,
00147 const IntVarArgs& end, const IntVarArgs& height,
00148 const IntArgs& limit, bool at_most,
00149 IntConLevel cl, PropKind) {
00150 post_cumulatives(home, machine, start, duration, end,
00151 height, limit, at_most, cl);
00152 }
00153
00154 void
00155 cumulatives(Space* home, const IntVarArgs& machine,
00156 const IntVarArgs& start, const IntArgs& duration,
00157 const IntVarArgs& end, const IntVarArgs& height,
00158 const IntArgs& limit, bool at_most,
00159 IntConLevel cl, PropKind) {
00160 post_cumulatives(home, machine, start, duration, end,
00161 height, limit, at_most, cl);
00162 }
00163
00164 void
00165 cumulatives(Space* home, const IntArgs& machine,
00166 const IntVarArgs& start, const IntArgs& duration,
00167 const IntVarArgs& end, const IntVarArgs& height,
00168 const IntArgs& limit, bool at_most,
00169 IntConLevel cl, PropKind) {
00170 post_cumulatives(home, machine, start, duration, end,
00171 height, limit, at_most, cl);
00172 }
00173
00174 void
00175 cumulatives(Space* home, const IntVarArgs& machine,
00176 const IntVarArgs& start, const IntVarArgs& duration,
00177 const IntVarArgs& end, const IntArgs& height,
00178 const IntArgs& limit, bool at_most,
00179 IntConLevel cl, PropKind) {
00180 post_cumulatives(home, machine, start, duration, end,
00181 height, limit, at_most, cl);
00182 }
00183
00184 void
00185 cumulatives(Space* home, const IntArgs& machine,
00186 const IntVarArgs& start, const IntVarArgs& duration,
00187 const IntVarArgs& end, const IntArgs& height,
00188 const IntArgs& limit, bool at_most,
00189 IntConLevel cl, PropKind) {
00190 post_cumulatives(home, machine, start, duration, end,
00191 height, limit, at_most, cl);
00192 }
00193
00194 void
00195 cumulatives(Space* home, const IntVarArgs& machine,
00196 const IntVarArgs& start, const IntArgs& duration,
00197 const IntVarArgs& end, const IntArgs& height,
00198 const IntArgs& limit, bool at_most,
00199 IntConLevel cl, PropKind) {
00200 post_cumulatives(home, machine, start, duration, end,
00201 height, limit, at_most, cl);
00202 }
00203
00204 void
00205 cumulatives(Space* home, const IntArgs& machine,
00206 const IntVarArgs& start, const IntArgs& duration,
00207 const IntVarArgs& end, const IntArgs& height,
00208 const IntArgs& limit, bool at_most,
00209 IntConLevel cl, PropKind) {
00210 post_cumulatives(home, machine, start, duration, end,
00211 height, limit, at_most, cl);
00212 }
00213
00214 GECODE_REGISTER4(Int::Cumulatives::Val<Int::ConstIntView, Int::IntView, Int::ConstIntView, Int::IntView>);
00215 GECODE_REGISTER4(Int::Cumulatives::Val<Int::ConstIntView, Int::IntView, Int::IntView, Int::IntView>);
00216 GECODE_REGISTER4(Int::Cumulatives::Val<Int::ConstIntView, Int::ConstIntView, Int::IntView, Int::IntView>);
00217 GECODE_REGISTER4(Int::Cumulatives::Val<Int::ConstIntView, Int::ConstIntView, Int::ConstIntView, Int::IntView>);
00218 GECODE_REGISTER4(Int::Cumulatives::Val<Int::IntView, Int::ConstIntView, Int::IntView, Int::IntView>);
00219 GECODE_REGISTER4(Int::Cumulatives::Val<Int::IntView, Int::ConstIntView, Int::ConstIntView, Int::IntView>);
00220 GECODE_REGISTER4(Int::Cumulatives::Val<Int::IntView, Int::IntView, Int::ConstIntView, Int::IntView>);
00221 GECODE_REGISTER4(Int::Cumulatives::Val<Int::IntView, Int::IntView, Int::IntView, Int::IntView>);
00222
00223 }
00224
00225
00226