Actual model
| 196 | }; |
| 197 | /// Actual model |
| 198 | PerfectSquare(const SizeOptions& opt) |
| 199 | : Script(opt), |
| 200 | x(*this,specs[opt.size()][0],0,specs[opt.size()][1]-1), |
| 201 | y(*this,specs[opt.size()][0],0,specs[opt.size()][1]-1) { |
| 202 | |
| 203 | const int* s = specs[opt.size()]; |
| 204 | int n = *s++; |
| 205 | int w = *s++; |
| 206 | |
| 207 | // Restrict position according to square size |
| 208 | for (int i=0; i<n; i++) { |
| 209 | rel(*this, x[i], IRT_LQ, w-s[i]); |
| 210 | rel(*this, y[i], IRT_LQ, w-s[i]); |
| 211 | } |
| 212 | |
| 213 | IntArgs sa(n,s); |
| 214 | |
| 215 | // Squares do not overlap |
| 216 | nooverlap(*this, x, sa, y, sa); |
| 217 | |
| 218 | /* |
| 219 | * Capacity constraints |
| 220 | * |
| 221 | */ |
| 222 | switch (opt.propagation()) { |
| 223 | case PROP_REIFIED: |
| 224 | { |
| 225 | for (int cx=0; cx<w; cx++) { |
| 226 | BoolVarArgs bx(*this,n,0,1); |
| 227 | for (int i=0; i<n; i++) |
| 228 | dom(*this, x[i], cx-s[i]+1, cx, bx[i]); |
| 229 | linear(*this, sa, bx, IRT_EQ, w); |
| 230 | } |
| 231 | for (int cy=0; cy<w; cy++) { |
| 232 | BoolVarArgs by(*this,n,0,1); |
| 233 | for (int i=0; i<n; i++) |
| 234 | dom(*this, y[i], cy-s[i]+1, cy, by[i]); |
| 235 | linear(*this, sa, by, IRT_EQ, w); |
| 236 | } |
| 237 | } |
| 238 | break; |
| 239 | case PROP_CUMULATIVES: |
| 240 | { |
| 241 | IntArgs m(n), dh(n); |
| 242 | for (int i=0; i<n; i++) { |
| 243 | m[i]=0; dh[i]=s[i]; |
| 244 | } |
| 245 | IntArgs limit({w}); |
| 246 | { |
| 247 | // x-direction |
| 248 | IntVarArgs e(n); |
| 249 | for (int i=0; i<n; i++) |
| 250 | e[i]=expr(*this, x[i]+dh[i]); |
| 251 | cumulatives(*this, m, x, dh, e, dh, limit, true); |
| 252 | cumulatives(*this, m, x, dh, e, dh, limit, false); |
| 253 | } |
| 254 | { |
| 255 | // y-direction |
nothing calls this directly
no test coverage detected