44 using namespace Gecode;
86 unsigned int _norders;
96 virtual void help(
void);
98 bool parse(
int& argc,
char* argv[]);
101 unsigned int size(
void)
const {
return _size; }
109 int*
loss(
void)
const {
return _loss; }
181 capacities(opt.capacities()), ncapacities(opt.ncapacities()),
182 maxcapacity(opt.maxcapacity()), loss(opt.loss()),
183 ncolors(opt.ncolors()), orders(opt.orders()),
184 norders(opt.
size()), nslabs(opt.
size()),
186 slab(*this, norders, 0,nslabs-1),
187 slabload(*this, nslabs, 0,45),
188 slabcost(*this, nslabs, 0, Int::Limits::
max),
189 total_cost(*this, 0, Int::Limits::
max)
193 for (
unsigned int i = 0;
i < norders; ++
i) {
195 for (
int j = nslabs; j--; ) {
196 boolslab[j +
i*nslabs] = tmp[j] =
BoolVar(*
this, 0, 1);
202 for (
unsigned int s = 0; s < nslabs; ++s) {
205 for (
int i = norders;
i--; ) {
207 x[
i] = boolslab[s +
i*nslabs];
213 for (
unsigned int i = norders;
i-- ; )
220 for (
int c = ncolors;
c--; ) {
222 for (
int o = norders; o--; ) {
227 for (
unsigned int s = 0; s < nslabs; ++s) {
229 for (
int c = ncolors;
c--; ) {
233 for (
int o = norders; o--; ) {
235 hasc[pos++] = boolslab[s + o*nslabs];
237 assert(pos == nofcolor[c]);
249 for (
int s = nslabs; s--; ) {
250 element(*
this, l, slabload[s], slabcost[s]);
255 if (opt.
symmetry() == SYMMETRY_BRANCHING) {
266 os <<
"What slab=" << slab << std::endl;
267 os <<
"Slab load=" << slabload << std::endl;
268 os <<
"Slab cost=" << slabcost << std::endl;
269 os <<
"Total cost=" << total_cost << std::endl;
272 bool unassigned =
false;
273 for (
int i = nslabs;
i--; ) {
278 if (slabload[
i].
min()>0) ++nslabsused;
279 if (slabcost[
i].
min()>0) ++nslabscost;
282 os <<
"Number of slabs used=" << nslabsused
283 <<
", slabs with cost=" << nslabscost
291 capacities(s.capacities), ncapacities(s.ncapacities),
292 maxcapacity(s.maxcapacity), loss(s.loss),
293 ncolors(s.ncolors), orders(s.orders),
294 norders(s.norders), nslabs(s.nslabs) {
295 slab.update(*
this, share, s.
slab);
296 slabload.update(*
this, share, s.
slabload);
297 slabcost.update(*
this, share, s.
slabcost);
298 total_cost.update(*
this, share, s.
total_cost);
334 : Gecode::
Choice(b,a),
pos(pos0), val(val0) {}
336 virtual size_t size(
void)
const {
342 e << alternatives() <<
pos << val;
351 :
Brancher(home, share, b), start(b.start) {
358 for (
unsigned int i = start;
i < sm.
norders; ++
i)
373 unsigned int pos = start;
374 for (
unsigned int i = start;
i<sm.
norders; ++
i) {
387 unsigned int val = sm.
slab[
pos].min();
389 unsigned int firstzero = 0;
394 return new Choice(*
this, (val<firstzero) ? 2 : 1, pos, val);
397 unsigned int alt;
int pos, val;
398 e >> alt >> pos >> val;
399 return new Choice(*
this, alt, pos, val);
423 return sizeof(*this);
438 if (!opt.
parse(argc,argv))
440 Script::run<SteelMill,BAB,SteelMillOptions>(
opt);
448 std::cerr <<
"\t(string), optional" << std::endl
449 <<
"\t\tBenchmark to load." << std::endl
450 <<
"\t\tIf none is given, the standard CSPLib instance is used."
452 std::cerr <<
"\t(unsigned int), optional" << std::endl
453 <<
"\t\tNumber of orders to use, in the interval [0..norders]."
455 <<
"\t\tIf none is given, all orders are used." << std::endl;
463 std::cerr <<
"Too many arguments given, max two allowed (given={";
464 for (
int i = 1;
i < argc; ++
i) {
465 std::cerr <<
"\"" << argv[
i] <<
"\"";
466 if (
i < argc-1) std::cerr <<
",";
468 std::cerr <<
"})." << std::endl;
474 for (
int i = strlen(argv[argc-1]);
i-- && issize; )
475 issize &= (isdigit(argv[argc-1][
i]) != 0);
477 _size = atoi(argv[argc-1]);
479 std::ifstream instance(argv[argc-1]);
480 if (instance.fail()) {
481 std::cerr <<
"Argument \"" << argv[argc-1]
482 <<
"\" is neither an integer nor a readable file"
487 instance >> _ncapacities;
488 _capacities =
new int[_ncapacities];
490 for (
int i = 0;
i < _ncapacities; ++
i) {
491 instance >> _capacities[
i];
492 _maxcapacity =
std::max(_maxcapacity, _capacities[
i]);
494 instance >> _ncolors >> _norders;
495 _orders =
new int[_norders][2];
496 for (
unsigned int i = 0;
i < _norders; ++
i) {
505 _loss =
new int[_maxcapacity+1];
508 for (
int c = 1;
c < _maxcapacity; ++
c) {
509 if (
c > _capacities[currcap]) ++currcap;
510 _loss[
c] = _capacities[currcap] -
c;
518 if (_size == 0 || _size > _norders) {
519 std::cerr <<
"Size must be between 1 and " << _norders << std::endl;