MCPcopy Create free account
hub / github.com/Gecode/gecode / SteelMill

Method SteelMill

examples/steel-mill.cpp:191–293  ·  view source on GitHub ↗

Actual model

Source from the content-addressed store, hash-verified

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];

Callers

nothing calls this directly

Calls 15

INT_VAR_MAX_MINFunction · 0.85
INT_VAL_MINFunction · 0.85
ValueSymmetryFunction · 0.85
quicksortFunction · 0.85
INT_VAR_SIZE_MINFunction · 0.85
capacitiesMethod · 0.80
ncapacitiesMethod · 0.80
maxcapacityMethod · 0.80
lossMethod · 0.80
ncolorsMethod · 0.80
ordersMethod · 0.80
BoolVarClass · 0.50

Tested by

no test coverage detected