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 #include <gecode/int/no-overlap.hh>
00035
00036 namespace Gecode {
00037
00038 namespace Int { namespace NoOverlap {
00039
00040 bool
00041 optional(const BoolVarArgs& m) {
00042 for (int i=0; i<m.size(); i++)
00043 if (m[i].none())
00044 return true;
00045 return false;
00046 }
00047
00048 }}
00049
00050 void
00051 nooverlap(Home home,
00052 const IntVarArgs& x, const IntArgs& w,
00053 const IntVarArgs& y, const IntArgs& h,
00054 IntPropLevel) {
00055 using namespace Int;
00056 using namespace NoOverlap;
00057 if ((x.size() != w.size()) || (x.size() != y.size()) ||
00058 (x.size() != h.size()))
00059 throw ArgumentSizeMismatch("Int::nooverlap");
00060 for (int i=0; i<x.size(); i++) {
00061 Limits::nonnegative(w[i],"Int::nooverlap");
00062 Limits::nonnegative(h[i],"Int::nooverlap");
00063 Limits::check(static_cast<long long int>(x[i].max()) + w[i],
00064 "Int::nooverlap");
00065 Limits::check(static_cast<long long int>(y[i].max()) + h[i],
00066 "Int::nooverlap");
00067 }
00068 GECODE_POST;
00069
00070 ManBox<FixDim,2>* b
00071 = static_cast<Space&>(home).alloc<ManBox<FixDim,2> >(x.size());
00072 for (int i=0; i<x.size(); i++) {
00073 b[i][0] = FixDim(x[i],w[i]);
00074 b[i][1] = FixDim(y[i],h[i]);
00075 }
00076
00077 GECODE_ES_FAIL((
00078 NoOverlap::ManProp<ManBox<FixDim,2> >::post(home,b,x.size())));
00079 }
00080
00081 void
00082 nooverlap(Home home,
00083 const IntVarArgs& x, const IntArgs& w,
00084 const IntVarArgs& y, const IntArgs& h,
00085 const BoolVarArgs& m,
00086 IntPropLevel) {
00087 using namespace Int;
00088 using namespace NoOverlap;
00089 if ((x.size() != w.size()) || (x.size() != y.size()) ||
00090 (x.size() != h.size()) || (x.size() != m.size()))
00091 throw ArgumentSizeMismatch("Int::nooverlap");
00092 for (int i=0; i<x.size(); i++) {
00093 Limits::nonnegative(w[i],"Int::nooverlap");
00094 Limits::nonnegative(h[i],"Int::nooverlap");
00095 Limits::check(static_cast<long long int>(x[i].max()) + w[i],
00096 "Int::nooverlap");
00097 Limits::check(static_cast<long long int>(y[i].max()) + h[i],
00098 "Int::nooverlap");
00099 }
00100 GECODE_POST;
00101
00102 if (optional(m)) {
00103 OptBox<FixDim,2>* b
00104 = static_cast<Space&>(home).alloc<OptBox<FixDim,2> >(x.size());
00105 for (int i=0; i<x.size(); i++) {
00106 b[i][0] = FixDim(x[i],w[i]);
00107 b[i][1] = FixDim(y[i],h[i]);
00108 b[i].optional(m[i]);
00109 }
00110 GECODE_ES_FAIL((
00111 NoOverlap::OptProp<OptBox<FixDim,2> >::post(home,b,x.size())));
00112 } else {
00113 ManBox<FixDim,2>* b
00114 = static_cast<Space&>(home).alloc<ManBox<FixDim,2> >(x.size());
00115 int n = 0;
00116 for (int i=0; i<x.size(); i++)
00117 if (m[i].one()) {
00118 b[n][0] = FixDim(x[i],w[i]);
00119 b[n][1] = FixDim(y[i],h[i]);
00120 n++;
00121 }
00122 GECODE_ES_FAIL((NoOverlap::ManProp<ManBox<FixDim,2> >::post(home,b,n)));
00123 }
00124 }
00125
00126 void
00127 nooverlap(Home home,
00128 const IntVarArgs& x0, const IntVarArgs& w, const IntVarArgs& x1,
00129 const IntVarArgs& y0, const IntVarArgs& h, const IntVarArgs& y1,
00130 IntPropLevel) {
00131 using namespace Int;
00132 using namespace NoOverlap;
00133 if ((x0.size() != w.size()) || (x0.size() != x1.size()) ||
00134 (x0.size() != y0.size()) || (x0.size() != h.size()) ||
00135 (x0.size() != y1.size()))
00136 throw ArgumentSizeMismatch("Int::nooverlap");
00137 GECODE_POST;
00138
00139 for (int i=0; i<x0.size(); i++) {
00140 GECODE_ME_FAIL(IntView(w[i]).gq(home,0));
00141 GECODE_ME_FAIL(IntView(h[i]).gq(home,0));
00142 }
00143
00144 if (w.assigned() && h.assigned()) {
00145 IntArgs wc(x0.size()), hc(x0.size());
00146 for (int i=0; i<x0.size(); i++) {
00147 wc[i] = w[i].val();
00148 hc[i] = h[i].val();
00149 }
00150 nooverlap(home, x0, wc, y0, hc);
00151 } else {
00152 ManBox<FlexDim,2>* b
00153 = static_cast<Space&>(home).alloc<ManBox<FlexDim,2> >(x0.size());
00154 for (int i=0; i<x0.size(); i++) {
00155 b[i][0] = FlexDim(x0[i],w[i],x1[i]);
00156 b[i][1] = FlexDim(y0[i],h[i],y1[i]);
00157 }
00158 GECODE_ES_FAIL((
00159 NoOverlap::ManProp<ManBox<FlexDim,2> >::post(home,b,x0.size())));
00160 }
00161 }
00162
00163 void
00164 nooverlap(Home home,
00165 const IntVarArgs& x0, const IntVarArgs& w, const IntVarArgs& x1,
00166 const IntVarArgs& y0, const IntVarArgs& h, const IntVarArgs& y1,
00167 const BoolVarArgs& m,
00168 IntPropLevel) {
00169 using namespace Int;
00170 using namespace NoOverlap;
00171 if ((x0.size() != w.size()) || (x0.size() != x1.size()) ||
00172 (x0.size() != y0.size()) || (x0.size() != h.size()) ||
00173 (x0.size() != y1.size()) || (x0.size() != m.size()))
00174 throw ArgumentSizeMismatch("Int::nooverlap");
00175 GECODE_POST;
00176
00177 for (int i=0; i<x0.size(); i++) {
00178 GECODE_ME_FAIL(IntView(w[i]).gq(home,0));
00179 GECODE_ME_FAIL(IntView(h[i]).gq(home,0));
00180 }
00181
00182 if (w.assigned() && h.assigned()) {
00183 IntArgs wc(x0.size()), hc(x0.size());
00184 for (int i=0; i<x0.size(); i++) {
00185 wc[i] = w[i].val();
00186 hc[i] = h[i].val();
00187 }
00188 nooverlap(home, x0, wc, y0, hc, m);
00189 } else if (optional(m)) {
00190 OptBox<FlexDim,2>* b
00191 = static_cast<Space&>(home).alloc<OptBox<FlexDim,2> >(x0.size());
00192 for (int i=0; i<x0.size(); i++) {
00193 b[i][0] = FlexDim(x0[i],w[i],x1[i]);
00194 b[i][1] = FlexDim(y0[i],h[i],y1[i]);
00195 b[i].optional(m[i]);
00196 }
00197 GECODE_ES_FAIL((
00198 NoOverlap::OptProp<OptBox<FlexDim,2> >::post(home,b,x0.size())));
00199 } else {
00200 ManBox<FlexDim,2>* b
00201 = static_cast<Space&>(home).alloc<ManBox<FlexDim,2> >(x0.size());
00202 int n = 0;
00203 for (int i=0; i<x0.size(); i++)
00204 if (m[i].one()) {
00205 b[n][0] = FlexDim(x0[i],w[i],x1[i]);
00206 b[n][1] = FlexDim(y0[i],h[i],y1[i]);
00207 n++;
00208 }
00209 GECODE_ES_FAIL((NoOverlap::ManProp<ManBox<FlexDim,2> >::post(home,b,n)));
00210 }
00211 }
00212
00213 }
00214
00215