Actual model
| 189 | |
| 190 | /// Actual model |
| 191 | SteelMill(const SteelMillOptions& opt) |
| 192 | : // Initialize instance data |
| 193 | IntMinimizeScript(opt), |
| 194 | capacities(opt.capacities()), ncapacities(opt.ncapacities()), |
| 195 | maxcapacity(opt.maxcapacity()), loss(opt.loss()), |
| 196 | ncolors(opt.ncolors()), orders(opt.orders()), |
| 197 | norders(opt.size()), nslabs(opt.size()), |
| 198 | // Initialize problem variables |
| 199 | slab(*this, norders, 0,nslabs-1), |
| 200 | slabload(*this, nslabs, 0,45), |
| 201 | slabcost(*this, nslabs, 0, Int::Limits::max), |
| 202 | total_cost(*this, 0, Int::Limits::max) |
| 203 | { |
| 204 | // Boolean variables for slab[o]==s |
| 205 | BoolVarArgs boolslab(norders*nslabs); |
| 206 | for (unsigned int i = 0; i < norders; ++i) { |
| 207 | BoolVarArgs tmp(nslabs); |
| 208 | for (int j = nslabs; j--; ) { |
| 209 | boolslab[j + i*nslabs] = tmp[j] = BoolVar(*this, 0, 1); |
| 210 | } |
| 211 | channel(*this, tmp, slab[i]); |
| 212 | } |
| 213 | |
| 214 | // Packing constraints |
| 215 | for (unsigned int s = 0; s < nslabs; ++s) { |
| 216 | IntArgs c(norders); |
| 217 | BoolVarArgs x(norders); |
| 218 | for (int i = norders; i--; ) { |
| 219 | c[i] = orders[i][order_weight]; |
| 220 | x[i] = boolslab[s + i*nslabs]; |
| 221 | } |
| 222 | linear(*this, c, x, IRT_EQ, slabload[s]); |
| 223 | } |
| 224 | // Redundant packing constraint |
| 225 | int totalweight = 0; |
| 226 | for (unsigned int i = norders; i-- ; ) |
| 227 | totalweight += orders[i][order_weight] ; |
| 228 | linear(*this, slabload, IRT_EQ, totalweight); |
| 229 | |
| 230 | |
| 231 | // Color constraints |
| 232 | IntArgs nofcolor(ncolors); |
| 233 | for (int c = ncolors; c--; ) { |
| 234 | nofcolor[c] = 0; |
| 235 | for (int o = norders; o--; ) { |
| 236 | if (orders[o][order_color] == c) nofcolor[c] += 1; |
| 237 | } |
| 238 | } |
| 239 | BoolVar f(*this, 0, 0); |
| 240 | for (unsigned int s = 0; s < nslabs; ++s) { |
| 241 | BoolVarArgs hascolor(ncolors); |
| 242 | for (int c = ncolors; c--; ) { |
| 243 | if (nofcolor[c]) { |
| 244 | BoolVarArgs hasc(nofcolor[c]); |
| 245 | int pos = 0; |
| 246 | for (int o = norders; o--; ) { |
| 247 | if (orders[o][order_color] == c) |
| 248 | hasc[pos++] = boolslab[s + o*nslabs]; |
nothing calls this directly
no test coverage detected